Improve Tempest credential provider usage

Instead of getting a DynamicCredentialProvider directly, use the
get_credentials_provider function. This allows for configuration via
TEMPEST_ variables, but the default will still be dynamic credentials.
Only create the default keypair for tests if it doesn't already exist.
Ensure that credentials are freed by calling clear_creds in all cases.

Change-Id: I62ad5ed9fe7c9f6675989df459f92194bb8d67a8
Implements: blueprint magnum-tempest
changes/71/271471/2
Corey O'Brien 7 years ago
parent 5302b88a1b
commit d52965d2d0
  1. 55
      magnum/tests/functional/api/v1/test_bay.py
  2. 22
      magnum/tests/functional/api/v1/test_baymodel.py
  3. 21
      magnum/tests/functional/common/base.py
  4. 1
      tox.ini

@ -37,35 +37,40 @@ class BayTest(base.BaseMagnumTest):
self.bay_client = None
def setUp(self):
super(BayTest, self).setUp()
self.credentials = self.get_credentials(type_of_creds='default')
(self.baymodel_client,
self.keypairs_client) = self.get_clients_with_existing_creds(
creds=self.credentials,
type_of_creds='default',
request_type='baymodel')
(self.bay_client, _) = self.get_clients_with_existing_creds(
creds=self.credentials,
type_of_creds='default',
request_type='bay')
model = datagen.valid_swarm_baymodel()
_, self.baymodel = self._create_baymodel(model)
# NOTE (dimtruck) by default tempest sets timeout to 20 mins.
# We need more time.
test_timeout = 3600
self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
try:
super(BayTest, self).setUp()
self.credentials = self.get_credentials(type_of_creds='default')
(self.baymodel_client,
self.keypairs_client) = self.get_clients_with_existing_creds(
creds=self.credentials,
type_of_creds='default',
request_type='baymodel')
(self.bay_client, _) = self.get_clients_with_existing_creds(
creds=self.credentials,
type_of_creds='default',
request_type='bay')
model = datagen.valid_swarm_baymodel()
_, self.baymodel = self._create_baymodel(model)
# NOTE (dimtruck) by default tempest sets timeout to 20 mins.
# We need more time.
test_timeout = 3600
self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
except Exception:
self.tearDown()
raise
def tearDown(self):
bay_list = self.bays[:]
for bay_id in bay_list:
self._delete_bay(bay_id)
self.bays.remove(bay_id)
self._delete_baymodel(self.baymodel.uuid)
super(BayTest, self).tearDown()
try:
bay_list = self.bays[:]
for bay_id in bay_list:
self._delete_bay(bay_id)
self.bays.remove(bay_id)
self._delete_baymodel(self.baymodel.uuid)
finally:
super(BayTest, self).tearDown()
def _create_baymodel(self, baymodel_model):
self.keypairs_client.create_keypair(name='default')
resp, model = self.baymodel_client.post_baymodel(baymodel_model)
return resp, model

