Commit 893a5bd2 authored by Jérome Perrin's avatar Jérome Perrin

kvm: fix python3 support in test

parent 748db419
...@@ -38,8 +38,8 @@ from six.moves.urllib.parse import parse_qs, urlparse ...@@ -38,8 +38,8 @@ from six.moves.urllib.parse import parse_qs, urlparse
import unittest import unittest
import subprocess import subprocess
import tempfile import tempfile
import SocketServer import six.moves.socketserver as SocketServer
import SimpleHTTPServer from six.moves import SimpleHTTPServer
import multiprocessing import multiprocessing
import time import time
import shutil import shutil
...@@ -604,13 +604,13 @@ class FakeImageServerMixin(object): ...@@ -604,13 +604,13 @@ class FakeImageServerMixin(object):
(self._ipv4_address, findFreeTCPPort(self._ipv4_address)), (self._ipv4_address, findFreeTCPPort(self._ipv4_address)),
FakeImageHandler) FakeImageHandler)
fake_image_content = 'fake_image_content' fake_image_content = b'fake_image_content'
self.fake_image_md5sum = hashlib.md5(fake_image_content).hexdigest() self.fake_image_md5sum = hashlib.md5(fake_image_content).hexdigest()
with open(os.path.join( with open(os.path.join(
self.image_source_directory, self.fake_image_md5sum), 'wb') as fh: self.image_source_directory, self.fake_image_md5sum), 'wb') as fh:
fh.write(fake_image_content) fh.write(fake_image_content)
fake_image2_content = 'fake_image2_content' fake_image2_content = b'fake_image2_content'
self.fake_image2_md5sum = hashlib.md5(fake_image2_content).hexdigest() self.fake_image2_md5sum = hashlib.md5(fake_image2_content).hexdigest()
with open(os.path.join( with open(os.path.join(
self.image_source_directory, self.fake_image2_md5sum), 'wb') as fh: self.image_source_directory, self.fake_image2_md5sum), 'wb') as fh:
...@@ -1187,17 +1187,16 @@ class TestWhitelistFirewall(InstanceTestCase): ...@@ -1187,17 +1187,16 @@ class TestWhitelistFirewall(InstanceTestCase):
'.slapos-whitelist-firewall') '.slapos-whitelist-firewall')
self.assertTrue(os.path.exists(slapos_whitelist_firewall)) self.assertTrue(os.path.exists(slapos_whitelist_firewall))
with open(slapos_whitelist_firewall, 'rb') as fh: with open(slapos_whitelist_firewall, 'rb') as fh:
content = fh.read().encode('utf-8') content = fh.read()
try: try:
self.content_json = json.loads(content) self.content_json = json.loads(content)
except ValueError: except ValueError:
self.fail('Failed to parse json of %s' % (content,)) self.fail('Failed to parse json of %r' % (content,))
self.assertTrue(isinstance(self.content_json, list)) self.assertTrue(isinstance(self.content_json, list))
# check /etc/resolv.conf # check /etc/resolv.conf
with open('/etc/resolv.conf', 'rb') as fh: with open('/etc/resolv.conf', 'r') as f:
resolv_conf_ip_list = [] resolv_conf_ip_list = []
for line in fh.readlines(): for line in f.readlines():
line = line.encode('utf-8')
if line.startswith('nameserver'): if line.startswith('nameserver'):
resolv_conf_ip_list.append(line.split()[1]) resolv_conf_ip_list.append(line.split()[1])
resolv_conf_ip_list = list(set(resolv_conf_ip_list)) resolv_conf_ip_list = list(set(resolv_conf_ip_list))
...@@ -1223,6 +1222,7 @@ class TestWhitelistFirewallRequest(TestWhitelistFirewall): ...@@ -1223,6 +1222,7 @@ class TestWhitelistFirewallRequest(TestWhitelistFirewall):
self.assertIn('4.4.4.4', self.content_json) self.assertIn('4.4.4.4', self.content_json)
@skipIfPython3
@skipUnlessKvm @skipUnlessKvm
class TestWhitelistFirewallResilient(TestWhitelistFirewall): class TestWhitelistFirewallResilient(TestWhitelistFirewall):
kvm_instance_partition_reference = 'wf2' kvm_instance_partition_reference = 'wf2'
...@@ -1232,6 +1232,7 @@ class TestWhitelistFirewallResilient(TestWhitelistFirewall): ...@@ -1232,6 +1232,7 @@ class TestWhitelistFirewallResilient(TestWhitelistFirewall):
return 'kvm-resilient' return 'kvm-resilient'
@skipIfPython3
@skipUnlessKvm @skipUnlessKvm
class TestWhitelistFirewallRequestResilient(TestWhitelistFirewallRequest): class TestWhitelistFirewallRequestResilient(TestWhitelistFirewallRequest):
kvm_instance_partition_reference = 'wf2' kvm_instance_partition_reference = 'wf2'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment