Exemplo n.º 1
0
    def test_seek_unexisting_path(self):
        unexisting = 'an/unexisting/path'

        with working_directory(self.sourcedir):
            with self.assertRaises(EnosFilePathError):
                xenos.seekpath(unexisting)

        with working_directory(self.workdir):
            with self.assertRaises(EnosFilePathError):
                xenos.seekpath(unexisting)
Exemplo n.º 2
0
def up(config, config_file=None, env=None, **kwargs):
    logging.debug('phase[up]: args=%s' % kwargs)
    # Calls the provider and initialise resources

    provider_conf = config['provider']
    provider = make_provider(provider_conf)

    # Applying default configuration
    config = load_config(config, provider.default_config())
    env['config'] = config
    env['config_file'] = config_file
    logging.debug("Loaded config: %s", config)

    rsc, networks = \
        provider.init(env['config'], kwargs['--force-deploy'])

    env['rsc'] = rsc
    env['networks'] = networks

    logging.debug("Provider ressources: %s", env['rsc'])
    logging.debug("Provider network information: %s", env['networks'])

    # Generates inventory for ansible/kolla
    inventory = os.path.join(env['resultdir'], 'multinode')
    inventory_conf = env['config'].get('inventory')
    if not inventory_conf:
        logging.debug("No inventory specified, using the sample.")
        base_inventory = os.path.join(INVENTORY_DIR, 'inventory.sample')
    else:
        base_inventory = seekpath(inventory_conf)
    generate_inventory(env['rsc'], env['networks'], base_inventory, inventory)
    logging.info('Generates inventory %s' % inventory)

    env['inventory'] = inventory

    # Set variables required by playbooks of the application
    vip_pool = get_vip_pool(networks)
    env['config'].update({
        'vip': pop_ip(vip_pool),
        'registry_vip': pop_ip(vip_pool),
        'influx_vip': pop_ip(vip_pool),
        'grafana_vip': pop_ip(vip_pool),
        'resultdir': env['resultdir'],
        'rabbitmq_password': "******",
        'database_password': "******"
    })

    options = {}
    options.update(env['config'])
    enos_action = "pull" if kwargs.get("--pull") else "deploy"
    options.update(enos_action=enos_action)
    # Runs playbook that initializes resources (eg,
    # installs the registry, install monitoring tools, ...)
    up_playbook = os.path.join(ANSIBLE_DIR, 'enos.yml')
    run_ansible([up_playbook],
                env['inventory'],
                extra_vars=options,
                tags=kwargs['--tags'])
Exemplo n.º 3
0
    def test_seek_path(self, abspath, relpath):
        # Execution from the source directory
        with working_directory(self.sourcedir):
            self.assertPathEqual(
                xenos.seekpath(abspath), abspath,
                f"Seeking for an {abspath} defined "
                "with an absolute path should always "
                "return that path")

            self.assertPathEqual(
                xenos.seekpath(relpath), os.path.join(C.RSCS_DIR, relpath),
                f"Seeking for {relpath} from the source "
                "directory should seek into enos source")

        # Execution from a working directory
        with working_directory(self.workdir):
            self.assertPathEqual(
                xenos.seekpath(abspath), abspath, "Seeking for %s defined "
                "with an absolute path should always "
                "return that path" % abspath)

            self.assertPathEqual(
                xenos.seekpath(relpath), os.path.join(C.RSCS_DIR, relpath),
                "In absence of %s in the working "
                "directory, enos should seek for that one "
                "in sources" % relpath)

            # Build a fake `relpath` in the working directory and
            # check seekpath behaviour
            _path = pathlib.Path(relpath)
            _path.parent.is_dir() or _path.parent.mkdir()
            _path.exists() or os.mknod(str(_path))
            self.assertPathEqual(
                xenos.seekpath(relpath), os.path.join(self.workdir, relpath),
                "In presence of %s in the working directory,"
                "enos should take this one" % relpath)
