summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-12-26 18:07:18 +0200
committerLars Wirzenius <liw@liw.fi>2019-12-26 18:15:36 +0200
commitb45f6c4360b86672c01b300f55bf8c84853733bd (patch)
tree45374a0f50e52a7cc2ab50abe7fa6a2d921e5bc4
parentfc0c174d798c8ddb8adb3048c8a5caf5b21415b8 (diff)
downloadvmdb2-b45f6c4360b86672c01b300f55bf8c84853733bd.tar.gz
Add: Tags.get_builder_from_target_mount_point
-rw-r--r--vmdb/__init__.py11
-rw-r--r--vmdb/tags.py13
-rw-r--r--vmdb/tags_tests.py25
3 files changed, 44 insertions, 5 deletions
diff --git a/vmdb/__init__.py b/vmdb/__init__.py
index 6913cfc..0b9ddc1 100644
--- a/vmdb/__init__.py
+++ b/vmdb/__init__.py
@@ -33,7 +33,16 @@ from .runcmd import (
progress,
error,
)
-from .tags import Tags, UnknownTag, TagInUse, AlreadyHasDev, AlreadyHasFsType, AlreadyHasTargetMountPoint, AlreadyMounted
+from .tags import (
+ Tags,
+ UnknownTag,
+ TagInUse,
+ AlreadyHasDev,
+ AlreadyHasFsType,
+ AlreadyHasTargetMountPoint,
+ AlreadyMounted,
+ NeedBothMountPoints,
+)
from .unmount import unmount, NotMounted
from .spec import (
Spec,
diff --git a/vmdb/tags.py b/vmdb/tags.py
index d774ec5..7cbae09 100644
--- a/vmdb/tags.py
+++ b/vmdb/tags.py
@@ -90,6 +90,12 @@ class Tags:
raise AlreadyHasTargetMountPoint(tag)
item['target_mount_point'] = target_mount_point
+ def get_builder_from_target_mount_point(self, target_mount_point):
+ for item in self._tags.values():
+ if item['target_mount_point'] == target_mount_point:
+ return item['builder_mount_point']
+ raise NeedBothMountPoints(target_mount_point)
+
def _get(self, tag):
item = self._tags.get(tag)
if item is None:
@@ -131,3 +137,10 @@ class AlreadyHasTargetMountPoint(Exception):
def __init__(self, tag):
super().__init__('Already has target mount point: {}'.format(tag))
+
+
+class NeedBothMountPoints(Exception):
+
+ def __init__(self, target_mp):
+ super().__init__(
+ 'Need both mount points set, target: {}'.format(target_mp))
diff --git a/vmdb/tags_tests.py b/vmdb/tags_tests.py
index 48d0b2a..29ca68e 100644
--- a/vmdb/tags_tests.py
+++ b/vmdb/tags_tests.py
@@ -46,7 +46,7 @@ class TagsTests(unittest.TestCase):
with self.assertRaises(vmdb.UnknownTag):
tags.get_dev('does-not-exist')
- def test_get_mount_point_raises_error_for_unknown_tag(self):
+ def test_getting_builder_mount_point_raises_error_for_unknown_tag(self):
tags = vmdb.Tags()
with self.assertRaises(vmdb.UnknownTag):
tags.get_builder_mount_point('does-not-exist')
@@ -65,7 +65,7 @@ class TagsTests(unittest.TestCase):
self.assertEqual(tags.get_dev('first'), '/dev/foo')
self.assertEqual(tags.get_builder_mount_point('first'), None)
- def test_adds_mount_point(self):
+ def test_adds_builder_mount_point(self):
tags = vmdb.Tags()
tags.append('first')
tags.set_builder_mount_point('first', '/mnt/foo')
@@ -73,13 +73,13 @@ class TagsTests(unittest.TestCase):
self.assertEqual(tags.get_dev('first'), None)
self.assertEqual(tags.get_builder_mount_point('first'), '/mnt/foo')
- def test_mount_point_is_uncached_by_default(self):
+ def test_builder_mount_point_is_uncached_by_default(self):
tags = vmdb.Tags()
tags.append('first')
tags.set_builder_mount_point('first', '/mnt/foo')
self.assertFalse(tags.is_cached('first'))
- def test_mount_point_can_be_made_cached(self):
+ def test_builder_mount_point_can_be_made_cached(self):
tags = vmdb.Tags()
tags.append('first')
tags.set_builder_mount_point('first', '/mnt/foo', cached=True)
@@ -134,3 +134,20 @@ class TagsTests(unittest.TestCase):
tags.set_target_mount_point('first', '/boot')
with self.assertRaises(vmdb.AlreadyHasTargetMountPoint):
tags.set_target_mount_point('first', '/')
+
+ def test_raises_error_if_both_mount_points_not_set(self):
+ tags = vmdb.Tags()
+ tags.append('first')
+ tags.set_target_mount_point('first', '/boot')
+ with self.assertRaises(vmdb.NeedBothMountPoints):
+ tags.get_builder_from_target_mount_point('/')
+
+ def test_returns_builder_when_given_target_mount_point(self):
+ tags = vmdb.Tags()
+ tags.append('first')
+ tags.set_builder_mount_point('first', '/mnt/foo')
+ tags.set_target_mount_point('first', '/boot')
+ self.assertEqual(
+ tags.get_builder_from_target_mount_point('/boot'),
+ '/mnt/foo'
+ )