@ -30,11 +30,15 @@ class BayModelTest(base.BaseMagnumTest):
self.keypairs_client = None
def setUp(self):
super(BayModelTest, self).setUp()
(self.baymodel_client,
self.keypairs_client) = self.get_clients_with_new_creds(
type_of_creds='default',
request_type='baymodel')
try:
super(BayModelTest, self).setUp()
(self.baymodel_client,
self.keypairs_client) = self.get_clients_with_new_creds(
type_of_creds='default',
request_type='baymodel')
except Exception:
self.tearDown()
raise
def tearDown(self):
for baymodel_id in self.baymodels:
@ -55,7 +59,6 @@ class BayModelTest(base.BaseMagnumTest):
@testtools.testcase.attr('positive')
def test_list_baymodels(self):
self.keypairs_client.create_keypair(name='default')
gen_model = datagen.baymodel_data_with_valid_keypair_and_image_id()
_, temp_model = self._create_baymodel(gen_model)
resp, model = self.baymodel_client.list_baymodels()
@ -66,13 +69,11 @@ class BayModelTest(base.BaseMagnumTest):
@testtools.testcase.attr('positive')
def test_create_baymodel(self):
self.keypairs_client.create_keypair(name='default')
gen_model = datagen.baymodel_data_with_valid_keypair_and_image_id()
resp, model = self._create_baymodel(gen_model)
@testtools.testcase.attr('positive')
def test_update_baymodel_by_uuid(self):
self.keypairs_client.create_keypair(name='default')
gen_model = datagen.baymodel_data_with_valid_keypair_and_image_id()
resp, old_model = self._create_baymodel(gen_model)
@ -88,7 +89,6 @@ class BayModelTest(base.BaseMagnumTest):
@testtools.testcase.attr('positive')
def test_delete_baymodel_by_uuid(self):
self.keypairs_client.create_keypair(name='default')
gen_model = datagen.baymodel_data_with_valid_keypair_and_image_id()
resp, model = self._create_baymodel(gen_model)
resp, _ = self.baymodel_client.delete_baymodel(model.uuid)
@ -97,7 +97,6 @@ class BayModelTest(base.BaseMagnumTest):
@testtools.testcase.attr('positive')
def test_delete_baymodel_by_name(self):
self.keypairs_client.create_keypair(name='default')
gen_model = datagen.baymodel_data_with_valid_keypair_and_image_id()
resp, model = self._create_baymodel(gen_model)
resp, _ = self.baymodel_client.delete_baymodel(model.name)
@ -147,7 +146,6 @@ class BayModelTest(base.BaseMagnumTest):
@testtools.testcase.attr('negative')
def test_create_baymodel_missing_image(self):
self.keypairs_client.create_keypair(name='default')
gen_model = datagen.baymodel_data_with_valid_keypair()
self.assertRaises(
exceptions.BadRequest,
@ -163,7 +161,6 @@ class BayModelTest(base.BaseMagnumTest):
@testtools.testcase.attr('negative')
def test_update_baymodel_invalid_patch(self):
# get json object
self.keypairs_client.create_keypair(name='default')
gen_model = datagen.baymodel_data_with_valid_keypair_and_image_id()
resp, old_model = self._create_baymodel(gen_model)
@ -174,7 +171,6 @@ class BayModelTest(base.BaseMagnumTest):
@testtools.testcase.attr('negative')
def test_create_baymodel_invalid_network_driver(self):
self.keypairs_client.create_keypair(name='default')
gen_model = datagen.baymodel_data_with_valid_keypair_and_image_id()
gen_model.network_driver = 'invalid_network_driver'
self.assertRaises(

@ -13,7 +13,6 @@
import inspect
from tempest.common import credentials_factory as common_creds
from tempest.common import dynamic_creds
from tempest_lib import base
from magnum.tests.functional.common import config
@ -37,9 +36,9 @@ class BaseMagnumTest(base.BaseTestCase):
super(BaseMagnumTest, cls).tearDownClass()
def tearDown(self):
super(BaseMagnumTest, self).tearDown()
if self.ic is not None:
self.ic.clear_creds()
super(BaseMagnumTest, self).tearDown()
def get_credentials(self, name=None, type_of_creds="default"):
if name is None:
@ -49,12 +48,10 @@ class BaseMagnumTest(base.BaseTestCase):
name = name[0:32]
# Choose type of isolated creds
self.ic = dynamic_creds.DynamicCredentialProvider(
identity_version=config.Config.auth_version,
name=name,
admin_role=config.Config.admin_role,
admin_creds=common_creds.get_configured_credentials(
'identity_admin'))
self.ic = common_creds.get_credentials_provider(
name,
identity_version=config.Config.auth_version
)
creds = None
if "admin" == type_of_creds:
@ -65,6 +62,14 @@ class BaseMagnumTest(base.BaseTestCase):
creds = self.ic.get_primary_creds()
else:
creds = self.ic.self.get_credentials(type_of_creds)
_, keypairs_client = self.get_clients(
creds, type_of_creds, 'keypair_setup')
try:
keypairs_client.show_keypair(config.Config.keypair_id)
except Exception:
keypairs_client.create_keypair(name=config.Config.keypair_id)
return creds
def get_clients(self, creds, type_of_creds, request_type):

@ -14,6 +14,7 @@ setenv =
VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
passenv = TEMPEST_* OS_TEST_*
commands =
find . -type f -name "*.pyc" -delete
bash tools/pretty_tox.sh '{posargs}'

Loading…
Cancel
Save