コード例 #1
0
    def test_multiple_actions_nodeps(self):
        """
        Check that a given component can contain multiple actions.
        RuleSet: #ta, #ta
        Components: a#ta
        Expecting: a#ta with 2 actions.
        """
        rules = set()
        rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                    name="R1",
                                    action="Action for a",
                                    types=["ta@cat"]))
        rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                    name="R2",
                                    action="Action for a",
                                    types=["ta@cat"]))
        ruleset = RuleSet(rules)
        depgraph = ruleset.get_depgraph([Component("a#ta@cat")])
        components = depgraph.components_map

        self.assertTrue(components is not None)
        self.assertEquals(len(components), 1, "Map: %s" % components)
        self.assertTrue("a#ta@cat" in components)
        self.assertTrue("R1" in components["a#ta@cat"].actions)
        self.assertTrue("R2" in components["a#ta@cat"].actions)
        self.assertEquals(len(components["a#ta@cat"].actions), 2)
        self.assertEquals(len(depgraph.dag.node_attributes("a#ta@cat")), 2)
コード例 #2
0
 def test_filtered_components(self):
     """
     Check that filter other than NONE and ALL works as expected.
     RuleSet: #root (filter = in.*)
     Components: in#root in_foo#root out#root
     Expecting: in#root, in_foo#root out#root
     (out#root has no action, it has been filtered out)
     """
     rules = set()
     rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                 name="R",
                                 types=["root@cat"],
                                 action="Root Action",
                                 # WARNING: space is important here!!
                                 filter="%name =~ in.*"))
     ruleset = RuleSet(rules)
     depgraph = ruleset.get_depgraph([Component("in#root@cat"),
                                      Component("in_foo#root@cat"),
                                      Component("out#root@cat")])
     components = depgraph.components_map
     self.assertTrue(components is not None)
     self.assertEquals(len(components), 3)
     self.assertTrue("in#root@cat" in components)
     self.assertTrue("in_foo#root@cat" in components)
     self.assertTrue("out#root@cat" in components)
     self.assertTrue(depgraph.dag is not None)
     self.assertTrue(depgraph.dag.has_node("in#root@cat"))
     self.assertTrue(depgraph.dag.has_node("in_foo#root@cat"))
     self.assertTrue(depgraph.dag.has_node("out#root@cat"))
     self.assertTrue("R" in components["in#root@cat"].actions)
     self.assertEquals("Root Action", components["in#root@cat"].actions["R"])
     self.assertTrue("R" in components["in_foo#root@cat"].actions)
     self.assertEquals("Root Action", components["in_foo#root@cat"].actions["R"])
     self.assertTrue("Root Action" not in components["out#root@cat"].actions)
コード例 #3
0
 def test_simple_nodeps_ta_tb_a_b(self):
     """
     RuleSet: #ta, #tb,
     Components: a#ta, b#tb
     Expecting: a#ta, b#tb
     """
     rules = set()
     rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                 name="Ra",
                                 action="Action for a",
                                 types=["ta@cat"]))
     rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                 name="Rb",
                                 action="Action for b",
                                 types=["tb@cat"]))
     ruleset = RuleSet(rules)
     depgraph = ruleset.get_depgraph([Component("a#ta@cat"),
                                      Component("b#tb@cat")])
     components = depgraph.components_map
     self.assertTrue(components is not None)
     self.assertEquals(len(components), 2)
     self.assertTrue("a#ta@cat" in components)
     self.assertTrue("b#tb@cat" in components)
     self.assertTrue(depgraph.dag is not None)
     self.assertTrue(depgraph.dag.has_node("a#ta@cat"))
     self.assertTrue(depgraph.dag.has_node("b#tb@cat"))
     self.assertTrue("Ra" in components["a#ta@cat"].actions)
     self.assertEquals("Action for a", components["a#ta@cat"].actions["Ra"])
     self.assertTrue("Rb" in components["b#tb@cat"].actions)
     self.assertEquals("Action for b", components["b#tb@cat"].actions["Rb"])
     self.assertNoEdgeBetween(depgraph.dag, "a#ta@cat", "b#tb@cat")
