예제 #1
0
def get_network_from_name(name, compute_networks_client):
    """Get a full network dict from just a network name

    :param str name: the name of the network to use
    :param NetworksClient compute_networks_client: The network client
        object to use for making the network lists api request
    :return: The full dictionary for the network in question
    :rtype: dict
    :raises InvalidConfiguration: If the name provided is invalid, the networks
        list returns a 404, there are no found networks, or the found network
        is invalid
    """
    caller = misc_utils.find_test_caller()

    if not name:
        raise exceptions.InvalidConfiguration()

    networks = compute_networks_client.list_networks()
    networks = [n for n in networks if n['label'] == name]

    # Check that a network exists, else raise an InvalidConfigurationException
    if len(networks) == 1:
        network = sorted(networks)[0]
    elif len(networks) > 1:
        msg = ("Network with name: %s had multiple matching networks in the "
               "list response: %s\n Unable to specify a single network" %
               (name, networks))
        if caller:
            msg = '(%s) %s' % (caller, msg)
        LOG.warn(msg)
        raise exceptions.InvalidConfiguration()
    else:
        msg = "Network with name: %s not found" % name
        if caller:
            msg = '(%s) %s' % (caller, msg)
        LOG.warn(msg)
        raise exceptions.InvalidConfiguration()
    # To be consistent between neutron and nova network always use name even
    # if label is used in the api response. If neither is present than then
    # the returned network is invalid.
    name = network.get('name') or network.get('label')
    if not name:
        msg = "Network found from list doesn't contain a valid name or label"
        if caller:
            msg = '(%s) %s' % (caller, msg)
        LOG.warn(msg)
        raise exceptions.InvalidConfiguration()
    network['name'] = name
    return network
예제 #2
0
 def _get_match_hash_list(self, roles=None):
     hashes = []
     if roles:
         # Loop over all the creds for each role in the subdict and generate
         # a list of cred lists for each role
         for role in roles:
             temp_hashes = self.hash_dict['roles'].get(role, None)
             if not temp_hashes:
                 raise exceptions.InvalidConfiguration(
                     "No credentials with role: %s specified in the "
                     "accounts ""file" % role)
             hashes.append(temp_hashes)
         # Take the list of lists and do a boolean and between each list to
         # find the creds which fall under all the specified roles
         temp_list = set(hashes[0])
         for hash_list in hashes[1:]:
             temp_list = temp_list & set(hash_list)
         hashes = temp_list
     else:
         hashes = self.hash_dict['creds'].keys()
     # NOTE(mtreinish): admin is a special case because of the increased
     # privlege set which could potentially cause issues on tests where that
     # is not expected. So unless the admin role isn't specified do not
     # allocate admin.
     admin_hashes = self.hash_dict['roles'].get(CONF.identity.admin_role,
                                                None)
     if ((not roles or CONF.identity.admin_role not in roles) and
             admin_hashes):
         useable_hashes = [x for x in hashes if x not in admin_hashes]
     else:
         useable_hashes = hashes
     return useable_hashes
예제 #3
0
 def is_multi_user(self):
     # Default credentials is not a valid option with locking Account
     if self.use_default_creds:
         raise exceptions.InvalidConfiguration(
             "Account file %s doesn't exist" % CONF.auth.test_accounts_file)
     else:
         return len(self.hash_dict['creds']) > 1
예제 #4
0
 def _set_identity_clients(self):
     params = {
         'service': CONF.identity.catalog_type,
         'region': CONF.identity.region
     }
     params.update(self.default_params_with_timeout_values)
     params_v2_admin = params.copy()
     params_v2_admin['endpoint_type'] = CONF.identity.v2_admin_endpoint_type
     # Client uses admin endpoint type of Keystone API v2
     self.identity_client = IdentityClient(self.auth_provider,
                                           **params_v2_admin)
     params_v2_public = params.copy()
     params_v2_public['endpoint_type'] = (
         CONF.identity.v2_public_endpoint_type)
     # Client uses public endpoint type of Keystone API v2
     self.identity_public_client = IdentityClient(self.auth_provider,
                                                  **params_v2_public)
     params_v3 = params.copy()
     params_v3['endpoint_type'] = CONF.identity.v3_endpoint_type
     # Client uses the endpoint type of Keystone API v3
     self.identity_v3_client = IdentityV3Client(self.auth_provider,
                                                **params_v3)
     self.endpoints_client = EndPointClient(self.auth_provider, **params)
     self.service_client = ServiceClient(self.auth_provider, **params)
     self.policy_client = PolicyClient(self.auth_provider, **params)
     self.region_client = RegionClient(self.auth_provider, **params)
     self.credentials_client = CredentialsClient(self.auth_provider,
                                                 **params)
     # Token clients do not use the catalog. They only need default_params.
     # They read auth_url, so they should only be set if the corresponding
     # API version is marked as enabled
     if CONF.identity_feature_enabled.api_v2:
         if CONF.identity.uri:
             self.token_client = TokenClientJSON(CONF.identity.uri,
                                                 **self.default_params)
         else:
             msg = 'Identity v2 API enabled, but no identity.uri set'
             raise exceptions.InvalidConfiguration(msg)
     if CONF.identity_feature_enabled.api_v3:
         if CONF.identity.uri_v3:
             self.token_v3_client = V3TokenClientJSON(
                 CONF.identity.uri_v3, **self.default_params)
         else:
             msg = 'Identity v3 API enabled, but no identity.uri_v3 set'
             raise exceptions.InvalidConfiguration(msg)
