예제 #1
0
def test_plan_without_server_info():
    context = plan.PlanContext()
    context.register_action('build', build_action)
    myplan = _get_plan(data={'a': 'a'},
                       content=[u'def myserver():\n', u'    build(a)\n'])
    actions = context.execute(myplan, 'myserver')
    assert actions[0].build.platform == e3.env.Env().build.platform
예제 #2
0
def test_plan_without_server_info():
    context = plan.PlanContext()
    context.register_action("build", build_action)
    myplan = _get_plan(data={"a": "a"},
                       content=["def myserver():\n", "    build(a)\n"])
    actions = context.execute(myplan, "myserver")
    assert actions[0].build.platform == e3.env.Env().build.platform
예제 #3
0
def _get_new_plancontext(machine_name, ignore_disabled=True):
    server = host.Host(hostname=machine_name,
                       platform="x86_64-linux",
                       version="suse11")

    context = plan.PlanContext(server=server, ignore_disabled=ignore_disabled)
    context.register_action("build", build_action)
    return context
예제 #4
0
    def test_dag_2_plan_sources(self):
        """Check that we can extract values from plan in final dag.

        Use a scheduler to always create source and ask for a source
        package creation.
        """
        # Create a new plan context
        ac = self.create_context()
        current_env = BaseEnv()
        cm = plan.PlanContext(server=current_env)

        # Declare available actions and their signature
        def anod_action(
            module,
            build=None,
            default_build=False,
            host=None,
            target=None,
            board=None,
            weathers=None,
            product_version=None,
            when_missing=None,
            manual_action=False,
            qualifier=None,
            jobs=None,
            releases=None,
            process_suffix=None,
            update_vcs=False,
            recursive=None,
            query_range=None,
            force_repackage=False,
        ):
            pass

        cm.register_action("anod_source", anod_action)

        # Create a simple plan
        content = ["def myserver():", '    anod_source("spec1", weathers="foo")']
        with open("plan.txt", "w") as f:
            f.write("\n".join(content))
        myplan = plan.Plan({})
        myplan.load("plan.txt")

        # Execute the plan and create anod actions
        for action in cm.execute(myplan, "myserver"):
            ac.add_plan_action(action)

        for uid, _ in ac.tree:
            if uid.endswith("sources"):
                assert ac.tree.get_tag(uid)
            elif uid.endswith(".source.spec1-src"):
                assert ac.tree.get_tag(uid)
                assert (
                    ac.tree.get_context(
                        vertex_id=uid, reverse_order=True, max_distance=1
                    )[0][2]["plan_args"]["weathers"]
                    == "foo"
                )
예제 #5
0
    def test_duplicated_lines(self, reject_duplicates):
        """Check that duplicated lines in plan are properly rejected."""
        ac = self.create_context(reject_duplicates=reject_duplicates)
        current_env = BaseEnv()
        cm = plan.PlanContext(server=current_env)

        # Declare available actions and their signature
        def anod_action(
            module,
            build=None,
            default_build=False,
            host=None,
            target=None,
            board=None,
            weathers=None,
            product_version=None,
            when_missing=None,
            manual_action=False,
            qualifier=None,
            jobs=None,
            releases=None,
            process_suffix=None,
            update_vcs=False,
            recursive=None,
            query_range=None,
            force_repackage=False,
        ):
            pass

        cm.register_action("anod_build", anod_action)
        # Create a simple plan
        content = [
            "def myserver():",
            '    anod_build("spec3", weathers="A")',
            '    anod_build("spec3", weathers="B")',
        ]
        with open("plan.plan", "w") as f:
            f.write("\n".join(content))
        myplan = plan.Plan({})
        myplan.load("plan.plan")

        if not reject_duplicates:
            # Execute the plan and create anod actions
            # Execute the plan and create anod actions
            for action in cm.execute(myplan, "myserver"):
                ac.add_plan_action(action)

            for uid, _ in ac.tree:
                if uid.endswith("build"):
                    assert ac.tree.get_tag(uid)["plan_args"]["weathers"] == "B"
        else:

            with pytest.raises(SchedulingError):
                for action in cm.execute(myplan, "myserver"):
                    ac.add_plan_action(action)
예제 #6
0
def _get_new_plancontext(machine_name):
    server = host.Host(hostname=machine_name,
                       platform='x86_64-linux',
                       version='suse11')

    def build(spec, build=None, host=None, target=None):
        return 'build ' + spec

    context = plan.PlanContext(server=server)
    context.register_action('build', build)
    return context