コード例 #4
0
    def test_no_root_with_self_cycle_in_graph_rules(self):
        """
        There are no match in the given component list.
        RuleSet: #ta->#ta
        Components: c#tc
        Expecting: c#tc.
        """
        rules = set()
        rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                    name="Ra",
                                    action="Action for a",
                                    types=["ta@cat"],
                                    depsfinder=tools.getMockDepsFinderCmd(["foo#bar@cat"]),
                                    dependson=["Ra"]))

        ruleset = RuleSet(rules)
        depgraph = ruleset.get_depgraph([Component("c#tc@cat")])
        components = depgraph.components_map

        self.assertTrue(components is not None)
        self.assertEquals(len(components), 1, "Map: %s" % components)
        self.assertTrue("c#tc@cat" in components)
        self.assertTrue(depgraph.dag is not None)
        self.assertEquals(len(depgraph.dag.nodes()), 1)
        self.assertTrue(depgraph.dag.has_node("c#tc@cat"))
コード例 #5
0
    def test_root_in_simple_cycle(self):
        """
        The root is in a simple cycle.
        RuleSet: #ta->#tb, #tb->#tc, #tc->#ta (triangle)
        Components: b#tb
        Expecting: b#tb
        """
        rules = set()
        rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                    name="Ra",
                                    action="Action for a",
                                    types=["ta@cat"],
                                    dependson=["Rb"]))
        rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                    name="Rb",
                                    action="Action for b",
                                    types=["tb@cat"],
                                    dependson=["Rc"]))
        rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                    name="Rc",
                                    action="Action for c",
                                    dependson=["Ra"],
                                    types=["tc@cat"]))
        ruleset = RuleSet(rules)
        depgraph = ruleset.get_depgraph([Component("b#tb@cat")])
        components = depgraph.components_map

        self.assertTrue(components is not None)
        self.assertEquals(len(components), 1, "Map: %s" % components)
        self.assertTrue("b#tb@cat" in components)
        self.assertTrue(depgraph.dag is not None)
        self.assertTrue(depgraph.dag.has_node("b#tb@cat"))
コード例 #6
0
    def test_simple_deps_ta_tb_b_a_withdepsfinder(self):
        """
        RuleSet: #ta->#tb,
        Components: b#tb, a#ta (reverse)
        Component a does provide a depfinder that returns b#tb
        Expecting: a#ta -> b#tb
        """
        rules = set()
        rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                    name="Ra",
                                    action="Action for a",
                                    types=["ta@cat"],
                                    depsfinder=tools.getMockDepsFinderCmd(["b#tb@cat"]),
                                    dependson=["Rb"]))
        rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                    name="Rb",
                                    action="Action for b",
                                    types=["tb@cat"]))
        ruleset = RuleSet(rules)
        depgraph = ruleset.get_depgraph([Component("b#tb@cat"),
                                         Component("a#ta@cat")])
        components = depgraph.components_map

        self.assertTrue(components is not None)
        self.assertEquals(len(components), 2, "Map: %s" % components)
        self.assertTrue("a#ta@cat" in components)
        self.assertTrue("b#tb@cat" in components)
        self.assertTrue(depgraph.dag is not None)
        self.assertTrue(depgraph.dag.has_node("a#ta@cat"))
        self.assertTrue(depgraph.dag.has_node("b#tb@cat"))
        self.assertTrue(depgraph.dag.has_edge(("a#ta@cat", "b#tb@cat")))
コード例 #7
0
 def test_simple_deps_ta_tb_b_a_nodepsfinder(self):
     """
     RuleSet: #ta->#tb,
     Components: b#tb, a#ta (reverse than test_simple_deps_ta_tb_a_b_nodepsfinder)
     Expecting: a#ta, b#tb (order does not count)
     """
     rules = set()
     rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                 name="Ra",
                                 action="Action for a",
                                 types=["ta@cat"],
                                 dependson=["Rb"]))
     rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                 name="Rb",
                                 action="Action for b",
                                 types=["tb@cat"]))
     ruleset = RuleSet(rules)
     depgraph = ruleset.get_depgraph([Component("b#tb@cat"),
                                      Component("a#ta@cat")])
     components = depgraph.components_map
     self.assertTrue(components is not None)
     self.assertEquals(len(components), 2)
     self.assertTrue("a#ta@cat" in components)
     self.assertTrue("b#tb@cat" in components)
     self.assertTrue(depgraph.dag is not None)
     self.assertTrue(depgraph.dag.has_node("a#ta@cat"))
     self.assertTrue(depgraph.dag.has_node("b#tb@cat"))
     self.assertNoEdgeBetween(depgraph.dag, "a#ta@cat", "b#tb@cat")
