Skip to content

Commit

Permalink
CI Unittests errors fix
Browse files Browse the repository at this point in the history
Signed-off-by: Teoman ONAY <[email protected]>
  • Loading branch information
asm0deuz committed Dec 3, 2024
1 parent 9405558 commit f6f09d7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 24 deletions.
45 changes: 32 additions & 13 deletions tests/library/test_ceph_crush.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,42 +52,61 @@ 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 = [
("host", "monhost"),
("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 = [
("host", "monhost"),
("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
26 changes: 15 additions & 11 deletions tests/library/test_ceph_ec_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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):
Expand All @@ -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')
Expand All @@ -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']
Expand Down

0 comments on commit f6f09d7

Please sign in to comment.