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
Carlos Ramos Carreño
slapos.core
Commits
5140ec99
Commit
5140ec99
authored
Jan 10, 2024
by
Titouan Soulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cli/request: allow enforcing a given serialisation
parent
09d2ca06
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
2 deletions
+49
-2
slapos/cli/request.py
slapos/cli/request.py
+9
-2
slapos/tests/test_cli.py
slapos/tests/test_cli.py
+40
-0
No files found.
slapos/cli/request.py
View file @
5140ec99
...
@@ -113,6 +113,10 @@ class RequestCommand(ClientConfigCommand):
...
@@ -113,6 +113,10 @@ class RequestCommand(ClientConfigCommand):
action
=
'store_true'
,
action
=
'store_true'
,
help
=
'Ask for a slave instance'
)
help
=
'Ask for a slave instance'
)
ap
.
add_argument
(
'--force-serialisation'
,
choices
=
[
s
.
value
for
s
in
SoftwareReleaseSerialisation
],
help
=
'Enforce serialisation of instance parameters when using --parameters-file'
)
parameter_args
=
ap
.
add_mutually_exclusive_group
()
parameter_args
=
ap
.
add_mutually_exclusive_group
()
parameter_args
.
add_argument
(
parameter_args
.
add_argument
(
...
@@ -151,7 +155,10 @@ def do_request(logger, conf, local):
...
@@ -151,7 +155,10 @@ def do_request(logger, conf, local):
software_schema
=
SoftwareReleaseSchema
(
conf
.
software_url
,
conf
.
type
)
software_schema
=
SoftwareReleaseSchema
(
conf
.
software_url
,
conf
.
type
)
parameters
=
conf
.
parameters
parameters
=
conf
.
parameters
if
conf
.
parameters_file
:
if
conf
.
parameters_file
:
# getSerialisation must throw an exception if serialization cannot be found
if
conf
.
force_serialisation
:
parameters
=
getParametersFromFile
(
conf
.
parameters_file
,
SoftwareReleaseSerialisation
(
conf
.
force_serialisation
))
else
:
# getSerialisation will throw an exception if serialization cannot be found
parameters
=
getParametersFromFile
(
conf
.
parameters_file
,
software_schema
.
getSerialisation
())
parameters
=
getParametersFromFile
(
conf
.
parameters_file
,
software_schema
.
getSerialisation
())
try
:
try
:
partition
=
local
[
'slap'
].
registerOpenOrder
().
request
(
partition
=
local
[
'slap'
].
registerOpenOrder
().
request
(
...
...
slapos/tests/test_cli.py
View file @
5140ec99
...
@@ -910,6 +910,7 @@ class TestCliRequest(CliMixin):
...
@@ -910,6 +910,7 @@ class TestCliRequest(CliMixin):
self
.
conf
.
type
=
None
self
.
conf
.
type
=
None
self
.
conf
.
state
=
None
self
.
conf
.
state
=
None
self
.
conf
.
slave
=
False
self
.
conf
.
slave
=
False
self
.
conf
.
force_serialisation
=
None
with
patch
.
object
(
with
patch
.
object
(
slapos
.
slap
.
slap
,
slapos
.
slap
.
slap
,
...
@@ -961,6 +962,7 @@ class TestCliRequest(CliMixin):
...
@@ -961,6 +962,7 @@ class TestCliRequest(CliMixin):
self
.
conf
.
type
=
None
self
.
conf
.
type
=
None
self
.
conf
.
state
=
None
self
.
conf
.
state
=
None
self
.
conf
.
slave
=
False
self
.
conf
.
slave
=
False
self
.
conf
.
force_serialisation
=
None
cp
=
slapos
.
slap
.
ComputerPartition
(
cp
=
slapos
.
slap
.
ComputerPartition
(
'computer_%s'
%
self
.
id
(),
'computer_%s'
%
self
.
id
(),
...
@@ -1013,6 +1015,7 @@ class TestCliRequestParameterFile(CliMixin):
...
@@ -1013,6 +1015,7 @@ class TestCliRequestParameterFile(CliMixin):
self
.
conf
.
type
=
None
self
.
conf
.
type
=
None
self
.
conf
.
state
=
None
self
.
conf
.
state
=
None
self
.
conf
.
slave
=
False
self
.
conf
.
slave
=
False
self
.
conf
.
force_serialisation
=
None
class
TestCliRequestParameterFileUndefinedSerialization
(
TestCliRequestParameterFile
):
class
TestCliRequestParameterFileUndefinedSerialization
(
TestCliRequestParameterFile
):
...
@@ -1118,3 +1121,40 @@ class TestCliRequestParametersFileXml(TestCliRequestParametersFileJson):
...
@@ -1118,3 +1121,40 @@ class TestCliRequestParametersFileXml(TestCliRequestParametersFileJson):
</instance>
</instance>
'''
'''
parameter_file_suffix
=
'.xml'
parameter_file_suffix
=
'.xml'
class
TestCliRequestForceSerialisation
(
TestCliRequestParameterFile
):
"""Request with --parameter-file, with a .json file, enforcing
serialisation with --force-serialisation.
"""
parameter_file_suffix
=
'.json'
parameter_file_content
=
'''
\
{
"foo": ["bar"]
}
'''
expected_partition_parameter_kw
=
{
"_"
:
"{
\
"
foo
\
"
: [
\
"
bar
\
"
]}"
}
def
test_request_parameters_file
(
self
):
self
.
_request_parameters_file_setup
()
self
.
conf
.
force_serialisation
=
'json-in-xml'
with
patch
.
object
(
slapos
.
slap
.
slap
,
'registerOpenOrder'
,
return_value
=
mock
.
create_autospec
(
slapos
.
slap
.
OpenOrder
))
as
registerOpenOrder
:
slapos
.
cli
.
request
.
do_request
(
self
.
logger
,
self
.
conf
,
self
.
local
)
registerOpenOrder
().
request
.
assert_called_once_with
(
software_release
=
'software URL'
,
partition_reference
=
'instance reference'
,
partition_parameter_kw
=
self
.
expected_partition_parameter_kw
,
software_type
=
None
,
filter_kw
=
{
'computer_guid'
:
'COMP-1234'
},
state
=
None
,
shared
=
False
,
)
self
.
logger
.
info
.
assert_any_call
(
'Requesting %s as instance of %s...'
,
'instance reference'
,
'software URL'
,
)
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