Merge "admin/test_flavors: some code cleanup and factorization"

This commit is contained in:
Jenkins 2017-02-17 09:47:09 +00:00 committed by Gerrit Code Review
commit 8f98c4b60b

View File

@ -80,20 +80,17 @@ class FlavorsAdminTestJSON(base.BaseV2ComputeAdminTest):
flavor_name = data_utils.rand_name(self.flavor_name_prefix) flavor_name = data_utils.rand_name(self.flavor_name_prefix)
# Create the flavor # Create the flavor
flavor = self.create_flavor(name=flavor_name, self.create_flavor(name=flavor_name,
ram=self.ram, vcpus=self.vcpus, ram=self.ram, vcpus=self.vcpus,
disk=self.disk, disk=self.disk,
ephemeral=self.ephemeral, ephemeral=self.ephemeral,
swap=self.swap, swap=self.swap,
rxtx_factor=self.rxtx) rxtx_factor=self.rxtx)
flag = False
# Verify flavor is retrieved # Check if flavor is present in list
flavors = self.admin_flavors_client.list_flavors( flavors_list = self.admin_flavors_client.list_flavors(
detail=True)['flavors'] detail=True)['flavors']
for flavor in flavors: self.assertIn(flavor_name, [f['name'] for f in flavors_list])
if flavor['name'] == flavor_name:
flag = True
self.assertTrue(flag)
@decorators.idempotent_id('63dc64e6-2e79-4fdf-868f-85500d308d66') @decorators.idempotent_id('63dc64e6-2e79-4fdf-868f-85500d308d66')
def test_create_list_flavor_without_extra_data(self): def test_create_list_flavor_without_extra_data(self):
@ -128,13 +125,12 @@ class FlavorsAdminTestJSON(base.BaseV2ComputeAdminTest):
verify_flavor_response_extension(flavor) verify_flavor_response_extension(flavor)
# Check if flavor is present in list # Check if flavor is present in list
flag = False flavors_list = [
flavors = self.flavors_client.list_flavors(detail=True)['flavors'] f for f in self.flavors_client.list_flavors(detail=True)['flavors']
for flavor in flavors: if f['name'] == flavor_name
if flavor['name'] == flavor_name: ]
verify_flavor_response_extension(flavor) self.assertNotEmpty(flavors_list)
flag = True verify_flavor_response_extension(flavors_list[0])
self.assertTrue(flag)
@decorators.idempotent_id('be6cc18c-7c5d-48c0-ac16-17eaf03c54eb') @decorators.idempotent_id('be6cc18c-7c5d-48c0-ac16-17eaf03c54eb')
def test_list_non_public_flavor(self): def test_list_non_public_flavor(self):
@ -145,26 +141,18 @@ class FlavorsAdminTestJSON(base.BaseV2ComputeAdminTest):
flavor_name = data_utils.rand_name(self.flavor_name_prefix) flavor_name = data_utils.rand_name(self.flavor_name_prefix)
# Create the flavor # Create the flavor
flavor = self.create_flavor(name=flavor_name, self.create_flavor(name=flavor_name,
ram=self.ram, vcpus=self.vcpus, ram=self.ram, vcpus=self.vcpus,
disk=self.disk, disk=self.disk,
is_public="False") is_public="False")
# Verify flavor is retrieved # Verify flavor is not retrieved
flag = False flavors_list = self.admin_flavors_client.list_flavors(
flavors = self.admin_flavors_client.list_flavors(
detail=True)['flavors'] detail=True)['flavors']
for flavor in flavors: self.assertNotIn(flavor_name, [f['name'] for f in flavors_list])
if flavor['name'] == flavor_name:
flag = True
self.assertFalse(flag)
# Verify flavor is not retrieved with other user # Verify flavor is not retrieved with other user
flag = False flavors_list = self.flavors_client.list_flavors(detail=True)['flavors']
flavors = self.flavors_client.list_flavors(detail=True)['flavors'] self.assertNotIn(flavor_name, [f['name'] for f in flavors_list])
for flavor in flavors:
if flavor['name'] == flavor_name:
flag = True
self.assertFalse(flag)
@decorators.idempotent_id('bcc418ef-799b-47cc-baa1-ce01368b8987') @decorators.idempotent_id('bcc418ef-799b-47cc-baa1-ce01368b8987')
def test_create_server_with_non_public_flavor(self): def test_create_server_with_non_public_flavor(self):
@ -186,17 +174,13 @@ class FlavorsAdminTestJSON(base.BaseV2ComputeAdminTest):
flavor_name = data_utils.rand_name(self.flavor_name_prefix) flavor_name = data_utils.rand_name(self.flavor_name_prefix)
# Create the flavor # Create the flavor
flavor = self.create_flavor(name=flavor_name, self.create_flavor(name=flavor_name,
ram=self.ram, vcpus=self.vcpus, ram=self.ram, vcpus=self.vcpus,
disk=self.disk, disk=self.disk,
is_public="True") is_public="True")
flag = False
# Verify flavor is retrieved with new user # Verify flavor is retrieved with new user
flavors = self.flavors_client.list_flavors(detail=True)['flavors'] flavors_list = self.flavors_client.list_flavors(detail=True)['flavors']
for flavor in flavors: self.assertIn(flavor_name, [f['name'] for f in flavors_list])
if flavor['name'] == flavor_name:
flag = True
self.assertTrue(flag)
@decorators.idempotent_id('fb9cbde6-3a0e-41f2-a983-bdb0a823c44e') @decorators.idempotent_id('fb9cbde6-3a0e-41f2-a983-bdb0a823c44e')
def test_is_public_string_variations(self): def test_is_public_string_variations(self):
@ -215,20 +199,13 @@ class FlavorsAdminTestJSON(base.BaseV2ComputeAdminTest):
disk=self.disk, disk=self.disk,
is_public="True") is_public="True")
def _flavor_lookup(flavors, flavor_name):
for flavor in flavors:
if flavor['name'] == flavor_name:
return flavor
return None
def _test_string_variations(variations, flavor_name): def _test_string_variations(variations, flavor_name):
for string in variations: for string in variations:
params = {'is_public': string} params = {'is_public': string}
flavors = (self.admin_flavors_client.list_flavors(detail=True, flavors = (self.admin_flavors_client.list_flavors(detail=True,
**params) **params)
['flavors']) ['flavors'])
flavor = _flavor_lookup(flavors, flavor_name) self.assertIn(flavor_name, [f['name'] for f in flavors])
self.assertIsNotNone(flavor)
_test_string_variations(['f', 'false', 'no', '0'], _test_string_variations(['f', 'false', 'no', '0'],
flavor_name_not_public) flavor_name_not_public)