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
a3be5ed0
Commit
a3be5ed0
authored
Oct 18, 2022
by
Cédric Le Ninivin
Committed by
Titouan Soulard
Mar 11, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapconfiguration: Use local instance file when available
* Also store shared instance list after retrieving it
parent
12b7ff95
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
114 additions
and
56 deletions
+114
-56
slapos/recipe/slapconfiguration.py
slapos/recipe/slapconfiguration.py
+62
-40
slapos/test/recipe/test_slaposconfiguration.py
slapos/test/recipe/test_slaposconfiguration.py
+52
-16
No files found.
slapos/recipe/slapconfiguration.py
View file @
a3be5ed0
...
...
@@ -36,6 +36,7 @@ import six
from
six.moves.configparser
import
RawConfigParser
from
netaddr
import
valid_ipv4
,
valid_ipv6
from
slapos.util
import
mkdir_p
,
dumps
,
calculate_dict_hash
from
slapos.grid.SlapObject
import
SOFTWARE_INSTANCE_JSON_FILENAME
from
slapos
import
format
as
slapformat
...
...
@@ -134,12 +135,22 @@ class Recipe(object):
1. SlapOS Master - for external computer/partition information
2. format.Partition.resource_file - for partition specific details
"""
software_instance
=
None
instance_json_path
=
os
.
path
.
join
(
instance_root
,
SOFTWARE_INSTANCE_JSON_FILENAME
)
if
os
.
path
.
exists
(
instance_json_path
):
with
open
(
instance_json_path
,
"r"
)
as
f
:
software_instance
=
json
.
load
(
f
)
slap
=
slapos
.
slap
.
slap
()
slap
.
initializeConnection
(
options
[
'url'
],
options
.
get
(
'key'
),
options
.
get
(
'cert'
),
)
# Fallback to requesting to SlapOS Master
if
not
software_instance
:
if
slap
.
jio_api_connector
:
if
options
.
get
(
"software-instance-reference"
):
software_instance
=
slap
.
jio_api_connector
.
get
({
...
...
@@ -152,6 +163,7 @@ class Recipe(object):
"compute_node_id"
:
options
[
"computer"
],
"compute_partition_id"
:
options
[
"partition"
],
})
if
software_instance
:
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"
)
...
...
@@ -166,6 +178,7 @@ class Recipe(object):
parameter_dict
=
json_loads_byteified
(
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"
),
...
...
@@ -191,8 +204,17 @@ class Recipe(object):
'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
:
computer_partition
=
slap
.
registerComputerPartition
(
options
[
'computer'
],
...
...
slapos/test/recipe/test_slaposconfiguration.py
View file @
a3be5ed0
...
...
@@ -8,6 +8,7 @@ import tempfile
from
collections
import
defaultdict
from
slapos.recipe
import
slapconfiguration
from
slapos
import
format
as
slapformat
from
slapos.grid.SlapObject
import
SOFTWARE_INSTANCE_JSON_FILENAME
from
slapos.util
import
dumps
,
calculate_dict_hash
...
...
@@ -32,7 +33,7 @@ class APIRequestHandler(object):
return
self
.
response_list
.
pop
(
0
)[
1
]
class
SlapConfigurationTest
(
unittest
.
TestCase
):
class
SlapConfigurationTest
Mixin
(
object
):
def
setUp
(
self
):
"""Prepare files on filesystem."""
...
...
@@ -49,6 +50,10 @@ class SlapConfigurationTest(unittest.TestCase):
}
with
open
(
self
.
resource_file
,
"wt"
)
as
fo
:
json
.
dump
(
self
.
resource
,
fo
)
self
.
instance_json_location
=
os
.
path
.
join
(
self
.
instance_root
,
SOFTWARE_INSTANCE_JSON_FILENAME
)
# do your tests inside try block and clean up in finally
self
.
buildout
=
{
"buildout"
:
{
...
...
@@ -58,9 +63,11 @@ class SlapConfigurationTest(unittest.TestCase):
def
tearDown
(
self
):
os
.
unlink
(
self
.
resource_file
)
if
os
.
path
.
exists
(
self
.
instance_json_location
):
os
.
unlink
(
self
.
instance_json_location
)
os
.
rmdir
(
self
.
instance_root
)
def
test_n
ew_api
(
self
):
def
test_n
o_shared_instance
(
self
):
"""Test proper call with new api"""
options
=
{
...
...
@@ -91,10 +98,17 @@ class SlapConfigurationTest(unittest.TestCase):
"parameters"
:
json
.
dumps
(
parameter_dict
),
"connection_parameters"
:
{
"1"
:
2
,
"3"
:
"YourURL"
},
}
if
self
.
use_api
:
api_handler
=
APIRequestHandler
([
(
"/api/get"
,
json
.
dumps
(
instance_data
)),
(
"/api/allDocs"
,
json
.
dumps
({
"result_list"
:
[]}))
])
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"
:
[]}))
])
with
httmock
.
HTTMock
(
api_handler
.
request_handler
):
slapconfiguration
.
Recipe
(
self
.
buildout
,
"slapconfiguration"
,
options
)
...
...
@@ -119,7 +133,7 @@ class SlapConfigurationTest(unittest.TestCase):
self
.
assertEqual
(
options
[
'address-list'
],
[
10
,
20
],
"All underscores should be replaced with -"
)
def
test_
new_api_
with_shared_instance
(
self
):
def
test_with_shared_instance
(
self
):
"""Test proper call with new api"""
options
=
{
...
...
@@ -174,6 +188,7 @@ class SlapConfigurationTest(unittest.TestCase):
"parameters"
:
json
.
dumps
(
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"
:
[{
...
...
@@ -182,6 +197,16 @@ class SlapConfigurationTest(unittest.TestCase):
}]})),
(
"/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
)
...
...
@@ -214,3 +239,14 @@ class SlapConfigurationTest(unittest.TestCase):
'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
):
use_api
=
True
class
SlapConfigurationWithApi
(
SlapConfigurationTestMixin
,
unittest
.
TestCase
):
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