From Dan Kenigsberg <danken(a)redhat.com>:
Dan Kenigsberg has uploaded a new change for review.
Change subject: py3: fix v2v and its test
......................................................................
py3: fix v2v and its test
Change-Id: I1a7d26d8731ccd1e03687fa6ab772f165cb9f523
Signed-off-by: Dan Kenigsberg <danken(a)redhat.com>
---
M lib/vdsm/v2v.py
M tests/Makefile.am
M tests/v2v_test.py
M tests/v2v_testlib.py
4 files changed, 27 insertions(+), 28 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/14/78414/1
diff --git a/lib/vdsm/v2v.py b/lib/vdsm/v2v.py
index eedcf6d..9d98886 100644
--- a/lib/vdsm/v2v.py
+++ b/lib/vdsm/v2v.py
@@ -74,7 +74,7 @@
_XEN_SSH_PROTOCOL = 'xen+ssh'
_VMWARE_PROTOCOL = 'vpx'
_KVM_PROTOCOL = 'qemu'
-_SSH_AUTH_RE = '(SSH_AUTH_SOCK)=([^;]+).*;\nSSH_AGENT_PID=(\d+)'
+_SSH_AUTH_RE = b'(SSH_AUTH_SOCK)=([^;]+).*;\nSSH_AGENT_PID=(\d+)'
_OVF_RESOURCE_CPU = 3
_OVF_RESOURCE_MEMORY = 4
_OVF_RESOURCE_NETWORK = 10
@@ -525,9 +525,9 @@
fd = os.open(self._passwd_file, os.O_WRONLY | os.O_CREAT, 0o600)
try:
if self._password.value is None:
- os.write(fd, "")
+ os.write(fd, b"")
else:
- os.write(fd, self._password.value)
+ os.write(fd, self._password.value.encode())
finally:
os.close(fd)
try:
@@ -940,12 +940,12 @@
class OutputParser(object):
- COPY_DISK_RE = re.compile(r'.*(Copying disk (\d+)/(\d+)).*')
- DISK_PROGRESS_RE = re.compile(r'\s+\((\d+).*')
+ COPY_DISK_RE = re.compile(br'.*(Copying disk (\d+)/(\d+)).*')
+ DISK_PROGRESS_RE = re.compile(br'\s+\((\d+).*')
def parse(self, stream):
for line in stream:
- if 'Copying disk' in line:
+ if b'Copying disk' in line:
description, current_disk, disk_count = self._parse_line(line)
yield ImportProgress(int(current_disk), int(disk_count),
description)
@@ -964,15 +964,15 @@
return m.group(1), m.group(2), m.group(3)
def _iter_progress(self, stream):
- chunk = ''
+ chunk = b''
while True:
c = stream.read(1)
if not c:
raise OutputParserError('copy-disk stream closed unexpectedly')
chunk += c
- if c == '\r':
+ if c == b'\r':
yield chunk
- chunk = ''
+ chunk = b''
def _parse_progress(self, chunk):
m = self.DISK_PROGRESS_RE.match(chunk)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7fe8571..edb9975 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -242,7 +242,6 @@
storage_workarounds_test.py \
unicode_test.py \
utils_test.py \
- v2v_test.py \
vmapi_test.py \
vmmigration_test.py \
vmoperations_test.py \
diff --git a/tests/v2v_test.py b/tests/v2v_test.py
index 2d44945..5f438de 100644
--- a/tests/v2v_test.py
+++ b/tests/v2v_test.py
@@ -18,7 +18,7 @@
#
from contextlib import contextmanager
-from io import StringIO
+import io
import subprocess
import tarfile
import uuid
@@ -41,7 +41,7 @@
from testlib import VdsmTestCase as TestCaseBase, recorded
from monkeypatch import MonkeyPatch, MonkeyPatchScope
-import vmfakelib as fake
+import vmfakecon as fake
FAKE_VIRT_V2V = CommandPath('fake-virt-v2v',
@@ -85,7 +85,7 @@
def read_ovf(ovf_path):
- return """<?xml version="1.0"
encoding="UTF-8"?>
+ return u"""<?xml version="1.0"
encoding="UTF-8"?>
<Envelope
xmlns="http://schemas.dmtf.org/ovf/envelope/1"
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Re\
@@ -129,7 +129,7 @@
ovapath = os.path.join(base, 'testvm.ova')
ovf = read_ovf('test')
- with open(ovfpath, 'w') as ovffile:
+ with io.open(ovfpath, 'w') as ovffile:
ovffile.write(ovf)
yield ovapath
@@ -319,7 +319,7 @@
u'[ 256.0] Finishing off')
parser = v2v.OutputParser()
- events = list(parser.parse(StringIO(output)))
+ events = list(parser.parse(io.StringIO(output)))
self.assertEqual(events, [
(v2v.ImportProgress(1, 2, 'Copying disk 1/2')),
(v2v.DiskProgress(0)),
@@ -458,10 +458,10 @@
rc, output, error = execCmd(cmd, raw=True)
self.assertEqual(rc, 0)
- with open('fake-virt-v2v.out', 'r') as f:
+ with io.open('fake-virt-v2v.out', 'rb') as f:
self.assertEqual(output, f.read())
- with open('fake-virt-v2v.err', 'r') as f:
+ with io.open('fake-virt-v2v.err', 'rb') as f:
self.assertEqual(error, f.read())
@MonkeyPatch(v2v, '_VIRT_V2V', FAKE_VIRT_V2V)
@@ -486,25 +486,25 @@
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
msg = "test\ntest"
- p.stdin.write(msg)
+ p.stdin.write(msg.encode())
p.stdin.close()
p.wait()
out = p.stdout.read()
- self.assertEqual(out, msg)
+ self.assertEqual(out, msg.encode())
p = v2v._simple_exec_cmd(['/bin/sh', '-c', 'echo -en
"%s" >&2' % msg],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
p.wait()
out = p.stdout.read()
- self.assertEqual(out, msg)
+ self.assertEqual(out, msg.encode())
@MonkeyPatch(v2v, '_VIRT_V2V', FAKE_VIRT_V2V)
def testV2VCapabilities(self):
cmd = v2v.V2VCommand({}, None, None)
- self.assertIn('virt-v2v', cmd._v2v_caps)
- self.assertIn('input:libvirt', cmd._v2v_caps)
- self.assertIn('output:vdsm', cmd._v2v_caps)
+ self.assertIn(b'virt-v2v', cmd._v2v_caps)
+ self.assertIn(b'input:libvirt', cmd._v2v_caps)
+ self.assertIn(b'output:vdsm', cmd._v2v_caps)
@MonkeyPatch(v2v, '_VIRT_V2V', FAKE_VIRT_V2V)
def testQcow2Compat(self):
@@ -514,7 +514,7 @@
# Make sure vdsm-compat capability is supported
cmd = v2v.V2VCommand({}, None, None)
- self.assertIn('vdsm-compat-option', cmd._v2v_caps)
+ self.assertIn(b'vdsm-compat-option', cmd._v2v_caps)
# Look for the command line argument
cmd = v2v.V2VCommand({'qcow2_compat': '1.1'}, None, None)
@@ -544,7 +544,7 @@
self.assertEqual(ret, True)
out = p.stdout.read()
- self.assertEqual(out, msg)
+ self.assertEqual(out, msg.encode())
@permutations([
# (cmd1, cmd2, returncode)
@@ -647,7 +647,7 @@
ovapath = os.path.join(base, 'testvm.ova')
ovf = read_ovf('test')
- with open(ovfpath, 'w') as ovffile:
+ with io.open(ovfpath, 'w') as ovffile:
ovffile.write(ovf)
yield base, ovfpath, ovapath
diff --git a/tests/v2v_testlib.py b/tests/v2v_testlib.py
index 0436b9a..579a9d5 100644
--- a/tests/v2v_testlib.py
+++ b/tests/v2v_testlib.py
@@ -22,7 +22,7 @@
import libvirt
import uuid
-import vmfakelib as fake
+import vmfakecon as fake
VmSpec = namedtuple('VmSpec',
['name', 'uuid', 'id', 'active',
'has_snapshots'])
@@ -51,7 +51,7 @@
class FakeVolume(object):
def __init__(self):
- self._bytes = BytesIO('x' * 1024)
+ self._bytes = BytesIO(b'x' * 1024)
def info(self):
# type, capacity, allocation
--
To view, visit
https://gerrit.ovirt.org/78414
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1a7d26d8731ccd1e03687fa6ab772f165cb9f523
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dan Kenigsberg <danken(a)redhat.com>