コード例 #8
0
 def test_filtered_none_components_deps(self):
     """
     Check that dependencies are not in the graph when they are filtered out.
     RuleSet: #root -> #deps (filter = NONE)
     Components: a#root
     Component a provides a depfinder that returns b#deps
     Expecting: a#root, b#deps (b#deps has no action, it has been filtered out)
     """
     rules = set()
     rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                 name="R-root",
                                 action="Root Action",
                                 types=["root@cat"],
                                 depsfinder=tools.getMockDepsFinderCmd(["b#deps@cat"]),
                                 dependson=["R-Deps"]))
     rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                 name="R-Deps",
                                 action="Deps Action",
                                 types=["deps@cat"],
                                 filter=NONE))
     ruleset = RuleSet(rules)
     depgraph = ruleset.get_depgraph([Component("a#root@cat")])
     components = depgraph.components_map
     self.assertTrue(components is not None)
     self.assertEquals(len(components), 2)
     self.assertTrue(depgraph.dag is not None)
     self.assertTrue("a#root@cat" in components)
     self.assertTrue("R-root" in components["a#root@cat"].actions)
     self.assertEquals("Root Action", components["a#root@cat"].actions["R-root"])
     self.assertTrue("b#deps@cat" in components)
     self.assertTrue(depgraph.dag.has_node("a#root@cat"))
     self.assertTrue(depgraph.dag.has_node("b#deps@cat"))
     self.assertTrue("Deps Action" not in components["b#deps@cat"].actions)
コード例 #9
0
 def test_a_nop_b(self):
     """
     Check that action NONE are understood correctly.
     RuleSet: #root, #dep (filter = ALL),
     a#root -> b#dep (a.action=NONE)
     Expecting: a#root -> b#dep
     But a#root has no attribute in the xml graph.
     """
     rules = set()
     rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                 name="Root",
                                 types=["root@cat"],
                                 action=NONE,
                                 depsfinder=tools.getMockDepsFinderCmd(["b#dep@cat"]),
                                 dependson=['Dep']))
     rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                 name="Dep",
                                 types=["dep@cat"],
                                 action="Dep Action"))
     ruleset = RuleSet(rules)
     depgraph = ruleset.get_depgraph([Component("a#root@cat")])
     components = depgraph.components_map
     self.assertTrue(components is not None)
     self.assertEquals(len(components), 2)
     self.assertTrue("a#root@cat" in components)
     self.assertTrue("b#dep@cat" in components)
     self.assertTrue(depgraph.dag is not None)
     self.assertTrue(depgraph.dag.has_node("a#root@cat"))
     self.assertTrue(depgraph.dag.has_node("b#dep@cat"))
     self.assertFalse("Root" in components["a#root@cat"].actions, components)
     self.assertTrue("Dep" in components["b#dep@cat"].actions)
     attributes = depgraph.dag.node_attributes("a#root@cat")
     self.assertEquals(len(attributes), 0)
     attributes = depgraph.dag.node_attributes("b#dep@cat")
     self.assertEquals(len(attributes), 1)
コード例 #10
0
    def test_multiple_actions_cycle(self):
        """
        Check that a given component can contain multiple actions.
        RuleSet: R1:#ta, R2:#ta->R1
        Components: a#ta (R1 depsfinder returns itself: a#ta)
        Expecting: a#ta with 2 actions and a cycle.
        """
        rules = set()
        rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                    name="R1",
                                    action="Action for a",
                                    types=["ta@cat"]))
        rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                    name="R2",
                                    action="Action for a",
                                    types=["ta@cat"],
                                    depsfinder=tools.getMockDepsFinderCmd(["a#ta@cat"]),
                                    dependson=["R1"]))
        ruleset = RuleSet(rules)
        depgraph = ruleset.get_depgraph([Component("a#ta@cat")])
        components = depgraph.components_map

        self.assertTrue(components is not None)
        self.assertEquals(len(components), 1, "Map: %s" % components)
        self.assertTrue("a#ta@cat" in components)
        self.assertTrue("R1" in components["a#ta@cat"].actions)
        self.assertTrue("R2" in components["a#ta@cat"].actions)
        self.assertEquals(len(components["a#ta@cat"].actions), 2)
        self.assertEquals(len(depgraph.dag.node_attributes("a#ta@cat")), 2)
        self.assertTrue(depgraph.dag.has_edge(("a#ta@cat", "a#ta@cat")))
