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
8f0d310b
Commit
8f0d310b
authored
Nov 01, 2022
by
Cédric Le Ninivin
Committed by
Titouan Soulard
Mar 11, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapconfiguration: no longer handle shared instances
parent
eff28fd4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
165 deletions
+2
-165
slapos/recipe/slapconfiguration.py
slapos/recipe/slapconfiguration.py
+0
-48
slapos/test/recipe/test_slaposconfiguration.py
slapos/test/recipe/test_slaposconfiguration.py
+2
-117
No files found.
slapos/recipe/slapconfiguration.py
View file @
8f0d310b
...
@@ -42,8 +42,6 @@ from slapos import format as slapformat
...
@@ -42,8 +42,6 @@ from slapos import format as slapformat
logger
=
logging
.
getLogger
(
"slapos"
)
logger
=
logging
.
getLogger
(
"slapos"
)
import
time
class
Recipe
(
object
):
class
Recipe
(
object
):
"""
"""
Retrieve slap partition parameters and make them available in buildout section.
Retrieve slap partition parameters and make them available in buildout section.
...
@@ -135,9 +133,6 @@ class Recipe(object):
...
@@ -135,9 +133,6 @@ class Recipe(object):
1. SlapOS Master - for external computer/partition information
1. SlapOS Master - for external computer/partition information
2. format.Partition.resource_file - for partition specific details
2. format.Partition.resource_file - for partition specific details
"""
"""
start
=
time
.
time
()
shared_instance_list
=
[]
software_instance
=
None
software_instance
=
None
instance_json_path
=
os
.
path
.
join
(
instance_root
,
SOFTWARE_INSTANCE_JSON_FILENAME
)
instance_json_path
=
os
.
path
.
join
(
instance_root
,
SOFTWARE_INSTANCE_JSON_FILENAME
)
...
@@ -180,42 +175,6 @@ class Recipe(object):
...
@@ -180,42 +175,6 @@ class Recipe(object):
full_ip_list
=
software_instance
.
get
(
"full_ip_list"
,
[])
full_ip_list
=
software_instance
.
get
(
"full_ip_list"
,
[])
parameter_dict
=
software_instance
.
get
(
"parameters"
)
parameter_dict
=
software_instance
.
get
(
"parameters"
)
# Get Share instance list
if
not
"slave_instance_list"
in
software_instance
:
result_shared_instance_list
=
slap
.
jio_api_connector
.
allDocs
({
"portal_type"
:
"Shared Instance"
,
"host_instance_reference"
:
software_instance
.
get
(
"reference"
),
"state"
:
"started"
,
}).
get
(
"result_list"
,
[])
shared_instance_list
=
[]
for
shared_instance_brain
in
result_shared_instance_list
:
shared_instance
=
slap
.
jio_api_connector
.
get
({
"portal_type"
:
"Software Instance"
,
"reference"
:
shared_instance_brain
.
get
(
"reference"
),
})
shared_instance_parameter
=
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
(
"software_type"
),
'slave_reference'
:
shared_instance
.
get
(
"reference"
),
'timestamp'
:
shared_instance
.
get
(
"processing_timestamp"
),
'parameters'
:
shared_instance_parameter
,
'connection_parameters'
:
shared_instance_connection
,
'connection-parameter-hash'
:
calculate_dict_hash
(
shared_instance_connection
),
})
# XXX CLN Should we update the content of software instance json with shared instance list
else
:
shared_instance_list
=
software_instance
[
"slave_instance_list"
]
options
[
"slave-instance-list"
]
=
shared_instance_list
options
[
"shared-instance-list"
]
=
shared_instance_list
if
not
"slave_instance_list"
in
software_instance
:
software_instance
[
"slave_instance_list"
]
=
shared_instance_list
with
open
(
instance_json_path
,
"w"
)
as
f
:
software_instance
=
json
.
dump
(
software_instance
,
f
,
indent
=
2
)
else
:
else
:
computer_partition
=
slap
.
registerComputerPartition
(
computer_partition
=
slap
.
registerComputerPartition
(
options
[
'computer'
],
options
[
'computer'
],
...
@@ -330,13 +289,6 @@ class Recipe(object):
...
@@ -330,13 +289,6 @@ class Recipe(object):
# print out augmented options to see what we are passing
# print out augmented options to see what we are passing
logger
.
debug
(
str
(
options
))
logger
.
debug
(
str
(
options
))
end
=
time
.
time
()
elapsed
=
end
-
start
logger
.
warning
(
"----------------------------------------------------------------------------------------------------------------"
)
logger
.
warning
(
"Number of hosted instances: %s"
%
len
(
shared_instance_list
))
logger
.
warning
(
"Elapsed time: %s"
%
elapsed
)
logger
.
warning
(
"----------------------------------------------------------------------------------------------------------------"
)
return
self
.
_expandParameterDict
(
options
,
parameter_dict
)
return
self
.
_expandParameterDict
(
options
,
parameter_dict
)
def
_expandParameterDict
(
self
,
options
,
parameter_dict
):
def
_expandParameterDict
(
self
,
options
,
parameter_dict
):
...
...
slapos/test/recipe/test_slaposconfiguration.py
View file @
8f0d310b
...
@@ -98,15 +98,12 @@ class SlapConfigurationTestMixin(object):
...
@@ -98,15 +98,12 @@ class SlapConfigurationTestMixin(object):
}
}
if
self
.
use_api
:
if
self
.
use_api
:
api_handler
=
APIRequestHandler
([
api_handler
=
APIRequestHandler
([
(
"/api/get/"
,
json
.
dumps
(
instance_data
)),
(
"/api/get/"
,
json
.
dumps
(
instance_data
))
(
"/api/allDocs/"
,
json
.
dumps
({
"result_list"
:
[]}))
])
])
else
:
else
:
with
open
(
self
.
instance_json_location
,
'w'
)
as
f
:
with
open
(
self
.
instance_json_location
,
'w'
)
as
f
:
json
.
dump
(
instance_data
,
f
,
indent
=
2
)
json
.
dump
(
instance_data
,
f
,
indent
=
2
)
api_handler
=
APIRequestHandler
([
api_handler
=
APIRequestHandler
([])
(
"/api/allDocs/"
,
json
.
dumps
({
"result_list"
:
[]}))
])
with
httmock
.
HTTMock
(
api_handler
.
request_handler
):
with
httmock
.
HTTMock
(
api_handler
.
request_handler
):
slapconfiguration
.
Recipe
(
self
.
buildout
,
"slapconfiguration"
,
options
)
slapconfiguration
.
Recipe
(
self
.
buildout
,
"slapconfiguration"
,
options
)
...
@@ -131,118 +128,6 @@ class SlapConfigurationTestMixin(object):
...
@@ -131,118 +128,6 @@ class SlapConfigurationTestMixin(object):
self
.
assertEqual
(
options
[
'address-list'
],
[
10
,
20
],
self
.
assertEqual
(
options
[
'address-list'
],
[
10
,
20
],
"All underscores should be replaced with -"
)
"All underscores should be replaced with -"
)
def
test_with_shared_instance
(
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"
:
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"
:
shared_instance_parameter_dict
,
"connection_parameters"
:
{
"4"
:
6
,
"8"
:
"YourURL2"
},
}
if
self
.
use_api
:
api_handler
=
APIRequestHandler
([
(
"/api/get/"
,
json
.
dumps
(
instance_data
)),
(
"/api/allDocs/"
,
json
.
dumps
({
"result_list"
:
[{
"portal_type"
:
"Shared Instance"
,
"reference"
:
shared_instance_data
[
"reference"
]
}]})),
(
"/api/get/"
,
json
.
dumps
(
shared_instance_data
)),
])
else
:
with
open
(
self
.
instance_json_location
,
'w'
)
as
f
:
json
.
dump
(
instance_data
,
f
,
indent
=
2
)
api_handler
=
APIRequestHandler
([
(
"/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
[
"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
[
"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"
)),
}
])
if
not
self
.
use_api
:
with
open
(
self
.
instance_json_location
,
"r"
)
as
f
:
dumped_data
=
json
.
load
(
f
)
self
.
assertEqual
(
dumped_data
[
"slave_instance_list"
],
options
[
"shared-instance-list"
])
class
SlapConfigurationWithLocalInstanceFile
(
SlapConfigurationTestMixin
,
unittest
.
TestCase
):
class
SlapConfigurationWithLocalInstanceFile
(
SlapConfigurationTestMixin
,
unittest
.
TestCase
):
use_api
=
False
use_api
=
False
...
...
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