Example #1
0
    def run_one_scenario(self, scenario_cfg, output_file):
        """run one scenario using context"""
        runner_cfg = scenario_cfg["runner"]
        runner_cfg['output_filename'] = output_file

        options = scenario_cfg.get('options', {})
        scenario_cfg['options'] = self._parse_options(options)

        # TODO support get multi hosts/vms info
        context_cfg = {}
        if "host" in scenario_cfg:
            context_cfg['host'] = Context.get_server(scenario_cfg["host"])

        if "target" in scenario_cfg:
            if is_ip_addr(scenario_cfg["target"]):
                context_cfg['target'] = {}
                context_cfg['target']["ipaddr"] = scenario_cfg["target"]
            else:
                context_cfg['target'] = Context.get_server(
                    scenario_cfg["target"])
                if self._is_same_heat_context(scenario_cfg["host"],
                                              scenario_cfg["target"]):
                    context_cfg["target"]["ipaddr"] = \
                        context_cfg["target"]["private_ip"]
                else:
                    context_cfg["target"]["ipaddr"] = \
                        context_cfg["target"]["ip"]

        if "targets" in scenario_cfg:
            ip_list = []
            for target in scenario_cfg["targets"]:
                if is_ip_addr(target):
                    ip_list.append(target)
                    context_cfg['target'] = {}
                else:
                    context_cfg['target'] = Context.get_server(target)
                    if self._is_same_heat_context(scenario_cfg["host"],
                                                  target):
                        ip_list.append(context_cfg["target"]["private_ip"])
                    else:
                        ip_list.append(context_cfg["target"]["ip"])
            context_cfg['target']['ipaddr'] = ','.join(ip_list)

        if "nodes" in scenario_cfg:
            context_cfg["nodes"] = parse_nodes_with_context(scenario_cfg)
            context_cfg["networks"] = get_networks_from_nodes(
                context_cfg["nodes"])
        runner = base_runner.Runner.get(runner_cfg)

        print("Starting runner of type '%s'" % runner_cfg["type"])
        runner.run(scenario_cfg, context_cfg)

        return runner
Example #2
0
def run_one_scenario(task_id, scenario_cfg, output_file):
    '''run one scenario using context'''
    runner_cfg = scenario_cfg["runner"]
    runner_cfg['output_filename'] = output_file

    # TODO support get multi hosts/vms info
    context_cfg = {}
    if "host" in scenario_cfg:
        scenario_cfg['host'] = scenario_cfg['host'] + '-' + task_id[:8]
        context_cfg['host'] = Context.get_server(scenario_cfg["host"])

    if "target" in scenario_cfg:
        scenario_cfg['target'] = scenario_cfg['target'] + '-' + task_id[:8]
        if is_ip_addr(scenario_cfg["target"]):
            context_cfg['target'] = {}
            context_cfg['target']["ipaddr"] = scenario_cfg["target"]
        else:
            context_cfg['target'] = Context.get_server(scenario_cfg["target"])
            if _is_same_heat_context(scenario_cfg["host"],
                                     scenario_cfg["target"]):
                context_cfg["target"]["ipaddr"] = \
                    context_cfg["target"]["private_ip"]
            else:
                context_cfg["target"]["ipaddr"] = \
                    context_cfg["target"]["ip"]

    if "targets" in scenario_cfg:
        ip_list = []
        for target in scenario_cfg["targets"]:
            if is_ip_addr(target):
                ip_list.append(target)
                context_cfg['target'] = {}
            else:
                context_cfg['target'] = Context.get_server(target)
                if _is_same_heat_context(scenario_cfg["host"], target):
                    ip_list.append(context_cfg["target"]["private_ip"])
                else:
                    ip_list.append(context_cfg["target"]["ip"])
        context_cfg['target']['ipaddr'] = ','.join(ip_list)

    if "nodes" in scenario_cfg:
        context_cfg["nodes"] = parse_nodes_with_context(scenario_cfg)
    runner = base_runner.Runner.get(runner_cfg)

    print "Starting runner of type '%s'" % runner_cfg["type"]
    runner.run(scenario_cfg, context_cfg)

    return runner
