"Fossies" - the Fresh Open Source Software Archive

Member "octavia-8.0.0/octavia/tests/unit/api/v2/types/test_load_balancer.py" (14 Apr 2021, 4241 Bytes) of package /linux/misc/openstack/octavia-8.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #    Copyright 2014 Rackspace
    2 #
    3 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    4 #    not use this file except in compliance with the License. You may obtain
    5 #    a copy of the License at
    6 #
    7 #         http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 #    Unless required by applicable law or agreed to in writing, software
   10 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   11 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   12 #    License for the specific language governing permissions and limitations
   13 #    under the License.
   14 
   15 from oslo_utils import uuidutils
   16 from wsme import exc
   17 from wsme.rest import json as wsme_json
   18 from wsme import types as wsme_types
   19 
   20 from octavia.api.v2.types import load_balancer as lb_type
   21 from octavia.tests.unit.api.common import base
   22 
   23 
   24 class TestLoadBalancer(object):
   25 
   26     _type = None
   27 
   28     def test_load_balancer(self):
   29         body = {"name": "test_name", "description": "test_description",
   30                 "vip_subnet_id": uuidutils.generate_uuid(),
   31                 "tags": ['test']}
   32         lb = wsme_json.fromjson(self._type, body)
   33         self.assertTrue(lb.admin_state_up)
   34 
   35     def test_invalid_name(self):
   36         body = {"name": 0}
   37         self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
   38                           body)
   39 
   40     def test_name_length(self):
   41         body = {"name": "x" * 256}
   42         self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
   43                           body)
   44 
   45     def test_invalid_description(self):
   46         body = {"description": 0}
   47         self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
   48                           body)
   49 
   50     def test_description_length(self):
   51         body = {"name": "x" * 256}
   52         self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
   53                           body)
   54 
   55     def test_invalid_enabled(self):
   56         body = {"admin_state_up": "notvalid"}
   57         self.assertRaises(ValueError, wsme_json.fromjson, self._type,
   58                           body)
   59 
   60     def test_invalid_qos_policy_id(self):
   61         body = {"vip_qos_policy_id": "invalid_uuid"}
   62         self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
   63                           body)
   64 
   65     def test_invalid_tags(self):
   66         body = {"tags": "invalid_tag"}
   67         self.assertRaises(ValueError, wsme_json.fromjson, self._type,
   68                           body)
   69         body = {"tags": [1, 2]}
   70         self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
   71                           body)
   72 
   73 
   74 class TestLoadBalancerPOST(base.BaseTypesTest, TestLoadBalancer):
   75 
   76     _type = lb_type.LoadBalancerPOST
   77 
   78     def test_non_uuid_project_id(self):
   79         body = {"name": "test_name", "description": "test_description",
   80                 "vip_subnet_id": uuidutils.generate_uuid(),
   81                 "project_id": "non-uuid"}
   82         lb = wsme_json.fromjson(self._type, body)
   83         self.assertEqual(lb.project_id, body['project_id'])
   84 
   85     def test_vip(self):
   86         body = {"vip_subnet_id": uuidutils.generate_uuid(),
   87                 "vip_port_id": uuidutils.generate_uuid(),
   88                 "vip_qos_policy_id": uuidutils.generate_uuid()}
   89         wsme_json.fromjson(self._type, body)
   90 
   91     def test_invalid_ip_address(self):
   92         body = {"vip_address": uuidutils.generate_uuid()}
   93         self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
   94                           body)
   95 
   96     def test_invalid_port_id(self):
   97         body = {"vip_port_id": "invalid_uuid"}
   98         self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
   99                           body)
  100 
  101     def test_invalid_subnet_id(self):
  102         body = {"vip_subnet_id": "invalid_uuid"}
  103         self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
  104                           body)
  105 
  106 
  107 class TestLoadBalancerPUT(base.BaseTypesTest, TestLoadBalancer):
  108 
  109     _type = lb_type.LoadBalancerPUT
  110 
  111     def test_load_balancer(self):
  112         body = {"name": "test_name", "description": "test_description",
  113                 "tags": ['test_tag']}
  114         lb = wsme_json.fromjson(self._type, body)
  115         self.assertEqual(wsme_types.Unset, lb.admin_state_up)