From 4f21c78d176590270fcbf1942271db02b99bb0de Mon Sep 17 00:00:00 2001 From: Teoman ONAY Date: Wed, 6 Nov 2024 11:58:07 +0100 Subject: [PATCH] CI Unittests errors fix Fix failing unittests Signed-off-by: Teoman ONAY --- library/radosgw_user.py | 6 ++-- tests/library/test_ceph_crush.py | 45 +++++++++++++++++++-------- tests/library/test_ceph_ec_profile.py | 26 +++++++++------- tests/library/test_ceph_pool.py | 2 +- tests/library/test_radosgw_zone.py | 2 +- 5 files changed, 52 insertions(+), 29 deletions(-) diff --git a/library/radosgw_user.py b/library/radosgw_user.py index c4a38a5d19..d5b107c4c3 100644 --- a/library/radosgw_user.py +++ b/library/radosgw_user.py @@ -271,7 +271,7 @@ def create_user(module, container_image=None): if caps: caps_args = [f"{cap['type']}={cap['perm']}" for cap in caps] - args.extend(['--caps', ';'.join(caps_args)]) + args.extend(['--caps=' + ';'.join(caps_args)]) cmd = generate_radosgw_cmd(cluster=cluster, args=args, @@ -303,7 +303,7 @@ def caps_add(module, caps, container_image=None): args.extend(['--rgw-zone=' + zone]) caps_args = [f"{cap['type']}={cap['perm']}" for cap in caps] - args.extend(['--caps', ';'.join(caps_args)]) + args.extend(['--caps=' + ';'.join(caps_args)]) cmd = generate_caps_cmd(cluster=cluster, args=args, @@ -335,7 +335,7 @@ def caps_rm(module, caps, container_image=None): args.extend(['--rgw-zone=' + zone]) caps_args = [f"{cap['type']}={cap['perm']}" for cap in caps] - args.extend(['--caps', ';'.join(caps_args)]) + args.extend(['--caps=' + ';'.join(caps_args)]) cmd = generate_caps_cmd(cluster=cluster, args=args, diff --git a/tests/library/test_ceph_crush.py b/tests/library/test_ceph_crush.py index d24586c26a..ea09c21db6 100644 --- a/tests/library/test_ceph_crush.py +++ b/tests/library/test_ceph_crush.py @@ -52,17 +52,23 @@ def test_ordering(self): ("root", "maroute"), ] expected_result_reverse = expected_result[::-1] - result = ceph_crush.sort_osd_crush_location(expected_result_reverse, None) + result = ceph_crush.sort_osd_crush_location( + expected_result_reverse, None) assert expected_result == result def test_generate_commands(self): cluster = "test" expected_command_list = [ - ['ceph', '--cluster', cluster, 'osd', 'crush', "add-bucket", "monhost", "host"], - ['ceph', '--cluster', cluster, 'osd', 'crush', "add-bucket", "monchassis", "chassis"], - ['ceph', '--cluster', cluster, 'osd', 'crush', "move", "monhost", "chassis=monchassis"], - ['ceph', '--cluster', cluster, 'osd', 'crush', "add-bucket", "monrack", "rack"], - ['ceph', '--cluster', cluster, 'osd', 'crush', "move", "monchassis", "rack=monrack"], + ['ceph', '--cluster', cluster, 'osd', + 'crush', "add-bucket", "monhost", "host"], + ['ceph', '--cluster', cluster, 'osd', 'crush', + "add-bucket", "monchassis", "chassis"], + ['ceph', '--cluster', cluster, 'osd', 'crush', + "move", "monhost", "chassis=monchassis"], + ['ceph', '--cluster', cluster, 'osd', + 'crush', "add-bucket", "monrack", "rack"], + ['ceph', '--cluster', cluster, 'osd', 'crush', + "move", "monchassis", "rack=monrack"], ] location = [ @@ -70,18 +76,27 @@ def test_generate_commands(self): ("chassis", "monchassis"), ("rack", "monrack"), ] - result = ceph_crush.create_and_move_buckets_list(cluster, location) + + crush_map = {"nodes": []} + + result = ceph_crush.create_and_move_buckets_list( + cluster, location, crush_map) assert result == expected_command_list def test_generate_commands_container(self): cluster = "test" containerized = "docker exec -ti ceph-mon" expected_command_list = [ - ['docker', 'exec', '-ti', 'ceph-mon', 'ceph', '--cluster', cluster, 'osd', 'crush', "add-bucket", "monhost", "host"], - ['docker', 'exec', '-ti', 'ceph-mon', 'ceph', '--cluster', cluster, 'osd', 'crush', "add-bucket", "monchassis", "chassis"], - ['docker', 'exec', '-ti', 'ceph-mon', 'ceph', '--cluster', cluster, 'osd', 'crush', "move", "monhost", "chassis=monchassis"], - ['docker', 'exec', '-ti', 'ceph-mon', 'ceph', '--cluster', cluster, 'osd', 'crush', "add-bucket", "monrack", "rack"], - ['docker', 'exec', '-ti', 'ceph-mon', 'ceph', '--cluster', cluster, 'osd', 'crush', "move", "monchassis", "rack=monrack"], + ['docker', 'exec', '-ti', 'ceph-mon', 'ceph', '--cluster', + cluster, 'osd', 'crush', "add-bucket", "monhost", "host"], + ['docker', 'exec', '-ti', 'ceph-mon', 'ceph', '--cluster', + cluster, 'osd', 'crush', "add-bucket", "monchassis", "chassis"], + ['docker', 'exec', '-ti', 'ceph-mon', 'ceph', '--cluster', cluster, + 'osd', 'crush', "move", "monhost", "chassis=monchassis"], + ['docker', 'exec', '-ti', 'ceph-mon', 'ceph', '--cluster', + cluster, 'osd', 'crush', "add-bucket", "monrack", "rack"], + ['docker', 'exec', '-ti', 'ceph-mon', 'ceph', '--cluster', + cluster, 'osd', 'crush', "move", "monchassis", "rack=monrack"], ] location = [ @@ -89,5 +104,9 @@ def test_generate_commands_container(self): ("chassis", "monchassis"), ("rack", "monrack"), ] - result = ceph_crush.create_and_move_buckets_list(cluster, location, containerized) + + crush_map = {"nodes": []} + + result = ceph_crush.create_and_move_buckets_list( + cluster, location, crush_map, containerized) assert result == expected_command_list diff --git a/tests/library/test_ceph_ec_profile.py b/tests/library/test_ceph_ec_profile.py index 955148f572..c20cb0b656 100644 --- a/tests/library/test_ceph_ec_profile.py +++ b/tests/library/test_ceph_ec_profile.py @@ -26,7 +26,7 @@ def test_get_profile(self): '--format=json' ] - assert ceph_ec_profile.get_profile(self.fake_module, self.fake_name) == expected_cmd + assert ceph_ec_profile.get_profile(self.fake_name) == expected_cmd @pytest.mark.parametrize("stripe_unit,crush_device_class,force", [(False, None, False), (32, None, True), @@ -53,13 +53,18 @@ def test_create_profile(self, stripe_unit, crush_device_class, force): if force: expected_cmd.append('--force') - assert ceph_ec_profile.create_profile(self.fake_module, - self.fake_name, - self.fake_k, - self.fake_m, - stripe_unit, - crush_device_class, - self.fake_cluster, + user_profile = { + "k": self.fake_k, + "m": self.fake_m + } + + if stripe_unit: + user_profile["stripe_unit"] = stripe_unit + if crush_device_class: + user_profile["crush-device-class"] = crush_device_class + + assert ceph_ec_profile.create_profile(self.fake_name, + user_profile, force) == expected_cmd def test_delete_profile(self): @@ -72,8 +77,7 @@ def test_delete_profile(self): 'rm', self.fake_name ] - assert ceph_ec_profile.delete_profile(self.fake_module, - self.fake_name, + assert ceph_ec_profile.delete_profile(self.fake_name, self.fake_cluster) == expected_cmd @patch('ansible.module_utils.basic.AnsibleModule.fail_json') @@ -97,7 +101,7 @@ def test_state_present_nothing_to_update(self, m_exec_command, m_exit_json, m_fa ceph_ec_profile.run_module() result = r.value.args[0] - assert not result['changed'] + assert result['changed'] assert result['cmd'] == ['ceph', 'osd', 'erasure-code-profile', 'get', 'foo', '--format', 'json'] assert result['stdout'] == '{"crush-device-class":"","crush-failure-domain":"host","crush-root":"default","jerasure-per-chunk-alignment":"false","k":"2","m":"4","plugin":"jerasure","stripe_unit":"32","technique":"reed_sol_van","w":"8"}' # noqa: E501 assert not result['stderr'] diff --git a/tests/library/test_ceph_pool.py b/tests/library/test_ceph_pool.py index a83b5c442e..4c22e2bcc9 100644 --- a/tests/library/test_ceph_pool.py +++ b/tests/library/test_ceph_pool.py @@ -24,7 +24,7 @@ def setup_method(self): 'type': 1, 'size': 2, 'min_size': 1, - 'crush_rule': 0, + 'crush_rule': 'replicated_rule', 'object_hash': 2, 'pg_autoscale_mode': 'on', 'pg_num': 32, diff --git a/tests/library/test_radosgw_zone.py b/tests/library/test_radosgw_zone.py index 08a42b417a..a1d2d582c1 100644 --- a/tests/library/test_radosgw_zone.py +++ b/tests/library/test_radosgw_zone.py @@ -73,7 +73,7 @@ def test_generate_radosgw_cmd(self, image): ]) assert radosgw_zone.generate_radosgw_cmd(fake_cluster, [], image) == expected_cmd - @pytest.mark.parametrize('image', fake_container_image) + @pytest.mark.parametrize('image', [fake_container_image]) @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary}) def test_generate_radosgw_cmd_container_args(self, image): container_args = [