Commit 04324a26 authored by Rafael Monnerat's avatar Rafael Monnerat

py3: Use unicode2str

parent b2db5730
......@@ -33,7 +33,7 @@ import collections
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from erp5.component.module.SlapOSCloud import _assertACI
from Products.ERP5Type.Utils import unicode2str
from zLOG import LOG, INFO
try:
......@@ -198,14 +198,14 @@ class SoftwareInstance(Item):
for internet_protocol_address in compute_partition.contentValues(portal_type='Internet Protocol Address'):
# XXX - There is new values, and we must keep compatibility
address_tuple = (
internet_protocol_address.getNetworkInterface('').decode("UTF-8"),
internet_protocol_address.getIpAddress().decode("UTF-8"))
unicode2str(internet_protocol_address.getNetworkInterface('')),
unicode2str(internet_protocol_address.getIpAddress()))
if internet_protocol_address.getGatewayIpAddress('') and \
internet_protocol_address.getNetmask(''):
address_tuple = address_tuple + (
internet_protocol_address.getGatewayIpAddress().decode("UTF-8"),
internet_protocol_address.getNetmask().decode("UTF-8"),
internet_protocol_address.getNetworkAddress('').decode("UTF-8"))
unicode2str(internet_protocol_address.getGatewayIpAddress()),
unicode2str(internet_protocol_address.getNetmask()),
unicode2str(internet_protocol_address.getNetworkAddress('')))
full_ip_list.append(address_tuple)
else:
ip_list.append(address_tuple)
......@@ -228,31 +228,31 @@ class SoftwareInstance(Item):
self._getModificationDateAsTimestamp(shared_instance)))
append({
'slave_title': shared_instance.getTitle().decode("UTF-8"),
'slave_title': unicode2str(shared_instance.getTitle()),
'slap_software_type': \
shared_instance.getSourceReference().decode("UTF-8"),
'slave_reference': shared_instance.getReference().decode("UTF-8"),
unicode2str(shared_instance.getSourceReference()),
'slave_reference': unicode2str(shared_instance.getReference()),
'timestamp': shared_timestamp,
'xml': shared_instance.getTextContent(),
'connection_xml': shared_instance.getConnectionXml(),
})
timestamp = max(timestamp, shared_timestamp)
return {
'instance_guid': self.getReference().decode("UTF-8"),
'instance_title': self.getTitle().decode("UTF-8"),
'root_instance_title': instance_tree.getTitle().decode("UTF-8"),
'root_instance_short_title': instance_tree.getShortTitle().decode("UTF-8"),
'instance_guid': unicode2str(self.getReference()),
'instance_title': unicode2str(self.getTitle()),
'root_instance_title': unicode2str(instance_tree.getTitle()),
'root_instance_short_title': unicode2str(instance_tree.getShortTitle()),
'xml': self.getTextContent(),
'connection_xml': self.getConnectionXml(),
'filter_xml': self.getSlaXml(),
'slap_computer_id': \
compute_partition.getParentValue().getReference().decode("UTF-8"),
unicode2str(compute_partition.getParentValue().getReference()),
'slap_computer_partition_id': \
compute_partition.getReference().decode("UTF-8"),
unicode2str(compute_partition.getReference()),
'slap_software_type': \
self.getSourceReference().decode("UTF-8"),
unicode2str(self.getSourceReference()),
'slap_software_release_url': \
self.getUrlString().decode("UTF-8"),
unicode2str(self.getUrlString()),
'slave_instance_list': shared_instance_list,
'ip_list': ip_list,
'full_ip_list': full_ip_list,
......@@ -276,8 +276,8 @@ class SoftwareInstance(Item):
for internet_protocol_address in compute_partition.contentValues(
portal_type='Internet Protocol Address'):
ip_address_list.append(
(internet_protocol_address.getNetworkInterface('').decode("UTF-8"),
internet_protocol_address.getIpAddress().decode("UTF-8"))
(unicode2str(internet_protocol_address.getNetworkInterface('')),
unicode2str(internet_protocol_address.getIpAddress()))
)
return ip_address_list
......
......@@ -32,6 +32,7 @@ from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from Products.ERP5Type.tests.utils import DummyMailHostMixin
from OFS.Traversable import NotFound
from erp5.component.module.SlapOSCloud import _assertACI
from Products.ERP5Type.Utils import unicode2str
import time
from lxml import etree
......@@ -64,8 +65,8 @@ class SlapOSComputeNodeMixin(object):
):
software_installation = _assertACI(software_installation.getObject())
software_release_dict = {
"software_release": software_installation.getUrlString().decode('UTF-8'),
"computer_guid": self.getReference().decode('UTF-8')
"software_release": unicode2str(software_installation.getUrlString()),
"computer_guid": unicode2str(self.getReference())
}
if software_installation.getSlapState() == 'destroy_requested':
software_release_dict["_requested_state"] = 'destroyed'
......@@ -85,7 +86,7 @@ class SlapOSComputeNodeMixin(object):
def _getCacheComputeNodeInformation(self, user):
compute_node_dict = {
"_computer_id": self.getReference().decode("UTF-8"),
"_computer_id": unicode2str(self.getReference()),
"_computer_partition_list": [],
"_software_release_list": self._getSoftwareReleaseValueList()
}
......@@ -192,7 +193,7 @@ class SlapOSComputeNodeMixin(object):
return self._getCacheComputeNodeInformation(user), None
else:
compute_node_dict = {
"_computer_id": self.getReference().decode("UTF-8"),
"_computer_id": unicode2str(self.getReference()),
"_computer_partition_list": [],
"_software_release_list": []
}
......@@ -259,10 +260,10 @@ class SlapOSComputeNodeMixin(object):
compute_node = compute_partition_document
while compute_node.getPortalType() != 'Compute Node':
compute_node = compute_node.getParentValue()
compute_node_id = compute_node.getReference().decode("UTF-8")
compute_node_id = unicode2str(compute_node.getReference())
partition_dict = {
"compute_node_id": compute_node_id,
"partition_id": compute_partition_document.getReference().decode("UTF-8"),
"partition_id": unicode2str(compute_partition_document.getReference()),
"_software_release_document": None,
"_requested_state": 'destroyed',
"_need_modification": 0
......@@ -288,7 +289,7 @@ class SlapOSComputeNodeMixin(object):
partition_dict['_access_status'] = software_instance.getTextAccessStatus()
partition_dict['_software_release_document'] = {
"software_release": software_instance.getUrlString().decode("UTF-8"),
"software_release": unicode2str(software_instance.getUrlString()),
"computer_guid": compute_node_id
}
......
......@@ -28,6 +28,7 @@
from erp5.component.module.SlapOSCloud import _assertACI
from zLOG import LOG, INFO
from OFS.Traversable import NotFound
from Products.ERP5Type.Utils import unicode2str
try:
from slapos.util import calculate_dict_hash
......@@ -76,11 +77,11 @@ class SlapOSComputePartitionMixin(object):
compute_node = self
while compute_node.getPortalType() != 'Compute Node':
compute_node = compute_node.getParentValue()
compute_node_id = compute_node.getReference().decode("UTF-8")
compute_node_id = unicode2str(compute_node.getReference())
partition_dict = {
"compute_node_id": compute_node_id,
"partition_id": self.getReference().decode("UTF-8"),
"partition_id": unicode2str(self.getReference()),
"_software_release_document": None,
"_requested_state": 'destroyed',
"_need_modification": 0
......@@ -110,7 +111,7 @@ class SlapOSComputePartitionMixin(object):
partition_dict['_requested_state'] = 'started'
partition_dict['_software_release_document'] = {
"software_release": software_instance.getUrlString().decode("UTF-8"),
"software_release": unicode2str(software_instance.getUrlString()),
"computer_guid": compute_node_id
}
partition_dict['_access_status'] = software_instance.getTextAccessStatus()
......
......@@ -16,6 +16,7 @@ import hashlib
import json
from binascii import hexlify
from OFS.Traversable import NotFound
from Products.ERP5Type.Utils import unicode2str
def hashData(data):
......@@ -42,11 +43,10 @@ class Simulator:
def canonical_xml(xml):
return etree.tostring(
return unicode2str(etree.tostring(
etree.fromstring(xml),
method="c14n",
).decode('utf-8')
))
class TestSlapOSSlapToolMixin(SlapOSTestCaseMixin):
def afterSetUp(self):
......
......@@ -28,7 +28,7 @@
#
##############################################################################
from Products.ERP5Type.Utils import unicode2str
from AccessControl import ClassSecurityInfo
from AccessControl import Unauthorized
from OFS.Traversable import NotFound
......@@ -124,7 +124,7 @@ def castToStr(dict_kw):
if not isinstance(_value, str):
text = str(_value)
etree.SubElement(instance, "parameter",
attrib={'id': _id}).text = text.decode("utf-8")
attrib={'id': _id}).text = unicode2str(text)
return etree.tostring(instance, pretty_print=True,
xml_declaration=True, encoding='utf-8')
......@@ -522,7 +522,7 @@ class SlapTool(BaseTool):
portal = self.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
person.requestComputeNode(compute_node_title=compute_node_title, project_reference=project_reference)
compute_node = ComputeNode(self.REQUEST.get('compute_node_reference').decode("UTF-8"))
compute_node = ComputeNode(unicode2str(self.REQUEST.get('compute_node_reference')))
return dumps(compute_node)
security.declareProtected(Permissions.AccessContentsInformation,
......@@ -699,8 +699,8 @@ class SlapTool(BaseTool):
def _generateComputerCertificate(self, compute_node_id):
self.getPortalObject().portal_catalog.getComputeNodeObject(compute_node_id).generateCertificate()
result = {
'certificate': self.REQUEST.get('compute_node_certificate').decode("UTF-8"),
'key': self.REQUEST.get('compute_node_key').decode("UTF-8")
'certificate': unicode2str(self.REQUEST.get('compute_node_certificate')),
'key': unicode2str(self.REQUEST.get('compute_node_key'))
}
return dumps(result)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment