def test_save_to_disk_dir_create_error(self, mock_mkdir):
        errors = {}
        base_path = tempfile.mkdtemp()
        json_obj = {
            "board": "board",
            "job": "job",
            "kernel": "kernel",
            "defconfig": "defconfig",
            "arch": "arm",
            "defconfig_full": "defconfig+FRAGMENT",
            "lab_name": "lab",
            "git_branch": "branch",
            "build_environment": "build_environment"
        }
        boot_doc = mboot.BootDocument("board", "job", "kernel", "defconfig",
                                      "lab", "branch", "build_environment",
                                      "defconfig+FRAGMENT", "arm")
        expected_path = os.path.join(base_path, "job", "branch", "kernel",
                                     "arm", "defconfig+FRAGMENT",
                                     "build_environment", "lab")
        expected_file = os.path.join(expected_path, "boot-board.json")

        exception = OSError("Error")
        exception.errno = errno.EIO
        mock_mkdir.side_effect = exception

        try:
            bimport.save_to_disk(boot_doc, json_obj, base_path, errors)
            self.assertFalse(os.path.exists(expected_path))
            self.assertFalse(os.path.exists(expected_file))
            self.assertListEqual([500], errors.keys())
        finally:
            shutil.rmtree(base_path)
    def test_save_to_disk_dir_exists(self):
        errors = {}
        base_path = tempfile.mkdtemp()
        json_obj = {
            "board": "board",
            "job": "job",
            "kernel": "kernel",
            "defconfig": "defconfig",
            "arch": "arm",
            "defconfig_full": "defconfig+FRAGMENT",
            "git_branch": "branch",
            "lab_name": "lab",
            "build_environment": "build_environment"
        }
        boot_doc = mboot.BootDocument("board", "job", "kernel", "defconfig",
                                      "lab", "branch", "build_environment",
                                      "defconfig+FRAGMENT", "arm")
        expected_path = os.path.join(base_path, "job", "branch", "kernel",
                                     "arm", "defconfig+FRAGMENT",
                                     "build_environment", "lab")
        expected_file = os.path.join(expected_path, "boot-board.json")
        try:
            os.makedirs(expected_path)
            self.assertTrue(os.path.isdir(expected_path))

            patcher = mock.patch("os.path.isdir", spec=True)
            patched_dir = patcher.start()
            patched_dir.return_value = False
            self.addCleanup(patcher.stop)

            bimport.save_to_disk(boot_doc, json_obj, base_path, errors)
            self.assertTrue(os.path.exists(expected_file))
            self.assertDictEqual({}, errors)
        finally:
            shutil.rmtree(base_path)
 def test_save_to_disk(self):
     errors = {}
     base_path = tempfile.mkdtemp()
     json_obj = {
         "board": "board",
         "job": "job",
         "kernel": "kernel",
         "defconfig": "defconfig",
         "arch": "arm",
         "defconfig_full": "defconfig+FRAGMENT",
         "lab_name": "lab",
         "git_branch": "branch",
         "build_environment": "build_environment"
     }
     boot_doc = mboot.BootDocument("board", "job", "kernel", "defconfig",
                                   "lab", "branch", "build_environment",
                                   "defconfig+FRAGMENT", "arm")
     expected_path = os.path.join(base_path, "job", "branch", "kernel",
                                  "arm", "defconfig+FRAGMENT",
                                  "build_environment", "lab")
     expected_file = os.path.join(expected_path, "boot-board.json")
     try:
         bimport.save_to_disk(boot_doc, json_obj, base_path, errors)
         self.assertTrue(os.path.isdir(expected_path))
         self.assertTrue(os.path.exists(expected_file))
         self.assertDictEqual(
             {},
             errors,
         )
     finally:
         shutil.rmtree(base_path)
예제 #4
0
        err_msg = "Missing mandatory key in boot data"
        utils.LOG.exception(ex)
        utils.LOG.error(err_msg)
        ERR_ADD(errors, 400, err_msg)
        return None

    defconfig_full = boot_json.get(models.DEFCONFIG_FULL_KEY, defconfig)
    arch = boot_json.get(models.ARCHITECTURE_KEY, models.ARM_ARCHITECTURE_KEY)

    if arch not in models.VALID_ARCHITECTURES:
        err_msg = "Invalid architecture found: %s".format(arch)
        utils.LOG.error(err_msg)
        ERR_ADD(errors, 400, err_msg)
        return None

    boot_doc = mboot.BootDocument(board, job, kernel, defconfig, lab_name,
                                  git_branch, defconfig_full, arch)
    boot_doc.created_on = datetime.datetime.now(tz=bson.tz_util.utc)
    _update_boot_doc_from_json(boot_doc, boot_json, errors)
    _update_boot_doc_ids(boot_doc, database)
    return boot_doc


