示例#1
0
 def validate(self):
     super().validate()
     lxc_version = debian_package_version(pkg='lxc', split=False)
     if lxc_version is not '':
         self.logger.info("lxc, installed at version: %s", lxc_version)
     else:
         self.logger.info(
             "lava-lxc-mocker, installed at version: %s",
             debian_package_version(pkg='lava-lxc-mocker', split=False))
     protocols = [protocol.name for protocol in self.job.protocols]
     if LxcProtocol.name not in protocols:
         self.logger.debug("Missing protocol '%s' in %s", LxcProtocol.name,
                           protocols)
         self.errors = "Missing protocol '%s'" % LxcProtocol.name
     which('lxc-create')
示例#2
0
文件: job.py 项目: ivoire/lava
    def validate(self):
        """
        Public wrapper for the pipeline validation.
        Send a "fail" results if needed.
        """
        label = "lava-dispatcher, installed at version: %s" % debian_package_version(
            pkg="lava-dispatcher")
        self.logger.info(label)
        self.logger.info("start: 0 validate")
        start = time.time()

        success = False
        try:
            self._validate()
            success = True
        except LAVAError:
            raise
        except Exception as exc:
            # provide useful info on command line, e.g. failed unit tests.
            self.logger.exception(traceback.format_exc())
            raise LAVABug(exc)
        finally:
            self.logger.info("validate duration: %.02f", time.time() - start)
            self.logger.results({
                "definition": "lava",
                "case": "validate",
                "result": "pass" if success else "fail",
            })
            if not success:
                self.cleanup(connection=None)
示例#3
0
文件: dbutils.py 项目: czfgd/lava
def _get_job_metadata(job):
    retval = {}
    # Add original_definition checksum to metadata
    retval.update({
        "definition-checksum":
        hashlib.md5(  # nosec - not used for crypto
            job.original_definition.encode("utf-8")).hexdigest()
    })
    # Add lava-server-version to metadata
    packaged = debian_package_version(pkg="lava-server")
    if packaged:
        retval.update({"lava-server-version": packaged})
    return retval
示例#4
0
文件: api.py 项目: czfgd/lava
    def version(self):
        """
        Name
        ----
        `system.version` ()

        Description
        -----------
        Return the lava-server version string

        Arguments
        ---------
        None

        Return value
        ------------
        lava-server version string
        """
        return debian_package_version(pkg="lava-server")
示例#5
0
 def get_debian_version(self, architecture):
     pkg_suffix = self.get_qemu_pkg_suffix(architecture)
     if pkg_suffix == "":
         return False
     if "docker" in self.parameters:
         # We will find it by get_raw_version()
         return False
     ver_str = debian_package_version(pkg="qemu-system-%s" % pkg_suffix)
     arch_str = debian_package_arch(pkg="qemu-system-%s" % pkg_suffix)
     if ver_str == "":
         return False
     self.qemu_data = {
         "qemu_version": ver_str,
         "host_arch": arch_str,
         "job_arch": architecture,
     }
     self.logger.info(
         "qemu-system-%s, installed at version: %s, host architecture: %s",
         pkg_suffix,
         ver_str,
         arch_str,
     )
     return True
