コード例 #1
0
 def _supplied_network(self):
     LOG.info("Looking for existing network id: {0}"
              "".format(self._public_network_id))
     # check if network exists
     network_list = self.client.list_networks()
     for network in network_list['networks']:
         if network['id'] == self._public_network_id:
             self._public_network_name = network['name']
             break
     else:
         raise ValueError('provided network id: {0} was not found.'
                          ''.format(self._public_network_id))
コード例 #2
0
    def _discover_network(self):
        LOG.info("No network supplied, trying auto discover for network")
        network_list = self.client.list_networks()
        for network in network_list['networks']:
            if network['router:external'] and network['subnets']:
                LOG.info("Found network, using: {0}".format(network['id']))
                self._public_network_id = network['id']
                self._public_network_name = network['name']
                break

        # Couldn't find an existing external network
        else:
            LOG.error("No external networks found. "
                      "Please note that any test that relies on external "
                      "connectivity would most likely fail.")
コード例 #3
0
def read_deployer_input(deployer_input_file, conf):
    """Read deployer-input file and set values in conf accordingly.

    :param deployer_input_file: Path to the deployer inut file
    :type deployer_input_file: String
    :param conf: TempestConf object
    """
    LOG.info("Adding options from deployer-input file '%s'",
             deployer_input_file)
    if six.PY3:
        deployer_input = configparser.ConfigParser()
    else:
        deployer_input = configparser.SafeConfigParser()
    deployer_input.read(deployer_input_file)
    for section in deployer_input.sections():
        # There are no deployer input options in DEFAULT
        for (key, value) in deployer_input.items(section):
            conf.set(section, key, value, priority=True)
コード例 #4
0
    def create_user_with_project(self, username, password, project_name):
        """Create a user and a project if it doesn't exist.

        :type username: string
        :type password: string
        :type project_name: string
        """
        LOG.info("Creating user '%s' with project '%s' and password '%s'",
                 username, project_name, password)
        project_description = "Project for Tempest %s user" % username
        email = "*****@*****.**" % username
        # create a project
        try:
            self.projects_client.create_project(
                name=project_name, description=project_description)
        except exceptions.Conflict:
            LOG.info("(no change) Project '%s' already exists", project_name)

        proj_id = self.projects_client.get_project_by_name(project_name)['id']

        params = {
            'name': username,
            'password': password,
            'tenantId': proj_id,
            'email': email
        }
        # create a user
        try:
            self.users_client.create_user(**params)
        except exceptions.Conflict:
            LOG.info("User '%s' already exists.", username)
コード例 #5
0
 def list_create_roles(self, conf, client):
     try:
         roles = client.list_roles()['roles']
         for section_key in ["operator_role", "reseller_admin_role"]:
             key_value = conf.get_defaulted("object-storage", section_key)
             if key_value not in [r['name'] for r in roles]:
                 LOG.info("Creating %s role", key_value)
                 try:
                     client.create_role(name=key_value)
                 except exceptions.Conflict:
                     LOG.info("Role %s already exists", key_value)
         conf.set('object-storage', 'operator_role', 'admin')
     except exceptions.Forbidden:
         LOG.info("Roles can't be listed or created. The user doesn't have "
                  "permissions.")
         # If is not admin, we set the operator_role to Member
         # otherwise we set to admin
         conf.set('object-storage', 'operator_role', 'Member')
