Commit 61386852 authored by Xavier Thompson's avatar Xavier Thompson

slapformat: Fix python3 bytes/str mismatch in dump

parent 783894a7
Pipeline #15286 failed with stage
in 0 seconds
...@@ -364,8 +364,8 @@ class Computer(object): ...@@ -364,8 +364,8 @@ class Computer(object):
computer_dict = _getDict(self) computer_dict = _getDict(self)
if path_to_json: if path_to_json:
with open(path_to_json, 'wb') as fout: with open(path_to_json, 'w') as fout:
fout.write(json.dumps(computer_dict, sort_keys=True, indent=2)) json.dump(computer_dict, fout, sort_keys=True, indent=2)
new_xml = dumps(computer_dict) new_xml = dumps(computer_dict)
new_pretty_xml = prettify_xml(new_xml) new_pretty_xml = prettify_xml(new_xml)
...@@ -767,7 +767,7 @@ class Partition(object): ...@@ -767,7 +767,7 @@ class Partition(object):
# dumped resources didn't change # dumped resources didn't change
return return
with open(file_path, "wb") as fo: with open(file_path, "w") as fo:
fo.write(content) fo.write(content)
owner_pw = pwd.getpwnam(self.user.name) owner_pw = pwd.getpwnam(self.user.name)
os.chmod(file_path, 0o644) os.chmod(file_path, 0o644)
......
...@@ -30,6 +30,9 @@ from __future__ import print_function ...@@ -30,6 +30,9 @@ from __future__ import print_function
import glob import glob
import logging import logging
import os
import shutil
import tempfile
import slapos.format import slapos.format
import slapos.util import slapos.util
import slapos.manager.cpuset import slapos.manager.cpuset
...@@ -684,6 +687,48 @@ class TestComputer(SlapformatMixin): ...@@ -684,6 +687,48 @@ class TestComputer(SlapformatMixin):
self.fakeCallAndRead.external_command_list) self.fakeCallAndRead.external_command_list)
class TestFormatDump(SlapformatMixin):
def setUp(self):
super(TestFormatDump, self).setUp()
self.restoreOs()
self._tempdir = tempfile.mkdtemp()
def test(self):
computer = slapos.format.Computer('computer',
instance_root=os.path.join(self._tempdir, 'instance_root'),
software_root=os.path.join(self._tempdir, 'software_root'),
tap_ipv6=True,
interface=slapos.format.Interface(
logger=self.logger, name='myinterface', ipv4_local_network='127.0.0.1/16'),
partition_list=[
slapos.format.Partition(
'partition', 'part_path', slapos.format.User('testuser'), [], tap=slapos.format.Tap('tap')),
])
global USER_LIST
USER_LIST = ['testuser']
global INTERFACE_DICT
INTERFACE_DICT['myinterface'] = {
socket.AF_INET: [{'addr': '192.168.242.77', 'broadcast': '127.0.0.1',
'netmask': '255.255.255.0'}],
socket.AF_INET6: [{'addr': '2a01:e35:2e27::e59c', 'netmask': 'ffff:ffff:ffff:ffff::'}]
}
computer.format(alter_user=False, alter_network=False, create_tap=False)
partition_path = os.path.join(self._tempdir, 'instance_root', 'partition')
self.assertTrue(os.path.exists(partition_path))
self.assertFalse(os.listdir(partition_path))
xml_path = os.path.join(self._tempdir, 'slapos.xml')
json_path = os.path.join(self._tempdir, 'slapos.json')
computer.dump(xml_path, json_path, self.logger)
self.assertEqual(os.listdir(partition_path), ['.slapos-resource'])
def tearDown(self):
shutil.rmtree(self._tempdir, True)
super(TestFormatDump, self).tearDown()
class SlapGridPartitionMock: class SlapGridPartitionMock:
def __init__(self, partition): def __init__(self, partition):
......
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