summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorConrad Hoffmann <1226676+bitfehler@users.noreply.github.com>2020-01-14 21:27:59 +0100
committerDaniel Watkins <oddbloke@ubuntu.com>2020-01-14 15:27:59 -0500
commitbb4131a2bd36d9e8932fdcb61432260f16159cde (patch)
treebe3501e7efbdfe21d221e4d221120f88ebdbba62 /tests
parent863394ba0b5f18483b350daec30af8434be8811b (diff)
downloadvyos-cloud-init-bb4131a2bd36d9e8932fdcb61432260f16159cde.tar.gz
vyos-cloud-init-bb4131a2bd36d9e8932fdcb61432260f16159cde.zip
Only use gpart if it is the BSD gpart (#131)
Currently, cloud-init will happily try to run `gpart` on Linux even though on most distributions this a different tool [1]. Extend the availability check to make sure the `gpart` present is really the BSD variant, to avoid accidental execution. Also add a pointer to the docs, so that people do not try to install gpart on Linux in the expectation it will work with this module. [1] https://github.com/baruch/gpart
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test_handler/test_handler_growpart.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/tests/unittests/test_handler/test_handler_growpart.py b/tests/unittests/test_handler/test_handler_growpart.py
index a3e46351..1f39ebe7 100644
--- a/tests/unittests/test_handler/test_handler_growpart.py
+++ b/tests/unittests/test_handler/test_handler_growpart.py
@@ -52,6 +52,18 @@ growpart disk partition
Resize partition 1 on /dev/sda
"""
+HELP_GPART = """
+usage: gpart add -t type [-a alignment] [-b start] <SNIP> geom
+ gpart backup geom
+ gpart bootcode [-b bootcode] [-p partcode -i index] [-f flags] geom
+<SNIP>
+ gpart resize -i index [-a alignment] [-s size] [-f flags] geom
+ gpart restore [-lF] [-f flags] provider [...]
+ gpart recover [-f flags] geom
+ gpart help
+<SNIP>
+"""
+
class TestDisabled(unittest.TestCase):
def setUp(self):
@@ -97,8 +109,9 @@ class TestConfig(TestCase):
self.handle(self.name, config, self.cloud_init, self.log,
self.args)
- mockobj.assert_called_once_with(
- ['growpart', '--help'], env={'LANG': 'C'})
+ mockobj.assert_has_calls([
+ mock.call(['growpart', '--help'], env={'LANG': 'C'}),
+ mock.call(['gpart', 'help'], env={'LANG': 'C'}, rcs=[0, 1])])
@mock.patch.dict("os.environ", clear=True)
def test_no_resizers_mode_growpart_is_exception(self):
@@ -124,6 +137,18 @@ class TestConfig(TestCase):
mockobj.assert_called_once_with(
['growpart', '--help'], env={'LANG': 'C'})
+ @mock.patch.dict("os.environ", clear=True)
+ def test_mode_auto_falls_back_to_gpart(self):
+ with mock.patch.object(
+ util, 'subp',
+ return_value=("", HELP_GPART)) as mockobj:
+ ret = cc_growpart.resizer_factory(mode="auto")
+ self.assertIsInstance(ret, cc_growpart.ResizeGpart)
+
+ mockobj.assert_has_calls([
+ mock.call(['growpart', '--help'], env={'LANG': 'C'}),
+ mock.call(['gpart', 'help'], env={'LANG': 'C'}, rcs=[0, 1])])
+
def test_handle_with_no_growpart_entry(self):
# if no 'growpart' entry in config, then mode=auto should be used