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
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."
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."