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)