コード例 #11
0
 def test_ruleset_field_empty(self):
     ruleset = RuleSet(set())
     self.assertTrue(ruleset.name is None)
     self.assertEquals(ruleset.rules, set())
     graph = ruleset.get_rules_graph()
     self.assertTrue(graph is not None)
     self.assertEquals(len(graph.edges()), 0)
     self.assertEquals(len(graph.nodes()), 0)
コード例 #12
0
 def test_ruleset_field_single(self):
     rules = set()
     rules.add(tools.create_rule(self.__class__.__name__,
                                 "ruleset_field_single"))
     ruleset = RuleSet(rules)
     self.assertEquals(ruleset.name, self.__class__.__name__)
     self.assertEquals(ruleset.rules, rules)
     graph = ruleset.get_rules_graph()
     self.assertTrue(graph is not None)
     self.assertEquals(len(graph.edges()), 0)
     self.assertEquals(len(graph.nodes()), 1)
     self.assertTrue(graph.has_node("ruleset_field_single"))
コード例 #13
0
    def test_only_root_rules_applied(self):
        """
        Check that a rule is applied on a parameter only if it is a
        potential root.

        RuleSet: #t(action1)->#t(action2)
        Components: a#t, b#t (a#t depsfinder returns b#t)
        Expecting: a#t contains only 1 action while b#t contains two actions.
        """
        rules = set()
        rules.add(
            tools.create_rule(
                ruleset=self.__class__.__name__,
                name="Ra",
                action="Action for a",
                types=["t@cat"],
                filter="%name =~ a",
                depsfinder=tools.getMockDepsFinderCmd(["b#t@cat"]),
                dependson=["Rdep"],
            )
        )
        rules.add(
            tools.create_rule(
                ruleset=self.__class__.__name__,
                name="Rb",
                action="Action for b",
                types=["t@cat"],
                filter="%name =~ b",
                dependson=["Rdep"],
            )
        )
        rules.add(
            tools.create_rule(ruleset=self.__class__.__name__, name="Rdep", action="Action for dep", types=["t@cat"])
        )

        ruleset = RuleSet(rules)
        depgraph = ruleset.get_depgraph([Component("a#t@cat"), Component("b#t@cat")])
        components = depgraph.components_map

        self.assertTrue(components is not None)
        self.assertEquals(len(components), 2, "Map: %s" % components)
        self.assertTrue("a#t@cat" in components)
        self.assertTrue("b#t@cat" in components)
        self.assertEquals(len(components["a#t@cat"].actions), 1)
        self.assertTrue("Ra" in components["a#t@cat"].actions)
        self.assertEquals(len(components["b#t@cat"].actions), 2)
        self.assertTrue("Rb" in components["b#t@cat"].actions)
        self.assertTrue("Rdep" in components["b#t@cat"].actions)

        self.assertEquals(len(depgraph.dag.node_attributes("a#t@cat")), 1)
        self.assertEquals(len(depgraph.dag.node_attributes("b#t@cat")), 2)
コード例 #14
0
 def test_unknown_component(self):
     rules = set()
     rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                 name="test_unknown_component",
                                 types=["known@cat"]))
     ruleset = RuleSet(rules)
     depgraph = ruleset.get_depgraph([Component("foo#unknown@cat")])
     components = depgraph.components_map
     self.assertTrue(components is not None)
     self.assertEquals(len(components), 1)
     self.assertTrue("foo#unknown@cat" in components)
     self.assertEquals(len(components["foo#unknown@cat"].actions), 0)
     self.assertTrue(depgraph.dag is not None)
     self.assertTrue(depgraph.dag.has_node("foo#unknown@cat"))
コード例 #15
0
 def test_ruleset_dependencies(self):
     rules = set()
     rules.add(tools.create_rule(self.__class__.__name__,
                                 "ruleset_dependencies"))
     rules.add(tools.create_rule(self.__class__.__name__,
                                 "ruleset_dependencies2",
                                 dependson=["ruleset_dependencies"]))
     ruleset = RuleSet(rules)
     self.assertEquals(ruleset.name, self.__class__.__name__)
     self.assertEquals(ruleset.rules, rules)
     graph = ruleset.get_rules_graph()
     self.assertTrue(graph is not None)
     self.assertEquals(len(graph.edges()), 1)
     self.assertTrue(graph.has_edge(("ruleset_dependencies2",
                                     "ruleset_dependencies")))