예제 #7
0
    def test_plan_call_args(self):
        """Retrieve call args values."""
        current_env = BaseEnv()
        cm = plan.PlanContext(server=current_env)

        # Declare available actions and their signature
        def plan_action(platform):
            pass

        cm.register_action("plan_action", plan_action)
        # Create a simple plan
        content = ["def myserver():", '    plan_action("any")']
        with open("plan.txt", "w") as f:
            f.write("\n".join(content))
        myplan = plan.Plan({})
        myplan.load("plan.txt")

        for action in cm.execute(myplan, "myserver"):
            assert action.plan_call_args == {"platform": "any"}
            assert action.plan_args["platform"] == BaseEnv().platform
예제 #8
0
    def test_plan_call_args(self):
        """Retrieve call args values."""
        current_env = BaseEnv()
        cm = plan.PlanContext(server=current_env)

        # Declare available actions and their signature
        def plan_action(platform):
            pass

        cm.register_action('plan_action', plan_action)
        # Create a simple plan
        content = [u'def myserver():', u'    plan_action("any")']
        with open('plan.txt', 'w') as f:
            f.write('\n'.join(content))
        myplan = plan.Plan({})
        myplan.load('plan.txt')

        for action in cm.execute(myplan, 'myserver'):
            assert action.plan_call_args == {'platform': 'any'}
            assert action.plan_args['platform'] == BaseEnv().platform
예제 #9
0
    def test_dag_2_plan(self):
        """Check that we can extract values from plan in final dag.

        Some paramaters passed in the plan are lost in the final
        scheduled dag, when plan lines are transformed into
        anod actions. It is possible to retrieve them by looking
        at the tags.
        """
        # Create a new plan context
        ac = self.create_context()
        current_env = BaseEnv()
        cm = plan.PlanContext(server=current_env)

        # Declare available actions and their signature
        def anod_action(
            module,
            build=None,
            default_build=False,
            host=None,
            target=None,
            board=None,
            weathers=None,
            product_version=None,
            when_missing=None,
            manual_action=False,
            qualifier=None,
            jobs=None,
            releases=None,
            process_suffix=None,
            update_vcs=False,
            recursive=None,
            query_range=None,
            force_repackage=False,
        ):
            pass

        for a in ("anod_build", "anod_install", "anod_source", "anod_test"):
            cm.register_action(a, anod_action)

        # Create a simple plan
        content = [
            "def myserver():",
            '    anod_build("spec12", weathers="foo")',
            '    anod_build("spec10", weathers="foo")',
            '    anod_build("spec11", weathers="bar")',
        ]
        with open("plan.txt", "w") as f:
            f.write("\n".join(content))
        myplan = plan.Plan({}, plan_ext=".txt")
        myplan.load("plan.txt")

        # Execute the plan and create anod actions
        for action in cm.execute(myplan, "myserver"):
            primitive = action.action.replace("anod_", "", 1)
            ac.add_anod_action(
                name=action.module,
                env=current_env if action.default_build else action,
                primitive=primitive,
                qualifier=action.qualifier,
                plan_line=action.plan_line,
                plan_args=action.plan_args,
            )

        # Create a reverse tag to have a working get_context
        # when looking for parameters such as weathers we want to
        # get the plan line that has triggered the action, e.g.
        # for spec3.build that has been triggered by spec10.build
        # we want to propagate the weathers set in the line
        #     anod_build("spec10", weathers="foo")
        # in the Build action for spec3
        reverse_dag = ac.tree.reverse_graph()

        for uid, action in ac.tree:
            if uid.endswith("spec12.build"):
                assert ac.tree.get_tag(uid)
                cdist, cuid, ctag = reverse_dag.get_context(uid)[0]
                assert cuid == uid
                assert ctag["plan_args"]["weathers"] == "foo"
                assert ctag["plan_line"] == "plan.txt:2"
            elif uid.endswith("spec3.build"):
                assert not ac.tree.get_tag(uid)
                cdist, cuid, ctag = reverse_dag.get_context(uid)[0]
                assert cuid != uid
                assert cuid.endswith("spec10.build")
                assert ctag["plan_args"]["weathers"] == "foo"
                assert ctag["plan_line"] == "plan.txt:3"
            elif uid.endswith("spec11.build"):
                assert ac.tree.get_tag(uid), ac.tree.tags
                cdist, cuid, ctag = reverse_dag.get_context(uid)[0]
                assert cuid == uid
                assert ctag["plan_args"]["weathers"] == "bar"
                assert ctag["plan_line"] == "plan.txt:4"

                # Also verify that the instance deps is properly loaded
                assert set(action.anod_instance.deps.keys()) == {"spec1"}
                assert action.anod_instance.deps[
                    "spec1"].__class__.__name__ == "Spec1"

        # Also test that we are still able to extract the values
        # after having scheduled the action graph.

        # Create an explict build action to make sure that the plan can be
        # scheduled
        ac.add_anod_action(
            name="spec3",
            env=current_env,
            primitive="build",
            plan_line="plan.txt:5",
            plan_args={"weathers": "my_spec3_weather"},
        )

        sched_dag = ac.schedule(ac.always_download_source_resolver)
        sched_rev = sched_dag.reverse_graph()

        for uid, action in sched_dag:
            if uid.endswith("spec12.build"):
                assert sched_dag.get_tag(uid)

                # Also verify that the instance deps is properly loaded
                assert set(
                    action.anod_instance.deps.keys()) == {"spec1", "spec11"}
                assert (action.anod_instance.deps["spec11"].__class__.__name__
                        == "Spec11")
                assert action.anod_instance.deps[
                    "spec1"].__class__.__name__ == "Spec1"

            elif uid.endswith("spec3.build"):
                assert sched_dag.get_tag(uid)
                assert (sched_rev.get_context(uid)[0][2]["plan_args"]
                        ["weathers"] == "my_spec3_weather")
