From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 06541A0613 for ; Wed, 28 Aug 2019 07:37:05 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AFB701C1EE; Wed, 28 Aug 2019 07:37:05 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 021491BFFB for ; Wed, 28 Aug 2019 07:37:03 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Aug 2019 22:37:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,440,1559545200"; d="scan'208";a="188116073" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by FMSMGA003.fm.intel.com with ESMTP; 27 Aug 2019 22:37:00 -0700 Received: from fmsmsx155.amr.corp.intel.com (10.18.116.71) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 27 Aug 2019 22:37:00 -0700 Received: from shsmsx153.ccr.corp.intel.com (10.239.6.53) by FMSMSX155.amr.corp.intel.com (10.18.116.71) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 27 Aug 2019 22:37:00 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.80]) by SHSMSX153.ccr.corp.intel.com ([169.254.12.215]) with mapi id 14.03.0439.000; Wed, 28 Aug 2019 13:36:58 +0800 From: "Tu, Lijuan" To: "Mo, YufengX" , "dts@dpdk.org" CC: "Mo, YufengX" Thread-Topic: [dts] [PATCH V1]framework\qemu_libvirt: fix xml format and pep8 issue Thread-Index: AQHVUZi2sxwg3UNmRESGxs5wKyqB+qcQIftg Date: Wed, 28 Aug 2019 05:36:57 +0000 Message-ID: <8CE3E05A3F976642AAB0F4675D0AD20E0BB06683@SHSMSX101.ccr.corp.intel.com> References: <1565674484-21165-1-git-send-email-yufengx.mo@intel.com> <1565674484-21165-2-git-send-email-yufengx.mo@intel.com> In-Reply-To: <1565674484-21165-2-git-send-email-yufengx.mo@intel.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNWFmYzcwMzctNDBlYi00NTAyLTgwZmUtNDBlNzEzNmRkMDU3IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiV0F3OFVGYjB2YmsxSG90RjVBUGhPV1JkeDZ3OCs2YUJBRGd0OFwvOTNobjJaTU55UmxyNmVGcXJ5K09ZS3RsRDgifQ== x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dts] [PATCH V1]framework\qemu_libvirt: fix xml format and pep8 issue X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dts-bounces@dpdk.org Sender: "dts" Applied, thanks > -----Original Message----- > From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of yufengmx > Sent: Tuesday, August 13, 2019 1:35 PM > To: dts@dpdk.org > Cc: Mo, YufengX > Subject: [dts] [PATCH V1]framework\qemu_libvirt: fix xml format and pep8 > issue >=20 >=20 > *. check vm xml file existence before remove it to fix warning of using e= xcept. > *. format libvirt xml content with pretty style to make vm config file ea= sier to > set manually. > *. fix pep8 issue. >=20 > Signed-off-by: yufengmx > --- > framework/qemu_libvirt.py | 60 ++++++++++++++++++++++++++++-------------= - > ----- > 1 file changed, 36 insertions(+), 24 deletions(-) >=20 > 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 >=20 >=20 > class LibvirtKvm(VirtBase): > @@ -102,7 +103,8 @@ class LibvirtKvm(VirtBase): > """ > arch =3D self.host_session.send_expect('uname -m', '# ') > if arch =3D=3D 'aarch64': > - out =3D self.host_session.send_expect('service libvirtd stat= us', "# ") > + out =3D 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 =3D self.domain.find('os') > if 'loader' in options.keys(): > loader =3D ET.SubElement( > - os, 'loader', {'readonly': 'yes', 'type': 'pflash'}) > + os, 'loader', {'readonly': 'yes', 'type': 'pflash'}) > loader.text =3D options['loader'] > if 'nvram' in options.keys(): > nvram =3D ET.SubElement(os, 'nvram') > nvram.text =3D options['nvram'] >=20 > - > def set_vm_default_aarch64(self): > os =3D ET.SubElement(self.domain, 'os') > type =3D ET.SubElement( > @@ -231,7 +232,7 @@ class LibvirtKvm(VirtBase): > ET.SubElement(features, 'acpi') >=20 > ET.SubElement(self.domain, 'cpu', > - {'mode': 'host-passthrough', 'check': 'none'}) > + {'mode': 'host-passthrough', 'check': 'none'}) >=20 > def set_vm_default_x86_64(self): > os =3D ET.SubElement(self.domain, 'os') @@ -252,7 +253,6 @@ clas= s > LibvirtKvm(VirtBase): > set_default_func =3D getattr(self, 'set_vm_default_' + arch) > if callable(set_default_func): > set_default_func() > - >=20 > # qemu-kvm for emulator > device =3D ET.SubElement(self.domain, 'devices') @@ -338,13 +338= ,14 > @@ class LibvirtKvm(VirtBase): >=20 > if 'opt_controller' in options: > controller =3D ET.SubElement(devices, 'controller', > - {'type': bus, > - 'index': hex(self.controllerindex)[2:], > - 'model': options['opt_controller']}) > + {'type': bus, > + 'index': hex(self.controllerinde= x)[2:], > + 'model': > + options['opt_controller']}) > self.controllerindex +=3D 1 > - ET.SubElement(controller, 'address', > + ET.SubElement( > + controller, 'address', > {'type': 'pci', 'domain': '0x0000', 'bus': hex(self.pcii= ndex), > - 'slot': '0x00', 'function': '0x00'}) > + 'slot': '0x00', 'function': '0x00'}) > self.pciindex +=3D 1 >=20 > def add_vm_serial_port(self, **options): > @@ -356,18 +357,26 @@ class LibvirtKvm(VirtBase): > else: > serial_type =3D 'unix' > if serial_type =3D=3D 'pty': > - serial =3D ET.SubElement(devices, 'serial', {'type':= serial_type}) > + serial =3D ET.SubElement( > + devices, 'serial', {'type': serial_type}) > ET.SubElement(serial, 'target', {'port': '0'}) > elif serial_type =3D=3D 'unix': > - serial =3D ET.SubElement(devices, 'serial', {'type':= serial_type}) > + serial =3D ET.SubElement( > + devices, 'serial', {'type': serial_type}) > self.serial_path =3D "/tmp/%s_serial.sock" % self.vm= _name > - ET.SubElement(serial, 'source', {'mode': 'bind', 'pa= th': > 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 =3D ET.SubElement(devices, 'console', {'type': s= erial_type}) > - ET.SubElement(console, 'target', {'type': 'serial', 'por= t': '0'}) > + console =3D ET.SubElement( > + devices, 'console', {'type': serial_type}) > + ET.SubElement( > + console, 'target', {'type': 'serial', 'port': '0'}) >=20 > def add_vm_login(self, **options): > """ > @@ -396,14 +405,14 @@ class LibvirtKvm(VirtBase): > bus =3D m.group(1) > slot =3D m.group(2) > func =3D m.group(3) > - dom =3D '0' > + dom =3D '0' > return (bus, slot, func, dom) > m =3D re.match(pci_regex_domain, pci_address) > if m is not None: > bus =3D m.group(2) > slot =3D m.group(3) > func =3D m.group(4) > - dom =3D m.group(1) > + dom =3D m.group(1) > return (bus, slot, func, dom) > return None >=20 > @@ -427,7 +436,6 @@ class LibvirtKvm(VirtBase): > print utils.RED("Missing opt_host for device option!!!") > return False >=20 > - > pci =3D self.__parse_pci(pci_addr) > if pci is None: > return False > @@ -449,8 +457,8 @@ class LibvirtKvm(VirtBase): > return False > bus, slot, func, dom =3D 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 =3D {} > pci_map['hostpci'] =3D pci_addr > @@ -570,11 +578,15 @@ class LibvirtKvm(VirtBase): >=20 > def _start_vm(self): > xml_file =3D "/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 =3D fp.read() > + doc =3D minidom.parseString(content) > + vm_content =3D doc.toprettyxml(indent=3D' ') > + with open(xml_file, 'wb') as fp: > + fp.write(vm_content) > self.host_session.copy_file_to(xml_file) > time.sleep(2) >=20 > -- > 1.9.3