예제 #5
0
 def _unique_creds(self, cred_arg=None):
     """Verify that the configured credentials are valid and distinct """
     try:
         user = self.get_primary_creds()
         alt_user = self.get_alt_creds()
         return getattr(user, cred_arg) != getattr(alt_user, cred_arg)
     except exceptions.InvalidCredentials as ic:
         msg = "At least one of the configured credentials is " \
               "not valid: %s" % ic.message
         raise exceptions.InvalidConfiguration(msg)
예제 #6
0
 def _get_creds(self, roles=None):
     if self.use_default_creds:
         raise exceptions.InvalidConfiguration(
             "Account file %s doesn't exist" % CONF.auth.test_accounts_file)
     useable_hashes = self._get_match_hash_list(roles)
     free_hash = self._get_free_hash(useable_hashes)
     clean_creds = self._sanitize_creds(
         self.hash_dict['creds'][free_hash])
     LOG.info('%s allocated creds:\n%s' % (self.name, clean_creds))
     return self._wrap_creds_with_network(free_hash)
예제 #7
0
 def __init__(self, identity_client, domain_name):
     super(V3CredsClient, self).__init__(identity_client)
     try:
         # Domain names must be unique, in any case a list is returned,
         # selecting the first (and only) element
         self.creds_domain = self.identity_client.list_domains(
             params={'name': domain_name})[0]
     except exceptions.NotFound:
         # TODO(andrea) we could probably create the domain on the fly
         msg = "Configured domain %s could not be found" % domain_name
         raise exceptions.InvalidConfiguration(msg)
예제 #8
0
    def _create_network_resources(self, tenant_id):
        network = None
        subnet = None
        router = None
        # Make sure settings
        if self.network_resources:
            if self.network_resources['router']:
                if (not self.network_resources['subnet']
                        or not self.network_resources['network']):
                    raise exceptions.InvalidConfiguration(
                        'A router requires a subnet and network')
            elif self.network_resources['subnet']:
                if not self.network_resources['network']:
                    raise exceptions.InvalidConfiguration(
                        'A subnet requires a network')
            elif self.network_resources['dhcp']:
                raise exceptions.InvalidConfiguration('DHCP requires a subnet')

        data_utils.rand_name_root = data_utils.rand_name(self.name)
        if not self.network_resources or self.network_resources['network']:
            network_name = data_utils.rand_name_root + "-network"
            network = self._create_network(network_name, tenant_id)
        try:
            if not self.network_resources or self.network_resources['subnet']:
                subnet_name = data_utils.rand_name_root + "-subnet"
                subnet = self._create_subnet(subnet_name, tenant_id,
                                             network['id'])
            if not self.network_resources or self.network_resources['router']:
                router_name = data_utils.rand_name_root + "-router"
                router = self._create_router(router_name, tenant_id)
                self._add_router_interface(router['id'], subnet['id'])
        except Exception:
            if router:
                self._clear_isolated_router(router['id'], router['name'])
            if subnet:
                self._clear_isolated_subnet(subnet['id'], subnet['name'])
            if network:
                self._clear_isolated_network(network['id'], network['name'])
            raise
        return network, subnet, router
예제 #9
0
    def renew_lease(self, fixed_ip=None):
        """Wrapper method for renewing DHCP lease via given client

        Supporting:
        * udhcpc
        * dhclient
        """
        # TODO(yfried): add support for dhcpcd
        suported_clients = ['udhcpc', 'dhclient']
        dhcp_client = CONF.scenario.dhcp_client
        if dhcp_client not in suported_clients:
            raise exceptions.InvalidConfiguration(
                '%s DHCP client unsupported' % dhcp_client)
        if dhcp_client == 'udhcpc' and not fixed_ip:
            raise ValueError("need to set 'fixed_ip' for udhcpc client")
        return getattr(self, '_renew_lease_' + dhcp_client)(fixed_ip=fixed_ip)
예제 #10
0
    def skip_checks(cls):
        super(BaseVolumeTest, cls).skip_checks()

        if not CONF.service_available.cinder:
            skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
            raise cls.skipException(skip_msg)
        if cls._api_version == 1:
            if not CONF.volume_feature_enabled.api_v1:
                msg = "Volume API v1 is disabled"
                raise cls.skipException(msg)
        elif cls._api_version == 2:
            if not CONF.volume_feature_enabled.api_v2:
                msg = "Volume API v2 is disabled"
                raise cls.skipException(msg)
        else:
            msg = ("Invalid Cinder API version (%s)" % cls._api_version)
            raise exceptions.InvalidConfiguration(message=msg)
예제 #11
0
 def _get_free_hash(self, hashes):
     # Cast as a list because in some edge cases a set will be passed in
     hashes = list(hashes)
     if not os.path.isdir(self.accounts_dir):
         os.mkdir(self.accounts_dir)
         # Create File from first hash (since none are in use)
         self._create_hash_file(hashes[0])
         return hashes[0]
     names = []
     for _hash in hashes:
         res = self._create_hash_file(_hash)
         if res:
             return _hash
         else:
             path = os.path.join(os.path.join(self.accounts_dir,
                                              _hash))
             with open(path, 'r') as fd:
                 names.append(fd.read())
     msg = ('Insufficient number of users provided. %s have allocated all '
            'the credentials for this allocation request' % ','.join(names))
     raise exceptions.InvalidConfiguration(msg)
예제 #12
0
 def get_creds_by_roles(self, roles, force_new=False):
     msg = "Credentials being specified through the config file can not be"\
           " used with tests that specify using credentials by roles. "\
           "Either exclude/skip the tests doing this or use either an "\
           "test_accounts_file or tenant isolation."
     raise exceptions.InvalidConfiguration(msg)