Add project reader to account-generator
Tempest requires project_reader to sucessfully run some tests [1]. However, account-generator does not support generating project reader accounts. This patch therefore changes accout-generator so that it generates project reader together with other accounts. [1] https://review.opendev.org/c/openstack/tempest/+/871210 Change-Id: Ie127c2ed159da8a6bc780919cdd4def44e457efb
This commit is contained in:
committed by
Lukáš Piwowarski
parent
baa3cc712c
commit
b15ff9b0f2
@@ -155,7 +155,7 @@ def generate_resources(cred_provider, admin):
|
|||||||
# Create the list of resources to be provisioned for each process
|
# Create the list of resources to be provisioned for each process
|
||||||
# NOTE(andreaf) get_credentials expects a string for types or a list for
|
# NOTE(andreaf) get_credentials expects a string for types or a list for
|
||||||
# roles. Adding all required inputs to the spec list.
|
# roles. Adding all required inputs to the spec list.
|
||||||
spec = ['primary', 'alt']
|
spec = ['primary', 'alt', 'project_reader']
|
||||||
if CONF.service_available.swift:
|
if CONF.service_available.swift:
|
||||||
spec.append([CONF.object_storage.operator_role])
|
spec.append([CONF.object_storage.operator_role])
|
||||||
spec.append([CONF.object_storage.reseller_admin_role])
|
spec.append([CONF.object_storage.reseller_admin_role])
|
||||||
@@ -163,8 +163,13 @@ def generate_resources(cred_provider, admin):
|
|||||||
spec.append('admin')
|
spec.append('admin')
|
||||||
resources = []
|
resources = []
|
||||||
for cred_type in spec:
|
for cred_type in spec:
|
||||||
|
scope = None
|
||||||
|
if "_" in cred_type:
|
||||||
|
scope = cred_type.split("_")[0]
|
||||||
|
cred_type = cred_type.split("_")[1:2]
|
||||||
|
|
||||||
resources.append((cred_type, cred_provider.get_credentials(
|
resources.append((cred_type, cred_provider.get_credentials(
|
||||||
credential_type=cred_type)))
|
credential_type=cred_type, scope=scope)))
|
||||||
return resources
|
return resources
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -153,13 +153,14 @@ class TestGenerateResourcesV2(base.TestCase, MockHelpersMixin):
|
|||||||
resources = account_generator.generate_resources(
|
resources = account_generator.generate_resources(
|
||||||
self.cred_provider, admin=False)
|
self.cred_provider, admin=False)
|
||||||
resource_types = [k for k, _ in resources]
|
resource_types = [k for k, _ in resources]
|
||||||
# No admin, no swift, expect two credentials only
|
# No admin, no swift, expect three credentials only
|
||||||
self.assertEqual(2, len(resources))
|
self.assertEqual(3, len(resources))
|
||||||
# Ensure create_user was invoked twice (two distinct users)
|
# Ensure create_user was invoked three times (three distinct users)
|
||||||
self.assertEqual(2, self.user_create_fixture.mock.call_count)
|
self.assertEqual(3, self.user_create_fixture.mock.call_count)
|
||||||
self.assertIn('primary', resource_types)
|
self.assertIn('primary', resource_types)
|
||||||
self.assertIn('alt', resource_types)
|
self.assertIn('alt', resource_types)
|
||||||
self.assertNotIn('admin', resource_types)
|
self.assertNotIn('admin', resource_types)
|
||||||
|
self.assertIn(['reader'], resource_types)
|
||||||
self.assertNotIn(['fake_operator'], resource_types)
|
self.assertNotIn(['fake_operator'], resource_types)
|
||||||
self.assertNotIn(['fake_reseller'], resource_types)
|
self.assertNotIn(['fake_reseller'], resource_types)
|
||||||
self.assertNotIn(['fake_owner'], resource_types)
|
self.assertNotIn(['fake_owner'], resource_types)
|
||||||
@@ -178,12 +179,13 @@ class TestGenerateResourcesV2(base.TestCase, MockHelpersMixin):
|
|||||||
self.cred_provider, admin=True)
|
self.cred_provider, admin=True)
|
||||||
resource_types = [k for k, _ in resources]
|
resource_types = [k for k, _ in resources]
|
||||||
# Admin, no swift, expect three credentials only
|
# Admin, no swift, expect three credentials only
|
||||||
self.assertEqual(3, len(resources))
|
self.assertEqual(4, len(resources))
|
||||||
# Ensure create_user was invoked 3 times (3 distinct users)
|
# Ensure create_user was invoked 4 times (4 distinct users)
|
||||||
self.assertEqual(3, self.user_create_fixture.mock.call_count)
|
self.assertEqual(4, self.user_create_fixture.mock.call_count)
|
||||||
self.assertIn('primary', resource_types)
|
self.assertIn('primary', resource_types)
|
||||||
self.assertIn('alt', resource_types)
|
self.assertIn('alt', resource_types)
|
||||||
self.assertIn('admin', resource_types)
|
self.assertIn('admin', resource_types)
|
||||||
|
self.assertIn(['reader'], resource_types)
|
||||||
self.assertNotIn(['fake_operator'], resource_types)
|
self.assertNotIn(['fake_operator'], resource_types)
|
||||||
self.assertNotIn(['fake_reseller'], resource_types)
|
self.assertNotIn(['fake_reseller'], resource_types)
|
||||||
self.assertNotIn(['fake_owner'], resource_types)
|
self.assertNotIn(['fake_owner'], resource_types)
|
||||||
@@ -201,13 +203,14 @@ class TestGenerateResourcesV2(base.TestCase, MockHelpersMixin):
|
|||||||
resources = account_generator.generate_resources(
|
resources = account_generator.generate_resources(
|
||||||
self.cred_provider, admin=True)
|
self.cred_provider, admin=True)
|
||||||
resource_types = [k for k, _ in resources]
|
resource_types = [k for k, _ in resources]
|
||||||
# all options on, expect five credentials
|
# all options on, expect six credentials
|
||||||
self.assertEqual(5, len(resources))
|
self.assertEqual(6, len(resources))
|
||||||
# Ensure create_user was invoked 5 times (5 distinct users)
|
# Ensure create_user was invoked 6 times (6 distinct users)
|
||||||
self.assertEqual(5, self.user_create_fixture.mock.call_count)
|
self.assertEqual(6, self.user_create_fixture.mock.call_count)
|
||||||
self.assertIn('primary', resource_types)
|
self.assertIn('primary', resource_types)
|
||||||
self.assertIn('alt', resource_types)
|
self.assertIn('alt', resource_types)
|
||||||
self.assertIn('admin', resource_types)
|
self.assertIn('admin', resource_types)
|
||||||
|
self.assertIn(['reader'], resource_types)
|
||||||
self.assertIn(['fake_operator'], resource_types)
|
self.assertIn(['fake_operator'], resource_types)
|
||||||
self.assertIn(['fake_reseller'], resource_types)
|
self.assertIn(['fake_reseller'], resource_types)
|
||||||
for resource in resources:
|
for resource in resources:
|
||||||
@@ -224,13 +227,14 @@ class TestGenerateResourcesV2(base.TestCase, MockHelpersMixin):
|
|||||||
resources = account_generator.generate_resources(
|
resources = account_generator.generate_resources(
|
||||||
self.cred_provider, admin=False)
|
self.cred_provider, admin=False)
|
||||||
resource_types = [k for k, _ in resources]
|
resource_types = [k for k, _ in resources]
|
||||||
# No Admin, swift, expect four credentials only
|
# No Admin, swift, expect five credentials only
|
||||||
self.assertEqual(4, len(resources))
|
self.assertEqual(5, len(resources))
|
||||||
# Ensure create_user was invoked 4 times (4 distinct users)
|
# Ensure create_user was invoked 5 times (5 distinct users)
|
||||||
self.assertEqual(4, self.user_create_fixture.mock.call_count)
|
self.assertEqual(5, self.user_create_fixture.mock.call_count)
|
||||||
self.assertIn('primary', resource_types)
|
self.assertIn('primary', resource_types)
|
||||||
self.assertIn('alt', resource_types)
|
self.assertIn('alt', resource_types)
|
||||||
self.assertNotIn('admin', resource_types)
|
self.assertNotIn('admin', resource_types)
|
||||||
|
self.assertIn(['reader'], resource_types)
|
||||||
self.assertIn(['fake_operator'], resource_types)
|
self.assertIn(['fake_operator'], resource_types)
|
||||||
self.assertIn(['fake_reseller'], resource_types)
|
self.assertIn(['fake_reseller'], resource_types)
|
||||||
self.assertNotIn(['fake_owner'], resource_types)
|
self.assertNotIn(['fake_owner'], resource_types)
|
||||||
@@ -284,14 +288,14 @@ class TestDumpAccountsV2(base.TestCase, MockHelpersMixin):
|
|||||||
# Ordered args in [0], keyword args in [1]
|
# Ordered args in [0], keyword args in [1]
|
||||||
accounts, f = yaml_dump_mock.call_args[0]
|
accounts, f = yaml_dump_mock.call_args[0]
|
||||||
self.assertEqual(handle, f)
|
self.assertEqual(handle, f)
|
||||||
self.assertEqual(5, len(accounts))
|
self.assertEqual(6, len(accounts))
|
||||||
if self.domain_is_in:
|
if self.domain_is_in:
|
||||||
self.assertIn('domain_name', accounts[0].keys())
|
self.assertIn('domain_name', accounts[0].keys())
|
||||||
else:
|
else:
|
||||||
self.assertNotIn('domain_name', accounts[0].keys())
|
self.assertNotIn('domain_name', accounts[0].keys())
|
||||||
self.assertEqual(1, len([x for x in accounts if
|
self.assertEqual(1, len([x for x in accounts if
|
||||||
x.get('types') == ['admin']]))
|
x.get('types') == ['admin']]))
|
||||||
self.assertEqual(2, len([x for x in accounts if 'roles' in x]))
|
self.assertEqual(3, len([x for x in accounts if 'roles' in x]))
|
||||||
for account in accounts:
|
for account in accounts:
|
||||||
self.assertIn('resources', account)
|
self.assertIn('resources', account)
|
||||||
self.assertIn('network', account.get('resources'))
|
self.assertIn('network', account.get('resources'))
|
||||||
@@ -315,14 +319,14 @@ class TestDumpAccountsV2(base.TestCase, MockHelpersMixin):
|
|||||||
# Ordered args in [0], keyword args in [1]
|
# Ordered args in [0], keyword args in [1]
|
||||||
accounts, f = yaml_dump_mock.call_args[0]
|
accounts, f = yaml_dump_mock.call_args[0]
|
||||||
self.assertEqual(handle, f)
|
self.assertEqual(handle, f)
|
||||||
self.assertEqual(5, len(accounts))
|
self.assertEqual(6, len(accounts))
|
||||||
if self.domain_is_in:
|
if self.domain_is_in:
|
||||||
self.assertIn('domain_name', accounts[0].keys())
|
self.assertIn('domain_name', accounts[0].keys())
|
||||||
else:
|
else:
|
||||||
self.assertNotIn('domain_name', accounts[0].keys())
|
self.assertNotIn('domain_name', accounts[0].keys())
|
||||||
self.assertEqual(1, len([x for x in accounts if
|
self.assertEqual(1, len([x for x in accounts if
|
||||||
x.get('types') == ['admin']]))
|
x.get('types') == ['admin']]))
|
||||||
self.assertEqual(2, len([x for x in accounts if 'roles' in x]))
|
self.assertEqual(3, len([x for x in accounts if 'roles' in x]))
|
||||||
for account in accounts:
|
for account in accounts:
|
||||||
self.assertIn('resources', account)
|
self.assertIn('resources', account)
|
||||||
self.assertIn('network', account.get('resources'))
|
self.assertIn('network', account.get('resources'))
|
||||||
|
|||||||
Reference in New Issue
Block a user