예제 #10
0
    def test_duplicated_lines(self, reject_duplicates):
        """Check that duplicated lines in plan are properly rejected."""
        ac = self.create_context(reject_duplicates=reject_duplicates)
        current_env = BaseEnv()
        cm = plan.PlanContext(server=current_env)

        # Declare available actions and their signature
        def anod_action(module,
                        build=None,
                        default_build=False,
                        host=None,
                        target=None,
                        board=None,
                        weathers=None,
                        product_version=None,
                        when_missing=None,
                        manual_action=False,
                        qualifier=None,
                        jobs=None,
                        releases=None,
                        process_suffix=None,
                        update_vcs=False,
                        recursive=None,
                        query_range=None,
                        force_repackage=False):
            pass

        cm.register_action('anod_build', anod_action)
        # Create a simple plan
        content = [
            u'def myserver():', u'    anod_build("spec3", weathers="A")',
            u'    anod_build("spec3", weathers="B")'
        ]
        with open('plan.txt', 'w') as f:
            f.write('\n'.join(content))
        myplan = plan.Plan({})
        myplan.load('plan.txt')

        if not reject_duplicates:
            # Execute the plan and create anod actions
            # Execute the plan and create anod actions
            for action in cm.execute(myplan, 'myserver'):
                primitive = action.action.replace('anod_', '', 1)
                ac.add_anod_action(
                    name=action.module,
                    env=current_env if action.default_build else action,
                    primitive=primitive,
                    qualifier=action.qualifier,
                    plan_line=action.plan_line,
                    plan_args=action.plan_args)

            for uid, action in ac.tree:
                if uid.endswith('build'):
                    assert ac.tree.get_tag(uid)['plan_args']['weathers'] == 'B'
        else:

            with pytest.raises(SchedulingError):
                for action in cm.execute(myplan, 'myserver'):
                    primitive = action.action.replace('anod_', '', 1)
                    ac.add_anod_action(
                        name=action.module,
                        env=current_env if action.default_build else action,
                        primitive=primitive,
                        qualifier=action.qualifier,
                        plan_line=action.plan_line,
                        plan_args=action.plan_args)
예제 #11
0
    def test_dag_2_plan_sources(self):
        """Check that we can extract values from plan in final dag.

        Use a scheduler to always create source and ask for a source
        package creation.
        """
        # Create a new plan context
        ac = self.create_context()
        current_env = BaseEnv()
        cm = plan.PlanContext(server=current_env)

        # Declare available actions and their signature
        def anod_action(module,
                        build=None,
                        default_build=False,
                        host=None,
                        target=None,
                        board=None,
                        weathers=None,
                        product_version=None,
                        when_missing=None,
                        manual_action=False,
                        qualifier=None,
                        jobs=None,
                        releases=None,
                        process_suffix=None,
                        update_vcs=False,
                        recursive=None,
                        query_range=None,
                        force_repackage=False):
            pass

        cm.register_action('anod_source', anod_action)

        # Create a simple plan
        content = [
            u'def myserver():', u'    anod_source("spec1", weathers="foo")'
        ]
        with open('plan.txt', 'w') as f:
            f.write('\n'.join(content))
        myplan = plan.Plan({})
        myplan.load('plan.txt')

        # Execute the plan and create anod actions
        for action in cm.execute(myplan, 'myserver'):
            primitive = action.action.replace('anod_', '', 1)
            ac.add_anod_action(
                name=action.module,
                env=current_env if action.default_build else action,
                primitive=primitive,
                qualifier=action.qualifier,
                plan_line=action.plan_line,
                plan_args=action.plan_args)

        for uid, action in ac.tree:
            if uid.endswith('sources'):
                assert ac.tree.get_tag(uid)
            elif uid.endswith('spec1-src'):
                assert ac.tree.get_tag(uid) is None
                assert ac.tree.get_context(
                    vertex_id=uid, reverse_order=True,
                    max_distance=1)[0][2]['plan_args']['weathers'] == 'foo'