Commit 43c06542 authored by Bryton Lacquement's avatar Bryton Lacquement 🚪 Committed by Julien Muchembled

Prepare for xml-marshaller 1.0.2

parent f143249d
...@@ -1441,8 +1441,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -1441,8 +1441,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
</marshal>""" </marshal>"""
stored_xml = """<?xml version='1.0' encoding='utf-8'?> stored_xml = """<?xml version='1.0' encoding='utf-8'?>
<instance> <instance>
<parameter id="p1é">v1é</parameter>
<parameter id="p2é">v2é</parameter> <parameter id="p2é">v2é</parameter>
<parameter id="p1é">v1é</parameter>
</instance> </instance>
""" """
self.login(self.start_requested_software_instance.getUserId()) self.login(self.start_requested_software_instance.getUserId())
...@@ -1474,8 +1474,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -1474,8 +1474,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
</marshal>""" </marshal>"""
stored_xml = """<?xml version='1.0' encoding='utf-8'?> stored_xml = """<?xml version='1.0' encoding='utf-8'?>
<instance> <instance>
<parameter id="p1é">v1é</parameter>
<parameter id="p2é">v2é</parameter> <parameter id="p2é">v2é</parameter>
<parameter id="p1é">v1é</parameter>
</instance> </instance>
""" """
self.login(self.start_requested_software_instance.getUserId()) self.login(self.start_requested_software_instance.getUserId())
......
...@@ -45,10 +45,12 @@ import hashlib ...@@ -45,10 +45,12 @@ import hashlib
import time import time
from Products.ERP5Type.tests.utils import DummyMailHostMixin from Products.ERP5Type.tests.utils import DummyMailHostMixin
try: try:
from slapos.slap.slap import Computer from slapos.slap.slap import (
from slapos.slap.slap import ComputerPartition as SlapComputerPartition Computer,
from slapos.slap.slap import SoftwareInstance ComputerPartition as SlapComputerPartition,
from slapos.slap.slap import SoftwareRelease SoftwareInstance,
SoftwareRelease)
from slapos.proxy.views import dict2xml
except ImportError: except ImportError:
# Do no prevent instance from starting # Do no prevent instance from starting
# if libs are not installed # if libs are not installed
...@@ -64,6 +66,8 @@ except ImportError: ...@@ -64,6 +66,8 @@ except ImportError:
class SoftwareRelease: class SoftwareRelease:
def __init__(self): def __init__(self):
raise ImportError raise ImportError
def dict2xml(dictionary):
raise ImportError
from zLOG import LOG, INFO from zLOG import LOG, INFO
import xml_marshaller import xml_marshaller
...@@ -1203,16 +1207,8 @@ class SlapTool(BaseTool): ...@@ -1203,16 +1207,8 @@ class SlapTool(BaseTool):
computer_id, computer_id,
computer_partition_id, computer_partition_id,
slave_reference) slave_reference)
partition_parameter_kw = xml_marshaller.xml_marshaller.loads( connection_xml = dict2xml(xml_marshaller.xml_marshaller.loads(
connection_xml) connection_xml))
instance = etree.Element('instance')
for parameter_id, parameter_value in partition_parameter_kw.iteritems():
if not isinstance(parameter_value, unicode):
parameter_value = str(parameter_value)
etree.SubElement(instance, "parameter",
attrib={'id':parameter_id}).text = parameter_value
connection_xml = etree.tostring(instance, pretty_print=True,
xml_declaration=True, encoding='utf-8')
reference = software_instance.getReference() reference = software_instance.getReference()
if self._getLastData(reference) != connection_xml: if self._getLastData(reference) != connection_xml:
software_instance.updateConnection( software_instance.updateConnection(
......
...@@ -70,7 +70,11 @@ def xml2dict(xml): ...@@ -70,7 +70,11 @@ def xml2dict(xml):
def dict2xml(dictionary): def dict2xml(dictionary):
instance = etree.Element('instance') instance = etree.Element('instance')
for k, v in six.iteritems(dictionary): for k, v in six.iteritems(dictionary):
if not isinstance(v, six.string_types): if isinstance(k, bytes):
k = k.decode('utf-8')
if isinstance(v, bytes):
v = v.decode('utf-8')
elif not isinstance(v, six.text_type):
v = str(v) v = str(v)
etree.SubElement(instance, "parameter", etree.SubElement(instance, "parameter",
attrib={'id': k}).text = v attrib={'id': k}).text = v
......
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