Exemplo n.º 4
0
def bench(env=None, **kwargs):
    def cartesian(d):
        """returns the cartesian product of the args."""
        logging.debug(d)
        f = []
        for k, v in d.items():
            if isinstance(v, list):
                f.extend([[[k, vv] for vv in v]])
            else:
                f.append([[k, v]])
        logging.debug(f)
        product = []
        for e in itertools.product(*f):
            product.append(dict(e))
        return product

    logging.debug('phase[bench]: args=%s' % kwargs)
    playbook_values = mk_enos_values(env)
    workload_dir = seekpath(kwargs["--workload"])
    with open(os.path.join(workload_dir, "run.yml")) as workload_f:
        workload = yaml.load(workload_f)
        for bench_type, desc in workload.items():
            scenarios = desc.get("scenarios", [])
            reset = kwargs.get("--reset")
            for idx, scenario in enumerate(scenarios):
                # merging args
                top_args = desc.get("args", {})
                args = scenario.get("args", {})
                top_args.update(args)
                # merging enabled, skipping if not enabled
                top_enabled = desc.get("enabled", True)
                enabled = scenario.get("enabled", True)
                if not (top_enabled and enabled):
                    continue
                for a in cartesian(top_args):
                    playbook_path = os.path.join(ANSIBLE_DIR, 'enos.yml')
                    inventory_path = os.path.join(env['resultdir'],
                                                  'multinode')
                    # NOTE(msimonin) all the scenarios and plugins
                    # must reside on the workload directory
                    scenario_location = os.path.join(workload_dir,
                                                     scenario["file"])
                    bench = {
                        'type': bench_type,
                        'scenario_location': scenario_location,
                        'file': scenario["file"],
                        'args': a
                    }
                    bench.update({'reset': False})
                    if reset and idx == 0:
                        bench.update({'reset': True})

                    if "plugin" in scenario:
                        plugin = os.path.join(workload_dir, scenario["plugin"])
                        if os.path.isdir(plugin):
                            plugin = plugin + "/"
                        bench['plugin_location'] = plugin
                    playbook_values.update(bench=bench)
                    playbook_values.update(enos_action="bench")

                    run_ansible([playbook_path],
                                inventory_path,
                                extra_vars=playbook_values)
Exemplo n.º 5
0
def bench(**kwargs):
    """\
    USAGE:
      enos bench [--workload=WORKLOAD] [--reset] [--pull] [-e ENV]

      Run Rally/Shaker on this OpenStack.

    OPTIONS:
      --workload=WORKLOAD  Path to the workload directory.
                           This directory must contain a run.yml file
                           that contains the description of the different
                           scenarios to launch [default: workload/].
      --reset              Recreate the benchmark environment.
      --pull               Only preinstall software (e.g pull docker images).
      -e, --env ENV        Path to the environment directory (Advanced option).
                           Enos creates a directory to track the state of the
                           experiment. Use this option to link enos with a
                           different environment [default: ./current].
    """

    logging.debug('phase[bench]: args=%s' % kwargs)
    from enos import tasks
    from enos.utils.extra import seekpath
    from enos.utils.errors import EnosFilePathError

    # Get parameters
    is_reset = kwargs.get('--reset', False)
    is_pull_only = kwargs.get('--pull', False)
    workload = pathlib.Path(seekpath(kwargs.get('--workload',
                                                'workload/'))).resolve()
    CLI.debug(f"Use workload directory at {workload}")

    # Launch the *bench* task
    try:
        with _elib_open(kwargs.get('--env')) as env:
            tasks.bench(env, workload, is_reset, is_pull_only)

            CLI.print("""\
            The bench phase completed.  Generated reports could be downloaded
            on your machine with `enos backup`.""")

    # Nicely handle errors for the user
    except EnosFilePathError as err:
        CLI.error(f"""\
        The path "{err.filepath}" does not point to a regular file.  Please,
        ensure to link an existing file with the `--workload`.""")
        sys.exit(1)
    except MissingEnvState as err:
        if err.key in ['kolla-ansible', 'inventory', 'networks']:
            CLI.error(f"""\
            {err.key} could not be found in your enos environment.  Did you
            successfully run `enos up` and `enos os` first?""")
        else:
            CLI.critical(err)
        sys.exit(1)
    except yaml.YAMLError as err:
        error_loc = ""
        if hasattr(err, 'problem_mark'):
            loc = getattr(err, 'problem_mark')
            error_loc = f"at {loc.line+1}:{loc.column+1}"
        CLI.error(f'Syntax error in the file "{workload / "run.yam"}" ' +
                  error_loc)
        sys.exit(1)
    except Exception as e:
        CLI.critical(str(e))
        sys.exit(1)