use neutron-lib auto allocated topology apidef

neutron-lib contains the auto allocated topology API definition. This
patch moves neutron over to lib's API def for it.

Note that we don't have any external (out-of-tree) consumers of this.

Change-Id: I01a3c99ae958bf0f57d27b4437065ba5b8de7908
This commit is contained in:
Boden R 2017-07-28 08:38:45 -06:00
parent e489c50f9c
commit e993a26292
2 changed files with 17 additions and 60 deletions

View File

@ -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)]

View File

@ -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()