def import_and_save_boot(json_obj, db_options, base_path=utils.BASE_PATH):
    """Wrapper function to be used as an external task.

    This function should only be called by Celery or other task managers.
    Import and save the boot report as found from the parameters in the
    provided JSON object.

    :param json_obj: The JSON object with the values that identify the boot
    report log.
예제 #5
0
    def test_boot_document_to_dict(self):
        boot_doc = mboot.BootDocument("board", "job", "kernel", "defconfig",
                                      "lab", "branch", "build_environment",
                                      "defconfig_full", "arch")
        boot_doc.id = "id"
        boot_doc.job_id = "job-id"
        boot_doc.created_on = "now"
        boot_doc.build_id = "build_id"
        boot_doc.retries = 10
        boot_doc.version = "1.1"
        boot_doc.dtb_append = False
        boot_doc.boot_log = "boot-log"
        boot_doc.boot_log_html = "boot-log-html"
        boot_doc.warnings = 2
        boot_doc.git_commit = "git-commit"
        boot_doc.git_describe = "git-describe"
        boot_doc.git_url = "git-url"
        boot_doc.fastboot_cmd = "fastboot"
        boot_doc.defconfig_full = "defconfig"
        boot_doc.file_server_url = "file-server"
        boot_doc.file_server_resource = "file-resource"
        boot_doc.initrd = "initrd"
        boot_doc.board_instance = "instance"
        boot_doc.device_type = "device-type"
        boot_doc.uimage = "path/to/uImage"
        boot_doc.uimage_addr = "uimage_addr"
        boot_doc.qemu = "qemu_binary"
        boot_doc.qemu_command = "qemu_command"
        boot_doc.plan = "boot"
        boot_doc.plan_variant = "welly"
        boot_doc.metadata = {"foo": "bar"}
        boot_doc.mach = "soc"
        boot_doc.lab_name = "lab-name"
        boot_doc.bootloader = "bootloader"
        boot_doc.bootloader_version = "1.2.3"
        boot_doc.chainloader = "chainloader"
        boot_doc.filesystem = "nfs"
        boot_doc.compiler = "gcc"
        boot_doc.compiler_version = "4.7.3"
        boot_doc.compiler_version_ext = "gcc 4.7.3"
        boot_doc.compiler_version_full = "gcc version 4.7.3"
        boot_doc.cross_compile = "cross-compile"
        boot_doc.boot_job_id = "1234"
        boot_doc.boot_job_url = "http://boot-executor.example.net"
        boot_doc.boot_job_path = "/public/job"

        expected = {
            "_id": "id",
            "arch": "arch",
            "board": "board",
            "board_instance": "instance",
            "boot_log": "boot-log",
            "boot_log_html": "boot-log-html",
            "boot_result_description": None,
            "created_on": "now",
            "defconfig": "defconfig",
            "defconfig_full": "defconfig",
            "device_type": "device-type",
            "build_id": "build_id",
            "dtb": None,
            "dtb_addr": None,
            "dtb_append": False,
            "endian": None,
            "fastboot": False,
            "fastboot_cmd": "fastboot",
            "file_server_resource": "file-resource",
            "file_server_url": "file-server",
            "git_branch": "branch",
            "git_commit": "git-commit",
            "git_describe": "git-describe",
            "git_url": "git-url",
            "initrd": "initrd",
            "initrd_addr": None,
            "job": "job",
            "job_id": "job-id",
            "kernel": "kernel",
            "kernel_image": None,
            "kernel_image_size": None,
            "lab_name": "lab-name",
            "load_addr": None,
            "mach": "soc",
            "metadata": {
                "foo": "bar"
            },
            "qemu": "qemu_binary",
            "qemu_command": "qemu_command",
            "plan": "boot",
            "plan_variant": "welly",
            "retries": 10,
            "status": None,
            "time": 0,
            "uimage": "path/to/uImage",
            "uimage_addr": "uimage_addr",
            "version": "1.1",
            "warnings": 2,
            "bootloader": "bootloader",
            "bootloader_version": "1.2.3",
            "chainloader": "chainloader",
            "filesystem": "nfs",
            "compiler": "gcc",
            "compiler_version": "4.7.3",
            "compiler_version_ext": "gcc 4.7.3",
            "compiler_version_full": "gcc version 4.7.3",
            "cross_compile": "cross-compile",
            "boot_job_id": "1234",
            "boot_job_url": "http://boot-executor.example.net",
            "boot_job_path": "/public/job",
            "build_environment": "build_environment"
        }

        self.assertDictEqual(expected, boot_doc.to_dict())
예제 #6
0
 def test_boot_document_valid_instance(self):
     boot_doc = mboot.BootDocument("board", "job", "kernel", "defconfig",
                                   "lab", "branch", "build_environment",
                                   "defconfig_full", "arch")
     self.assertIsInstance(boot_doc, mbase.BaseDocument)