diff --git a/nova/tests/virt/vmwareapi/test_ds_util.py b/nova/tests/virt/vmwareapi/test_ds_util.py index 2715f423e390..3ae1a60139d8 100644 --- a/nova/tests/virt/vmwareapi/test_ds_util.py +++ b/nova/tests/virt/vmwareapi/test_ds_util.py @@ -17,6 +17,7 @@ import re import mock from oslo.vmware import exceptions as vexc +from testtools import matchers from nova import exception from nova.i18n import _ @@ -447,6 +448,14 @@ class DatastorePathTestCase(test.NoDBTestCase): p = ds_util.DatastorePath(t[0], *t[1]) self.assertNotEqual(str(canonical_p), str(p)) + def test_ds_path_hashable(self): + ds1 = ds_util.DatastorePath('dsname', 'path') + ds2 = ds_util.DatastorePath('dsname', 'path') + + # If the above objects have the same hash, they will only be added to + # the set once + self.assertThat(set([ds1, ds2]), matchers.HasLength(1)) + def test_equal(self): a = ds_util.DatastorePath('ds_name', 'a') b = ds_util.DatastorePath('ds_name', 'a') diff --git a/nova/virt/vmwareapi/ds_util.py b/nova/virt/vmwareapi/ds_util.py index 764272e548e3..b5881480ee96 100644 --- a/nova/virt/vmwareapi/ds_util.py +++ b/nova/virt/vmwareapi/ds_util.py @@ -161,6 +161,9 @@ class DatastorePath(object): self._datastore_name == other._datastore_name and self._rel_path == other._rel_path) + def __hash__(self): + return str(self).__hash__() + @classmethod def parse(cls, datastore_path): """Constructs a DatastorePath object given a datastore path string."""