Esempio n. 1
0
 def _param_value(self, key):
     try:
         if self._is_param(key):
             return self.params[key]
         elif re.search(r"@", key):
             msg = "Word:%s contains '@', cannot distinguish it `hostname` or `@parameter@`." % key
             raise scenario_error.ScenarioTestDefinitionError(msg)
         else:
             return key
     except KeyError as err:
         msg = "Parameter:%s not found in param table.\n%s" % (key, err)
         raise scenario_error.ScenarioTestDefinitionError(msg)
 def _set_l1patch_data(self):
     try:
         params = self.testdef_data["l1patch-defs"]
         # node info
         self._set_node_mgr(params["physical-info-file"])
         # generate flow-rules files
         gen_exc_wire_flows_cmd = self._make_command(
             params, "generate-exclusive-wire-flows-command"
         )
         gen_shd_wire_flows_cmd = self._make_command(
             params, "generate-shared-wire-flows-command"
         )
         self._exec_command(gen_exc_wire_flows_cmd)
         self._exec_command(gen_shd_wire_flows_cmd)
         # set flow-rules ops command
         self.put_exc_wire_flows_cmd = self._make_command(
             params, "put-exclusive-wire-flows-command"
         )
         self.del_exc_wire_flows_cmd = self._make_command(
             params, "delete-exclusive-wire-flows-command"
         )
         self.put_shd_wire_flows_cmd = self._make_command(
             params, "put-shared-wire-flows-command"
         )
         self.del_shd_wire_flows_cmd = self._make_command(
             params, "delete-shared-wire-flows-command"
         )
     except KeyError as err:
         msg = "Cannot find key:%s in test definition 'l1patch-defs' section." % err.message
         raise scenario_error.ScenarioTestDefinitionError(msg)
 def _set_test_env_params(self):
     try:
         params = self.testdef_data["test-env-params"]
         self.mn_ext_intfs = params["mininet-external-interfaces"]
         self.ofp_version = params["ofs-openflow-version"]
     except KeyError as err:
         msg = "Cannot find key:%s in test definition 'test-env-params' section." % err.message
         raise scenario_error.ScenarioTestDefinitionError(msg)
 def _make_command(data, cmd_key):
     cmd = data[cmd_key]
     for param in re.findall(r"@([_\w\d\-]+)@", cmd):
         param_key = param + "-file"
         try:
             param_val = data[param_key]
         except KeyError:
             msg = "Cannot find param:%s -> key:@%s@ in command-key:%s" % (
                 param, param_key, cmd_key
             )
             raise scenario_error.ScenarioTestDefinitionError(msg)
         replacement = "@%s@" % param
         cmd = cmd.replace(replacement, param_val)
     return cmd
Esempio n. 5
0
 def _generate_ping_task(self, task, host1, host2):
     try:
         match = re.match(self.TASK_RE, task)
         task_name = match.group(1)
         expected_result = match.group(2)
     except AttributeError as err:
         msg = "task:%s does not match pattern 'task-name(RESULT)'.\n%s" % (task, err)
         raise scenario_error.ScenarioTestDefinitionError(msg)
     return {
         "task": "[%s] ping %s to %s" % (task_name, host1, host2),
         "source": self._param_value(host1),
         "destination": self._param_value(host2),
         "command": "ping",
         "expect": expected_result
     }
Esempio n. 6
0
 def __init__(self, file_name):
     try:
         scenario_data_file = open(file_name, 'r')
         # use Ordered Dict to keep key order in file
         scenario_data = json.load(
             scenario_data_file, object_pairs_hook=collections.OrderedDict)
         self.params = scenario_data["params"]
         self.scenarios = scenario_data["scenarios"]
         self.data = []
     except ValueError as err:
         msg = "Scenario data file, %s: json parse error.\n%s" % (file_name, err)
         raise scenario_error.ScenarioTestDefinitionError(msg)
     except IOError as err:
         msg = "Cannot open sceanrio data file: %s.\n%s" % (file_name, err)
         raise scenario_error.ScenarioTestError(msg)
    # test_runner selection
    class_str = test_runner.runner_class
    if class_str:
        logger.info("reload runner class: %s", class_str)
        match = re.match(r"(.+)\.(.+)", class_str)
        if match:
            package_name = match.group(1)
            class_name = match.group(2)
            try:
                exec("import %s" % package_name)
                class_gen_str = "%s(args.testdef)" % class_str
                test_runner = eval(class_gen_str)
            except ImportError as err:
                msg = "Cannot import package:%s of test runner class." % package_name
                raise scenario_error.ScenarioTestDefinitionError(msg)
            except AttributeError as err:
                msg = "Cannot find class:%s in package:%s.\n%s" % (
                    class_name, package_name, err)
                raise scenario_error.ScenarioTestDefinitionError(msg)
        else:
            msg = "Test runner class string format error in file:%s." % args.testdef
            raise scenario_error.ScenarioTestDefinitionError(msg)

    # run test
    logger.info("run scenario test with runner-class: %s",
                test_runner.__class__.__name__)
    opt_dic = {
        'manual': args.manual,
        'test-cli': args.test_cli,
        'layer1': args.layer1,