Esempio n. 1
0
    def setUpClass(cls):
        os = clients.AdminManager(interface=cls._interface)
        cls.client = os.identity_client
        cls.token_client = os.token_client
        cls.endpoints_client = os.endpoints_client
        cls.v3_client = os.identity_v3_client
        cls.service_client = os.service_client

        if not cls.client.has_admin_extensions():
            raise cls.skipException("Admin extensions disabled")

        cls.data = DataGenerator(cls.client)

        os = clients.Manager(interface=cls._interface)
        cls.non_admin_client = os.identity_client
Esempio n. 2
0
 def _remove_admin_role(self, tenant_id):
     LOG.debug("Remove admin user role for tenant: %s", tenant_id)
     # Must initialize Admin Manager for each user role
     # Otherwise authentication exception is thrown, weird
     id_cl = clients.Manager(
         credentials.get_configured_admin_credentials()).identity_client
     if (self._tenant_exists(tenant_id)):
         try:
             id_cl.delete_role_from_user_on_project(tenant_id,
                                                    self.admin_id,
                                                    self.admin_role_id)
         except Exception as ex:
             LOG.exception(
                 "Failed removing role from tenant which still"
                 "exists, exception: %s", ex)
Esempio n. 3
0
 def _wrap_creds_with_network(self, hash):
     creds_dict = self.hash_dict['creds'][hash]
     credential = cred_provider.get_credentials(
         identity_version=self.identity_version, **creds_dict)
     net_creds = cred_provider.TestResources(credential)
     net_clients = clients.Manager(credentials=credential)
     compute_network_client = net_clients.compute_networks_client
     net_name = self.hash_dict['networks'].get(hash, None)
     try:
         network = fixed_network.get_network_from_name(
             net_name, compute_network_client)
     except exceptions.InvalidConfiguration:
         network = {}
     net_creds.set_resources(network=network)
     return net_creds
Esempio n. 4
0
    def resource_setup(cls):
        cls.set_network_resources()
        super(BaseObjectTest, cls).resource_setup()
        if not CONF.service_available.swift:
            skip_msg = ("%s skipped as swift is not available" % cls.__name__)
            raise cls.skipException(skip_msg)
        cls.isolated_creds = isolated_creds.IsolatedCreds(
            cls.__name__, network_resources=cls.network_resources)
        # Get isolated creds for normal user
        cls.os = clients.Manager(cls.isolated_creds.get_primary_creds())
        # Get isolated creds for admin user
        cls.os_admin = clients.Manager(cls.isolated_creds.get_admin_creds())
        # Get isolated creds for alt user
        cls.os_alt = clients.Manager(cls.isolated_creds.get_alt_creds())

        cls.object_client = cls.os.object_client
        cls.container_client = cls.os.container_client
        cls.account_client = cls.os.account_client
        cls.custom_object_client = cls.os.custom_object_client
        cls.token_client = cls.os_admin.token_client
        cls.identity_admin_client = cls.os_admin.identity_client
        cls.custom_account_client = cls.os.custom_account_client
        cls.object_client_alt = cls.os_alt.object_client
        cls.container_client_alt = cls.os_alt.container_client
        cls.identity_client_alt = cls.os_alt.identity_client

        # Make sure we get fresh auth data after assigning swift role
        cls.object_client.auth_provider.clear_auth()
        cls.container_client.auth_provider.clear_auth()
        cls.account_client.auth_provider.clear_auth()
        cls.custom_object_client.auth_provider.clear_auth()
        cls.custom_account_client.auth_provider.clear_auth()
        cls.object_client_alt.auth_provider.clear_auth()
        cls.container_client_alt.auth_provider.clear_auth()

        cls.data = SwiftDataGenerator(cls.identity_admin_client)