コード例 #16
0
 def test_filtered_all_components(self):
     rules = set()
     rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                 name="test_filtered_all_components",
                                 types=["any@cat"],
                                 filter=ALL))
     ruleset = RuleSet(rules)
     depgraph = ruleset.get_depgraph([Component("in#any@cat"),
                                      Component("out#any@cat")])
     components = depgraph.components_map
     self.assertTrue(components is not None)
     self.assertEquals(len(components), 2)
     self.assertTrue(depgraph.dag is not None)
     self.assertTrue("in#any@cat" in components)
     self.assertTrue("out#any@cat" in components)
     self.assertTrue(depgraph.dag.has_node("in#any@cat"))
     self.assertTrue(depgraph.dag.has_node("out#any@cat"))
コード例 #17
0
    def test_simple_noroot(self):
        """
        There are no root in the given component list.
        RuleSet: #ta->#tb, #ta->#tc, #tb->#tc (triangle)
        Components: b#tb, a#ta (each depsfinder returns c#tc)
        Expecting: a#ta -> b#tb, a#ta -> c#tc
        """
        rules = set()
        rules.add(
            tools.create_rule(
                ruleset=self.__class__.__name__,
                name="Ra",
                action="Action for a",
                types=["ta@cat"],
                depsfinder=tools.getMockDepsFinderCmd(["c#tc@cat"]),
                dependson=["Rb", "Rc"],
            )
        )
        rules.add(
            tools.create_rule(
                ruleset=self.__class__.__name__,
                name="Rb",
                action="Action for b",
                types=["tb@cat"],
                depsfinder=tools.getMockDepsFinderCmd(["c#tc@cat"]),
                dependson=["Rc"],
            )
        )
        rules.add(
            tools.create_rule(ruleset=self.__class__.__name__, name="Rc", action="Action for c", types=["tc@cat"])
        )
        ruleset = RuleSet(rules)
        depgraph = ruleset.get_depgraph([Component("b#tb@cat"), Component("a#ta@cat")])
        components = depgraph.components_map

        self.assertTrue(components is not None)
        self.assertEquals(len(components), 3, "Map: %s" % components)
        self.assertTrue("a#ta@cat" in components)
        self.assertTrue("b#tb@cat" in components)
        self.assertTrue("c#tc@cat" in components)
        self.assertTrue(depgraph.dag is not None)
        self.assertTrue(depgraph.dag.has_node("a#ta@cat"))
        self.assertTrue(depgraph.dag.has_node("b#tb@cat"))
        self.assertTrue(depgraph.dag.has_node("c#tc@cat"))
        self.assertTrue(depgraph.dag.has_edge(("a#ta@cat", "c#tc@cat")))
        self.assertTrue(depgraph.dag.has_edge(("b#tb@cat", "c#tc@cat")))
コード例 #18
0
 def test_root_rules_all_type_apply_to_any_component(self):
     rules = set()
     r1 = tools.create_rule(ruleset=self.__class__.__name__, name="R1", action="A1", types=["ALL"])
     rules.add(r1)
     ruleset = RuleSet(rules)
     depgraph = ruleset.get_depgraph([Component("a#ta@cat"), Component("b#tb@cat")])
     components = depgraph.components_map
     self.assertTrue(components is not None)
     self.assertEquals(len(components), 2)
     self.assertTrue("a#ta@cat" in components)
     self.assertTrue("b#tb@cat" in components)
     self.assertTrue(depgraph.dag is not None)
     self.assertTrue(depgraph.dag.has_node("a#ta@cat"))
     self.assertTrue(depgraph.dag.has_node("b#tb@cat"))
     self.assertTrue("R1" in components["a#ta@cat"].actions)
     self.assertTrue("R1" in components["b#tb@cat"].actions)
     self.assertNoEdgeBetween(depgraph.dag, "a#ta@cat", "b#tb@cat")
