From 2be986c6a8e2f3bcad92acd488e485064afedd11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Date: Thu, 26 Oct 2023 17:36:25 +0200 Subject: [PATCH] virt: v2v: parse progress from new virt-v2v MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Progress generated by virt-v2v has changed and is more graphical. This breaks the parser and causes the import to abort even when there is no real problem and virt-v2 completes successfully. Update the parsing logic to handle both old and new progress format. Signed-off-by: Tomáš Golembiovský --- lib/vdsm/v2v.py | 5 +++-- tests/virt/v2v_test.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/vdsm/v2v.py b/lib/vdsm/v2v.py index 2df126a368..a05d38313e 100644 --- a/lib/vdsm/v2v.py +++ b/lib/vdsm/v2v.py @@ -933,7 +933,7 @@ def _abort(self): class OutputParser(object): COPY_DISK_RE = re.compile(br'.*(Copying disk (\d+)/(\d+)).*') - DISK_PROGRESS_RE = re.compile(br'\s+\((\d+).*') + DISK_PROGRESS_RE = re.compile(br'\s+\((\d+).*|.+ (\d+)% \[[*-]+\]') def parse(self, stream): for line in stream: @@ -970,8 +970,9 @@ def _parse_progress(self, chunk): m = self.DISK_PROGRESS_RE.match(chunk) if m is None: return None + value = [x for x in m.groups() if x is not None][0] try: - return int(m.group(1)) + return int(value) except ValueError: raise OutputParserError('error parsing progress regex: %r' % m.groups) diff --git a/tests/virt/v2v_test.py b/tests/virt/v2v_test.py index 83b46ceeca..956c1defff 100644 --- a/tests/virt/v2v_test.py +++ b/tests/virt/v2v_test.py @@ -322,6 +322,38 @@ def testOutputParser(self): (v2v.DiskProgress(50)), (v2v.DiskProgress(100))] + def testOutputParser2(self): + output = bytes('[ 0.0] Opening the source -i libvirt ://roo...\n' + '[ 1.0] Creating an overlay to protect the f...\n' + '[ 88.0] Copying disk 1/2\n' + '▝ 0% [----------------------------------------]\r' + 'some messages\r' + '▍ 25% [***********-----------------------------]\r' + 'more messages\n' + '▐ 50% [********************--------------------]\r' + 'much much more messages\r\n' + '█ 100% [****************************************]\r' + '[ 180.0] Copying disk 2/2\n' + '▝ 0% [----------------------------------------]\r' + '▃ 50% [*********************-------------------]\r' + '█ 100% [****************************************]\r' + '[ 256.0] Creating output metadata\n' + '[ 256.0] Finishing off', + encoding='utf-8') + + parser = v2v.OutputParser() + events = list(parser.parse(io.BytesIO(output))) + assert events == [ + (v2v.ImportProgress(1, 2, 'Copying disk 1/2')), + (v2v.DiskProgress(0)), + (v2v.DiskProgress(25)), + (v2v.DiskProgress(50)), + (v2v.DiskProgress(100)), + (v2v.ImportProgress(2, 2, 'Copying disk 2/2')), + (v2v.DiskProgress(0)), + (v2v.DiskProgress(50)), + (v2v.DiskProgress(100))] + def testGetExternalVMsWithoutDisksInfo(self): def internal_error(name): raise fake.Error(libvirt.VIR_ERR_INTERNAL_ERROR)