Merge "Rename "endpoint" to "credential" (part 3)"
This commit is contained in:
@@ -39,15 +39,15 @@ class RoleGenerator(context.Context):
|
||||
|
||||
def __init__(self, ctx):
|
||||
super(RoleGenerator, self).__init__(ctx)
|
||||
self.endpoint = self.context["admin"]["endpoint"]
|
||||
self.credential = self.context["admin"]["endpoint"]
|
||||
|
||||
def _add_role(self, admin_endpoint, context_role):
|
||||
def _add_role(self, admin_credential, context_role):
|
||||
"""Add role to users.
|
||||
|
||||
:param admin_endpoint: The base url.
|
||||
:param admin_credential: The base url.
|
||||
:param context_role: name of existing role.
|
||||
"""
|
||||
client = keystone.wrap(osclients.Clients(admin_endpoint).keystone())
|
||||
client = keystone.wrap(osclients.Clients(admin_credential).keystone())
|
||||
default_roles = client.list_roles()
|
||||
for def_role in default_roles:
|
||||
if str(def_role.name) == context_role:
|
||||
@@ -63,13 +63,13 @@ class RoleGenerator(context.Context):
|
||||
|
||||
return {"id": str(role.id), "name": str(role.name)}
|
||||
|
||||
def _remove_role(self, admin_endpoint, role):
|
||||
def _remove_role(self, admin_credential, role):
|
||||
"""Remove given role from users.
|
||||
|
||||
:param admin_endpoint: The base url.
|
||||
:param admin_credential: The base url.
|
||||
:param role: dictionary with role parameters (id, name).
|
||||
"""
|
||||
client = keystone.wrap(osclients.Clients(admin_endpoint).keystone())
|
||||
client = keystone.wrap(osclients.Clients(admin_credential).keystone())
|
||||
|
||||
for user in self.context["users"]:
|
||||
with logging.ExceptionLogger(
|
||||
@@ -81,11 +81,11 @@ class RoleGenerator(context.Context):
|
||||
@logging.log_task_wrapper(LOG.info, _("Enter context: `roles`"))
|
||||
def setup(self):
|
||||
"""Add roles to all users."""
|
||||
self.context["roles"] = [self._add_role(self.endpoint, name)
|
||||
self.context["roles"] = [self._add_role(self.credential, name)
|
||||
for name in self.config]
|
||||
|
||||
@logging.log_task_wrapper(LOG.info, _("Exit context: `roles`"))
|
||||
def cleanup(self):
|
||||
"""Remove roles from users."""
|
||||
for role in self.context["roles"]:
|
||||
self._remove_role(self.endpoint, role)
|
||||
self._remove_role(self.credential, role)
|
||||
|
||||
@@ -115,11 +115,11 @@ class UserGenerator(UserContextMixin, context.Context):
|
||||
|
||||
def __init__(self, context):
|
||||
super(UserGenerator, self).__init__(context)
|
||||
self.endpoint = self.context["admin"]["endpoint"]
|
||||
self.credential = self.context["admin"]["endpoint"]
|
||||
|
||||
def _remove_default_security_group(self):
|
||||
"""Delete default security group for tenants."""
|
||||
clients = osclients.Clients(self.endpoint)
|
||||
clients = osclients.Clients(self.credential)
|
||||
|
||||
if consts.Service.NEUTRON not in clients.services().values():
|
||||
return
|
||||
@@ -143,7 +143,7 @@ class UserGenerator(UserContextMixin, context.Context):
|
||||
# NOTE(rmk): Ugly hack to deal with the fact that Nova Network
|
||||
# networks can only be disassociated in an admin context. Discussed
|
||||
# with boris-42 before taking this approach [LP-Bug #1350517].
|
||||
clients = osclients.Clients(self.endpoint)
|
||||
clients = osclients.Clients(self.credential)
|
||||
if consts.Service.NOVA not in clients.services().values():
|
||||
return
|
||||
|
||||
@@ -175,7 +175,7 @@ class UserGenerator(UserContextMixin, context.Context):
|
||||
def consume(cache, args):
|
||||
domain, task_id, i = args
|
||||
if "client" not in cache:
|
||||
clients = osclients.Clients(self.endpoint)
|
||||
clients = osclients.Clients(self.credential)
|
||||
cache["client"] = keystone.wrap(clients.keystone())
|
||||
tenant = cache["client"].create_project(
|
||||
self.generate_random_name(), domain)
|
||||
@@ -209,22 +209,22 @@ class UserGenerator(UserContextMixin, context.Context):
|
||||
def consume(cache, args):
|
||||
username, password, project_dom, user_dom, tenant_id = args
|
||||
if "client" not in cache:
|
||||
clients = osclients.Clients(self.endpoint)
|
||||
clients = osclients.Clients(self.credential)
|
||||
cache["client"] = keystone.wrap(clients.keystone())
|
||||
client = cache["client"]
|
||||
user = client.create_user(username, password,
|
||||
"%s@email.me" % username,
|
||||
tenant_id, user_dom)
|
||||
user_endpoint = objects.Credential(
|
||||
user_credential = objects.Credential(
|
||||
client.auth_url, user.name, password,
|
||||
self.context["tenants"][tenant_id]["name"],
|
||||
consts.EndpointPermission.USER, client.region_name,
|
||||
project_domain_name=project_dom, user_domain_name=user_dom,
|
||||
endpoint_type=self.endpoint.endpoint_type,
|
||||
https_insecure=self.endpoint.insecure,
|
||||
https_cacert=self.endpoint.cacert)
|
||||
endpoint_type=self.credential.endpoint_type,
|
||||
https_insecure=self.credential.insecure,
|
||||
https_cacert=self.credential.cacert)
|
||||
users.append({"id": user.id,
|
||||
"endpoint": user_endpoint,
|
||||
"endpoint": user_credential,
|
||||
"tenant_id": tenant_id})
|
||||
|
||||
# NOTE(msdubov): consume() will fill the users list in the closure.
|
||||
@@ -242,7 +242,7 @@ class UserGenerator(UserContextMixin, context.Context):
|
||||
|
||||
def consume(cache, tenant_id):
|
||||
if "client" not in cache:
|
||||
clients = osclients.Clients(self.endpoint)
|
||||
clients = osclients.Clients(self.credential)
|
||||
cache["client"] = keystone.wrap(clients.keystone())
|
||||
cache["client"].delete_project(tenant_id)
|
||||
|
||||
@@ -258,7 +258,7 @@ class UserGenerator(UserContextMixin, context.Context):
|
||||
|
||||
def consume(cache, user_id):
|
||||
if "client" not in cache:
|
||||
clients = osclients.Clients(self.endpoint)
|
||||
clients = osclients.Clients(self.credential)
|
||||
cache["client"] = keystone.wrap(clients.keystone())
|
||||
cache["client"].delete_user(user_id)
|
||||
|
||||
|
||||
@@ -26,18 +26,18 @@ from rally.task import context
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _prepare_open_secgroup(endpoint, secgroup_name):
|
||||
def _prepare_open_secgroup(credential, secgroup_name):
|
||||
"""Generate secgroup allowing all tcp/udp/icmp access.
|
||||
|
||||
In order to run tests on instances it is necessary to have SSH access.
|
||||
This function generates a secgroup which allows all tcp/udp/icmp access.
|
||||
|
||||
:param endpoint: clients endpoint
|
||||
:param credential: clients credential
|
||||
:param secgroup_name: security group name
|
||||
|
||||
:returns: dict with security group details
|
||||
"""
|
||||
nova = osclients.Clients(endpoint).nova()
|
||||
nova = osclients.Clients(credential).nova()
|
||||
|
||||
if secgroup_name not in [sg.name for sg in nova.security_groups.list()]:
|
||||
descr = "Allow ssh access to VMs created by Rally for benchmarking"
|
||||
|
||||
@@ -28,10 +28,10 @@ LOG = logging.getLogger(__name__)
|
||||
@context.configure(name="keypair", order=310)
|
||||
class Keypair(context.Context):
|
||||
|
||||
def _generate_keypair(self, endpoint):
|
||||
def _generate_keypair(self, credential):
|
||||
keypair_name = self.generate_random_name()
|
||||
|
||||
nova_client = osclients.Clients(endpoint).nova()
|
||||
nova_client = osclients.Clients(credential).nova()
|
||||
|
||||
# NOTE(hughsaunders): If keypair exists, it must be deleted as we can't
|
||||
# retrieve the private key
|
||||
|
||||
@@ -206,8 +206,8 @@ class CloudResources(object):
|
||||
"""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
endpoint = osclients.objects.Endpoint(**kwargs)
|
||||
self.clients = osclients.Clients(endpoint)
|
||||
credential = osclients.objects.Endpoint(**kwargs)
|
||||
self.clients = osclients.Clients(credential)
|
||||
|
||||
def _deduplicate(self, lst):
|
||||
"""Change list duplicates to make all items unique.
|
||||
|
||||
@@ -920,7 +920,7 @@ class FakeObjectManager(FakeManager):
|
||||
|
||||
|
||||
class FakeServiceCatalog(object):
|
||||
def get_endpoints(self):
|
||||
def get_credentials(self):
|
||||
return {"image": [{"publicURL": "http://fake.to"}],
|
||||
"metering": [{"publicURL": "http://fake.to"}],
|
||||
"monitoring": [{"publicURL": "http://fake.to"}]}
|
||||
@@ -1451,7 +1451,7 @@ class FakeEC2Client(object):
|
||||
|
||||
class FakeClients(object):
|
||||
|
||||
def __init__(self, endpoint_=None):
|
||||
def __init__(self, credential_=None):
|
||||
self._nova = None
|
||||
self._glance = None
|
||||
self._keystone = None
|
||||
@@ -1468,7 +1468,7 @@ class FakeClients(object):
|
||||
self._murano = None
|
||||
self._monasca = None
|
||||
self._ec2 = None
|
||||
self._endpoint = endpoint_ or objects.Credential(
|
||||
self._credential = credential_ or objects.Credential(
|
||||
"http://fake.example.org:5000/v2.0/",
|
||||
"fake_username",
|
||||
"fake_password",
|
||||
|
||||
@@ -152,7 +152,7 @@ class UserGeneratorTestCase(test.ScenarioTestCase):
|
||||
|
||||
mock_iterate_per_tenants.assert_called_once_with(
|
||||
user_generator.context["users"])
|
||||
expected = [mock.call(user_generator.endpoint)] + [
|
||||
expected = [mock.call(user_generator.credential)] + [
|
||||
mock.call(u["endpoint"])
|
||||
for u, t in mock_iterate_per_tenants.return_value]
|
||||
self.osclients.Clients.assert_has_calls(expected, any_order=True)
|
||||
@@ -312,16 +312,16 @@ class UserGeneratorTestCase(test.ScenarioTestCase):
|
||||
wrapped_keystone = mock.MagicMock()
|
||||
mock_keystone.wrap.return_value = wrapped_keystone
|
||||
|
||||
endpoint = objects.Credential("foo_url", "foo", "foo_pass",
|
||||
https_insecure=True,
|
||||
https_cacert="cacert")
|
||||
credential = objects.Credential("foo_url", "foo", "foo_pass",
|
||||
https_insecure=True,
|
||||
https_cacert="cacert")
|
||||
tmp_context = dict(self.context)
|
||||
tmp_context["config"]["users"] = {"tenants": 1,
|
||||
"users_per_tenant": 2,
|
||||
"resource_management_workers": 1}
|
||||
tmp_context["admin"]["endpoint"] = endpoint
|
||||
tmp_context["admin"]["endpoint"] = credential
|
||||
|
||||
endpoint_dict = endpoint.to_dict(False)
|
||||
credential_dict = credential.to_dict(False)
|
||||
user_list = [mock.MagicMock(id="id_%d" % i)
|
||||
for i in range(self.users_num)]
|
||||
wrapped_keystone.create_user.side_effect = user_list
|
||||
@@ -340,16 +340,16 @@ class UserGeneratorTestCase(test.ScenarioTestCase):
|
||||
self.assertEqual(set(["id", "endpoint", "tenant_id"]),
|
||||
set(user.keys()))
|
||||
|
||||
user_endpoint_dict = user["endpoint"].to_dict(False)
|
||||
user_credential_dict = user["endpoint"].to_dict(False)
|
||||
|
||||
excluded_keys = ["auth_url", "username", "password",
|
||||
"tenant_name", "region_name",
|
||||
"project_domain_name",
|
||||
"admin_domain_name",
|
||||
"user_domain_name"]
|
||||
for key in (set(endpoint_dict.keys()) - set(excluded_keys)):
|
||||
self.assertEqual(endpoint_dict[key],
|
||||
user_endpoint_dict[key])
|
||||
for key in (set(credential_dict.keys()) - set(excluded_keys)):
|
||||
self.assertEqual(credential_dict[key],
|
||||
user_credential_dict[key])
|
||||
|
||||
tenants_ids = []
|
||||
for t in ctx.context["tenants"].keys():
|
||||
@@ -362,7 +362,7 @@ class UserGeneratorTestCase(test.ScenarioTestCase):
|
||||
|
||||
@mock.patch("%s.keystone" % CTX)
|
||||
def test_users_contains_correct_endpoint_type(self, mock_keystone):
|
||||
endpoint = objects.Credential(
|
||||
credential = objects.Credential(
|
||||
"foo_url", "foo", "foo_pass",
|
||||
endpoint_type=consts.EndpointType.INTERNAL)
|
||||
config = {
|
||||
@@ -373,7 +373,7 @@ class UserGeneratorTestCase(test.ScenarioTestCase):
|
||||
"resource_management_workers": 1
|
||||
}
|
||||
},
|
||||
"admin": {"endpoint": endpoint},
|
||||
"admin": {"endpoint": credential},
|
||||
"task": {"uuid": "task_id"}
|
||||
}
|
||||
|
||||
@@ -385,7 +385,7 @@ class UserGeneratorTestCase(test.ScenarioTestCase):
|
||||
|
||||
@mock.patch("%s.keystone" % CTX)
|
||||
def test_users_contains_default_endpoint_type(self, mock_keystone):
|
||||
endpoint = objects.Credential("foo_url", "foo", "foo_pass")
|
||||
credential = objects.Credential("foo_url", "foo", "foo_pass")
|
||||
config = {
|
||||
"config": {
|
||||
"users": {
|
||||
@@ -394,7 +394,7 @@ class UserGeneratorTestCase(test.ScenarioTestCase):
|
||||
"resource_management_workers": 1
|
||||
}
|
||||
},
|
||||
"admin": {"endpoint": endpoint},
|
||||
"admin": {"endpoint": credential},
|
||||
"task": {"uuid": "task_id"}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class SaharaInputDataSourcesTestCase(test.ScenarioTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(SaharaInputDataSourcesTestCase, self).setUp()
|
||||
endpoint = objects.Endpoint("foo_url", "user", "passwd")
|
||||
credential = objects.Endpoint("foo_url", "user", "passwd")
|
||||
self.tenants_num = 2
|
||||
self.users_per_tenant = 2
|
||||
self.users = self.tenants_num * self.users_per_tenant
|
||||
@@ -40,7 +40,7 @@ class SaharaInputDataSourcesTestCase(test.ScenarioTestCase):
|
||||
for j in range(self.users_per_tenant):
|
||||
self.users_key.append({"id": "%s_%s" % (str(i), str(j)),
|
||||
"tenant_id": str(i),
|
||||
"endpoint": endpoint})
|
||||
"endpoint": credential})
|
||||
|
||||
self.user_key = [{"id": i, "tenant_id": j, "endpoint": "endpoint"}
|
||||
for j in range(self.tenants_num)
|
||||
|
||||
Reference in New Issue
Block a user