コード例 #19
0
    def test_rule_applied_at_most_once(self):
        """
        Check that a given rule is applied at most once for a given component.
        RuleSet: #ta->#tc, #tb->#tc
        Components: a#ta, b#tb (each depsfinder returns c#tc)
        Expecting: c#tc contains a single action (applied once only).
        """
        rules = set()
        rules.add(
            tools.create_rule(
                ruleset=self.__class__.__name__,
                name="Ra",
                action="Action for a",
                types=["ta@cat"],
                depsfinder=tools.getMockDepsFinderCmd(["c#tc@cat"]),
                dependson=["Rc"],
            )
        )
        rules.add(
            tools.create_rule(
                ruleset=self.__class__.__name__,
                name="Rb",
                action="Action for b",
                types=["tb@cat"],
                depsfinder=tools.getMockDepsFinderCmd(["c#tc@cat"]),
                dependson=["Rc"],
            )
        )
        rules.add(
            tools.create_rule(ruleset=self.__class__.__name__, name="Rc", action="Action for c", types=["tc@cat"])
        )
        ruleset = RuleSet(rules)
        depgraph = ruleset.get_depgraph([Component("b#tb@cat"), Component("a#ta@cat")])
        components = depgraph.components_map

        self.assertTrue(components is not None)
        self.assertEquals(len(components), 3, "Map: %s" % components)
        self.assertTrue("c#tc@cat" in components)
        self.assertTrue("Rc" in components["c#tc@cat"].actions)
        self.assertEquals(components["c#tc@cat"].actions["Rc"], "Action for c")
        self.assertEquals(len(components["c#tc@cat"].actions), 1)
        self.assertEquals(len(depgraph.dag.node_attributes("c#tc@cat")), 1)
コード例 #20
0
ファイル: cli.py プロジェクト: af-bull/sequencer
def graphrules(db, config, args):
    """
    This action fetch the rules from the DB sequencer table and call
    the DGM stage for the computation of the related graph.
    This graph is then given to the user in the DOT format.
    """
    usage = "Usage: %prog [global_options] " + GRAPHRULES_ACTION_NAME + \
        " [action_options] ruleset"
    doc = GRAPHRULES_DOC + \
        " The graph is given in DOT format."
    parser = optparse.OptionParser(usage, description=doc)
    add_options_to(parser, ['--out'], config)
    (options, action_args) = parser.parse_args(args)
    if len(action_args) != 1:
        parser.error(GRAPHRULES_ACTION_NAME + ": ruleSet is missing.")

    req_ruleset = action_args[0]
    rules = db.get_rules_for(req_ruleset)
    ruleset = RuleSet(rules.values())
    write_graph_to(ruleset.get_rules_graph(), options.out)
コード例 #21
0
    def test_rule_applied_only_on_deps(self):
        """
        Check that a rule 'd' is applied on a component 'e' only if
        'e' is a parameter or if it is a dependency of a component 'c'
        which was applied a rule 'r' where 'r'.dependson includes 'd'.

        RuleSet: #ta->#tb, #tc
        Components: a#ta, c#tc (a#ta depsfinder returns foo#tc)
        Expecting: foo#tc should not contain any action.
        """
        rules = set()
        rules.add(
            tools.create_rule(
                ruleset=self.__class__.__name__,
                name="Ra",
                action="Action for a",
                types=["ta@cat"],
                depsfinder=tools.getMockDepsFinderCmd(["foo#tc@cat"]),
                dependson=["Rb"],
            )
        )
        rules.add(
            tools.create_rule(ruleset=self.__class__.__name__, name="Rb", action="Action for b", types=["tb@cat"])
        )
        rules.add(
            tools.create_rule(ruleset=self.__class__.__name__, name="Rc", action="Action for c", types=["tc@cat"])
        )
        ruleset = RuleSet(rules)
        depgraph = ruleset.get_depgraph([Component("a#ta@cat"), Component("c#tc@cat")])
        components = depgraph.components_map

        self.assertTrue(components is not None)
        self.assertEquals(len(components), 3, "Map: %s" % components)
        self.assertTrue("foo#tc@cat" in components)
        self.assertTrue("c#tc@cat" in components)
        self.assertTrue("Rc" in components["c#tc@cat"].actions)
        self.assertEquals(components["c#tc@cat"].actions["Rc"], "Action for c")
        self.assertEquals(len(components["c#tc@cat"].actions), 1)
        self.assertEquals(len(depgraph.dag.node_attributes("c#tc@cat")), 1)
        self.assertEquals(len(components["foo#tc@cat"].actions), 0)
        self.assertEquals(len(depgraph.dag.node_attributes("foo#tc@cat")), 0)
