Ejemplo n.º 1
0
    def test_create_non_existing_replicated_rule(self, m_run_command,
                                                 m_exit_json):
        ca_test_common.set_module_args({
            'name': fake_name,
            'rule_type': 'replicated',
            'bucket_root': fake_bucket_root,
            'bucket_type': fake_bucket_type
        })
        m_exit_json.side_effect = ca_test_common.exit_json
        get_rc = 2
        get_stderr = 'Error ENOENT: unknown crush rule \'{}\''.format(
            fake_name)
        get_stdout = ''
        create_rc = 0
        create_stderr = ''
        create_stdout = ''
        m_run_command.side_effect = [(get_rc, get_stdout, get_stderr),
                                     (create_rc, create_stdout, create_stderr)]

        with pytest.raises(ca_test_common.AnsibleExitJson) as result:
            ceph_crush_rule.main()

        result = result.value.args[0]
        assert result['changed']
        assert result['cmd'] == [
            'ceph', '-n', fake_user, '-k', fake_keyring, '--cluster',
            fake_cluster, 'osd', 'crush', 'rule', 'create-replicated',
            fake_name, fake_bucket_root, fake_bucket_type
        ]
        assert result['rc'] == create_rc
        assert result['stderr'] == create_stderr
        assert result['stdout'] == create_stdout
Ejemplo n.º 2
0
    def test_create_existing_replicated_rule(self, m_run_command, m_exit_json):
        ca_test_common.set_module_args({
            'name': fake_name,
            'rule_type': 'replicated',
            'bucket_root': fake_bucket_root,
            'bucket_type': fake_bucket_type
        })
        m_exit_json.side_effect = ca_test_common.exit_json
        rc = 0
        stderr = ''
        stdout = '{{"rule_name":"{}","type":1,"steps":[{{"item_name":"{}"}},{{"type":"{}"}}]}}'.format(
            fake_name, fake_bucket_root, fake_bucket_type)
        m_run_command.return_value = rc, stdout, stderr

        with pytest.raises(ca_test_common.AnsibleExitJson) as result:
            ceph_crush_rule.main()

        result = result.value.args[0]
        assert not result['changed']
        assert result['cmd'] == [
            'ceph', '-n', fake_user, '-k', fake_keyring, '--cluster',
            fake_cluster, 'osd', 'crush', 'rule', 'dump', fake_name,
            '--format=json'
        ]
        assert result['rc'] == 0
        assert result['stderr'] == stderr
        assert result['stdout'] == stdout
Ejemplo n.º 3
0
    def test_with_container(self, m_run_command, m_exit_json):
        ca_test_common.set_module_args({'name': fake_name, 'state': 'info'})
        m_exit_json.side_effect = ca_test_common.exit_json
        rc = 0
        stderr = ''
        stdout = '{{"rule_name":"{}","steps":[{{"item_name":"{}"}},{{"type":"{}"}}]}}'.format(
            fake_name, fake_bucket_root, fake_bucket_type)
        m_run_command.return_value = rc, stdout, stderr

        with pytest.raises(ca_test_common.AnsibleExitJson) as result:
            ceph_crush_rule.main()

        result = result.value.args[0]
        assert not result['changed']
        assert result['cmd'] == [
            fake_container_binary, 'run', '--rm', '--net=host', '-v',
            '/etc/ceph:/etc/ceph:z', '-v', '/var/lib/ceph/:/var/lib/ceph/:z',
            '-v', '/var/log/ceph/:/var/log/ceph/:z', '--entrypoint=ceph',
            fake_container_image, '-n', fake_user, '-k', fake_keyring,
            '--cluster', fake_cluster, 'osd', 'crush', 'rule', 'dump',
            fake_name, '--format=json'
        ]
        assert result['rc'] == rc
        assert result['stderr'] == stderr
        assert result['stdout'] == stdout
