summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Terceiro <terceiro@debian.org>2019-02-21 09:07:02 -0300
committerLars Wirzenius <liw@liw.fi>2019-12-15 17:15:08 +0200
commit7ffc1ff5266fc612c868650844533b11da780ffd (patch)
tree167f911cb6d417fb9cffb4c3263fa93c71bcfb8c
parent67ff9e09719b6e1c6faf60da9128adc2496dce27 (diff)
downloadvmdb2-7ffc1ff5266fc612c868650844533b11da780ffd.tar.gz
Add: target mount point attribute to tags
-rw-r--r--vmdb/__init__.py2
-rw-r--r--vmdb/tags.py17
-rw-r--r--vmdb/tags_tests.py13
3 files changed, 31 insertions, 1 deletions
diff --git a/vmdb/__init__.py b/vmdb/__init__.py
index 4ebc76b..6913cfc 100644
--- a/vmdb/__init__.py
+++ b/vmdb/__init__.py
@@ -33,7 +33,7 @@ from .runcmd import (
progress,
error,
)
-from .tags import Tags, UnknownTag, TagInUse, AlreadyHasDev, AlreadyHasFsType, AlreadyMounted
+from .tags import Tags, UnknownTag, TagInUse, AlreadyHasDev, AlreadyHasFsType, AlreadyHasTargetMountPoint, AlreadyMounted
from .unmount import unmount, NotMounted
from .spec import (
Spec,
diff --git a/vmdb/tags.py b/vmdb/tags.py
index 7730033..9ac3a80 100644
--- a/vmdb/tags.py
+++ b/vmdb/tags.py
@@ -46,6 +46,10 @@ class Tags:
item = self._get(tag)
return item['fstype']
+ def get_target_mount_point(self, tag):
+ item = self._get(tag)
+ return item['target_mount_point']
+
def is_cached(self, tag):
item = self._get(tag)
return item.get('cached', False)
@@ -58,6 +62,7 @@ class Tags:
'dev': None,
'mount_point': None,
'fstype': None,
+ 'target_mount_point': None,
}
def set_dev(self, tag, dev):
@@ -79,6 +84,12 @@ class Tags:
raise AlreadyHasFsType(tag)
item['fstype'] = fstype
+ def set_target_mount_point(self, tag, target_mount_point):
+ item = self._get(tag)
+ if item['target_mount_point'] is not None:
+ raise AlreadyHasTargetMountPoint(tag)
+ item['target_mount_point'] = target_mount_point
+
def _get(self, tag):
item = self._tags.get(tag)
if item is None:
@@ -114,3 +125,9 @@ class AlreadyHasFsType(Exception):
def __init__(self, tag):
super().__init__('Already has filesytem type: {}'.format(tag))
+
+
+class AlreadyHasTargetMountPoint(Exception):
+
+ def __init__(self, tag):
+ super().__init__('Already has target mount point: {}'.format(tag))
diff --git a/vmdb/tags_tests.py b/vmdb/tags_tests.py
index 1fc1f27..383ac14 100644
--- a/vmdb/tags_tests.py
+++ b/vmdb/tags_tests.py
@@ -121,3 +121,16 @@ class TagsTests(unittest.TestCase):
tags.set_fstype('first', 'ext3')
with self.assertRaises(vmdb.AlreadyHasFsType):
tags.set_fstype('first', 'ext4')
+
+ def test_set_target_mount_point(self):
+ tags = vmdb.Tags()
+ tags.append('first')
+ tags.set_target_mount_point('first', '/boot')
+ self.assertEqual(tags.get_target_mount_point('first'), '/boot')
+
+ def test_set_target_mount_point_raises_error_for_double_target_mount_point(self):
+ tags = vmdb.Tags()
+ tags.append('first')
+ tags.set_target_mount_point('first', '/boot')
+ with self.assertRaises(vmdb.AlreadyHasTargetMountPoint):
+ tags.set_target_mount_point('first', '/')