コード例 #22
0
ファイル: cli.py プロジェクト: pv-bull/sequencer
def makedepgraph(config, rules, components_lists, options):
    """
    Return the dependency graph for the given pair ('req_ruleset',
    'components_lists').
    """
    ruleset = RuleSet(rules.values())
    all_set = get_component_set_from(config, components_lists)
    force_opt = options.force
    force_rule = force_opt.split(',') if force_opt is not None else []
    docache = True if getattr(options, 'docache', 'yes') == 'yes' else False
    _LOGGER.debug("Caching filter results (docache) is: %s", docache)
    depgraph = ruleset.get_depgraph(all_set, force_rule, docache)
    if _LOGGER.isEnabledFor(logging.DEBUG):
        _LOGGER.debug("Components set: %s",
                      NodeSet.fromlist([to_str_from_unicode(x.id) for x in all_set]))
        _LOGGER.debug("Remaining: %s",
                      NodeSet.fromlist([str(x) for x in depgraph.remaining_components]))
        _LOGGER.debug("List: %s",
                      NodeSet.fromlist([str(x) for x in depgraph.components_map]))

    return depgraph
コード例 #23
0
 def test_substitution_in_depsfinder(self):
     rules = set()
     pattern = "%id-%name-%type-%category-%ruleset-%rulename"
     rules.add(tools.create_rule(ruleset="RS",
                                 name="RN",
                                 action="Action",
                                 depsfinder=tools.getMockDepsFinderCmd([pattern]),
                                 types=["known@cat"],
                                 dependson=["Dummy"]))
     rules.add(tools.create_rule(ruleset="RS",
                                 name="Dummy"))
     ruleset = RuleSet(rules)
     depgraph = ruleset.get_depgraph([Component("foo#known@cat")])
     components = depgraph.components_map
     self.assertTrue(components is not None)
     self.assertEquals(len(components), 2)
     self.assertTrue("foo#known@cat" in components)
     self.assertTrue("foo#known@cat-foo-known-cat-RS-RN" in components)
     self.assertTrue(depgraph.dag is not None)
     self.assertTrue(depgraph.dag.has_node("foo#known@cat"))
     self.assertTrue(depgraph.dag.has_node("foo#known@cat-foo-known-cat-RS-RN"))
コード例 #24
0
    def test_multiple_deps_ta_tb_a_withdepsfinder(self):
        """
        RuleSet: #ta->#tb,
        Components: a#ta
        Component a does provide a depfinder that returns b1#tb, b2#tb, c#tc
        Expecting: a#ta -> b1#tb, a#ta->b2#tb
        """
        rules = set()
        rules.add(
            tools.create_rule(
                ruleset=self.__class__.__name__,
                name="Ra",
                action="Action for a",
                types=["ta@cat"],
                depsfinder=tools.getMockDepsFinderCmd(["b1#tb@cat", "b2#tb@cat", "c#tc@cat"]),
                dependson=["Rb"],
            )
        )
        rules.add(
            tools.create_rule(ruleset=self.__class__.__name__, name="Rb", action="Action for b", types=["tb@cat"])
        )
        ruleset = RuleSet(rules)
        depgraph = ruleset.get_depgraph([Component("a#ta@cat")])
        components = depgraph.components_map

        self.assertTrue(components is not None)
        self.assertEquals(len(components), 4, "Map: %s" % components)
        self.assertTrue("a#ta@cat" in components)
        self.assertTrue("b1#tb@cat" in components)
        self.assertTrue("b2#tb@cat" in components)
        self.assertTrue("c#tc@cat" in components)
        self.assertTrue(depgraph.dag is not None)
        self.assertTrue(depgraph.dag.has_node("a#ta@cat"))
        self.assertTrue(depgraph.dag.has_node("b1#tb@cat"))
        self.assertTrue(depgraph.dag.has_node("b2#tb@cat"))
        self.assertTrue(depgraph.dag.has_node("c#tc@cat"))
        self.assertTrue(depgraph.dag.has_edge(("a#ta@cat", "b1#tb@cat")))
        self.assertTrue(depgraph.dag.has_edge(("a#ta@cat", "b2#tb@cat")))
        # There are no rules for #tc, therefore, no dependency hold.
        self.assertFalse(depgraph.dag.has_edge(("a#ta@cat", "c#tc@cat")))
