Fail create if validation flags do not agree

This makes us sanity check the wait_until, validateable, and
valiadation_resources flags we get in create_test_server(). Specifying
wait_until='SSHABLE' without the other two will silently not actually
wait for the server to be sshable.

Help make this harder to do by making create_server in the volumes
base class ensure we pass validation_resources for tests that
request SSHABLE.

Note this also includes a change to get_class_validation_resources()
to make sure it returns an empty dict just like
get_test_validation_resources() does if/when CONF has validation
disabled.

Change-Id: Ic8ae7bb322eaf1294d48d5f5242365bec5e863e2
This commit is contained in:
Dan Smith
2023-05-01 14:02:46 -07:00
parent 49c2b3ba83
commit 8f9c77b368
5 changed files with 16 additions and 6 deletions
+8
View File
@@ -225,6 +225,14 @@ class BaseVolumeTest(api_version_utils.BaseMicroversionTest,
'name',
data_utils.rand_name(self.__class__.__name__ + '-instance'))
if wait_until == 'SSHABLE' and not kwargs.get('validation_resources'):
# If we were asked for SSHABLE but were not provided with the
# required validation_resources and validatable flag, ensure we
# pass them to create_test_server() so that it will actually wait.
kwargs['validation_resources'] = (
self.get_test_validation_resources(self.os_primary))
kwargs['validatable'] = True
tenant_network = self.get_tenant_network()
body, _ = compute.create_test_server(
self.os_primary,
+1 -4
View File
@@ -114,10 +114,7 @@ class BaseVolumesExtendAttachedTest(base.BaseVolumeTest):
if the action on the server fails.
"""
# Create a test server. Will be automatically cleaned up on teardown.
validation_resources = self.get_test_validation_resources(
self.os_primary)
server = self.create_server(wait_until='SSHABLE', validatable=True,
validation_resources=validation_resources)
server = self.create_server(wait_until='SSHABLE')
# Attach the volume to the server and wait for the volume status to be
# "in-use".
self.attach_volume(server['id'], volume['id'])
+5
View File
@@ -299,6 +299,11 @@ def create_test_server(clients, validatable=False, validation_resources=None,
if wait_until:
if wait_until == 'SSHABLE' and not (
validatable and validation_resources is not None):
raise RuntimeError('SSHABLE requires validatable=True and '
'validation_resources to be passed')
# NOTE(lyarwood): PINGABLE and SSHABLE both require the instance to
# go ACTIVE initially before we can setup the fip(s) etc so stash
# this additional wait state for later use.
+1 -1
View File
@@ -809,7 +809,7 @@ class BaseTestCase(testtools.testcase.WithAttributes,
@param os_clients: Clients to be used to provision the resources.
"""
if not CONF.validation.run_validation:
return
return {}
if os_clients in cls._validation_resources:
return cls._validation_resources[os_clients]
+1 -1
View File
@@ -69,7 +69,7 @@ class TestValidationResources(base.TestCase):
creds = fake_credentials.FakeKeystoneV3Credentials()
osclients = clients.Manager(creds)
vr = self.test_test_class.get_class_validation_resources(osclients)
self.assertIsNone(vr)
self.assertEqual({}, vr)
def test_validation_resources_exists(self):
cfg.CONF.set_default('run_validation', True, 'validation')