Esempio n. 5
0
    def setUpClass(cls):
        # No network resources required for this test
        cls.set_network_resources()
        super(AuthorizationTestJSON, cls).setUpClass()
        if not cls.multi_user:
            msg = "Need >1 user"
            raise cls.skipException(msg)
        cls.client = cls.os.servers_client
        cls.images_client = cls.os.images_client
        cls.keypairs_client = cls.os.keypairs_client
        cls.security_client = cls.os.security_groups_client

        if CONF.compute.allow_tenant_isolation:
            creds = cls.isolated_creds.get_alt_creds()
            cls.alt_manager = clients.Manager(credentials=creds)
        else:
            # Use the alt_XXX credentials in the config file
            cls.alt_manager = clients.AltManager()

        cls.alt_client = cls.alt_manager.servers_client
        cls.alt_images_client = cls.alt_manager.images_client
        cls.alt_keypairs_client = cls.alt_manager.keypairs_client
        cls.alt_security_client = cls.alt_manager.security_groups_client

        resp, server = cls.create_test_server(wait_until='ACTIVE')
        resp, cls.server = cls.client.get_server(server['id'])

        name = data_utils.rand_name('image')
        resp, body = cls.images_client.create_image(server['id'], name)
        image_id = data_utils.parse_image_id(resp['location'])
        cls.images_client.wait_for_image_status(image_id, 'ACTIVE')
        resp, cls.image = cls.images_client.get_image(image_id)

        cls.keypairname = data_utils.rand_name('keypair')
        resp, keypair = \
            cls.keypairs_client.create_keypair(cls.keypairname)

        name = data_utils.rand_name('security')
        description = data_utils.rand_name('description')
        resp, cls.security_group = cls.security_client.create_security_group(
            name, description)

        parent_group_id = cls.security_group['id']
        ip_protocol = 'tcp'
        from_port = 22
        to_port = 22
        resp, cls.rule = cls.security_client.create_security_group_rule(
            parent_group_id, ip_protocol, from_port, to_port)
Esempio n. 6
0
    def resource_setup(cls):
        trustor_user = {
            'name': data_utils.rand_name('user'),
            'password': data_utils.rand_password(),
        }
        cls.trustor = cls.admin_client.users_v3_client.create_user(
            **trustor_user)['user']['id']
        cls.addClassResourceCleanup(
            cls.admin_client.users_v3_client.delete_user,
            user_id=cls.trustor)
        cls.trustee = cls.admin_client.users_v3_client.create_user(
            name=data_utils.rand_name())['user']['id']
        cls.addClassResourceCleanup(
            cls.admin_client.users_v3_client.delete_user,
            user_id=cls.trustee)
        cls.project = cls.admin_client.projects_client.create_project(
            name=data_utils.rand_name()
        )['project']['id']
        cls.addClassResourceCleanup(
            cls.admin_client.projects_client.delete_project,
            project_id=cls.project)
        cls.roles = [
            {'id': cls.admin_client.roles_v3_client.create_role(
                name=data_utils.rand_name())['role']['id']}
        ]
        cls.addClassResourceCleanup(
            cls.admin_client.roles_v3_client.delete_role,
            role_id=cls.roles[0]['id'])
        cls.admin_client.roles_v3_client.create_user_role_on_project(
            project_id=cls.project,
            user_id=cls.trustor,
            role_id=cls.roles[0]['id']
        )
        creds = auth.KeystoneV3Credentials(
            user_id=cls.trustor,
            password=trustor_user['password'],
            project_id=cls.project)
        auth_provider = clients.get_auth_provider(creds)
        creds = auth_provider.fill_credentials()
        user_client = clients.Manager(credentials=creds)
        cls.user_trust_client = user_client.trusts_client

        cls.admin_role_id = cls.admin_client.roles_v3_client.list_roles(
            name='admin')['roles'][0]['id']
        cls.member_role_id = cls.admin_client.roles_v3_client.list_roles(
            name='member')['roles'][0]['id']
        cls.reader_role_id = cls.admin_client.roles_v3_client.list_roles(
            name='reader')['roles'][0]['id']
def main(opts=None):
    print('Running config verification...')
    if opts is None:
        print("Use of: 'verify-tempest-config' is deprecated, "
              "please use: 'tempest verify-config'")
        opts = parse_args()
    update = opts.update
    replace = opts.replace_ext
    global CONF_PARSER

    if update:
        conf_file = _get_config_file()
        CONF_PARSER = moves.configparser.ConfigParser()
        CONF_PARSER.optionxform = str
        CONF_PARSER.readfp(conf_file)

    # Indicate not to create network resources as part of getting credentials
    net_resources = {
        'network': False,
        'router': False,
        'subnet': False,
        'dhcp': False
    }
    icreds = credentials.get_credentials_provider(
        'verify_tempest_config', network_resources=net_resources)
    try:
        os = clients.Manager(icreds.get_primary_creds().credentials)
        services = check_service_availability(os, update)
        results = {}
        for service in ['nova', 'cinder', 'neutron', 'swift']:
            if service not in services:
                continue
            results = verify_extensions(os, service, results)

        # Verify API versions of all services in the keystone catalog and
        # keystone itself.
        services.append('keystone')
        for service in services:
            verify_api_versions(os, service, update)

        display_results(results, update, replace)
        if update:
            conf_file.close()
            if opts.output:
                with open(opts.output, 'w+') as outfile:
                    CONF_PARSER.write(outfile)
    finally:
        icreds.clear_creds()
Esempio n. 8
0
    def create_trustor_and_roles(self):
        # Get trustor project ID, use the admin project
        self.trustor_project_name = self.client.tenant_name
        self.trustor_project_id = self.get_tenant_by_name(
            self.trustor_project_name)['id']
        self.assertIsNotNone(self.trustor_project_id)

        # Create a trustor User
        self.trustor_username = data_utils.rand_name('user-')
        u_desc = self.trustor_username + 'description'
        u_email = self.trustor_username + '@testmail.xx'
        self.trustor_password = data_utils.rand_name('pass-')
        _, user = self.client.create_user(self.trustor_username,
                                          description=u_desc,
                                          password=self.trustor_password,
                                          email=u_email,
                                          project_id=self.trustor_project_id)
        self.trustor_user_id = user['id']

        # And two roles, one we'll delegate and one we won't
        self.delegated_role = data_utils.rand_name('DelegatedRole-')
        self.not_delegated_role = data_utils.rand_name('NotDelegatedRole-')

        _, role = self.client.create_role(self.delegated_role)
        self.delegated_role_id = role['id']

        _, role = self.client.create_role(self.not_delegated_role)
        self.not_delegated_role_id = role['id']

        # Assign roles to trustor
        self.client.assign_user_role(self.trustor_project_id,
                                     self.trustor_user_id,
                                     self.delegated_role_id)
        self.client.assign_user_role(self.trustor_project_id,
                                     self.trustor_user_id,
                                     self.not_delegated_role_id)

        # Get trustee user ID, use the demo user
        trustee_username = self.non_admin_client.user
        self.trustee_user_id = self.get_user_by_name(trustee_username)['id']
        self.assertIsNotNone(self.trustee_user_id)

        # Initialize a new client with the trustor credentials
        creds = auth.get_credentials(username=self.trustor_username,
                                     password=self.trustor_password,
                                     tenant_name=self.trustor_project_name)
        os = clients.Manager(credentials=creds, interface=self._interface)
        self.trustor_client = os.identity_v3_client
Esempio n. 9
0
    def resource_setup(cls):
        super(BaseTestCase, cls).resource_setup()

        credentials = cls.isolated_creds.get_primary_creds()
        mgr = tempest_clients.Manager(credentials=credentials)
        auth_provider = mgr.get_auth_provider(credentials)
        client_args = [auth_provider, 'network', 'regionOne']

        cls.load_balancers_client = (
            load_balancers_client.LoadBalancersClientJSON(*client_args))
        cls.listeners_client = (
            listeners_client.ListenersClientJSON(*client_args))
        cls.pools_client = pools_client.PoolsClientJSON(*client_args)
        cls.members_client = members_client.MembersClientJSON(*client_args)
        cls.health_monitors_client = (
            health_monitors_client.HealthMonitorsClientJSON(*client_args))
Esempio n. 10
0
    def _get_admin_clients(self):
        """Returns a tuple with instances of the following admin clients

        (in this order):
            identity
            network
        """
        os = clients.Manager(self.default_admin_creds)
        if self.identity_version == 'v2':
            return (os.identity_client, os.tenants_client, os.roles_client,
                    os.network_client, os.networks_client, os.subnets_client,
                    os.ports_client, os.security_groups_client)
        else:
            return (os.identity_v3_client, None, None, os.network_client,
                    os.networks_client, os.subnets_client, os.ports_client,
                    os.security_groups_client)
Esempio n. 11
0
 def setUpClass(cls):
     super(BaseVolumeV1AdminTest, cls).setUpClass()
     cls.adm_user = CONF.identity.admin_username
     cls.adm_pass = CONF.identity.admin_password
     cls.adm_tenant = CONF.identity.admin_tenant_name
     if not all((cls.adm_user, cls.adm_pass, cls.adm_tenant)):
         msg = ("Missing Volume Admin API credentials " "in configuration.")
         raise cls.skipException(msg)
     if CONF.compute.allow_tenant_isolation:
         cls.os_adm = clients.Manager(cls.isolated_creds.get_admin_creds(),
                                      interface=cls._interface)
     else:
         cls.os_adm = clients.AdminManager(interface=cls._interface)
     cls.client = cls.os_adm.volume_types_client
     cls.hosts_client = cls.os_adm.volume_hosts_client
     cls.quotas_client = cls.os_adm.volume_quotas_client
Esempio n. 12
0
    def setUpClass(cls):
        super(BaseV1ImageMembersTest, cls).setUpClass()
        if CONF.compute.allow_tenant_isolation:
            creds = cls.isolated_creds.get_alt_creds()
            username, tenant_name, password = creds
            cls.os_alt = clients.Manager(username=username,
                                         password=password,
                                         tenant_name=tenant_name)
            cls.alt_tenant_id = cls.isolated_creds.get_alt_tenant()['id']
        else:
            cls.os_alt = clients.AltManager()
            identity_client = cls._get_identity_admin_client()
            cls.alt_tenant_id = identity_client.get_tenant_by_name(
                cls.os_alt.credentials['tenant_name'])['id']

        cls.alt_img_cli = cls.os_alt.image_client
Esempio n. 13
0
 def setUpClass(cls):
     super(BaseAdminNetworkTest, cls).setUpClass()
     admin_username = CONF.compute_admin.username
     admin_password = CONF.compute_admin.password
     admin_tenant = CONF.compute_admin.tenant_name
     if not (admin_username and admin_password and admin_tenant):
         msg = ("Missing Administrative Network API credentials "
                "in configuration.")
         raise cls.skipException(msg)
     if (CONF.compute.allow_tenant_isolation
             or cls.force_tenant_isolation is True):
         cls.os_adm = clients.Manager(cls.isolated_creds.get_admin_creds(),
                                      interface=cls._interface)
     else:
         cls.os_adm = clients.ComputeAdminManager(interface=cls._interface)
     cls.admin_client = cls.os_adm.network_client
Esempio n. 14
0
 def setUpClass(cls):
     super(BaseNetworkTest, cls).setUpClass()
     os = clients.Manager(interface=cls._interface)
     cls.network_cfg = os.config.network
     if not cls.config.service_available.neutron:
         raise cls.skipException("Neutron support is required")
     cls.client = os.network_client
     cls.networks = []
     cls.subnets = []
     cls.ports = []
     cls.routers = []
     cls.pools = []
     cls.vips = []
     cls.members = []
     cls.health_monitors = []
     cls.vpnservices = []
Esempio n. 15
0
 def __init__(self):
     network_resources = {
         'network': False,
         'router': False,
         'subnet': False,
         'dhcp': False,
     }
     self.cred_provider = credentials.get_credentials_provider(
         name='InputScenarioUtils',
         identity_version=CONF.identity.auth_version,
         network_resources=network_resources)
     os = clients.Manager(self.cred_provider.get_primary_creds())
     self.images_client = os.images_client
     self.flavors_client = os.flavors_client
     self.image_pattern = CONF.input_scenario.image_regex
     self.flavor_pattern = CONF.input_scenario.flavor_regex
Esempio n. 16
0
    def setUpClass(cls):
        super(AccountQuotasTest, cls).setUpClass()
        cls.container_name = rand_name(name="TestContainer")
        cls.container_client.create_container(cls.container_name)

        cls.data.setup_test_user()

        cls.os_reselleradmin = clients.Manager(cls.data.test_user,
                                               cls.data.test_password,
                                               cls.data.test_tenant)

        # Retrieve the ResellerAdmin role id
        reseller_role_id = None
        try:
            _, roles = cls.os_admin.identity_client.list_roles()
            reseller_role_id = next(r['id'] for r in roles
                                    if r['name'] == 'ResellerAdmin')
        except StopIteration:
            msg = "No ResellerAdmin role found"
            raise exceptions.NotFound(msg)

        # Retrieve the ResellerAdmin tenant id
        _, users = cls.os_admin.identity_client.get_users()
        reseller_user_id = next(usr['id'] for usr in users
                                if usr['name'] == cls.data.test_user)

        # Retrieve the ResellerAdmin tenant id
        _, tenants = cls.os_admin.identity_client.list_tenants()
        reseller_tenant_id = next(tnt['id'] for tnt in tenants
                                  if tnt['name'] == cls.data.test_tenant)

        # Assign the newly created user the appropriate ResellerAdmin role
        cls.os_admin.identity_client.assign_user_role(reseller_tenant_id,
                                                      reseller_user_id,
                                                      reseller_role_id)

        # Retrieve a ResellerAdmin auth token and use it to set a quota
        # on the client's account
        cls.reselleradmin_token = cls.token_client.get_token(
            cls.data.test_user, cls.data.test_password, cls.data.test_tenant)

        headers = {
            "X-Auth-Token": cls.reselleradmin_token,
            "X-Account-Meta-Quota-Bytes": "20"
        }

        cls.os.custom_account_client.request("POST", "", headers, "")
    def setUpClass(cls):
        super(NeutronResourcesTestJSON, cls).setUpClass()
        if not CONF.orchestration.image_ref:
            raise cls.skipException("No image available to test")
        os = clients.Manager()
        if not CONF.service_available.neutron:
            raise cls.skipException("Neutron support is required")
        cls.network_client = os.network_client
        cls.stack_name = data_utils.rand_name('heat')
        template = cls.load_template('neutron_basic')
        cls.keypair_name = (CONF.orchestration.keypair_name or
                            cls._create_keypair()['name'])
        cls.external_router_id = cls._get_external_router_id()
        cls.external_network_id = CONF.network.public_network_id

        # create the stack
        cls.stack_identifier = cls.create_stack(
            cls.stack_name,
            template,
            parameters={
                'KeyName': cls.keypair_name,
                'InstanceType': CONF.orchestration.instance_type,
                'ImageId': CONF.orchestration.image_ref,
                'ExternalRouterId': cls.external_router_id,
                'ExternalNetworkId': cls.external_network_id,
                'timeout': CONF.orchestration.build_timeout
            })
        cls.stack_id = cls.stack_identifier.split('/')[1]
        try:
            cls.client.wait_for_stack_status(cls.stack_id, 'CREATE_COMPLETE')
            _, resources = cls.client.list_resources(cls.stack_identifier)
        except exceptions.TimeoutException as e:
            # attempt to log the server console to help with debugging
            # the cause of the server not signalling the waitcondition
            # to heat.
            resp, body = cls.client.get_resource(cls.stack_identifier,
                                                 'Server')
            server_id = body['physical_resource_id']
            LOG.debug('Console output for %s', server_id)
            resp, output = cls.servers_client.get_console_output(
                server_id, None)
            LOG.debug(output)
            raise e

        cls.test_resources = {}
        for resource in resources:
            cls.test_resources[resource['logical_resource_id']] = resource