コード例 #25
0
 def test_substitution_in_action(self):
     rules = set()
     pattern = "%id-%name-%type-%category-%ruleset-%rulename"
     rules.add(tools.create_rule(ruleset="RS",
                                 name="RN",
                                 action= pattern,
                                 types=["known@cat"]))
     ruleset = RuleSet(rules)
     depgraph = ruleset.get_depgraph([Component("foo#known@cat")])
     components = depgraph.components_map
     self.assertTrue(components is not None)
     self.assertEquals(len(components), 1)
     self.assertTrue("foo#known@cat" in components)
     self.assertTrue("RN" in components["foo#known@cat"].actions)
     self.assertEquals("foo#known@cat-foo-known-cat-RS-RN",
                       components["foo#known@cat"].actions["RN"])
     self.assertTrue(depgraph.dag is not None)
     self.assertTrue(depgraph.dag.has_node("foo#known@cat"))
     attributes = depgraph.dag.node_attributes("foo#known@cat")
     self.assertEquals(len(attributes), 1)
     rule, action = attributes[0]
     self.assertEquals(rule, "RN")
     self.assertEquals(action, "foo#known@cat-foo-known-cat-RS-RN")
コード例 #26
0
    def test_filtered_none_components_requested(self):
        """
        When filtered out components are requested, rules are not applied, but the
        components remains in the depgraph.
        RuleSet: #root (filter = NONE) -> #deps
        Components: a#root, b#deps
        Component a provides a depfinder that returns c#deps but it is filtered out
        Expecting: a#root, b#deps (a#root has no action)
        """
        rules = set()
        rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                    name="R-root",
                                    action="Root Action",
                                    types=["root@cat"],
                                    depsfinder=tools.getMockDepsFinderCmd(["c#deps@cat"]),
                                    dependson=["R-deps"],
                                    filter=NONE))
        rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                    name="R-deps",
                                    action="Deps Action",
                                    types=["deps@cat"]))

        ruleset = RuleSet(rules)
        depgraph = ruleset.get_depgraph([Component("a#root@cat"),
                                         Component("b#deps@cat")])
        components = depgraph.components_map
        self.assertTrue(components is not None)
        self.assertEquals(len(components), 2)
        self.assertTrue(depgraph.dag is not None)
        self.assertTrue("a#root@cat" in components)
        self.assertTrue("b#deps@cat" in components)
        self.assertTrue("c#deps@cat" not in components)
        self.assertTrue("R-root" not in components["a#root@cat"].actions)
        self.assertTrue("R-deps" in components["b#deps@cat"].actions)
        self.assertTrue(depgraph.dag.has_node("a#root@cat"))
        self.assertTrue(depgraph.dag.has_node("b#deps@cat"))
        self.assertFalse(depgraph.dag.has_node("c#deps@cat"))
コード例 #27
0
    def test_force_options(self):
        """
        Check that force flag is generated correctly.
        """
        rules = set()
        rules.add(tools.create_rule(ruleset=self.__class__.__name__,
                                    name="R",
                                    types=["force@cat"],
                                    action="Test Action"))
        ruleset = RuleSet(rules)
        depgraph = ruleset.get_depgraph([Component("in#force@cat")], force_rule=['R'])
        components = depgraph.components_map
        attributes = depgraph.dag.node_attributes("in#force@cat")
        self.assertEquals('R?force=always', attributes[0][0])
        self.assertTrue("R?force=always" in components["in#force@cat"].actions)
        self.assertEquals("Test Action", components["in#force@cat"].actions["R?force=always"])

        depgraph = ruleset.get_depgraph([Component("in#force@cat")],
                                        force_rule=[NOT_FORCE_OP + 'R'])
        components = depgraph.components_map
        attributes = depgraph.dag.node_attributes("in#force@cat")
        self.assertEquals('R?force=never', attributes[0][0])
        self.assertTrue("R?force=never" in components["in#force@cat"].actions)
        self.assertEquals("Test Action", components["in#force@cat"].actions["R?force=never"])
コード例 #28
0
 def test_empty_ruleset(self):
     ruleset = RuleSet(set())
     depgraph = ruleset.get_depgraph([Component("unknown#unknown@cat")])
     self.assertTrue(depgraph is not None)