Commit b1b19629 authored by Alain Takoudjou's avatar Alain Takoudjou

Update computer from dict: Save network information of tap interface (without bridge)

parent 684c6366
...@@ -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
......
...@@ -131,6 +131,51 @@ class TestSlapOSCoreComputerUpdateFromDict(testSlapOSMixin): ...@@ -131,6 +131,51 @@ class TestSlapOSCoreComputerUpdateFromDict(testSlapOSMixin):
self.assertEqual(address.getNetworkInterface(), 'bar') self.assertEqual(address.getNetworkInterface(), 'bar')
self.assertEqual(address.getId(), 'default_network_address') self.assertEqual(address.getId(), 'default_network_address')
def test_CreateSinglePartition_TapNetworkInformation(self):
partition = self.computer.newContent(
reference='foo',
portal_type='Computer Partition',
)
# No address in the empty partition
address_list = partition.contentValues(
portal_type='Internet Protocol Address')
self.assertEqual(len(address_list), 0)
parameter_dict = {
'partition_list': [{
'reference': 'foo',
'address_list': [{
'addr': 'c',
'netmask': 'd',
}],
'tap': {'name': 'bar',
'ipv4_addr': 'e',
'ipv4_netmask': 'f',
'ipv4_network': 'g',
'ipv4_gateway': 'h'},
}],
'address': 'a',
'netmask': 'b',
}
self.computer.Computer_updateFromDict(parameter_dict)
address_list = partition.contentValues(
portal_type='Internet Protocol Address')
self.assertEqual(len(address_list), 2)
address_list.sort(key=lambda x: {0: 1, 1: 2}[int(x.getId() != 'default_network_address')])
address = address_list[0]
self.assertEqual(address.getIpAddress(), 'c')
self.assertEqual(address.getNetmask(), 'd')
self.assertEqual(address.getNetworkInterface(), 'bar')
self.assertEqual(address.getId(), 'default_network_address')
address1 = address_list[1]
self.assertEqual(address1.getIpAddress(), 'e')
self.assertEqual(address1.getNetmask(), 'f')
self.assertEqual(address1.getNetworkAddress(), 'g')
self.assertEqual(address1.getGatewayIpAddress(), 'h')
self.assertEqual(address1.getNetworkInterface(), 'route_bar')
def test_CreateMultiplePartitionNetworkInformation(self): def test_CreateMultiplePartitionNetworkInformation(self):
partition = self.computer.newContent( partition = self.computer.newContent(
reference='foo', reference='foo',
...@@ -173,6 +218,61 @@ class TestSlapOSCoreComputerUpdateFromDict(testSlapOSMixin): ...@@ -173,6 +218,61 @@ class TestSlapOSCoreComputerUpdateFromDict(testSlapOSMixin):
self.assertEqual(other_address.getNetmask(), 'f') self.assertEqual(other_address.getNetmask(), 'f')
self.assertEqual(other_address.getNetworkInterface(), 'bar') self.assertEqual(other_address.getNetworkInterface(), 'bar')
def test_CreateMultiplePartition_TapNetworkInformation(self):
partition = self.computer.newContent(
reference='foo',
portal_type='Computer Partition',
)
# No address in the empty partition
address_list = partition.contentValues(
portal_type='Internet Protocol Address')
self.assertEqual(len(address_list), 0)
parameter_dict = {
'partition_list': [{
'reference': 'foo',
'address_list': [{
'addr': 'c',
'netmask': 'd',
},{
'addr': 'e',
'netmask': 'f',
}],
'tap': {'name': 'bar',
'ipv4_addr': 'g',
'ipv4_netmask': 'h',
'ipv4_network': 'i',
'ipv4_gateway': 'j'},
}],
'address': 'a',
'netmask': 'b',
}
self.computer.Computer_updateFromDict(parameter_dict)
address_list = partition.contentValues(
portal_type='Internet Protocol Address')
self.assertEqual(len(address_list), 3)
default_address = [x for x in address_list \
if x.getId() == 'default_network_address'][0]
self.assertEqual(default_address.getIpAddress(), 'c')
self.assertEqual(default_address.getNetmask(), 'd')
self.assertEqual(default_address.getNetworkInterface(), 'bar')
other_address_list = [x for x in address_list \
if x.getId() != 'default_network_address']
other_address_list.sort(key=lambda x: {1: 1, 0: 2}[int(x.getNetworkInterface() == 'bar')])
other_address = other_address_list[0]
self.assertEqual(other_address.getIpAddress(), 'e')
self.assertEqual(other_address.getNetmask(), 'f')
self.assertEqual(other_address.getNetworkInterface(), 'bar')
other_address1 = other_address_list[1]
self.assertEqual(other_address1.getIpAddress(), 'g')
self.assertEqual(other_address1.getNetmask(), 'h')
self.assertEqual(other_address1.getNetworkAddress(), 'i')
self.assertEqual(other_address1.getGatewayIpAddress(), 'j')
self.assertEqual(other_address1.getNetworkInterface(), 'route_bar')
def test_UpdateSinglePartitionNetworkInformation(self): def test_UpdateSinglePartitionNetworkInformation(self):
partition = self.computer.newContent( partition = self.computer.newContent(
reference='foo', reference='foo',
...@@ -210,6 +310,55 @@ class TestSlapOSCoreComputerUpdateFromDict(testSlapOSMixin): ...@@ -210,6 +310,55 @@ class TestSlapOSCoreComputerUpdateFromDict(testSlapOSMixin):
self.assertEqual(address.getNetworkInterface(), 'bar') self.assertEqual(address.getNetworkInterface(), 'bar')
self.assertEqual(address.getId(), 'foo') self.assertEqual(address.getId(), 'foo')
def test_UpdateSinglePartition_TapNetworkInformation(self):
partition = self.computer.newContent(
reference='foo',
portal_type='Computer Partition',
)
# No address in the empty partition
address_list = partition.contentValues(
portal_type='Internet Protocol Address')
self.assertEqual(len(address_list), 0)
address = partition.newContent(
id ='foo',
portal_type='Internet Protocol Address',
)
parameter_dict = {
'partition_list': [{
'reference': 'foo',
'address_list': [{
'addr': 'c',
'netmask': 'd',
}],
'tap': {'name': 'bar',
'ipv4_addr': 'e',
'ipv4_netmask': 'f',
'ipv4_network': 'g',
'ipv4_gateway': 'h'},
}],
'address': 'a',
'netmask': 'b',
}
self.computer.Computer_updateFromDict(parameter_dict)
address_list = partition.contentValues(
portal_type='Internet Protocol Address')
self.assertEqual(len(address_list), 2)
address_list.sort(key=lambda x: {1: 1, 0: 2}[int(x.getNetworkInterface() == 'bar')])
address = address_list[0]
self.assertEqual(address.getIpAddress(), 'c')
self.assertEqual(address.getNetmask(), 'd')
self.assertEqual(address.getNetworkInterface(), 'bar')
self.assertEqual(address.getId(), 'foo')
other_address = address_list[1]
self.assertEqual(other_address.getIpAddress(), 'e')
self.assertEqual(other_address.getNetmask(), 'f')
self.assertEqual(other_address.getNetworkAddress(), 'g')
self.assertEqual(other_address.getGatewayIpAddress(), 'h')
self.assertEqual(other_address.getNetworkInterface(), 'route_bar')
def test_UpdateMultiplePartitionNetworkInformation(self): def test_UpdateMultiplePartitionNetworkInformation(self):
partition = self.computer.newContent( partition = self.computer.newContent(
reference='foo', reference='foo',
...@@ -258,6 +407,143 @@ class TestSlapOSCoreComputerUpdateFromDict(testSlapOSMixin): ...@@ -258,6 +407,143 @@ class TestSlapOSCoreComputerUpdateFromDict(testSlapOSMixin):
self.assertEqual(other_address.getNetmask(), 'f') self.assertEqual(other_address.getNetmask(), 'f')
self.assertEqual(other_address.getNetworkInterface(), 'bar') self.assertEqual(other_address.getNetworkInterface(), 'bar')
def test_UpdateMultiplePartition_TapNetworkInformation(self):
partition = self.computer.newContent(
reference='foo',
portal_type='Computer Partition',
)
# No address in the empty partition
address_list = partition.contentValues(
portal_type='Internet Protocol Address')
self.assertEqual(len(address_list), 0)
other_address = partition.newContent(
id ='foo',
portal_type='Internet Protocol Address',
)
other_address2 = partition.newContent(
id ='route_foo',
portal_type='Internet Protocol Address',
)
default_address = partition.newContent(
id ='default_network_interface',
portal_type='Internet Protocol Address',
)
parameter_dict = {
'partition_list': [{
'reference': 'foo',
'address_list': [{
'addr': 'c',
'netmask': 'd',
},{
'addr': 'e',
'netmask': 'f',
}],
'tap': {'name': 'bar',
'ipv4_addr': 'g',
'ipv4_netmask': 'h',
'ipv4_network': 'i',
'ipv4_gateway': 'j'},
}],
'address': 'a',
'netmask': 'b',
}
self.computer.Computer_updateFromDict(parameter_dict)
address_list = partition.contentValues(
portal_type='Internet Protocol Address')
self.assertEqual(len(address_list), 3)
# First address should go to the default one
self.assertEqual(default_address.getIpAddress(), 'c')
self.assertEqual(default_address.getNetmask(), 'd')
self.assertEqual(default_address.getNetworkInterface(), 'bar')
other_address_list = [x for x in address_list \
if x.getId() != 'default_network_interface']
other_address_list.sort(
key=lambda x: {1: 1, 0: 2}[int(x.getNetworkInterface() == 'bar')])
other_address = other_address_list[0]
self.assertEqual(other_address.getIpAddress(), 'e')
self.assertEqual(other_address.getNetmask(), 'f')
self.assertEqual(other_address.getNetworkInterface(), 'bar')
other_address = other_address_list[1]
self.assertEqual(other_address.getIpAddress(), 'g')
self.assertEqual(other_address.getNetmask(), 'h')
self.assertEqual(other_address.getNetworkAddress(), 'i')
self.assertEqual(other_address.getGatewayIpAddress(), 'j')
self.assertEqual(other_address.getNetworkInterface(), 'route_bar')
def test_removePartitionTapNetworkInformation(self):
partition = self.computer.newContent(
reference='foo',
portal_type='Computer Partition',
)
# No address in the empty partition
address_list = partition.contentValues(
portal_type='Internet Protocol Address')
self.assertEqual(len(address_list), 0)
parameter_dict = {
'partition_list': [{
'reference': 'foo',
'address_list': [{
'addr': 'c',
'netmask': 'd',
}],
'tap': {'name': 'bar',
'ipv4_addr': 'e',
'ipv4_netmask': 'f',
'ipv4_network': 'g',
'ipv4_gateway': 'h'},
}],
'address': 'a',
'netmask': 'b',
}
parameter_dict2 = {
'partition_list': [{
'reference': 'foo',
'address_list': [{
'addr': 'c',
'netmask': 'd',
}],
'tap': {'name': 'bar'},
}],
'address': 'a',
'netmask': 'b',
}
self.computer.Computer_updateFromDict(parameter_dict)
address_list = partition.contentValues(
portal_type='Internet Protocol Address')
address_list.sort(
key=lambda x: {1: 1, 0: 2}[int(x.getId() == 'default_network_address')])
self.assertEqual(len(address_list), 2)
address = address_list[0]
self.assertEqual(address.getIpAddress(), 'c')
self.assertEqual(address.getNetmask(), 'd')
self.assertEqual(address.getNetworkInterface(), 'bar')
self.assertEqual(address.getId(), 'default_network_address')
other_address = address_list[1]
self.assertEqual(other_address.getIpAddress(), 'e')
self.assertEqual(other_address.getNetmask(), 'f')
self.assertEqual(other_address.getNetworkAddress(), 'g')
self.assertEqual(other_address.getGatewayIpAddress(), 'h')
self.assertEqual(other_address.getNetworkInterface(), 'route_bar')
self.computer.Computer_updateFromDict(parameter_dict2)
address_list = partition.contentValues(
portal_type='Internet Protocol Address')
self.assertEqual(len(address_list), 1)
self.assertEqual(address_list[0].getIpAddress(), 'c')
self.assertEqual(address_list[0].getNetmask(), 'd')
self.assertEqual(address_list[0].getNetworkInterface(), 'bar')
self.assertEqual(address_list[0].getId(), 'default_network_address')
def test_RemoveSinglePartitionNetworkInformation(self): def test_RemoveSinglePartitionNetworkInformation(self):
partition = self.computer.newContent( partition = self.computer.newContent(
reference='foo', reference='foo',
......
...@@ -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"):
......
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