Commit c09214cb authored by Cédric de Saint Martin's avatar Cédric de Saint Martin Committed by Rafael Monnerat

slapos format: fix use_unique_local_address_block feature, and put default to...

slapos format: fix use_unique_local_address_block feature, and put default to false in configure_local.
parent f641dfaf
Changes Changes
======= =======
1.2.4.2 (unreleased)
--------------------
* slapos format: fix use_unique_local_address_block feature, and put default to false in configure_local.
1.2.4.1 (2014-10-09) 1.2.4.1 (2014-10-09)
-------------------- --------------------
......
...@@ -140,7 +140,7 @@ def _generateSlaposNodeConfigurationFile(slapos_node_config_path, args): ...@@ -140,7 +140,7 @@ def _generateSlaposNodeConfigurationFile(slapos_node_config_path, args):
('software_root', args.slapos_software_root), ('software_root', args.slapos_software_root),
('computer_xml', '%s/slapos.xml' % slapos_home), ('computer_xml', '%s/slapos.xml' % slapos_home),
('log_file', '%s/log/slapos-node-format.log' % slapos_home), ('log_file', '%s/log/slapos-node-format.log' % slapos_home),
('use_unique_local_address', 'true') ('use_unique_local_address_block', 'false')
] ]
slapos_node_configuration_content = _replaceParameterValue( slapos_node_configuration_content = _replaceParameterValue(
......
...@@ -52,7 +52,7 @@ import zipfile ...@@ -52,7 +52,7 @@ import zipfile
import lxml.etree import lxml.etree
import xml_marshaller.xml_marshaller import xml_marshaller.xml_marshaller
from slapos.util import chownDirectory import slapos.util
from slapos.util import mkdir_p from slapos.util import mkdir_p
import slapos.slap as slap import slapos.slap as slap
...@@ -400,20 +400,20 @@ class Computer(object): ...@@ -400,20 +400,20 @@ class Computer(object):
See https://en.wikipedia.org/wiki/Unique_local_address. See https://en.wikipedia.org/wiki/Unique_local_address.
""" """
command = 'ip address add dev %s fd00::1/64' % interface_name command = 'ip address add dev %s fd00::1/64' % interface_name
subprocess.Popen(command.split()).communicate() callAndRead(command.split())
def construct(self, alter_user=True, alter_network=True, create_tap=True, unique_local_address=False): def construct(self, alter_user=True, alter_network=True, create_tap=True, use_unique_local_address_block=False):
""" """
Construct the computer object as it is. Construct the computer object as it is.
""" """
if alter_network and self.address is not None: if alter_network and self.address is not None:
self.interface.addAddr(self.address, self.netmask) self.interface.addAddr(self.address, self.netmask)
if unique_local_address and alter_network: if use_unique_local_address_block and alter_network:
if self.ipv6_interface: if self.ipv6_interface:
network_interface_name = self.ipv6_interface network_interface_name = self.ipv6_interface
else: else:
network_interface_name = self.name network_interface_name = self.interface.name
self._addUniqueLocalAddressIpv6(network_interface_name) self._addUniqueLocalAddressIpv6(network_interface_name)
for path in self.instance_root, self.software_root: for path in self.instance_root, self.software_root:
...@@ -428,7 +428,7 @@ class Computer(object): ...@@ -428,7 +428,7 @@ class Computer(object):
if alter_user: if alter_user:
slapsoft.create() slapsoft.create()
slapsoft_pw = pwd.getpwnam(slapsoft.name) slapsoft_pw = pwd.getpwnam(slapsoft.name)
chownDirectory(slapsoft.path, slapsoft_pw.pw_uid, slapsoft_pw.pw_gid) slapos.util.chownDirectory(slapsoft.path, slapsoft_pw.pw_uid, slapsoft_pw.pw_gid)
os.chmod(self.software_root, 0o755) os.chmod(self.software_root, 0o755)
if alter_network: if alter_network:
...@@ -1106,7 +1106,7 @@ def do_format(conf): ...@@ -1106,7 +1106,7 @@ def do_format(conf):
computer.construct(alter_user=conf.alter_user, computer.construct(alter_user=conf.alter_user,
alter_network=conf.alter_network, alter_network=conf.alter_network,
create_tap=conf.create_tap, create_tap=conf.create_tap,
unique_local_address=conf.use_unique_local_address_block) use_unique_local_address_block=conf.use_unique_local_address_block)
if getattr(conf, 'certificate_repository_path', None): if getattr(conf, 'certificate_repository_path', None):
mkdir_p(conf.certificate_repository_path, mode=0o700) mkdir_p(conf.certificate_repository_path, mode=0o700)
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
import logging import logging
import slapos.format import slapos.format
import slapos.util
import unittest import unittest
import netaddr import netaddr
...@@ -67,8 +68,12 @@ class FakeCallAndRead: ...@@ -67,8 +68,12 @@ class FakeCallAndRead:
retval = 0, 'UP' retval = 0, 'UP'
global INTERFACE_DICT global INTERFACE_DICT
if 'useradd' in argument_list: if 'useradd' in argument_list:
print argument_list
global USER_LIST global USER_LIST
USER_LIST.append(argument_list[-1]) username = argument_list[-1]
if username == '-r':
username = argument_list[-2]
USER_LIST.append(username)
elif 'groupadd' in argument_list: elif 'groupadd' in argument_list:
global GROUP_LIST global GROUP_LIST
GROUP_LIST.append(argument_list[-1]) GROUP_LIST.append(argument_list[-1])
...@@ -144,6 +149,10 @@ class NetifacesMock: ...@@ -144,6 +149,10 @@ class NetifacesMock:
global INTERFACE_DICT global INTERFACE_DICT
return INTERFACE_DICT.keys() return INTERFACE_DICT.keys()
class SlaposUtilMock:
@classmethod
def chownDirectory(*args, **kw):
pass
class SlapformatMixin(unittest.TestCase): class SlapformatMixin(unittest.TestCase):
# keep big diffs # keep big diffs
...@@ -206,6 +215,17 @@ class SlapformatMixin(unittest.TestCase): ...@@ -206,6 +215,17 @@ class SlapformatMixin(unittest.TestCase):
setattr(os, name, original_value) setattr(os, name, original_value)
del self.saved_os del self.saved_os
def patchSlaposUtil(self):
self.saved_slapos_util = {}
for fake in ['chownDirectory']:
self.saved_slapos_util[fake] = getattr(slapos.util, fake, None)
setattr(slapos.util, fake, getattr(SlaposUtilMock, fake))
def restoreSlaposUtil(self):
for name, original_value in self.saved_slapos_util.items():
setattr(slapos.util, name, original_value)
del self.saved_slapos_util
def setUp(self): def setUp(self):
config = FakeConfig() config = FakeConfig()
config.dry_run = True config.dry_run = True
...@@ -232,6 +252,7 @@ class SlapformatMixin(unittest.TestCase): ...@@ -232,6 +252,7 @@ class SlapformatMixin(unittest.TestCase):
self.patchTime() self.patchTime()
self.patchPwd() self.patchPwd()
self.patchNetifaces() self.patchNetifaces()
self.patchSlaposUtil()
def tearDown(self): def tearDown(self):
self.restoreOs() self.restoreOs()
...@@ -239,6 +260,7 @@ class SlapformatMixin(unittest.TestCase): ...@@ -239,6 +260,7 @@ class SlapformatMixin(unittest.TestCase):
self.restoreTime() self.restoreTime()
self.restorePwd() self.restorePwd()
self.restoreNetifaces() self.restoreNetifaces()
self.restoreSlaposUtil()
slapos.format.callAndRead = self.real_callAndRead slapos.format.callAndRead = self.real_callAndRead
...@@ -498,6 +520,46 @@ class TestComputer(SlapformatMixin): ...@@ -498,6 +520,46 @@ class TestComputer(SlapformatMixin):
], ],
self.fakeCallAndRead.external_command_list) self.fakeCallAndRead.external_command_list)
def test_construct_use_unique_local_address_block(self):
"""
Test that slapformat creates a unique local address in the interface.
"""
global USER_LIST
USER_LIST = ['root']
computer = slapos.format.Computer('computer',
interface=slapos.format.Interface(logger=self.test_result,
name='myinterface',
ipv4_local_network='127.0.0.1/16'))
computer.instance_root = '/instance_root'
computer.software_root = '/software_root'
partition = slapos.format.Partition('partition', '/part_path',
slapos.format.User('testuser'), [], None)
partition.tap = slapos.format.Tap('tap')
computer.partition_list = [partition]
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.construct(use_unique_local_address_block=True, alter_user=False, create_tap=False)
self.assertEqual([
"makedirs('/instance_root', 493)",
"makedirs('/software_root', 493)",
"chmod('/software_root', 493)",
"mkdir('/instance_root/partition', 488)",
"chmod('/instance_root/partition', 488)"
],
self.test_result.bucket)
self.assertEqual([
'ip addr list myinterface',
'ip address add dev myinterface fd00::1/64',
'ip addr add ip/255.255.255.255 dev myinterface',
'ip addr add ip/ffff:ffff:ffff:ffff:: dev myinterface',
'ip -6 addr list myinterface'
],
self.fakeCallAndRead.external_command_list)
class TestPartition(SlapformatMixin): class TestPartition(SlapformatMixin):
......
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