Allow get_tenant_network() for non-primary creds

Within get_tenant_network(), a client manager was always retrieved, but
because no arguments were passed, it always retrieved the client manager
for the primary credentials. The credentials for the tenant network to
retrieve needs to be passed in so the appropriate client manager can be
retrieved.

Change-Id: I1b20259fc4418d722ed4144e156607ec2a667c33
Closes-Bug: #1549381
This commit is contained in:
Ryan Rossiter 2016-02-25 03:06:12 +00:00
parent 7117f49117
commit 9228bf7bb0
2 changed files with 124 additions and 2 deletions

View File

@ -611,13 +611,25 @@ class BaseTestCase(testtools.testcase.WithAttributes,
'dhcp': dhcp}
@classmethod
def get_tenant_network(cls):
def get_tenant_network(cls, credentials_type='primary'):
"""Get the network to be used in testing
:param credentials_type: The type of credentials for which to get the
tenant network
:return: network dict including 'id' and 'name'
"""
# Get a manager for the given credentials_type, but at least
# always fall back on getting the manager for primary credentials
if isinstance(credentials_type, six.string_types):
manager = cls.get_client_manager(credential_type=credentials_type)
elif isinstance(credentials_type, list):
manager = cls.get_client_manager(roles=credentials_type[1:])
else:
manager = cls.get_client_manager()
# Make sure cred_provider exists and get a network client
networks_client = cls.get_client_manager().compute_networks_client
networks_client = manager.compute_networks_client
cred_provider = cls._get_credentials_provider()
# In case of nova network, isolated tenants are not able to list the
# network configured in fixed_network_name, even if they can use it

View File

@ -0,0 +1,110 @@
# Copyright 2016 IBM Corp.
#
# 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 mock
from tempest import clients
from tempest.common import credentials_factory as credentials
from tempest.common import fixed_network
from tempest import config
from tempest import test
from tempest.tests import base
from tempest.tests import fake_config
class TestBaseTestCase(base.TestCase):
def setUp(self):
super(TestBaseTestCase, self).setUp()
self.useFixture(fake_config.ConfigFixture())
self.fixed_network_name = 'fixed-net'
config.CONF.compute.fixed_network_name = self.fixed_network_name
config.CONF.service_available.neutron = True
@mock.patch.object(test.BaseTestCase, 'get_client_manager')
@mock.patch.object(test.BaseTestCase, '_get_credentials_provider')
@mock.patch.object(fixed_network, 'get_tenant_network')
def test_get_tenant_network(self, mock_gtn, mock_gprov, mock_gcm):
net_client = mock.Mock()
mock_prov = mock.Mock()
mock_gcm.return_value.compute_networks_client = net_client
mock_gprov.return_value = mock_prov
test.BaseTestCase.get_tenant_network()
mock_gcm.assert_called_once_with(credential_type='primary')
mock_gprov.assert_called_once_with()
mock_gtn.assert_called_once_with(mock_prov, net_client,
self.fixed_network_name)
@mock.patch.object(test.BaseTestCase, 'get_client_manager')
@mock.patch.object(test.BaseTestCase, '_get_credentials_provider')
@mock.patch.object(fixed_network, 'get_tenant_network')
@mock.patch.object(test.BaseTestCase, 'get_identity_version')
@mock.patch.object(credentials, 'is_admin_available')
@mock.patch.object(clients, 'Manager')
def test_get_tenant_network_with_nova_net(self, mock_man, mock_iaa,
mock_giv, mock_gtn, mock_gcp,
mock_gcm):
config.CONF.service_available.neutron = False
mock_prov = mock.Mock()
mock_admin_man = mock.Mock()
mock_iaa.return_value = True
mock_gcp.return_value = mock_prov
mock_man.return_value = mock_admin_man
test.BaseTestCase.get_tenant_network()
mock_man.assert_called_once_with(
mock_prov.get_admin_creds.return_value)
mock_iaa.assert_called_once_with(
identity_version=mock_giv.return_value)
mock_gcp.assert_called_once_with()
mock_gtn.assert_called_once_with(
mock_prov, mock_admin_man.compute_networks_client,
self.fixed_network_name)
@mock.patch.object(test.BaseTestCase, 'get_client_manager')
@mock.patch.object(test.BaseTestCase, '_get_credentials_provider')
@mock.patch.object(fixed_network, 'get_tenant_network')
def test_get_tenant_network_with_alt_creds(self, mock_gtn, mock_gprov,
mock_gcm):
net_client = mock.Mock()
mock_prov = mock.Mock()
mock_gcm.return_value.compute_networks_client = net_client
mock_gprov.return_value = mock_prov
test.BaseTestCase.get_tenant_network(credentials_type='alt')
mock_gcm.assert_called_once_with(credential_type='alt')
mock_gprov.assert_called_once_with()
mock_gtn.assert_called_once_with(mock_prov, net_client,
self.fixed_network_name)
@mock.patch.object(test.BaseTestCase, 'get_client_manager')
@mock.patch.object(test.BaseTestCase, '_get_credentials_provider')
@mock.patch.object(fixed_network, 'get_tenant_network')
def test_get_tenant_network_with_role_creds(self, mock_gtn, mock_gprov,
mock_gcm):
net_client = mock.Mock()
mock_prov = mock.Mock()
mock_gcm.return_value.compute_networks_client = net_client
mock_gprov.return_value = mock_prov
creds = ['foo_type', 'role1']
test.BaseTestCase.get_tenant_network(credentials_type=creds)
mock_gcm.assert_called_once_with(roles=['role1'])
mock_gprov.assert_called_once_with()
mock_gtn.assert_called_once_with(mock_prov, net_client,
self.fixed_network_name)