Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Hardik Juneja
slapos.core
Commits
b1b19629
Commit
b1b19629
authored
Mar 10, 2015
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update computer from dict: Save network information of tap interface (without bridge)
parent
684c6366
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
346 additions
and
10 deletions
+346
-10
master/bt5/slapos_slap_tool/SkinTemplateItem/portal_skins/slapos_slap_tool/Computer_updateFromDict.xml
...portal_skins/slapos_slap_tool/Computer_updateFromDict.xml
+14
-0
master/bt5/slapos_slap_tool/TestTemplateItem/portal_components/test.erp5.testSlapOSSlapToolComputerUpdateFromDict.py
...nts/test.erp5.testSlapOSSlapToolComputerUpdateFromDict.py
+286
-0
master/bt5/slapos_slap_tool/TestTemplateItem/portal_components/test.erp5.testSlapOSSlapToolComputerUpdateFromDict.xml
...ts/test.erp5.testSlapOSSlapToolComputerUpdateFromDict.xml
+35
-7
master/product/Vifib/Tool/SlapTool.py
master/product/Vifib/Tool/SlapTool.py
+11
-3
No files found.
master/bt5/slapos_slap_tool/SkinTemplateItem/portal_skins/slapos_slap_tool/Computer_updateFromDict.xml
View file @
b1b19629
...
...
@@ -65,6 +65,10 @@
if current_dict in to_add_ip_dict_list:\n
to_add_ip_dict_list.remove(current_dict)\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
\n
for address in to_add_ip_dict_list:\n
...
...
@@ -114,6 +118,16 @@ for send_partition in computer_dict[\'partition_list\']:\n
partition.edit(reference=send_partition[\'reference\'])\n
network_interface = send_partition[\'tap\'][\'name\']\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
# Desactivate all other partitions\n
for key, value in existing_partition_dict.items():\n
...
...
master/bt5/slapos_slap_tool/TestTemplateItem/portal_components/test.erp5.testSlapOSSlapToolComputerUpdateFromDict.py
View file @
b1b19629
...
...
@@ -131,6 +131,51 @@ class TestSlapOSCoreComputerUpdateFromDict(testSlapOSMixin):
self
.
assertEqual
(
address
.
getNetworkInterface
(),
'bar'
)
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
):
partition
=
self
.
computer
.
newContent
(
reference
=
'foo'
,
...
...
@@ -173,6 +218,61 @@ class TestSlapOSCoreComputerUpdateFromDict(testSlapOSMixin):
self
.
assertEqual
(
other_address
.
getNetmask
(),
'f'
)
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
):
partition
=
self
.
computer
.
newContent
(
reference
=
'foo'
,
...
...
@@ -210,6 +310,55 @@ class TestSlapOSCoreComputerUpdateFromDict(testSlapOSMixin):
self
.
assertEqual
(
address
.
getNetworkInterface
(),
'bar'
)
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
):
partition
=
self
.
computer
.
newContent
(
reference
=
'foo'
,
...
...
@@ -258,6 +407,143 @@ class TestSlapOSCoreComputerUpdateFromDict(testSlapOSMixin):
self
.
assertEqual
(
other_address
.
getNetmask
(),
'f'
)
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
):
partition
=
self
.
computer
.
newContent
(
reference
=
'foo'
,
...
...
master/bt5/slapos_slap_tool/TestTemplateItem/portal_components/test.erp5.testSlapOSSlapToolComputerUpdateFromDict.xml
View file @
b1b19629
...
...
@@ -6,10 +6,22 @@
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
_recorded_property_dict
</string>
</key>
<value>
<persistent>
<string
encoding=
"base64"
>
AAAAAAAAAAI=
</string>
</persistent>
</value>
</item>
<item>
<key>
<string>
default_reference
</string>
</key>
<value>
<string>
testSlapOSSlapToolComputerUpdateFromDict
</string>
</value>
</item>
<item>
<key>
<string>
description
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
test.erp5.testSlapOSSlapToolComputerUpdateFromDict
</string>
</value>
...
...
@@ -34,10 +46,11 @@
<key>
<string>
text_content_warning_message
</string>
</key>
<value>
<tuple>
<string>
W:274, 4: Unused variable \'default_address\' (unused-variable)
</string>
<string>
W:270, 4: Unused variable \'other_address\' (unused-variable)
</string>
<string>
W:315, 4: Unused variable \'default_address\' (unused-variable)
</string>
<string>
W:311, 4: Unused variable \'other_address\' (unused-variable)
</string>
<string>
W:423, 4: Unused variable \'other_address2\' (unused-variable)
</string>
<string>
W:560, 4: Unused variable \'default_address\' (unused-variable)
</string>
<string>
W:556, 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>
</value>
</item>
...
...
@@ -48,13 +61,28 @@
<item>
<key>
<string>
workflow_history
</string>
</key>
<value>
<persistent>
<string
encoding=
"base64"
>
AAAAAAAAAA
I
=
</string>
</persistent>
<persistent>
<string
encoding=
"base64"
>
AAAAAAAAAA
M
=
</string>
</persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<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>
<global
name=
"PersistentMapping"
module=
"Persistence.mapping"
/>
</pickle>
...
...
@@ -67,7 +95,7 @@
<item>
<key>
<string>
component_validation_workflow
</string>
</key>
<value>
<persistent>
<string
encoding=
"base64"
>
AAAAAAAAAA
M
=
</string>
</persistent>
<persistent>
<string
encoding=
"base64"
>
AAAAAAAAAA
Q
=
</string>
</persistent>
</value>
</item>
</dictionary>
...
...
@@ -76,7 +104,7 @@
</dictionary>
</pickle>
</record>
<record
id=
"
3"
aka=
"AAAAAAAAAAM
="
>
<record
id=
"
4"
aka=
"AAAAAAAAAAQ
="
>
<pickle>
<global
name=
"WorkflowHistoryList"
module=
"Products.ERP5Type.patches.WorkflowTool"
/>
</pickle>
...
...
master/product/Vifib/Tool/SlapTool.py
View file @
b1b19629
...
...
@@ -1429,9 +1429,17 @@ class SlapTool(BaseTool):
ip_list
=
[]
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
.
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
=
[]
if
(
software_instance
.
getPortalType
()
==
"Software Instance"
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment