Skip to content

Commit a6d8cf1

Browse files
nyoximz-pdm
authored andcommitted
virt: v2v: parse progress from new virt-v2v
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ý <[email protected]>
1 parent 1938e3c commit a6d8cf1

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

lib/vdsm/v2v.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ def _abort(self):
933933

934934
class OutputParser(object):
935935
COPY_DISK_RE = re.compile(br'.*(Copying disk (\d+)/(\d+)).*')
936-
DISK_PROGRESS_RE = re.compile(br'\s+\((\d+).*')
936+
DISK_PROGRESS_RE = re.compile(br'\s+\((\d+).*|.+ (\d+)% \[[*-]+\]')
937937

938938
def parse(self, stream):
939939
for line in stream:
@@ -970,8 +970,9 @@ def _parse_progress(self, chunk):
970970
m = self.DISK_PROGRESS_RE.match(chunk)
971971
if m is None:
972972
return None
973+
value = [x for x in m.groups() if x is not None][0]
973974
try:
974-
return int(m.group(1))
975+
return int(value)
975976
except ValueError:
976977
raise OutputParserError('error parsing progress regex: %r'
977978
% m.groups)

tests/virt/v2v_test.py

+32
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,38 @@ def testOutputParser(self):
322322
(v2v.DiskProgress(50)),
323323
(v2v.DiskProgress(100))]
324324

325+
def testOutputParser2(self):
326+
output = bytes('[ 0.0] Opening the source -i libvirt ://roo...\n'
327+
'[ 1.0] Creating an overlay to protect the f...\n'
328+
'[ 88.0] Copying disk 1/2\n'
329+
'▝ 0% [----------------------------------------]\r'
330+
'some messages\r'
331+
'▍ 25% [***********-----------------------------]\r'
332+
'more messages\n'
333+
'▐ 50% [********************--------------------]\r'
334+
'much much more messages\r\n'
335+
'█ 100% [****************************************]\r'
336+
'[ 180.0] Copying disk 2/2\n'
337+
'▝ 0% [----------------------------------------]\r'
338+
'▃ 50% [*********************-------------------]\r'
339+
'█ 100% [****************************************]\r'
340+
'[ 256.0] Creating output metadata\n'
341+
'[ 256.0] Finishing off',
342+
encoding='utf-8')
343+
344+
parser = v2v.OutputParser()
345+
events = list(parser.parse(io.BytesIO(output)))
346+
assert events == [
347+
(v2v.ImportProgress(1, 2, 'Copying disk 1/2')),
348+
(v2v.DiskProgress(0)),
349+
(v2v.DiskProgress(25)),
350+
(v2v.DiskProgress(50)),
351+
(v2v.DiskProgress(100)),
352+
(v2v.ImportProgress(2, 2, 'Copying disk 2/2')),
353+
(v2v.DiskProgress(0)),
354+
(v2v.DiskProgress(50)),
355+
(v2v.DiskProgress(100))]
356+
325357
def testGetExternalVMsWithoutDisksInfo(self):
326358
def internal_error(name):
327359
raise fake.Error(libvirt.VIR_ERR_INTERNAL_ERROR)

0 commit comments

Comments
 (0)