Commit 4b4f65ae authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼

[slapos.core] improve format

See merge request nexedi/slapos.core!365
parents acfb7b53 a8917a3c
Changes Changes
======= =======
1.7.4 (unreleased)
------------------
* format: remove use_unique_local_address_block option as it was never really used. User can add a local IPv6 range on the interface before running "slapos node format".
1.7.3 (2022-02-17) 1.7.3 (2022-02-17)
------------------ ------------------
* runpromises: support software releases older than slapos 1.0.118 * runpromises: support software releases older than slapos 1.0.118
......
...@@ -32,8 +32,6 @@ tap_ipv6 = true ...@@ -32,8 +32,6 @@ tap_ipv6 = true
# You can choose any other local network which does not conflict with your # You can choose any other local network which does not conflict with your
# current machine configuration # current machine configuration
ipv4_local_network = 10.0.0.0/16 ipv4_local_network = 10.0.0.0/16
# Change to true if you want slapos to use local-only IPv6
use_unique_local_address = False
# to enable, change to [firewall] # to enable, change to [firewall]
[disabled-firewall] [disabled-firewall]
......
...@@ -140,8 +140,7 @@ def _generateSlaposNodeConfigurationFile(slapos_node_config_path, args): ...@@ -140,8 +140,7 @@ def _generateSlaposNodeConfigurationFile(slapos_node_config_path, args):
('instance_root', args.slapos_instance_root), ('instance_root', args.slapos_instance_root),
('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_block', 'false')
] ]
slapos_node_configuration_content = _replaceParameterValue( slapos_node_configuration_content = _replaceParameterValue(
......
...@@ -506,15 +506,6 @@ class Computer(object): ...@@ -506,15 +506,6 @@ class Computer(object):
except ValueError: except ValueError:
pass pass
def _addUniqueLocalAddressIpv6(self, interface_name):
"""
Create a unique local address in the interface interface_name, so that
slapformat can build upon this.
See https://en.wikipedia.org/wiki/Unique_local_address.
"""
command = 'ip address add dev %s fd00::1/64' % interface_name
callAndRead(command.split())
@property @property
def software_gid(self): def software_gid(self):
"""Return GID for self.software_user. """Return GID for self.software_user.
...@@ -523,7 +514,7 @@ class Computer(object): ...@@ -523,7 +514,7 @@ class Computer(object):
effectively create the user and group.""" effectively create the user and group."""
return pwd.getpwnam(self.software_user)[3] return pwd.getpwnam(self.software_user)[3]
def format(self, alter_user=True, alter_network=True, create_tap=True, use_unique_local_address_block=False): def format(self, alter_user=True, alter_network=True, create_tap=True):
""" """
Setup underlaying OS so it reflects this instance (``self``). Setup underlaying OS so it reflects this instance (``self``).
...@@ -569,22 +560,12 @@ class Computer(object): ...@@ -569,22 +560,12 @@ class Computer(object):
if self.address is not None: if self.address is not None:
self.interface.addIPv6Address(self.address, self.netmask) self.interface.addIPv6Address(self.address, self.netmask)
if use_unique_local_address_block: if create_tap and self.tap_gateway_interface:
self._addUniqueLocalAddressIpv6(self.ipv6_interface or self.interface.name) gateway_addr_dict = getIfaceAddressIPv4(self.tap_gateway_interface)
tap_address_list = getIPv4SubnetAddressRange(gateway_addr_dict['addr'],
if create_tap: gateway_addr_dict['netmask'],
if self.tap_gateway_interface: len(self.partition_list))
gateway_addr_dict = getIfaceAddressIPv4(self.tap_gateway_interface) assert(len(self.partition_list) <= len(tap_address_list))
tap_address_list = getIPv4SubnetAddressRange(gateway_addr_dict['addr'],
gateway_addr_dict['netmask'],
len(self.partition_list))
assert(len(self.partition_list) <= len(tap_address_list))
else:
gateway_addr_dict = {'peer': '10.0.0.1', 'netmask': '255.255.0.0',
'addr': '10.0.0.1', 'network': '10.0.0.0'}
tap_address_list = getIPv4SubnetAddressRange(gateway_addr_dict['addr'],
gateway_addr_dict['netmask'],
len(self.partition_list))
self._speedHackAddAllOldIpsToInterface() self._speedHackAddAllOldIpsToInterface()
...@@ -609,16 +590,22 @@ class Computer(object): ...@@ -609,16 +590,22 @@ class Computer(object):
if create_tap: if create_tap:
partition.tap.createWithOwner(owner) partition.tap.createWithOwner(owner)
# add addresses and create route for this tap if self.tap_gateway_interface:
# Pop IP from tap_address_list and attach to tap if has no ipv4 yet # add addresses and create route for this tap
next_ipv4_addr = '%s' % tap_address_list.pop(0) # Pop IP from tap_address_list and attach to tap if has no ipv4 yet
# skip to set this IP to tap if already exits next_ipv4_addr = '%s' % tap_address_list.pop(0)
if not partition.tap.ipv4_addr: # skip to set this IP to tap if already exits
# define new ipv4 address for this tap if not partition.tap.ipv4_addr:
partition.tap.ipv4_addr = next_ipv4_addr # define new ipv4 address for this tap
partition.tap.ipv4_netmask = gateway_addr_dict['netmask'] partition.tap.ipv4_addr = next_ipv4_addr
partition.tap.ipv4_gateway = gateway_addr_dict['addr'] partition.tap.ipv4_netmask = gateway_addr_dict['netmask']
partition.tap.ipv4_network = gateway_addr_dict['network'] partition.tap.ipv4_gateway = gateway_addr_dict['addr']
partition.tap.ipv4_network = gateway_addr_dict['network']
else:
partition.tap.ipv4_addr = ''
partition.tap.ipv4_netmask = ''
partition.tap.ipv4_gateway = ''
partition.tap.ipv4_network = ''
if self.tap_ipv6: if self.tap_ipv6:
if not partition.tap.ipv6_addr: if not partition.tap.ipv6_addr:
...@@ -1409,8 +1396,7 @@ def do_format(conf): ...@@ -1409,8 +1396,7 @@ def do_format(conf):
computer.format(alter_user=conf.alter_user, computer.format(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)
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)
...@@ -1442,7 +1428,6 @@ class FormatConfig(object): ...@@ -1442,7 +1428,6 @@ class FormatConfig(object):
tap_ipv6 = True tap_ipv6 = True
tap_gateway_interface = '' tap_gateway_interface = ''
ipv4_local_network = None ipv4_local_network = None
use_unique_local_address_block = False
# User options # User options
alter_user = 'True' # modifiable by cmdline alter_user = 'True' # modifiable by cmdline
...@@ -1501,7 +1486,7 @@ class FormatConfig(object): ...@@ -1501,7 +1486,7 @@ class FormatConfig(object):
raise UsageError(message) raise UsageError(message)
# Convert strings to booleans # Convert strings to booleans
for option in ['alter_network', 'alter_user', 'create_tap', 'create_tun', 'use_unique_local_address_block', 'tap_ipv6']: for option in ['alter_network', 'alter_user', 'create_tap', 'create_tun', 'tap_ipv6']:
attr = getattr(self, option) attr = getattr(self, option)
if isinstance(attr, str): if isinstance(attr, str):
if attr.lower() == 'true': if attr.lower() == 'true':
......
...@@ -646,46 +646,6 @@ class TestComputer(SlapformatMixin): ...@@ -646,46 +646,6 @@ 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',
instance_root='/instance_root',
software_root='/software_root',
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 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(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 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 TestFormatDump(SlapformatMixin): class TestFormatDump(SlapformatMixin):
def setUp(self): def setUp(self):
......
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