Merge "API tests: Check MTU sanity of trunk/subport"
diff --git a/neutron/tests/tempest/api/admin/test_networks.py b/neutron/tests/tempest/api/admin/test_networks.py
new file mode 100644
index 0000000..1068c0b
--- /dev/null
+++ b/neutron/tests/tempest/api/admin/test_networks.py
@@ -0,0 +1,70 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# 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.
+
+from oslo_utils import uuidutils
+from tempest.lib import exceptions as lib_exc
+from tempest import test
+
+from neutron.tests.tempest.api import base
+
+
+class NetworksTestAdmin(base.BaseAdminNetworkTest):
+
+ @test.idempotent_id('d3c76044-d067-4cb0-ae47-8cdd875c7f67')
+ @test.requires_ext(extension="project-id", service="network")
+ def test_admin_create_network_keystone_v3(self):
+ project_id = self.client.tenant_id # non-admin
+
+ name = 'admin-created-with-project_id'
+ new_net = self.create_network_keystone_v3(name, project_id,
+ client=self.admin_client)
+ self.assertEqual(name, new_net['name'])
+ self.assertEqual(project_id, new_net['project_id'])
+ self.assertEqual(project_id, new_net['tenant_id'])
+
+ body = self.client.list_networks(id=new_net['id'])
+ lookup_net = body['networks'][0]
+ self.assertEqual(name, lookup_net['name'])
+ self.assertEqual(project_id, lookup_net['project_id'])
+ self.assertEqual(project_id, lookup_net['tenant_id'])
+
+ @test.idempotent_id('8d21aaca-4364-4eb9-8b79-44b4fff6373b')
+ @test.requires_ext(extension="project-id", service="network")
+ def test_admin_create_network_keystone_v3_and_tenant(self):
+ project_id = self.client.tenant_id # non-admin
+
+ name = 'created-with-project-and-tenant'
+ new_net = self.create_network_keystone_v3(
+ name, project_id, tenant_id=project_id, client=self.admin_client)
+ self.assertEqual(name, new_net['name'])
+ self.assertEqual(project_id, new_net['project_id'])
+ self.assertEqual(project_id, new_net['tenant_id'])
+
+ body = self.client.list_networks(id=new_net['id'])
+ lookup_net = body['networks'][0]
+ self.assertEqual(name, lookup_net['name'])
+ self.assertEqual(project_id, lookup_net['project_id'])
+ self.assertEqual(project_id, lookup_net['tenant_id'])
+
+ @test.idempotent_id('08b92179-669d-45ee-8233-ef6611190809')
+ @test.requires_ext(extension="project-id", service="network")
+ def test_admin_create_network_keystone_v3_and_other_tenant(self):
+ project_id = self.client.tenant_id # non-admin
+ other_tenant = uuidutils.generate_uuid()
+
+ name = 'created-with-project-and-other-tenant'
+ e = self.assertRaises(lib_exc.BadRequest,
+ self.create_network_keystone_v3, name,
+ project_id, tenant_id=other_tenant,
+ client=self.admin_client)
+ expected_message = "'project_id' and 'tenant_id' do not match"
+ self.assertEqual(expected_message, e.resp_body['message'])
diff --git a/neutron/tests/tempest/api/admin/test_quotas_negative.py b/neutron/tests/tempest/api/admin/test_quotas_negative.py
index 12ae0be..3ff49c6 100644
--- a/neutron/tests/tempest/api/admin/test_quotas_negative.py
+++ b/neutron/tests/tempest/api/admin/test_quotas_negative.py
@@ -71,6 +71,7 @@
subnet_args = {'tenant_id': tenant_id,
'network_id': net['id'],
+ 'enable_dhcp': False,
'cidr': '10.0.0.0/24',
'ip_version': '4'}
subnet = self.admin_client.create_subnet(**subnet_args)['subnet']
diff --git a/neutron/tests/tempest/api/base.py b/neutron/tests/tempest/api/base.py
index 045cca2..39c714c 100644
--- a/neutron/tests/tempest/api/base.py
+++ b/neutron/tests/tempest/api/base.py
@@ -93,7 +93,7 @@
super(BaseNetworkTest, cls).resource_setup()
cls.networks = []
- cls.shared_networks = []
+ cls.admin_networks = []
cls.subnets = []
cls.ports = []
cls.routers = []
@@ -162,8 +162,8 @@
cls._try_delete_resource(cls.client.delete_network,
network['id'])
- # Clean up shared networks
- for network in cls.shared_networks:
+ # Clean up admin networks
+ for network in cls.admin_networks:
cls._try_delete_resource(cls.admin_client.delete_network,
network['id'])
@@ -222,7 +222,24 @@
post_body.update({'name': network_name, 'shared': True})
body = cls.admin_client.create_network(**post_body)
network = body['network']
- cls.shared_networks.append(network)
+ cls.admin_networks.append(network)
+ return network
+
+ @classmethod
+ def create_network_keystone_v3(cls, network_name=None, project_id=None,
+ tenant_id=None, client=None):
+ """Wrapper utility that creates a test network with project_id."""
+ client = client or cls.client
+ network_name = network_name or data_utils.rand_name(
+ 'test-network-with-project_id')
+ project_id = cls.client.tenant_id
+ body = client.create_network_keystone_v3(network_name, project_id,
+ tenant_id)
+ network = body['network']
+ if client is cls.client:
+ cls.networks.append(network)
+ else:
+ cls.admin_networks.append(network)
return network
@classmethod
@@ -728,3 +745,12 @@
# marker
expected_resources[:-1],
self._extract_resources(body))
+
+ def _test_list_validation_filters(self):
+ validation_args = {
+ 'unknown_filter': 'value',
+ }
+ body = self.list_method(**validation_args)
+ resources = self._extract_resources(body)
+ for resource in resources:
+ self.assertIn(resource['name'], self.resource_names)
diff --git a/neutron/tests/tempest/api/test_floating_ips.py b/neutron/tests/tempest/api/test_floating_ips.py
index 8ccdd44..bafa54c 100644
--- a/neutron/tests/tempest/api/test_floating_ips.py
+++ b/neutron/tests/tempest/api/test_floating_ips.py
@@ -71,3 +71,33 @@
self.assertEqual('d2', body['floatingip']['description'])
body = self.client.show_floatingip(body['floatingip']['id'])
self.assertEqual('d2', body['floatingip']['description'])
+ # disassociate
+ body = self.client.update_floatingip(body['floatingip']['id'],
+ port_id=None)
+ self.assertEqual('d2', body['floatingip']['description'])
+
+ @test.idempotent_id('fd7161e1-2167-4686-a6ff-0f3df08001bb')
+ @test.requires_ext(extension="standard-attr-description",
+ service="network")
+ def test_floatingip_update_extra_attributes_port_id_not_changed(self):
+ port_id = self.ports[1]['id']
+ body = self.client.create_floatingip(
+ floating_network_id=self.ext_net_id,
+ port_id=port_id,
+ description='d1'
+ )['floatingip']
+ self.assertEqual('d1', body['description'])
+ body = self.client.show_floatingip(body['id'])['floatingip']
+ self.assertEqual(port_id, body['port_id'])
+ # Update description
+ body = self.client.update_floatingip(body['id'], description='d2')
+ self.assertEqual('d2', body['floatingip']['description'])
+ # Floating IP association is not changed.
+ self.assertEqual(port_id, body['floatingip']['port_id'])
+ body = self.client.show_floatingip(body['floatingip']['id'])
+ self.assertEqual('d2', body['floatingip']['description'])
+ self.assertEqual(port_id, body['floatingip']['port_id'])
+ # disassociate
+ body = self.client.update_floatingip(body['floatingip']['id'],
+ port_id=None)
+ self.assertEqual(None, body['floatingip']['port_id'])
diff --git a/neutron/tests/tempest/api/test_networks.py b/neutron/tests/tempest/api/test_networks.py
index a6d8262..279964a 100644
--- a/neutron/tests/tempest/api/test_networks.py
+++ b/neutron/tests/tempest/api/test_networks.py
@@ -106,8 +106,7 @@
project_id = self.client.tenant_id
name = 'created-with-project_id'
- body = self.client.create_network_keystone_v3(name, project_id)
- new_net = body['network']
+ new_net = self.create_network_keystone_v3(name, project_id)
self.assertEqual(name, new_net['name'])
self.assertEqual(project_id, new_net['project_id'])
self.assertEqual(project_id, new_net['tenant_id'])
@@ -202,3 +201,7 @@
@test.idempotent_id('f1867fc5-e1d6-431f-bc9f-8b882e43a7f9')
def test_list_no_pagination_limit_0(self):
self._test_list_no_pagination_limit_0()
+
+ @test.idempotent_id('3574ec9b-a8b8-43e3-9c11-98f5875df6a9')
+ def test_list_validation_filters(self):
+ self._test_list_validation_filters()
diff --git a/neutron/tests/tempest/api/test_ports.py b/neutron/tests/tempest/api/test_ports.py
index 916f549..093de07 100644
--- a/neutron/tests/tempest/api/test_ports.py
+++ b/neutron/tests/tempest/api/test_ports.py
@@ -47,6 +47,18 @@
self.client.update_subnet(s['id'], enable_dhcp=True)
self.create_port(self.network)
+ @test.idempotent_id('1d6d8683-8691-43c6-a7ba-c69723258726')
+ def test_add_ips_to_port(self):
+ s = self.create_subnet(self.network)
+ port = self.create_port(self.network)
+ # request another IP on the same subnet
+ port['fixed_ips'].append({'subnet_id': s['id']})
+ updated = self.client.update_port(port['id'],
+ fixed_ips=port['fixed_ips'])
+ subnets = [ip['subnet_id'] for ip in updated['port']['fixed_ips']]
+ expected = [s['id'], s['id']]
+ self.assertEqual(expected, subnets)
+
class PortsSearchCriteriaTest(base.BaseSearchCriteriaTest):
diff --git a/neutron/tests/tempest/api/test_revisions.py b/neutron/tests/tempest/api/test_revisions.py
index b45990f..10438b7 100644
--- a/neutron/tests/tempest/api/test_revisions.py
+++ b/neutron/tests/tempest/api/test_revisions.py
@@ -20,7 +20,7 @@
class TestRevisions(base.BaseAdminNetworkTest, bsg.BaseSecGroupTest):
@classmethod
- @test.requires_ext(extension="revisions", service="network")
+ @test.requires_ext(extension="standard-attr-revisions", service="network")
def skip_checks(cls):
super(TestRevisions, cls).skip_checks()
@@ -153,3 +153,5 @@
b2 = self.client.update_floatingip(body['id'], description='d2')
self.assertGreater(b2['floatingip']['revision_number'],
body['revision_number'])
+ # disassociate
+ self.client.update_floatingip(b2['floatingip']['id'], port_id=None)
diff --git a/neutron/tests/tempest/api/test_subnetpools.py b/neutron/tests/tempest/api/test_subnetpools.py
index 5bd222f..e8ec954 100644
--- a/neutron/tests/tempest/api/test_subnetpools.py
+++ b/neutron/tests/tempest/api/test_subnetpools.py
@@ -110,13 +110,15 @@
body = self._create_subnetpool(description='d1')
self.assertEqual('d1', body['description'])
sub_id = body['id']
- body = filter(lambda x: x['id'] == sub_id,
- self.client.list_subnetpools()['subnetpools'])[0]
+ subnet_pools = [x for x in
+ self.client.list_subnetpools()['subnetpools'] if x['id'] == sub_id]
+ body = subnet_pools[0]
self.assertEqual('d1', body['description'])
body = self.client.update_subnetpool(sub_id, description='d2')
self.assertEqual('d2', body['subnetpool']['description'])
- body = filter(lambda x: x['id'] == sub_id,
- self.client.list_subnetpools()['subnetpools'])[0]
+ subnet_pools = [x for x in
+ self.client.list_subnetpools()['subnetpools'] if x['id'] == sub_id]
+ body = subnet_pools[0]
self.assertEqual('d2', body['description'])
@test.idempotent_id('741d08c2-1e3f-42be-99c7-0ea93c5b728c')
@@ -390,3 +392,7 @@
@test.idempotent_id('82a13efc-c18f-4249-b8ec-cec7cf26fbd6')
def test_list_no_pagination_limit_0(self):
self._test_list_no_pagination_limit_0()
+
+ @test.idempotent_id('27feb3f8-40f4-4e50-8cd2-7d0096a98682')
+ def test_list_validation_filters(self):
+ self._test_list_validation_filters()
diff --git a/neutron/tests/tempest/api/test_subnets.py b/neutron/tests/tempest/api/test_subnets.py
index a3a2e00..4e63a3a 100644
--- a/neutron/tests/tempest/api/test_subnets.py
+++ b/neutron/tests/tempest/api/test_subnets.py
@@ -63,3 +63,7 @@
@test.idempotent_id('d851937c-9821-4b46-9d18-43e9077ecac0')
def test_list_no_pagination_limit_0(self):
self._test_list_no_pagination_limit_0()
+
+ @test.idempotent_id('c0f9280b-9d81-4728-a967-6be22659d4c8')
+ def test_list_validation_filters(self):
+ self._test_list_validation_filters()
diff --git a/neutron/tests/tempest/api/test_timestamp.py b/neutron/tests/tempest/api/test_timestamp.py
index 290e162..d3a2361 100644
--- a/neutron/tests/tempest/api/test_timestamp.py
+++ b/neutron/tests/tempest/api/test_timestamp.py
@@ -34,7 +34,7 @@
larger_prefix = '10.11.0.0/16'
@classmethod
- @test.requires_ext(extension="timestamp_core", service="network")
+ @test.requires_ext(extension="standard-attr-timestamp", service="network")
def skip_checks(cls):
super(TestTimeStamp, cls).skip_checks()
@@ -186,8 +186,9 @@
def skip_checks(cls):
super(TestTimeStampWithL3, cls).skip_checks()
- if not test.is_extension_enabled('timestamp_ext', 'network'):
- raise cls.skipException("timestamp_ext extension not enabled")
+ if not test.is_extension_enabled('standard-attr-timestamp', 'network'):
+ raise cls.skipException("standard-attr-timestamp extension not "
+ "enabled")
@classmethod
def resource_setup(cls):
@@ -260,8 +261,9 @@
def skip_checks(cls):
super(TestTimeStampWithSecurityGroup, cls).skip_checks()
- if not test.is_extension_enabled('timestamp_ext', 'network'):
- raise cls.skipException("timestamp_ext extension not enabled")
+ if not test.is_extension_enabled('standard-attr-timestamp', 'network'):
+ raise cls.skipException("standard-attr-timestamp extension not "
+ "enabled")
@classmethod
def resource_setup(cls):
diff --git a/neutron/tests/tempest/scenario/test_trunk.py b/neutron/tests/tempest/scenario/test_trunk.py
new file mode 100644
index 0000000..30d6022
--- /dev/null
+++ b/neutron/tests/tempest/scenario/test_trunk.py
@@ -0,0 +1,160 @@
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# 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.
+
+from oslo_log import log as logging
+from tempest.common import waiters
+from tempest import test
+
+from neutron.common import utils
+from neutron.tests.tempest import config
+from neutron.tests.tempest.scenario import base
+from neutron.tests.tempest.scenario import constants
+
+CONF = config.CONF
+LOG = logging.getLogger(__name__)
+
+
+class TrunkTest(base.BaseTempestTestCase):
+ credentials = ['primary']
+ force_tenant_isolation = False
+
+ @classmethod
+ @test.requires_ext(extension="trunk", service="network")
+ def resource_setup(cls):
+ super(TrunkTest, cls).resource_setup()
+ # setup basic topology for servers we can log into
+ cls.network = cls.create_network()
+ cls.subnet = cls.create_subnet(cls.network)
+ cls.create_router_and_interface(cls.subnet['id'])
+ cls.keypair = cls.create_keypair()
+ cls.create_loginable_secgroup_rule()
+
+ def _create_server_with_trunk_port(self):
+ port = self.create_port(self.network)
+ trunk = self.client.create_trunk(port['id'], subports=[])['trunk']
+ fip = self.create_and_associate_floatingip(port['id'])
+ server = self.create_server(
+ flavor_ref=CONF.compute.flavor_ref,
+ image_ref=CONF.compute.image_ref,
+ key_name=self.keypair['name'],
+ networks=[{'port': port['id']}])['server']
+ self.addCleanup(self._detach_and_delete_trunk, server, trunk)
+ return {'port': port, 'trunk': trunk, 'fip': fip,
+ 'server': server}
+
+ def _detach_and_delete_trunk(self, server, trunk):
+ # we have to detach the interface from the server before
+ # the trunk can be deleted.
+ self.manager.compute.InterfacesClient().delete_interface(
+ server['id'], trunk['port_id'])
+
+ def is_port_detached():
+ p = self.client.show_port(trunk['port_id'])['port']
+ return p['device_id'] == ''
+ utils.wait_until_true(is_port_detached)
+ self.client.delete_trunk(trunk['id'])
+
+ def _is_port_down(self, port_id):
+ p = self.client.show_port(port_id)['port']
+ return p['status'] == 'DOWN'
+
+ def _is_port_active(self, port_id):
+ p = self.client.show_port(port_id)['port']
+ return p['status'] == 'ACTIVE'
+
+ def _is_trunk_active(self, trunk_id):
+ t = self.client.show_trunk(trunk_id)['trunk']
+ return t['status'] == 'ACTIVE'
+
+ @test.idempotent_id('bb13fe28-f152-4000-8131-37890a40c79e')
+ def test_trunk_subport_lifecycle(self):
+ """Test trunk creation and subport transition to ACTIVE status.
+
+ This is a basic test for the trunk extension to ensure that we
+ can create a trunk, attach it to a server, add/remove subports,
+ while ensuring the status transitions as appropriate.
+
+ This test does not assert any dataplane behavior for the subports.
+ It's just a high-level check to ensure the agents claim to have
+ wired the port correctly and that the trunk port itself maintains
+ connectivity.
+ """
+ server1 = self._create_server_with_trunk_port()
+ server2 = self._create_server_with_trunk_port()
+ for server in (server1, server2):
+ waiters.wait_for_server_status(self.manager.servers_client,
+ server['server']['id'],
+ constants.SERVER_STATUS_ACTIVE)
+ self.check_connectivity(server['fip']['floating_ip_address'],
+ CONF.validation.image_ssh_user,
+ self.keypair['private_key'])
+ trunk1_id, trunk2_id = server1['trunk']['id'], server2['trunk']['id']
+ # trunks should transition to ACTIVE without any subports
+ utils.wait_until_true(
+ lambda: self._is_trunk_active(trunk1_id),
+ exception=RuntimeError("Timed out waiting for trunk %s to "
+ "transition to ACTIVE." % trunk1_id))
+ utils.wait_until_true(
+ lambda: self._is_trunk_active(trunk2_id),
+ exception=RuntimeError("Timed out waiting for trunk %s to "
+ "transition to ACTIVE." % trunk2_id))
+ # create a few more networks and ports for subports
+ subports = [{'port_id': self.create_port(self.create_network())['id'],
+ 'segmentation_type': 'vlan', 'segmentation_id': seg_id}
+ for seg_id in range(3, 7)]
+ # add all subports to server1
+ self.client.add_subports(trunk1_id, subports)
+ # ensure trunk transitions to ACTIVE
+ utils.wait_until_true(
+ lambda: self._is_trunk_active(trunk1_id),
+ exception=RuntimeError("Timed out waiting for trunk %s to "
+ "transition to ACTIVE." % trunk1_id))
+ # ensure all underlying subports transitioned to ACTIVE
+ for s in subports:
+ utils.wait_until_true(lambda: self._is_port_active(s['port_id']))
+ # ensure main dataplane wasn't interrupted
+ self.check_connectivity(server1['fip']['floating_ip_address'],
+ CONF.validation.image_ssh_user,
+ self.keypair['private_key'])
+ # move subports over to other server
+ self.client.remove_subports(trunk1_id, subports)
+ # ensure all subports go down
+ for s in subports:
+ utils.wait_until_true(
+ lambda: self._is_port_down(s['port_id']),
+ exception=RuntimeError("Timed out waiting for subport %s to "
+ "transition to DOWN." % s['port_id']))
+ self.client.add_subports(trunk2_id, subports)
+ # wait for both trunks to go back to ACTIVE
+ utils.wait_until_true(
+ lambda: self._is_trunk_active(trunk1_id),
+ exception=RuntimeError("Timed out waiting for trunk %s to "
+ "transition to ACTIVE." % trunk1_id))
+ utils.wait_until_true(
+ lambda: self._is_trunk_active(trunk2_id),
+ exception=RuntimeError("Timed out waiting for trunk %s to "
+ "transition to ACTIVE." % trunk2_id))
+ # ensure subports come up on other trunk
+ for s in subports:
+ utils.wait_until_true(
+ lambda: self._is_port_active(s['port_id']),
+ exception=RuntimeError("Timed out waiting for subport %s to "
+ "transition to ACTIVE." % s['port_id']))
+ # final connectivity check
+ self.check_connectivity(server1['fip']['floating_ip_address'],
+ CONF.validation.image_ssh_user,
+ self.keypair['private_key'])
+ self.check_connectivity(server2['fip']['floating_ip_address'],
+ CONF.validation.image_ssh_user,
+ self.keypair['private_key'])
diff --git a/neutron/tests/tempest/services/network/json/network_client.py b/neutron/tests/tempest/services/network/json/network_client.py
index 4828059..3b1a9a8 100644
--- a/neutron/tests/tempest/services/network/json/network_client.py
+++ b/neutron/tests/tempest/services/network/json/network_client.py
@@ -872,7 +872,7 @@
body = jsonutils.loads(body)
return service_client.ResponseBody(resp, body)
- def create_network_keystone_v3(self, name, project_id):
+ def create_network_keystone_v3(self, name, project_id, tenant_id=None):
uri = '%s/networks' % self.uri_prefix
post_data = {
'network': {
@@ -880,6 +880,8 @@
'project_id': project_id
}
}
+ if tenant_id is not None:
+ post_data['network']['tenant_id'] = tenant_id
resp, body = self.post(uri, self.serialize(post_data))
body = self.deserialize_single(body)
self.expected_success(201, resp.status)