Esempio n. 1
0
 def test_repositories(self):
     job = TestJob.from_yaml_and_user(self.factory.make_job_yaml(), self.user)
     job_def = yaml_safe_load(job.definition)
     job_ctx = job_def.get("context", {})
     job_ctx.update(
         {"no_kvm": True}
     )  # override to allow unit tests on all types of systems
     device = Device.objects.get(hostname="fakeqemu1")
     device_config = device.load_configuration(job_ctx)  # raw dict
     parser = JobParser()
     obj = PipelineDevice(device_config)
     pipeline_job = parser.parse(job.definition, obj, job.id, None, "")
     allow_missing_path(
         pipeline_job.pipeline.validate_actions, self, "qemu-system-x86_64"
     )
     pipeline = pipeline_job.describe()
     testdata, _ = TestData.objects.get_or_create(testjob=job)
     retval = _get_action_metadata(pipeline["job"]["actions"])
     self.assertEqual(
         retval,
         {
             "test.1.common.definition.from": "git",
             "test.0.common.definition.repository": "git://git.linaro.org/lava-team/lava-functional-tests.git",
             "test.0.common.definition.name": "smoke-tests",
             "test.1.common.definition.repository": "http://git.linaro.org/lava-team/lava-functional-tests.git",
             "boot.0.common.method": "qemu",
             "test.1.common.definition.name": "singlenode-advanced",
             "test.0.common.definition.from": "git",
             "test.0.common.definition.path": "lava-test-shell/smoke-tests-basic.yaml",
             "test.1.common.definition.path": "lava-test-shell/single-node/singlenode03.yaml",
         },
     )
Esempio n. 2
0
 def test_parameter_support(self):
     data = self.factory.make_job_data()
     test_block = [block for block in data["actions"] if "test" in block][0]
     smoke = test_block["test"]["definitions"][0]
     smoke["parameters"] = {
         "VARIABLE_NAME_1": "first variable value",
         "VARIABLE_NAME_2": "second value",
     }
     job = TestJob.from_yaml_and_user(yaml_dump(data), self.user)
     job_def = yaml_safe_load(job.definition)
     job_ctx = job_def.get("context", {})
     job_ctx.update(
         {"no_kvm": True}
     )  # override to allow unit tests on all types of systems
     device = Device.objects.get(hostname="fakeqemu1")
     device_config = device.load_configuration(job_ctx)  # raw dict
     parser = JobParser()
     obj = PipelineDevice(device_config)
     pipeline_job = parser.parse(job.definition, obj, job.id, None, "")
     allow_missing_path(
         pipeline_job.pipeline.validate_actions, self, "qemu-system-x86_64"
     )
     pipeline = pipeline_job.describe()
     testdata, _ = TestData.objects.get_or_create(testjob=job)
     retval = _get_action_metadata(pipeline["job"]["actions"])
     self.assertIn("test.0.common.definition.parameters.VARIABLE_NAME_2", retval)
     self.assertIn("test.0.common.definition.parameters.VARIABLE_NAME_1", retval)
     self.assertEqual(
         retval["test.0.common.definition.parameters.VARIABLE_NAME_1"],
         "first variable value",
     )
     self.assertEqual(
         retval["test.0.common.definition.parameters.VARIABLE_NAME_2"],
         "second value",
     )
Esempio n. 3
0
 def test_parameter_support(self):  # pylint: disable=too-many-locals
     data = self.factory.make_job_data()
     test_block = [block for block in data['actions'] if 'test' in block][0]
     smoke = test_block['test']['definitions'][0]
     smoke['parameters'] = {
         'VARIABLE_NAME_1': "first variable value",
         'VARIABLE_NAME_2': "second value"
     }
     job = TestJob.from_yaml_and_user(yaml.dump(data), self.user)
     job_def = yaml.load(job.definition)
     job_ctx = job_def.get('context', {})
     job_ctx.update({'no_kvm': True})  # override to allow unit tests on all types of systems
     device = Device.objects.get(hostname='fakeqemu1')
     device_config = device.load_configuration(job_ctx)  # raw dict
     parser = JobParser()
     obj = PipelineDevice(device_config)
     pipeline_job = parser.parse(job.definition, obj, job.id, None, "")
     allow_missing_path(pipeline_job.pipeline.validate_actions, self,
                        'qemu-system-x86_64')
     pipeline = pipeline_job.describe()
     device_values = _get_device_metadata(pipeline['device'])
     try:
         testdata, _ = TestData.objects.get_or_create(testjob=job)
     except (MultipleObjectsReturned):
         self.fail('multiple objects')
     for key, value in device_values.items():
         if not key or not value:
             continue
         testdata.attributes.create(name=key, value=value)
     retval = _get_action_metadata(pipeline['job']['actions'])
     self.assertIn('test.0.common.definition.parameters.VARIABLE_NAME_2', retval)
     self.assertIn('test.0.common.definition.parameters.VARIABLE_NAME_1', retval)
     self.assertEqual(retval['test.0.common.definition.parameters.VARIABLE_NAME_1'], 'first variable value')
     self.assertEqual(retval['test.0.common.definition.parameters.VARIABLE_NAME_2'], 'second value')
Esempio n. 4
0
 def test_job(self):
     MetaType.objects.all().delete()
     TestJob.objects.all().delete()
     job = TestJob.from_yaml_and_user(self.factory.make_job_yaml(), self.user)
     job_def = yaml_safe_load(job.definition)
     job_ctx = job_def.get("context", {})
     job_ctx.update(
         {"no_kvm": True}
     )  # override to allow unit tests on all types of systems
     device = Device.objects.get(hostname="fakeqemu1")
     device_config = device.load_configuration(job_ctx)  # raw dict
     parser = JobParser()
     obj = PipelineDevice(device_config)
     pipeline_job = parser.parse(job.definition, obj, job.id, None, "")
     allow_missing_path(
         pipeline_job.pipeline.validate_actions, self, "qemu-system-x86_64"
     )
     pipeline = pipeline_job.describe()
     map_metadata(yaml_dump(pipeline), job)
     self.assertEqual(
         MetaType.objects.filter(metatype=MetaType.DEPLOY_TYPE).count(), 1
     )
     self.assertEqual(
         MetaType.objects.filter(metatype=MetaType.BOOT_TYPE).count(), 1
     )
     count = ActionData.objects.all().count()
     self.assertEqual(TestData.objects.all().count(), 1)
     testdata = TestData.objects.all()[0]
     self.assertEqual(testdata.testjob, job)
     for actionlevel in ActionData.objects.all():
         self.assertEqual(actionlevel.testdata, testdata)
     action_levels = []
     action_levels.extend(job.testdata.actionlevels.all())
     self.assertEqual(count, len(action_levels))
     count = ActionData.objects.filter(
         meta_type__metatype=MetaType.DEPLOY_TYPE
     ).count()
     self.assertNotEqual(
         ActionData.objects.filter(meta_type__metatype=MetaType.BOOT_TYPE).count(), 0
     )
     self.assertEqual(
         ActionData.objects.filter(
             meta_type__metatype=MetaType.UNKNOWN_TYPE
         ).count(),
         0,
     )
     for actionlevel in ActionData.objects.filter(
         meta_type__metatype=MetaType.BOOT_TYPE
     ):
         self.assertEqual(actionlevel.testdata.testjob.id, job.id)
     self.assertEqual(
         ActionData.objects.filter(
             meta_type__metatype=MetaType.DEPLOY_TYPE, testdata__testjob=job
         ).count(),
         count,
     )
Esempio n. 5
0
def device():
    return PipelineDevice({
        "commands": {
            "hard_reset": "/path/to/hard-reset",
            "users": {
                "do_something": {
                    "do": "/bin/do",
                    "undo": "/bin/undo"
                }
            },
        }
    })
