def finish_init(self): self.src_dir = os.path.join(self.SOURCES_dir, 'patches.addon') self.cfg_dir = os.path.join(self.SOURCES_dir, 'config.addon') d = distro.detect() if d.version == '11': self.spec = os.path.join(self.SPECS_dir, 'kernel-ppc64.spec') self.config_file = os.path.join(self.cfg_dir, utils.get_current_kernel_arch(), utils.get_current_kernel_arch()) # sles11 needs both kernel and kernel-base self.binrpm_pattern = re.compile(r'kernel-%s-(base|[0-9])' % utils.get_current_kernel_arch()) if d.version == '12': self.spec = os.path.join(self.SPECS_dir, 'kernel-default.spec') self.config_file = os.path.join(self.cfg_dir, utils.get_current_kernel_arch(), 'default') self.binrpm_pattern = re.compile(r'kernel-default-[0-9]')
def set_cross_cc(self, target_arch=None, cross_compile=None, build_target='bzImage'): """Set up to cross-compile. This is broken. We need to work out what the default compile produces, and if not, THEN set the cross compiler. """ if self.target_arch: return # if someone has set build_target, don't clobber in set_cross_cc # run set_build_target before calling set_cross_cc if not self.build_target: self.set_build_target(build_target) # If no 'target_arch' given assume native compilation if target_arch is None: target_arch = utils.get_current_kernel_arch() if target_arch == 'ppc64': if self.build_target == 'bzImage': self.build_target = 'vmlinux' if not cross_compile: cross_compile = self.job.config_get('kernel.cross_cc') if cross_compile: os.environ['CROSS_COMPILE'] = cross_compile else: if os.environ.has_key('CROSS_COMPILE'): del os.environ['CROSS_COMPILE'] return # HACK. Crap out for now. # At this point I know what arch I *want* to build for # but have no way of working out what arch the default # compiler DOES build for. def install_package(package): raise NotImplementedError("I don't exist yet!") if target_arch in ['ppc64', 'ppc']: install_package('ppc64-cross') cross_compile = os.path.join(self.autodir, 'sources/ppc64-cross/bin') elif target_arch == 'x86_64': install_package('x86_64-cross') cross_compile = os.path.join(self.autodir, 'sources/x86_64-cross/bin') os.environ['ARCH'] = self.target_arch = target_arch self.cross_compile = cross_compile if self.cross_compile: os.environ['CROSS_COMPILE'] = self.cross_compile
def setup_source(self): if len(self.configs) > 0: for config_file in glob.glob( os.path.join( self.SOURCES_dir, 'kernel-*%s*' % utils.get_current_kernel_arch())): with open(config_file, 'a') as cfg: for config in self.configs: cfg.write("%s\n" % config)
def output_check(nodeinfo_output): # Check CPU model cpu_model_nodeinfo = _check_nodeinfo(nodeinfo_output, "CPU model", 3) cpu_model_os = utils.get_current_kernel_arch() if not re.match(cpu_model_nodeinfo, cpu_model_os): raise error.TestFail( "Virsh nodeinfo output didn't match CPU model") # Check number of CPUs cpus_nodeinfo = _check_nodeinfo(nodeinfo_output, "CPU(s)", 2) cpus_os = utils.count_cpus() if int(cpus_nodeinfo) != cpus_os: raise error.TestFail( "Virsh nodeinfo output didn't match number of " "CPU(s)") # Check CPU frequency cpu_frequency_nodeinfo = _check_nodeinfo(nodeinfo_output, 'CPU frequency', 3) cmd = ("cat /proc/cpuinfo | grep 'cpu MHz' | head -n1 | " "awk '{print $4}' | awk -F. '{print $1}'") cmd_result = utils.run(cmd, ignore_status=True) cpu_frequency_os = cmd_result.stdout.strip() print cpu_frequency_os if not re.match(cpu_frequency_nodeinfo, cpu_frequency_os): raise error.TestFail("Virsh nodeinfo output didn't match CPU " "frequency") # Check CPU socket(s) cpu_sockets_nodeinfo = int( _check_nodeinfo(nodeinfo_output, 'CPU socket(s)', 3)) cmd = "grep 'physical id' /proc/cpuinfo | uniq | sort | uniq |wc -l" cmd_result = utils.run(cmd, ignore_status=True) cpu_NUMA_nodeinfo = _check_nodeinfo(nodeinfo_output, 'NUMA cell(s)', 3) cpu_sockets_os = int( cmd_result.stdout.strip()) / int(cpu_NUMA_nodeinfo) if cpu_sockets_os != cpu_sockets_nodeinfo: raise error.TestFail("Virsh nodeinfo output didn't match CPU " "socket(s)") # Check Core(s) per socket cores_per_socket_nodeinfo = _check_nodeinfo(nodeinfo_output, 'Core(s) per socket', 4) cmd = "grep 'cpu cores' /proc/cpuinfo | head -n1 | awk '{print $4}'" cmd_result = utils.run(cmd, ignore_status=True) cores_per_socket_os = cmd_result.stdout.strip() if not re.match(cores_per_socket_nodeinfo, cores_per_socket_os): raise error.TestFail("Virsh nodeinfo output didn't match Core(s) " "per socket") # Check Memory size memory_size_nodeinfo = int( _check_nodeinfo(nodeinfo_output, 'Memory size', 3)) memory_size_os = utils.memtotal() if memory_size_nodeinfo != memory_size_os: raise error.TestFail("Virsh nodeinfo output didn't match " "Memory size")
def output_check(nodeinfo_output): # Check CPU model cpu_model_nodeinfo = _check_nodeinfo(nodeinfo_output, "CPU model", 3) cpu_model_os = utils.get_current_kernel_arch() if not re.match(cpu_model_nodeinfo, cpu_model_os): raise error.TestFail( "Virsh nodeinfo output didn't match CPU model") # Check number of CPUs cpus_nodeinfo = _check_nodeinfo(nodeinfo_output, "CPU(s)", 2) cpus_os = utils.count_cpus() if int(cpus_nodeinfo) != cpus_os: raise error.TestFail("Virsh nodeinfo output didn't match number of " "CPU(s)") # Check CPU frequency cpu_frequency_nodeinfo = _check_nodeinfo( nodeinfo_output, 'CPU frequency', 3) cmd = ("cat /proc/cpuinfo | grep 'cpu MHz' | head -n1 | " "awk '{print $4}' | awk -F. '{print $1}'") cmd_result = utils.run(cmd, ignore_status=True) cpu_frequency_os = cmd_result.stdout.strip() print cpu_frequency_os if not re.match(cpu_frequency_nodeinfo, cpu_frequency_os): raise error.TestFail("Virsh nodeinfo output didn't match CPU " "frequency") # Check CPU socket(s) cpu_sockets_nodeinfo = int( _check_nodeinfo(nodeinfo_output, 'CPU socket(s)', 3)) cmd = "grep 'physical id' /proc/cpuinfo | uniq | sort | uniq |wc -l" cmd_result = utils.run(cmd, ignore_status=True) cpu_NUMA_nodeinfo = _check_nodeinfo(nodeinfo_output, 'NUMA cell(s)', 3) cpu_sockets_os = int( cmd_result.stdout.strip()) / int(cpu_NUMA_nodeinfo) if cpu_sockets_os != cpu_sockets_nodeinfo: raise error.TestFail("Virsh nodeinfo output didn't match CPU " "socket(s)") # Check Core(s) per socket cores_per_socket_nodeinfo = _check_nodeinfo( nodeinfo_output, 'Core(s) per socket', 4) cmd = "grep 'cpu cores' /proc/cpuinfo | head -n1 | awk '{print $4}'" cmd_result = utils.run(cmd, ignore_status=True) cores_per_socket_os = cmd_result.stdout.strip() if not re.match(cores_per_socket_nodeinfo, cores_per_socket_os): raise error.TestFail("Virsh nodeinfo output didn't match Core(s) " "per socket") # Check Memory size memory_size_nodeinfo = int( _check_nodeinfo(nodeinfo_output, 'Memory size', 3)) memory_size_os = utils_memory.memtotal() if memory_size_nodeinfo != memory_size_os: raise error.TestFail("Virsh nodeinfo output didn't match " "Memory size")
def output_check(nodeinfo_output): # Check CPU model cpu_model_nodeinfo = _check_nodeinfo(nodeinfo_output, "CPU model", 3) cpu_model_os = utils.get_current_kernel_arch() if not re.match(cpu_model_nodeinfo, cpu_model_os): raise error.TestFail("Virsh nodeinfo output didn't match CPU model") # Check number of CPUs cpus_nodeinfo = _check_nodeinfo(nodeinfo_output, "CPU(s)", 2) cpus_os = utils.count_cpus() if int(cpus_nodeinfo) != cpus_os: raise error.TestFail("Virsh nodeinfo output didn't match number of " "CPU(s)") # Check CPU frequency cpu_frequency_nodeinfo = _check_nodeinfo(nodeinfo_output, "CPU frequency", 3) cmd = "cat /proc/cpuinfo | grep 'cpu MHz' | head -n1 | " "awk '{print $4}' | awk -F. '{print $1}'" cmd_result = utils.run(cmd, ignore_status=True) cpu_frequency_os = cmd_result.stdout.strip() logging.debug("cpu_frequency_nodeinfo=%s cpu_frequency_os=%s", cpu_frequency_nodeinfo, cpu_frequency_os) # # Matching CPU Frequency is not an exact science in todays modern # processors and OS's. CPU's can have their execution speed varied # based on current workload in order to save energy and keep cool. # Thus since we're getting the values at disparate points in time, # we cannot necessarily do a pure comparison. # So, let's get the absolute value of the difference and ensure # that it's within 20 percent of each value to give us enough of # a "fudge" factor to declare "close enough". Don't return a failure # just print a debug message and move on. diffval = abs(int(cpu_frequency_nodeinfo) - int(cpu_frequency_os)) if float(diffval) / float(cpu_frequency_nodeinfo) > 0.20 or float(diffval) / float(cpu_frequency_os) > 0.20: logging.debug("Virsh nodeinfo output didn't match CPU " "frequency within 20 percent") # Check CPU socket(s) cpu_sockets_nodeinfo = int(_check_nodeinfo(nodeinfo_output, "CPU socket(s)", 3)) cmd = "grep 'physical id' /proc/cpuinfo | uniq | sort | uniq |wc -l" cmd_result = utils.run(cmd, ignore_status=True) cpu_NUMA_nodeinfo = _check_nodeinfo(nodeinfo_output, "NUMA cell(s)", 3) cpu_sockets_os = int(cmd_result.stdout.strip()) / int(cpu_NUMA_nodeinfo) if cpu_sockets_os != cpu_sockets_nodeinfo: raise error.TestFail("Virsh nodeinfo output didn't match CPU " "socket(s)") # Check Core(s) per socket cores_per_socket_nodeinfo = _check_nodeinfo(nodeinfo_output, "Core(s) per socket", 4) cmd = "grep 'cpu cores' /proc/cpuinfo | head -n1 | awk '{print $4}'" cmd_result = utils.run(cmd, ignore_status=True) cores_per_socket_os = cmd_result.stdout.strip() if not re.match(cores_per_socket_nodeinfo, cores_per_socket_os): raise error.TestFail("Virsh nodeinfo output didn't match Core(s) " "per socket") # Check Memory size memory_size_nodeinfo = int(_check_nodeinfo(nodeinfo_output, "Memory size", 3)) memory_size_os = utils_memory.memtotal() if memory_size_nodeinfo != memory_size_os: raise error.TestFail("Virsh nodeinfo output didn't match " "Memory size")
def set_cross_cc(self, target_arch=None, cross_compile=None, build_target='bzImage'): """Set up to cross-compile. This is broken. We need to work out what the default compile produces, and if not, THEN set the cross compiler. """ if self.target_arch: return # if someone has set build_target, don't clobber in set_cross_cc # run set_build_target before calling set_cross_cc if not self.build_target: self.set_build_target(build_target) # If no 'target_arch' given assume native compilation if target_arch is None: target_arch = utils.get_current_kernel_arch() if target_arch == 'ppc64': if self.build_target == 'bzImage': self.build_target = 'vmlinux' if not cross_compile: cross_compile = self.job.config_get('kernel.cross_cc') if cross_compile: os.environ['CROSS_COMPILE'] = cross_compile else: if os.environ.has_key('CROSS_COMPILE'): del os.environ['CROSS_COMPILE'] return # HACK. Crap out for now. # At this point I know what arch I *want* to build for # but have no way of working out what arch the default # compiler DOES build for. def install_package(package): raise NotImplementedError("I don't exist yet!") if target_arch == 'ppc64': install_package('ppc64-cross') cross_compile = os.path.join(self.autodir, 'sources/ppc64-cross/bin') elif target_arch == 'x86_64': install_package('x86_64-cross') cross_compile = os.path.join(self.autodir, 'sources/x86_64-cross/bin') os.environ['ARCH'] = self.target_arch = target_arch self.cross_compile = cross_compile if self.cross_compile: os.environ['CROSS_COMPILE'] = self.cross_compile
def initialize(self, config): arch = utils.get_current_kernel_arch() if arch in ['i386', 'i486', 'i586', 'i686', 'athlon']: self.arch = 'ia32' elif arch == 'ppc': self.arch = 'ppc32' elif arch in ['s390', 's390x', 'ia64', 'x86_64', 'ppc64']: self.arch = arch else: e_msg = 'Architecture %s not supported by LSB' % arch raise error.TestError(e_msg) self.config = config_loader(config, self.tmpdir) self.cachedir = os.path.join(os.path.dirname(self.srcdir), 'cache') if not os.path.isdir(self.cachedir): os.makedirs(self.cachedir) self.packages_installed = False self.libraries_linked = False
def setup(self, tarball='iozone3_398.tar'): """ Builds the given version of IOzone from a tarball. @param tarball: Tarball with IOzone @see: http://www.iozone.org/src/current/iozone3_398.tar """ tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir) utils.extract_tarball_to_dir(tarball, self.srcdir) os.chdir(os.path.join(self.srcdir, 'src/current')) utils.system('patch -p3 < ../../../makefile.patch') arch = utils.get_current_kernel_arch() if (arch == 'ppc'): utils.make('linux-powerpc') elif (arch == 'ppc64'): utils.make('linux-powerpc64') elif (arch == 'x86_64'): utils.make('linux-AMD64') else: utils.make('linux')
def get_kernel_build_arch(self, arch=None): """ Work out the current kernel architecture (as a kernel arch) """ if not arch: arch = utils.get_current_kernel_arch() if re.match('i.86', arch): return 'i386' elif re.match('sun4u', arch): return 'sparc64' elif re.match('arm.*', arch): return 'arm' elif re.match('sa110', arch): return 'arm' elif re.match('s390x', arch): return 's390' elif re.match('parisc64', arch): return 'parisc' elif re.match('ppc.*', arch): return 'powerpc' elif re.match('mips.*', arch): return 'mips' else: return arch
def get_kernel_build_arch(self, arch=None): """ Work out the current kernel architecture (as a kernel arch) """ if not arch: arch = utils.get_current_kernel_arch() if re.match("i.86", arch): return "i386" elif re.match("sun4u", arch): return "sparc64" elif re.match("arm.*", arch): return "arm" elif re.match("sa110", arch): return "arm" elif re.match("s390x", arch): return "s390" elif re.match("parisc64", arch): return "parisc" elif re.match("ppc.*", arch): return "powerpc" elif re.match("mips.*", arch): return "mips" else: return arch
def output_check(nodeinfo_output): # Check CPU model cpu_model_nodeinfo = _check_nodeinfo(nodeinfo_output, "CPU model", 3) cpu_model_os = utils.get_current_kernel_arch() if not re.match(cpu_model_nodeinfo, cpu_model_os): raise error.TestFail( "Virsh nodeinfo output didn't match CPU model") # Check number of CPUs, nodeinfo CPUs represent online threads in the # system, check all online cpus in sysfs cpus_nodeinfo = _check_nodeinfo(nodeinfo_output, "CPU(s)", 2) cmd = "cat /sys/devices/system/cpu/cpu*/online | grep 1 | wc -l" cpus_online = utils.run(cmd, ignore_status=True).stdout.strip() cmd = "cat /sys/devices/system/cpu/cpu*/online | wc -l" cpus_total = utils.run(cmd, ignore_status=True).stdout.strip() if not os.path.exists('/sys/devices/system/cpu/cpu0/online'): cpus_online = str(int(cpus_online) + 1) cpus_total = str(int(cpus_total) + 1) logging.debug("host online cpus are %s", cpus_online) logging.debug("host total cpus are %s", cpus_total) if cpus_nodeinfo != cpus_online: if 'power' in cpu_util.get_cpu_arch(): if cpus_nodeinfo != cpus_total: raise error.TestFail("Virsh nodeinfo output of CPU(s) on" " ppc did not match all threads in " "the system") else: raise error.TestFail("Virsh nodeinfo output didn't match " "number of CPU(s)") # Check CPU frequency, frequency is under clock for ppc cpu_frequency_nodeinfo = _check_nodeinfo( nodeinfo_output, 'CPU frequency', 3) cmd = ("cat /proc/cpuinfo | grep -E 'cpu MHz|clock' | head -n1 | " "awk -F: '{print $2}' | awk -F. '{print $1}'") cmd_result = utils.run(cmd, ignore_status=True) cpu_frequency_os = cmd_result.stdout.strip() logging.debug("cpu_frequency_nodeinfo=%s cpu_frequency_os=%s", cpu_frequency_nodeinfo, cpu_frequency_os) # # Matching CPU Frequency is not an exact science in todays modern # processors and OS's. CPU's can have their execution speed varied # based on current workload in order to save energy and keep cool. # Thus since we're getting the values at disparate points in time, # we cannot necessarily do a pure comparison. # So, let's get the absolute value of the difference and ensure # that it's within 20 percent of each value to give us enough of # a "fudge" factor to declare "close enough". Don't return a failure # just print a debug message and move on. diffval = abs(int(cpu_frequency_nodeinfo) - int(cpu_frequency_os)) if float(diffval) / float(cpu_frequency_nodeinfo) > 0.20 or \ float(diffval) / float(cpu_frequency_os) > 0.20: logging.debug("Virsh nodeinfo output didn't match CPU " "frequency within 20 percent") # Get CPU topology from virsh capabilities xml cpu_topology = capability_xml.CapabilityXML()['cpu_topology'] logging.debug("Cpu topology in virsh capabilities output: %s", cpu_topology) # Check CPU socket(s) cpu_sockets_nodeinfo = int( _check_nodeinfo(nodeinfo_output, 'CPU socket(s)', 3)) # CPU socket(s) in virsh nodeinfo is Total sockets in each node, not # total sockets in the system, so get total sockets in one node and # check with it node_info = utils_misc.NumaInfo() node_online_list = node_info.get_online_nodes() cmd = "cat /sys/devices/system/node/node%s" % node_online_list[0] cmd += "/cpu*/topology/physical_package_id | uniq |wc -l" cmd_result = utils.run(cmd, ignore_status=True) total_sockets_in_node = int(cmd_result.stdout.strip()) if total_sockets_in_node != cpu_sockets_nodeinfo: raise error.TestFail("Virsh nodeinfo output didn't match CPU " "socket(s) of host OS") if cpu_sockets_nodeinfo != int(cpu_topology['sockets']): raise error.TestFail("Virsh nodeinfo output didn't match CPU " "socket(s) of virsh capabilities output") # Check Core(s) per socket cores_per_socket_nodeinfo = _check_nodeinfo( nodeinfo_output, 'Core(s) per socket', 4) cmd = "lscpu | grep 'Core(s) per socket' | head -n1 | awk '{print $4}'" cmd_result = utils.run(cmd, ignore_status=True) cores_per_socket_os = cmd_result.stdout.strip() if not re.match(cores_per_socket_nodeinfo, cores_per_socket_os): raise error.TestFail("Virsh nodeinfo output didn't match Core(s) " "per socket of host OS") if cores_per_socket_nodeinfo != cpu_topology['cores']: raise error.TestFail("Virsh nodeinfo output didn't match Core(s) " "per socket of virsh capabilities output") # Ckeck Thread(s) per core threads_per_core_nodeinfo = _check_nodeinfo(nodeinfo_output, 'Thread(s) per core', 4) if threads_per_core_nodeinfo != cpu_topology['threads']: raise error.TestFail("Virsh nodeinfo output didn't match Thread(s) " "per core of virsh capabilities output") # Check Memory size memory_size_nodeinfo = int( _check_nodeinfo(nodeinfo_output, 'Memory size', 3)) memory_size_os = 0 for i in node_online_list: node_memory = node_info.read_from_node_meminfo(i, 'MemTotal') memory_size_os += int(node_memory) logging.debug('The host total memory from nodes is %s', memory_size_os) if memory_size_nodeinfo != memory_size_os: raise error.TestFail("Virsh nodeinfo output didn't match " "Memory size")
def make_create_command(self, name=None, params=None, root_dir=None): """ Generate a libvirt command line. All parameters are optional. If a parameter is not supplied, the corresponding value stored in the class attributes is used. @param name: The name of the object @param params: A dict containing VM params @param root_dir: Base directory for relative filenames @note: The params dict should contain: mem -- memory size in MBs cdrom -- ISO filename to use with the qemu -cdrom parameter extra_params -- a string to append to the qemu command shell_port -- port of the remote shell daemon on the guest (SSH, Telnet or the home-made Remote Shell Server) shell_client -- client program to use for connecting to the remote shell daemon on the guest (ssh, telnet or nc) x11_display -- if specified, the DISPLAY environment variable will be be set to this value for the qemu process (useful for SDL rendering) images -- a list of image object names, separated by spaces nics -- a list of NIC object names, separated by spaces For each image in images: drive_format -- string to pass as 'if' parameter for this image (e.g. ide, scsi) image_snapshot -- if yes, pass 'snapshot=on' to qemu for this image image_boot -- if yes, pass 'boot=on' to qemu for this image In addition, all parameters required by get_image_filename. For each NIC in nics: nic_model -- string to pass as 'model' parameter for this NIC (e.g. e1000) """ # helper function for command line option wrappers def has_option(help_text, option): return bool(re.search(r"--%s" % option, help_text, re.MULTILINE)) # Wrappers for all supported libvirt command line parameters. # This is meant to allow support for multiple libvirt versions. # Each of these functions receives the output of 'libvirt --help' as a # parameter, and should add the requested command line option # accordingly. def add_name(help_text, name): return " --name '%s'" % name def add_machine_type(help_text, machine_type): if has_option(help_text, "machine"): return " --machine %s" % machine_type else: return "" def add_hvm_or_pv(help_text, hvm_or_pv): if hvm_or_pv == "hvm": return " --hvm --accelerate" elif hvm_or_pv == "pv": return " --paravirt" else: logging.warning("Unknown virt type hvm_or_pv, using default.") return "" def add_mem(help_text, mem): return " --ram=%s" % mem def add_check_cpu(help_text): if has_option(help_text, "check-cpu"): return " --check-cpu" else: return "" def add_smp(help_text, smp): return " --vcpu=%s" % smp def add_location(help_text, location): if has_option(help_text, "location"): return " --location %s" % location else: return "" def add_cdrom(help_text, filename, index=None): if has_option(help_text, "cdrom"): return " --cdrom %s" % filename else: return "" def add_pxe(help_text): if has_option(help_text, "pxe"): return " --pxe" else: return "" def add_import(help_text): if has_option(help_text, "import"): return " --import" else: return "" def add_drive( help_text, filename, pool=None, vol=None, device=None, bus=None, perms=None, size=None, sparse=False, cache=None, fmt=None, ): cmd = " --disk" if filename: cmd += " path=%s" % filename elif pool: if vol: cmd += " vol=%s/%s" % (pool, vol) else: cmd += " pool=%s" % pool if device: cmd += ",device=%s" % device if bus: cmd += ",bus=%s" % bus if perms: cmd += ",%s" % perms if size: cmd += ",size=%s" % size.rstrip("Gg") if sparse: cmd += ",sparse=false" if fmt: cmd += ",format=%s" % fmt if cache: cmd += ",cache=%s" % cache return cmd def add_floppy(help_text, filename): return " --disk path=%s,device=floppy,ro" % filename def add_vnc(help_text, vnc_port=None): if vnc_port: return " --vnc --vncport=%d" % (vnc_port) else: return " --vnc" def add_vnclisten(help_text, vnclisten): if has_option(help_text, "vnclisten"): return " --vnclisten=%s" % (vnclisten) else: return "" def add_sdl(help_text): if has_option(help_text, "sdl"): return " --sdl" else: return "" def add_nographic(help_text): return " --nographics" def add_video(help_text, video_device): if has_option(help_text, "video"): return " --video=%s" % (video_device) else: return "" def add_uuid(help_text, uuid): if has_option(help_text, "uuid"): return " --uuid %s" % uuid else: return "" def add_os_type(help_text, os_type): if has_option(help_text, "os-type"): return " --os-type %s" % os_type else: return "" def add_os_variant(help_text, os_variant): if has_option(help_text, "os-variant"): return " --os-variant %s" % os_variant else: return "" def add_pcidevice(help_text, pci_device): if has_option(help_text, "host-device"): return " --host-device %s" % pci_device else: return "" def add_soundhw(help_text, sound_device): if has_option(help_text, "soundhw"): return " --soundhw %s" % sound_device else: return "" def add_serial(help_text, filename): if has_option(help_text, "serial"): return " --serial file,path=%s --serial pty" % filename else: self.only_pty = True return "" def add_kernel_cmdline(help_text, cmdline): return " -append %s" % cmdline def add_connect_uri(help_text, uri): if uri and has_option(help_text, "connect"): return " --connect=%s" % uri else: return "" def add_nic(help_text, nic_params): """ Return additional command line params based on dict-like nic_params """ mac = nic_params.get("mac") nettype = nic_params.get("nettype") netdst = nic_params.get("netdst") nic_model = nic_params.get("nic_model") if nettype: result = " --network=%s" % nettype else: result = "" if has_option(help_text, "bridge"): # older libvirt (--network=NATdev --bridge=bridgename --mac=mac) if nettype != "user": result += ":%s" % netdst if mac: # possible to specify --mac w/o --network result += " --mac=%s" % mac else: # newer libvirt (--network=mynet,model=virtio,mac=00:11) if nettype != "user": result += "=%s" % netdst if nettype and nic_model: # only supported along with nettype result += ",model=%s" % nic_model if nettype and mac: result += ",mac=%s" % mac elif mac: # possible to specify --mac w/o --network result += " --mac=%s" % mac logging.debug("vm.make_create_command.add_nic returning: %s" % result) return result # End of command line option wrappers if name is None: name = self.name if params is None: params = self.params if root_dir is None: root_dir = self.root_dir # Clone this VM using the new params vm = self.clone(name, params, root_dir, copy_state=True) virt_install_binary = utils_misc.get_path(root_dir, params.get("virt_install_binary", "virt-install")) help_text = utils.system_output("%s --help" % virt_install_binary) # Find all supported machine types, so we can rule out an unsupported # machine type option passed in the configuration. hvm_or_pv = params.get("hvm_or_pv", "hvm") # default to 'uname -m' output arch_name = params.get("vm_arch_name", utils.get_current_kernel_arch()) capabs = libvirt_xml.LibvirtXML() support_machine_type = capabs.os_arch_machine_map[hvm_or_pv][arch_name] logging.debug("Machine types supported for %s\%s: %s" % (hvm_or_pv, arch_name, support_machine_type)) # Start constructing the qemu command virt_install_cmd = "" # Set the X11 display parameter if requested if params.get("x11_display"): virt_install_cmd += "DISPLAY=%s " % params.get("x11_display") # Add the qemu binary virt_install_cmd += virt_install_binary # set connect uri virt_install_cmd += add_connect_uri(help_text, self.connect_uri) # hvm or pv specificed by libvirt switch (pv used by Xen only) if hvm_or_pv: virt_install_cmd += add_hvm_or_pv(help_text, hvm_or_pv) # Add the VM's name virt_install_cmd += add_name(help_text, name) machine_type = params.get("machine_type") if machine_type: if machine_type in support_machine_type: virt_install_cmd += add_machine_type(help_text, machine_type) else: raise error.TestNAError("Unsupported machine type %s." % (machine_type)) mem = params.get("mem") if mem: virt_install_cmd += add_mem(help_text, mem) # TODO: should we do the check before we call ? negative case ? check_cpu = params.get("use_check_cpu") if check_cpu: virt_install_cmd += add_check_cpu(help_text) smp = params.get("smp") if smp: virt_install_cmd += add_smp(help_text, smp) # TODO: directory location for vmlinuz/kernel for cdrom install ? location = None if params.get("medium") == "url": location = params.get("url") elif params.get("medium") == "kernel_initrd": # directory location of kernel/initrd pair (directory layout must # be in format libvirt will recognize) location = params.get("image_dir") elif params.get("medium") == "nfs": location = "nfs:%s:%s" % (params.get("nfs_server"), params.get("nfs_dir")) elif params.get("medium") == "cdrom": if params.get("use_libvirt_cdrom_switch") == "yes": virt_install_cmd += add_cdrom(help_text, params.get("cdrom_cd1")) elif params.get("unattended_delivery_method") == "integrated": virt_install_cmd += add_cdrom( help_text, os.path.join(data_dir.get_data_dir(), params.get("cdrom_unattended")) ) else: location = params.get("image_dir") kernel_dir = os.path.dirname(params.get("kernel")) kernel_parent_dir = os.path.dirname(kernel_dir) pxeboot_link = os.path.join(kernel_parent_dir, "pxeboot") if os.path.islink(pxeboot_link): os.unlink(pxeboot_link) if os.path.isdir(pxeboot_link): logging.info("Removed old %s leftover directory", pxeboot_link) shutil.rmtree(pxeboot_link) os.symlink(kernel_dir, pxeboot_link) elif params.get("medium") == "import": virt_install_cmd += add_import(help_text) if location: virt_install_cmd += add_location(help_text, location) if params.get("display") == "vnc": if params.get("vnc_autoport") == "yes": vm.vnc_autoport = True else: vm.vnc_autoport = False if not vm.vnc_autoport and params.get("vnc_port"): vm.vnc_port = int(params.get("vnc_port")) virt_install_cmd += add_vnc(help_text, vm.vnc_port) if params.get("vnclisten"): vm.vnclisten = params.get("vnclisten") virt_install_cmd += add_vnclisten(help_text, vm.vnclisten) elif params.get("display") == "sdl": virt_install_cmd += add_sdl(help_text) elif params.get("display") == "nographic": virt_install_cmd += add_nographic(help_text) video_device = params.get("video_device") if video_device: virt_install_cmd += add_video(help_text, video_device) sound_device = params.get("sound_device") if sound_device: virt_install_cmd += add_soundhw(help_text, sound_device) # if none is given a random UUID will be generated by libvirt if params.get("uuid"): virt_install_cmd += add_uuid(help_text, params.get("uuid")) # selectable OS type if params.get("use_os_type") == "yes": virt_install_cmd += add_os_type(help_text, params.get("os_type")) # selectable OS variant if params.get("use_os_variant") == "yes": virt_install_cmd += add_os_variant(help_text, params.get("os_variant")) # Add serial console virt_install_cmd += add_serial(help_text, self.get_serial_console_filename()) # If the PCI assignment step went OK, add each one of the PCI assigned # devices to the command line. if self.pci_devices: for pci_id in self.pci_devices: virt_install_cmd += add_pcidevice(help_text, pci_id) for image_name in params.objects("images"): image_params = params.object_params(image_name) filename = storage.get_image_filename(image_params, data_dir.get_data_dir()) if image_params.get("use_storage_pool") == "yes": filename = None virt_install_cmd += add_drive( help_text, filename, image_params.get("image_pool"), image_params.get("image_vol"), image_params.get("image_device"), image_params.get("image_bus"), image_params.get("image_perms"), image_params.get("image_size"), image_params.get("drive_sparse"), image_params.get("drive_cache"), image_params.get("image_format"), ) if image_params.get("boot_drive") == "no": continue if filename: virt_install_cmd += add_drive( help_text, filename, None, None, None, image_params.get("drive_format"), None, image_params.get("image_size"), image_params.get("drive_sparse"), image_params.get("drive_cache"), image_params.get("image_format"), ) if params.get("unattended_delivery_method") != "integrated" and not ( self.driver_type == "xen" and params.get("hvm_or_pv") == "pv" ): for cdrom in params.objects("cdroms"): cdrom_params = params.object_params(cdrom) iso = cdrom_params.get("cdrom") if params.get("use_libvirt_cdrom_switch") == "yes": # we don't want to skip the winutils iso if not cdrom == "winutils": logging.debug("Using --cdrom instead of --disk for install") logging.debug("Skipping CDROM:%s:%s", cdrom, iso) continue if params.get("medium") == "cdrom_no_kernel_initrd": if iso == params.get("cdrom_cd1"): logging.debug("Using cdrom or url for install") logging.debug("Skipping CDROM: %s", iso) continue if iso: virt_install_cmd += add_drive( help_text, utils_misc.get_path(root_dir, iso), image_params.get("iso_image_pool"), image_params.get("iso_image_vol"), "cdrom", None, None, None, None, None, None, ) # We may want to add {floppy_otps} parameter for -fda # {fat:floppy:}/path/. However vvfat is not usually recommended. # Only support to add the main floppy if you want to add the second # one please modify this part. floppy = params.get("floppy_name") if floppy: floppy = utils_misc.get_path(data_dir.get_data_dir(), floppy) virt_install_cmd += add_drive(help_text, floppy, None, None, "floppy", None, None, None, None, None, None) # setup networking parameters for nic in vm.virtnet: # make_create_command can be called w/o vm.create() nic = vm.add_nic(**dict(nic)) logging.debug("make_create_command() setting up command for" " nic: %s" % str(nic)) virt_install_cmd += add_nic(help_text, nic) if params.get("use_no_reboot") == "yes": virt_install_cmd += " --noreboot" if params.get("use_autostart") == "yes": virt_install_cmd += " --autostart" if params.get("virt_install_debug") == "yes": virt_install_cmd += " --debug" # bz still open, not fully functional yet if params.get("use_virt_install_wait") == "yes": virt_install_cmd += " --wait %s" % params.get("virt_install_wait_time") kernel_params = params.get("kernel_params") if kernel_params: virt_install_cmd += " --extra-args '%s'" % kernel_params virt_install_cmd += " --noautoconsole" return virt_install_cmd
def __init__(self, job, base_tree, subdir, tmp_dir, build_dir, leave=False): """Initialize the kernel build environment job which job this build is part of base_tree base kernel tree. Can be one of the following: 1. A local tarball 2. A URL to a tarball 3. A local directory (will symlink it) 4. A shorthand expandable (eg '2.6.11-git3') subdir subdir in the results directory (eg "build") (holds config/, debug/, results/) tmp_dir leave Boolean, whether to leave existing tmpdir or not """ super(kernel, self).__init__(job) self.autodir = job.autodir self.src_dir = os.path.join(tmp_dir, 'src') self.build_dir = os.path.join(tmp_dir, build_dir) # created by get_kernel_tree self.config_dir = os.path.join(subdir, 'config') self.log_dir = os.path.join(subdir, 'debug') self.results_dir = os.path.join(subdir, 'results') self.subdir = os.path.basename(subdir) if not leave: if os.path.isdir(self.src_dir): utils.system('rm -rf ' + self.src_dir) if os.path.isdir(self.build_dir): utils.system('rm -rf ' + self.build_dir) if not os.path.exists(self.src_dir): os.mkdir(self.src_dir) for path in [self.config_dir, self.log_dir, self.results_dir]: if os.path.exists(path): utils.system('rm -rf ' + path) os.mkdir(path) logpath = os.path.join(self.log_dir, 'build_log') self.logfile = open(logpath, 'w+') self.applied_patches = [] self.target_arch = None self.build_target = 'bzImage' self.build_image = None arch = utils.get_current_kernel_arch() if arch == 'ia64': self.build_target = 'all' self.build_image = 'vmlinux.gz' elif arch in ['s390', 's390x']: self.build_target = 'image' elif arch in ['ppc64', 'ppc']: self.build_target = 'vmlinux' if not leave: self.logfile.write('BASE: %s\n' % base_tree) # Where we have direct version hint record that # for later configuration selection. shorthand = re.compile(r'^\d+\.\d+\.\d+') if shorthand.match(base_tree): self.base_tree_version = base_tree else: self.base_tree_version = None # Actually extract the tree. Make sure we know it occurred self.extract(base_tree)
def __init__(self, job, rpm_package, subdir): # download and install src.rpm super(srpm_kernel_suse, self).__init__(job, rpm_package, subdir) utils.system('rm -rf ' + self.cfg_dir) os.mkdir(self.cfg_dir) os.mkdir(os.path.join(self.cfg_dir, utils.get_current_kernel_arch()))
def setup_source(self): if len(self.configs) > 0: for config_file in glob.glob(os.path.join(self.SOURCES_dir, 'kernel-*%s*' % utils.get_current_kernel_arch())): with open(config_file, 'a') as cfg: for config in self.configs: cfg.write("%s\n" % config)
def __init__(self, job, base_tree, subdir, tmp_dir, build_dir, leave=False): """Initialize the kernel build environment job which job this build is part of base_tree base kernel tree. Can be one of the following: 1. A local tarball 2. A URL to a tarball 3. A local directory (will symlink it) 4. A shorthand expandable (eg '2.6.11-git3') subdir subdir in the results directory (eg "build") (holds config/, debug/, results/) tmp_dir leave Boolean, whether to leave existing tmpdir or not """ super(kernel, self).__init__(job) self.autodir = job.autodir self.src_dir = os.path.join(tmp_dir, 'src') self.build_dir = os.path.join(tmp_dir, build_dir) # created by get_kernel_tree self.config_dir = os.path.join(subdir, 'config') self.log_dir = os.path.join(subdir, 'debug') self.results_dir = os.path.join(subdir, 'results') self.subdir = os.path.basename(subdir) if not leave: if os.path.isdir(self.src_dir): utils.system('rm -rf ' + self.src_dir) if os.path.isdir(self.build_dir): utils.system('rm -rf ' + self.build_dir) if not os.path.exists(self.src_dir): os.mkdir(self.src_dir) for path in [self.config_dir, self.log_dir, self.results_dir]: if os.path.exists(path): utils.system('rm -rf ' + path) os.mkdir(path) logpath = os.path.join(self.log_dir, 'build_log') self.logfile = open(logpath, 'w+') self.applied_patches = [] self.target_arch = None self.build_target = 'bzImage' self.build_image = None arch = utils.get_current_kernel_arch() if arch == 'ia64': self.build_target = 'all' self.build_image = 'vmlinux.gz' elif arch in ['s390', 's390x']: self.build_target = 'image' elif 'ppc' in arch: self.build_target = 'vmlinux' if not leave: self.logfile.write('BASE: %s\n' % base_tree) # Where we have direct version hint record that # for later configuration selection. shorthand = re.compile(r'^\d+\.\d+\.\d+') if shorthand.match(base_tree): self.base_tree_version = base_tree else: self.base_tree_version = None # Actually extract the tree. Make sure we know it occurred self.extract(base_tree)
def make_create_command(self, name=None, params=None, root_dir=None): """ Generate a libvirt command line. All parameters are optional. If a parameter is not supplied, the corresponding value stored in the class attributes is used. @param name: The name of the object @param params: A dict containing VM params @param root_dir: Base directory for relative filenames @note: The params dict should contain: mem -- memory size in MBs cdrom -- ISO filename to use with the qemu -cdrom parameter extra_params -- a string to append to the qemu command shell_port -- port of the remote shell daemon on the guest (SSH, Telnet or the home-made Remote Shell Server) shell_client -- client program to use for connecting to the remote shell daemon on the guest (ssh, telnet or nc) x11_display -- if specified, the DISPLAY environment variable will be be set to this value for the qemu process (useful for SDL rendering) images -- a list of image object names, separated by spaces nics -- a list of NIC object names, separated by spaces For each image in images: drive_format -- string to pass as 'if' parameter for this image (e.g. ide, scsi) image_snapshot -- if yes, pass 'snapshot=on' to qemu for this image image_boot -- if yes, pass 'boot=on' to qemu for this image In addition, all parameters required by get_image_filename. For each NIC in nics: nic_model -- string to pass as 'model' parameter for this NIC (e.g. e1000) """ # helper function for command line option wrappers def has_option(help, option): return bool(re.search(r"--%s" % option, help, re.MULTILINE)) # Wrappers for all supported libvirt command line parameters. # This is meant to allow support for multiple libvirt versions. # Each of these functions receives the output of 'libvirt --help' as a # parameter, and should add the requested command line option # accordingly. def add_name(help, name): return " --name '%s'" % name def add_machine_type(help, machine_type): if has_option(help, "machine"): return " --machine %s" % machine_type else: return "" def add_hvm_or_pv(help, hvm_or_pv): if hvm_or_pv == "hvm": return " --hvm --accelerate" elif hvm_or_pv == "pv": return " --paravirt" else: logging.warning("Unknown virt type hvm_or_pv, using default.") return "" def add_mem(help, mem): return " --ram=%s" % mem def add_check_cpu(help): if has_option(help, "check-cpu"): return " --check-cpu" else: return "" def add_smp(help, smp): return " --vcpu=%s" % smp def add_location(help, location): if has_option(help, "location"): return " --location %s" % location else: return "" def add_cdrom(help, filename, index=None): if has_option(help, "cdrom"): return " --cdrom %s" % filename else: return "" def add_pxe(help): if has_option(help, "pxe"): return " --pxe" else: return "" def add_import(help): if has_option(help, "import"): return " --import" else: return "" def add_drive(help, filename, pool=None, vol=None, device=None, bus=None, perms=None, size=None, sparse=False, cache=None, format=None): cmd = " --disk" if filename: cmd += " path=%s" % filename elif pool: if vol: cmd += " vol=%s/%s" % (pool, vol) else: cmd += " pool=%s" % pool if device: cmd += ",device=%s" % device if bus: cmd += ",bus=%s" % bus if perms: cmd += ",%s" % perms if size: cmd += ",size=%s" % size.rstrip("Gg") if sparse: cmd += ",sparse=false" if format: cmd += ",format=%s" % format if cache: cmd += ",cache=%s" % cache return cmd def add_floppy(help, filename): return " --disk path=%s,device=floppy,ro" % filename def add_vnc(help, vnc_port=None): if vnc_port: return " --vnc --vncport=%d" % (vnc_port) else: return " --vnc" def add_vnclisten(help, vnclisten): if has_option(help, "vnclisten"): return " --vnclisten=%s" % (vnclisten) else: return "" def add_sdl(help): if has_option(help, "sdl"): return " --sdl" else: return "" def add_nographic(help): return " --nographics" def add_video(help, video_device): if has_option(help, "video"): return " --video=%s" % (video_device) else: return "" def add_uuid(help, uuid): if has_option(help, "uuid"): return " --uuid %s" % uuid else: return "" def add_os_type(help, os_type): if has_option(help, "os-type"): return " --os-type %s" % os_type else: return "" def add_os_variant(help, os_variant): if has_option(help, "os-variant"): return " --os-variant %s" % os_variant else: return "" def add_pcidevice(help, pci_device): if has_option(help, "host-device"): return " --host-device %s" % pci_device else: return "" def add_soundhw(help, sound_device): if has_option(help, "soundhw"): return " --soundhw %s" % sound_device else: return "" def add_serial(help, filename): if has_option(help, "serial"): return " --serial file,path=%s --serial pty" % filename else: self.only_pty = True return "" def add_kernel_cmdline(help, cmdline): return " -append %s" % cmdline def add_connect_uri(help, uri): if uri and has_option(help, "connect"): return " --connect=%s" % uri else: return "" def add_nic(help, nic_params): """ Return additional command line params based on dict-like nic_params """ mac = nic_params.get('mac') nettype = nic_params.get('nettype') netdst = nic_params.get('netdst') nic_model = nic_params.get('nic_model') if nettype: result = " --network=%s" % nettype else: result = "" if has_option(help, "bridge"): # older libvirt (--network=NATdev --bridge=bridgename --mac=mac) if nettype != 'user': result += ':%s' % netdst if mac: # possible to specify --mac w/o --network result += " --mac=%s" % mac else: # newer libvirt (--network=mynet,model=virtio,mac=00:11) if nettype != 'user': result += '=%s' % netdst if nettype and nic_model: # only supported along with nettype result += ",model=%s" % nic_model if nettype and mac: result += ',mac=%s' % mac elif mac: # possible to specify --mac w/o --network result += " --mac=%s" % mac logging.debug("vm.make_create_command.add_nic returning: %s" % result) return result # End of command line option wrappers if name is None: name = self.name if params is None: params = self.params if root_dir is None: root_dir = self.root_dir # Clone this VM using the new params vm = self.clone(name, params, root_dir, copy_state=True) virt_install_binary = utils_misc.get_path( root_dir, params.get("virt_install_binary", "virt-install")) help = utils.system_output("%s --help" % virt_install_binary) # Find all supported machine types, so we can rule out an unsupported # machine type option passed in the configuration. hvm_or_pv = params.get("hvm_or_pv", "hvm") # default to 'uname -m' output arch_name = params.get("vm_arch_name", utils.get_current_kernel_arch()) capabs = libvirt_xml.LibvirtXML() support_machine_type = capabs.os_arch_machine_map[hvm_or_pv][arch_name] logging.debug("Machine types supported for %s\%s: %s" % (hvm_or_pv, arch_name, support_machine_type)) # Start constructing the qemu command virt_install_cmd = "" # Set the X11 display parameter if requested if params.get("x11_display"): virt_install_cmd += "DISPLAY=%s " % params.get("x11_display") # Add the qemu binary virt_install_cmd += virt_install_binary # set connect uri virt_install_cmd += add_connect_uri(help, self.connect_uri) # hvm or pv specificed by libvirt switch (pv used by Xen only) if hvm_or_pv: virt_install_cmd += add_hvm_or_pv(help, hvm_or_pv) # Add the VM's name virt_install_cmd += add_name(help, name) machine_type = params.get("machine_type") if machine_type: if machine_type in support_machine_type: virt_install_cmd += add_machine_type(help, machine_type) else: raise error.TestNAError("Unsupported machine type %s." % (machine_type)) mem = params.get("mem") if mem: virt_install_cmd += add_mem(help, mem) # TODO: should we do the check before we call ? negative case ? check_cpu = params.get("use_check_cpu") if check_cpu: virt_install_cmd += add_check_cpu(help) smp = params.get("smp") if smp: virt_install_cmd += add_smp(help, smp) # TODO: directory location for vmlinuz/kernel for cdrom install ? location = None if params.get("medium") == 'url': location = params.get('url') elif params.get("medium") == 'kernel_initrd': # directory location of kernel/initrd pair (directory layout must # be in format libvirt will recognize) location = params.get("image_dir") elif params.get("medium") == 'nfs': location = "nfs:%s:%s" % (params.get("nfs_server"), params.get("nfs_dir")) elif params.get("medium") == 'cdrom': if params.get("use_libvirt_cdrom_switch") == 'yes': virt_install_cmd += add_cdrom(help, params.get("cdrom_cd1")) elif params.get("unattended_delivery_method") == "integrated": virt_install_cmd += add_cdrom(help, params.get("cdrom_unattended")) else: location = params.get("image_dir") kernel_dir = os.path.dirname(params.get("kernel")) kernel_parent_dir = os.path.dirname(kernel_dir) pxeboot_link = os.path.join(kernel_parent_dir, "pxeboot") if os.path.islink(pxeboot_link): os.unlink(pxeboot_link) if os.path.isdir(pxeboot_link): logging.info("Removed old %s leftover directory", pxeboot_link) shutil.rmtree(pxeboot_link) os.symlink(kernel_dir, pxeboot_link) elif params.get("medium") == "import": virt_install_cmd += add_import(help) if location: virt_install_cmd += add_location(help, location) if params.get("display") == "vnc": if params.get("vnc_autoport") == "yes": vm.vnc_autoport = True else: vm.vnc_autoport = False if not vm.vnc_autoport and params.get("vnc_port"): vm.vnc_port = int(params.get("vnc_port")) virt_install_cmd += add_vnc(help, vm.vnc_port) if params.get("vnclisten"): vm.vnclisten = params.get("vnclisten") virt_install_cmd += add_vnclisten(help, vm.vnclisten) elif params.get("display") == "sdl": virt_install_cmd += add_sdl(help) elif params.get("display") == "nographic": virt_install_cmd += add_nographic(help) video_device = params.get("video_device") if video_device: virt_install_cmd += add_video(help, video_device) sound_device = params.get("sound_device") if sound_device: virt_install_cmd += add_soundhw(help, sound_device) # if none is given a random UUID will be generated by libvirt if params.get("uuid"): virt_install_cmd += add_uuid(help, params.get("uuid")) # selectable OS type if params.get("use_os_type") == "yes": virt_install_cmd += add_os_type(help, params.get("os_type")) # selectable OS variant if params.get("use_os_variant") == "yes": virt_install_cmd += add_os_variant(help, params.get("os_variant")) # Add serial console virt_install_cmd += add_serial(help, self.get_serial_console_filename()) # If the PCI assignment step went OK, add each one of the PCI assigned # devices to the command line. if self.pci_devices: for pci_id in self.pci_devices: virt_install_cmd += add_pcidevice(help, pci_id) for image_name in params.objects("images"): image_params = params.object_params(image_name) filename = storage.get_image_filename(image_params, data_dir.get_data_dir()) if image_params.get("use_storage_pool") == "yes": filename = None virt_install_cmd += add_drive(help, filename, image_params.get("image_pool"), image_params.get("image_vol"), image_params.get("image_device"), image_params.get("image_bus"), image_params.get("image_perms"), image_params.get("image_size"), image_params.get("drive_sparse"), image_params.get("drive_cache"), image_params.get("image_format")) if image_params.get("boot_drive") == "no": continue if filename: virt_install_cmd += add_drive(help, filename, None, None, None, image_params.get("drive_format"), None, image_params.get("image_size"), image_params.get("drive_sparse"), image_params.get("drive_cache"), image_params.get("image_format")) if (params.get('unattended_delivery_method') != 'integrated' and not (self.driver_type == 'xen' and params.get('hvm_or_pv') == 'pv')): for cdrom in params.objects("cdroms"): cdrom_params = params.object_params(cdrom) iso = cdrom_params.get("cdrom") if params.get("use_libvirt_cdrom_switch") == 'yes': # we don't want to skip the winutils iso if not cdrom == 'winutils': logging.debug("Using --cdrom instead of --disk for install") logging.debug("Skipping CDROM:%s:%s", cdrom, iso) continue if params.get("medium") == 'cdrom_no_kernel_initrd': if iso == params.get("cdrom_cd1"): logging.debug("Using cdrom or url for install") logging.debug("Skipping CDROM: %s", iso) continue if iso: virt_install_cmd += add_drive(help, utils_misc.get_path(root_dir, iso), image_params.get("iso_image_pool"), image_params.get("iso_image_vol"), 'cdrom', None, None, None, None, None, None) # We may want to add {floppy_otps} parameter for -fda # {fat:floppy:}/path/. However vvfat is not usually recommended. # Only support to add the main floppy if you want to add the second # one please modify this part. floppy = params.get("floppy_name") if floppy: floppy = utils_misc.get_path(data_dir.get_data_dir(), floppy) virt_install_cmd += add_drive(help, floppy, None, None, 'floppy', None, None, None, None, None, None) # setup networking parameters for nic in vm.virtnet: # make_create_command can be called w/o vm.create() nic = vm.add_nic(**dict(nic)) logging.debug("make_create_command() setting up command for" " nic: %s" % str(nic)) virt_install_cmd += add_nic(help,nic) if params.get("use_no_reboot") == "yes": virt_install_cmd += " --noreboot" if params.get("use_autostart") == "yes": virt_install_cmd += " --autostart" if params.get("virt_install_debug") == "yes": virt_install_cmd += " --debug" # bz still open, not fully functional yet if params.get("use_virt_install_wait") == "yes": virt_install_cmd += (" --wait %s" % params.get("virt_install_wait_time")) kernel_params = params.get("kernel_params") if kernel_params: virt_install_cmd += " --extra-args '%s'" % kernel_params virt_install_cmd += " --noautoconsole" return virt_install_cmd
def output_check(nodeinfo_output): # Check CPU model cpu_model_nodeinfo = _check_nodeinfo(nodeinfo_output, "CPU model", 3) cpu_model_os = utils.get_current_kernel_arch() if not re.match(cpu_model_nodeinfo, cpu_model_os): raise error.TestFail( "Virsh nodeinfo output didn't match CPU model") # Check number of CPUs cpus_nodeinfo = _check_nodeinfo(nodeinfo_output, "CPU(s)", 2) cpus_os = utils.count_cpus() if int(cpus_nodeinfo) != cpus_os: raise error.TestFail( "Virsh nodeinfo output didn't match number of " "CPU(s)") # Check CPU frequency cpu_frequency_nodeinfo = _check_nodeinfo(nodeinfo_output, 'CPU frequency', 3) cmd = ("cat /proc/cpuinfo | grep 'cpu MHz' | head -n1 | " "awk '{print $4}' | awk -F. '{print $1}'") cmd_result = utils.run(cmd, ignore_status=True) cpu_frequency_os = cmd_result.stdout.strip() logging.debug("cpu_frequency_nodeinfo=%s cpu_frequency_os=%s", cpu_frequency_nodeinfo, cpu_frequency_os) # # Matching CPU Frequency is not an exact science in todays modern # processors and OS's. CPU's can have their execution speed varied # based on current workload in order to save energy and keep cool. # Thus since we're getting the values at disparate points in time, # we cannot necessarily do a pure comparison. # So, let's get the absolute value of the difference and ensure # that it's within 20 percent of each value to give us enough of # a "fudge" factor to declare "close enough". Don't return a failure # just print a debug message and move on. diffval = abs(int(cpu_frequency_nodeinfo) - int(cpu_frequency_os)) if float(diffval) / float(cpu_frequency_nodeinfo) > 0.20 or \ float(diffval) / float(cpu_frequency_os) > 0.20: logging.debug("Virsh nodeinfo output didn't match CPU " "frequency within 20 percent") # Get CPU topolopy from virsh capabilities xml cpu_topolopy = capability_xml.CapabilityXML()['cpu_topolopy'] logging.debug("Cpu topolopy in virsh capabilities output: %s", cpu_topolopy) # Check CPU socket(s) cpu_sockets_nodeinfo = int( _check_nodeinfo(nodeinfo_output, 'CPU socket(s)', 3)) cmd = "grep 'physical id' /proc/cpuinfo | uniq | sort | uniq |wc -l" cmd_result = utils.run(cmd, ignore_status=True) cpu_NUMA_nodeinfo = _check_nodeinfo(nodeinfo_output, 'NUMA cell(s)', 3) cpu_sockets_os = int( cmd_result.stdout.strip()) / int(cpu_NUMA_nodeinfo) if cpu_sockets_os != cpu_sockets_nodeinfo: raise error.TestFail("Virsh nodeinfo output didn't match CPU " "socket(s) of host OS") if cpu_sockets_nodeinfo != int(cpu_topolopy['sockets']): raise error.TestFail("Virsh nodeinfo output didn't match CPU " "socket(s) of virsh capabilities output") # Check Core(s) per socket cores_per_socket_nodeinfo = _check_nodeinfo(nodeinfo_output, 'Core(s) per socket', 4) cmd = "grep 'cpu cores' /proc/cpuinfo | head -n1 | awk '{print $4}'" cmd_result = utils.run(cmd, ignore_status=True) cores_per_socket_os = cmd_result.stdout.strip() if not re.match(cores_per_socket_nodeinfo, cores_per_socket_os): raise error.TestFail("Virsh nodeinfo output didn't match Core(s) " "per socket of host OS") if cores_per_socket_nodeinfo != cpu_topolopy['cores']: raise error.TestFail("Virsh nodeinfo output didn't match Core(s) " "per socket of virsh capabilities output") # Ckeck Thread(s) per core threads_per_core_nodeinfo = _check_nodeinfo(nodeinfo_output, 'Thread(s) per core', 4) if threads_per_core_nodeinfo != cpu_topolopy['threads']: raise error.TestFail( "Virsh nodeinfo output didn't match Thread(s) " "per core of virsh capabilities output") # Check Memory size memory_size_nodeinfo = int( _check_nodeinfo(nodeinfo_output, 'Memory size', 3)) memory_size_os = utils_memory.memtotal() if memory_size_nodeinfo != memory_size_os: raise error.TestFail("Virsh nodeinfo output didn't match " "Memory size")