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):
<string>slave_instance_list</string>
<list id='i9'>
<dictionary id='i10'>
<string>connection-parameter-key-list</string>
<string>connection-parameter-hash</string>
<list id='i11'/>
<unicode>paramé</unicode>
<unicode>%(slave_1_param)s</unicode>
......@@ -2318,7 +2318,7 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<string>slave_instance_list</string>
<list id='i9'>
<dictionary id='i10'>
<string>connection-parameter-key-list</string>
<string>connection-parameter-hash</string>
<list id='i11'/>
<unicode>paramé</unicode>
<unicode>%(slave_1_param)s</unicode>
......
......@@ -41,6 +41,7 @@ from Products.ERP5Type import Permissions
from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE
from Products.ERP5Type.Cache import CachingMethod
from lxml import etree
import hashlib
import time
from Products.ERP5Type.tests.utils import DummyMailHostMixin
try:
......@@ -829,8 +830,8 @@ class SlapTool(BaseTool):
connection_dict = self._instanceXmlToDict(
slave_instance_dict.pop("connection_xml"))
slave_instance_dict.update(connection_dict)
slave_instance_dict['connection-parameter-key-list'] = \
connection_dict.keys()
slave_instance_dict['connection-parameter-hash'] = \
hashlib.sha256(str(connection_dict)).hexdigest()
if slave_instance_dict.has_key("xml"):
slave_instance_dict.update(self._instanceXmlToDict(
slave_instance_dict.pop("xml")))
......
......@@ -40,6 +40,7 @@ import json
import logging
import re
import urlparse
import hashlib
from util import xml2dict
import netaddr
......@@ -574,14 +575,13 @@ class ComputerPartition(SlapRequester):
slave_parameter_list = self.getInstanceParameter("slave_instance_list")
slave_connection_dict = {}
for slave_parameter_dict in slave_parameter_list:
if slave_parameter_dict["reference"] == slave_reference:
for key in slave_parameter_dict.get(
"connection-parameter-key-list", []):
slave_connection_dict[key] = slave_parameter_dict[key]
if slave_parameter_dict.get("slave_reference") == slave_reference:
connection_parameter_hash = slave_parameter_dict.get("connection-parameter-hash", None)
break
# 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
self._connection_helper.POST('setComputerPartitionConnectionXml', data={
......@@ -1037,4 +1037,3 @@ class SlapHateoasNavigator(HateoasNavigator):
instance_url = self.hateoasGetLinkFromLinks(instance_list, reference)
instance = self._hateoasGetInformation(instance_url)
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