Esempio n. 6
0
def test_run(monkeypatch):
    class Proc:
        def wait(self):
            return 0

        def expect(self, arg):
            assert arg == pexpect.EOF

    commands = [
        ["nice", "/home/lava/bin/PiCtrl.py", "PowerPlug", "0", "off"],
        ["nice", "touch"],
    ]

    def spawn(cmd, args, cwd, encoding, codec_errors, logfile, timeout,
              searchwindowsize):
        command = commands.pop(0)
        assert cmd == command[0]
        assert args == command[1:]
        assert encoding == "utf-8"
        assert codec_errors == "replace"
        assert searchwindowsize == 10
        return Proc()

    monkeypatch.setattr(pexpect, "spawn", spawn)

    action = FlasherAction()
    device = PipelineDevice({
        "actions": {
            "deploy": {
                "methods": {
                    "flasher": {
                        "commands": ["{HARD_RESET_COMMAND}", "touch"]
                    }
                }
            }
        },
        "commands": {
            "hard_reset": "/home/lava/bin/PiCtrl.py PowerPlug 0 off"
        },
    })
    action.job = Job(1234, {}, None)
    action.job.device = device
    action.parameters = {"namespace": "common", "images": {}}
    action.section = Flasher.action_type

    # self.commands is populated by validate
    action.validate()
    assert action.errors == []  # nosec - unit test

    # Run the action
    action.run(None, 10)
    assert commands == []  # nosec - unit test
Esempio n. 7
0
 def test_repositories(self):  # pylint: disable=too-many-locals
     job = TestJob.from_yaml_and_user(
         self.factory.make_job_yaml(), self.user)
     job_def = yaml.load(job.definition)
     job_ctx = job_def.get('context', {})
     job_ctx.update({'no_kvm': True})  # override to allow unit tests on all types of systems
     device = Device.objects.get(hostname='fakeqemu1')
     device_config = device.load_configuration(job_ctx)  # raw dict
     parser = JobParser()
     obj = PipelineDevice(device_config)
     pipeline_job = parser.parse(job.definition, obj, job.id, None, "")
     allow_missing_path(pipeline_job.pipeline.validate_actions, self,
                        'qemu-system-x86_64')
     pipeline = pipeline_job.describe()
     device_values = _get_device_metadata(pipeline['device'])
     self.assertEqual(
         device_values,
         {'target.device_type': 'qemu'}
     )
     del pipeline['device']['device_type']
     self.assertNotIn('device_type', pipeline['device'])
     device_values = _get_device_metadata(pipeline['device'])
     try:
         testdata, _ = TestData.objects.get_or_create(testjob=job)
     except (MultipleObjectsReturned):
         self.fail('multiple objects')
     for key, value in device_values.items():
         if not key or not value:
             continue
         testdata.attributes.create(name=key, value=value)
     retval = _get_action_metadata(pipeline['job']['actions'])
     self.assertEqual(
         retval,
         {
             'test.1.common.definition.from': 'git',
             'test.0.common.definition.repository': 'git://git.linaro.org/lava-team/lava-functional-tests.git',
             'test.0.common.definition.name': 'smoke-tests',
             'test.1.common.definition.repository': 'http://git.linaro.org/lava-team/lava-functional-tests.git',
             'boot.0.common.method': 'qemu',
             'test.1.common.definition.name': 'singlenode-advanced',
             'test.0.common.definition.from': 'git',
             'test.0.common.definition.path': 'lava-test-shell/smoke-tests-basic.yaml',
             'test.1.common.definition.path': 'lava-test-shell/single-node/singlenode03.yaml'}
     )
