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 E413CA0471 for ; Tue, 13 Aug 2019 08:39:27 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D7EF81BE83; Tue, 13 Aug 2019 08:39:27 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id F00A01BDAE for ; Tue, 13 Aug 2019 08:39:25 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Aug 2019 23:39:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,380,1559545200"; d="scan'208";a="204984008" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by fmsmga002.fm.intel.com with ESMTP; 12 Aug 2019 23:39:25 -0700 Received: from FMSMSX109.amr.corp.intel.com (10.18.116.9) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 12 Aug 2019 23:39:24 -0700 Received: from shsmsx154.ccr.corp.intel.com (10.239.6.54) by fmsmsx109.amr.corp.intel.com (10.18.116.9) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 12 Aug 2019 23:39:24 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.112]) by SHSMSX154.ccr.corp.intel.com ([169.254.7.249]) with mapi id 14.03.0439.000; Tue, 13 Aug 2019 14:39:22 +0800 From: "Wang, Yinan" 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: AQHVUZi2tBzLWb7wkkmq3H1P9g4eoqb4oHPA Date: Tue, 13 Aug 2019 06:39:22 +0000 Message-ID: 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: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZGNlMTNlNzYtZWYwYi00NDYwLTgwOWQtZjZhMDhlYWNhODhmIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiN21zcGIrdG1GczVzaVZDUXgzTUJlbHF2M2NUYzFsNzRuYTF4UFhnZVFiVDlLbHNqU3A0bkg3YkNPMktGUCtGeSJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="iso-2022-jp" 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" Acked-by: Wang, Yinan > -----Original Message----- > From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of yufengmx > Sent: 2019=1B$BG/=1B(B8=1B$B7n=1B(B13=1B$BF|=1B(B 13:35 > 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.controllerindex)[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': > serial_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