示例#1
0
文件: action.py 项目: doytsujin/lava
    def __set_parameters__(self, data):
        try:
            self.__parameters__.update(data)
        except ValueError:
            raise LAVABug("Action parameters need to be a dictionary")

        # Overide the duration if needed
        if "timeout" in self.parameters:
            # preserve existing overrides
            if self.timeout.duration == Timeout.default_duration():
                self.timeout.duration = Timeout.parse(
                    self.parameters["timeout"])
        if "connection_timeout" in self.parameters:
            self.connection_timeout.duration = Timeout.parse(
                self.parameters["connection_timeout"])

        # only unit tests should have actions without a pointer to the job.
        if "failure_retry" in self.parameters and "repeat" in self.parameters:
            raise JobError(
                "Unable to use repeat and failure_retry, use a repeat block")
        if "failure_retry" in self.parameters:
            self.max_retries = self.parameters["failure_retry"]
        if "repeat" in self.parameters:
            self.max_retries = self.parameters["repeat"]
        if self.job:
            if self.job.device:
                if "character_delays" in self.job.device:
                    self.character_delay = self.job.device[
                        "character_delays"].get(self.section, 0)
示例#2
0
def test_parsing():
    # 1/ simple durations
    assert Timeout.parse(
        {"days": 1}) == 86400  # nosec - assert is part of the test process.
    assert Timeout.parse(
        {"hours":
         3}) == 3 * 3600  # nosec - assert is part of the test process.
    assert Timeout.parse(
        {"minutes":
         1}) == 1 * 60  # nosec - assert is part of the test process.
    assert Timeout.parse(
        {"seconds": 345}) == 345  # nosec - assert is part of the test process.

    # 2/ complexe durations
    assert Timeout.parse({
        "minutes": 22,
        "seconds": 17
    }) == 22 * 60 + 17  # nosec - assert is part of the test process.
    assert Timeout.parse(
        {
            "hours": 2,
            "minutes": 22,
            "seconds": 17
        }
    ) == 2 * 3600 + 22 * 60 + 17  # nosec - assert is part of the test process.
    assert Timeout.parse({
        "days": 1,
        "minutes": 22,
        "seconds": 17
    }) == 86400 + 22 * 60 + 17  # nosec - assert is part of the test process.

    # 3/ invalid durations
    assert Timeout.parse({"day": 1}) == Timeout.default_duration(
    )  # nosec - assert is part of the test process.
    assert Timeout.parse({}) == Timeout.default_duration(
    )  # nosec - assert is part of the test process.

    with pytest.raises(ConfigurationError):
        Timeout.parse("")
示例#3
0
    def test_testshell(self):
        testshell = None
        for action in self.job.pipeline.actions:
            self.assertIsNotNone(action.name)
            if isinstance(action, TestShellRetry):
                testshell = action.pipeline.actions[0]
                break
        self.assertIsInstance(testshell, TestShellAction)
        self.assertTrue(testshell.valid)

        if 'timeout' in testshell.parameters:
            time_int = Timeout.parse(testshell.parameters['timeout'])
        else:
            time_int = Timeout.default_duration()
        self.assertEqual(
            datetime.timedelta(seconds=time_int).total_seconds(),
            testshell.timeout.duration)
示例#4
0
 def test_action_timeout(self, which_mock):
     factory = ConnectionFactory()
     job = factory.create_bbb_job("sample_jobs/uboot-ramdisk.yaml")
     job.validate()
     deploy = [
         action for action in job.pipeline.actions if action.name == "tftp-deploy"
     ][0]
     test_action = [
         action
         for action in job.pipeline.actions
         if action.name == "lava-test-retry"
     ][0]
     test_shell = [
         action
         for action in test_action.pipeline.actions
         if action.name == "lava-test-shell"
     ][0]
     self.assertEqual(
         test_shell.connection_timeout.duration, 240
     )  # job specifies 4 minutes
     self.assertEqual(
         test_shell.timeout.duration, 300
     )  # job (test action block) specifies 5 minutes
     self.assertEqual(deploy.timeout.duration, 120)  # job specifies 2 minutes
     self.assertEqual(deploy.connection_timeout.duration, Timeout.default_duration())
     self.assertNotEqual(
         deploy.connection_timeout.duration, test_shell.connection_timeout
     )
     self.assertEqual(test_action.timeout.duration, 300)
     uboot = [
         action for action in job.pipeline.actions if action.name == "uboot-action"
     ][0]
     retry = [
         action
         for action in uboot.pipeline.actions
         if action.name == "uboot-commands"
     ][0]
     auto = [
         action
         for action in retry.pipeline.actions
         if action.name == "auto-login-action"
     ][0]
     self.assertEqual(auto.timeout.duration / 60, 9)  # 9 minutes in the job def
示例#5
0
 def test_action_timeout(self):
     factory = ConnectionFactory()
     job = factory.create_bbb_job('sample_jobs/uboot-ramdisk.yaml')
     job.validate()
     deploy = [
         action for action in job.pipeline.actions
         if action.name == 'tftp-deploy'
     ][0]
     test_action = [
         action for action in job.pipeline.actions
         if action.name == 'lava-test-retry'
     ][0]
     test_shell = [
         action for action in test_action.internal_pipeline.actions
         if action.name == 'lava-test-shell'
     ][0]
     self.assertEqual(test_shell.connection_timeout.duration,
                      240)  # job specifies 4 minutes
     self.assertEqual(test_shell.timeout.duration,
                      300)  # job (test action block) specifies 5 minutes
     self.assertEqual(deploy.timeout.duration,
                      120)  # job specifies 2 minutes
     self.assertEqual(deploy.connection_timeout.duration,
                      Timeout.default_duration())
     self.assertNotEqual(deploy.connection_timeout.duration,
                         test_shell.connection_timeout)
     self.assertEqual(test_action.timeout.duration, 300)
     uboot = [
         action for action in job.pipeline.actions
         if action.name == 'uboot-action'
     ][0]
     retry = [
         action for action in uboot.internal_pipeline.actions
         if action.name == 'uboot-retry'
     ][0]
     auto = [
         action for action in retry.internal_pipeline.actions
         if action.name == 'auto-login-action'
     ][0]
     self.assertEqual(auto.timeout.duration / 60,
                      9)  # 9 minutes in the job def