summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/config/cc_growpart.py3
-rw-r--r--cloudinit/config/cc_resizefs.py6
-rw-r--r--cloudinit/util.py22
-rw-r--r--tests/unittests/test_datasource/test_azure.py24
-rw-r--r--tests/unittests/test_distros/test_freebsd.py45
-rw-r--r--tests/unittests/test_handler/test_handler_resizefs.py2
6 files changed, 64 insertions, 38 deletions
diff --git a/cloudinit/config/cc_growpart.py b/cloudinit/config/cc_growpart.py
index bafca9d8..564f376f 100644
--- a/cloudinit/config/cc_growpart.py
+++ b/cloudinit/config/cc_growpart.py
@@ -215,7 +215,8 @@ def device_part_info(devpath):
# FreeBSD doesn't know of sysfs so just get everything we need from
# the device, like /dev/vtbd0p2.
if util.is_FreeBSD():
- m = re.search('^(/dev/.+)p([0-9])$', devpath)
+ freebsd_part = "/dev/" + util.find_freebsd_part(devpath)
+ m = re.search('^(/dev/.+)p([0-9])$', freebsd_part)
return (m.group(1), m.group(2))
if not os.path.exists(syspath):
diff --git a/cloudinit/config/cc_resizefs.py b/cloudinit/config/cc_resizefs.py
index 076b9d5a..afd2e060 100644
--- a/cloudinit/config/cc_resizefs.py
+++ b/cloudinit/config/cc_resizefs.py
@@ -81,7 +81,7 @@ def _resize_xfs(mount_point, devpth):
def _resize_ufs(mount_point, devpth):
- return ('growfs', '-y', devpth)
+ return ('growfs', '-y', mount_point)
def _resize_zfs(mount_point, devpth):
@@ -101,7 +101,7 @@ def _can_skip_resize_ufs(mount_point, devpth):
"""
# dumpfs -m /
# newfs command for / (/dev/label/rootfs)
- newfs -O 2 -U -a 4 -b 32768 -d 32768 -e 4096 -f 4096 -g 16384
+ newfs -L rootf -O 2 -U -a 4 -b 32768 -d 32768 -e 4096 -f 4096 -g 16384
-h 64 -i 8192 -j -k 6408 -m 8 -o time -s 58719232 /dev/label/rootf
"""
cur_fs_sz = None
@@ -110,7 +110,7 @@ def _can_skip_resize_ufs(mount_point, devpth):
for line in dumpfs_res.splitlines():
if not line.startswith('#'):
newfs_cmd = shlex.split(line)
- opt_value = 'O:Ua:s:b:d:e:f:g:h:i:jk:m:o:'
+ opt_value = 'O:Ua:s:b:d:e:f:g:h:i:jk:m:o:L:'
optlist, _args = getopt.getopt(newfs_cmd[1:], opt_value)
for o, a in optlist:
if o == "-s":
diff --git a/cloudinit/util.py b/cloudinit/util.py
index ea4199cd..aa23b3f3 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -2337,17 +2337,21 @@ def parse_mtab(path):
return None
-def find_freebsd_part(label_part):
- if label_part.startswith("/dev/label/"):
- target_label = label_part[5:]
- (label_part, _err) = subp(['glabel', 'status', '-s'])
- for labels in label_part.split("\n"):
+def find_freebsd_part(fs):
+ splitted = fs.split('/')
+ if len(splitted) == 3:
+ return splitted[2]
+ elif splitted[2] in ['label', 'gpt', 'ufs']:
+ target_label = fs[5:]
+ (part, _err) = subp(['glabel', 'status', '-s'])
+ for labels in part.split("\n"):
items = labels.split()
- if len(items) > 0 and items[0].startswith(target_label):
- label_part = items[2]
+ if len(items) > 0 and items[0] == target_label:
+ part = items[2]
break
- label_part = str(label_part)
- return label_part
+ return str(part)
+ else:
+ LOG.warning("Unexpected input in find_freebsd_part: %s", fs)
def get_path_dev_freebsd(path, mnt_list):
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
index 427ab7e7..afb614e4 100644
--- a/tests/unittests/test_datasource/test_azure.py
+++ b/tests/unittests/test_datasource/test_azure.py
@@ -6,7 +6,6 @@ from cloudinit import url_helper
from cloudinit.sources import (
UNSET, DataSourceAzure as dsaz, InvalidMetaDataException)
from cloudinit.util import (b64e, decode_binary, load_file, write_file,
- find_freebsd_part, get_path_dev_freebsd,
MountFailedError, json_dumps, load_json)
from cloudinit.version import version_string as vs
from cloudinit.tests.helpers import (
@@ -391,29 +390,6 @@ scbus-1 on xpt0 bus 0
dev = ds.get_resource_disk_on_freebsd(1)
self.assertEqual("da1", dev)
- @mock.patch('cloudinit.util.subp')
- def test_find_freebsd_part_on_Azure(self, mock_subp):
- glabel_out = '''
-gptid/fa52d426-c337-11e6-8911-00155d4c5e47 N/A da0p1
- label/rootfs N/A da0p2
- label/swap N/A da0p3
-'''
- mock_subp.return_value = (glabel_out, "")
- res = find_freebsd_part("/dev/label/rootfs")
- self.assertEqual("da0p2", res)
-
- def test_get_path_dev_freebsd_on_Azure(self):
- mnt_list = '''
-/dev/label/rootfs / ufs rw 1 1
-devfs /dev devfs rw,multilabel 0 0
-fdescfs /dev/fd fdescfs rw 0 0
-/dev/da1s1 /mnt/resource ufs rw 2 2
-'''
- with mock.patch.object(os.path, 'exists',
- return_value=True):
- res = get_path_dev_freebsd('/etc', mnt_list)
- self.assertIsNotNone(res)
-
@mock.patch(MOCKPATH + '_is_platform_viable')
def test_call_is_platform_viable_seed(self, m_is_platform_viable):
"""Check seed_dir using _is_platform_viable and return False."""
diff --git a/tests/unittests/test_distros/test_freebsd.py b/tests/unittests/test_distros/test_freebsd.py
new file mode 100644
index 00000000..8af253a2
--- /dev/null
+++ b/tests/unittests/test_distros/test_freebsd.py
@@ -0,0 +1,45 @@
+# This file is part of cloud-init. See LICENSE file for license information.
+
+from cloudinit.util import (find_freebsd_part, get_path_dev_freebsd)
+from cloudinit.tests.helpers import (CiTestCase, mock)
+
+import os
+
+
+class TestDeviceLookUp(CiTestCase):
+
+ @mock.patch('cloudinit.util.subp')
+ def test_find_freebsd_part_label(self, mock_subp):
+ glabel_out = '''
+gptid/fa52d426-c337-11e6-8911-00155d4c5e47 N/A da0p1
+ label/rootfs N/A da0p2
+ label/swap N/A da0p3
+'''
+ mock_subp.return_value = (glabel_out, "")
+ res = find_freebsd_part("/dev/label/rootfs")
+ self.assertEqual("da0p2", res)
+
+ @mock.patch('cloudinit.util.subp')
+ def test_find_freebsd_part_gpt(self, mock_subp):
+ glabel_out = '''
+ gpt/bootfs N/A vtbd0p1
+gptid/3f4cbe26-75da-11e8-a8f2-002590ec6166 N/A vtbd0p1
+ gpt/swapfs N/A vtbd0p2
+ gpt/rootfs N/A vtbd0p3
+ iso9660/cidata N/A vtbd2
+'''
+ mock_subp.return_value = (glabel_out, "")
+ res = find_freebsd_part("/dev/gpt/rootfs")
+ self.assertEqual("vtbd0p3", res)
+
+ def test_get_path_dev_freebsd_label(self):
+ mnt_list = '''
+/dev/label/rootfs / ufs rw 1 1
+devfs /dev devfs rw,multilabel 0 0
+fdescfs /dev/fd fdescfs rw 0 0
+/dev/da1s1 /mnt/resource ufs rw 2 2
+'''
+ with mock.patch.object(os.path, 'exists',
+ return_value=True):
+ res = get_path_dev_freebsd('/etc', mnt_list)
+ self.assertIsNotNone(res)
diff --git a/tests/unittests/test_handler/test_handler_resizefs.py b/tests/unittests/test_handler/test_handler_resizefs.py
index 35187847..db9a0414 100644
--- a/tests/unittests/test_handler/test_handler_resizefs.py
+++ b/tests/unittests/test_handler/test_handler_resizefs.py
@@ -147,7 +147,7 @@ class TestResizefs(CiTestCase):
def test_resize_ufs_cmd_return(self):
mount_point = '/'
devpth = '/dev/sda2'
- self.assertEqual(('growfs', '-y', devpth),
+ self.assertEqual(('growfs', '-y', mount_point),
_resize_ufs(mount_point, devpth))
@mock.patch('cloudinit.util.is_container', return_value=False)