Ejemplo n.º 4
0
    def test_remove_existing_rule(self, m_run_command, m_exit_json):
        ca_test_common.set_module_args({'name': fake_name, 'state': 'absent'})
        m_exit_json.side_effect = ca_test_common.exit_json
        get_rc = 0
        get_stderr = ''
        get_stdout = '{{"rule_name":"{}","steps":[{{"item_name":"{}"}},{{"type":"{}"}}]}}'.format(
            fake_name, fake_bucket_root, fake_bucket_type)
        remove_rc = 0
        remove_stderr = ''
        remove_stdout = ''
        m_run_command.side_effect = [(get_rc, get_stdout, get_stderr),
                                     (remove_rc, remove_stdout, remove_stderr)]

        with pytest.raises(ca_test_common.AnsibleExitJson) as result:
            ceph_crush_rule.main()

        result = result.value.args[0]
        assert result['changed']
        assert result['cmd'] == [
            'ceph', '-n', fake_user, '-k', fake_keyring, '--cluster',
            fake_cluster, 'osd', 'crush', 'rule', 'rm', fake_name
        ]
        assert result['rc'] == remove_rc
        assert result['stderr'] == remove_stderr
        assert result['stdout'] == remove_stdout
Ejemplo n.º 5
0
    def test_update_existing_replicated_rule(self, m_run_command, m_fail_json):
        ca_test_common.set_module_args({
            'name': fake_name,
            'rule_type': 'replicated',
            'bucket_root': fake_bucket_root,
            'bucket_type': fake_bucket_type,
            'device_class': fake_device_class
        })
        m_fail_json.side_effect = ca_test_common.fail_json
        rc = 0
        stderr = ''
        stdout = '{{"type":3,"rule_name":"{}","steps":[{{"item_name":"default"}},{{"type":"host"}}]}}'.format(
            fake_name)
        m_run_command.return_value = rc, stdout, stderr

        with pytest.raises(ca_test_common.AnsibleFailJson) as result:
            ceph_crush_rule.main()

        result = result.value.args[0]
        print(result)
        assert not result['changed']
        assert result[
            'msg'] == 'Can not convert crush rule {} to replicated'.format(
                fake_name)
        assert result['rc'] == 1
Ejemplo n.º 6
0
    def test_without_parameters(self, m_fail_json):
        ca_test_common.set_module_args({})
        m_fail_json.side_effect = ca_test_common.fail_json

        with pytest.raises(ca_test_common.AnsibleFailJson) as result:
            ceph_crush_rule.main()

        result = result.value.args[0]
        assert result['msg'] == 'missing required arguments: name'
Ejemplo n.º 7
0
    def test_with_name_only(self, m_fail_json):
        ca_test_common.set_module_args({'name': fake_name})
        m_fail_json.side_effect = ca_test_common.fail_json

        with pytest.raises(ca_test_common.AnsibleFailJson) as result:
            ceph_crush_rule.main()

        result = result.value.args[0]
        assert result[
            'msg'] == 'state is present but all of the following are missing: rule_type'
Ejemplo n.º 8
0
    def test_with_check_mode(self, m_exit_json):
        ca_test_common.set_module_args({
            'name': fake_name,
            'rule_type': 'replicated',
            'bucket_root': fake_bucket_root,
            'bucket_type': fake_bucket_type,
            '_ansible_check_mode': True
        })
        m_exit_json.side_effect = ca_test_common.exit_json

        with pytest.raises(ca_test_common.AnsibleExitJson) as result:
            ceph_crush_rule.main()

        result = result.value.args[0]
        assert not result['changed']
        assert result['rc'] == 0
        assert not result['stdout']
        assert not result['stderr']
Ejemplo n.º 9
0
    def test_get_non_existing_rule(self, m_run_command, m_exit_json):
        ca_test_common.set_module_args({'name': fake_name, 'state': 'info'})
        m_exit_json.side_effect = ca_test_common.exit_json
        rc = 2
        stderr = 'Error ENOENT: unknown crush rule \'{}\''.format(fake_name)
        stdout = ''
        m_run_command.return_value = rc, stdout, stderr

        with pytest.raises(ca_test_common.AnsibleExitJson) as result:
            ceph_crush_rule.main()

        result = result.value.args[0]
        assert not result['changed']
        assert result['cmd'] == [
            'ceph', '-n', fake_user, '-k', fake_keyring, '--cluster',
            fake_cluster, 'osd', 'crush', 'rule', 'dump', fake_name,
            '--format=json'
        ]
        assert result['rc'] == rc
        assert result['stderr'] == stderr
        assert result['stdout'] == stdout