Permalink
Browse files

Merge "VMware: DatastorePath join() and __eq__()"

  • Loading branch information...
2 parents 64d0c42 + dc67784 commit 4ff26f2ca0eadfa50aec54e5ba4d1c90221b7ecf Jenkins committed with openstack-gerrit Jul 19, 2014
Showing with 35 additions and 0 deletions.
  1. +22 −0 nova/tests/virt/vmwareapi/test_ds_util.py
  2. +13 −0 nova/virt/vmwareapi/ds_util.py
@@ -384,6 +384,28 @@ def test_ds_path_non_equivalence(self):
p = ds_util.DatastorePath(t[0], *t[1])
self.assertNotEqual(str(canonical_p), str(p))
+ def test_equal(self):
+ a = ds_util.DatastorePath('ds_name', 'a')
+ b = ds_util.DatastorePath('ds_name', 'a')
+ self.assertEqual(a, b)
+
+ def test_join(self):
+ p = ds_util.DatastorePath('ds_name', 'a')
+ ds_path = p.join('b')
+ self.assertEqual('[ds_name] a/b', str(ds_path))
+
+ p = ds_util.DatastorePath('ds_name', 'a')
+ ds_path = p.join()
+ self.assertEqual('[ds_name] a', str(ds_path))
+
+ bad_args = [
+ [None],
+ ['', None],
+ ['a', None],
+ ['a', None, 'b']]
+ for arg in bad_args:
+ self.assertRaises(ValueError, p.join, *arg)
+
def test_ds_path_parse(self):
p = ds_util.DatastorePath.parse('[dsname]')
self.assertEqual('dsname', p.datastore)
@@ -140,6 +140,19 @@ def dirname(self):
def rel_path(self):
return self._rel_path
+ def join(self, *paths):
+ if paths:
+ if None in paths:
+ raise ValueError(_("path component cannot be None"))
+ return DatastorePath(self.datastore,
+ posixpath.join(self._rel_path, *paths))
+ return self
+
+ def __eq__(self, other):
+ return (isinstance(other, DatastorePath) and
+ self._datastore_name == other._datastore_name and
+ self._rel_path == other._rel_path)
+
@classmethod
def parse(cls, datastore_path):
"""Constructs a DatastorePath object given a datastore path string."""

0 comments on commit 4ff26f2

Please sign in to comment.