Neutron-LBaaS: Load Balancers, remove XML support
* remove XML support for load balancer model * added current year to license Change-Id: I3177ed60d5e10af498fe7c9e149b943ac4a418ea
This commit is contained in:
parent
c2cf462aa3
commit
201417d483
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
Copyright 2014 Rackspace
|
||||
Copyright 2014-2015 Rackspace
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -12,13 +12,16 @@ distributed under the License is distributed on an "AS IS" BASIS,
|
|||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
@summary: Load balancer request models.
|
||||
|
||||
CreateLoadBalancer
|
||||
UpdateLoadBalancer
|
||||
"""
|
||||
|
||||
import json
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from cafe.engine.models.base import AutoMarshallingModel
|
||||
from cloudcafe.networking.lbaas.common.constants import Constants
|
||||
|
||||
|
||||
class CreateLoadBalancer(AutoMarshallingModel):
|
||||
|
@ -37,17 +40,6 @@ class CreateLoadBalancer(AutoMarshallingModel):
|
|||
"admin_state_up": true
|
||||
}
|
||||
}
|
||||
|
||||
xml ex:
|
||||
<loadbalancer xmlns=""
|
||||
name="a-new-loadbalancer"
|
||||
description="A very simple example load balancer."
|
||||
vip_subnet="SUBNET_ID"
|
||||
vip_address="1.2.3.4"
|
||||
tenant_id="7725fe12-1c14-4f45-ba8e-44bf01763578"
|
||||
admin_state_up="True"
|
||||
</loadbalancer>
|
||||
|
||||
"""
|
||||
|
||||
ROOT_TAG = 'loadbalancer'
|
||||
|
@ -92,22 +84,6 @@ class CreateLoadBalancer(AutoMarshallingModel):
|
|||
main_body = {self.ROOT_TAG: body}
|
||||
return json.dumps(main_body)
|
||||
|
||||
def _obj_to_xml(self):
|
||||
xml = Constants.XML_HEADER
|
||||
element = ET.Element(self.ROOT_TAG)
|
||||
element.set('xmlns', Constants.XML_API_NAMESPACE)
|
||||
element.set('name', self.name)
|
||||
element.set('vip_subnet', self.vip_subnet)
|
||||
element.set('tenant_id', self.tenant_id)
|
||||
if self.admin_state_up is not None:
|
||||
element.set('admin_state_up', str(self.admin_state_up))
|
||||
if self.description is not None:
|
||||
element.set('description', self.description)
|
||||
if self.vip_address is not None:
|
||||
element.set('vip_address', self.vip_address)
|
||||
xml = "{0}{1}".format(xml, ET.tostring(element))
|
||||
return xml
|
||||
|
||||
|
||||
class UpdateLoadBalancer(AutoMarshallingModel):
|
||||
""" Update Load Balancer Request Model
|
||||
|
@ -122,13 +98,6 @@ class UpdateLoadBalancer(AutoMarshallingModel):
|
|||
"admin_state_up": false
|
||||
}
|
||||
}
|
||||
|
||||
xml ex:
|
||||
<loadbalancer xmlns=""
|
||||
name="an_updated-loadbalancer"
|
||||
description="A new very simple example load balancer."
|
||||
admin_state_up="False" >
|
||||
|
||||
"""
|
||||
|
||||
ROOT_TAG = CreateLoadBalancer.ROOT_TAG
|
||||
|
@ -159,16 +128,3 @@ class UpdateLoadBalancer(AutoMarshallingModel):
|
|||
body = self._remove_empty_values(body)
|
||||
main_body = {self.ROOT_TAG: body}
|
||||
return json.dumps(main_body)
|
||||
|
||||
def _obj_to_xml(self):
|
||||
xml = Constants.XML_HEADER
|
||||
element = ET.Element(self.ROOT_TAG)
|
||||
element.set('xmlns', Constants.XML_API_NAMESPACE)
|
||||
if self.name is not None:
|
||||
element.set('name', self.name)
|
||||
if self.description is not None:
|
||||
element.set('description', self.description)
|
||||
if self.admin_state_up is not None:
|
||||
element.set('admin_state_up', str(self.admin_state_up))
|
||||
xml = "{0}{1}".format(xml, ET.tostring(element))
|
||||
return xml
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
Copyright 2014 Rackspace
|
||||
Copyright 2014-2015 Rackspace
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -28,11 +28,9 @@ LoadBalancers Response Model
|
|||
"""
|
||||
|
||||
import json
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from cafe.engine.models.base import \
|
||||
AutoMarshallingModel, AutoMarshallingListModel
|
||||
from cloudcafe.networking.lbaas.common.constants import Constants
|
||||
|
||||
|
||||
class LoadBalancers(AutoMarshallingListModel):
|
||||
|
@ -55,20 +53,6 @@ class LoadBalancers(AutoMarshallingListModel):
|
|||
}
|
||||
]
|
||||
}
|
||||
|
||||
xml ex:
|
||||
<loadbalancers xmlns="">
|
||||
<loadbalancer xmlns=""
|
||||
id="8992a43f-83af-4b49-9afd-c2bfbd82d7d7"
|
||||
name="a-new-loadbalancer"
|
||||
description="A very simple example load balancer."
|
||||
vip_subnet="SUBNET_ID"
|
||||
vip_address="1.2.3.4"
|
||||
tenant_id="7725fe12-1c14-4f45-ba8e-44bf01763578"
|
||||
admin_state_up="True"
|
||||
status="ACTIVE"
|
||||
/>
|
||||
</loadbalancers>
|
||||
"""
|
||||
ROOT_TAG = 'loadbalancers'
|
||||
|
||||
|
@ -84,21 +68,6 @@ class LoadBalancers(AutoMarshallingListModel):
|
|||
for load_balancer in load_balancers_dict_list])
|
||||
return load_balancers
|
||||
|
||||
@classmethod
|
||||
def _xml_to_obj(cls, serialized_string):
|
||||
element = ET.fromstring(serialized_string)
|
||||
if element.tag != cls.ROOT_TAG:
|
||||
return None
|
||||
return cls._xml_list_to_obj(element.findall(LoadBalancer.ROOT_TAG))
|
||||
|
||||
@classmethod
|
||||
def _xml_list_to_obj(cls, xml_list):
|
||||
load_balancers = LoadBalancers()
|
||||
load_balancers.extend(
|
||||
[LoadBalancer._xml_ele_to_obj(load_balancers_ele)
|
||||
for load_balancers_ele in xml_list])
|
||||
return load_balancers
|
||||
|
||||
|
||||
class LoadBalancer(AutoMarshallingModel):
|
||||
"""LoadBalancer Response Model
|
||||
|
@ -118,18 +87,6 @@ class LoadBalancer(AutoMarshallingModel):
|
|||
"status": "ACTIVE"
|
||||
}
|
||||
}
|
||||
|
||||
xml ex:
|
||||
<loadbalancer xmlns=""
|
||||
id="8992a43f-83af-4b49-9afd-c2bfbd82d7d7"
|
||||
name="a-new-loadbalancer"
|
||||
description="A very simple example load balancer."
|
||||
vip_subnet="SUBNET_ID"
|
||||
vip_address="1.2.3.4"
|
||||
tenant_id="7725fe12-1c14-4f45-ba8e-44bf01763578"
|
||||
admin_state_up="True"
|
||||
status="ACTIVE"
|
||||
/>
|
||||
"""
|
||||
|
||||
ROOT_TAG = 'loadbalancer'
|
||||
|
@ -164,30 +121,3 @@ class LoadBalancer(AutoMarshallingModel):
|
|||
admin_state_up=load_balancer_dict.get('admin_state_up'),
|
||||
status=load_balancer_dict.get('status'))
|
||||
return load_balancer
|
||||
|
||||
@classmethod
|
||||
def _xml_to_obj(cls, serialized_string):
|
||||
element = ET.fromstring(serialized_string)
|
||||
if element.tag != cls.ROOT_TAG:
|
||||
return None
|
||||
cls._remove_xml_etree_namespace(element, Constants.XML_API_NAMESPACE)
|
||||
load_balancer = cls._xml_ele_to_obj(element)
|
||||
return load_balancer
|
||||
|
||||
@classmethod
|
||||
def _xml_ele_to_obj(cls, element):
|
||||
load_balancer_dict = element.attrib
|
||||
# Cast boolean
|
||||
if 'admin_state_up' in load_balancer_dict:
|
||||
load_balancer_dict['admin_state_up'] = cls._string_to_bool(
|
||||
load_balancer_dict.get('admin_state_up'))
|
||||
load_balancer = LoadBalancer(
|
||||
id_=load_balancer_dict.get('id'),
|
||||
name=load_balancer_dict.get('name'),
|
||||
description=load_balancer_dict.get('description'),
|
||||
vip_subnet=load_balancer_dict.get('vip_subnet'),
|
||||
vip_address=load_balancer_dict.get('vip_address'),
|
||||
tenant_id=load_balancer_dict.get('tenant_id'),
|
||||
admin_state_up=load_balancer_dict.get('admin_state_up'),
|
||||
status=load_balancer_dict.get('status'))
|
||||
return load_balancer
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
Copyright 2014 Rackspace
|
||||
Copyright 2014-2015 Rackspace
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -22,7 +22,6 @@ UpdateLoadBalancerRequestTest
|
|||
import json
|
||||
import unittest
|
||||
|
||||
from cloudcafe.networking.lbaas.common.constants import Constants
|
||||
from cloudcafe.networking.lbaas.lbaas_api.load_balancer.request import \
|
||||
CreateLoadBalancer, UpdateLoadBalancer
|
||||
|
||||
|
@ -31,7 +30,6 @@ class LoadBalancerRequestTestBase(unittest.TestCase):
|
|||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.XML_HEADER = Constants.XML_HEADER
|
||||
cls.name = "a-new-loadbalancer"
|
||||
cls.vip_subnet = "SUBNET_ID"
|
||||
cls.tenant_id = "7725fe12-1c14-4f45-ba8e-44bf01763578"
|
||||
|
@ -78,26 +76,6 @@ class CreateLoadBalancerRequestTest(LoadBalancerRequestTestBase):
|
|||
expected_json = json.loads(json.dumps(json_dict))
|
||||
self.assertEqual(expected_json, actual_json)
|
||||
|
||||
def test_create_load_balancer_xml(self):
|
||||
actual_xml = self.create_load_balancer_obj.serialize('xml')
|
||||
expected_xml = (
|
||||
'{xml_header}<{root_tag} '
|
||||
'admin_state_up="{admin_state_up}" '
|
||||
'description="{description}" '
|
||||
'name="{name}" '
|
||||
'tenant_id="{tenant_id}" '
|
||||
'vip_address="{vip_address}" '
|
||||
'vip_subnet="{vip_subnet}" '
|
||||
'xmlns="{xmlns}" />').format(
|
||||
xml_header=self.XML_HEADER,
|
||||
xmlns=Constants.XML_API_NAMESPACE,
|
||||
root_tag=self.ROOT_TAG,
|
||||
name=self.name, description=self.description,
|
||||
vip_subnet=self.vip_subnet, vip_address=self.vip_address,
|
||||
tenant_id=self.tenant_id,
|
||||
admin_state_up=str(self.admin_state_up))
|
||||
self.assertEqual(expected_xml, actual_xml)
|
||||
|
||||
|
||||
class UpdateLoadBalancerRequestTest(LoadBalancerRequestTestBase):
|
||||
|
||||
|
@ -114,20 +92,6 @@ class UpdateLoadBalancerRequestTest(LoadBalancerRequestTestBase):
|
|||
expected_json = json.loads(json.dumps(json_dict))
|
||||
self.assertEqual(expected_json, actual_json)
|
||||
|
||||
def test_update_load_balancer_xml(self):
|
||||
actual_xml = self.update_load_balancer_obj.serialize('xml')
|
||||
expected_xml = ('{xml_header}<{root_tag} '
|
||||
'admin_state_up="{admin_state_up}" '
|
||||
'description="{description}" '
|
||||
'name="{name}" '
|
||||
'xmlns="{xmlns}" />').format(
|
||||
xml_header=self.XML_HEADER,
|
||||
xmlns=Constants.XML_API_NAMESPACE,
|
||||
root_tag=self.ROOT_TAG,
|
||||
name=self.updated_name,
|
||||
description=self.updated_description,
|
||||
admin_state_up=str(self.updated_admin_state_up))
|
||||
self.assertEqual(expected_xml, actual_xml)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
Copyright 2014 Rackspace
|
||||
Copyright 2014-2015 Rackspace
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -22,7 +22,6 @@ LoadBalancersResponseTest
|
|||
|
||||
import unittest
|
||||
|
||||
from cloudcafe.networking.lbaas.common.constants import Constants
|
||||
from cloudcafe.networking.lbaas.lbaas_api.load_balancer.response \
|
||||
import LoadBalancer, LoadBalancers
|
||||
|
||||
|
@ -32,8 +31,6 @@ class BaseLoadBalancerResponseTest(unittest.TestCase):
|
|||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(BaseLoadBalancerResponseTest, cls).setUpClass()
|
||||
cls.XML_HEADER = Constants.XML_HEADER
|
||||
cls.XML_NS = Constants.XML_API_NAMESPACE
|
||||
cls.id_ = "8992a43f-83af-4b49-9afd-c2bfbd82d7d7"
|
||||
cls.name = "a-new-loadbalancer"
|
||||
cls.vip_subnet = "SUBNET_ID"
|
||||
|
@ -72,17 +69,6 @@ class BaseLoadBalancerResponseTest(unittest.TestCase):
|
|||
"status": "{status}"
|
||||
""".format(**cls.lb_attribute_kwargs)
|
||||
|
||||
cls.actual_xml_base = """
|
||||
id="{id_}"
|
||||
name="{name}"
|
||||
vip_subnet="{vip_subnet}"
|
||||
tenant_id="{tenant_id}"
|
||||
admin_state_up="{admin_state_up}"
|
||||
description="{description}"
|
||||
vip_address="{vip_address}"
|
||||
status="{status}"
|
||||
""".format(**cls.lb_attribute_kwargs)
|
||||
|
||||
|
||||
class LoadBalancerResponseTest(BaseLoadBalancerResponseTest):
|
||||
|
||||
|
@ -104,27 +90,12 @@ class LoadBalancerResponseTest(BaseLoadBalancerResponseTest):
|
|||
actual_obj = LoadBalancer.deserialize(actual_json, 'json')
|
||||
self.assertEqual(self.expected_obj, actual_obj)
|
||||
|
||||
def test_load_balancer_xml(self):
|
||||
actual_xml = """{xml_header}
|
||||
<{root_tag}
|
||||
{actual_xml_base}
|
||||
xmlns="{xmlns}"
|
||||
/>""".format(
|
||||
xml_header=self.XML_HEADER,
|
||||
xmlns=self.XML_NS,
|
||||
root_tag=self.ROOT_TAG,
|
||||
actual_xml_base=self.actual_xml_base,
|
||||
**self.lb_attribute_kwargs)
|
||||
actual_obj = LoadBalancer.deserialize(actual_xml, 'xml')
|
||||
self.assertEqual(self.expected_obj, actual_obj)
|
||||
|
||||
|
||||
class LoadBalancersResponseTest(BaseLoadBalancerResponseTest):
|
||||
|
||||
def setUp(self):
|
||||
super(LoadBalancersResponseTest, self).setUp()
|
||||
self.ROOT_TAG = LoadBalancers.ROOT_TAG
|
||||
self.CHILD_TAG = LoadBalancer.ROOT_TAG
|
||||
self.expected_obj = self.load_balancers_obj
|
||||
|
||||
def test_load_balancers_json(self):
|
||||
|
@ -140,22 +111,6 @@ class LoadBalancersResponseTest(BaseLoadBalancerResponseTest):
|
|||
actual_obj = LoadBalancers.deserialize(actual_json, 'json')
|
||||
self.assertEqual(self.expected_obj, actual_obj)
|
||||
|
||||
def test_load_balancers_xml(self):
|
||||
actual_xml = """{xml_header}
|
||||
<{root_tag} xmlns="{xmlns}">
|
||||
<{child_tag}
|
||||
{actual_xml_base}
|
||||
/>
|
||||
</{root_tag}>""".format(
|
||||
xml_header=self.XML_HEADER,
|
||||
xmlns=self.XML_NS,
|
||||
root_tag=self.ROOT_TAG,
|
||||
child_tag=self.CHILD_TAG,
|
||||
actual_xml_base=self.actual_xml_base,
|
||||
**self.lb_attribute_kwargs)
|
||||
actual_obj = LoadBalancers.deserialize(actual_xml, 'xml')
|
||||
self.assertEqual(self.expected_obj, actual_obj)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue