Exemplo n.º 1
0
 def test_get_configured_admin_credentials_not_fill_not_valid(
         self, mock_get_credentials):
     cfg.CONF.set_default('auth_version', 'v2', 'identity')
     expected_result = mock.Mock()
     expected_result.is_valid.return_value = False
     mock_get_credentials.return_value = expected_result
     with testtools.ExpectedException(exceptions.InvalidConfiguration,
                                      value_re='.*\n.*identity version v2'):
         cf.get_configured_admin_credentials(fill_in=False)
Exemplo n.º 2
0
 def test_get_configured_admin_credentials_not_fill_not_valid(
         self, mock_get_credentials):
     cfg.CONF.set_default('auth_version', 'v2', 'identity')
     expected_result = mock.Mock()
     expected_result.is_valid.return_value = False
     mock_get_credentials.return_value = expected_result
     with testtools.ExpectedException(exceptions.InvalidConfiguration,
                                      value_re='.*\n.*identity version v2'):
         cf.get_configured_admin_credentials(fill_in=False)
Exemplo n.º 3
0
    def _get_dynamic_creds(cls, name, network_resources=None):
        identity_version = CONF.identity.auth_version
        if identity_version == 'v3':
            identity_uri = CONF.identity.uri_v3
            identity_admin_endpoint_type = CONF.identity.v3_endpoint_type
        elif identity_version == 'v2':
            identity_uri = CONF.identity.uri
            identity_admin_endpoint_type = CONF.identity.v2_admin_endpoint_type

        return dynamic_creds.DynamicCredentialProvider(
            identity_version=identity_version,
            name=name,
            network_resources=network_resources,
            credentials_domain=CONF.auth.default_credentials_domain_name,
            admin_role=CONF.identity.admin_role,
            admin_creds=common_creds.get_configured_admin_credentials(),
            identity_admin_domain_scope=CONF.identity.admin_domain_scope,
            identity_admin_role=CONF.identity.admin_role,
            extra_roles=None,
            neutron_available=CONF.service_available.neutron,
            create_networks=(
                CONF.share.create_networks_when_multitenancy_enabled),
            project_network_cidr=CONF.network.project_network_cidr,
            project_network_mask_bits=CONF.network.project_network_mask_bits,
            public_network_id=CONF.network.public_network_id,
            resource_prefix='tempest',
            identity_admin_endpoint_type=identity_admin_endpoint_type,
            identity_uri=identity_uri)
Exemplo n.º 4
0
    def setup_clients(cls):
        super(ScenarioTest, cls).setup_clients()
        # Clients
        cls.admin_flavors_client = cls.admin_manager.flavors_client
        if CONF.service_available.glance:
            # Check if glance v1 is available to determine which client to use.
            if CONF.image_feature_enabled.api_v1:
                cls.image_client = cls.os_primary.image_client
            elif CONF.image_feature_enabled.api_v2:
                cls.image_client = cls.os_primary.image_client_v2
            else:
                raise lib_exc.InvalidConfiguration(
                    'Either api_v1 or api_v2 must be True in '
                    '[image-feature-enabled].')
        # Compute image client
        cls.compute_images_client = cls.os_primary.compute_images_client
        cls.keypairs_client = cls.os_primary.keypairs_client
        # Nova security groups client
        cls.compute_security_groups_client = (
            cls.os_primary.compute_security_groups_client)
        cls.compute_security_group_rules_client = (
            cls.os_primary.compute_security_group_rules_client)
        cls.servers_client = cls.os_primary.servers_client
        # Neutron network client
        cls.networks_client = cls.os_primary.networks_client
        cls.ports_client = cls.os_primary.ports_client

        credentials = common_creds.get_configured_admin_credentials(
            'identity_admin')

        auth_prov = get_auth_provider(credentials)
        cls.os_admin.cyborg_client = (
            clients.CyborgRestClient(auth_prov,
                                     'accelerator',
                                     CONF.identity.region))
Exemplo n.º 5
0
    def get_configured_isolated_creds(cls, type_of_creds='admin'):
        identity_version = CONF.identity.auth_version
        if identity_version == 'v3':
            cls.admin_role = CONF.identity.admin_role
            cls.identity_uri = CONF.identity.uri_v3
        else:
            cls.admin_role = 'admin'
            cls.identity_uri = CONF.identity.uri
        cls.dynamic_cred = dynamic_creds.DynamicCredentialProvider(
            identity_version=CONF.identity.auth_version,
            identity_uri=cls.identity_uri,
            name=cls.__name__,
            admin_role=cls.admin_role,
            admin_creds=common_creds.get_configured_admin_credentials(
                'identity_admin'))
        if type_of_creds == 'primary':
            creds = cls.dynamic_cred.get_primary_creds()
        elif type_of_creds == 'admin':
            creds = cls.dynamic_cred.get_admin_creds()
        elif type_of_creds == 'alt':
            creds = cls.dynamic_cred.get_alt_creds()
        else:
            creds = cls.dynamic_cred.get_credentials(type_of_creds)
        cls.dynamic_cred.type_of_creds = type_of_creds

        return creds.credentials
