From: "Wang, Yinan" <yinan.wang@intel.com>
To: "Mo, YufengX" <yufengx.mo@intel.com>, "dts@dpdk.org" <dts@dpdk.org>
Cc: "Mo, YufengX" <yufengx.mo@intel.com>
Subject: Re: [dts] [PATCH V1]framework\qemu_libvirt: fix xml format and pep8 issue
Date: Tue, 13 Aug 2019 06:39:22 +0000 [thread overview]
Message-ID: <E0CBA5A1980F1F408E1F28F9991B5B1D50EE522D@SHSMSX104.ccr.corp.intel.com> (raw)
In-Reply-To: <1565674484-21165-2-git-send-email-yufengx.mo@intel.com>
Acked-by: Wang, Yinan <yinan.wang@intel.com>
> -----Original Message-----
> From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of yufengmx
> Sent: 2019年8月13日 13:35
> To: dts@dpdk.org
> Cc: Mo, YufengX <yufengx.mo@intel.com>
> Subject: [dts] [PATCH V1]framework\qemu_libvirt: fix xml format and pep8 issue
>
>
> *. check vm xml file existence before remove it to fix warning of using except.
> *. format libvirt xml content with pretty style to make vm config file easier to set
> manually.
> *. fix pep8 issue.
>
> Signed-off-by: yufengmx <yufengx.mo@intel.com>
> ---
> framework/qemu_libvirt.py | 60
> ++++++++++++++++++++++++++++-------------------
> 1 file changed, 36 insertions(+), 24 deletions(-)
>
> diff --git a/framework/qemu_libvirt.py b/framework/qemu_libvirt.py index
> 66fc54b..ab62ab8 100644
> --- a/framework/qemu_libvirt.py
> +++ b/framework/qemu_libvirt.py
> @@ -44,6 +44,7 @@ from config import VIRTCONF from exception import
> StartVMFailedException import xml.etree.ElementTree as ET from
> xml.etree.ElementTree import ElementTree
> +from xml.dom import minidom
>
>
> class LibvirtKvm(VirtBase):
> @@ -102,7 +103,8 @@ class LibvirtKvm(VirtBase):
> """
> arch = self.host_session.send_expect('uname -m', '# ')
> if arch == 'aarch64':
> - out = self.host_session.send_expect('service libvirtd status', "# ")
> + out = self.host_session.send_expect(
> + 'service libvirtd status', "# ")
> if 'active (running)' not in out:
> return False
> return True
> @@ -214,13 +216,12 @@ class LibvirtKvm(VirtBase):
> os = self.domain.find('os')
> if 'loader' in options.keys():
> loader = ET.SubElement(
> - os, 'loader', {'readonly': 'yes', 'type': 'pflash'})
> + os, 'loader', {'readonly': 'yes', 'type': 'pflash'})
> loader.text = options['loader']
> if 'nvram' in options.keys():
> nvram = ET.SubElement(os, 'nvram')
> nvram.text = options['nvram']
>
> -
> def set_vm_default_aarch64(self):
> os = ET.SubElement(self.domain, 'os')
> type = ET.SubElement(
> @@ -231,7 +232,7 @@ class LibvirtKvm(VirtBase):
> ET.SubElement(features, 'acpi')
>
> ET.SubElement(self.domain, 'cpu',
> - {'mode': 'host-passthrough', 'check': 'none'})
> + {'mode': 'host-passthrough', 'check': 'none'})
>
> def set_vm_default_x86_64(self):
> os = ET.SubElement(self.domain, 'os') @@ -252,7 +253,6 @@ class
> LibvirtKvm(VirtBase):
> set_default_func = getattr(self, 'set_vm_default_' + arch)
> if callable(set_default_func):
> set_default_func()
> -
>
> # qemu-kvm for emulator
> device = ET.SubElement(self.domain, 'devices') @@ -338,13 +338,14
> @@ class LibvirtKvm(VirtBase):
>
> if 'opt_controller' in options:
> controller = ET.SubElement(devices, 'controller',
> - {'type': bus,
> - 'index': hex(self.controllerindex)[2:],
> - 'model': options['opt_controller']})
> + {'type': bus,
> + 'index':
> hex(self.controllerindex)[2:],
> + 'model':
> + options['opt_controller']})
> self.controllerindex += 1
> - ET.SubElement(controller, 'address',
> + ET.SubElement(
> + controller, 'address',
> {'type': 'pci', 'domain': '0x0000', 'bus': hex(self.pciindex),
> - 'slot': '0x00', 'function': '0x00'})
> + 'slot': '0x00', 'function': '0x00'})
> self.pciindex += 1
>
> def add_vm_serial_port(self, **options):
> @@ -356,18 +357,26 @@ class LibvirtKvm(VirtBase):
> else:
> serial_type = 'unix'
> if serial_type == 'pty':
> - serial = ET.SubElement(devices, 'serial', {'type':
> serial_type})
> + serial = ET.SubElement(
> + devices, 'serial', {'type': serial_type})
> ET.SubElement(serial, 'target', {'port': '0'})
> elif serial_type == 'unix':
> - serial = ET.SubElement(devices, 'serial', {'type':
> serial_type})
> + serial = ET.SubElement(
> + devices, 'serial', {'type': serial_type})
> self.serial_path = "/tmp/%s_serial.sock" % self.vm_name
> - ET.SubElement(serial, 'source', {'mode': 'bind', 'path':
> self.serial_path})
> + ET.SubElement(
> + serial,
> + 'source',
> + {'mode': 'bind', 'path': self.serial_path})
> ET.SubElement(serial, 'target', {'port': '0'})
> else:
> - print utils.RED("Serial type %s is not supported!" %
> serial_type)
> + print utils.RED(
> + "Serial type %s is not supported!" %
> + serial_type)
> return False
> - console = ET.SubElement(devices, 'console', {'type':
> serial_type})
> - ET.SubElement(console, 'target', {'type': 'serial', 'port': '0'})
> + console = ET.SubElement(
> + devices, 'console', {'type': serial_type})
> + ET.SubElement(
> + console, 'target', {'type': 'serial', 'port': '0'})
>
> def add_vm_login(self, **options):
> """
> @@ -396,14 +405,14 @@ class LibvirtKvm(VirtBase):
> bus = m.group(1)
> slot = m.group(2)
> func = m.group(3)
> - dom = '0'
> + dom = '0'
> return (bus, slot, func, dom)
> m = re.match(pci_regex_domain, pci_address)
> if m is not None:
> bus = m.group(2)
> slot = m.group(3)
> func = m.group(4)
> - dom = m.group(1)
> + dom = m.group(1)
> return (bus, slot, func, dom)
> return None
>
> @@ -427,7 +436,6 @@ class LibvirtKvm(VirtBase):
> print utils.RED("Missing opt_host for device option!!!")
> return False
>
> -
> pci = self.__parse_pci(pci_addr)
> if pci is None:
> return False
> @@ -449,8 +457,8 @@ class LibvirtKvm(VirtBase):
> return False
> bus, slot, func, dom = pci
> ET.SubElement(hostdevice, 'address', {
> - 'type': 'pci', 'domain': '0x%s' % dom, 'bus': '0x%s' % bus,
> - 'slot': '0x%s' % slot, 'function': '0x%s' % func})
> + 'type': 'pci', 'domain': '0x%s' % dom, 'bus': '0x%s' % bus,
> + 'slot': '0x%s' % slot, 'function': '0x%s' % func})
> # save host and guest pci address mapping
> pci_map = {}
> pci_map['hostpci'] = pci_addr
> @@ -570,11 +578,15 @@ class LibvirtKvm(VirtBase):
>
> def _start_vm(self):
> xml_file = "/tmp/%s.xml" % self.vm_name
> - try:
> + if os.path.exists(xml_file):
> os.remove(xml_file)
> - except:
> - pass
> self.root.write(xml_file)
> + with open(xml_file, 'rb') as fp:
> + content = fp.read()
> + doc = minidom.parseString(content)
> + vm_content = doc.toprettyxml(indent=' ')
> + with open(xml_file, 'wb') as fp:
> + fp.write(vm_content)
> self.host_session.copy_file_to(xml_file)
> time.sleep(2)
>
> --
> 1.9.3
next prev parent reply other threads:[~2019-08-13 6:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-13 5:34 [dts] [PATCH V1]framework/qemu_libvirt: " yufengmx
2019-08-13 5:34 ` [dts] [PATCH V1]framework\qemu_libvirt: " yufengmx
2019-08-13 6:39 ` Wang, Yinan [this message]
2019-08-28 5:36 ` Tu, Lijuan
2019-08-13 6:39 ` [dts] [PATCH V1]framework/qemu_libvirt: " Wang, Yinan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E0CBA5A1980F1F408E1F28F9991B5B1D50EE522D@SHSMSX104.ccr.corp.intel.com \
--to=yinan.wang@intel.com \
--cc=dts@dpdk.org \
--cc=yufengx.mo@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).