Merge "Remove hyphen from rand_name calls in identity tests"
diff --git a/etc/tempest.conf.sample b/etc/tempest.conf.sample
index 2e57007..f5e0cf8 100644
--- a/etc/tempest.conf.sample
+++ b/etc/tempest.conf.sample
@@ -302,9 +302,11 @@
# value)
#ssh_channel_timeout = 60
-# Name of the fixed network that is visible to all test tenants.
-# (string value)
-#fixed_network_name = private
+# Name of the fixed network that is visible to all test tenants. If
+# multiple networks are available for a tenant this is the network
+# which will be used for creating servers if tempest does not create a
+# network or a network is not specified elsewhere (string value)
+#fixed_network_name = <None>
# Network used for SSH connections. Ignored if
# use_floatingip_for_ssh=true or run_ssh=false. (string value)
diff --git a/tempest/api/compute/admin/test_networks.py b/tempest/api/compute/admin/test_networks.py
index c20d483..477dc61 100644
--- a/tempest/api/compute/admin/test_networks.py
+++ b/tempest/api/compute/admin/test_networks.py
@@ -37,12 +37,15 @@
@test.idempotent_id('d206d211-8912-486f-86e2-a9d090d1f416')
def test_get_network(self):
networks = self.client.list_networks()
- configured_network = [x for x in networks if x['label'] ==
- CONF.compute.fixed_network_name]
- self.assertEqual(1, len(configured_network),
- "{0} networks with label {1}".format(
- len(configured_network),
- CONF.compute.fixed_network_name))
+ if CONF.compute.fixed_network_name:
+ configured_network = [x for x in networks if x['label'] ==
+ CONF.compute.fixed_network_name]
+ self.assertEqual(1, len(configured_network),
+ "{0} networks with label {1}".format(
+ len(configured_network),
+ CONF.compute.fixed_network_name))
+ else:
+ configured_network = networks
configured_network = configured_network[0]
network = self.client.get_network(configured_network['id'])
self.assertEqual(configured_network['label'], network['label'])
@@ -51,5 +54,9 @@
def test_list_all_networks(self):
networks = self.client.list_networks()
# Check the configured network is in the list
- configured_network = CONF.compute.fixed_network_name
- self.assertIn(configured_network, [x['label'] for x in networks])
+ if CONF.compute.fixed_network_name:
+ configured_network = CONF.compute.fixed_network_name
+ self.assertIn(configured_network, [x['label'] for x in networks])
+ else:
+ network_name = map(lambda x: x['label'], networks)
+ self.assertGreaterEqual(len(network_name), 1)
diff --git a/tempest/api/compute/admin/test_servers.py b/tempest/api/compute/admin/test_servers.py
index c872184..ef3a029 100644
--- a/tempest/api/compute/admin/test_servers.py
+++ b/tempest/api/compute/admin/test_servers.py
@@ -16,6 +16,7 @@
from tempest_lib import decorators
from tempest.api.compute import base
+from tempest.common import fixed_network
from tempest import test
@@ -112,7 +113,10 @@
name = data_utils.rand_name('server')
flavor = self.flavor_ref
image_id = self.image_ref
- test_server = self.client.create_server(name, image_id, flavor)
+ network = self.get_tenant_network()
+ network_kwargs = fixed_network.set_networks_kwarg(network)
+ test_server = self.client.create_server(name, image_id, flavor,
+ **network_kwargs)
self.addCleanup(self.client.delete_server, test_server['id'])
self.client.wait_for_server_status(test_server['id'], 'ACTIVE')
server = self.client.get_server(test_server['id'])
diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py
index 05bc9f8..4995209 100644
--- a/tempest/api/compute/base.py
+++ b/tempest/api/compute/base.py
@@ -22,6 +22,7 @@
from tempest import clients
from tempest.common import credentials
+from tempest.common import fixed_network
from tempest import config
from tempest import exceptions
import tempest.test
@@ -212,6 +213,8 @@
flavor = kwargs.get('flavor', cls.flavor_ref)
image_id = kwargs.get('image_id', cls.image_ref)
+ kwargs = fixed_network.set_networks_kwarg(
+ cls.get_tenant_network(), kwargs) or {}
body = cls.servers_client.create_server(
name, image_id, flavor, **kwargs)
diff --git a/tempest/api/compute/servers/test_attach_interfaces.py b/tempest/api/compute/servers/test_attach_interfaces.py
index 0702f3f..42a61da 100644
--- a/tempest/api/compute/servers/test_attach_interfaces.py
+++ b/tempest/api/compute/servers/test_attach_interfaces.py
@@ -13,13 +13,15 @@
# License for the specific language governing permissions and limitations
# under the License.
+import time
+
+from tempest_lib import exceptions as lib_exc
+
from tempest.api.compute import base
from tempest import config
from tempest import exceptions
from tempest import test
-import time
-
CONF = config.CONF
@@ -125,8 +127,15 @@
self.assertTrue(interface_count > 0)
self._check_interface(ifs[0])
- iface = self._test_create_interface(server)
- ifs.append(iface)
+ try:
+ iface = self._test_create_interface(server)
+ except lib_exc.BadRequest as e:
+ msg = ('Multiple possible networks found, use a Network ID to be '
+ 'more specific.')
+ if not CONF.compute.fixed_network_name and e.message == msg:
+ raise
+ else:
+ ifs.append(iface)
iface = self._test_create_interface_by_network_id(server, ifs)
ifs.append(iface)
diff --git a/tempest/api/compute/servers/test_list_server_filters.py b/tempest/api/compute/servers/test_list_server_filters.py
index 5c10f30..f33204d 100644
--- a/tempest/api/compute/servers/test_list_server_filters.py
+++ b/tempest/api/compute/servers/test_list_server_filters.py
@@ -19,6 +19,7 @@
from tempest.api.compute import base
from tempest.api import utils
+from tempest.common import fixed_network
from tempest import config
from tempest import test
@@ -66,9 +67,16 @@
raise RuntimeError("Image %s (image_ref_alt) was not found!" %
cls.image_ref_alt)
+ network = cls.get_tenant_network()
+ if network:
+ cls.fixed_network_name = network['name']
+ else:
+ cls.fixed_network_name = None
+ network_kwargs = fixed_network.set_networks_kwarg(network)
cls.s1_name = data_utils.rand_name(cls.__name__ + '-instance')
cls.s1 = cls.create_test_server(name=cls.s1_name,
- wait_until='ACTIVE')
+ wait_until='ACTIVE',
+ **network_kwargs)
cls.s2_name = data_utils.rand_name(cls.__name__ + '-instance')
cls.s2 = cls.create_test_server(name=cls.s2_name,
@@ -80,12 +88,6 @@
flavor=cls.flavor_ref_alt,
wait_until='ACTIVE')
- cls.fixed_network_name = CONF.compute.fixed_network_name
- if CONF.service_available.neutron:
- if hasattr(cls.isolated_creds, 'get_primary_network'):
- network = cls.isolated_creds.get_primary_network()
- cls.fixed_network_name = network['name']
-
@test.idempotent_id('05e8a8e7-9659-459a-989d-92c2f501f4ba')
@utils.skip_unless_attr('multiple_images', 'Only one image found')
@test.attr(type='gate')
@@ -284,6 +286,9 @@
def test_list_servers_filtered_by_ip(self):
# Filter servers by ip
# Here should be listed 1 server
+ if not self.fixed_network_name:
+ msg = 'fixed_network_name needs to be configured to run this test'
+ raise self.skipException(msg)
self.s1 = self.client.get_server(self.s1['id'])
ip = self.s1['addresses'][self.fixed_network_name][0]['addr']
params = {'ip': ip}
@@ -302,6 +307,9 @@
# Filter servers by regex ip
# List all servers filtered by part of ip address.
# Here should be listed all servers
+ if not self.fixed_network_name:
+ msg = 'fixed_network_name needs to be configured to run this test'
+ raise self.skipException(msg)
self.s1 = self.client.get_server(self.s1['id'])
ip = self.s1['addresses'][self.fixed_network_name][0]['addr'][0:-3]
params = {'ip': ip}
diff --git a/tempest/api/identity/base.py b/tempest/api/identity/base.py
index e171a02..b83da3e 100644
--- a/tempest/api/identity/base.py
+++ b/tempest/api/identity/base.py
@@ -19,6 +19,7 @@
from tempest import clients
from tempest.common import cred_provider
+from tempest.common import credentials
from tempest import config
import tempest.test
@@ -26,13 +27,7 @@
LOG = logging.getLogger(__name__)
-class BaseIdentityAdminTest(tempest.test.BaseTestCase):
-
- @classmethod
- def setup_credentials(cls):
- super(BaseIdentityAdminTest, cls).setup_credentials()
- cls.os = cls.get_client_manager()
- cls.os_adm = clients.Manager(cls.isolated_creds.get_admin_creds())
+class BaseIdentityTest(tempest.test.BaseTestCase):
@classmethod
def disable_user(cls, user_name):
@@ -69,24 +64,55 @@
return role[0]
-class BaseIdentityV2AdminTest(BaseIdentityAdminTest):
+class BaseIdentityV2Test(BaseIdentityTest):
+
+ @classmethod
+ def setup_credentials(cls):
+ super(BaseIdentityV2Test, cls).setup_credentials()
+ cls.os = cls.get_client_manager(identity_version='v2')
@classmethod
def skip_checks(cls):
- super(BaseIdentityV2AdminTest, cls).skip_checks()
+ super(BaseIdentityV2Test, cls).skip_checks()
if not CONF.identity_feature_enabled.api_v2:
raise cls.skipException("Identity api v2 is not enabled")
@classmethod
def setup_clients(cls):
+ super(BaseIdentityV2Test, cls).setup_clients()
+ cls.non_admin_client = cls.os.identity_client
+ cls.non_admin_token_client = cls.os.token_client
+
+ @classmethod
+ def resource_setup(cls):
+ super(BaseIdentityV2Test, cls).resource_setup()
+
+ @classmethod
+ def resource_cleanup(cls):
+ super(BaseIdentityV2Test, cls).resource_cleanup()
+
+
+class BaseIdentityV2AdminTest(BaseIdentityV2Test):
+
+ @classmethod
+ def setup_credentials(cls):
+ super(BaseIdentityV2AdminTest, cls).setup_credentials()
+ cls.os_adm = clients.Manager(cls.isolated_creds.get_admin_creds())
+
+ @classmethod
+ def skip_checks(cls):
+ if not credentials.is_admin_available():
+ raise cls.skipException('v2 Admin auth disabled')
+ super(BaseIdentityV2AdminTest, cls).skip_checks()
+
+ @classmethod
+ def setup_clients(cls):
super(BaseIdentityV2AdminTest, cls).setup_clients()
cls.client = cls.os_adm.identity_client
cls.token_client = cls.os_adm.token_client
if not cls.client.has_admin_extensions():
raise cls.skipException("Admin extensions disabled")
- cls.non_admin_client = cls.os.identity_client
-
@classmethod
def resource_setup(cls):
super(BaseIdentityV2AdminTest, cls).resource_setup()
@@ -98,27 +124,59 @@
super(BaseIdentityV2AdminTest, cls).resource_cleanup()
-class BaseIdentityV3AdminTest(BaseIdentityAdminTest):
+class BaseIdentityV3Test(BaseIdentityTest):
+
+ @classmethod
+ def setup_credentials(cls):
+ super(BaseIdentityV3Test, cls).setup_credentials()
+ cls.os = cls.get_client_manager(identity_version='v3')
@classmethod
def skip_checks(cls):
- super(BaseIdentityV3AdminTest, cls).skip_checks()
+ super(BaseIdentityV3Test, cls).skip_checks()
if not CONF.identity_feature_enabled.api_v3:
raise cls.skipException("Identity api v3 is not enabled")
@classmethod
def setup_clients(cls):
+ super(BaseIdentityV3Test, cls).setup_clients()
+ cls.non_admin_client = cls.os.identity_v3_client
+ cls.non_admin_token = cls.os.token_v3_client
+ cls.non_admin_endpoints_client = cls.os.endpoints_client
+ cls.non_admin_region_client = cls.os.region_client
+ cls.non_admin_service_client = cls.os.service_client
+ cls.non_admin_policy_client = cls.os.policy_client
+ cls.non_admin_creds_client = cls.os.credentials_client
+
+ @classmethod
+ def resource_cleanup(cls):
+ super(BaseIdentityV3Test, cls).resource_cleanup()
+
+
+class BaseIdentityV3AdminTest(BaseIdentityV3Test):
+
+ @classmethod
+ def setup_credentials(cls):
+ super(BaseIdentityV3AdminTest, cls).setup_credentials()
+ cls.os_adm = clients.Manager(cls.isolated_creds.get_admin_creds())
+
+ @classmethod
+ def skip_checks(cls):
+ if not credentials.is_admin_available():
+ raise cls.skipException('v3 Admin auth disabled')
+ super(BaseIdentityV3AdminTest, cls).skip_checks()
+
+ @classmethod
+ def setup_clients(cls):
super(BaseIdentityV3AdminTest, cls).setup_clients()
cls.client = cls.os_adm.identity_v3_client
cls.token = cls.os_adm.token_v3_client
cls.endpoints_client = cls.os_adm.endpoints_client
cls.region_client = cls.os_adm.region_client
cls.data = DataGenerator(cls.client)
- cls.non_admin_client = cls.os.identity_v3_client
cls.service_client = cls.os_adm.service_client
cls.policy_client = cls.os_adm.policy_client
cls.creds_client = cls.os_adm.credentials_client
- cls.non_admin_client = cls.os.identity_v3_client
@classmethod
def resource_cleanup(cls):
diff --git a/tempest/api/identity/v2/__init__.py b/tempest/api/identity/v2/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tempest/api/identity/v2/__init__.py
diff --git a/tempest/api/identity/v2/test_tokens.py b/tempest/api/identity/v2/test_tokens.py
new file mode 100644
index 0000000..5a8afa0
--- /dev/null
+++ b/tempest/api/identity/v2/test_tokens.py
@@ -0,0 +1,38 @@
+# Copyright 2015 OpenStack Foundation
+# 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 tempest.api.identity import base
+from tempest import test
+
+
+class TokensTest(base.BaseIdentityV2Test):
+
+ @test.idempotent_id('65ae3b78-91ff-467b-a705-f6678863b8ec')
+ def test_create_token(self):
+
+ token_client = self.non_admin_token_client
+
+ # get a token for the user
+ creds = self.os.credentials
+ username = creds.username
+ password = creds.password
+ tenant_name = creds.tenant_name
+
+ body = token_client.auth(username,
+ password,
+ tenant_name)
+
+ self.assertEqual(body['token']['tenant']['name'],
+ tenant_name)
diff --git a/tempest/api/identity/v3/__init__.py b/tempest/api/identity/v3/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tempest/api/identity/v3/__init__.py
diff --git a/tempest/api/identity/v3/test_tokens.py b/tempest/api/identity/v3/test_tokens.py
new file mode 100644
index 0000000..ab4a09f
--- /dev/null
+++ b/tempest/api/identity/v3/test_tokens.py
@@ -0,0 +1,33 @@
+# Copyright 2015 OpenStack Foundation
+# 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 tempest.api.identity import base
+from tempest import test
+
+
+class TokensV3Test(base.BaseIdentityV3Test):
+
+ @test.idempotent_id('6f8e4436-fc96-4282-8122-e41df57197a9')
+ def test_create_token(self):
+
+ creds = self.os.credentials
+ user_id = creds.user_id
+ username = creds.username
+ password = creds.password
+ resp = self.non_admin_token.auth(user_id=user_id,
+ password=password)
+
+ subject_name = resp['token']['user']['name']
+ self.assertEqual(subject_name, username)
diff --git a/tempest/api/network/admin/test_agent_management.py b/tempest/api/network/admin/test_agent_management.py
index d5454ec..be5bb1f 100644
--- a/tempest/api/network/admin/test_agent_management.py
+++ b/tempest/api/network/admin/test_agent_management.py
@@ -20,11 +20,15 @@
class AgentManagementTestJSON(base.BaseAdminNetworkTest):
@classmethod
- def resource_setup(cls):
- super(AgentManagementTestJSON, cls).resource_setup()
+ def skip_checks(cls):
+ super(AgentManagementTestJSON, cls).skip_checks()
if not test.is_extension_enabled('agent', 'network'):
msg = "agent extension not enabled."
raise cls.skipException(msg)
+
+ @classmethod
+ def resource_setup(cls):
+ super(AgentManagementTestJSON, cls).resource_setup()
body = cls.admin_client.list_agents()
agents = body['agents']
cls.agent = agents[0]
diff --git a/tempest/api/network/admin/test_dhcp_agent_scheduler.py b/tempest/api/network/admin/test_dhcp_agent_scheduler.py
index 26f5e7a..3b94b82 100644
--- a/tempest/api/network/admin/test_dhcp_agent_scheduler.py
+++ b/tempest/api/network/admin/test_dhcp_agent_scheduler.py
@@ -19,11 +19,15 @@
class DHCPAgentSchedulersTestJSON(base.BaseAdminNetworkTest):
@classmethod
- def resource_setup(cls):
- super(DHCPAgentSchedulersTestJSON, cls).resource_setup()
+ def skip_checks(cls):
+ super(DHCPAgentSchedulersTestJSON, cls).skip_checks()
if not test.is_extension_enabled('dhcp_agent_scheduler', 'network'):
msg = "dhcp_agent_scheduler extension not enabled."
raise cls.skipException(msg)
+
+ @classmethod
+ def resource_setup(cls):
+ super(DHCPAgentSchedulersTestJSON, cls).resource_setup()
# Create a network and make sure it will be hosted by a
# dhcp agent: this is done by creating a regular port
cls.network = cls.create_network()
diff --git a/tempest/api/network/admin/test_floating_ips_admin_actions.py b/tempest/api/network/admin/test_floating_ips_admin_actions.py
index ccf3980..ce3e319 100644
--- a/tempest/api/network/admin/test_floating_ips_admin_actions.py
+++ b/tempest/api/network/admin/test_floating_ips_admin_actions.py
@@ -24,16 +24,23 @@
class FloatingIPAdminTestJSON(base.BaseAdminNetworkTest):
-
force_tenant_isolation = True
@classmethod
+ def setup_credentials(cls):
+ super(FloatingIPAdminTestJSON, cls).setup_credentials()
+ cls.alt_manager = clients.Manager(cls.isolated_creds.get_alt_creds())
+
+ @classmethod
+ def setup_clients(cls):
+ super(FloatingIPAdminTestJSON, cls).setup_clients()
+ cls.alt_client = cls.alt_manager.network_client
+
+ @classmethod
def resource_setup(cls):
super(FloatingIPAdminTestJSON, cls).resource_setup()
cls.ext_net_id = CONF.network.public_network_id
cls.floating_ip = cls.create_floatingip(cls.ext_net_id)
- cls.alt_manager = clients.Manager(cls.isolated_creds.get_alt_creds())
- cls.alt_client = cls.alt_manager.network_client
cls.network = cls.create_network()
cls.subnet = cls.create_subnet(cls.network)
cls.router = cls.create_router(data_utils.rand_name('router-'),
diff --git a/tempest/api/network/admin/test_l3_agent_scheduler.py b/tempest/api/network/admin/test_l3_agent_scheduler.py
index 257289f..ad121b0 100644
--- a/tempest/api/network/admin/test_l3_agent_scheduler.py
+++ b/tempest/api/network/admin/test_l3_agent_scheduler.py
@@ -15,11 +15,11 @@
from tempest_lib.common.utils import data_utils
from tempest.api.network import base
+from tempest import exceptions
from tempest import test
class L3AgentSchedulerTestJSON(base.BaseAdminNetworkTest):
-
"""
Tests the following operations in the Neutron API using the REST client for
Neutron:
@@ -34,12 +34,15 @@
"""
@classmethod
- def resource_setup(cls):
- super(L3AgentSchedulerTestJSON, cls).resource_setup()
+ def skip_checks(cls):
+ super(L3AgentSchedulerTestJSON, cls).skip_checks()
if not test.is_extension_enabled('l3_agent_scheduler', 'network'):
msg = "L3 Agent Scheduler Extension not enabled."
raise cls.skipException(msg)
- # Trying to get agent details for L3 Agent
+
+ @classmethod
+ def resource_setup(cls):
+ super(L3AgentSchedulerTestJSON, cls).resource_setup()
body = cls.admin_client.list_agents()
agents = body['agents']
for agent in agents:
@@ -47,8 +50,8 @@
cls.agent = agent
break
else:
- msg = "L3 Agent not found"
- raise cls.skipException(msg)
+ msg = "L3 Agent Scheduler enabled in conf, but L3 Agent not found"
+ raise exceptions.InvalidConfiguration(msg)
@test.attr(type='smoke')
@test.idempotent_id('b7ce6e89-e837-4ded-9b78-9ed3c9c6a45a')
diff --git a/tempest/api/network/admin/test_lbaas_agent_scheduler.py b/tempest/api/network/admin/test_lbaas_agent_scheduler.py
index 29b69c3..c4f117b 100644
--- a/tempest/api/network/admin/test_lbaas_agent_scheduler.py
+++ b/tempest/api/network/admin/test_lbaas_agent_scheduler.py
@@ -19,7 +19,6 @@
class LBaaSAgentSchedulerTestJSON(base.BaseAdminNetworkTest):
-
"""
Tests the following operations in the Neutron API using the REST client for
Neutron:
@@ -35,11 +34,15 @@
"""
@classmethod
- def resource_setup(cls):
- super(LBaaSAgentSchedulerTestJSON, cls).resource_setup()
+ def skip_checks(cls):
+ super(LBaaSAgentSchedulerTestJSON, cls).skip_checks()
if not test.is_extension_enabled('lbaas_agent_scheduler', 'network'):
msg = "LBaaS Agent Scheduler Extension not enabled."
raise cls.skipException(msg)
+
+ @classmethod
+ def resource_setup(cls):
+ super(LBaaSAgentSchedulerTestJSON, cls).resource_setup()
cls.network = cls.create_network()
cls.subnet = cls.create_subnet(cls.network)
pool_name = data_utils.rand_name('pool-')
diff --git a/tempest/api/network/admin/test_load_balancer_admin_actions.py b/tempest/api/network/admin/test_load_balancer_admin_actions.py
index b49b57c..5a32119 100644
--- a/tempest/api/network/admin/test_load_balancer_admin_actions.py
+++ b/tempest/api/network/admin/test_load_balancer_admin_actions.py
@@ -20,7 +20,6 @@
class LoadBalancerAdminTestJSON(base.BaseAdminNetworkTest):
-
"""
Test admin actions for load balancer.
@@ -29,15 +28,28 @@
"""
@classmethod
- def resource_setup(cls):
- super(LoadBalancerAdminTestJSON, cls).resource_setup()
+ def skip_checks(cls):
+ super(LoadBalancerAdminTestJSON, cls).skip_checks()
if not test.is_extension_enabled('lbaas', 'network'):
msg = "lbaas extension not enabled."
raise cls.skipException(msg)
+
+ @classmethod
+ def setup_credentials(cls):
+ super(LoadBalancerAdminTestJSON, cls).setup_credentials()
+ cls.manager = cls.get_client_manager()
+ cls.primary_creds = cls.isolated_creds.get_primary_creds()
+
+ @classmethod
+ def setup_clients(cls):
+ super(LoadBalancerAdminTestJSON, cls).setup_clients()
+ cls.client = cls.manager.network_client
+
+ @classmethod
+ def resource_setup(cls):
+ super(LoadBalancerAdminTestJSON, cls).resource_setup()
cls.force_tenant_isolation = True
- manager = cls.get_client_manager()
- cls.client = manager.network_client
- cls.tenant_id = cls.isolated_creds.get_primary_creds().tenant_id
+ cls.tenant_id = cls.primary_creds.tenant_id
cls.network = cls.create_network()
cls.subnet = cls.create_subnet(cls.network)
cls.pool = cls.create_pool(data_utils.rand_name('pool-'),
diff --git a/tempest/api/network/admin/test_quotas.py b/tempest/api/network/admin/test_quotas.py
index 60552b9..275c0d1 100644
--- a/tempest/api/network/admin/test_quotas.py
+++ b/tempest/api/network/admin/test_quotas.py
@@ -20,7 +20,6 @@
class QuotasTest(base.BaseAdminNetworkTest):
-
"""
Tests the following operations in the Neutron API using the REST client for
Neutron:
@@ -38,11 +37,15 @@
"""
@classmethod
- def resource_setup(cls):
- super(QuotasTest, cls).resource_setup()
+ def skip_checks(cls):
+ super(QuotasTest, cls).skip_checks()
if not test.is_extension_enabled('quotas', 'network'):
msg = "quotas extension not enabled."
raise cls.skipException(msg)
+
+ @classmethod
+ def setup_clients(cls):
+ super(QuotasTest, cls).setup_clients()
cls.identity_admin_client = cls.os_adm.identity_client
def _check_quotas(self, new_quotas):
diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py
index cc2d21a..09a5555 100644
--- a/tempest/api/network/base.py
+++ b/tempest/api/network/base.py
@@ -19,6 +19,7 @@
from tempest_lib import exceptions as lib_exc
from tempest import clients
+from tempest.common import credentials
from tempest import config
from tempest import exceptions
import tempest.test
@@ -56,19 +57,30 @@
_ip_version = 4
@classmethod
- def resource_setup(cls):
- # Create no network resources for these test.
- cls.set_network_resources()
- super(BaseNetworkTest, cls).resource_setup()
+ def skip_checks(cls):
+ super(BaseNetworkTest, cls).skip_checks()
if not CONF.service_available.neutron:
raise cls.skipException("Neutron support is required")
if cls._ip_version == 6 and not CONF.network_feature_enabled.ipv6:
raise cls.skipException("IPv6 Tests are disabled.")
- os = cls.get_client_manager()
+ @classmethod
+ def setup_credentials(cls):
+ # Create no network resources for these test.
+ cls.set_network_resources()
+ super(BaseNetworkTest, cls).setup_credentials()
+ cls.os = cls.get_client_manager()
+
+ @classmethod
+ def setup_clients(cls):
+ super(BaseNetworkTest, cls).setup_clients()
+ cls.client = cls.os.network_client
+
+ @classmethod
+ def resource_setup(cls):
+ super(BaseNetworkTest, cls).resource_setup()
cls.network_cfg = CONF.network
- cls.client = os.network_client
cls.networks = []
cls.subnets = []
cls.ports = []
@@ -414,16 +426,22 @@
class BaseAdminNetworkTest(BaseNetworkTest):
@classmethod
- def resource_setup(cls):
- super(BaseAdminNetworkTest, cls).resource_setup()
-
- try:
- creds = cls.isolated_creds.get_admin_creds()
- cls.os_adm = clients.Manager(credentials=creds)
- except NotImplementedError:
+ def skip_checks(cls):
+ super(BaseAdminNetworkTest, cls).skip_checks()
+ if not credentials.is_admin_available():
msg = ("Missing Administrative Network API credentials "
"in configuration.")
raise cls.skipException(msg)
+
+ @classmethod
+ def setup_credentials(cls):
+ super(BaseAdminNetworkTest, cls).setup_credentials()
+ creds = cls.isolated_creds.get_admin_creds()
+ cls.os_adm = clients.Manager(credentials=creds)
+
+ @classmethod
+ def setup_clients(cls):
+ super(BaseAdminNetworkTest, cls).setup_clients()
cls.admin_client = cls.os_adm.network_client
@classmethod
diff --git a/tempest/api/network/base_routers.py b/tempest/api/network/base_routers.py
index 1b580b0..aa4e200 100644
--- a/tempest/api/network/base_routers.py
+++ b/tempest/api/network/base_routers.py
@@ -21,10 +21,6 @@
# as some router operations, such as enabling or disabling SNAT
# require admin credentials by default
- @classmethod
- def resource_setup(cls):
- super(BaseRouterTest, cls).resource_setup()
-
def _delete_router(self, router_id):
self.client.delete_router(router_id)
# Asserting that the router is not found in the list
diff --git a/tempest/api/network/base_security_groups.py b/tempest/api/network/base_security_groups.py
index c704049..6699bf7 100644
--- a/tempest/api/network/base_security_groups.py
+++ b/tempest/api/network/base_security_groups.py
@@ -20,10 +20,6 @@
class BaseSecGroupTest(base.BaseNetworkTest):
- @classmethod
- def resource_setup(cls):
- super(BaseSecGroupTest, cls).resource_setup()
-
def _create_security_group(self):
# Create a security group
name = data_utils.rand_name('secgroup-')
diff --git a/tempest/api/network/test_allowed_address_pair.py b/tempest/api/network/test_allowed_address_pair.py
index 99bd82c..d2db326 100644
--- a/tempest/api/network/test_allowed_address_pair.py
+++ b/tempest/api/network/test_allowed_address_pair.py
@@ -23,7 +23,6 @@
class AllowedAddressPairTestJSON(base.BaseNetworkTest):
-
"""
Tests the Neutron Allowed Address Pair API extension using the Tempest
ReST client. The following API operations are tested with this extension:
@@ -41,11 +40,15 @@
"""
@classmethod
- def resource_setup(cls):
- super(AllowedAddressPairTestJSON, cls).resource_setup()
+ def skip_checks(cls):
+ super(AllowedAddressPairTestJSON, cls).skip_checks()
if not test.is_extension_enabled('allowed-address-pairs', 'network'):
msg = "Allowed Address Pairs extension not enabled."
raise cls.skipException(msg)
+
+ @classmethod
+ def resource_setup(cls):
+ super(AllowedAddressPairTestJSON, cls).resource_setup()
cls.network = cls.create_network()
cls.create_subnet(cls.network)
port = cls.create_port(cls.network)
diff --git a/tempest/api/network/test_dhcp_ipv6.py b/tempest/api/network/test_dhcp_ipv6.py
index a10f749..253d779 100644
--- a/tempest/api/network/test_dhcp_ipv6.py
+++ b/tempest/api/network/test_dhcp_ipv6.py
@@ -41,6 +41,7 @@
@classmethod
def skip_checks(cls):
+ super(NetworksTestDHCPv6, cls).skip_checks()
msg = None
if not CONF.network_feature_enabled.ipv6:
msg = "IPv6 is not enabled"
diff --git a/tempest/api/network/test_extensions.py b/tempest/api/network/test_extensions.py
index bce8efe..e9f1bf4 100644
--- a/tempest/api/network/test_extensions.py
+++ b/tempest/api/network/test_extensions.py
@@ -31,10 +31,6 @@
"""
- @classmethod
- def resource_setup(cls):
- super(ExtensionsTestJSON, cls).resource_setup()
-
@test.attr(type='smoke')
@test.idempotent_id('ef28c7e6-e646-4979-9d67-deb207bc5564')
def test_list_show_extensions(self):
diff --git a/tempest/api/network/test_extra_dhcp_options.py b/tempest/api/network/test_extra_dhcp_options.py
index 5060a48..1937028 100644
--- a/tempest/api/network/test_extra_dhcp_options.py
+++ b/tempest/api/network/test_extra_dhcp_options.py
@@ -20,7 +20,6 @@
class ExtraDHCPOptionsTestJSON(base.BaseNetworkTest):
-
"""
Tests the following operations with the Extra DHCP Options Neutron API
extension:
@@ -36,11 +35,15 @@
"""
@classmethod
- def resource_setup(cls):
- super(ExtraDHCPOptionsTestJSON, cls).resource_setup()
+ def skip_checks(cls):
+ super(ExtraDHCPOptionsTestJSON, cls).skip_checks()
if not test.is_extension_enabled('extra_dhcp_opt', 'network'):
msg = "Extra DHCP Options extension not enabled."
raise cls.skipException(msg)
+
+ @classmethod
+ def resource_setup(cls):
+ super(ExtraDHCPOptionsTestJSON, cls).resource_setup()
cls.network = cls.create_network()
cls.subnet = cls.create_subnet(cls.network)
cls.port = cls.create_port(cls.network)
diff --git a/tempest/api/network/test_floating_ips.py b/tempest/api/network/test_floating_ips.py
index 212013a..23223f6 100644
--- a/tempest/api/network/test_floating_ips.py
+++ b/tempest/api/network/test_floating_ips.py
@@ -24,7 +24,6 @@
class FloatingIPTestJSON(base.BaseNetworkTest):
-
"""
Tests the following operations in the Quantum API using the REST client for
Neutron:
@@ -45,11 +44,15 @@
"""
@classmethod
- def resource_setup(cls):
- super(FloatingIPTestJSON, cls).resource_setup()
+ def skip_checks(cls):
+ super(FloatingIPTestJSON, cls).skip_checks()
if not test.is_extension_enabled('router', 'network'):
msg = "router extension not enabled."
raise cls.skipException(msg)
+
+ @classmethod
+ def resource_setup(cls):
+ super(FloatingIPTestJSON, cls).resource_setup()
cls.ext_net_id = CONF.network.public_network_id
# Create network, subnet, router and add interface
diff --git a/tempest/api/network/test_floating_ips_negative.py b/tempest/api/network/test_floating_ips_negative.py
index a7f806c..824034f 100644
--- a/tempest/api/network/test_floating_ips_negative.py
+++ b/tempest/api/network/test_floating_ips_negative.py
@@ -25,7 +25,6 @@
class FloatingIPNegativeTestJSON(base.BaseNetworkTest):
-
"""
Test the following negative operations for floating ips:
@@ -35,11 +34,15 @@
"""
@classmethod
- def resource_setup(cls):
- super(FloatingIPNegativeTestJSON, cls).resource_setup()
+ def skip_checks(cls):
+ super(FloatingIPNegativeTestJSON, cls).skip_checks()
if not test.is_extension_enabled('router', 'network'):
msg = "router extension not enabled."
raise cls.skipException(msg)
+
+ @classmethod
+ def resource_setup(cls):
+ super(FloatingIPNegativeTestJSON, cls).resource_setup()
cls.ext_net_id = CONF.network.public_network_id
# Create a network with a subnet connected to a router.
cls.network = cls.create_network()
diff --git a/tempest/api/network/test_fwaas_extensions.py b/tempest/api/network/test_fwaas_extensions.py
index e2b6ff1..cecf96d 100644
--- a/tempest/api/network/test_fwaas_extensions.py
+++ b/tempest/api/network/test_fwaas_extensions.py
@@ -24,7 +24,6 @@
class FWaaSExtensionTestJSON(base.BaseNetworkTest):
-
"""
Tests the following operations in the Neutron API using the REST client for
Neutron:
@@ -51,11 +50,15 @@
"""
@classmethod
- def resource_setup(cls):
- super(FWaaSExtensionTestJSON, cls).resource_setup()
+ def skip_checks(cls):
+ super(FWaaSExtensionTestJSON, cls).skip_checks()
if not test.is_extension_enabled('fwaas', 'network'):
msg = "FWaaS Extension not enabled."
raise cls.skipException(msg)
+
+ @classmethod
+ def resource_setup(cls):
+ super(FWaaSExtensionTestJSON, cls).resource_setup()
cls.fw_rule = cls.create_firewall_rule("allow", "tcp")
cls.fw_policy = cls.create_firewall_policy()
diff --git a/tempest/api/network/test_load_balancer.py b/tempest/api/network/test_load_balancer.py
index 583f91a..8bd0f24 100644
--- a/tempest/api/network/test_load_balancer.py
+++ b/tempest/api/network/test_load_balancer.py
@@ -21,7 +21,6 @@
class LoadBalancerTestJSON(base.BaseNetworkTest):
-
"""
Tests the following operations in the Neutron API using the REST client for
Neutron:
@@ -39,11 +38,15 @@
"""
@classmethod
- def resource_setup(cls):
- super(LoadBalancerTestJSON, cls).resource_setup()
+ def skip_checks(cls):
+ super(LoadBalancerTestJSON, cls).skip_checks()
if not test.is_extension_enabled('lbaas', 'network'):
msg = "lbaas extension not enabled."
raise cls.skipException(msg)
+
+ @classmethod
+ def resource_setup(cls):
+ super(LoadBalancerTestJSON, cls).resource_setup()
cls.network = cls.create_network()
cls.name = cls.network['name']
cls.subnet = cls.create_subnet(cls.network)
diff --git a/tempest/api/network/test_metering_extensions.py b/tempest/api/network/test_metering_extensions.py
index c712af2..7935e5b 100644
--- a/tempest/api/network/test_metering_extensions.py
+++ b/tempest/api/network/test_metering_extensions.py
@@ -23,7 +23,6 @@
class MeteringTestJSON(base.BaseAdminNetworkTest):
-
"""
Tests the following operations in the Neutron API using the REST client for
Neutron:
@@ -33,11 +32,15 @@
"""
@classmethod
- def resource_setup(cls):
- super(MeteringTestJSON, cls).resource_setup()
+ def skip_checks(cls):
+ super(MeteringTestJSON, cls).skip_checks()
if not test.is_extension_enabled('metering', 'network'):
msg = "metering extension not enabled."
raise cls.skipException(msg)
+
+ @classmethod
+ def resource_setup(cls):
+ super(MeteringTestJSON, cls).resource_setup()
description = "metering label created by tempest"
name = data_utils.rand_name("metering-label")
cls.metering_label = cls.create_metering_label(name, description)
diff --git a/tempest/api/network/test_networks.py b/tempest/api/network/test_networks.py
index 2e01a85..f85e8cf 100644
--- a/tempest/api/network/test_networks.py
+++ b/tempest/api/network/test_networks.py
@@ -27,7 +27,6 @@
class NetworksTestJSON(base.BaseNetworkTest):
-
"""
Tests the following operations in the Neutron API using the REST client for
Neutron:
@@ -417,7 +416,6 @@
class BulkNetworkOpsTestJSON(base.BaseNetworkTest):
-
"""
Tests the following operations in the Neutron API using the REST client for
Neutron:
@@ -604,11 +602,11 @@
class NetworksIpV6TestAttrs(NetworksIpV6TestJSON):
@classmethod
- def resource_setup(cls):
+ def skip_checks(cls):
+ super(NetworksIpV6TestAttrs, cls).skip_checks()
if not CONF.network_feature_enabled.ipv6_subnet_attributes:
raise cls.skipException("IPv6 extended attributes for "
"subnets not available")
- super(NetworksIpV6TestAttrs, cls).resource_setup()
@test.attr(type='smoke')
@test.idempotent_id('da40cd1b-a833-4354-9a85-cd9b8a3b74ca')
diff --git a/tempest/api/network/test_ports.py b/tempest/api/network/test_ports.py
index 6fe955e..953b268 100644
--- a/tempest/api/network/test_ports.py
+++ b/tempest/api/network/test_ports.py
@@ -28,7 +28,6 @@
class PortsTestJSON(sec_base.BaseSecGroupTest):
-
"""
Test the following operations for ports:
@@ -315,13 +314,17 @@
class PortsAdminExtendedAttrsTestJSON(base.BaseAdminNetworkTest):
@classmethod
+ def setup_clients(cls):
+ super(PortsAdminExtendedAttrsTestJSON, cls).setup_clients()
+ cls.identity_client = cls.os_adm.identity_client
+
+ @classmethod
def resource_setup(cls):
super(PortsAdminExtendedAttrsTestJSON, cls).resource_setup()
- cls.identity_client = cls._get_identity_admin_client()
- cls.tenant = cls.identity_client.get_tenant_by_name(
- CONF.identity.tenant_name)
cls.network = cls.create_network()
cls.host_id = socket.gethostname()
+ cls.tenant = cls.identity_client.get_tenant_by_name(
+ CONF.identity.tenant_name)
@test.attr(type='smoke')
@test.idempotent_id('8e8569c1-9ac7-44db-8bc1-f5fb2814f29b')
diff --git a/tempest/api/network/test_routers.py b/tempest/api/network/test_routers.py
index e9c9484..c6f3849 100644
--- a/tempest/api/network/test_routers.py
+++ b/tempest/api/network/test_routers.py
@@ -17,7 +17,6 @@
from tempest_lib.common.utils import data_utils
from tempest.api.network import base_routers as base
-from tempest import clients
from tempest import config
from tempest import test
@@ -27,13 +26,20 @@
class RoutersTest(base.BaseRouterTest):
@classmethod
- def resource_setup(cls):
- super(RoutersTest, cls).resource_setup()
+ def skip_checks(cls):
+ super(RoutersTest, cls).skip_checks()
if not test.is_extension_enabled('router', 'network'):
msg = "router extension not enabled."
raise cls.skipException(msg)
- admin_manager = clients.AdminManager()
- cls.identity_admin_client = admin_manager.identity_client
+
+ @classmethod
+ def setup_clients(cls):
+ super(RoutersTest, cls).setup_clients()
+ cls.identity_admin_client = cls.os_adm.identity_client
+
+ @classmethod
+ def resource_setup(cls):
+ super(RoutersTest, cls).resource_setup()
cls.tenant_cidr = (CONF.network.tenant_network_cidr
if cls._ip_version == 4 else
CONF.network.tenant_network_v6_cidr)
diff --git a/tempest/api/network/test_routers_negative.py b/tempest/api/network/test_routers_negative.py
index 9e7d574..ae17222 100644
--- a/tempest/api/network/test_routers_negative.py
+++ b/tempest/api/network/test_routers_negative.py
@@ -27,11 +27,15 @@
class RoutersNegativeTest(base.BaseRouterTest):
@classmethod
- def resource_setup(cls):
- super(RoutersNegativeTest, cls).resource_setup()
+ def skip_checks(cls):
+ super(RoutersNegativeTest, cls).skip_checks()
if not test.is_extension_enabled('router', 'network'):
msg = "router extension not enabled."
raise cls.skipException(msg)
+
+ @classmethod
+ def resource_setup(cls):
+ super(RoutersNegativeTest, cls).resource_setup()
cls.router = cls.create_router(data_utils.rand_name('router-'))
cls.network = cls.create_network()
cls.subnet = cls.create_subnet(cls.network)
diff --git a/tempest/api/network/test_security_groups.py b/tempest/api/network/test_security_groups.py
index 46dbeee..71e1beb 100644
--- a/tempest/api/network/test_security_groups.py
+++ b/tempest/api/network/test_security_groups.py
@@ -24,12 +24,11 @@
class SecGroupTest(base.BaseSecGroupTest):
-
_tenant_network_cidr = CONF.network.tenant_network_cidr
@classmethod
- def resource_setup(cls):
- super(SecGroupTest, cls).resource_setup()
+ def skip_checks(cls):
+ super(SecGroupTest, cls).skip_checks()
if not test.is_extension_enabled('security-group', 'network'):
msg = "security-group extension not enabled."
raise cls.skipException(msg)
diff --git a/tempest/api/network/test_security_groups_negative.py b/tempest/api/network/test_security_groups_negative.py
index 97c0592..0c5f017 100644
--- a/tempest/api/network/test_security_groups_negative.py
+++ b/tempest/api/network/test_security_groups_negative.py
@@ -25,12 +25,11 @@
class NegativeSecGroupTest(base.BaseSecGroupTest):
-
_tenant_network_cidr = CONF.network.tenant_network_cidr
@classmethod
- def resource_setup(cls):
- super(NegativeSecGroupTest, cls).resource_setup()
+ def skip_checks(cls):
+ super(NegativeSecGroupTest, cls).skip_checks()
if not test.is_extension_enabled('security-group', 'network'):
msg = "security-group extension not enabled."
raise cls.skipException(msg)
diff --git a/tempest/api/network/test_service_type_management.py b/tempest/api/network/test_service_type_management.py
index a1e4136..085ad73 100644
--- a/tempest/api/network/test_service_type_management.py
+++ b/tempest/api/network/test_service_type_management.py
@@ -19,8 +19,8 @@
class ServiceTypeManagementTestJSON(base.BaseNetworkTest):
@classmethod
- def resource_setup(cls):
- super(ServiceTypeManagementTestJSON, cls).resource_setup()
+ def skip_checks(cls):
+ super(ServiceTypeManagementTestJSON, cls).skip_checks()
if not test.is_extension_enabled('service-type', 'network'):
msg = "Neutron Service Type Management not enabled."
raise cls.skipException(msg)
diff --git a/tempest/api/network/test_vpnaas_extensions.py b/tempest/api/network/test_vpnaas_extensions.py
index ba30326..4ab69e0 100644
--- a/tempest/api/network/test_vpnaas_extensions.py
+++ b/tempest/api/network/test_vpnaas_extensions.py
@@ -24,7 +24,6 @@
class VPNaaSTestJSON(base.BaseAdminNetworkTest):
-
"""
Tests the following operations in the Neutron API using the REST client for
Neutron:
@@ -34,10 +33,14 @@
"""
@classmethod
- def resource_setup(cls):
+ def skip_checks(cls):
+ super(VPNaaSTestJSON, cls).skip_checks()
if not test.is_extension_enabled('vpnaas', 'network'):
msg = "vpnaas extension not enabled."
raise cls.skipException(msg)
+
+ @classmethod
+ def resource_setup(cls):
super(VPNaaSTestJSON, cls).resource_setup()
cls.ext_net_id = CONF.network.public_network_id
cls.network = cls.create_network()
diff --git a/tempest/api/volume/base.py b/tempest/api/volume/base.py
index 157bd44..1f76b1c 100644
--- a/tempest/api/volume/base.py
+++ b/tempest/api/volume/base.py
@@ -18,6 +18,7 @@
from tempest_lib import exceptions as lib_exc
from tempest import clients
+from tempest.common import fixed_network
from tempest import config
from tempest import exceptions
import tempest.test
@@ -62,6 +63,7 @@
super(BaseVolumeTest, cls).setup_clients()
cls.servers_client = cls.os.servers_client
+ cls.networks_client = cls.os.networks_client
if cls._api_version == 1:
cls.snapshots_client = cls.os.snapshots_client
@@ -159,6 +161,15 @@
except Exception:
pass
+ @classmethod
+ def create_server(cls, name, **kwargs):
+ network = cls.get_tenant_network()
+ network_kwargs = fixed_network.set_networks_kwarg(network, kwargs)
+ return cls.servers_client.create_server(name,
+ cls.image_ref,
+ cls.flavor_ref,
+ **network_kwargs)
+
class BaseVolumeAdminTest(BaseVolumeTest):
"""Base test case class for all Volume Admin API tests."""
diff --git a/tempest/api/volume/test_volumes_actions.py b/tempest/api/volume/test_volumes_actions.py
index 3de5021..1872ec7 100644
--- a/tempest/api/volume/test_volumes_actions.py
+++ b/tempest/api/volume/test_volumes_actions.py
@@ -36,9 +36,7 @@
# Create a test shared instance
srv_name = data_utils.rand_name(cls.__name__ + '-Instance')
- cls.server = cls.servers_client.create_server(srv_name,
- cls.image_ref,
- cls.flavor_ref)
+ cls.server = cls.create_server(srv_name)
cls.servers_client.wait_for_server_status(cls.server['id'], 'ACTIVE')
# Create a test shared volume for attach/detach tests
diff --git a/tempest/api/volume/test_volumes_negative.py b/tempest/api/volume/test_volumes_negative.py
index af6e24e..a47e964 100644
--- a/tempest/api/volume/test_volumes_negative.py
+++ b/tempest/api/volume/test_volumes_negative.py
@@ -179,9 +179,7 @@
@test.services('compute')
def test_attach_volumes_with_nonexistent_volume_id(self):
srv_name = data_utils.rand_name('Instance')
- server = self.servers_client.create_server(srv_name,
- self.image_ref,
- self.flavor_ref)
+ server = self.create_server(srv_name)
self.addCleanup(self.servers_client.delete_server, server['id'])
self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
self.assertRaises(lib_exc.NotFound,
diff --git a/tempest/api/volume/test_volumes_snapshots.py b/tempest/api/volume/test_volumes_snapshots.py
index 2b6339a..b277390 100644
--- a/tempest/api/volume/test_volumes_snapshots.py
+++ b/tempest/api/volume/test_volumes_snapshots.py
@@ -69,9 +69,7 @@
# Create a snapshot when volume status is in-use
# Create a test instance
server_name = data_utils.rand_name('instance')
- server = self.servers_client.create_server(server_name,
- self.image_ref,
- self.flavor_ref)
+ server = self.create_server(server_name)
self.addCleanup(self.servers_client.delete_server, server['id'])
self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
mountpoint = '/dev/%s' % CONF.compute.volume_device_name
diff --git a/tempest/common/fixed_network.py b/tempest/common/fixed_network.py
new file mode 100644
index 0000000..b06ddf2
--- /dev/null
+++ b/tempest/common/fixed_network.py
@@ -0,0 +1,89 @@
+# 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.
+
+import copy
+from oslo_log import log as logging
+
+from tempest_lib import exceptions as lib_exc
+
+from tempest import config
+from tempest import exceptions
+
+CONF = config.CONF
+
+LOG = logging.getLogger(__name__)
+
+
+def get_tenant_network(creds_provider, compute_networks_client):
+ """Get a network usable by the primary tenant
+
+ :param creds_provider: instance of credential provider
+ :param compute_networks_client: compute network client. We want to have the
+ compute network client so we can have use a common approach for both
+ neutron and nova-network cases. If this is not an admin network
+ client, set_network_kwargs might fail in case fixed_network_name
+ is the network to be used, and it's not visible to the tenant
+ :return a dict with 'id' and 'name' of the network
+ """
+ fixed_network_name = CONF.compute.fixed_network_name
+ network = None
+ # NOTE(andreaf) get_primary_network will always be available once
+ # bp test-accounts-continued is implemented
+ if (CONF.auth.allow_tenant_isolation and
+ (CONF.service_available.neutron and
+ not CONF.service_available.ironic)):
+ network = creds_provider.get_primary_network()
+ else:
+ if fixed_network_name:
+ try:
+ resp = compute_networks_client.list_networks(
+ name=fixed_network_name)
+ if isinstance(resp, list):
+ networks = resp
+ elif isinstance(resp, dict):
+ networks = resp['networks']
+ else:
+ raise lib_exc.NotFound()
+ if len(networks) > 0:
+ network = networks[0]
+ else:
+ msg = "Configured fixed_network_name not found"
+ raise exceptions.InvalidConfiguration(msg)
+ # To be consistent with network isolation, add name is only
+ # label is available
+ network['name'] = network.get('name', network.get('label'))
+ except lib_exc.NotFound:
+ # In case of nova network, if the fixed_network_name is not
+ # owned by the tenant, and the network client is not an admin
+ # one, list_networks will not find it
+ LOG.info('Unable to find network %s. '
+ 'Starting instance without specifying a network.' %
+ fixed_network_name)
+ network = {'name': fixed_network_name}
+ LOG.info('Found network %s available for tenant' % network)
+ return network
+
+
+def set_networks_kwarg(network, kwargs=None):
+ """Set 'networks' kwargs for a server create if missing
+
+ :param network: dict of network to be used with 'id' and 'name'
+ :param kwargs: server create kwargs to be enhanced
+ :return: new dict of kwargs updated to include networks
+ """
+ params = copy.copy(kwargs) or {}
+ if kwargs and 'networks' in kwargs:
+ return params
+
+ if network:
+ params.update({"networks": [{'uuid': network['id']}]})
+ return params
diff --git a/tempest/config.py b/tempest/config.py
index 4ee4669..f884baa 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -232,9 +232,11 @@
help="Timeout in seconds to wait for output from ssh "
"channel."),
cfg.StrOpt('fixed_network_name',
- default='private',
help="Name of the fixed network that is visible to all test "
- "tenants."),
+ "tenants. If multiple networks are available for a tenant"
+ " this is the network which will be used for creating "
+ "servers if tempest does not create a network or a "
+ "network is not specified elsewhere"),
cfg.StrOpt('network_for_ssh',
default='public',
help="Network used for SSH connections. Ignored if "
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index f8cc17c..bae8296 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -24,6 +24,7 @@
from tempest import clients
from tempest.common import credentials
+from tempest.common import fixed_network
from tempest.common.utils.linux import remote_client
from tempest import config
from tempest import exceptions
@@ -184,6 +185,8 @@
flavor = CONF.compute.flavor_ref
if create_kwargs is None:
create_kwargs = {}
+ network = self.get_tenant_network()
+ fixed_network.set_networks_kwarg(network, create_kwargs)
LOG.debug("Creating a server (name: %s, image: %s, flavor: %s)",
name, image, flavor)
diff --git a/tempest/services/compute/json/networks_client.py b/tempest/services/compute/json/networks_client.py
index ef1c058..0ae0920 100644
--- a/tempest/services/compute/json/networks_client.py
+++ b/tempest/services/compute/json/networks_client.py
@@ -20,11 +20,15 @@
class NetworksClientJSON(service_client.ServiceClient):
- def list_networks(self):
+ def list_networks(self, name=None):
resp, body = self.get("os-networks")
body = json.loads(body)
self.expected_success(200, resp.status)
- return service_client.ResponseBodyList(resp, body['networks'])
+ if name:
+ networks = [n for n in body['networks'] if n['label'] == name]
+ else:
+ networks = body['networks']
+ return service_client.ResponseBodyList(resp, networks)
def get_network(self, network_id):
resp, body = self.get("os-networks/%s" % str(network_id))
diff --git a/tempest/test.py b/tempest/test.py
index 19bae74..da936b4 100644
--- a/tempest/test.py
+++ b/tempest/test.py
@@ -32,6 +32,7 @@
from tempest import clients
from tempest.common import credentials
+from tempest.common import fixed_network
import tempest.common.generator.valid_generator as valid
from tempest import config
from tempest import exceptions
@@ -435,6 +436,21 @@
'subnet': subnet,
'dhcp': dhcp}
+ @classmethod
+ def get_tenant_network(cls):
+ """Get the network to be used in testing
+
+ :return: network dict including 'id' and 'name'
+ """
+ # Make sure isolated_creds exists and get a network client
+ networks_client = cls.get_client_manager().networks_client
+ isolated_creds = getattr(cls, 'isolated_creds', None)
+ if credentials.is_admin_available():
+ admin_creds = isolated_creds.get_admin_creds()
+ networks_client = clients.Manager(admin_creds).networks_client
+ return fixed_network.get_tenant_network(isolated_creds,
+ networks_client)
+
def assertEmpty(self, list, msg=None):
self.assertTrue(len(list) == 0, msg)