Exemplo n.º 6
0
 def test_get_configured_admin_credentials_not_fill_valid(
         self, mock_get_credentials):
     cfg.CONF.set_default('auth_version', 'v2', 'identity')
     all_params = [
         ('admin_username', 'username', 'my_name'),
         ('admin_user_domain_name', 'user_domain_name', 'my_dname'),
         ('admin_password', 'password', 'secret'),
         ('admin_project_domain_name', 'project_domain_name', 'my_dname'),
         ('admin_project_name', 'project_name', 'my_pname'),
         ('admin_domain_name', 'domain_name', 'my_dname'),
         ('admin_system', 'system', None),
     ]
     expected_result = mock.Mock()
     expected_result.is_valid.return_value = True
     mock_get_credentials.return_value = expected_result
     for config_item, _, value in all_params:
         cfg.CONF.set_default(config_item, value, 'auth')
     # Build the expected params
     expected_params = dict([(field, value)
                             for _, field, value in all_params])
     expected_params.update(config.service_client_config())
     admin_creds = cf.get_configured_admin_credentials(
         fill_in=False, identity_version='v3')
     mock_get_credentials.assert_called_once_with(fill_in=False,
                                                  identity_version='v3',
                                                  **expected_params)
     self.assertEqual(expected_result, admin_creds)
     expected_result.is_valid.assert_called_once()
Exemplo n.º 7
0
    def init(self, parsed_args):
        cleanup_service.init_conf()
        self.options = parsed_args
        self.admin_mgr = clients.Manager(
            credentials.get_configured_admin_credentials())
        self.dry_run_data = {}
        self.json_data = {}

        self.admin_id = ""
        self.admin_role_id = ""
        self.admin_project_id = ""
        self._init_admin_ids()

        # available services
        self.project_associated_services = (
            cleanup_service.get_project_associated_cleanup_services())
        self.resource_cleanup_services = (
            cleanup_service.get_resource_cleanup_services())
        self.global_services = cleanup_service.get_global_cleanup_services()

        if parsed_args.init_saved_state:
            self._init_state()
            return

        self._load_json()
Exemplo n.º 8
0
 def setup_clients(cls):
     super(BaseAPITest, cls).setup_clients()
     credentials = common_creds.get_configured_admin_credentials(
         'identity_admin')
     auth_prov = get_auth_provider(credentials=credentials)
     cls.os_admin.cyborg_client = (client.CyborgRestClient(
         auth_prov, 'accelerator', CONF.identity.region))
Exemplo n.º 9
0
    def __init__(self,
                 credentials=None):
        """Initialization of Manager class.

        Setup service client and make it available for test cases.
        :param credentials: type Credentials or TestResources
        """
        if credentials is None:
            global ADMIN_CREDS
            if ADMIN_CREDS is None:
                ADMIN_CREDS = common_creds.get_configured_admin_credentials()
            credentials = ADMIN_CREDS
        super(Manager, self).__init__(credentials)
        default_params_with_timeout_values = {
            'build_interval': CONF.compute.build_interval,
            'build_timeout': CONF.compute.build_timeout
        }
        default_params_with_timeout_values.update(self.default_params)

        self.baremetal_client = BaremetalClient(
            self.auth_provider,
            CONF.baremetal.catalog_type,
            CONF.identity.region,
            endpoint_type=CONF.baremetal.endpoint_type,
            **default_params_with_timeout_values)
Exemplo n.º 10
0
    def create_client(self, client_type):
        creds = credentials.get_configured_admin_credentials('identity_admin')
        auth_prov = tempestmanager.get_auth_provider(creds)

        return policy_client.PolicyClient(
            auth_prov, client_type,
            CONF.identity.region)
Exemplo n.º 11
0
 def setup_clients(cls):
     super(BaseIdentityTest, cls).setup_clients()
     credentials = common_creds.get_configured_admin_credentials(
         cls.credential_type, identity_version=cls.identity_version)
     cls.keystone_manager = clients.Manager(credentials=credentials)
     cls.idps_client = cls.keystone_manager.identity_providers_client
     cls.mappings_client = cls.keystone_manager.mapping_rules_client
     cls.sps_client = cls.keystone_manager.service_providers_client
Exemplo n.º 12
0
    def setUp(self):
        super(TestCase, self).setUp()

        credentials = common_creds.get_configured_admin_credentials(
            'identity_admin')

        auth_provider = get_auth_provider(credentials)
        self.client = SolumClient(auth_provider)
        self.builderclient = SolumClient(auth_provider, 'image_builder')
 def __init__(self, credentials=None, api_microversions=None):
     if not credentials:
         credentials = common_creds.get_configured_admin_credentials()
     super(Manager, self).__init__(credentials)
     self.introspection_client = BaremetalIntrospectionClient(
         self.auth_provider,
         CONF.baremetal_introspection.catalog_type,
         CONF.identity.region,
         endpoint_type=CONF.baremetal_introspection.endpoint_type)
    def setup_credentials(cls):
        """Do not create network resources for these tests

        Using public network for ssh
        """
        cls.set_network_resources()
        super(BaseTest, cls).setup_credentials()
        cls.manager = clients.Manager(
            credentials=common_creds.get_configured_admin_credentials())
Exemplo n.º 15
0
 def __init__(self,
              credentials=common_creds.get_configured_admin_credentials(
                  'identity_admin')):
     self.auth_provider = get_auth_provider(credentials)
     self.service_broker_client = service_broker_client.ServiceBrokerClient(
         self.auth_provider)
     self.application_catalog_client = \
         application_catalog_client.ApplicationCatalogClient(
             self.auth_provider)
    def setup_credentials(cls):
        """Do not create network resources for these tests

        Using public network for ssh
        """
        cls.set_network_resources()
        super(BaseTest, cls).setup_credentials()
        cls.manager = clients.Manager(
            credentials=common_creds.get_configured_admin_credentials())
Exemplo n.º 17
0
 def __init__(self,
              credentials=common_creds.get_configured_admin_credentials(
                  'identity_admin'),
              service=None):
     super(Manager, self).__init__(credentials, service)
     self.service_broker_client = service_broker_client.ServiceBrokerClient(
         self.auth_provider)
     self.application_catalog_client = \
         application_catalog_client.ApplicationCatalogClient(
             self.auth_provider)
Exemplo n.º 18
0
    def __init__(self, credentials=None):
        if credentials is None:
            global ADMIN_CREDS
            if ADMIN_CREDS is None:
                ADMIN_CREDS = common_creds.get_configured_admin_credentials()
            credentials = ADMIN_CREDS
        super(Manager, self).__init__(credentials)

        self.artifacts_client = artifacts_client.ArtifactsClient(
            self.auth_provider)
Exemplo n.º 19
0
    def _get_session_for_admin(cls):
        admin_creds = common_creds.get_configured_admin_credentials()
        password = admin_creds.password
        username = admin_creds.username
        user_domain_id = admin_creds.user_domain_id
        project_name = admin_creds.project_name
        project_domain_id = admin_creds.project_domain_id

        return cls._get_session(username, password, user_domain_id,
                                project_name, project_domain_id)
Exemplo n.º 20
0
 def _remove_admin_role(self, project_id):
     LOG.debug("Remove admin user role for projectt: %s", project_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._project_exists(project_id)):
         try:
             id_cl.delete_role_from_user_on_project(project_id,
                                                    self.admin_id,
                                                    self.admin_role_id)
         except Exception as ex:
             LOG.exception("Failed removing role from project which still "
                           "exists, exception: %s", ex)
Exemplo n.º 21
0
 def __init__(self,
              credentials=common_creds.get_configured_admin_credentials(
                  'identity_admin')):
     self.auth_provider = get_auth_provider(credentials)
     self.service_broker_client = service_broker_client.ServiceBrokerClient(
         self.auth_provider)
     if CONF.application_catalog.glare_backend:
         self.artifacts_client = artifacts_client.ArtifactsClient(
             self.auth_provider)
     else:
         self.artifacts_client = None
     self.application_catalog_client = \
         application_catalog_client.ApplicationCatalogClient(
             self.auth_provider)
Exemplo n.º 22
0
 def _remove_admin_role(self, project_id):
     LOG.debug("Remove admin user role for projectt: %s", project_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._project_exists(project_id)):
         try:
             id_cl.delete_role_from_user_on_project(project_id,
                                                    self.admin_id,
                                                    self.admin_role_id)
         except Exception as ex:
             LOG.exception("Failed removing role from project which still"
                           "exists, exception: %s", ex)
Exemplo n.º 23
0
def _get_network_id(net_name, project_name):
    am = clients.Manager(credentials.get_configured_admin_credentials())
    net_cl = am.networks_client
    tn_cl = am.tenants_client

    networks = net_cl.list_networks()
    tenant = identity.get_tenant_by_name(tn_cl, project_name)
    t_id = tenant['id']
    n_id = None
    for net in networks['networks']:
        if (net['tenant_id'] == t_id and net['name'] == net_name):
            n_id = net['id']
            break
    return n_id
Exemplo n.º 24
0
 def __init__(self,
              credentials=common_creds.get_configured_admin_credentials(
                  'identity_admin')):
     self.auth_provider = get_auth_provider(credentials)
     self.service_broker_client = service_broker_client.ServiceBrokerClient(
         self.auth_provider)
     if CONF.application_catalog.glare_backend:
         self.artifacts_client = artifacts_client.ArtifactsClient(
             self.auth_provider)
     else:
         self.artifacts_client = None
     self.application_catalog_client = \
         application_catalog_client.ApplicationCatalogClient(
             self.auth_provider)
Exemplo n.º 25
0
def _get_network_id(net_name, project_name):
    am = clients.Manager(credentials.get_configured_admin_credentials())
    net_cl = am.networks_client
    pr_cl = am.projects_client

    networks = net_cl.list_networks()
    project = identity.get_project_by_name(pr_cl, project_name)
    p_id = project['id']
    n_id = None
    for net in networks['networks']:
        if (net['project_id'] == p_id and net['name'] == net_name):
            n_id = net['id']
            break
    return n_id
Exemplo n.º 26
0
def _get_network_id(net_name, project_name):
    am = clients.Manager(
        credentials.get_configured_admin_credentials())
    net_cl = am.networks_client
    pr_cl = am.projects_client

    networks = net_cl.list_networks()
    project = identity.get_project_by_name(pr_cl, project_name)
    p_id = project['id']
    n_id = None
    for net in networks['networks']:
        if (net['project_id'] == p_id and net['name'] == net_name):
            n_id = net['id']
            break
    return n_id
Exemplo n.º 27
0
    def __init__(self, test_obj):
        """Constructor for ``RbacUtils``.

        :param test_obj: An instance of `tempest.test.BaseTestCase`.
        """
        # Intialize the admin roles_client to perform role switching.
        admin_mgr = clients.Manager(
            credentials.get_configured_admin_credentials())
        if test_obj.get_identity_version() == 'v3':
            admin_roles_client = admin_mgr.roles_v3_client
        else:
            admin_roles_client = admin_mgr.roles_client

        self.admin_roles_client = admin_roles_client
        self._override_role(test_obj, False)
Exemplo n.º 28
0
    def setUpClass(cls):
        super(ScenarioPolicyBase, cls).setUpClass()
        # auth provider for admin credentials
        creds = credentials.get_configured_admin_credentials('identity_admin')
        auth_prov = tempestmanager.get_auth_provider(creds)

        cls.admin_manager.congress_client = policy_client.PolicyClient(
            auth_prov, "policy", CONF.identity.region)

        if getattr(CONF.service_available, 'ceilometer', False):
            import ceilometer.tests.tempest.service.client as telemetry_client
            cls.admin_manager.telemetry_client = (
                telemetry_client.TelemetryClient(
                    auth_prov, CONF.telemetry.catalog_type,
                    CONF.identity.region,
                    endpoint_type=CONF.telemetry.endpoint_type))
Exemplo n.º 29
0
 def setup_clients(cls):
     super(BaseIdentityTest, cls).setup_clients()
     credentials = common_creds.get_configured_admin_credentials(
         cls.credential_type, identity_version=cls.identity_version)
     cls.keystone_manager = clients.Manager(credentials)
     cls.auth_client = cls.keystone_manager.auth_client
     cls.idps_client = cls.keystone_manager.identity_providers_client
     cls.mappings_client = cls.keystone_manager.mapping_rules_client
     cls.roles_client = cls.keystone_manager.roles_v3_client
     cls.saml2_client = cls.keystone_manager.saml2_client
     cls.sps_client = cls.keystone_manager.service_providers_client
     cls.tokens_client = cls.keystone_manager.token_v3_client
     cls.consumers_client = cls.keystone_manager.oauth_consumers_client
     cls.oauth_token_client = cls.keystone_manager.oauth_token_client
     cls.registered_limits_client = (
         cls.keystone_manager.registered_limits_client)
     cls.limits_client = cls.keystone_manager.limits_client
Exemplo n.º 30
0
 def _get_dynamic_creds(cls, name, network_resources=None):
     return dynamic_creds.DynamicCredentialProvider(
         identity_version=CONF.identity.auth_version,
         name=name,
         network_resources=network_resources,
         credentials_domain=CONF.auth.default_credentials_domain_name,
         admin_role=CONF.identity.admin_role,
         admin_creds=common_creds.get_configured_admin_credentials(),
         identity_admin_domain_scope=CONF.identity.admin_domain_scope,
         identity_admin_role=CONF.identity.admin_role,
         extra_roles=None,
         neutron_available=CONF.service_available.neutron,
         create_networks=(
             CONF.share.create_networks_when_multitenancy_enabled),
         project_network_cidr=CONF.network.project_network_cidr,
         project_network_mask_bits=CONF.network.project_network_mask_bits,
         public_network_id=CONF.network.public_network_id,
         resource_prefix=CONF.resources_prefix)
Exemplo n.º 31
0
 def test_get_configured_admin_credentials(self, mock_get_credentials):
     cfg.CONF.set_default('auth_version', 'v3', 'identity')
     all_params = [('admin_username', 'username', 'my_name'),
                   ('admin_password', 'password', 'secret'),
                   ('admin_project_name', 'project_name', 'my_pname'),
                   ('admin_domain_name', 'domain_name', 'my_dname')]
     expected_result = 'my_admin_credentials'
     mock_get_credentials.return_value = expected_result
     for config_item, _, value in all_params:
         cfg.CONF.set_default(config_item, value, 'auth')
     # Build the expected params
     expected_params = dict(
         [(field, value) for _, field, value in all_params])
     expected_params.update(config.service_client_config())
     admin_creds = cf.get_configured_admin_credentials()
     mock_get_credentials.assert_called_once_with(
         fill_in=True, identity_version='v3', **expected_params)
     self.assertEqual(expected_result, admin_creds)
Exemplo n.º 32
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=(',', ': ')))
Exemplo n.º 33
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=(',', ': ')))
Exemplo n.º 34
0
 def test_get_configured_admin_credentials(self, mock_get_credentials):
     cfg.CONF.set_default('auth_version', 'v3', 'identity')
     all_params = [('admin_username', 'username', 'my_name'),
                   ('admin_password', 'password', 'secret'),
                   ('admin_project_name', 'project_name', 'my_pname'),
                   ('admin_domain_name', 'domain_name', 'my_dname')]
     expected_result = 'my_admin_credentials'
     mock_get_credentials.return_value = expected_result
     for config_item, _, value in all_params:
         cfg.CONF.set_default(config_item, value, 'auth')
     # Build the expected params
     expected_params = dict([(field, value)
                             for _, field, value in all_params])
     expected_params.update(cf.DEFAULT_PARAMS)
     admin_creds = cf.get_configured_admin_credentials()
     mock_get_credentials.assert_called_once_with(fill_in=True,
                                                  identity_version='v3',
                                                  **expected_params)
     self.assertEqual(expected_result, admin_creds)
Exemplo n.º 35
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)
Exemplo n.º 36
0
    def setup_clients(cls):
        # Intialize the admin roles_client to perform role switching.
        admin_mgr = clients.Manager(
            credentials.get_configured_admin_credentials())
        if CONF.identity_feature_enabled.api_v3:
            admin_roles_client = admin_mgr.roles_v3_client
        else:
            raise lib_exc.InvalidConfiguration(
                "Patrole role overriding only supports v3 identity API.")

        cls.admin_roles_client = admin_roles_client

        cls._project_id = cls.os_primary.credentials.tenant_id
        cls._user_id = cls.os_primary.credentials.user_id
        cls._role_inferences_mapping = cls._prepare_role_inferences_mapping()

        cls._init_roles()

        # Change default role to admin
        cls._override_role(False)
        super(RbacUtilsMixin, cls).setup_clients()
Exemplo n.º 37
0
def credentials():
    # You can get credentials either from tempest.conf file or
    # from OS environment.
    tempest_creds = clients.get_auth_provider(
        creds_factory.get_configured_admin_credentials())
    creds = tempest_creds.credentials
    creds_dict = {
        '--os-username':
        os.environ.get('OS_USERNAME', creds.username),
        '--os-password':
        os.environ.get('OS_PASSWORD', creds.password),
        '--os-project-name':
        os.environ.get('OS_PROJECT_NAME', creds.project_name),
        '--os-auth-url':
        os.environ.get('OS_AUTH_URL', tempest_creds.auth_url),
        '--os-project-domain-name':
        os.environ.get('OS_PROJECT_DOMAIN_ID', creds.project_domain_name),
        '--os-user-domain-name':
        os.environ.get('OS_USER_DOMAIN_ID', creds.user_domain_name),
    }
    return [x for sub in creds_dict.items() for x in sub]
Exemplo n.º 38
0
    def get_configured_isolated_creds(cls, type_of_creds='admin'):
        identity_version = CONF.identity.auth_version
        if identity_version == 'v3':
            cls.admin_role = CONF.identity.admin_role
        else:
            cls.admin_role = 'admin'
        cls.dynamic_cred = dynamic_creds.DynamicCredentialProvider(
            identity_version=CONF.identity.auth_version,
            name=cls.__name__, admin_role=cls.admin_role,
            admin_creds=common_creds.get_configured_admin_credentials(
                'identity_admin'))
        if type_of_creds == 'primary':
            creds = cls.dynamic_cred.get_primary_creds()
        elif type_of_creds == 'admin':
            creds = cls.dynamic_cred.get_admin_creds()
        elif type_of_creds == 'alt':
            creds = cls.dynamic_cred.get_alt_creds()
        else:
            creds = cls.dynamic_cred.get_credentials(type_of_creds)
        cls.dynamic_cred.type_of_creds = type_of_creds

        return creds.credentials
Exemplo n.º 39
0
    def init(self, parsed_args):
        cleanup_service.init_conf()
        self.options = parsed_args
        self.admin_mgr = clients.Manager(
            credentials.get_configured_admin_credentials())
        self.dry_run_data = {}
        self.json_data = {}

        self.admin_id = ""
        self.admin_role_id = ""
        self.admin_project_id = ""
        self._init_admin_ids()

        self.admin_role_added = []

        # available services
        self.project_services = cleanup_service.get_project_cleanup_services()
        self.global_services = cleanup_service.get_global_cleanup_services()

        if parsed_args.init_saved_state:
            self._init_state()
            return

        self._load_json()
Exemplo n.º 40
0
    def setUp(self):
        super(BaseTestCase, self).setUp()
        self.servers_keypairs = {}
        self.servers = {}
        self.members = []
        self.floating_ips = {}
        self.servers_floating_ips = {}
        self.server_ips = {}
        self.start_port = 80
        self.num = 50
        self.server_fixed_ips = {}

        mgr = self.get_client_manager()

        auth_provider = mgr.auth_provider
        region = config.network.region or config.identity.region
        self.client_args = [auth_provider, 'load-balancer', region]
        self.load_balancers_client = (
            load_balancers_client.LoadBalancersClient(*self.client_args))
        self.listeners_client = (listeners_client.ListenersClient(
            *self.client_args))
        self.pools_client = pools_client.PoolsClient(*self.client_args)
        self.members_client = members_client.MembersClient(*self.client_args)
        self.health_monitors_client = (
            health_monitors_client.HealthMonitorsClient(*self.client_args))
        self.quotas_client = quotas_client.QuotasClient(*self.client_args)

        self._create_security_group_for_test()
        self._set_net_and_subnet()

        # admin network client needed for assigning octavia port to flip
        os_admin = clients.Manager(
            credentials_factory.get_configured_admin_credentials())
        os_admin.auth_provider.fill_credentials()
        self.floating_ips_client_admin = os_admin.floating_ips_client
        self.ports_client_admin = os_admin.ports_client
Exemplo n.º 41
0
    def __init__(self, credentials=None):
        """Initialization of Manager class.

        Setup service client and make it available for test cases.
        :param credentials: type Credentials or TestResources
        """
        if credentials is None:
            global ADMIN_CREDS
            if ADMIN_CREDS is None:
                ADMIN_CREDS = common_creds.get_configured_admin_credentials()
            credentials = ADMIN_CREDS
        super(Manager, self).__init__(credentials)
        default_params_with_timeout_values = {
            'build_interval': CONF.compute.build_interval,
            'build_timeout': CONF.compute.build_timeout
        }
        default_params_with_timeout_values.update(self.default_params)

        self.baremetal_client = BaremetalClient(
            self.auth_provider,
            CONF.baremetal.catalog_type,
            CONF.identity.region,
            endpoint_type=CONF.baremetal.endpoint_type,
            **default_params_with_timeout_values)
Exemplo n.º 42
0
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from tempest import clients
from tempest.common import credentials_factory as common_creds
from tempest import config

from ironic_tempest_plugin.services.baremetal.v1.json.baremetal_client import \
    BaremetalClient


CONF = config.CONF

ADMIN_CREDS = common_creds.get_configured_admin_credentials()


class Manager(clients.Manager):
    def __init__(self,
                 credentials=ADMIN_CREDS,
                 service=None):
        """Initialization of Manager class.

        Setup service client and make it available for test cases.
        :param credentials: type Credentials or TestResources
        :param service: service name
        """
        super(Manager, self).__init__(credentials, service)
        self.baremetal_client = BaremetalClient(
            self.auth_provider,
Exemplo n.º 43
0
 def setUpClass(cls):
     super(ScenarioPolicyBase, cls).setUpClass()
     # auth provider for admin credentials
     creds = credentials.get_configured_admin_credentials('identity_admin')
     auth_prov = tempestmanager.get_auth_provider(creds)
     cls.setup_required_clients(auth_prov)
Exemplo n.º 44
0
    def provide_share_network(cls, shares_client, networks_client,
                              isolated_creds_client=None):
        """Used for finding/creating share network for multitenant driver.

        This method creates/gets entity share-network for one tenant. This
        share-network will be used for creation of service vm.

        :param shares_client: shares client, which requires share-network
        :param networks_client: network client from same tenant as shares
        :param isolated_creds_client: DynamicCredentialProvider instance
            If provided, then its networking will be used if needed.
            If not provided, then common network will be used if needed.
        :returns: str -- share network id for shares_client tenant
        :returns: None -- if single-tenant driver used
        """

        sc = shares_client
        search_word = "reusable"
        sn_name = "autogenerated_by_tempest_%s" % search_word

        if not CONF.share.multitenancy_enabled:
            # Assumed usage of a single-tenant driver
            share_network_id = None
        elif sc.share_network_id:
            # Share-network already exists, use it
            share_network_id = sc.share_network_id
        elif not CONF.share.create_networks_when_multitenancy_enabled:
            share_network_id = None

            # Try get suitable share-network
            share_networks = sc.list_share_networks_with_detail()
            for sn in share_networks:
                if (sn["neutron_net_id"] is None and
                        sn["neutron_subnet_id"] is None and
                        sn["name"] and search_word in sn["name"]):
                    share_network_id = sn["id"]
                    break

            # Create new share-network if one was not found
            if share_network_id is None:
                sn_desc = "This share-network was created by tempest"
                sn = sc.create_share_network(name=sn_name, description=sn_desc)
                share_network_id = sn["id"]
        else:
            net_id = subnet_id = share_network_id = None

            if not isolated_creds_client:
                # Search for networks, created in previous runs
                service_net_name = "share-service"
                networks = networks_client.list_networks()
                if "networks" in networks.keys():
                    networks = networks["networks"]
                for network in networks:
                    if (service_net_name in network["name"] and
                            sc.tenant_id == network['tenant_id']):
                        net_id = network["id"]
                        if len(network["subnets"]) > 0:
                            subnet_id = network["subnets"][0]
                            break

                # Create suitable network
                if (net_id is None or subnet_id is None):
                    ic = dynamic_creds.DynamicCredentialProvider(
                        identity_version=CONF.identity.auth_version,
                        name=service_net_name,
                        admin_role=CONF.identity.admin_role,
                        admin_creds=(
                            common_creds.get_configured_admin_credentials()))
                    net_data = ic._create_network_resources(sc.tenant_id)
                    network, subnet, router = net_data
                    net_id = network["id"]
                    subnet_id = subnet["id"]

                # Try get suitable share-network
                share_networks = sc.list_share_networks_with_detail()
                for sn in share_networks:
                    if (net_id == sn["neutron_net_id"] and
                            subnet_id == sn["neutron_subnet_id"] and
                            sn["name"] and search_word in sn["name"]):
                        share_network_id = sn["id"]
                        break
            else:
                sn_name = "autogenerated_by_tempest_for_isolated_creds"
                # Use precreated network and subnet from isolated creds
                net_id = isolated_creds_client.get_credentials(
                    isolated_creds_client.type_of_creds).network['id']
                subnet_id = isolated_creds_client.get_credentials(
                    isolated_creds_client.type_of_creds).subnet['id']

            # Create suitable share-network
            if share_network_id is None:
                sn_desc = "This share-network was created by tempest"
                sn = sc.create_share_network(name=sn_name,
                                             description=sn_desc,
                                             neutron_net_id=net_id,
                                             neutron_subnet_id=subnet_id)
                share_network_id = sn["id"]

        return share_network_id
Exemplo n.º 45
0
 def setup_credentials(cls):
     super(TestHugepages, cls).setup_credentials()
     cls.manager = clients.Manager(
         credentials=common_creds.get_configured_admin_credentials(
             fill_in=False))
Exemplo n.º 46
0
    def provide_share_network(cls,
                              shares_client,
                              networks_client,
                              isolated_creds_client=None):
        """Used for finding/creating share network for multitenant driver.

        This method creates/gets entity share-network for one tenant. This
        share-network will be used for creation of service vm.

        :param shares_client: shares client, which requires share-network
        :param networks_client: network client from same tenant as shares
        :param isolated_creds_client: DynamicCredentialProvider instance
            If provided, then its networking will be used if needed.
            If not provided, then common network will be used if needed.
        :returns: str -- share network id for shares_client tenant
        :returns: None -- if single-tenant driver used
        """

        sc = shares_client
        search_word = "reusable"
        sn_name = "autogenerated_by_tempest_%s" % search_word

        if not CONF.share.multitenancy_enabled:
            # Assumed usage of a single-tenant driver
            share_network_id = None
        elif sc.share_network_id:
            # Share-network already exists, use it
            share_network_id = sc.share_network_id
        elif not CONF.share.create_networks_when_multitenancy_enabled:
            share_network_id = None

            # Try get suitable share-network
            share_networks = sc.list_share_networks_with_detail()
            for sn in share_networks:
                if (sn["neutron_net_id"] is None
                        and sn["neutron_subnet_id"] is None and sn["name"]
                        and search_word in sn["name"]):
                    share_network_id = sn["id"]
                    break

            # Create new share-network if one was not found
            if share_network_id is None:
                sn_desc = "This share-network was created by tempest"
                sn = sc.create_share_network(name=sn_name, description=sn_desc)
                share_network_id = sn["id"]
        else:
            net_id = subnet_id = share_network_id = None

            if not isolated_creds_client:
                # Search for networks, created in previous runs
                service_net_name = "share-service"
                networks = networks_client.list_networks()
                if "networks" in networks.keys():
                    networks = networks["networks"]
                for network in networks:
                    if (service_net_name in network["name"]
                            and sc.tenant_id == network['tenant_id']):
                        net_id = network["id"]
                        if len(network["subnets"]) > 0:
                            subnet_id = network["subnets"][0]
                            break

                # Create suitable network
                if (net_id is None or subnet_id is None):
                    ic = dynamic_creds.DynamicCredentialProvider(
                        identity_version=CONF.identity.auth_version,
                        name=service_net_name,
                        admin_role=CONF.identity.admin_role,
                        admin_creds=(
                            common_creds.get_configured_admin_credentials()))
                    net_data = ic._create_network_resources(sc.tenant_id)
                    network, subnet, router = net_data
                    net_id = network["id"]
                    subnet_id = subnet["id"]

                # Try get suitable share-network
                share_networks = sc.list_share_networks_with_detail()
                for sn in share_networks:
                    if (net_id == sn["neutron_net_id"]
                            and subnet_id == sn["neutron_subnet_id"]
                            and sn["name"] and search_word in sn["name"]):
                        share_network_id = sn["id"]
                        break
            else:
                sn_name = "autogenerated_by_tempest_for_isolated_creds"
                # Use precreated network and subnet from isolated creds
                net_id = isolated_creds_client.get_credentials(
                    isolated_creds_client.type_of_creds).network['id']
                subnet_id = isolated_creds_client.get_credentials(
                    isolated_creds_client.type_of_creds).subnet['id']

            # Create suitable share-network
            if share_network_id is None:
                sn_desc = "This share-network was created by tempest"
                sn = sc.create_share_network(name=sn_name,
                                             description=sn_desc,
                                             neutron_net_id=net_id,
                                             neutron_subnet_id=subnet_id)
                share_network_id = sn["id"]

        return share_network_id
Exemplo n.º 47
0
 def __init__(self, service=None):
     super(AltManager, self).__init__(
         common_creds.get_configured_admin_credentials('alt_user'), service)
Exemplo n.º 48
0
    def get_client_with_isolated_creds(cls,
                                       name=None,
                                       type_of_creds="admin",
                                       cleanup_in_class=False,
                                       client_version='1'):
        """Creates isolated creds.

        :param name: name, will be used for naming ic and related stuff
        :param type_of_creds: admin, alt or primary
        :param cleanup_in_class: defines place where to delete
        :returns: SharesClient -- shares client with isolated creds.
        :returns: To client added dict attr 'creds' with
        :returns: key elements 'tenant' and 'user'.
        """
        if name is None:
            # Get name of test method
            name = inspect.stack()[1][3]
            if len(name) > 32:
                name = name[0:32]

        # Choose type of isolated creds
        ic = dynamic_creds.DynamicCredentialProvider(
            identity_version=CONF.identity.auth_version,
            name=name,
            admin_role=CONF.identity.admin_role,
            admin_creds=common_creds.get_configured_admin_credentials())
        if "admin" in type_of_creds:
            creds = ic.get_admin_creds().credentials
        elif "alt" in type_of_creds:
            creds = ic.get_alt_creds().credentials
        else:
            creds = ic.get_credentials(type_of_creds).credentials
        ic.type_of_creds = type_of_creds

        # create client with isolated creds
        os = clients.Manager(credentials=creds)
        if client_version == '1':
            client = shares_client.SharesClient(os.auth_provider)
        elif client_version == '2':
            client = shares_v2_client.SharesV2Client(os.auth_provider)

        # Set place where will be deleted isolated creds
        ic_res = {
            "method": ic.clear_creds,
            "deleted": False,
        }
        if cleanup_in_class:
            cls.class_isolated_creds.insert(0, ic_res)
        else:
            cls.method_isolated_creds.insert(0, ic_res)

        # Provide share network
        if CONF.share.multitenancy_enabled:
            if (not CONF.service_available.neutron and
                    CONF.share.create_networks_when_multitenancy_enabled):
                raise cls.skipException("Neutron support is required")
            nc = os.networks_client
            share_network_id = cls.provide_share_network(client, nc, ic)
            client.share_network_id = share_network_id
            resource = {
                "type": "share_network",
                "id": client.share_network_id,
                "client": client,
            }
            if cleanup_in_class:
                cls.class_resources.insert(0, resource)
            else:
                cls.method_resources.insert(0, resource)
        return client