diff --git a/neutron/extensions/auto_allocated_topology.py b/neutron/extensions/auto_allocated_topology.py index 15162cd0e73..215b59c9569 100644 --- a/neutron/extensions/auto_allocated_topology.py +++ b/neutron/extensions/auto_allocated_topology.py @@ -14,69 +14,25 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron_lib.api import converters +from neutron_lib.api.definitions import auto_allocated_topology from neutron_lib.api import extensions as api_extensions from neutron_lib.plugins import directory from neutron.api import extensions from neutron.api.v2 import base -RESOURCE_NAME = "auto_allocated_topology" -COLLECTION_NAME = "auto_allocated_topologies" -IS_DEFAULT = "is_default" -EXT_ALIAS = RESOURCE_NAME.replace('_', '-') -RESOURCE_ATTRIBUTE_MAP = { - COLLECTION_NAME: { - 'id': {'allow_post': False, 'allow_put': False, - 'validate': {'type:uuid': None}, - 'is_visible': True}, - 'tenant_id': {'allow_post': False, 'allow_put': False, - 'validate': {'type:uuid': None}, - 'is_visible': True}, - }, - 'networks': {IS_DEFAULT: {'allow_post': True, - 'allow_put': True, - 'default': False, - 'is_visible': True, - 'convert_to': converters.convert_to_boolean, - 'enforce_policy': True, - 'required_by_policy': True}}, -} - - -class Auto_allocated_topology(api_extensions.ExtensionDescriptor): - - @classmethod - def get_name(cls): - return "Auto Allocated Topology Services" - - @classmethod - def get_alias(cls): - return EXT_ALIAS - - @classmethod - def get_description(cls): - return "Auto Allocated Topology Services." - - @classmethod - def get_updated(cls): - return "2016-01-01T00:00:00-00:00" +class Auto_allocated_topology(api_extensions.APIExtensionDescriptor): + api_definition = auto_allocated_topology @classmethod def get_resources(cls): - params = RESOURCE_ATTRIBUTE_MAP.get(COLLECTION_NAME, dict()) - controller = base.create_resource(COLLECTION_NAME, - EXT_ALIAS, - directory.get_plugin(EXT_ALIAS), - params, allow_bulk=False) - return [extensions.ResourceExtension(EXT_ALIAS, controller)] - - def get_required_extensions(self): - return ["subnet_allocation", "external-net", "router"] - - def get_extended_resources(self, version): - if version == "2.0": - return RESOURCE_ATTRIBUTE_MAP - else: - return {} + params = auto_allocated_topology.RESOURCE_ATTRIBUTE_MAP.get( + auto_allocated_topology.COLLECTION_NAME, dict()) + controller = base.create_resource( + auto_allocated_topology.COLLECTION_NAME, + auto_allocated_topology.ALIAS, + directory.get_plugin(auto_allocated_topology.ALIAS), + params, allow_bulk=False) + return [extensions.ResourceExtension( + auto_allocated_topology.ALIAS, controller)] diff --git a/neutron/tests/tempest/api/test_auto_allocated_topology.py b/neutron/tests/tempest/api/test_auto_allocated_topology.py index 0f0de5442e9..e7ebfa0124e 100644 --- a/neutron/tests/tempest/api/test_auto_allocated_topology.py +++ b/neutron/tests/tempest/api/test_auto_allocated_topology.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.api.definitions import auto_allocated_topology from oslo_config import cfg from tempest.lib import decorators @@ -30,7 +31,7 @@ class TestAutoAllocatedTopology(base.BaseAdminNetworkTest): # all tests are added under TestAutoAllocatedTopology, # nothing bad should happen. force_tenant_isolation = True - required_extensions = ['auto-allocated-topology'] + required_extensions = [auto_allocated_topology.ALIAS] @classmethod def resource_setup(cls): @@ -84,7 +85,7 @@ class TestAutoAllocatedTopology(base.BaseAdminNetworkTest): self.assertEqual((0, 0, 0), resources_before) body = self.client.get_auto_allocated_topology() - topology = body['auto_allocated_topology'] + topology = body[auto_allocated_topology.RESOURCE_NAME] self.assertIsNotNone(topology) self._add_topology_cleanup(self.client) @@ -97,7 +98,7 @@ class TestAutoAllocatedTopology(base.BaseAdminNetworkTest): self.assertEqual((1, self.num_subnetpools, 1), resources_after1) body = self.client.get_auto_allocated_topology() - topology = body['auto_allocated_topology'] + topology = body[auto_allocated_topology.RESOURCE_NAME] network_id2 = topology['id'] resources_after2 = self._count_topology_resources() # After the initial GET, the API should be idempotent @@ -109,7 +110,7 @@ class TestAutoAllocatedTopology(base.BaseAdminNetworkTest): resources_before = self._count_topology_resources() self.assertEqual((0, 0, 0), resources_before) body = self.client.get_auto_allocated_topology() - topology = body['auto_allocated_topology'] + topology = body[auto_allocated_topology.RESOURCE_NAME] self.assertIsNotNone(topology) self.client.delete_auto_allocated_topology() resources_after = self._count_topology_resources()