def images(self, deploy_id=None): """Display available images. :param deploy_id: the UUID of a deployment """ headers = ['UUID', 'Name', 'Size (B)'] mixed_case_fields = ['UUID', 'Name'] float_cols = ["Size (B)"] table_rows = [] formatters = dict(zip(float_cols, [cliutils.pretty_float_formatter(col) for col in float_cols])) try: for endpoint_dict in self._get_endpoints(deploy_id): clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict)) glance_client = clients.glance() for image in glance_client.images.list(): data = [image.id, image.name, image.size] table_rows.append(utils.Struct(**dict(zip(headers, data)))) common_cliutils.print_list(table_rows, fields=headers, formatters=formatters, mixed_case_fields=mixed_case_fields) except exceptions.InvalidArgumentsException as e: print(_("Authentication Issues: %s") % e) return(1)
def test_create_image_and_boot_instances(self, mock_osclients, mock_create_image, mock_boot_servers, mock_random_name): glance_scenario = images.GlanceImages() nova_scenario = servers.NovaServers() fc = fakes.FakeClients() mock_osclients.Clients.return_value = fc fake_glance = fakes.FakeGlanceClient() fc.glance = lambda: fake_glance fake_nova = fakes.FakeNovaClient() fc.nova = lambda: fake_nova user_endpoint = endpoint.Endpoint("url", "user", "password", "tenant") nova_scenario._clients = osclients.Clients(user_endpoint) fake_image = fakes.FakeImage() fake_servers = [object() for i in range(5)] mock_create_image.return_value = fake_image mock_boot_servers.return_value = fake_servers mock_random_name.return_value = "random_name" kwargs = {'fakearg': 'f'} with mock.patch("rally.benchmark.scenarios.glance.utils.time.sleep"): glance_scenario.create_image_and_boot_instances("cf", "url", "df", "fid", 5, **kwargs) mock_create_image.assert_called_once_with("random_name", "cf", "url", "df", **kwargs) mock_boot_servers.assert_called_once_with("random_name", "image-id-0", "fid", 5, **kwargs)
def _prepare_boot(self, mock_osclients, nic=None, assert_nic=False): fake_server = mock.MagicMock() fc = fakes.FakeClients() mock_osclients.Clients.return_value = fc nova = fakes.FakeNovaClient() fc.nova = lambda: nova user_endpoint = endpoint.Endpoint("url", "user", "password", "tenant") clients = osclients.Clients(user_endpoint) scenario = servers.NovaServers(clients=clients) scenario._boot_server = mock.MagicMock(return_value=fake_server) scenario._generate_random_name = mock.MagicMock(return_value="name") kwargs = {'fakearg': 'f'} expected_kwargs = {'fakearg': 'f'} assert_nic = nic or assert_nic if nic: kwargs['nics'] = nic if assert_nic: nova.networks.create('net-1') expected_kwargs['nics'] = nic or [{'net-id': 'net-2'}] print(kwargs) print(expected_kwargs) return scenario, kwargs, expected_kwargs
def check(self, deploy_id=None): """Check the deployment. Check keystone authentication and list all available services. :param deploy_id: a UUID of the deployment """ headers = ['services', 'type', 'status'] table = prettytable.PrettyTable(headers) try: endpoints = db.deployment_get(deploy_id)['endpoints'] for endpoint_dict in endpoints: clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict)) client = clients.verified_keystone() print("keystone endpoints are valid and following " "services are available:") for service in client.service_catalog.get_data(): table.add_row([service['name'], service['type'], 'Available']) except exceptions.InvalidArgumentsException: table.add_row(['keystone', 'identity', 'Error']) print(_("Authentication Issues: %s.") % sys.exc_info()[1]) return(1) print(table)
def check(self, deploy_id=None): """Check the deployment. Check keystone authentication and list all available services. :param deploy_id: a UUID of the deployment """ headers = ['services', 'type', 'status'] table_rows = [] try: endpoints = db.deployment_get(deploy_id)['endpoints'] for endpoint_dict in endpoints: clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict)) client = clients.verified_keystone() print("keystone endpoints are valid and following " "services are available:") for service in client.services.list(): data = [service.name, service.type, 'Available'] table_rows.append(utils.Struct(**dict(zip(headers, data)))) except exceptions.InvalidArgumentsException: data = ['keystone', 'identity', 'Error'] table_rows.append(utils.Struct(**dict(zip(headers, data)))) print(_("Authentication Issues: %s.") % sys.exc_info()[1]) return(1) common_cliutils.print_list(table_rows, headers)
def flavors(self, deploy_id=None): """Display available flavors. :param deploy_id: the UUID of a deployment """ headers = ['ID', 'Name', 'vCPUs', 'RAM (MB)', 'Swap (MB)', 'Disk (GB)'] mixed_case_fields = ['ID', 'Name', 'vCPUs'] float_cols = ['RAM (MB)', 'Swap (MB)', 'Disk (GB)'] formatters = dict(zip(float_cols, [cliutils.pretty_float_formatter(col) for col in float_cols])) table_rows = [] try: for endpoint_dict in self._get_endpoints(deploy_id): clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict)) nova_client = clients.nova() for flavor in nova_client.flavors.list(): data = [flavor.id, flavor.name, flavor.vcpus, flavor.ram, flavor.swap, flavor.disk] table_rows.append(utils.Struct(**dict(zip(headers, data)))) common_cliutils.print_list(table_rows, fields=headers, formatters=formatters, mixed_case_fields=mixed_case_fields) except exceptions.InvalidArgumentsException as e: print(_("Authentication Issues: %s") % e) return(1)
def __init__(self, endpoint_=None): self._nova = None self._glance = None self._keystone = None self._cinder = None self._neutron = None self._sahara = None self._endpoint = endpoint_ or endpoint.Endpoint( "http://fake.example.org:5000/v2.0/", "fake_username", "fake_password", "fake_tenant_name")
class FakeUserContext(FakeContext): admin = { "id": "adminuuid", "endpoint": endpoint.Endpoint("aurl", "aname", "apwd", "atenant") } user = { "id": "uuid", "endpoint": endpoint.Endpoint("url", "name", "pwd", "tenant") } tenant = {"id": "uuid", "nema": "tenant"} def __init__(self, context): context.setdefault("task", mock.MagicMock()) super(FakeUserContext, self).__init__(context) context.setdefault("admin", FakeUserContext.admin) context.setdefault("users", [FakeUserContext.user]) context.setdefault("tenants", [FakeUserContext.tenant]) context.setdefault("scenario_name", 'NovaServers.boot_server_from_volume_and_delete')
def __init__(self, deployment, config): super(OpenStackProvider, self).__init__(deployment, config) user_endpoint = endpoint.Endpoint(config['auth_url'], config['user'], config['password'], config['tenant']) clients = osclients.Clients(user_endpoint) self.nova = clients.nova() try: self.glance = clients.glance() except KeyError: self.glance = None LOG.warning( _('Glance endpoint not available in service catalog' ', only existing images can be used'))
def bind(self, endpoints): self.endpoints = [ endpoint.Endpoint(**endpoint_dict) for endpoint_dict in endpoints ] # NOTE(msdubov): Passing predefined user endpoints hasn't been # implemented yet, so the scenario runner always gets # a single admin endpoint here. self.admin_endpoint = self.endpoints[0] self.admin_endpoint.permission = consts.EndpointPermission.ADMIN # Try to access cloud via keystone client clients = osclients.Clients(self.admin_endpoint) clients.verified_keystone() return self
def bind(self, admin=None, users=None): """Bind benchmark engine to OpenStack cloud. This method will set self.admin_endpoint with passed values, as well it will check that admin user is actually admin. :param admin: admin credentials :param users: List of users credentials :returns: self """ self.admin_endpoint = endpoint.Endpoint(**admin) clients = osclients.Clients(self.admin_endpoint) clients.verified_keystone() return self
def setUp(self): super(OSClientsTestCase, self).setUp() self.endpoint = endpoint.Endpoint("http://auth_url", "use", "pass", "tenant") self.clients = osclients.Clients(self.endpoint) self.fake_keystone = fakes.FakeKeystoneClient() self.fake_keystone.auth_token = mock.MagicMock() self.service_catalog = self.fake_keystone.service_catalog self.service_catalog.url_for = mock.MagicMock() keystone_patcher = mock.patch("rally.osclients.create_keystone_client") self.mock_create_keystone_client = keystone_patcher.start() self.addCleanup(keystone_patcher.stop) self.mock_create_keystone_client.return_value = self.fake_keystone
def networks(self, deploy_id=None): headers = ['ID', 'Label', 'CIDR'] mixed_case_fields = ['ID', 'Label', 'CIDR'] table_rows = [] try: endpoints = db.deployment_get(deploy_id)['endpoints'] for endpoint_dict in endpoints: clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict)) nova_client = clients.nova() for network in nova_client.networks.list(): data = [network.id, network.label, network.cidr] table_rows.append(utils.Struct(**dict(zip(headers, data)))) except exceptions.InvalidArgumentsException: print(_("Authentication Issues: %s") % sys.exc_info()[1]) return (1) common_cliutils.print_list(table_rows, fields=headers, mixed_case_fields=mixed_case_fields)
def secgroups(self, deploy_id=None): headers = ['ID', 'Name', 'Description'] mixed_case_fields = ['ID', 'Name', 'Description'] table_rows = [] try: endpoints = db.deployment_get(deploy_id)['endpoints'] for endpoint_dict in endpoints: clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict)) nova_client = clients.nova() for secgroup in nova_client.security_groups.list(): data = [secgroup.id, secgroup.name, secgroup.description] table_rows.append(utils.Struct(**dict(zip(headers, data)))) except exceptions.InvalidArgumentsException: print(_("Authentication Issues: %s") % sys.exc_info()[1]) return (1) common_cliutils.print_list(table_rows, fields=headers, mixed_case_fields=mixed_case_fields)
def keypairs(self, deploy_id=None): headers = ['Name', 'Fingerprint'] mixed_case_fields = ['Name', 'Fingerprint'] table_rows = [] try: endpoints = db.deployment_get(deploy_id)['endpoints'] for endpoint_dict in endpoints: clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict)) nova_client = clients.nova() for keypair in nova_client.keypairs.list(): data = [keypair.name, keypair.fingerprint] table_rows.append(utils.Struct(**dict(zip(headers, data)))) except exceptions.InvalidArgumentsException: print(_("Authentication Issues: %s") % sys.exc_info()[1]) return (1) common_cliutils.print_list(table_rows, fields=headers, mixed_case_fields=mixed_case_fields)
def _create_tenant_users(cls, args): """Create tenant with users and their endpoints. This is suitable for using with pool of threads. :param args: tuple arguments, for Pool.imap() :returns: tuple (dict tenant, list users) """ admin_endpoint, users_num, project_dom, user_dom, task_id, i = args users = [] client = keystone.wrap(osclients.Clients(admin_endpoint).keystone()) tenant = client.create_project( cls.PATTERN_TENANT % { "task_id": task_id, "iter": i }, project_dom) LOG.debug("Creating %d users for tenant %s" % (users_num, tenant.id)) for user_id in range(users_num): username = cls.PATTERN_USER % { "tenant_id": tenant.id, "uid": user_id } user = client.create_user(username, "password", "*****@*****.**" % username, tenant.id, user_dom) user_endpoint = endpoint.Endpoint(client.auth_url, user.name, "password", tenant.name, consts.EndpointPermission.USER, client.region_name, project_domain_name=project_dom, user_domain_name=user_dom) users.append({ "id": user.id, "endpoint": user_endpoint, "tenant_id": tenant.id }) return ({"id": tenant.id, "name": tenant.name}, users)
def keypairs(self, deploy_id=None): """Display available ssh keypairs.""" headers = ['Name', 'Fingerprint'] mixed_case_fields = ['Name', 'Fingerprint'] table_rows = [] try: for endpoint_dict in self._get_endpoints(deploy_id): clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict)) nova_client = clients.nova() for keypair in nova_client.keypairs.list(): data = [keypair.name, keypair.fingerprint] table_rows.append(utils.Struct(**dict(zip(headers, data)))) common_cliutils.print_list(table_rows, fields=headers, mixed_case_fields=mixed_case_fields) except exceptions.InvalidArgumentsException as e: print(_("Authentication Issues: %s") % e) return(1)
def networks(self, deploy_id=None): """Display configured networks.""" headers = ['ID', 'Label', 'CIDR'] mixed_case_fields = ['ID', 'Label', 'CIDR'] table_rows = [] try: for endpoint_dict in self._get_endpoints(deploy_id): clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict)) nova_client = clients.nova() for network in nova_client.networks.list(): data = [network.id, network.label, network.cidr] table_rows.append(utils.Struct(**dict(zip(headers, data)))) common_cliutils.print_list(table_rows, fields=headers, mixed_case_fields=mixed_case_fields) except exceptions.InvalidArgumentsException as e: print(_("Authentication Issues: %s") % e) return(1)
def __init__(self, deploy_id): self.endpoint = db.deployment_get(deploy_id)['endpoints'][0] self.clients = osclients.Clients(endpoint.Endpoint(**self.endpoint)) try: self.keystoneclient = self.clients.verified_keystone() except exceptions.InvalidAdminException: msg = _('Admin permission is required to run tempest. User %s ' 'doesn\'t have admin role') % self.endpoint['username'] raise exceptions.TempestConfigCreationFailure(message=msg) self.available_services = [ service['name'] for service in self.keystoneclient.service_catalog.get_data() ] self.conf = configparser.ConfigParser() self.conf.read(os.path.join(os.path.dirname(__file__), 'config.ini')) self.deploy_id = deploy_id self.data_path = os.path.join(os.path.expanduser('~'), '.rally', 'tempest', 'data') if not os.path.exists(self.data_path): os.makedirs(self.data_path) self.img_path = os.path.join(self.data_path, CONF.image.cirros_image) if not os.path.isfile(self.img_path): self._load_img()
def secgroups(self, deploy_id=None): """Display security groups.""" headers = ['ID', 'Name', 'Description'] mixed_case_fields = ['ID', 'Name', 'Description'] table_rows = [] try: for endpoint_dict in self._get_endpoints(deploy_id): clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict)) nova_client = clients.nova() for secgroup in nova_client.security_groups.list(): data = [secgroup.id, secgroup.name, secgroup.description] table_rows.append(utils.Struct(**dict(zip(headers, data)))) common_cliutils.print_list( table_rows, fields=headers, mixed_case_fields=mixed_case_fields) except exceptions.InvalidArgumentsException as e: print(_("Authentication Issues: %s") % e) return(1)
def __init__(self, deploy_id): self.endpoint = db.deployment_get(deploy_id)['admin'] self.clients = osclients.Clients(endpoint.Endpoint(**self.endpoint)) try: self.keystoneclient = self.clients.verified_keystone() except exceptions.InvalidAdminException: msg = (_("Admin permission is required to generate tempest " "configuration file. User %s doesn't have admin role.") % self.endpoint['username']) raise TempestConfigCreationFailure(msg) self.available_services = self.clients.services().values() self.conf = configparser.ConfigParser() self.conf.read(os.path.join(os.path.dirname(__file__), 'config.ini')) self.deploy_id = deploy_id self.data_path = os.path.join(os.path.expanduser('~'), '.rally', 'tempest', 'data') if not os.path.exists(self.data_path): os.makedirs(self.data_path) self.img_path = os.path.join(self.data_path, CONF.image.cirros_image) if not os.path.isfile(self.img_path): self._load_img()
def setUp(self): super(OSClientsTestCase, self).setUp() self.endpoint = endpoint.Endpoint("http://auth_url", "use", "pass", "tenant") self.clients = osclients.Clients(self.endpoint)