Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
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
Titouan Soulard
slapos
Commits
6c4e5c2a
Commit
6c4e5c2a
authored
Oct 03, 2022
by
Cédric Le Ninivin
Committed by
Titouan Soulard
Mar 11, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapconfiguration: Update, fix and add tests
parent
c9a4591c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
26 deletions
+119
-26
slapos/recipe/slapconfiguration.py
slapos/recipe/slapconfiguration.py
+17
-12
slapos/test/recipe/test_slaposconfiguration.py
slapos/test/recipe/test_slaposconfiguration.py
+102
-14
No files found.
slapos/recipe/slapconfiguration.py
View file @
6c4e5c2a
...
...
@@ -30,11 +30,13 @@ import logging
import
os
import
slapos.slap
from
slapos.slap.slap
import
json_loads_byteified
from
slapos.recipe.librecipe
import
unwrap
import
six
from
six.moves.configparser
import
RawConfigParser
from
netaddr
import
valid_ipv4
,
valid_ipv6
from
slapos.util
import
mkdir_p
,
dumps
from
slapos.util
import
mkdir_p
,
dumps
,
calculate_dict_hash
from
slapos
import
format
as
slapformat
...
...
@@ -151,17 +153,17 @@ class Recipe(object):
"compute_partition_id"
:
options
[
"partition"
],
})
options
[
"instance-state"
]
=
software_instance
.
get
(
"state"
)
options
[
"slap
_software_
type"
]
=
software_instance
.
get
(
"software_type"
)
options
[
"slap
_computer_partition_
id"
]
=
software_instance
.
get
(
"compute_partition_id"
)
options
[
"slap
_computer_
id"
]
=
software_instance
.
get
(
"compute_node_id"
)
options
[
"slap
_software_release_
url"
]
=
software_instance
.
get
(
"software_release_uri"
)
options
[
"slap
-software-
type"
]
=
software_instance
.
get
(
"software_type"
)
options
[
"slap
-computer-partition-
id"
]
=
software_instance
.
get
(
"compute_partition_id"
)
options
[
"slap
-computer-
id"
]
=
software_instance
.
get
(
"compute_node_id"
)
options
[
"slap
-software-release-
url"
]
=
software_instance
.
get
(
"software_release_uri"
)
options
[
"timestamp"
]
=
software_instance
.
get
(
"processing_timestamp"
)
options
[
"instance-title"
]
=
software_instance
.
get
(
"title"
)
options
[
"root-instance-title"
]
=
software_instance
.
get
(
"root_instance_title"
)
options
[
"instance-guid"
]
=
software_instance
.
get
(
"reference"
)
ip_list
=
software_instance
.
get
(
"ip_list"
,
[])
full_ip_list
=
software_instance
.
get
(
"full_ip_list"
,
[])
parameter_dict
=
json
.
loads
(
software_instance
.
get
(
"parameters"
))
parameter_dict
=
json
_loads_byteified
(
software_instance
.
get
(
"parameters"
))
# Get Share instance list
result_shared_instance_list
=
slap
.
jio_api_connector
.
allDocs
({
...
...
@@ -175,19 +177,22 @@ class Recipe(object):
"portal_type"
:
"Software Instance"
,
"reference"
:
shared_instance_brain
.
get
(
"reference"
),
})
shared_instance_parameter
=
json
.
loads
(
shared_instance
.
get
(
"parameters"
))
shared_instance_connection
=
json
.
loads
(
shared_instance
.
get
(
"connection_parameters"
)
)
shared_instance_parameter
=
json
_loads_byteified
(
shared_instance
.
get
(
"parameters"
))
shared_instance_connection
=
shared_instance
.
get
(
"connection_parameters"
)
shared_instance_list
.
append
({
'slave_title'
:
shared_instance
.
get
(
"title"
),
'slap_software_type'
:
\
shared_instance
.
get
(
"type"
),
shared_instance
.
get
(
"
software_
type"
),
'slave_reference'
:
shared_instance
.
get
(
"reference"
),
'timestamp'
:
shared_instance
.
get
(
"timestamp"
),
'timestamp'
:
shared_instance
.
get
(
"
processing_
timestamp"
),
'xml'
:
dumps
(
shared_instance_parameter
),
'parameters'
:
shared_instance
.
get
(
"parameters"
)
,
'parameters'
:
shared_instance
_parameter
,
'connection_xml'
:
dumps
(
shared_instance_connection
),
'connection_parameters'
:
shared_instance
.
get
(
"connection_parameters"
),
'connection_parameters'
:
shared_instance_connection
,
'connection-parameter-hash'
:
calculate_dict_hash
(
shared_instance_connection
),
})
options
[
"slave-instance-list"
]
=
shared_instance_list
options
[
"shared-instance-list"
]
=
shared_instance_list
else
:
computer_partition
=
slap
.
registerComputerPartition
(
options
[
'computer'
],
...
...
slapos/test/recipe/test_slaposconfiguration.py
View file @
6c4e5c2a
...
...
@@ -8,6 +8,7 @@ import tempfile
from
collections
import
defaultdict
from
slapos.recipe
import
slapconfiguration
from
slapos
import
format
as
slapformat
from
slapos.util
import
dumps
,
calculate_dict_hash
class
APIRequestHandler
(
object
):
...
...
@@ -55,14 +56,57 @@ class SlapConfigurationTest(unittest.TestCase):
os
.
unlink
(
self
.
resource_file
)
os
.
rmdir
(
self
.
instance_root
)
@
mock
.
patch
(
"slapos.slap.slap"
)
def
test_correct_naming
(
self
,
MockClient
):
"""Test correct naming of variables from resource file."""
MockClient
.
initializeConnection
.
return_value
=
None
MockClient
.
getInstanceParameterDict
.
return_value
=
dict
()
options
=
defaultdict
(
str
)
recipe
=
slapconfiguration
.
Recipe
(
self
.
buildout
,
"slapconfiguration"
,
options
)
def
test_new_api
(
self
):
"""Test proper call with new api"""
options
=
{
"url"
:
"http://127.0.0.1:80"
,
"software-instance-reference"
:
"SOFTINST-12"
,
}
parameter_dict
=
{
"foo"
:
"bar"
,
"hello"
:
"bye"
}
instance_data
=
{
"reference"
:
options
[
"software-instance-reference"
],
"state"
:
"started"
,
"software_type"
:
"Couscous"
,
"compute_partition_id"
:
"slappartx12"
,
"compute_node_id"
:
"COMP-321"
,
"software_release_uri"
:
"foo.cfg"
,
"processing_timestamp"
:
1223231231
,
"title"
:
"MyInstance"
,
"root_instance_title"
:
"MyInstanceRoot"
,
"ip_list"
:
[
[
"slaptap9"
,
"fe80::1ff:fe23:4567:890a"
],
[
"slaptap9"
,
"10.0.246.114"
]
],
"parameters"
:
json
.
dumps
(
parameter_dict
),
"connection_parameters"
:
{
"1"
:
2
,
"3"
:
"YourURL"
},
}
api_handler
=
APIRequestHandler
([
(
"/api/get"
,
json
.
dumps
(
instance_data
)),
(
"/api/allDocs"
,
json
.
dumps
({
"result_list"
:
[]}))
])
with
httmock
.
HTTMock
(
api_handler
.
request_handler
):
slapconfiguration
.
Recipe
(
self
.
buildout
,
"slapconfiguration"
,
options
)
self
.
assertEqual
(
options
[
"instance-state"
],
instance_data
.
get
(
"state"
))
self
.
assertEqual
(
options
[
"slap-software-type"
],
instance_data
.
get
(
"software_type"
))
self
.
assertEqual
(
options
[
"slap-computer-partition-id"
],
instance_data
.
get
(
"compute_partition_id"
))
self
.
assertEqual
(
options
[
"slap-computer-id"
],
instance_data
.
get
(
"compute_node_id"
))
self
.
assertEqual
(
options
[
"slap-software-release-url"
],
instance_data
.
get
(
"software_release_uri"
))
self
.
assertEqual
(
options
[
"timestamp"
],
instance_data
.
get
(
"processing_timestamp"
))
self
.
assertEqual
(
options
[
"instance-title"
],
instance_data
.
get
(
"title"
))
self
.
assertEqual
(
options
[
"root-instance-title"
],
instance_data
.
get
(
"root_instance_title"
))
self
.
assertEqual
(
options
[
"instance-guid"
],
instance_data
.
get
(
"reference"
))
self
.
assertEqual
(
options
[
"ipv4"
],
set
([
instance_data
.
get
(
"ip_list"
)[
1
][
1
]]))
self
.
assertEqual
(
options
[
"ipv6"
],
set
([
instance_data
.
get
(
"ip_list"
)[
0
][
1
]]))
for
key
,
value
in
parameter_dict
.
items
():
options
[
'configuration.'
+
key
]
=
value
self
.
assertEqual
(
options
[
'tun-ipv4'
],
"192.168.0.1"
,
"Folded attrs should be separated by -"
)
...
...
@@ -71,7 +115,7 @@ class SlapConfigurationTest(unittest.TestCase):
self
.
assertEqual
(
options
[
'address-list'
],
[
10
,
20
],
"All underscores should be replaced with -"
)
def
test_new_api
(
self
):
def
test_new_api
_with_shared_instance
(
self
):
"""Test proper call with new api"""
options
=
{
...
...
@@ -102,18 +146,46 @@ class SlapConfigurationTest(unittest.TestCase):
"parameters"
:
json
.
dumps
(
parameter_dict
),
"connection_parameters"
:
{
"1"
:
2
,
"3"
:
"YourURL"
},
}
shared_instance_parameter_dict
=
{
"zooo"
:
"heee"
,
"bye"
:
"hello"
}
shared_instance_data
=
{
"reference"
:
"SHARED-124"
,
"state"
:
"started"
,
"software_type"
:
"Couscous"
,
"compute_partition_id"
:
"slappartx12"
,
"compute_node_id"
:
"COMP-321"
,
"software_release_uri"
:
"foo.cfg"
,
"processing_timestamp"
:
14444332
,
"title"
:
"MySharedInstance"
,
"root_instance_title"
:
"MySharedInstance"
,
"ip_list"
:
[
[
"slaptap9"
,
"fe80::1ff:fe23:4567:890a"
],
[
"slaptap9"
,
"10.0.246.114"
]
],
"parameters"
:
json
.
dumps
(
shared_instance_parameter_dict
),
"connection_parameters"
:
{
"4"
:
6
,
"8"
:
"YourURL2"
},
}
api_handler
=
APIRequestHandler
([
(
"/api/get"
,
json
.
dumps
(
instance_data
)),
(
"/api/allDocs"
,
json
.
dumps
({
"result_list"
:
[]}))
(
"/api/allDocs"
,
json
.
dumps
({
"result_list"
:
[{
"portal_type"
:
"Shared Instance"
,
"reference"
:
shared_instance_data
[
"reference"
]
}]})),
(
"/api/get"
,
json
.
dumps
(
shared_instance_data
)),
])
with
httmock
.
HTTMock
(
api_handler
.
request_handler
):
slapconfiguration
.
Recipe
(
self
.
buildout
,
"slapconfiguration"
,
options
)
self
.
assertEqual
(
options
[
"instance-state"
],
instance_data
.
get
(
"state"
))
self
.
assertEqual
(
options
[
"slap
_software_
type"
],
instance_data
.
get
(
"software_type"
))
self
.
assertEqual
(
options
[
"slap
_computer_partition_
id"
],
instance_data
.
get
(
"compute_partition_id"
))
self
.
assertEqual
(
options
[
"slap
_computer_
id"
],
instance_data
.
get
(
"compute_node_id"
))
self
.
assertEqual
(
options
[
"slap
_software_release_
url"
],
instance_data
.
get
(
"software_release_uri"
))
self
.
assertEqual
(
options
[
"slap
-software-
type"
],
instance_data
.
get
(
"software_type"
))
self
.
assertEqual
(
options
[
"slap
-computer-partition-
id"
],
instance_data
.
get
(
"compute_partition_id"
))
self
.
assertEqual
(
options
[
"slap
-computer-
id"
],
instance_data
.
get
(
"compute_node_id"
))
self
.
assertEqual
(
options
[
"slap
-software-release-
url"
],
instance_data
.
get
(
"software_release_uri"
))
self
.
assertEqual
(
options
[
"timestamp"
],
instance_data
.
get
(
"processing_timestamp"
))
self
.
assertEqual
(
options
[
"instance-title"
],
instance_data
.
get
(
"title"
))
self
.
assertEqual
(
options
[
"root-instance-title"
],
instance_data
.
get
(
"root_instance_title"
))
...
...
@@ -122,3 +194,19 @@ class SlapConfigurationTest(unittest.TestCase):
self
.
assertEqual
(
options
[
"ipv6"
],
set
([
instance_data
.
get
(
"ip_list"
)[
0
][
1
]]))
for
key
,
value
in
parameter_dict
.
items
():
options
[
'configuration.'
+
key
]
=
value
self
.
assertEqual
(
options
[
"slave-instance-list"
],
options
[
"shared-instance-list"
])
self
.
assertEqual
(
options
[
"shared-instance-list"
],[
{
'slave_title'
:
shared_instance_data
.
get
(
"title"
),
'slap_software_type'
:
\
shared_instance_data
.
get
(
"software_type"
),
'slave_reference'
:
shared_instance_data
.
get
(
"reference"
),
'timestamp'
:
shared_instance_data
.
get
(
"processing_timestamp"
),
'xml'
:
dumps
(
shared_instance_parameter_dict
),
'parameters'
:
shared_instance_parameter_dict
,
'connection_xml'
:
dumps
(
shared_instance_data
.
get
(
"connection_parameters"
)),
'connection_parameters'
:
shared_instance_data
.
get
(
"connection_parameters"
),
'connection-parameter-hash'
:
calculate_dict_hash
(
shared_instance_data
.
get
(
"connection_parameters"
)),
}
])
\ No newline at end of file
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