Skip to content

Commit

Permalink
Merge pull request #115 from zopefoundation/fix-114
Browse files Browse the repository at this point in the history
fix #114
  • Loading branch information
jensens committed Dec 1, 2021
2 parents 3b36d8c + 4e361a8 commit b6e85ba
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
2.1.5 (unreleased)
------------------

- Fix #114: Problems using ZMI on multi-instance clusters due to instable hash key.
(`#114 <https://github.com/zopefoundation/Products.GenericSetup/issues/114>`_)

- Move several tabs to Zope 4+ ZMI-markup standard. [jensens]


Expand Down
3 changes: 2 additions & 1 deletion src/Products/GenericSetup/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from Products.GenericSetup.interfaces import IUpgradeSteps
from Products.GenericSetup.registry import GlobalRegistryStorage
from Products.GenericSetup.utils import _getHash


def normalize_version(version):
Expand Down Expand Up @@ -123,7 +124,7 @@ class UpgradeEntity(object):
"""
def __init__(self, title, profile, source, dest, desc, checker=None,
sortkey=0):
self.id = str(abs(hash('%s%s%s%s' % (title, source, dest, sortkey))))
self.id = _getHash(title, source, dest, sortkey)
self.title = title
if source == '*':
source = None
Expand Down
8 changes: 8 additions & 0 deletions src/Products/GenericSetup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
""" GenericSetup product utilities
"""

import hashlib
import os
import sys
from inspect import getdoc
Expand Down Expand Up @@ -1027,3 +1028,10 @@ def _getProductPath(product_name):
% product_name)

return product.__path__[0]


def _getHash(*args):
"""return a stable md hash of given string arguments"""
base = "".join([str(x) for x in args])
hashmd5 = hashlib.md5(base.encode('utf8'))
return hashmd5.hexdigest()
7 changes: 3 additions & 4 deletions src/Products/GenericSetup/zcml.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .upgrade import UpgradeStep
from .upgrade import _registerNestedUpgradeStep
from .upgrade import _registerUpgradeStep
from .utils import _getHash


# genericsetup:registerProfile
Expand Down Expand Up @@ -354,8 +355,7 @@ def upgradeStep(self, _context, title, handler,
step = UpgradeStep(title, self.profile, self.source, self.dest,
description, handler, checker, self.sortkey)
if self.id is None:
self.id = str(abs(hash('%s%s%s%s' % (title, self.source, self.dest,
self.sortkey))))
self.id = _getHash(title, self.source, self.dest, self.sortkey)
_context.action(
discriminator=(
'upgradeStep', self.profile, self.source, self.dest, handler,
Expand All @@ -372,8 +372,7 @@ def upgradeDepends(self, _context, title, description=None,
description, import_profile, import_steps,
run_deps, purge, checker, self.sortkey)
if self.id is None:
self.id = str(abs(hash('%s%s%s%s' % (title, self.source, self.dest,
self.sortkey))))
self.id = _getHash(title, self.source, self.dest, self.sortkey)
_context.action(
discriminator=(
'upgradeDepends', self.profile, self.source, self.dest,
Expand Down

0 comments on commit b6e85ba

Please sign in to comment.