Esempio n. 18
0
 def resource_setup(cls):
     super(SwiftResourcesTestJSON, cls).resource_setup()
     cls.stack_name = data_utils.rand_name('heat')
     template = cls.read_template('swift_basic')
     os = clients.Manager()
     if not CONF.service_available.swift:
         raise cls.skipException("Swift support is required")
     cls.account_client = os.account_client
     cls.container_client = os.container_client
     # create the stack
     cls.stack_identifier = cls.create_stack(cls.stack_name, template)
     cls.stack_id = cls.stack_identifier.split('/')[1]
     cls.client.wait_for_stack_status(cls.stack_id, 'CREATE_COMPLETE')
     cls.test_resources = {}
     resources = cls.client.list_resources(cls.stack_identifier)
     for resource in resources:
         cls.test_resources[resource['logical_resource_id']] = resource
Esempio n. 19
0
    def setUpClass(cls):
        super(ImageMembersTests, cls).setUpClass()
        if cls.config.compute.allow_tenant_isolation:
            creds = cls.isolated_creds.get_alt_creds()
            username, tenant_name, password = creds
            cls.os_alt = clients.Manager(username=username,
                                         password=password,
                                         tenant_name=tenant_name)
        else:
            cls.os_alt = clients.AltManager()

        alt_tenant_name = cls.os_alt.tenant_name
        identity_client = cls._get_identity_admin_client()
        _, tenants = identity_client.list_tenants()
        cls.alt_tenant_id = [
            tnt['id'] for tnt in tenants if tnt['name'] == alt_tenant_name
        ][0]
    def setUp(self):
        super(TestNeutronV2QosDriver, self).setUp()
        self.qos_rules = []
        self.qos_policies = []

        self.os_primary = clients.Manager(
            self.os_admin.auth_provider.credentials)

        body = {
            "config": {
                "username": CONF.auth.admin_username,
                "tenant_name": CONF.auth.admin_project_name,
                "password": CONF.auth.admin_password,
                "auth_url": CONF.identity.uri
            },
            "driver": self.DATASOURCE_NAME,
            "name": self.DATASOURCE_NAME
        }
        try:
            self.os_admin.congress_client.create_datasource(body)['id']
        except exceptions.Conflict:
            pass

        self.datasource_id = manager_congress.get_datasource_id(
            self.os_admin.congress_client, self.DATASOURCE_NAME)

        # Get client
        self.admin_qos_client = self.os_admin.qos_client
        self.admin_qos_rule_client = self.os_admin.qos_rule_client
        self.networks_client = self.os_primary.networks_client
        self.ports_client = self.os_primary.ports_client

        # Create qos and qos rule
        self.qos_policy = self._create_qos_policy('test_qos_policy',
                                                  description="test",
                                                  share=True)
        self.qos_rule = self._create_qos_bandwidth_limit_rule(
            self.qos_policy['id'], 1000, 1000)

        # Associate policy with port
        body = self.networks_client.create_network(name="test_qos_network")
        self.network = body["network"]
        body = self.ports_client.create_port(network_id=self.network['id'])
        self.port = body["port"]
        self.ports_client.update_port(self.port['id'],
                                      qos_policy_id=self.qos_policy['id'])
