Commit ef4551b8 authored by Alain Takoudjou's avatar Alain Takoudjou

Merge branch 'tap-nobridge' to master

Conflicts:
	master/bt5/slapos_pdm/SkinTemplateItem/portal_skins/slapos_pdm/SoftwareProduct_getSortedSoftwareReleaseList.xml
parents 28753466 eb76d6cc
...@@ -65,6 +65,10 @@ ...@@ -65,6 +65,10 @@
if current_dict in to_add_ip_dict_list:\n if current_dict in to_add_ip_dict_list:\n
to_add_ip_dict_list.remove(current_dict)\n to_add_ip_dict_list.remove(current_dict)\n
else:\n else:\n
# XXX - Only delete if Network interface are supposed to be the same\n
if additional_dict.has_key(\'network_interface\'):\n
if address.getNetworkInterface(\'\') and additional_dict[\'network_interface\'] != address.getNetworkInterface():\n
continue\n
to_delete_ip_id_list.append(address.getId())\n to_delete_ip_id_list.append(address.getId())\n
\n \n
for address in to_add_ip_dict_list:\n for address in to_add_ip_dict_list:\n
...@@ -114,6 +118,16 @@ for send_partition in computer_dict[\'partition_list\']:\n ...@@ -114,6 +118,16 @@ for send_partition in computer_dict[\'partition_list\']:\n
partition.edit(reference=send_partition[\'reference\'])\n partition.edit(reference=send_partition[\'reference\'])\n
network_interface = send_partition[\'tap\'][\'name\']\n network_interface = send_partition[\'tap\'][\'name\']\n
compareAndUpdateAddressList(partition, send_partition[\'address_list\'], {\'network_interface\': network_interface})\n compareAndUpdateAddressList(partition, send_partition[\'address_list\'], {\'network_interface\': network_interface})\n
tap_addr_list = []\n
additional_dict = {\'network_interface\': \'route_\' + network_interface}\n
if send_partition[\'tap\'].has_key(\'ipv4_addr\') and send_partition[\'tap\'][\'ipv4_addr\']:\n
tap_addr_list.append({\n
\'addr\': send_partition[\'tap\'][\'ipv4_addr\'],\n
\'netmask\': send_partition[\'tap\'][\'ipv4_netmask\']\n
})\n
additional_dict[\'gateway_ip_address\'] = send_partition[\'tap\'][\'ipv4_gateway\']\n
additional_dict[\'network_address\'] = send_partition[\'tap\'][\'ipv4_network\']\n
compareAndUpdateAddressList(partition, tap_addr_list, additional_dict)\n
\n \n
# Desactivate all other partitions\n # Desactivate all other partitions\n
for key, value in existing_partition_dict.items():\n for key, value in existing_partition_dict.items():\n
......
...@@ -6,10 +6,22 @@ ...@@ -6,10 +6,22 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>testSlapOSSlapToolComputerUpdateFromDict</string> </value> <value> <string>testSlapOSSlapToolComputerUpdateFromDict</string> </value>
</item> </item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>test.erp5.testSlapOSSlapToolComputerUpdateFromDict</string> </value> <value> <string>test.erp5.testSlapOSSlapToolComputerUpdateFromDict</string> </value>
...@@ -34,10 +46,11 @@ ...@@ -34,10 +46,11 @@
<key> <string>text_content_warning_message</string> </key> <key> <string>text_content_warning_message</string> </key>
<value> <value>
<tuple> <tuple>
<string>W:274, 4: Unused variable \'default_address\' (unused-variable)</string> <string>W:423, 4: Unused variable \'other_address2\' (unused-variable)</string>
<string>W:270, 4: Unused variable \'other_address\' (unused-variable)</string> <string>W:560, 4: Unused variable \'default_address\' (unused-variable)</string>
<string>W:315, 4: Unused variable \'default_address\' (unused-variable)</string> <string>W:556, 4: Unused variable \'other_address\' (unused-variable)</string>
<string>W:311, 4: Unused variable \'other_address\' (unused-variable)</string> <string>W:601, 4: Unused variable \'default_address\' (unused-variable)</string>
<string>W:597, 4: Unused variable \'other_address\' (unused-variable)</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -48,13 +61,28 @@ ...@@ -48,13 +61,28 @@
<item> <item>
<key> <string>workflow_history</string> </key> <key> <string>workflow_history</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="2" aka="AAAAAAAAAAI="> <record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="PersistentMapping" module="Persistence.mapping"/> <global name="PersistentMapping" module="Persistence.mapping"/>
</pickle> </pickle>
...@@ -67,7 +95,7 @@ ...@@ -67,7 +95,7 @@
<item> <item>
<key> <string>component_validation_workflow</string> </key> <key> <string>component_validation_workflow</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
...@@ -76,7 +104,7 @@ ...@@ -76,7 +104,7 @@
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="3" aka="AAAAAAAAAAM="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle> </pickle>
......
...@@ -1429,9 +1429,17 @@ class SlapTool(BaseTool): ...@@ -1429,9 +1429,17 @@ class SlapTool(BaseTool):
ip_list = [] ip_list = []
for internet_protocol_address in computer_partition.contentValues(portal_type='Internet Protocol Address'): for internet_protocol_address in computer_partition.contentValues(portal_type='Internet Protocol Address'):
ip_list.append(( # XXX - There is new values, and we must keep compatibility
address_tuple = (
internet_protocol_address.getNetworkInterface('').decode("UTF-8"), internet_protocol_address.getNetworkInterface('').decode("UTF-8"),
internet_protocol_address.getIpAddress().decode("UTF-8"))) internet_protocol_address.getIpAddress().decode("UTF-8"))
if internet_protocol_address.getGatewayIpAddress('') and \
internet_protocol_address.getNetmask(''):
address_tuple = address_tuple + (
internet_protocol_address.getGatewayIpAddress().decode("UTF-8"),
internet_protocol_address.getNetmask().decode("UTF-8"),
internet_protocol_address.getNetworkAddress('').decode("UTF-8"))
ip_list.append(address_tuple)
slave_instance_list = [] slave_instance_list = []
if (software_instance.getPortalType() == "Software Instance"): if (software_instance.getPortalType() == "Software Instance"):
......
This diff is collapsed.
...@@ -57,6 +57,8 @@ WATCHDOG_MARK = '-on-watch' ...@@ -57,6 +57,8 @@ WATCHDOG_MARK = '-on-watch'
REQUIRED_COMPUTER_PARTITION_PERMISSION = 0o750 REQUIRED_COMPUTER_PARTITION_PERMISSION = 0o750
CP_STORAGE_FOLDER_NAME = 'DATA'
# XXX not very clean. this is changed when testing # XXX not very clean. this is changed when testing
PROGRAM_PARTITION_TEMPLATE = pkg_resources.resource_stream(__name__, PROGRAM_PARTITION_TEMPLATE = pkg_resources.resource_stream(__name__,
'templates/program_partition_supervisord.conf.in').read() 'templates/program_partition_supervisord.conf.in').read()
...@@ -341,7 +343,8 @@ class Partition(object): ...@@ -341,7 +343,8 @@ class Partition(object):
logger, logger,
certificate_repository_path=None, certificate_repository_path=None,
retention_delay='0', retention_delay='0',
instance_min_free_space=None instance_min_free_space=None,
instance_storage_home=''
): ):
"""Initialisation of class parameters""" """Initialisation of class parameters"""
self.buildout = buildout self.buildout = buildout
...@@ -358,6 +361,7 @@ class Partition(object): ...@@ -358,6 +361,7 @@ class Partition(object):
self.partition_id = partition_id self.partition_id = partition_id
self.server_url = server_url self.server_url = server_url
self.software_release_url = software_release_url self.software_release_url = software_release_url
self.instance_storage_home = instance_storage_home
self.key_file = '' self.key_file = ''
self.cert_file = '' self.cert_file = ''
...@@ -512,6 +516,7 @@ class Partition(object): ...@@ -512,6 +516,7 @@ class Partition(object):
'software_release_url': self.software_release_url, 'software_release_url': self.software_release_url,
'key_file': self.key_file, 'key_file': self.key_file,
'cert_file': self.cert_file, 'cert_file': self.cert_file,
'storage_home': self.instance_storage_home,
} }
open(config_location, 'w').write(buildout_text) open(config_location, 'w').write(buildout_text)
os.chmod(config_location, 0o640) os.chmod(config_location, 0o640)
...@@ -684,12 +689,22 @@ class Partition(object): ...@@ -684,12 +689,22 @@ class Partition(object):
sr_symlink = os.path.join(self.instance_path, 'software_release') sr_symlink = os.path.join(self.instance_path, 'software_release')
if os.path.islink(sr_symlink): if os.path.islink(sr_symlink):
os.unlink(sr_symlink) os.unlink(sr_symlink)
data_base_link = os.path.join(self.instance_path, CP_STORAGE_FOLDER_NAME)
if self.instance_storage_home and os.path.exists(data_base_link) and \
os.path.isdir(data_base_link):
for filename in os.listdir(data_base_link):
data_symlink = os.path.join(data_base_link, filename)
partition_data_path = os.path.join(self.instance_storage_home,
filename, self.partition_id)
if os.path.lexists(data_symlink):
os.unlink(data_symlink)
if os.path.exists(partition_data_path):
self.cleanupFolder(partition_data_path)
self.cleanupFolder(self.instance_path)
# Cleanup all Data storage location of this partition
for root, dirs, file_list in os.walk(self.instance_path):
for directory in dirs:
shutil.rmtree(os.path.join(self.instance_path, directory))
for file in file_list:
os.remove(os.path.join(self.instance_path, file))
if os.path.exists(self.supervisord_partition_configuration_path): if os.path.exists(self.supervisord_partition_configuration_path):
os.remove(self.supervisord_partition_configuration_path) os.remove(self.supervisord_partition_configuration_path)
...@@ -699,6 +714,15 @@ class Partition(object): ...@@ -699,6 +714,15 @@ class Partition(object):
return True return True
def cleanupFolder(self, folder_path):
"""Delete all files and folders in a specified directory
"""
for root, dirs, file_list in os.walk(folder_path):
for directory in dirs:
shutil.rmtree(os.path.join(folder_path, directory))
for file in file_list:
os.remove(os.path.join(folder_path, file))
def fetchInformations(self): def fetchInformations(self):
"""Fetch usage informations with buildout, returns it. """Fetch usage informations with buildout, returns it.
""" """
......
...@@ -232,7 +232,8 @@ def create_slapgrid_object(options, logger): ...@@ -232,7 +232,8 @@ def create_slapgrid_object(options, logger):
# Try to fetch from deprecated argument # Try to fetch from deprecated argument
computer_partition_filter_list=op.get('only-cp', op.get('only_cp')), computer_partition_filter_list=op.get('only-cp', op.get('only_cp')),
software_min_free_space=software_min_free_space, software_min_free_space=software_min_free_space,
instance_min_free_space=instance_min_free_space) instance_min_free_space=instance_min_free_space,
instance_storage_home=op.get('instance_storage_home'))
def check_required_only_partitions(existing, required): def check_required_only_partitions(existing, required):
...@@ -286,6 +287,7 @@ class Slapgrid(object): ...@@ -286,6 +287,7 @@ class Slapgrid(object):
computer_partition_filter_list=None, computer_partition_filter_list=None,
software_min_free_space=None, software_min_free_space=None,
instance_min_free_space=None, instance_min_free_space=None,
instance_storage_home=None,
): ):
"""Makes easy initialisation of class parameters""" """Makes easy initialisation of class parameters"""
# Parses arguments # Parses arguments
...@@ -337,6 +339,10 @@ class Slapgrid(object): ...@@ -337,6 +339,10 @@ class Slapgrid(object):
self.maximum_periodicity = maximum_periodicity self.maximum_periodicity = maximum_periodicity
self.software_min_free_space = software_min_free_space self.software_min_free_space = software_min_free_space
self.instance_min_free_space = instance_min_free_space self.instance_min_free_space = instance_min_free_space
if instance_storage_home:
self.instance_storage_home = os.path.abspath(instance_storage_home)
else:
self.instance_storage_home = ""
def _getWatchdogLine(self): def _getWatchdogLine(self):
invocation_list = [WATCHDOG_PATH] invocation_list = [WATCHDOG_PATH]
...@@ -644,6 +650,7 @@ class Slapgrid(object): ...@@ -644,6 +650,7 @@ class Slapgrid(object):
logger=self.logger, logger=self.logger,
retention_delay=retention_delay, retention_delay=retention_delay,
instance_min_free_space=self.instance_min_free_space, instance_min_free_space=self.instance_min_free_space,
instance_storage_home=self.instance_storage_home,
) )
computer_partition_state = computer_partition.getState() computer_partition_state = computer_partition.getState()
...@@ -1102,6 +1109,7 @@ class Slapgrid(object): ...@@ -1102,6 +1109,7 @@ class Slapgrid(object):
certificate_repository_path=self.certificate_repository_path, certificate_repository_path=self.certificate_repository_path,
buildout=self.buildout, buildout=self.buildout,
logger=self.logger, logger=self.logger,
instance_storage_home=self.instance_storage_home,
) )
local_partition.stop() local_partition.stop()
try: try:
......
...@@ -22,4 +22,7 @@ server_url = %(server_url)s ...@@ -22,4 +22,7 @@ server_url = %(server_url)s
software_release_url = %(software_release_url)s software_release_url = %(software_release_url)s
key_file = %(key_file)s key_file = %(key_file)s
cert_file = %(cert_file)s cert_file = %(cert_file)s
[storage-configuration]
storage-home = %(storage_home)s
# This is end of zc.builodout profile's tail added by slapgrid # This is end of zc.builodout profile's tail added by slapgrid
...@@ -94,6 +94,10 @@ class FakeCallAndRead: ...@@ -94,6 +94,10 @@ class FakeCallAndRead:
elif argument_list[:3] == ['ip', 'addr', 'list'] or \ elif argument_list[:3] == ['ip', 'addr', 'list'] or \
argument_list[:4] == ['ip', '-6', 'addr', 'list']: argument_list[:4] == ['ip', '-6', 'addr', 'list']:
retval = 0, str(INTERFACE_DICT) retval = 0, str(INTERFACE_DICT)
elif argument_list[:3] == ['ip', 'route', 'show']:
retval = 0, 'OK'
elif argument_list[:3] == ['route', 'add', '-host']:
retval = 0, 'OK'
self.external_command_list.append(' '.join(argument_list)) self.external_command_list.append(' '.join(argument_list))
return retval return retval
...@@ -441,6 +445,56 @@ class TestComputer(SlapformatMixin): ...@@ -441,6 +445,56 @@ class TestComputer(SlapformatMixin):
], ],
self.fakeCallAndRead.external_command_list) self.fakeCallAndRead.external_command_list)
def test_construct_prepared_tap_no_alter_user(self):
computer = slapos.format.Computer('computer',
interface=slapos.format.Interface(logger=self.test_result,
name='iface',
ipv4_local_network='127.0.0.1/16'),
tap_gateway_interface='eth1')
computer.instance_root = '/instance_root'
computer.software_root = '/software_root'
partition = slapos.format.Partition('partition', '/part_path',
slapos.format.User('testuser'), [], None)
global USER_LIST
USER_LIST = ['testuser']
partition.tap = slapos.format.Tap('tap')
computer.partition_list = [partition]
global INTERFACE_DICT
INTERFACE_DICT['iface'] = {
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::'}]
}
INTERFACE_DICT['eth1'] = {
socket.AF_INET: [{'addr': '10.8.0.1', 'broadcast': '10.8.0.254',
'netmask': '255.255.255.0'}]
}
computer.construct(alter_user=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 iface',
'tunctl -t tap -u testuser',
'ip link set tap up',
'ip route show 10.8.0.2',
'route add -host 10.8.0.2 dev tap',
'ip addr add ip/255.255.255.255 dev iface',
'ip addr add ip/ffff:ffff:ffff:ffff:: dev iface',
'ip -6 addr list iface'
],
self.fakeCallAndRead.external_command_list)
self.assertEqual(partition.tap.ipv4_addr, '10.8.0.2')
self.assertEqual(partition.tap.ipv4_netmask, '255.255.255.0')
self.assertEqual(partition.tap.ipv4_gateway, '10.8.0.1')
self.assertEqual(partition.tap.ipv4_network, '10.8.0.0')
@unittest.skip("Not implemented") @unittest.skip("Not implemented")
def test_construct_prepared_no_alter_network(self): def test_construct_prepared_no_alter_network(self):
computer = slapos.format.Computer('computer', computer = slapos.format.Computer('computer',
......
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