Skip to content

Commit

Permalink
Replace builtin hash with MD5 to solve 32/64-bit issues.
Browse files Browse the repository at this point in the history
It seems that Python's builtin hash returns different
values on 32-bit and 64-bit architectures, so it's
safer to use a well-defined hash like MD5.

bug 1050359

Change-Id: Ibb49f7b9028085d2aedaf05b94e1e1dcdf5e4cb4
  • Loading branch information
Ben Swartzlander committed Sep 20, 2012
1 parent 2934799 commit ba8cca2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions nova/tests/test_nfs.py
Expand Up @@ -109,8 +109,9 @@ def test_local_path(self):
volume['provider_location'] = self.TEST_NFS_EXPORT1
volume['name'] = 'volume-123'

self.assertEqual('/mnt/test/12118957640568004265/volume-123',
drv.local_path(volume))
self.assertEqual(
'/mnt/test/2f4f60214cf43c595666dd815f0360a4/volume-123',
drv.local_path(volume))

def test_mount_nfs_should_mount_correctly(self):
"""_mount_nfs common case usage"""
Expand Down Expand Up @@ -212,7 +213,7 @@ def test_get_hash_str(self):
"""_get_hash_str should calculation correct value"""
drv = self._driver

self.assertEqual('12118957640568004265',
self.assertEqual('2f4f60214cf43c595666dd815f0360a4',
drv._get_hash_str(self.TEST_NFS_EXPORT1))

def test_get_mount_point_for_share(self):
Expand All @@ -221,7 +222,7 @@ def test_get_mount_point_for_share(self):

nfs.FLAGS.nfs_mount_point_base = self.TEST_MNT_POINT_BASE

self.assertEqual('/mnt/test/12118957640568004265',
self.assertEqual('/mnt/test/2f4f60214cf43c595666dd815f0360a4',
drv._get_mount_point_for_share(self.TEST_NFS_EXPORT1))

def test_get_available_capacity_with_df(self):
Expand Down
4 changes: 2 additions & 2 deletions nova/volume/nfs.py
Expand Up @@ -15,8 +15,8 @@
# License for the specific language governing permissions and limitations
# under the License.

import ctypes
import errno
import hashlib
import os

from nova import exception
Expand Down Expand Up @@ -290,4 +290,4 @@ def _path_exists(self, path):

def _get_hash_str(self, base_str):
"""returns string that represents hash of base_str (in a hex format)"""
return str(ctypes.c_uint64(hash(base_str)).value)
return hashlib.md5(base_str).hexdigest()

0 comments on commit ba8cca2

Please sign in to comment.