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
Boxiang Sun
slapos.core
Commits
e4681d73
Commit
e4681d73
authored
Feb 13, 2025
by
Rafael Monnerat
👻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py3: Fixup some py3 bytes x str inconsistencies
parent
51230a65
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
20 deletions
+22
-20
master/bt5/slapos_cloud/TestTemplateItem/portal_components/test.erp5.SlapOSTestCaseDefaultScenarioMixin.py
...omponents/test.erp5.SlapOSTestCaseDefaultScenarioMixin.py
+8
-8
master/bt5/slapos_slap_tool/ToolComponentTemplateItem/portal_components/tool.erp5.SlapTool.py
...onentTemplateItem/portal_components/tool.erp5.SlapTool.py
+14
-12
No files found.
master/bt5/slapos_cloud/TestTemplateItem/portal_components/test.erp5.SlapOSTestCaseDefaultScenarioMixin.py
View file @
e4681d73
...
@@ -25,7 +25,7 @@ from erp5.component.test.testSlapOSCloudSecurityGroup import TestSlapOSSecurityM
...
@@ -25,7 +25,7 @@ from erp5.component.test.testSlapOSCloudSecurityGroup import TestSlapOSSecurityM
from
erp5.component.test.SlapOSTestCaseMixin
import
changeSkin
from
erp5.component.test.SlapOSTestCaseMixin
import
changeSkin
import
re
import
re
from
slapos.util
import
dumps
,
loads
from
slapos.util
import
dumps
,
loads
from
Products.ERP5Type.Utils
import
str2bytes
from
Products.ERP5Type.Utils
import
str2bytes
,
bytes2str
from
AccessControl.SecurityManagement
import
getSecurityManager
,
\
from
AccessControl.SecurityManagement
import
getSecurityManager
,
\
setSecurityManager
setSecurityManager
...
@@ -229,7 +229,7 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -229,7 +229,7 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
try
:
try
:
self
.
login
(
compute_node
.
getUserId
())
self
.
login
(
compute_node
.
getUserId
())
self
.
portal
.
portal_slap
.
loadComputerConfigurationFromXML
(
self
.
portal
.
portal_slap
.
loadComputerConfigurationFromXML
(
dumps
(
compute_node_dict
))
bytes2str
(
dumps
(
compute_node_dict
)
))
self
.
tic
()
self
.
tic
()
self
.
assertEqual
(
partition_count
,
self
.
assertEqual
(
partition_count
,
len
(
compute_node
.
contentValues
(
portal_type
=
'Compute Partition'
)))
len
(
compute_node
.
contentValues
(
portal_type
=
'Compute Partition'
)))
...
@@ -276,9 +276,9 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -276,9 +276,9 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
if
partition
.
_requested_state
==
'destroyed'
\
if
partition
.
_requested_state
==
'destroyed'
\
and
partition
.
_need_modification
==
1
:
and
partition
.
_need_modification
==
1
:
self
.
portal
.
portal_slap
.
destroyedComputerPartition
(
compute_node
.
getReference
(),
self
.
portal
.
portal_slap
.
destroyedComputerPartition
(
compute_node
.
getReference
(),
partition
.
_partition_id
.
encode
(
"UTF-8"
)
partition
.
_partition_id
)
)
destroyed_partition_id_list
.
append
(
partition
.
_partition_id
.
encode
(
"UTF-8"
)
)
destroyed_partition_id_list
.
append
(
partition
.
_partition_id
)
finally
:
finally
:
setSecurityManager
(
sm
)
setSecurityManager
(
sm
)
self
.
tic
()
self
.
tic
()
...
@@ -306,10 +306,10 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -306,10 +306,10 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
and
partition
.
_need_modification
==
1
:
and
partition
.
_need_modification
==
1
:
instance_reference
=
partition
.
_instance_guid
.
encode
(
'UTF-8'
)
instance_reference
=
partition
.
_instance_guid
.
encode
(
'UTF-8'
)
ip_list
=
partition
.
_parameter_dict
[
'ip_list'
]
ip_list
=
partition
.
_parameter_dict
[
'ip_list'
]
connection_xml
=
dumps
(
dict
(
connection_xml
=
bytes2str
(
dumps
(
dict
(
url_1
=
'http://%s/'
%
ip_list
[
0
][
1
],
url_1
=
'http://%s/'
%
ip_list
[
0
][
1
],
url_2
=
'http://%s/'
%
ip_list
[
1
][
1
],
url_2
=
'http://%s/'
%
ip_list
[
1
][
1
],
))
))
)
self
.
login
()
self
.
login
()
instance_user_id
=
self
.
portal
.
portal_catalog
.
getResultValue
(
instance_user_id
=
self
.
portal
.
portal_catalog
.
getResultValue
(
reference
=
instance_reference
,
portal_type
=
"Software Instance"
).
getUserId
()
reference
=
instance_reference
,
portal_type
=
"Software Instance"
).
getUserId
()
...
@@ -324,10 +324,10 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -324,10 +324,10 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
)
)
for
slave
in
partition
.
_parameter_dict
[
'slave_instance_list'
]:
for
slave
in
partition
.
_parameter_dict
[
'slave_instance_list'
]:
slave_reference
=
slave
[
'slave_reference'
]
slave_reference
=
slave
[
'slave_reference'
]
connection_xml
=
dumps
(
dict
(
connection_xml
=
bytes2str
(
dumps
(
dict
(
url_1
=
'http://%s/%s'
%
(
ip_list
[
0
][
1
],
slave_reference
),
url_1
=
'http://%s/%s'
%
(
ip_list
[
0
][
1
],
slave_reference
),
url_2
=
'http://%s/%s'
%
(
ip_list
[
1
][
1
],
slave_reference
)
url_2
=
'http://%s/%s'
%
(
ip_list
[
1
][
1
],
slave_reference
)
))
))
)
self
.
portal
.
portal_slap
.
setComputerPartitionConnectionXml
(
self
.
portal
.
portal_slap
.
setComputerPartitionConnectionXml
(
computer_id
=
compute_node_reference
,
computer_id
=
compute_node_reference
,
computer_partition_id
=
partition
.
_partition_id
,
computer_partition_id
=
partition
.
_partition_id
,
...
...
master/bt5/slapos_slap_tool/ToolComponentTemplateItem/portal_components/tool.erp5.SlapTool.py
View file @
e4681d73
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
#
#
##############################################################################
##############################################################################
from
Products.ERP5Type.Utils
import
str2unicode
from
Products.ERP5Type.Utils
import
str2unicode
,
bytes2str
,
str2bytes
from
AccessControl
import
ClassSecurityInfo
from
AccessControl
import
ClassSecurityInfo
from
AccessControl
import
Unauthorized
from
AccessControl
import
Unauthorized
from
OFS.Traversable
import
NotFound
from
OFS.Traversable
import
NotFound
...
@@ -75,7 +75,7 @@ except ImportError:
...
@@ -75,7 +75,7 @@ except ImportError:
from
zLOG
import
LOG
,
INFO
from
zLOG
import
LOG
,
INFO
from
six
import
StringIO
import
six
import
pkg_resources
import
pkg_resources
from
DateTime
import
DateTime
from
DateTime
import
DateTime
from
App.Common
import
rfc1123_date
from
App.Common
import
rfc1123_date
...
@@ -112,13 +112,15 @@ def convertToREST(function):
...
@@ -112,13 +112,15 @@ def convertToREST(function):
raise
Unauthorized
raise
Unauthorized
self
.
REQUEST
.
response
.
setHeader
(
'Content-Type'
,
'text/xml; charset=utf-8'
)
self
.
REQUEST
.
response
.
setHeader
(
'Content-Type'
,
'text/xml; charset=utf-8'
)
if
isinstance
(
retval
,
bytes
):
return
'%s'
%
bytes2str
(
retval
)
return
'%s'
%
retval
return
'%s'
%
retval
wrapper
.
__doc__
=
function
.
__doc__
wrapper
.
__doc__
=
function
.
__doc__
return
wrapper
return
wrapper
def
castToStr
(
dict_kw
):
def
castToStr
(
dict_kw
):
instance
=
etree
.
Element
(
'instance'
)
instance
=
etree
.
Element
(
'instance'
)
for
_id
,
_value
in
dict_kw
.
iteritems
(
):
for
_id
,
_value
in
six
.
iteritems
(
dict_kw
):
# cast everything to string.
# cast everything to string.
text
=
_value
text
=
_value
if
not
isinstance
(
_value
,
str
):
if
not
isinstance
(
_value
,
str
):
...
@@ -690,7 +692,7 @@ class SlapTool(BaseTool):
...
@@ -690,7 +692,7 @@ class SlapTool(BaseTool):
'loadComputerConfigurationFromXML'
)
'loadComputerConfigurationFromXML'
)
def
loadComputerConfigurationFromXML
(
self
,
xml
):
def
loadComputerConfigurationFromXML
(
self
,
xml
):
"Load the given xml as configuration for the compute_node object"
"Load the given xml as configuration for the compute_node object"
compute_node_dict
=
loads
(
xml
)
compute_node_dict
=
loads
(
str2bytes
(
xml
)
)
compute_node
=
self
.
getPortalObject
().
portal_catalog
.
getComputeNodeObject
(
compute_node_dict
[
'reference'
])
compute_node
=
self
.
getPortalObject
().
portal_catalog
.
getComputeNodeObject
(
compute_node_dict
[
'reference'
])
compute_node
.
ComputeNode_updateFromDict
(
compute_node_dict
)
compute_node
.
ComputeNode_updateFromDict
(
compute_node_dict
)
return
'Content properly posted.'
return
'Content properly posted.'
...
@@ -771,11 +773,11 @@ class SlapTool(BaseTool):
...
@@ -771,11 +773,11 @@ class SlapTool(BaseTool):
def
_validateXML
(
self
,
to_be_validated
,
xsd_model
):
def
_validateXML
(
self
,
to_be_validated
,
xsd_model
):
"""Will validate the xml file"""
"""Will validate the xml file"""
#We parse the XSD model
#We parse the XSD model
xsd_model
=
StringIO
(
xsd_model
)
xsd_model
=
six
.
StringIO
(
xsd_model
)
xmlschema_doc
=
etree
.
parse
(
xsd_model
)
xmlschema_doc
=
etree
.
parse
(
xsd_model
)
xmlschema
=
etree
.
XMLSchema
(
xmlschema_doc
)
xmlschema
=
etree
.
XMLSchema
(
xmlschema_doc
)
string_to_validate
=
StringIO
(
to_be_validated
)
string_to_validate
=
six
.
StringIO
(
to_be_validated
)
try
:
try
:
document
=
etree
.
parse
(
string_to_validate
)
document
=
etree
.
parse
(
string_to_validate
)
...
@@ -927,7 +929,7 @@ class SlapTool(BaseTool):
...
@@ -927,7 +929,7 @@ class SlapTool(BaseTool):
compute_node_id
,
compute_node_id
,
compute_partition_id
,
compute_partition_id
,
slave_reference
)
slave_reference
)
connection_xml
=
dict2xml
(
loads
(
connection_xml
))
connection_xml
=
dict2xml
(
loads
(
str2bytes
(
connection_xml
)
))
if
not
software_instance
.
isLastData
(
value
=
connection_xml
):
if
not
software_instance
.
isLastData
(
value
=
connection_xml
):
software_instance
.
updateConnection
(
software_instance
.
updateConnection
(
connection_xml
=
connection_xml
,
connection_xml
=
connection_xml
,
...
@@ -952,19 +954,19 @@ class SlapTool(BaseTool):
...
@@ -952,19 +954,19 @@ class SlapTool(BaseTool):
In any other case returns not important data and HTTP code is 403 Forbidden
In any other case returns not important data and HTTP code is 403 Forbidden
"""
"""
if
state
:
if
state
:
state
=
loads
(
st
ate
)
state
=
loads
(
st
r2bytes
(
state
)
)
if
state
is
None
:
if
state
is
None
:
state
=
'started'
state
=
'started'
if
shared_xml
is
not
_MARKER
:
if
shared_xml
is
not
_MARKER
:
shared
=
loads
(
s
hared_xml
)
shared
=
loads
(
s
tr2bytes
(
shared_xml
)
)
else
:
else
:
shared
=
False
shared
=
False
if
partition_parameter_xml
:
if
partition_parameter_xml
:
partition_parameter_kw
=
loads
(
partition_parameter_xml
)
partition_parameter_kw
=
loads
(
str2bytes
(
partition_parameter_xml
)
)
else
:
else
:
partition_parameter_kw
=
dict
()
partition_parameter_kw
=
dict
()
if
filter_xml
:
if
filter_xml
:
filter_kw
=
loads
(
filter_xml
)
filter_kw
=
loads
(
str2bytes
(
filter_xml
)
)
if
software_type
==
'pull-backup'
and
not
'retention_delay'
in
filter_kw
:
if
software_type
==
'pull-backup'
and
not
'retention_delay'
in
filter_kw
:
filter_kw
[
'retention_delay'
]
=
7.0
filter_kw
[
'retention_delay'
]
=
7.0
else
:
else
:
...
@@ -1109,7 +1111,7 @@ class SlapTool(BaseTool):
...
@@ -1109,7 +1111,7 @@ class SlapTool(BaseTool):
slap_software_release
.
_known_state
=
software_release_dict
[
'_known_state'
]
slap_software_release
.
_known_state
=
software_release_dict
[
'_known_state'
]
slap_compute_node
.
_software_release_list
.
append
(
slap_software_release
)
slap_compute_node
.
_software_release_list
.
append
(
slap_software_release
)
return
dumps
(
slap_compute_node
)
return
bytes2str
(
dumps
(
slap_compute_node
)
)
def
_getSoftwareInstanceForComputePartition
(
self
,
compute_node_id
,
def
_getSoftwareInstanceForComputePartition
(
self
,
compute_node_id
,
compute_partition_id
,
slave_reference
=
None
):
compute_partition_id
,
slave_reference
=
None
):
...
...
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