Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virt: v2v: parse progress from new virt-v2v #402

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
mz-pdm marked this conversation as resolved.
Show resolved Hide resolved
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