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