Example #3
0
def run_one_scenario(scenario_cfg, output_file):
    '''run one scenario using context'''
    runner_cfg = scenario_cfg["runner"]
    runner_cfg['output_filename'] = output_file

    # TODO support get multi hosts/vms info
    context_cfg = {}
    if "host" in scenario_cfg:
        context_cfg['host'] = Context.get_server(scenario_cfg["host"])

    if "target" in scenario_cfg:
        if is_ip_addr(scenario_cfg["target"]):
            context_cfg['target'] = {}
            context_cfg['target']["ipaddr"] = scenario_cfg["target"]
        else:
            context_cfg['target'] = Context.get_server(scenario_cfg["target"])
            if _is_same_heat_context(scenario_cfg["host"],
                                     scenario_cfg["target"]):
                context_cfg["target"]["ipaddr"] = \
                    context_cfg["target"]["private_ip"]
            else:
                context_cfg["target"]["ipaddr"] = \
                    context_cfg["target"]["ip"]

    if "targets" in scenario_cfg:
        ip_list = []
        for target in scenario_cfg["targets"]:
            if is_ip_addr(target):
                ip_list.append(target)
                context_cfg['target'] = {}
            else:
                context_cfg['target'] = Context.get_server(target)
                if _is_same_heat_context(scenario_cfg["host"], target):
                    ip_list.append(context_cfg["target"]["private_ip"])
                else:
                    ip_list.append(context_cfg["target"]["ip"])
        context_cfg['target']['ipaddr'] = ','.join(ip_list)

    if "nodes" in scenario_cfg:
        context_cfg["nodes"] = parse_nodes_with_context(scenario_cfg)
    runner = base_runner.Runner.get(runner_cfg)

    print "Starting runner of type '%s'" % runner_cfg["type"]
    runner.run(scenario_cfg, context_cfg)

    return runner
Example #4
0
def parse_nodes_with_context(scenario_cfg):
    '''paras the 'nodes' fields in scenario '''
    nodes = scenario_cfg["nodes"]

    nodes_cfg = {}
    for nodename in nodes:
        nodes_cfg[nodename] = Context.get_server(nodes[nodename])

    return nodes_cfg
Example #5
0
def parse_nodes_with_context(scenario_cfg):
    """paras the 'nodes' fields in scenario """
    nodes = scenario_cfg["nodes"]

    nodes_cfg = {}
    for nodename in nodes:
        nodes_cfg[nodename] = Context.get_server(nodes[nodename])

    return nodes_cfg
Example #6
0
 def config_context_target(cfg):
     target = cfg['target']
     if is_ip_addr(target):
         context_cfg['target'] = {"ipaddr": target}
     else:
         context_cfg['target'] = Context.get_server(target)
         if self._is_same_context(cfg["host"], target):
             context_cfg['target']["ipaddr"] = context_cfg['target'][
                 "private_ip"]
         else:
             context_cfg['target']["ipaddr"] = context_cfg['target'][
                 "ip"]
Example #7
0
def parse_nodes_with_context(scenario_cfg):
    """parse the 'nodes' fields in scenario """
    # ensure consistency in node instantiation order
    return OrderedDict(
        (nodename, Context.get_server(scenario_cfg["nodes"][nodename]))
        for nodename in sorted(scenario_cfg["nodes"]))
Example #8
0
    def run_one_scenario(self, scenario_cfg, output_file):
        """run one scenario using context"""
        runner_cfg = scenario_cfg["runner"]
        runner_cfg['output_filename'] = output_file

        options = scenario_cfg.get('options', {})
        scenario_cfg['options'] = self._parse_options(options)

        # TODO support get multi hosts/vms info
        context_cfg = {}
        server_name = scenario_cfg.get('options', {}).get('server_name', {})

        def config_context_target(cfg):
            target = cfg['target']
            if is_ip_addr(target):
                context_cfg['target'] = {"ipaddr": target}
            else:
                context_cfg['target'] = Context.get_server(target)
                if self._is_same_context(cfg["host"], target):
                    context_cfg['target']["ipaddr"] = context_cfg['target'][
                        "private_ip"]
                else:
                    context_cfg['target']["ipaddr"] = context_cfg['target'][
                        "ip"]

        host_name = server_name.get('host', scenario_cfg.get('host'))
        if host_name:
            context_cfg['host'] = Context.get_server(host_name)

        for item in [server_name, scenario_cfg]:
            try:
                config_context_target(item)
            except KeyError:
                pass
            else:
                break

        if "targets" in scenario_cfg:
            ip_list = []
            for target in scenario_cfg["targets"]:
                if is_ip_addr(target):
                    ip_list.append(target)
                    context_cfg['target'] = {}
                else:
                    context_cfg['target'] = Context.get_server(target)
                    if self._is_same_context(scenario_cfg["host"], target):
                        ip_list.append(context_cfg["target"]["private_ip"])
                    else:
                        ip_list.append(context_cfg["target"]["ip"])
            context_cfg['target']['ipaddr'] = ','.join(ip_list)

        if "nodes" in scenario_cfg:
            context_cfg["nodes"] = parse_nodes_with_context(scenario_cfg)
            context_cfg["networks"] = get_networks_from_nodes(
                context_cfg["nodes"])

        runner = base_runner.Runner.get(runner_cfg)

        LOG.info("Starting runner of type '%s'", runner_cfg["type"])
        runner.run(scenario_cfg, context_cfg)

        return runner