Skip to content

Commit

Permalink
CI Unittests errors fix
Browse files Browse the repository at this point in the history
Fix failing unittests

Signed-off-by: Teoman ONAY <[email protected]>
(cherry picked from commit 3814c2e)
  • Loading branch information
asm0deuz committed Dec 5, 2024
1 parent 88b6ece commit c39137a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 29 deletions.
6 changes: 3 additions & 3 deletions library/radosgw_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
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
2 changes: 1 addition & 1 deletion tests/library/test_ceph_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/library/test_radosgw_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit c39137a

Please sign in to comment.