Esempio n. 21
0
 def setup_credentials(cls):
     cls.set_network_resources()
     super(BaseObjectTest, cls).setup_credentials()
     operator_role = CONF.object_storage.operator_role
     # There are no credentials by type used by object storage tests so
     # isolated_creds must still be initialized
     cls.isolated_creds = credentials.get_isolated_credentials(
         cls.__name__, network_resources=cls.network_resources)
     if not cls.isolated_creds.is_role_available(operator_role):
         skip_msg = ("%s skipped because the configured credential provider"
                     " is not able to provide credentials with the %s role "
                     "assigned." % (cls.__name__, operator_role))
         raise cls.skipException(skip_msg)
     else:
         # Get isolated creds for normal user
         cls.os = clients.Manager(
             cls.isolated_creds.get_creds_by_roles([operator_role]))
Esempio n. 22
0
    def get_tenant_network(cls):
        """Get the network to be used in testing

        :return: network dict including 'id' and 'name'
        """
        # Make sure isolated_creds exists and get a network client
        networks_client = cls.get_client_manager().networks_client
        cred_provider = cls._get_credentials_provider()
        # In case of nova network, isolated tenants are not able to list the
        # network configured in fixed_network_name, even if the can use it
        # for their servers, so using an admin network client to validate
        # the network name
        if (not CONF.service_available.neutron
                and credentials.is_admin_available()):
            admin_creds = cred_provider.get_admin_creds()
            networks_client = clients.Manager(admin_creds).networks_client
        return fixed_network.get_tenant_network(cred_provider, networks_client)
Esempio n. 23
0
    def resource_setup(cls):
        super(BaseOrchestrationTest, cls).resource_setup()
        cls.os = clients.Manager()
        if not CONF.service_available.heat:
            raise cls.skipException("Heat support is required")
        cls.build_timeout = CONF.orchestration.build_timeout
        cls.build_interval = CONF.orchestration.build_interval

        cls.orchestration_client = cls.os.orchestration_client
        cls.client = cls.orchestration_client
        cls.servers_client = cls.os.servers_client
        cls.keypairs_client = cls.os.keypairs_client
        cls.network_client = cls.os.network_client
        cls.volumes_client = cls.os.volumes_client
        cls.images_v2_client = cls.os.image_client_v2
        cls.stacks = []
        cls.keypairs = []
        cls.images = []
Esempio n. 24
0
 def setUpClass(cls):
     super(BaseV2MemberImageTest, cls).setUpClass()
     if CONF.compute.allow_tenant_isolation:
         creds = cls.isolated_creds.get_alt_creds()
         username, tenant_name, password = creds
         cls.os_alt = clients.Manager(username=username,
                                      password=password,
                                      tenant_name=tenant_name,
                                      interface=cls._interface)
         cls.alt_tenant_id = cls.isolated_creds.get_alt_tenant()['id']
     else:
         cls.os_alt = clients.AltManager()
         alt_tenant_name = cls.os_alt.tenant_name
         identity_client = cls._get_identity_admin_client()
         cls.alt_tenant_id = identity_client.get_tenant_by_name(
             alt_tenant_name)['id']
     cls.os_img_client = cls.os.image_client_v2
     cls.alt_img_client = cls.os_alt.image_client_v2
Esempio n. 25
0
    def setUpClass(cls):
        super(ImagesTestJSON, cls).setUpClass()
        cls.client = cls.images_client
        cls.servers_client = cls.servers_client

        cls.image_ids = []

        if compute.MULTI_USER:
            if cls.config.compute.allow_tenant_isolation:
                creds = cls._get_isolated_creds()
                username, tenant_name, password = creds
                cls.alt_manager = clients.Manager(username=username,
                                                  password=password,
                                                  tenant_name=tenant_name)
            else:
                # Use the alt_XXX credentials in the config file
                cls.alt_manager = clients.AltManager()
            cls.alt_client = cls.alt_manager.images_client
