Exemplo n.º 1
0
    def __load_user_gconfs(gconfs):
        from arjuna.lib.core import ArjunaCore
        console = ArjunaCore.console
        ugcdir = ArjunaCore.config.value(UniteePropertyEnum.PROJECT_CONFIG_DIR)
        ugfpath = os.path.join(ugcdir, "groups.xml")

        def display_err_and_exit(msg):
            console.display_error((msg + " Fix groups template file: {}").format(ugfpath))
            sys_utils.fexit()

        try:
            tree = ETree.parse(ugfpath)
        except Exception as e:
            print(e)
            display_err_and_exit("Groups definition file could not be loaded because of errors in XML.")
        else:
            root = tree.getroot()
            if root.tag != 'groups':
                display_err_and_exit("Invalid groups template file. Root element tag should be >>groups<<.")
            node_dict = etree_utils.convert_to_cidict(root)

            # Validate only group keys exist.
            if node_dict.keys() != {'group'}:
                display_err_and_exit(">>groups<< element can contain only one or more >>group<< elements.")
            elif not node_dict:
                display_err_and_exit(">>groups<< element must contain atleast one >>group<< element.")
            else:
                for group in list(root):
                    run_conf_utils.validate_group_xml_child("session", ugfpath, group)
                    group_attrs = etree_utils.convert_attribs_to_cidict(group)
                    name = group_attrs['name'].strip()
                    if not name:
                        display_err_and_exit(">>name<< attribute in group definition can not be empty.")
                    gconfs[name] = GroupConf(name, group, ugfpath)
Exemplo n.º 2
0
    def __process(self, group_hocon):
        def display_err_and_exit(msg):
            self.console.display_error((msg + " Fix session template file: {}").format(self.sdef.fpath))
            sys_utils.fexit()

        stage_attrs = etree_utils.convert_attribs_to_cidict(self.root)

        if "name" in stage_attrs:
            self.name = stage_attrs['name'].strip()
            if not self.name:
                display_err_and_exit(">>name<< attribute in stage definition should be a non-empty string.")

        threads_err_msg = ">>threads<< attribute in stage definition can be integer >=1."
        if "threads" in stage_attrs:
            self.threads = stage_attrs['threads'].strip()
            try:
                self.threads = int(self.threads)
            except:
                display_err_and_exit(threads_err_msg)
            else:
                if self.threads <=0:
                    display_err_and_exit(threads_err_msg)


        node_dict = etree_utils.convert_to_cidict(self.root)

        if "groups" not in node_dict:
            display_err_and_exit(">>stage<< element in session definition must contain >>groups<< element.")

        for child_tag, child in node_dict.items():
            child_tag = child_tag.lower()
            if child_tag == 'evars':
                evars = child
                for child in evars:
                    run_conf_utils.validate_evar_xml_child("session", self.sdef.fpath, child)
                    run_conf_utils.add_evar_node_to_evars("session", self.evars, child)
            elif child_tag == 'fixtures':
                fixtures = child
                for child in fixtures:
                    run_conf_utils.validate_fixture_xml_child("session", "stage", self.sdef.fpath, child)
                    run_conf_utils.add_fixture_node_to_fixdefs(self.fixture_defs, child)
            elif child_tag =='groups':
                if "group" not in etree_utils.convert_to_cidict(child):
                    display_err_and_exit(">>groups<< element in stage definition must contain atleast one >>group<< element.")

                groups = list(child)

                for index, group in enumerate(groups):
                    run_conf_utils.validate_group_xml_child("session", self.sdef.fpath, group)
                    node = GroupDef(self.sdef, self, len(self.gdefs) + 1, group)
                    self.gdefs.append(node)
            else:
                display_err_and_exit("Unexpected element >>{}<< found in >>stage<< definition in session file.".format(child.tag))
Exemplo n.º 3
0
def validate_rule_xml_child(conf_type, group_name, groups_path, rule_node):
    for k, v in rule_node.attrib.items():
        if k.lower() not in ALLOWED_RULE_ATTRS:
            display_err_and_exit(
                conf_type, groups_path,
                ">>patten<< attributes can only be set as: {}. Check group: {}"
                .format(ALLOWED_RULE_ATTRS, group_name))
    if not MANDATORY_RULE_ATTRS.issubset(
            etree_utils.convert_attribs_to_cidict(rule_node)):
        display_err_and_exit(
            conf_type, groups_path,
            ">>pattern<< element must define these attributes: {}. Check group: {}"
            .format(MANDATORY_RULE_ATTRS, group_name))