コード例 #6
0
def config_tempest(**kwargs):
    # convert a list of remove values to a dict
    remove = parse_values_to_remove(kwargs.get('remove', []))
    add = parse_values_to_append(kwargs.get('append', []))
    set_logging(kwargs.get('debug', False), kwargs.get('verbose', False))

    accounts_path = kwargs.get('test_accounts')
    if kwargs.get('create_accounts_file') is not None:
        accounts_path = kwargs.get('create_accounts_file')
    conf = TempestConf(write_credentials=accounts_path is None)
    set_options(conf, kwargs.get('deployer_input'),
                kwargs.get('non_admin', False),
                kwargs.get('image_path', C.DEFAULT_IMAGE),
                kwargs.get('overrides', []), accounts_path,
                kwargs.get('cloud_creds'))

    credentials = Credentials(conf, not kwargs.get('non_admin', False))
    clients = ClientManager(conf, credentials)
    services = Services(clients, conf, credentials)

    if kwargs.get('create', False) and kwargs.get('test_accounts') is None:
        users = Users(clients.projects, clients.roles, clients.users, conf)
        users.create_tempest_users()

    if services.is_service(**{"type": "compute"}):
        flavors = Flavors(clients.flavors,
                          kwargs.get('create', False),
                          conf,
                          kwargs.get('flavor_min_mem', C.DEFAULT_FLAVOR_RAM),
                          kwargs.get('flavor_min_disk', C.DEFAULT_FLAVOR_DISK),
                          no_rng=kwargs.get('no_rng', False))
        flavors.create_tempest_flavors()

    if services.is_service(**{"type": "image"}):
        image = services.get_service('image')
        image.set_image_preferences(kwargs.get('image_disk_format',
                                               C.DEFAULT_IMAGE_FORMAT),
                                    kwargs.get('non_admin', False),
                                    no_rng=kwargs.get('no_rng', False),
                                    convert=kwargs.get('convert_to_raw',
                                                       False))
        image.create_tempest_images(conf)

    if services.is_service(**{"type": "network"}):
        network = services.get_service("network")
        network.create_tempest_networks(conf, kwargs.get('network_id'))

    services.post_configuration()
    services.set_supported_api_versions()
    services.set_service_extensions()

    if accounts_path is not None and kwargs.get('test_accounts') is None:
        LOG.info("Creating an accounts.yaml file in: %s", accounts_path)
        accounts.create_accounts_file(kwargs.get('create', False),
                                      accounts_path, conf)

    # remove all unwanted values if were specified
    if remove != {}:
        LOG.info("Removing configuration: %s", str(remove))
        conf.remove_values(remove)
    if add != {}:
        LOG.info("Adding configuration: %s", str(add))
        conf.append_values(add)
    out_path = kwargs.get('out', 'etc/tempest.conf')
    conf.write(out_path)
コード例 #7
0
def set_options(conf,
                deployer_input,
                non_admin,
                image_path,
                overrides=[],
                accounts_path=None,
                cloud_creds=None,
                no_default_deployer=False):
    """Set options in conf provided by different source.

    1. read the default values
    2. read a file provided by --deployer-input argument
    3. read default DEPLOYER_INPUT if --no-deployer-input is False and no
       deployer_input was passed
    4. set values from client's config (openstacksdk support) if provided
    5. set overrides - may override values which were set in the steps above

    :param conf: TempestConf object
    :param deployer_input: Path to the deployer inut file
    :type deployer_input: string
    :type non_admin: boolean
    :param image_path: An image to be uploaded to glance
    :type image_path: string
    :param overrides: list of tuples: [(section, key, value)]
    :type overrides: list
    :param accounts_path: A path where accounts.yaml is or will be created.
    :type accounts_path: string
    :param cloud_creds: Cloud credentials from client's config
    :type cloud_creds: dict
    """
    load_basic_defaults(conf)
    # image.image_path is a python-tempestconf option which defines which
    # image will be uploaded to glance
    conf.set('image', 'image_path', image_path)

    if deployer_input and os.path.isfile(deployer_input):
        LOG.info("Reading deployer input from file {}".format(deployer_input))
        read_deployer_input(deployer_input, conf)
    elif os.path.isfile(C.DEPLOYER_INPUT) and not no_default_deployer:
        LOG.info("Reading deployer input from file {}".format(
            C.DEPLOYER_INPUT))
        read_deployer_input(C.DEPLOYER_INPUT, conf)

    if non_admin:
        # non admin, so delete auth admin values which were set
        # in load_basic_defaults method
        conf.set("auth", "admin_username", "")
        conf.set("auth", "admin_project_name", "")
        conf.set("auth", "admin_password", "")
        conf.set("auth", "use_dynamic_credentials", "False", priority=True)

    # get and set auth data from client's config
    if cloud_creds:
        set_cloud_config_values(non_admin, cloud_creds, conf)

    if accounts_path:
        # new way for running using accounts file
        conf.set("auth", "use_dynamic_credentials", "False", priority=True)
        conf.set("auth", "test_accounts_file", os.path.abspath(accounts_path))

    # set overrides - values specified in CLI
    for section, key, value in overrides:
        conf.set(section, key, value, priority=True)

    uri = conf.get("identity", "uri")
    if "v3" in uri:
        conf.set("identity", "auth_version", "v3")
        conf.set("identity", "uri_v3", uri)
    else:
        # TODO(arxcruz) make a check if v3 is enabled
        conf.set("identity", "uri_v3", uri.replace("v2.0", "v3"))
コード例 #8
0
 def create_tempest_networks(self, conf, network_id):
     LOG.info("Setting up network")
     self.client = self.client.get_neutron_client()
     self.create_tempest_networks_neutron(conf, network_id)