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
Labels
Merge Requests
18
Merge Requests
18
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos.core
Commits
80cf8cf1
Commit
80cf8cf1
authored
Jul 28, 2021
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cli/request: automatically deserialize json-in-xml connection parameter dict
This is more readable
parent
98c41a27
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
1 deletion
+60
-1
slapos/cli/request.py
slapos/cli/request.py
+5
-1
slapos/tests/test_cli.py
slapos/tests/test_cli.py
+55
-0
No files found.
slapos/cli/request.py
View file @
80cf8cf1
...
...
@@ -163,7 +163,11 @@ def do_request(logger, conf, local):
)
logger
.
info
(
'Instance requested.
\
n
State is : %s.'
,
partition
.
getState
())
logger
.
info
(
'Connection parameters of instance are:'
)
logger
.
info
(
pprint
.
pformat
(
partition
.
getConnectionParameterDict
()))
connection_parameter_dict
=
partition
.
getConnectionParameterDict
()
if
software_schema_serialisation
==
SoftwareReleaseSerialisation
.
JsonInXml
:
if
'_'
in
connection_parameter_dict
:
connection_parameter_dict
=
json
.
loads
(
connection_parameter_dict
[
'_'
])
logger
.
info
(
pprint
.
pformat
(
connection_parameter_dict
))
logger
.
info
(
'You can rerun the command to get up-to-date information.'
)
except
ResourceNotReady
:
logger
.
warning
(
'Instance requested. Master is provisioning it. Please rerun in a '
...
...
slapos/tests/test_cli.py
View file @
80cf8cf1
...
...
@@ -25,6 +25,7 @@
#
##############################################################################
import
json
import
logging
import
pprint
import
unittest
...
...
@@ -40,6 +41,7 @@ from contextlib import contextmanager
from
mock
import
patch
,
create_autospec
import
mock
from
slapos.util
import
sqlite_connect
,
bytes2str
from
slapos.slap.slap
import
DEFAULT_SOFTWARE_TYPE
import
slapos.cli.console
import
slapos.cli.entry
...
...
@@ -691,6 +693,59 @@ class TestCliRequest(CliMixin):
'software URL'
,
)
def
test_request_json_in_xml_published_parameters
(
self
):
tmpdir
=
tempfile
.
mkdtemp
()
self
.
addCleanup
(
shutil
.
rmtree
,
tmpdir
)
with
open
(
os
.
path
.
join
(
tmpdir
,
'software.cfg.json'
),
'w'
)
as
f
:
json
.
dump
(
{
"name"
:
"Test Software"
,
"description"
:
"Dummy software for Test"
,
"serialisation"
:
"json-in-xml"
,
"software-type"
:
{
DEFAULT_SOFTWARE_TYPE
:
{
"title"
:
"Default"
,
"description"
:
"Default type"
,
"request"
:
"instance-default-input-schema.json"
,
"response"
:
"instance-default-output-schema.json"
,
"index"
:
0
},
}
},
f
)
self
.
conf
.
reference
=
'instance reference'
self
.
conf
.
software_url
=
os
.
path
.
join
(
tmpdir
,
'software.cfg'
)
self
.
conf
.
parameters
=
{
'key'
:
'value'
}
self
.
conf
.
parameters_file
=
None
self
.
conf
.
node
=
{
'computer_guid'
:
'COMP-1234'
}
self
.
conf
.
type
=
None
self
.
conf
.
state
=
None
self
.
conf
.
slave
=
False
cp
=
slapos
.
slap
.
ComputerPartition
(
'computer_%s'
%
self
.
id
(),
'partition_%s'
%
self
.
id
())
cp
.
_requested_state
=
'started'
cp
.
_connection_dict
=
{
'_'
:
json
.
dumps
({
'foo'
:
'bar'
})}
with
patch
.
object
(
slapos
.
slap
.
slap
,
'registerOpenOrder'
,
return_value
=
mock
.
create_autospec
(
slapos
.
slap
.
OpenOrder
))
as
registerOpenOrder
:
registerOpenOrder
().
request
.
return_value
=
cp
slapos
.
cli
.
request
.
do_request
(
self
.
logger
,
self
.
conf
,
self
.
local
)
registerOpenOrder
().
request
.
assert_called_once
()
self
.
assertEqual
(
self
.
logger
.
info
.
mock_calls
,
[
mock
.
call
(
'Requesting %s as instance of %s...'
,
self
.
conf
.
reference
,
self
.
conf
.
software_url
),
mock
.
call
(
'Instance requested.
\
n
State is : %s.'
,
'started'
),
mock
.
call
(
'Connection parameters of instance are:'
),
mock
.
call
(
"{'foo': 'bar'}"
),
mock
.
call
(
'You can rerun the command to get up-to-date information.'
),
])
class
TestCliRequestParametersFileJson
(
CliMixin
):
"""Request with --parameter-file, with a .json 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