Esempio n. 8
0
 def test_job_multi(self):
     MetaType.objects.all().delete()
     multi_test_file = os.path.join(os.path.dirname(__file__), 'multi-test.yaml')
     self.assertTrue(os.path.exists(multi_test_file))
     with open(multi_test_file, 'r') as test_support:
         data = test_support.read()
     job = TestJob.from_yaml_and_user(data, self.user)
     job_def = yaml.load(job.definition)
     job_ctx = job_def.get('context', {})
     job_ctx.update({'no_kvm': True})  # override to allow unit tests on all types of systems
     device = Device.objects.get(hostname='fakeqemu1')
     device_config = device.load_configuration(job_ctx)  # raw dict
     parser = JobParser()
     obj = PipelineDevice(device_config)
     pipeline_job = parser.parse(job.definition, obj, job.id, None, "")
     allow_missing_path(pipeline_job.pipeline.validate_actions, self,
                        'qemu-system-x86_64')
     pipeline = pipeline_job.describe()
     map_metadata(yaml.dump(pipeline), job)
Esempio n. 9
0
 def test_inline(self):
     """
     Test inline can be parsed without run steps
     """
     data = self.factory.make_job_data()
     test_block = [block for block in data['actions'] if 'test' in block][0]
     smoke = [{
         "path": "inline/smoke-tests-basic.yaml",
         "from": "inline",
         "name": "smoke-tests-inline",
         "repository": {
             "install": {
                 "steps": [
                     "apt",
                 ]
             },
             "metadata": {
                 "description":
                 "Basic system test command for Linaro Ubuntu images",
                 "format": "Lava-Test Test Definition 1.0",
                 "name": "smoke-tests-basic"
             }
         }
     }]
     test_block['test']['definitions'] = smoke
     job = TestJob.from_yaml_and_user(yaml.dump(data), self.user)
     job_def = yaml.safe_load(job.definition)
     job_ctx = job_def.get('context', {})
     job_ctx.update(
         {'no_kvm':
          True})  # override to allow unit tests on all types of systems
     device = Device.objects.get(hostname='fakeqemu1')
     device_config = device.load_configuration(job_ctx)  # raw dict
     parser = JobParser()
     obj = PipelineDevice(device_config)
     pipeline_job = parser.parse(job.definition, obj, job.id, None, "")
     allow_missing_path(pipeline_job.pipeline.validate_actions, self,
                        'qemu-system-x86_64')
     pipeline = pipeline_job.describe()
     map_metadata(yaml.dump(pipeline), job)
Esempio n. 10
0
def test_unconfigured_device(action):
    action.job.device = PipelineDevice({})
    action.parameters = {"name": "some-action"}
    assert not action.validate()  # should not crash
Esempio n. 11
0
def test_run(monkeypatch):
    class FD:
        def readlines(self):
            return []

    class Proc:
        def __init__(self):
            self.stderr = FD()
            self.stdout = FD()

        def poll(self):
            return 0

        def wait(self):
            return 0

    class Poller:
        def register(self, fd, flag):
            pass

    commands = [
        ["nice", "/home/lava/bin/PiCtrl.py", "PowerPlug", "0", "off"],
        ["nice", "touch"],
    ]

    def Popen(
        cmd, cwd, stdout, stderr, bufsize, universal_newlines
    ):  # nosec - unit test
        assert cmd == commands.pop(0)  # nosec - unit test
        assert stdout == subprocess.PIPE  # nosec - unit test
        assert stderr == subprocess.PIPE  # nosec - unit test
        assert bufsize == 1  # nosec - unit test
        assert universal_newlines  # nosec - unit test
        return Proc()

    monkeypatch.setattr(subprocess, "Popen", Popen)
    monkeypatch.setattr(select, "epoll", lambda: Poller())

    action = FlasherAction()
    device = PipelineDevice(
        {
            "actions": {
                "deploy": {
                    "methods": {
                        "flasher": {"commands": ["{HARD_RESET_COMMAND}", "touch"]}
                    }
                }
            },
            "commands": {"hard_reset": "/home/lava/bin/PiCtrl.py PowerPlug 0 off"},
        }
    )
    action.job = Job(1234, {}, None)
    action.job.device = device
    action.parameters = {"namespace": "common", "images": {}}
    action.section = Flasher.action_type

    # self.commands is populated by validate
    action.validate()
    assert action.errors == []  # nosec - unit test

    # Run the action
    action.run(None, 10)
    assert commands == []  # nosec - unit test