示例#6
0
文件: qemu.py 项目: b59118/lava
    def validate(self):
        super().validate()

        # 'arch' must be defined in job definition context.
        architecture = self.job.parameters["context"]["arch"]
        if "available_architectures" not in self.job.device:
            self.errors = "Device lacks list of available architectures."
        try:
            if architecture not in self.job.device["available_architectures"]:
                self.errors = "Non existing architecture specified in context arch parameter. Please check the device configuration for available options."
                return
        except KeyError:
            self.errors = "Arch parameter must be set in the context section. Please check the device configuration for available architectures."
            return
        if architecture in ["amd64", "x86_64"]:
            ver_str = debian_package_version(pkg="qemu-system-x86",
                                             split=False)
            arch_str = debian_package_arch(pkg="qemu-system-x86")
            self.qemu_data = {
                "qemu_version": ver_str,
                "host_arch": arch_str,
                "job_arch": architecture,
            }
            self.logger.info(
                "qemu-system-x86, installed at version: %s, host architecture: %s",
                ver_str,
                arch_str,
            )
        if architecture in ["arm64", "arm", "armhf", "aarch64"]:
            ver_str = debian_package_version(pkg="qemu-system-arm",
                                             split=False)
            arch_str = debian_package_arch(pkg="qemu-system-arm")
            self.qemu_data = {
                "qemu_version": ver_str,
                "host_arch": arch_str,
                "job_arch": architecture,
            }
            self.logger.info(
                "qemu-system-arm, installed at version: %s, host architecture: %s",
                ver_str,
                arch_str,
            )

        if self.parameters["method"] in ["qemu", "qemu-nfs"]:
            if "prompts" not in self.parameters:
                if self.test_has_shell(self.parameters):
                    self.errors = "Unable to identify boot prompts from job definition."
        self.methods = self.job.device["actions"]["boot"]["methods"]
        method = self.parameters["method"]
        boot = (self.methods["qemu"]
                if "qemu" in self.methods else self.methods["qemu-nfs"])
        try:
            if "parameters" not in boot or "command" not in boot["parameters"]:
                self.errors = "Invalid device configuration - missing parameters"
            elif not boot["parameters"]["command"]:
                self.errors = "No QEMU binary command found - missing context."
            qemu_binary = which(boot["parameters"]["command"])
            self.sub_command = [qemu_binary]
            self.sub_command.extend(boot["parameters"].get("options", []))
            self.sub_command.extend(
                ["%s" % item for item in boot["parameters"].get("extra", [])])
        except AttributeError as exc:
            self.errors = "Unable to parse device options: %s %s" % (
                exc,
                self.job.device["actions"]["boot"]["methods"][method],
            )
        except (KeyError, TypeError):
            self.errors = "Invalid parameters for %s" % self.name

        for label in self.get_namespace_keys("download-action"):
            if label in ["offset", "available_loops", "uefi", "nfsrootfs"]:
                continue
            image_arg = self.get_namespace_data(action="download-action",
                                                label=label,
                                                key="image_arg")
            action_arg = self.get_namespace_data(action="download-action",
                                                 label=label,
                                                 key="file")
            if not image_arg or not action_arg:
                self.errors = "Missing image_arg for %s. " % label
                continue
            self.substitutions["{%s}" % label] = action_arg
            self.commands.append(image_arg)
        self.substitutions["{NFS_SERVER_IP}"] = dispatcher_ip(
            self.job.parameters["dispatcher"])
        self.sub_command.extend(substitute(self.commands, self.substitutions))
        if not self.sub_command:
            self.errors = "No QEMU command to execute"
        uefi_dir = self.get_namespace_data(action="deployimages",
                                           label="image",
                                           key="uefi_dir")
        if uefi_dir:
            self.sub_command.extend(["-L", uefi_dir, "-monitor", "none"])

        # Check for enable-kvm command line option in device configuration.
        if method not in self.job.device["actions"]["boot"]["methods"]:
            self.errors = "Unknown boot method '%s'" % method
            return

        options = self.job.device["actions"]["boot"]["methods"][method][
            "parameters"]["options"]
        if "-enable-kvm" in options:
            # Check if the worker has kvm enabled.
            if not os.path.exists(SYS_CLASS_KVM):
                self.errors = "Device configuration contains -enable-kvm option but kvm module is not enabled."
