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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
slapos
Commits
2967180b
Commit
2967180b
authored
Oct 05, 2022
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
request: Add first test
parent
6d772baa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
4 deletions
+87
-4
slapos/recipe/request.py
slapos/recipe/request.py
+5
-3
slapos/test/recipe/test_request.py
slapos/test/recipe/test_request.py
+79
-1
slapos/test/recipe/test_slaposconfiguration.py
slapos/test/recipe/test_slaposconfiguration.py
+3
-0
No files found.
slapos/recipe/request.py
View file @
2967180b
...
@@ -166,6 +166,8 @@ class Recipe(object):
...
@@ -166,6 +166,8 @@ class Recipe(object):
"software_type"
:
software_type
,
"software_type"
:
software_type
,
"software_release_uri"
:
software_url
,
"software_release_uri"
:
software_url
,
"portal_type"
:
"Software Instance"
,
"portal_type"
:
"Software Instance"
,
"compute_node_id"
:
options
[
'computer-id'
],
"compute_partition_id"
:
options
[
'partition-id'
],
}
}
if
partition_parameter_kw
:
if
partition_parameter_kw
:
request_dict
[
"parameters"
]
=
json
.
dumps
(
partition_parameter_kw
)
request_dict
[
"parameters"
]
=
json
.
dumps
(
partition_parameter_kw
)
...
@@ -206,8 +208,8 @@ class Recipe(object):
...
@@ -206,8 +208,8 @@ class Recipe(object):
options
[
'instance-guid'
]
=
partition_dict
[
"reference"
]
options
[
'instance-guid'
]
=
partition_dict
[
"reference"
]
# XXX: deprecated, to be removed
# XXX: deprecated, to be removed
options
[
'instance_guid'
]
=
options
[
'instance-guid'
]
options
[
'instance_guid'
]
=
options
[
'instance-guid'
]
options
[
'instance-state'
]
=
options
[
'state'
]
options
[
'instance-state'
]
=
partition_dict
[
'state'
]
options
[
'instance-status'
]
=
options
.
get
(
'access_status_message'
)
options
[
'instance-status'
]
=
partition_dict
.
get
(
'access_status_message'
)
else
:
else
:
# Try to do the request and fetch parameter dict...
# Try to do the request and fetch parameter dict...
...
@@ -275,7 +277,7 @@ class Recipe(object):
...
@@ -275,7 +277,7 @@ class Recipe(object):
def
_getFilteredParameterDict
(
self
,
partition_dict
,
return_parameter_list
):
def
_getFilteredParameterDict
(
self
,
partition_dict
,
return_parameter_list
):
result
=
{}
result
=
{}
parameters
=
json_loads_byteified
(
partition
.
get
(
"parameters"
,
"{}"
))
parameters
=
json_loads_byteified
(
partition
_dict
.
get
(
"parameters"
,
"{}"
))
for
key
in
return_parameter_list
:
for
key
in
return_parameter_list
:
if
key
in
parameters
:
if
key
in
parameters
:
result
[
key
]
=
parameters
[
"key"
]
result
[
key
]
=
parameters
[
"key"
]
...
...
slapos/test/recipe/test_request.py
View file @
2967180b
import
httmock
import
json
import
mock
import
mock
import
unittest
import
unittest
from
collections
import
defaultdict
from
collections
import
defaultdict
...
@@ -153,4 +155,80 @@ class RequestOptionalJSONEncodedTest(RecipeTestMixin, unittest.TestCase):
...
@@ -153,4 +155,80 @@ class RequestOptionalJSONEncodedTest(RecipeTestMixin, unittest.TestCase):
called_partition_parameter_kw
=
{
'_'
:
'{}'
}
called_partition_parameter_kw
=
{
'_'
:
'{}'
}
class
RecipejIOTestMixin
:
class
RecipejIOTestMixin
:
pass
\ No newline at end of file
def
setUp
(
self
):
self
.
buildout
=
{
"buildout"
:
{
},
"slap-connection"
:
{
}
}
self
.
parameter_dict
=
{
"foo"
:
"bar"
,
"hello"
:
"bye"
}
self
.
instance_data
=
{
"reference"
:
"SOFTINST-12"
,
"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
(
self
.
parameter_dict
),
"connection_parameters"
:
self
.
connection_parameter_dict
,
}
self
.
options
=
{
"server-url"
:
"http://127.0.0.1:80"
,
"name"
:
self
.
instance_data
[
"title"
],
"software-instance-reference"
:
"SOFTINST-12"
,
"computer-id"
:
self
.
instance_data
[
"compute_node_id"
],
"partition-id"
:
self
.
instance_data
[
"compute_partition_id"
],
"software-url"
:
self
.
instance_data
[
"software_release_uri"
],
}
def
test_no_return_in_options_logs
(
self
):
api_handler
=
APIRequestHandler
([
(
"/api/get"
,
json
.
dumps
(
self
.
instance_data
)),
])
with
httmock
.
HTTMock
(
api_handler
.
request_handler
):
with
LogCapture
()
as
log
:
#import pdb; pdb.set_trace()
self
.
recipe
(
self
.
buildout
,
"request"
,
self
.
options
)
log
.
check
(
(
'request'
,
'DEBUG'
,
'No parameter to return to main instance.Be careful about that...'
),
)
self
.
assertEqual
(
api_handler
.
request_payload_list
[
0
],
json
.
dumps
({
"software_release_uri"
:
"foo.cfg"
,
"title"
:
"MyInstance"
,
"portal_type"
:
"Software Instance"
,
"compute_partition_id"
:
"slappartx12"
,
"state"
:
"started"
,
"compute_node_id"
:
"COMP-321"
,
"software_type"
:
"RootSoftwareInstance"
}))
def
test_return_in_options_logs
(
self
):
pass
def
test_return_not_ready
(
self
):
pass
def
test_return_ready
(
self
):
pass
class
RequestjIOTest
(
RecipejIOTestMixin
,
unittest
.
TestCase
):
recipe
=
request
.
Recipe
connection_parameter_dict_empty
=
{}
connection_parameter_dict
=
{
"foo"
:
"bar"
}
slapos/test/recipe/test_slaposconfiguration.py
View file @
2967180b
...
@@ -15,8 +15,10 @@ class APIRequestHandler(object):
...
@@ -15,8 +15,10 @@ class APIRequestHandler(object):
def
__init__
(
self
,
response_list
):
def
__init__
(
self
,
response_list
):
self
.
response_list
=
response_list
self
.
response_list
=
response_list
self
.
request_payload_list
=
[]
self
.
request_payload_list
=
[]
self
.
sequence_list
=
[]
def
request_handler
(
self
,
url
,
req
):
def
request_handler
(
self
,
url
,
req
):
self
.
sequence_list
.
append
(
url
.
path
)
if
url
.
path
==
"/getHateoasUrl"
:
if
url
.
path
==
"/getHateoasUrl"
:
return
""
return
""
elif
url
.
path
==
"/getJIOAPIUrl"
:
elif
url
.
path
==
"/getJIOAPIUrl"
:
...
@@ -25,6 +27,7 @@ class APIRequestHandler(object):
...
@@ -25,6 +27,7 @@ class APIRequestHandler(object):
if
not
self
.
response_list
and
self
.
response_list
[
0
][
0
]
!=
url
.
path
:
if
not
self
.
response_list
and
self
.
response_list
[
0
][
0
]
!=
url
.
path
:
raise
ValueError
(
"Unexcpected call: %s %s"
%
(
url
.
path
,
req
.
body
))
raise
ValueError
(
"Unexcpected call: %s %s"
%
(
url
.
path
,
req
.
body
))
self
.
request_payload_list
.
append
(
req
.
body
)
return
self
.
response_list
.
pop
(
0
)[
1
]
return
self
.
response_list
.
pop
(
0
)[
1
]
...
...
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