Exemple #1
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", [])
            for scenario in 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, 'run-bench.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
                    }

                    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)

                    run_ansible([playbook_path],
                                inventory_path,
                                extra_vars=playbook_values)
Exemple #2
0
def up(env=None, **kwargs):
    logging.debug('phase[up]: args=%s' % kwargs)

    # Generate or get the directory for results
    env['resultdir'] = _set_resultdir(kwargs['--env'])
    logging.info("Directory for experiment results is %s", env['resultdir'])

    # Loads the configuration file
    config_file = os.path.abspath(kwargs['-f'])
    if os.path.isfile(config_file):
        env['config_file'] = config_file
        with open(config_file, 'r') as f:
            env['config'].update(yaml.load(f))
            logging.info("Reloaded configuration file %s", env['config_file'])
            logging.debug("Configuration is %s", env['config'])
    else:
        raise EnosFilePathError(
            config_file, "Configuration file %s does not exist" % config_file)

    # Calls the provider and initialise resources
    provider = make_provider(env)
    config = load_config(env['config'], provider.topology_to_resources,
                         provider.default_config())
    rsc, provider_net, eths = \
        provider.init(config, kwargs['--force-deploy'])

    env['rsc'] = rsc
    env['provider_net'] = provider_net
    env['eths'] = eths

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

    # Generates inventory for ansible/kolla
    base_inventory = seekpath(env['config']['inventory'])
    inventory = os.path.join(env['resultdir'], 'multinode')
    generate_inventory(env['rsc'], base_inventory, inventory)
    logging.info('Generates inventory %s' % inventory)

    env['inventory'] = inventory

    # Wait for resources to be ssh reachable
    wait_ssh(env)

    # Set variables required by playbooks of the application
    env['config'].update({
        'vip':
        pop_ip(env),
        'registry_vip':
        env['config']['registry'].get('ip') or pop_ip(env),
        'influx_vip':
        pop_ip(env),
        'grafana_vip':
        pop_ip(env),
        'network_interface':
        eths[NETWORK_IFACE],
        'resultdir':
        env['resultdir'],
        'rabbitmq_password':
        "******",
        'database_password':
        "******",
        'external_vip':
        pop_ip(env)
    })

    # Runs playbook that initializes resources (eg,
    # installs the registry, install monitoring tools, ...)
    up_playbook = os.path.join(ANSIBLE_DIR, 'up.yml')
    run_ansible([up_playbook],
                inventory,
                extra_vars=env['config'],
                tags=kwargs['--tags'])