示例#7
0
文件: qemu.py 项目: haoyujie/mylava
    def validate(self):
        super().validate()

        # 'arch' must be defined in job definition context.
        architecture = self.job.parameters['context']['arch']
        if 'available_architectures' not in self.job.device:
            self.errors = "Device lacks list of available architectures."
        try:
            if architecture not in \
               self.job.device['available_architectures']:
                self.errors = "Non existing architecture specified in context arch parameter. Please check the device configuration for available options."
                return
        except KeyError:
            self.errors = "Arch parameter must be set in the context section. Please check the device configuration for available architectures."
            return
        if architecture in ['amd64', 'x86_64']:
            ver_str = debian_package_version(pkg='qemu-system-x86',
                                             split=False)
            arch_str = debian_package_arch(pkg='qemu-system-x86')
            self.qemu_data = {
                'qemu_version': ver_str,
                'host_arch': arch_str,
                'job_arch': architecture
            }
            self.logger.info(
                "qemu-system-x86, installed at version: %s, host architecture: %s",
                ver_str, arch_str)
        if architecture in ['arm64', 'arm', 'armhf', 'aarch64']:
            ver_str = debian_package_version(pkg='qemu-system-arm',
                                             split=False)
            arch_str = debian_package_arch(pkg='qemu-system-arm')
            self.qemu_data = {
                'qemu_version': ver_str,
                'host_arch': arch_str,
                'job_arch': architecture
            }
            self.logger.info(
                "qemu-system-arm, installed at version: %s, host architecture: %s",
                ver_str, arch_str)

        if self.parameters['method'] in ['qemu', 'qemu-nfs']:
            if 'prompts' not in self.parameters:
                if self.test_has_shell(self.parameters):
                    self.errors = "Unable to identify boot prompts from job definition."
        self.methods = self.job.device['actions']['boot']['methods']
        method = self.parameters['method']
        boot = self.methods[
            'qemu'] if 'qemu' in self.methods else self.methods['qemu-nfs']
        try:
            if 'parameters' not in boot or 'command' not in boot['parameters']:
                self.errors = "Invalid device configuration - missing parameters"
            elif not boot['parameters']['command']:
                self.errors = "No QEMU binary command found - missing context."
            qemu_binary = which(boot['parameters']['command'])
            self.sub_command = [qemu_binary]
            self.sub_command.extend(boot['parameters'].get('options', []))
            self.sub_command.extend(
                ['%s' % item for item in boot['parameters'].get('extra', [])])
        except AttributeError as exc:
            self.errors = "Unable to parse device options: %s %s" % (
                exc, self.job.device['actions']['boot']['methods'][method])
        except (KeyError, TypeError):
            self.errors = "Invalid parameters for %s" % self.name

        for label in self.get_namespace_keys('download-action'):
            if label in ['offset', 'available_loops', 'uefi', 'nfsrootfs']:
                continue
            image_arg = self.get_namespace_data(action='download-action',
                                                label=label,
                                                key='image_arg')
            action_arg = self.get_namespace_data(action='download-action',
                                                 label=label,
                                                 key='file')
            if not image_arg or not action_arg:
                self.errors = "Missing image_arg for %s. " % label
                continue
            self.substitutions["{%s}" % label] = action_arg
            self.commands.append(image_arg)
        self.substitutions["{NFS_SERVER_IP}"] = dispatcher_ip(
            self.job.parameters['dispatcher'])
        self.sub_command.extend(substitute(self.commands, self.substitutions))
        if not self.sub_command:
            self.errors = "No QEMU command to execute"
        uefi_dir = self.get_namespace_data(action='deployimages',
                                           label='image',
                                           key='uefi_dir')
        if uefi_dir:
            self.sub_command.extend(['-L', uefi_dir, '-monitor', 'none'])

        # Check for enable-kvm command line option in device configuration.
        if method not in self.job.device['actions']['boot']['methods']:
            self.errors = "Unknown boot method '%s'" % method
            return

        options = self.job.device['actions']['boot']['methods'][method][
            'parameters']['options']
        if "-enable-kvm" in options:
            # Check if the worker has kvm enabled.
            if not os.path.exists(SYS_CLASS_KVM):
                self.errors = "Device configuration contains -enable-kvm option but kvm module is not enabled."