Exemplo n.º 4
0
def validate_evar_xml_child(conf_type, session_path, evar_node):
    if evar_node.tag.lower() != 'evar':
        display_err_and_exit(
            conf_type, session_path,
            ">>evars<< element can only contain one or more children of type >>evar<<."
        )
    for k, v in evar_node.attrib.items():
        if k.lower() not in ALLOWED_EVAR_ATTRS:
            display_err_and_exit(
                conf_type, session_path,
                ">>evar<< attributes can only be set as: {}.".format(
                    ALLOWED_EVAR_ATTRS))
    if not MANDATORY_EVAR_ATTRS.issubset(
            etree_utils.convert_attribs_to_cidict(evar_node)):
        display_err_and_exit(
            conf_type, session_path,
            ">>evar<< element must define >>name<< and >>value<< attributes.")
Exemplo n.º 5
0
def validate_gconf_xml_child(conf_type, groups_path, gconf_node):
    if gconf_node.tag.lower() != 'group':
        display_err_and_exit(
            conf_type, groups_path,
            ">>groups<< element can only contain one or more children of type >>group<<."
        )
    for k, v in gconf_node.attrib.items():
        if k.lower() not in ALLOWED_GCONF_ATTRS:
            display_err_and_exit(
                conf_type, groups_path,
                ">>group<< attributes can only be set as: {}.".format(
                    ALLOWED_GCONF_ATTRS))
    if not MANDATORY_GCONF_ATTRS.issubset(
            etree_utils.convert_attribs_to_cidict(gconf_node)):
        display_err_and_exit(
            conf_type, groups_path,
            ">>group<< element must define these attributes: {}".format(
                MANDATORY_GCONF_ATTRS))
Exemplo n.º 6
0
    def __process(self):
        def display_err_and_exit(msg):
            self.console.display_error(
                (msg + " Fix groups template file: {}").format(self.fpath))
            sys_utils.fexit()

        node_dict = etree_utils.convert_to_cidict(self.root)
        pattern_set = {i.lower() for i in self._rule_dict.keys()}

        # Validate only pickers keys exist.
        if node_dict.keys() != {'picker'}:
            display_err_and_exit(
                ">>pickers<< element can contain only one or more >>picker<< element. Check group: {}"
                .format(self.gname))
        elif not node_dict:
            display_err_and_exit(
                ">>pickers<< element must contain atleast one >>picker<< element.Check group: {}"
                .format(self.gname))

        for pattern in list(self.root):
            run_conf_utils.validate_pattern_xml_child("groups", self.gname,
                                                      self.fpath, pattern)
            pattern_dict = etree_utils.convert_attribs_to_cidict(pattern)
            pattern_name = pattern_dict['type'].lower()
            if pattern_name not in pattern_set:
                display_err_and_exit(
                    ">>pickers<< element type attribute can only contain one of {}.Check group: {}"
                    .format(pattern_set, self.gname))
            pattern_value = pattern_dict['pattern'].strip()
            if not pattern_value:
                display_err_and_exit(
                    ">>pickers<< element's >>pattern<< attribute can not be empty.Check group: {}"
                    .format(pattern_set, self.gname))

            if pattern_name in {'cm', 'im'}:
                self._rule_dict[pattern_name].append(
                    re.compile(self.tm_prefix + pattern_value))
            else:
                self._rule_dict[pattern_name].append(re.compile(pattern_value))

        self.__module_matcher = NameMatcher(self._rule_dict['cm'],
                                            self._rule_dict['im'])
        self.__function_matcher = NameMatcher(self._rule_dict['cf'],
                                              self._rule_dict['if'])
Exemplo n.º 7
0
    def __process(self):
        def display_err_and_exit(msg):
            self.console.display_error((msg + " Fix session template file: {}").format(self.sdef.fpath))
            sys_utils.fexit()

        group_attrs = etree_utils.convert_attribs_to_cidict(self.root)
        self.name = group_attrs['name'].strip()
        if not self.name:
            display_err_and_exit(
                ">>name<< attribute in group definition can not be empty.")

        if self.name not in Unitee.groups:
            display_err_and_exit(
                ">>name<< attribute in group definition is pointing to a non-existing group '{}'.".format(self.name))
        else:
            self.__gconf = Unitee.groups[self.name]

        threads_err_msg = ">>threads<< attribute in stage definition can be integer >=1."
        if "threads" in group_attrs:
            self.threads = group_attrs['threads'].strip()
            try:
                self.threads = int(self.threads)
            except:
                display_err_and_exit(threads_err_msg)
            else:
                if self.threads <=0:
                    display_err_and_exit(threads_err_msg)

        node_dict = etree_utils.convert_to_cidict(self.root)

        for child_name, child in node_dict.items():
            if child.tag == 'evars':
                evars = child
                for child in evars:
                    run_conf_utils.validate_evar_xml_child("session", self.sdef.fpath, child)
                    run_conf_utils.add_evar_node_to_evars("session", self.__gconf.evars, child)
            else:
                display_err_and_exit("Unexpected element >>{}<< found in >>group<< definition in session file.".format(child.tag))
