Skip to content

Commit

Permalink
virt: v2v: parse progress from new virt-v2v
Browse files Browse the repository at this point in the history
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ý <tgolembi@redhat.com>
  • Loading branch information
nyoxi authored and mz-pdm committed Nov 6, 2023
1 parent 1938e3c commit a6d8cf1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/vdsm/v2v.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions tests/virt/v2v_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a6d8cf1

Please sign in to comment.