diff options
author | Lars Wirzenius <liw@liw.fi> | 2019-01-01 12:08:18 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2019-01-01 12:08:18 +0200 |
commit | d167338338d08748caa94799fb424ee35b6a0325 (patch) | |
tree | e9e094dc3f44f987d4ad8579db0656581c858268 | |
parent | 1a893d445228b18a5121d200a0207f22930ba5ce (diff) | |
download | vmdb2-d167338338d08748caa94799fb424ee35b6a0325.tar.gz |
Add: mark mount points as (not) cached in tags table
-rw-r--r-- | vmdb/tags.py | 7 | ||||
-rw-r--r-- | vmdb/tags_tests.py | 12 |
2 files changed, 18 insertions, 1 deletions
diff --git a/vmdb/tags.py b/vmdb/tags.py index 337b36d..1dccfc5 100644 --- a/vmdb/tags.py +++ b/vmdb/tags.py @@ -45,6 +45,10 @@ class Tags: item = self._get(tag) return item['mount_point'] + def is_cached(self, tag): + item = self._get(tag) + return item['cached'] + def append(self, tag): if tag in self._tags: raise TagInUse(tag) @@ -60,11 +64,12 @@ class Tags: raise AlreadyHasDev(tag) item['dev'] = dev - def set_mount_point(self, tag, mount_point): + def set_mount_point(self, tag, mount_point, cached=False): item = self._get(tag) if item['mount_point'] is not None: raise AlreadyMounted(tag) item['mount_point'] = mount_point + item['cached'] = cached def _get(self, tag): item = self._tags.get(tag) diff --git a/vmdb/tags_tests.py b/vmdb/tags_tests.py index e4d342a..928b875 100644 --- a/vmdb/tags_tests.py +++ b/vmdb/tags_tests.py @@ -73,6 +73,18 @@ class TagsTests(unittest.TestCase): self.assertEqual(tags.get_dev('first'), None) self.assertEqual(tags.get_mount_point('first'), '/mnt/foo') + def test_mount_point_is_uncached_by_default(self): + tags = vmdb.Tags() + tags.append('first') + tags.set_mount_point('first', '/mnt/foo') + self.assertFalse(tags.is_cached('first')) + + def test_mount_point_can_be_made_cached(self): + tags = vmdb.Tags() + tags.append('first') + tags.set_mount_point('first', '/mnt/foo', cached=True) + self.assertTrue(tags.is_cached('first')) + def test_set_dev_raises_error_for_unknown_tag(self): tags = vmdb.Tags() with self.assertRaises(vmdb.UnknownTag): |