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
1
Merge Requests
1
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
Romain Courteaud
slapos.core
Commits
9a79de52
Commit
9a79de52
authored
Dec 11, 2024
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_json_rpc_api: test bang + use jIOWebSection_getObjectFromData
parent
eedac28e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
42 deletions
+60
-42
master/bt5/slapos_json_rpc_api/PathTemplateItem/portal_callables/ComputeNode_updateFromJSON.xml
...plateItem/portal_callables/ComputeNode_updateFromJSON.xml
+1
-1
master/bt5/slapos_json_rpc_api/SkinTemplateItem/portal_skins/slapos_jio_api/ComputeNode_updateFromAPIDict.py
...tal_skins/slapos_jio_api/ComputeNode_updateFromAPIDict.py
+10
-9
master/bt5/slapos_json_rpc_api/SkinTemplateItem/portal_skins/slapos_jio_api/jIOWebSection_createSoftwareInstallation.py
...lapos_jio_api/jIOWebSection_createSoftwareInstallation.py
+1
-11
master/bt5/slapos_json_rpc_api/SkinTemplateItem/portal_skins/slapos_jio_api/jIOWebSection_getObjectFromData.py
...l_skins/slapos_jio_api/jIOWebSection_getObjectFromData.py
+12
-2
master/bt5/slapos_json_rpc_api/TestTemplateItem/portal_components/test.erp5.testSlapOSJsonRpc.py
...lateItem/portal_components/test.erp5.testSlapOSJsonRpc.py
+36
-19
No files found.
master/bt5/slapos_json_rpc_api/PathTemplateItem/portal_callables/ComputeNode_updateFromJSON.xml
View file @
9a79de52
...
@@ -56,7 +56,7 @@
...
@@ -56,7 +56,7 @@
"title": "Success Message",\n
"title": "Success Message",\n
"type": "string",\n
"type": "string",\n
"description": "Success Message"\n
"description": "Success Message"\n
}
,
\n
}\n
}\n
}\n
}\n
}\n
</string>
</value>
</string>
</value>
...
...
master/bt5/slapos_json_rpc_api/SkinTemplateItem/portal_skins/slapos_jio_api/ComputeNode_updateFromAPIDict.py
View file @
9a79de52
compute_node
=
context
.
jIOWebSection_getObjectFromData
(
data_dict
)
def
compareAndUpdateAddressList
(
partition
,
partition_ip_list
):
def
compareAndUpdateAddressList
(
partition
,
partition_ip_list
):
to_delete_ip_id_list
=
[]
to_delete_ip_id_list
=
[]
to_add_ip_dict_list
=
partition_ip_list
[:]
to_add_ip_dict_list
=
partition_ip_list
[:]
...
@@ -43,28 +45,28 @@ def compareAndUpdateAddressList(partition, partition_ip_list):
...
@@ -43,28 +45,28 @@ def compareAndUpdateAddressList(partition, partition_ip_list):
partition
.
deleteContent
(
to_delete_ip_id_list
)
partition
.
deleteContent
(
to_delete_ip_id_list
)
if
"bang_status_message"
in
data_dict
:
if
"bang_status_message"
in
data_dict
:
co
ntext
.
reportComputeNodeBang
(
comment
=
data_dict
[
"bang_status_message"
])
co
mpute_node
.
reportComputeNodeBang
(
comment
=
data_dict
[
"bang_status_message"
])
# Getting existing partitions
# Getting existing partitions
existing_partition_dict
=
{}
existing_partition_dict
=
{}
for
c
in
co
ntext
.
contentValues
(
portal_type
=
"Compute Partition"
):
for
c
in
co
mpute_node
.
contentValues
(
portal_type
=
"Compute Partition"
):
existing_partition_dict
[
c
.
getReference
()]
=
c
existing_partition_dict
[
c
.
getReference
()]
=
c
# update compute_node data
# update compute_node data
edit_kw
=
{}
edit_kw
=
{}
quantity
=
len
(
data_dict
.
get
(
'compute_partition_list'
,
[]))
quantity
=
len
(
data_dict
.
get
(
'compute_partition_list'
,
[]))
if
co
ntext
.
getQuantity
()
!=
quantity
:
if
co
mpute_node
.
getQuantity
()
!=
quantity
:
edit_kw
[
'quantity'
]
=
quantity
edit_kw
[
'quantity'
]
=
quantity
if
edit_kw
:
if
edit_kw
:
co
ntext
.
edit
(
**
edit_kw
)
co
mpute_node
.
edit
(
**
edit_kw
)
expected_partition_dict
=
{}
expected_partition_dict
=
{}
for
send_partition
in
data_dict
.
get
(
'compute_partition_list'
,
[]):
for
send_partition
in
data_dict
.
get
(
'compute_partition_list'
,
[]):
partition
=
existing_partition_dict
.
get
(
send_partition
[
'partition_id'
],
None
)
partition
=
existing_partition_dict
.
get
(
send_partition
[
'partition_id'
],
None
)
expected_partition_dict
[
send_partition
[
'partition_id'
]]
=
True
expected_partition_dict
[
send_partition
[
'partition_id'
]]
=
True
if
partition
is
None
:
if
partition
is
None
:
partition
=
co
ntext
.
newContent
(
portal_type
=
'Compute Partition'
)
partition
=
co
mpute_node
.
newContent
(
portal_type
=
'Compute Partition'
)
partition
.
validate
()
partition
.
validate
()
partition
.
markFree
()
partition
.
markFree
()
elif
partition
.
getSlapState
()
==
'inactive'
:
elif
partition
.
getSlapState
()
==
'inactive'
:
...
@@ -85,11 +87,10 @@ for key, value in existing_partition_dict.items():
...
@@ -85,11 +87,10 @@ for key, value in existing_partition_dict.items():
if
value
.
getValidationState
()
==
"validated"
:
if
value
.
getValidationState
()
==
"validated"
:
value
.
invalidate
(
comment
=
"Desactivated by slapformat"
)
value
.
invalidate
(
comment
=
"Desactivated by slapformat"
)
import
json
return
{
return
json
.
dumps
({
"$schema"
:
json_form
.
absolute_url
().
strip
()
+
"/getOutputJSONSchema"
,
"$schema"
:
json_form
.
absolute_url
().
strip
()
+
"/getOutputJSONSchema"
,
"compute_node_id"
:
co
ntext
.
getReference
(),
"compute_node_id"
:
co
mpute_node
.
getReference
(),
"date"
:
str
(
DateTime
()),
"date"
:
str
(
DateTime
()),
"portal_type"
:
"Compute Node"
,
"portal_type"
:
"Compute Node"
,
"success"
:
"Done"
"success"
:
"Done"
}
,
indent
=
2
)
}
master/bt5/slapos_json_rpc_api/SkinTemplateItem/portal_skins/slapos_jio_api/jIOWebSection_createSoftwareInstallation.py
View file @
9a79de52
from
erp5.component.document.JsonRpcAPIService
import
JsonRpcAPIError
from
erp5.component.document.JsonRpcAPIService
import
JsonRpcAPIError
class
ComputeNodeNotFoundError
(
JsonRpcAPIError
):
type
=
"COMPUTE-NODE-NOT-FOUND"
status
=
403
class
RequestFailsError
(
JsonRpcAPIError
):
class
RequestFailsError
(
JsonRpcAPIError
):
type
=
"SUPPLY-FAILED"
type
=
"SUPPLY-FAILED"
status
=
403
status
=
403
compute_node
=
context
.
getPortalObject
().
portal_catalog
.
getResultValue
(
compute_node
=
context
.
jIOWebSection_getObjectFromData
(
data_dict
)
portal_type
=
'Compute Node'
,
validation_state
=
"validated"
,
reference
=
data_dict
[
"compute_node_id"
],
)
if
not
compute_node
:
raise
ComputeNodeNotFoundError
(
"Compute Node '%s' not found"
%
data_dict
[
"compute_node_id"
])
compute_node
.
requestSoftwareRelease
(
compute_node
.
requestSoftwareRelease
(
software_release_url
=
data_dict
[
"software_release_uri"
],
software_release_url
=
data_dict
[
"software_release_uri"
],
...
...
master/bt5/slapos_json_rpc_api/SkinTemplateItem/portal_skins/slapos_jio_api/jIOWebSection_getObjectFromData.py
View file @
9a79de52
from
erp5.component.document.JsonRpcAPIService
import
JsonRpcAPIError
portal_type
=
data_dict
[
"portal_type"
]
portal_type
=
data_dict
[
"portal_type"
]
import
urllib
import
urllib
...
@@ -11,6 +13,11 @@ if portal_type == "Software Installation":
...
@@ -11,6 +13,11 @@ if portal_type == "Software Installation":
return
compute_node
.
getSoftwareInstallationFromUrl
(
urllib
.
unquote
(
data_dict
[
"software_release_uri"
]))
return
compute_node
.
getSoftwareInstallationFromUrl
(
urllib
.
unquote
(
data_dict
[
"software_release_uri"
]))
elif
portal_type
==
"Compute Node"
:
elif
portal_type
==
"Compute Node"
:
class
ComputeNodeNotFoundError
(
JsonRpcAPIError
):
type
=
"COMPUTE-NODE-NOT-FOUND"
status
=
403
if
"compute_node_id"
in
data_dict
:
if
"compute_node_id"
in
data_dict
:
compute_node_id
=
data_dict
[
"compute_node_id"
]
compute_node_id
=
data_dict
[
"compute_node_id"
]
user
=
portal
.
portal_membership
.
getAuthenticatedMember
().
getUserName
()
user
=
portal
.
portal_membership
.
getAuthenticatedMember
().
getUserName
()
...
@@ -21,6 +28,7 @@ elif portal_type == "Compute Node":
...
@@ -21,6 +28,7 @@ elif portal_type == "Compute Node":
compute_node
=
portal
.
portal_catalog
.
getComputeNodeObject
(
compute_node_id
)
compute_node
=
portal
.
portal_catalog
.
getComputeNodeObject
(
compute_node_id
)
if
compute_node
:
if
compute_node
:
return
compute_node
return
compute_node
raise
ComputeNodeNotFoundError
(
"Compute Node '%s' not found"
%
data_dict
[
"compute_node_id"
])
elif
portal_type
==
"Software Instance"
:
elif
portal_type
==
"Software Instance"
:
if
"reference"
in
data_dict
:
if
"reference"
in
data_dict
:
...
@@ -50,5 +58,7 @@ elif portal_type == "Software Instance Certificate Record":
...
@@ -50,5 +58,7 @@ elif portal_type == "Software Instance Certificate Record":
portal_type
=
"Software Instance Certificate Record"
,
portal_type
=
"Software Instance Certificate Record"
,
)
)
class
ObjectNotFoundError
(
JsonRpcAPIError
):
return
None
type
=
"OBJECT-NODE-NOT-FOUND"
status
=
403
raise
ObjectNotFoundError
(
"Object not found"
)
master/bt5/slapos_json_rpc_api/TestTemplateItem/portal_components/test.erp5.testSlapOSJsonRpc.py
View file @
9a79de52
...
@@ -1253,30 +1253,47 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSJsonRpcMixin):
...
@@ -1253,30 +1253,47 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSJsonRpcMixin):
self
.
person_user_id
=
self
.
person
.
getUserId
()
self
.
person_user_id
=
self
.
person
.
getUserId
()
def
test_30_computerBang
(
self
):
def
test_30_computerBang
(
self
):
self
.
called_banged_kw
=
""
def
calledBang
(
*
args
,
**
kw
):
self
.
called_banged_kw
=
kw
start_date
=
DateTime
()
start_date
=
DateTime
()
try
:
# XXX XXX XXX TODO pin datetime to check the result
reportComputeNodeBang
=
self
.
compute_node
.
__class__
.
reportComputeNodeBang
error_log
=
'Please force slapos node rerun'
self
.
compute_node
.
__class__
.
reportComputeNodeBang
=
calledBang
response
=
self
.
callJsonRpcWebService
(
self
.
login
(
self
.
person_user_id
)
"slapos.put.slapos_jio_api_put_compute_node"
,
error_log
=
'Please bang me'
{
response
=
self
.
callJsonRpcWebService
(
"slapos.put.slapos_jio_api_put_compute_node"
,
{
"compute_node_id"
:
self
.
compute_node_id
,
"compute_node_id"
:
self
.
compute_node_id
,
"portal_type"
:
"Compute Node"
,
"portal_type"
:
"Compute Node"
,
"bang_status_message"
:
error_log
,
"bang_status_message"
:
error_log
,
})
},
response_dict
=
json
.
loads
(
response
.
getBody
())
self
.
person_user_id
self
.
assertEqual
(
self
.
called_banged_kw
,
{
"comment"
:
error_log
})
)
self
.
assertEqual
(
response_dict
[
"compute_node_id"
],
self
.
compute_node
.
getReference
())
response_dict
=
json
.
loads
(
response
.
getBody
())
self
.
assertEqual
(
response_dict
[
"success"
],
"Done"
)
self
.
assertEqual
(
'application/json'
,
response
.
headers
.
get
(
'content-type'
))
self
.
assertEqual
(
response_dict
[
"portal_type"
],
"Compute Node"
)
"""
self
.
assertTrue
(
response_dict
[
"$schema"
].
endswith
(
"ComputeNode_updateFromJSON/getOutputJSONSchema"
))
self.assertEqual(
self
.
assertTrue
(
DateTime
(
response_dict
[
"date"
])
>=
start_date
)
response.getBody(),
finally
:
json.dumps(
self
.
compute_node
.
__class__
.
reportComputeNodeBang
=
reportComputeNodeBang
{
'type': 'success-type',
'title': "query completed",
'status': 200
}).encode())"""
self
.
assertEqual
(
response
.
getStatus
(),
200
)
self
.
assertEqual
(
response_dict
[
"compute_node_id"
],
self
.
compute_node
.
getReference
().
decode
(
'UTF-8'
))
self
.
assertEqual
(
response_dict
[
"success"
],
"Done"
)
self
.
assertEqual
(
response_dict
[
"portal_type"
],
"Compute Node"
)
self
.
assertTrue
(
response_dict
[
"$schema"
].
endswith
(
"ComputeNode_updateFromJSON/getOutputJSONSchema"
))
self
.
assertTrue
(
DateTime
(
response_dict
[
"date"
])
>=
start_date
)
portal_workflow
=
self
.
portal
.
portal_workflow
comment
=
portal_workflow
.
getInfoFor
(
ob
=
self
.
compute_node
,
name
=
'comment'
,
wf_id
=
'compute_node_slap_interface_workflow'
)
self
.
assertEqual
(
comment
,
error_log
)
action_id
=
portal_workflow
.
getInfoFor
(
ob
=
self
.
compute_node
,
name
=
'action'
,
wf_id
=
'compute_node_slap_interface_workflow'
)
self
.
assertEqual
(
action_id
,
'report_compute_node_bang'
)
def
test_31_getInstanceWithSharedInstance
(
self
,
with_slave
=
True
):
def
test_31_getInstanceWithSharedInstance
(
self
,
with_slave
=
True
):
self
.
_makeComplexComputeNode
(
self
.
project
,
person
=
self
.
person
,
with_slave
=
with_slave
)
self
.
_makeComplexComputeNode
(
self
.
project
,
person
=
self
.
person
,
with_slave
=
with_slave
)
...
...
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