Commit 8fb1893b authored by Rafael Monnerat's avatar Rafael Monnerat

Use hash instead a reference list to compare Connection parameters

  Some parameters has the same ids on connection_xml and parameter_xml,
  which makes in certain cases parameters always diference.

  The hash would simplify the comparations for slaves.
parent 92cd8252
...@@ -1223,7 +1223,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): ...@@ -1223,7 +1223,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<string>slave_instance_list</string> <string>slave_instance_list</string>
<list id='i9'> <list id='i9'>
<dictionary id='i10'> <dictionary id='i10'>
<string>connection-parameter-key-list</string> <string>connection-parameter-hash</string>
<list id='i11'/> <list id='i11'/>
<unicode>paramé</unicode> <unicode>paramé</unicode>
<unicode>%(slave_1_param)s</unicode> <unicode>%(slave_1_param)s</unicode>
...@@ -2318,7 +2318,7 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin): ...@@ -2318,7 +2318,7 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<string>slave_instance_list</string> <string>slave_instance_list</string>
<list id='i9'> <list id='i9'>
<dictionary id='i10'> <dictionary id='i10'>
<string>connection-parameter-key-list</string> <string>connection-parameter-hash</string>
<list id='i11'/> <list id='i11'/>
<unicode>paramé</unicode> <unicode>paramé</unicode>
<unicode>%(slave_1_param)s</unicode> <unicode>%(slave_1_param)s</unicode>
......
...@@ -41,6 +41,7 @@ from Products.ERP5Type import Permissions ...@@ -41,6 +41,7 @@ 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:
...@@ -829,8 +830,8 @@ class SlapTool(BaseTool): ...@@ -829,8 +830,8 @@ class SlapTool(BaseTool):
connection_dict = self._instanceXmlToDict( connection_dict = self._instanceXmlToDict(
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-key-list'] = \ slave_instance_dict['connection-parameter-hash'] = \
connection_dict.keys() hashlib.sha256(str(connection_dict)).hexdigest()
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")))
......
...@@ -40,6 +40,7 @@ import json ...@@ -40,6 +40,7 @@ import json
import logging import logging
import re import re
import urlparse import urlparse
import hashlib
from util import xml2dict from util import xml2dict
import netaddr import netaddr
...@@ -567,23 +568,22 @@ class ComputerPartition(SlapRequester): ...@@ -567,23 +568,22 @@ class ComputerPartition(SlapRequester):
if self.getConnectionParameterDict() == connection_dict: if self.getConnectionParameterDict() == connection_dict:
return return
if slave_reference is not None: if slave_reference is not None:
# check the connection parameters from the slave # check the connection parameters from the slave
# Should we check existence? # Should we check existence?
slave_parameter_list = self.getInstanceParameter("slave_instance_list") slave_parameter_list = self.getInstanceParameter("slave_instance_list")
slave_connection_dict = {} slave_connection_dict = {}
for slave_parameter_dict in slave_parameter_list: for slave_parameter_dict in slave_parameter_list:
if slave_parameter_dict["reference"] == slave_reference: if slave_parameter_dict.get("slave_reference") == slave_reference:
for key in slave_parameter_dict.get( connection_parameter_hash = slave_parameter_dict.get("connection-parameter-hash", None)
"connection-parameter-key-list", []):
slave_connection_dict[key] = slave_parameter_dict[key]
break break
# Skip as nothing changed for the slave # Skip as nothing changed for the slave
if slave_connection_dict == connection_dict: if connection_parameter_hash is not None and \
connection_parameter_hash == hashlib.sha256(str(connection_dict)).hexdigest():
return return
self._connection_helper.POST('setComputerPartitionConnectionXml', data={ self._connection_helper.POST('setComputerPartitionConnectionXml', data={
'computer_id': self._computer_id, 'computer_id': self._computer_id,
'computer_partition_id': self._partition_id, 'computer_partition_id': self._partition_id,
...@@ -1037,4 +1037,3 @@ class SlapHateoasNavigator(HateoasNavigator): ...@@ -1037,4 +1037,3 @@ class SlapHateoasNavigator(HateoasNavigator):
instance_url = self.hateoasGetLinkFromLinks(instance_list, reference) instance_url = self.hateoasGetLinkFromLinks(instance_list, reference)
instance = self._hateoasGetInformation(instance_url) instance = self._hateoasGetInformation(instance_url)
return instance return instance
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