Commit b29a79a6 authored by Łukasz Nowak's avatar Łukasz Nowak Committed by Łukasz Nowak

slapos/master: Use methods from slapos.util

/reviewed-on nexedi/slapos.core!132
parent 973a0724
...@@ -1247,7 +1247,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -1247,7 +1247,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<list id='i9'> <list id='i9'>
<dictionary id='i10'> <dictionary id='i10'>
<string>connection-parameter-hash</string> <string>connection-parameter-hash</string>
<string>44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a</string> <string>4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945</string>
<string>paramé</string> <string>paramé</string>
<string>%(slave_1_param)s</string> <string>%(slave_1_param)s</string>
<string>slap_software_type</string> <string>slap_software_type</string>
...@@ -1445,8 +1445,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -1445,8 +1445,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="p2é">v2é</parameter>
<parameter id="p1é">v1é</parameter> <parameter id="p1é">v1é</parameter>
<parameter id="p2é">v2é</parameter>
</instance> </instance>
""" """
self.login(self.start_requested_software_instance.getUserId()) self.login(self.start_requested_software_instance.getUserId())
...@@ -1478,8 +1478,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -1478,8 +1478,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="p2é">v2é</parameter>
<parameter id="p1é">v1é</parameter> <parameter id="p1é">v1é</parameter>
<parameter id="p2é">v2é</parameter>
</instance> </instance>
""" """
self.login(self.start_requested_software_instance.getUserId()) self.login(self.start_requested_software_instance.getUserId())
...@@ -2390,7 +2390,7 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin): ...@@ -2390,7 +2390,7 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<list id='i9'> <list id='i9'>
<dictionary id='i10'> <dictionary id='i10'>
<string>connection-parameter-hash</string> <string>connection-parameter-hash</string>
<string>44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a</string> <string>4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945</string>
<string>paramé</string> <string>paramé</string>
<string>%(slave_1_param)s</string> <string>%(slave_1_param)s</string>
<string>slap_software_type</string> <string>slap_software_type</string>
......
...@@ -41,7 +41,6 @@ from Products.ERP5Type import Permissions ...@@ -41,7 +41,6 @@ from Products.ERP5Type import Permissions
from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
from lxml import etree from lxml import etree
import hashlib
import time import time
from Products.ERP5Type.tests.utils import DummyMailHostMixin from Products.ERP5Type.tests.utils import DummyMailHostMixin
try: try:
...@@ -50,7 +49,7 @@ try: ...@@ -50,7 +49,7 @@ try:
ComputerPartition as SlapComputerPartition, ComputerPartition as SlapComputerPartition,
SoftwareInstance, SoftwareInstance,
SoftwareRelease) SoftwareRelease)
from slapos.proxy.views import dict2xml from slapos.util import dict2xml, xml2dict, calculate_dict_hash
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
...@@ -68,6 +67,10 @@ except ImportError: ...@@ -68,6 +67,10 @@ except ImportError:
raise ImportError raise ImportError
def dict2xml(dictionary): def dict2xml(dictionary):
raise ImportError raise ImportError
def xml2dict(dictionary):
raise ImportError
def calculate_dict_hash(dictionary):
raise ImportError
from zLOG import LOG, INFO from zLOG import LOG, INFO
import xml_marshaller import xml_marshaller
...@@ -833,7 +836,7 @@ class SlapTool(BaseTool): ...@@ -833,7 +836,7 @@ class SlapTool(BaseTool):
slave_instance_dict.pop("connection_xml")) slave_instance_dict.pop("connection_xml"))
slave_instance_dict.update(connection_dict) slave_instance_dict.update(connection_dict)
slave_instance_dict['connection-parameter-hash'] = \ slave_instance_dict['connection-parameter-hash'] = \
hashlib.sha256(str(connection_dict)).hexdigest() calculate_dict_hash(connection_dict)
if slave_instance_dict.has_key("xml"): if slave_instance_dict.has_key("xml"):
slave_instance_dict.update(self._instanceXmlToDict( slave_instance_dict.update(self._instanceXmlToDict(
slave_instance_dict.pop("xml"))) slave_instance_dict.pop("xml")))
...@@ -896,16 +899,7 @@ class SlapTool(BaseTool): ...@@ -896,16 +899,7 @@ class SlapTool(BaseTool):
def _instanceXmlToDict(self, xml): def _instanceXmlToDict(self, xml):
result_dict = {} result_dict = {}
try: try:
if xml is not None and xml != '': result_dict = xml2dict(xml)
tree = etree.fromstring(xml)
for element in tree.findall('parameter'):
key = element.get('id')
value = result_dict.get(key, None)
if value is not None:
value = value + ' ' + element.text
else:
value = element.text
result_dict[key] = value
except (etree.XMLSchemaError, etree.XMLSchemaParseError, except (etree.XMLSchemaError, etree.XMLSchemaParseError,
etree.XMLSchemaValidateError, etree.XMLSyntaxError): etree.XMLSchemaValidateError, etree.XMLSyntaxError):
LOG('SlapTool', INFO, 'Issue during parsing xml:', error=True) LOG('SlapTool', INFO, 'Issue during parsing xml:', error=True)
......
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