From 6671cb4fd1636505b1a10d81d3bd0db23bb2fbd0 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Thu, 22 Feb 2018 13:47:53 -0500 Subject: [PATCH] ceph-volume tests.util update tests for mount flags Include parametrized flags for ensuring a combination of values will still be normalized regardless on how they are on ceph.conf Signed-off-by: Alfredo Deza --- .../ceph_volume/tests/util/test_prepare.py | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/src/ceph-volume/ceph_volume/tests/util/test_prepare.py b/src/ceph-volume/ceph_volume/tests/util/test_prepare.py index 2524f0eb128c1..c65e51f6b5d6b 100644 --- a/src/ceph-volume/ceph_volume/tests/util/test_prepare.py +++ b/src/ceph-volume/ceph_volume/tests/util/test_prepare.py @@ -150,7 +150,7 @@ class TestMountOSD(object): prepare.mount_osd('/dev/sda1', 1) expected = [ 'mount', '-t', 'xfs', '-o', - 'rw', 'noatime', 'inode64', # default flags + 'rw,noatime,inode64', # default flags '/dev/sda1', '/var/lib/ceph/osd/ceph-1'] assert expected == fake_run.calls[0]['args'][0] @@ -167,7 +167,7 @@ class TestMountOSD(object): '/dev/sda1', '/var/lib/ceph/osd/ceph-1'] assert expected == fake_run.calls[0]['args'][0] - def test_multiple_options_are_used(self, conf_ceph_stub, fake_run): + def test_multiple_whitespace_options_are_used(self, conf_ceph_stub, fake_run): conf_ceph_stub(dedent("""[global] fsid = 1234lkjh1234 [osd] @@ -176,7 +176,20 @@ class TestMountOSD(object): prepare.mount_osd('/dev/sda1', 1) expected = [ 'mount', '-t', 'xfs', '-o', - 'rw', 'auto', 'exec', + 'rw,auto,exec', + '/dev/sda1', '/var/lib/ceph/osd/ceph-1'] + assert expected == fake_run.calls[0]['args'][0] + + def test_multiple_comma_whitespace_options_are_used(self, conf_ceph_stub, fake_run): + conf_ceph_stub(dedent("""[global] + fsid = 1234lkjh1234 + [osd] + osd mount options xfs = rw, auto, exec""")) + conf.cluster = 'ceph' + prepare.mount_osd('/dev/sda1', 1) + expected = [ + 'mount', '-t', 'xfs', '-o', + 'rw,auto,exec', '/dev/sda1', '/var/lib/ceph/osd/ceph-1'] assert expected == fake_run.calls[0]['args'][0] @@ -192,3 +205,40 @@ class TestMountOSD(object): 'rw', '/dev/sda1', '/var/lib/ceph/osd/ceph-1'] assert expected == fake_run.calls[0]['args'][0] + + +ceph_conf_mount_values = [ + ['rw,', 'auto,' 'exec'], + ['rw', 'auto', 'exec'], + [' rw ', ' auto ', ' exec '], + ['rw,', 'auto,', 'exec,'], + [',rw ', ',auto ', ',exec,'], + [',rw,', ',auto,', ',exec,'], +] + +string_mount_values = [ + 'rw, auto exec ', + 'rw auto exec', + ',rw, auto, exec,', + ' rw auto exec ', + ' rw,auto,exec ', + 'rw,auto,exec', + ',rw,auto,exec,', + 'rw,auto,exec ', + 'rw, auto, exec ', +] + + +class TestNormalizeFlags(object): + # a bit overkill since most of this is already tested in prepare.mount_osd + # tests + + @pytest.mark.parametrize("flags", ceph_conf_mount_values) + def test_normalize_lists(self, flags): + result = prepare._normalize_mount_flags(flags) + assert result == 'rw,auto,exec' + + @pytest.mark.parametrize("flags", string_mount_values) + def test_normalize_strings(self, flags): + result = prepare._normalize_mount_flags(flags) + assert result == 'rw,auto,exec' -- 2.39.5