X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FQemuUtils.py;h=0113dc9e03a68d1341ee243955f9f25093caf601;hb=5dc176ab31af5dff73be6dd5266169a7be19dd13;hp=09c3df77256e0122943d37a53451763c61d7551a;hpb=ae652334356c12b167399a340ad55abd1ef7bbce;p=csit.git diff --git a/resources/libraries/python/QemuUtils.py b/resources/libraries/python/QemuUtils.py index 09c3df7725..0113dc9e03 100644 --- a/resources/libraries/python/QemuUtils.py +++ b/resources/libraries/python/QemuUtils.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019 Cisco and/or its affiliates. +# Copyright (c) 2020 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -60,10 +60,20 @@ class QemuUtils: self._vhost_id = 0 self._node = node self._arch = Topology.get_node_arch(self._node) - dpdk_target = u"arm64-armv8a" if self._arch == u"aarch64" \ - else u"x86_64-native" + self._opt = dict() + + # Architecture specific options + if self._arch == u"aarch64": + dpdk_target = u"arm64-armv8a" + self._opt[u"machine_args"] = \ + u"virt,accel=kvm,usb=off,mem-merge=off,gic-version=3" + self._opt[u"console"] = u"ttyAMA0" + else: + dpdk_target = u"x86_64-native" + self._opt[u"machine_args"] = u"pc,accel=kvm,usb=off,mem-merge=off" + self._opt[u"console"] = u"ttyS0" self._testpmd_path = f"{Constants.QEMU_VM_DPDK}/" \ - f"{dpdk_target}-linuxapp-gcc/app" + f"{dpdk_target}-linux-gcc/app" self._vm_info = { u"host": node[u"host"], u"type": NodeType.VM, @@ -78,7 +88,6 @@ class QemuUtils: self._vm_info[u"host_username"] = node[u"username"] self._vm_info[u"host_password"] = node[u"password"] # Input Options. - self._opt = dict() self._opt[u"qemu_id"] = qemu_id self._opt[u"mem"] = int(mem) self._opt[u"smp"] = int(smp) @@ -86,11 +95,11 @@ class QemuUtils: self._opt[u"vnf"] = vnf # Temporary files. self._temp = dict() - self._temp[u"pidfile"] = f"/var/run/qemu_{qemu_id}.pid" + self._temp[u"pidfile"] = f"/run/qemu_{qemu_id}.pid" if img == Constants.QEMU_VM_IMAGE: self._opt[u"vm_type"] = u"nestedvm" - self._temp[u"qmp"] = f"/var/run/qmp_{qemu_id}.sock" - self._temp[u"qga"] = f"/var/run/qga_{qemu_id}.sock" + self._temp[u"qmp"] = f"/run/qmp_{qemu_id}.sock" + self._temp[u"qga"] = f"/run/qga_{qemu_id}.sock" elif img == Constants.QEMU_VM_KERNEL: self._opt[u"img"], _ = exec_cmd_no_error( node, f"ls -1 {Constants.QEMU_VM_KERNEL}* | tail -1", @@ -134,11 +143,7 @@ class QemuUtils: self._params.add_with_value(u"pidfile", self._temp.get(u"pidfile")) self._params.add_with_value(u"cpu", u"host") - if self._arch == u"aarch64": - machine_args = u"virt,accel=kvm,usb=off,mem-merge=off,gic-version=3" - else: - machine_args = u"pc,accel=kvm,usb=off,mem-merge=off" - self._params.add_with_value(u"machine", machine_args) + self._params.add_with_value(u"machine", self._opt.get(u"machine_args")) self._params.add_with_value( u"smp", f"{self._opt.get(u'smp')},sockets=1," f"cores={self._opt.get(u'smp')},threads=1" @@ -180,7 +185,6 @@ class QemuUtils: def add_kernelvm_params(self): """Set KernelVM QEMU parameters.""" - console = u"ttyAMA0" if self._arch == u"aarch64" else u"ttyS0" self._params.add_with_value( u"serial", f"file:{self._temp.get(u'log')}" ) @@ -194,7 +198,8 @@ class QemuUtils: self._params.add_with_value(u"initrd", f"{self._opt.get(u'initrd')}") self._params.add_with_value( u"append", f"'ro rootfstype=9p rootflags=trans=virtio " - f"root=virtioroot console={console} tsc=reliable hugepages=256 " + f"root=virtioroot console={self._opt.get(u'console')} " + f"tsc=reliable hugepages=256 " f"init={self._temp.get(u'ini')} fastboot'" ) @@ -228,15 +233,15 @@ class QemuUtils: if not kwargs[u"jumbo_frames"]: vpp_config.add_dpdk_no_multi_seg() vpp_config.add_dpdk_no_tx_checksum_offload() - vpp_config.add_plugin(u"disable", [u"default"]) - vpp_config.add_plugin(u"enable", [u"dpdk_plugin.so"]) + vpp_config.add_plugin(u"disable", u"default") + vpp_config.add_plugin(u"enable", u"dpdk_plugin.so") vpp_config.write_config(startup) # Create VPP running configuration. template = f"{Constants.RESOURCES_TPL_VM}/{self._opt.get(u'vnf')}.exec" exec_cmd_no_error(self._node, f"rm -f {running}", sudo=True) - with open(template, "r") as src_file: + with open(template, u"rt") as src_file: src = Template(src_file.read()) exec_cmd_no_error( self._node, f"echo '{src.safe_substitute(**kwargs)}' | " @@ -296,7 +301,7 @@ class QemuUtils: init = self._temp.get(u"ini") exec_cmd_no_error(self._node, f"rm -f {init}", sudo=True) - with open(template, "r") as src_file: + with open(template, u"rt") as src_file: src = Template(src_file.read()) exec_cmd_no_error( self._node, f"echo '{src.safe_substitute(**kwargs)}' | " @@ -318,7 +323,7 @@ class QemuUtils: self.create_kernelvm_config_testpmd_mac(**kwargs) else: raise RuntimeError(u"QEMU: Unsupported VNF!") - self.create_kernelvm_init(vnf_bin=self._opt[u"vnf_bin"]) + self.create_kernelvm_init(vnf_bin=self._opt.get(u"vnf_bin")) def get_qemu_pids(self): """Get QEMU CPU pids. @@ -420,7 +425,6 @@ class QemuUtils: f"addr={self._vhost_id+5}.0,mq=on,vectors={2 * queues + 2}," f"csum={u'on' if csum else u'off'},gso={u'on' if gso else u'off'}," f"guest_tso4=off,guest_tso6=off,guest_ecn=off," - f"mrg_rxbuf={u'on,host_mtu=9200' if jumbo_frames else u'off'}," f"{queue_size}" ) @@ -611,7 +615,7 @@ class QemuUtils: message = f"QEMU: Start failed on {self._node[u'host']}!" try: DUTSetup.check_huge_page( - self._node, u"/dev/hugepages", self._opt.get(u"mem")) + self._node, u"/dev/hugepages", int(self._opt.get(u"mem"))) exec_cmd_no_error( self._node, cmd_opts, timeout=300, sudo=True, message=message