diff --git a/doc/api_samples/os-attach-interfaces/attach-interfaces-create-req.json b/doc/api_samples/os-attach-interfaces/attach-interfaces-create-req.json deleted file mode 100644 index 11dcf64373a0..000000000000 --- a/doc/api_samples/os-attach-interfaces/attach-interfaces-create-req.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "interfaceAttachment": { - "port_id": "ce531f90-199f-48c0-816c-13e38010b442" - } -} diff --git a/doc/api_samples/os-attach-interfaces/attach-interfaces-create-resp.json b/doc/api_samples/os-attach-interfaces/attach-interfaces-create-resp.json deleted file mode 100644 index 309f2a1e8e58..000000000000 --- a/doc/api_samples/os-attach-interfaces/attach-interfaces-create-resp.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "interfaceAttachment": { - "fixed_ips": [{ - "ip_address": "192.168.1.1", - "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef" - }], - "mac_addr": "fa:16:3e:4c:2c:30", - "net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", - "port_id": "ce531f90-199f-48c0-816c-13e38010b442", - "port_state": "ACTIVE" - } -} diff --git a/doc/api_samples/os-attach-interfaces/attach-interfaces-list-resp.json b/doc/api_samples/os-attach-interfaces/attach-interfaces-list-resp.json deleted file mode 100644 index 2c62ef9d5da2..000000000000 --- a/doc/api_samples/os-attach-interfaces/attach-interfaces-list-resp.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "interfaceAttachments": [ - { - "port_state": "ACTIVE", - "fixed_ips": [ - { - "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef", - "ip_address": "192.168.1.3" - } - ], - "net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", - "port_id": "ce531f90-199f-48c0-816c-13e38010b442", - "mac_addr": "fa:16:3e:4c:2c:30" - } - ] -} diff --git a/doc/api_samples/os-attach-interfaces/attach-interfaces-show-resp.json b/doc/api_samples/os-attach-interfaces/attach-interfaces-show-resp.json deleted file mode 100644 index 14f5b9e1ed4c..000000000000 --- a/doc/api_samples/os-attach-interfaces/attach-interfaces-show-resp.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "interfaceAttachment": { - "port_state": "ACTIVE", - "fixed_ips": [ - { - "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef", - "ip_address": "192.168.1.3" - } - ], - "net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", - "port_id": "ce531f90-199f-48c0-816c-13e38010b442", - "mac_addr": "fa:16:3e:4c:2c:30" - } -} diff --git a/nova/tests/functional/api_samples/os-attach-interfaces/attach-interfaces-create-req.json.tpl b/nova/tests/functional/api_samples/os-attach-interfaces/attach-interfaces-create-req.json.tpl deleted file mode 100644 index 11dcf64373a0..000000000000 --- a/nova/tests/functional/api_samples/os-attach-interfaces/attach-interfaces-create-req.json.tpl +++ /dev/null @@ -1,5 +0,0 @@ -{ - "interfaceAttachment": { - "port_id": "ce531f90-199f-48c0-816c-13e38010b442" - } -} diff --git a/nova/tests/functional/api_samples/os-attach-interfaces/attach-interfaces-create-resp.json.tpl b/nova/tests/functional/api_samples/os-attach-interfaces/attach-interfaces-create-resp.json.tpl deleted file mode 100644 index d882cdc61239..000000000000 --- a/nova/tests/functional/api_samples/os-attach-interfaces/attach-interfaces-create-resp.json.tpl +++ /dev/null @@ -1,12 +0,0 @@ -{ - "interfaceAttachment": { - "fixed_ips": [{ - "subnet_id": "%(subnet_id)s", - "ip_address": "%(ip_address)s" - }], - "mac_addr": "fa:16:3e:4c:2c:30", - "net_id": "%(net_id)s", - "port_id": "%(port_id)s", - "port_state": "%(port_state)s" - } -} diff --git a/nova/tests/functional/api_samples/os-attach-interfaces/attach-interfaces-list-resp.json.tpl b/nova/tests/functional/api_samples/os-attach-interfaces/attach-interfaces-list-resp.json.tpl deleted file mode 100644 index 47dcf2dc64c0..000000000000 --- a/nova/tests/functional/api_samples/os-attach-interfaces/attach-interfaces-list-resp.json.tpl +++ /dev/null @@ -1,16 +0,0 @@ -{ - "interfaceAttachments": [ - { - "port_state": "%(port_state)s", - "fixed_ips": [ - { - "subnet_id": "%(subnet_id)s", - "ip_address": "%(ip_address)s" - } - ], - "net_id": "%(net_id)s", - "port_id": "%(port_id)s", - "mac_addr": "%(mac_addr)s" - } - ] -} diff --git a/nova/tests/functional/api_samples/os-attach-interfaces/attach-interfaces-show-resp.json.tpl b/nova/tests/functional/api_samples/os-attach-interfaces/attach-interfaces-show-resp.json.tpl deleted file mode 100644 index 3333bb49991a..000000000000 --- a/nova/tests/functional/api_samples/os-attach-interfaces/attach-interfaces-show-resp.json.tpl +++ /dev/null @@ -1,14 +0,0 @@ -{ - "interfaceAttachment": { - "port_state": "%(port_state)s", - "fixed_ips": [ - { - "subnet_id": "%(subnet_id)s", - "ip_address": "%(ip_address)s" - } - ], - "net_id": "%(net_id)s", - "port_id": "%(port_id)s", - "mac_addr": "%(mac_addr)s" - } -} diff --git a/nova/tests/functional/test_api_samples.py b/nova/tests/functional/test_api_samples.py index 154553e3148a..e871b0c1c3cb 100644 --- a/nova/tests/functional/test_api_samples.py +++ b/nova/tests/functional/test_api_samples.py @@ -42,7 +42,6 @@ from nova.compute import vm_states from nova.conductor import manager as conductor_manager from nova.console import manager as console_manager # noqa - only for cfg from nova import db -from nova import exception from nova.network import api as network_api from nova.network.neutronv2 import api as neutron_api # noqa - only for cfg from nova import objects @@ -55,7 +54,6 @@ from nova.tests.unit.api.openstack.compute.contrib import test_networks from nova.tests.unit.api.openstack.compute.contrib import test_services from nova.tests.unit.api.openstack import fakes from nova.tests.unit import fake_network -from nova.tests.unit import fake_network_cache_model from nova.tests.unit import fake_utils from nova.tests.unit.image import fake from nova import utils @@ -2192,151 +2190,6 @@ class HypervisorsCellsSampleJsonTests(ApiSampleTestBaseV2): self._verify_response('hypervisors-uptime-resp', subs, response, 200) -class AttachInterfacesSampleJsonTest(ServersSampleBase): - extension_name = ('nova.api.openstack.compute.contrib.attach_interfaces.' - 'Attach_interfaces') - - def setUp(self): - super(AttachInterfacesSampleJsonTest, self).setUp() - - def fake_list_ports(self, *args, **kwargs): - uuid = kwargs.get('device_id', None) - if not uuid: - raise exception.InstanceNotFound(instance_id=None) - port_data = { - "id": "ce531f90-199f-48c0-816c-13e38010b442", - "network_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", - "admin_state_up": True, - "status": "ACTIVE", - "mac_address": "fa:16:3e:4c:2c:30", - "fixed_ips": [ - { - "ip_address": "192.168.1.3", - "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef" - } - ], - "device_id": uuid, - } - ports = {'ports': [port_data]} - return ports - - def fake_show_port(self, context, port_id=None): - if not port_id: - raise exception.PortNotFound(port_id=None) - port_data = { - "id": port_id, - "network_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", - "admin_state_up": True, - "status": "ACTIVE", - "mac_address": "fa:16:3e:4c:2c:30", - "fixed_ips": [ - { - "ip_address": "192.168.1.3", - "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef" - } - ], - "device_id": 'bece68a3-2f8b-4e66-9092-244493d6aba7', - } - port = {'port': port_data} - return port - - def fake_attach_interface(self, context, instance, - network_id, port_id, - requested_ip='192.168.1.3'): - if not network_id: - network_id = "fake_net_uuid" - if not port_id: - port_id = "fake_port_uuid" - vif = fake_network_cache_model.new_vif() - vif['id'] = port_id - vif['network']['id'] = network_id - vif['network']['subnets'][0]['ips'][0] = requested_ip - return vif - - def fake_detach_interface(self, context, instance, port_id): - pass - - self.stubs.Set(network_api.API, 'list_ports', fake_list_ports) - self.stubs.Set(network_api.API, 'show_port', fake_show_port) - self.stubs.Set(compute_api.API, 'attach_interface', - fake_attach_interface) - self.stubs.Set(compute_api.API, 'detach_interface', - fake_detach_interface) - self.flags(auth_strategy=None, group='neutron') - self.flags(url='http://anyhost/', group='neutron') - self.flags(timeout=30, group='neutron') - - def generalize_subs(self, subs, vanilla_regexes): - subs['subnet_id'] = vanilla_regexes['uuid'] - subs['net_id'] = vanilla_regexes['uuid'] - subs['port_id'] = vanilla_regexes['uuid'] - subs['mac_addr'] = '(?:[a-f0-9]{2}:){5}[a-f0-9]{2}' - subs['ip_address'] = vanilla_regexes['ip'] - return subs - - def test_list_interfaces(self): - instance_uuid = self._post_server() - response = self._do_get('servers/%s/os-interface' % instance_uuid) - subs = { - 'ip_address': '192.168.1.3', - 'subnet_id': 'f8a6e8f8-c2ec-497c-9f23-da9616de54ef', - 'mac_addr': 'fa:16:3e:4c:2c:30', - 'net_id': '3cb9bc59-5699-4588-a4b1-b87f96708bc6', - 'port_id': 'ce531f90-199f-48c0-816c-13e38010b442', - 'port_state': 'ACTIVE' - } - self._verify_response('attach-interfaces-list-resp', subs, - response, 200) - - def _stub_show_for_instance(self, instance_uuid, port_id): - show_port = network_api.API().show_port(None, port_id) - show_port['port']['device_id'] = instance_uuid - self.stubs.Set(network_api.API, 'show_port', lambda *a, **k: show_port) - - def test_show_interfaces(self): - instance_uuid = self._post_server() - port_id = 'ce531f90-199f-48c0-816c-13e38010b442' - self._stub_show_for_instance(instance_uuid, port_id) - response = self._do_get('servers/%s/os-interface/%s' % - (instance_uuid, port_id)) - subs = { - 'ip_address': '192.168.1.3', - 'subnet_id': 'f8a6e8f8-c2ec-497c-9f23-da9616de54ef', - 'mac_addr': 'fa:16:3e:4c:2c:30', - 'net_id': '3cb9bc59-5699-4588-a4b1-b87f96708bc6', - 'port_id': port_id, - 'port_state': 'ACTIVE' - } - self._verify_response('attach-interfaces-show-resp', subs, - response, 200) - - def test_create_interfaces(self, instance_uuid=None): - if instance_uuid is None: - instance_uuid = self._post_server() - subs = { - 'net_id': '3cb9bc59-5699-4588-a4b1-b87f96708bc6', - 'port_id': 'ce531f90-199f-48c0-816c-13e38010b442', - 'subnet_id': 'f8a6e8f8-c2ec-497c-9f23-da9616de54ef', - 'ip_address': '192.168.1.3', - 'port_state': 'ACTIVE', - 'mac_addr': 'fa:16:3e:4c:2c:30', - } - self._stub_show_for_instance(instance_uuid, subs['port_id']) - response = self._do_post('servers/%s/os-interface' % instance_uuid, - 'attach-interfaces-create-req', subs) - subs.update(self._get_regexes()) - self._verify_response('attach-interfaces-create-resp', subs, - response, 200) - - def test_delete_interfaces(self): - instance_uuid = self._post_server() - port_id = 'ce531f90-199f-48c0-816c-13e38010b442' - response = self._do_delete('servers/%s/os-interface/%s' % - (instance_uuid, port_id)) - self.assertEqual(response.status_code, 202) - self.assertEqual(response.content, '') - - class AssistedVolumeSnapshotsJsonTest(ApiSampleTestBaseV2): """Assisted volume snapshots.""" extension_name = ("nova.api.openstack.compute.contrib." diff --git a/nova/tests/functional/v3/test_attach_interfaces.py b/nova/tests/functional/v3/test_attach_interfaces.py index b903bc5cd0a0..15a00bd4d671 100644 --- a/nova/tests/functional/v3/test_attach_interfaces.py +++ b/nova/tests/functional/v3/test_attach_interfaces.py @@ -13,15 +13,34 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_config import cfg + from nova.compute import api as compute_api from nova import exception from nova.network import api as network_api from nova.tests.functional.v3 import test_servers from nova.tests.unit import fake_network_cache_model +CONF = cfg.CONF +CONF.import_opt('osapi_compute_extension', + 'nova.api.openstack.compute.extensions') + class AttachInterfacesSampleJsonTest(test_servers.ServersSampleBase): extension_name = 'os-attach-interfaces' + # TODO(gmann): Overriding '_api_version' till all functional tests + # are merged between v2 and v2.1. After that base class variable + # itself can be changed to 'v2' + _api_version = 'v2' + extra_extensions_to_load = ["os-access-ips"] + + def _get_flags(self): + f = super(AttachInterfacesSampleJsonTest, self)._get_flags() + f['osapi_compute_extension'] = CONF.osapi_compute_extension[:] + f['osapi_compute_extension'].append( + 'nova.api.openstack.compute.contrib.' + 'attach_interfaces.Attach_interfaces') + return f def setUp(self): super(AttachInterfacesSampleJsonTest, self).setUp()