Exemplo n.º 8
0
    def __process(self):
        def display_err_and_exit(msg):
            self.console.display_error(
                (msg + " Fix groups template file: {}").format(self.fpath))
            sys_utils.fexit()

        node_dict = etree_utils.convert_to_cidict(self.root)

        # Validate only pickers keys exist.
        if not set(node_dict.keys()).issubset({'modules', 'functions'}):
            display_err_and_exit(
                ">>rules<< element can contain only >>modules<< and/or >>functions<< elements. Check group: {}."
                .format(self.gname))
        elif not node_dict:
            display_err_and_exit(
                ">>rules<< element is empty.Check group: {}.".format(
                    self.gname))

        # xyz -- boolean built-in property or flags
        pattern_1 = re.compile(r"^\s*(?P<object>\w+)\s*$", re.IGNORECASE)
        # tagged abc[,.....]
        pattern_2 = re.compile(r"^\s*tagged\s*(?P<object>(.+?))\s*$",
                               re.IGNORECASE)
        # tags/bugs a[,....] are defined
        pattern_3 = re.compile(
            r"^\s*(?P<container>\w+)\s*(?P<object>.*?)\s+(?P<condition>are)\s+(?P<expression>defined|present)\s*$",
            re.IGNORECASE)
        # prop is DEFINED
        pattern_4 = re.compile(
            r"^\s*(?P<object>\w+)\s+(?P<condition>is)\s+(?P<expression>defined|present)\s*$",
            re.IGNORECASE)
        # xyz condition def
        condition_str = "is|eq|=|==|lt|le|gt|ge|matches|~=|contains|\*="
        p5_raw = r"^\s*(?P<object>\w+)\s+(?P<condition>({}){{1,1}})\s+(?P<expression>.*?)\s*$".format(
            condition_str)
        pattern_5 = re.compile(p5_raw, re.IGNORECASE)
        # property_type xyz condition def
        condition_str = "is|eq|=|==|lt|le|gt|ge|matches|~=|contains|\*="
        p6_raw = r"^\s*(?P<container>prop|evar|tag|bug)\s*(?P<object>\w+)\s+(?P<condition>({}){{1,1}})\s+(?P<expression>.*?)\s*$".format(
            condition_str)
        pattern_6 = re.compile(p6_raw, re.IGNORECASE)

        for target_object in list(self.root):
            tobject = target_object.tag.lower(
            ) == 'modules' and 'Module' or 'Function'
            for rule in list(target_object):
                if rule.tag not in {'include', 'exclude'}:
                    display_err_and_exit(
                        ">>{}<< element in >>rules<< element can contain only rules with >>include<< and/or >>exclude<< tags. Check group: {}."
                        .format(target_object.tag, self.gname))
                run_conf_utils.validate_rule_xml_child("groups", self.gname,
                                                       self.fpath, rule)
                rule_dict = etree_utils.convert_attribs_to_cidict(rule)
                try:
                    match = pattern_1.match(rule_dict['if'])
                    if match:
                        self.__create_1_word_boolean_rule(
                            rule, tobject, rule.tag, match)
                        continue

                    match = pattern_2.match(rule_dict['if'])
                    if match:
                        self.__create_2_word_value_rule_for_tags(
                            rule, tobject, rule.tag, match)
                        continue

                    match = pattern_3.match(rule_dict['if'])
                    if match:
                        self.__create_4_word_value_rule_for_multi_defined(
                            rule, tobject, rule.tag, match)
                        continue

                    match = pattern_4.match(rule_dict['if'])
                    if match:
                        self.__create_3_word_value_rule_for_prop(
                            rule, tobject, rule.tag, match)
                        continue

                    match = pattern_5.match(rule_dict['if'])
                    if match:
                        self.__create_3_word_value_rule_for_prop(
                            rule, tobject, rule.tag, match)
                        continue

                    match = pattern_6.match(rule_dict['if'])
                    if match:
                        self.__create_4_word_rule_for_container(
                            rule, tobject, rule.tag, match)
                        continue

                    # Invalid rule
                    raise Exception(
                        "The >>if<< condition content in the rule is invalid: "
                        + rule_dict['if'])

                except Exception as e:
                    import traceback
                    traceback.print_exc()
                    display_err_and_exit(
                        "Exception in processing rule: {}. {}. Check group: {}."
                        .format(ETree.tostring(rule).strip(), e, self.gname))