Esempio n. 26
0
 def setUpClass(cls):
     super(BaseComputeAdminTest, cls).setUpClass()
     admin_username = cls.config.compute_admin.username
     admin_password = cls.config.compute_admin.password
     admin_tenant = cls.config.compute_admin.tenant_name
     if not (admin_username and admin_password and admin_tenant):
         msg = ("Missing Compute Admin API credentials "
                "in configuration.")
         raise cls.skipException(msg)
     if cls.config.compute.allow_tenant_isolation:
         creds = cls._get_isolated_creds(admin=True)
         admin_username, admin_tenant_name, admin_password = creds
         cls.os_adm = clients.Manager(username=admin_username,
                                      password=admin_password,
                                      tenant_name=admin_tenant_name,
                                      interface=cls._interface)
     else:
         cls.os_adm = clients.ComputeAdminManager(interface=cls._interface)
Esempio n. 27
0
    def get_client_manager(cls, identity_version=None):
        """
        Returns an OpenStack client manager
        """
        force_tenant_isolation = getattr(cls, 'force_tenant_isolation', None)
        identity_version = identity_version or CONF.identity.auth_version

        if (not hasattr(cls, 'isolated_creds')
                or not cls.isolated_creds.name == cls.__name__):
            cls.isolated_creds = credentials.get_isolated_credentials(
                name=cls.__name__,
                network_resources=cls.network_resources,
                force_tenant_isolation=force_tenant_isolation,
                identity_version=identity_version)

        creds = cls.isolated_creds.get_primary_creds()
        os = clients.Manager(credentials=creds, service=cls._service)
        return os
Esempio n. 28
0
 def _create_server(self, project, **kwargs):
     creds = credentials_factory.get_credentials(fill_in=False,
                                                 identity_version='v3',
                                                 **{
                                                     'user_id':
                                                     project['user']['id'],
                                                     'password':
                                                     '******',
                                                     'project_name':
                                                     project['name']
                                                 })
     client = tempest_clients.Manager(creds).servers_client
     kwargs['flavorRef'] = CONF.compute.flavor_ref
     kwargs['imageRef'] = CONF.compute.image_ref
     server = client.create_server(**kwargs)['server']
     self.addCleanup(self.admin_client.servers_client.delete_server,
                     server['id'])
     return server
Esempio n. 29
0
    def validate_service(cls, service):
        """Validate whether the service passed to ``__init__`` exists."""
        service = service.lower().strip() if service else None

        # Cache the list of available services in memory to avoid needlessly
        # doing an API call every time.
        if not hasattr(cls, 'available_services'):
            admin_mgr = clients.Manager(
                credentials.get_configured_admin_credentials())
            services_client = (admin_mgr.identity_services_v3_client
                               if CONF.identity_feature_enabled.api_v3
                               else admin_mgr.identity_services_client)
            services = services_client.list_services()['services']
            cls.available_services = [s['name'] for s in services]

        if not service or service not in cls.available_services:
            LOG.debug("%s is NOT a valid service.", service)
            raise rbac_exceptions.RbacInvalidService(
                "%s is NOT a valid service." % service)
Esempio n. 30
0
    def _init_state(self):
        print("Initializing saved state.")
        data = {}
        self.global_services = cleanup_service.get_global_cleanup_services()
        self.admin_mgr = clients.Manager(
            credentials.get_configured_admin_credentials())
        admin_mgr = self.admin_mgr
        kwargs = {'data': data,
                  'is_dry_run': False,
                  'saved_state_json': data,
                  'is_preserve': False,
                  'is_save_state': True}
        for service in self.global_services:
            svc = service(admin_mgr, **kwargs)
            svc.run()

        with open(SAVED_STATE_JSON, 'w+') as f:
            f.write(json.dumps(data,
                    sort_keys=True, indent=2, separators=(',', ': ')))