Exemple #1
0
    def test_state_info(self, m_exec_commands, m_exit_json, output_format):
        ca_test_common.set_module_args({
            "state": "info",
            "cluster": "ceph",
            "name": "client.admin",
            "output_format": output_format
        })
        m_exit_json.side_effect = ca_test_common.exit_json
        m_exec_commands.return_value = (
            0,
            ['ceph', 'auth', 'get', 'client.admin', '-f', output_format],
            '[{"entity":"client.admin","key":"AQC1tw5fF156GhAAoJCvHGX/jl/k7/N4VZm8iQ==","caps":{"mds":"allow *","mgr":"allow *","mon":"allow *","osd":"allow *"}}]',  # noqa: E501
            'exported keyring for client.admin')

        with pytest.raises(ca_test_common.AnsibleExitJson) as result:
            ceph_key.run_module()

        result = result.value.args[0]
        assert not result['changed']
        assert result['cmd'] == [
            'ceph', 'auth', 'get', 'client.admin', '-f', output_format
        ]
        assert result[
            'stdout'] == '[{"entity":"client.admin","key":"AQC1tw5fF156GhAAoJCvHGX/jl/k7/N4VZm8iQ==","caps":{"mds":"allow *","mgr":"allow *","mon":"allow *","osd":"allow *"}}]'  # noqa: E501
        assert result['stderr'] == 'exported keyring for client.admin'
        assert result['rc'] == 0
Exemple #2
0
    def test_generate_key(self, m_exit_json, m_generate_secret):
        fake_secret = b'AQDaLb1fAAAAABAAsIMKdGEKu+lGOyXnRfT0Hg=='
        ca_test_common.set_module_args({"state": "generate_secret"})
        m_exit_json.side_effect = ca_test_common.exit_json
        m_generate_secret.return_value = fake_secret

        with pytest.raises(ca_test_common.AnsibleExitJson) as result:
            ceph_key.run_module()
        assert result.value.args[0]['stdout'] == fake_secret.decode()
Exemple #3
0
    def test_state_info_invalid_format(self, m_fail_json):
        invalid_format = 'txt'
        ca_test_common.set_module_args({
            "state": "info",
            "cluster": "ceph",
            "name": "client.admin",
            "output_format": invalid_format
        })
        m_fail_json.side_effect = ca_test_common.fail_json

        with pytest.raises(ca_test_common.AnsibleFailJson) as result:
            ceph_key.run_module()

        result = result.value.args[0]
        assert result[
            'msg'] == 'value of output_format must be one of: json, plain, xml, yaml, got: {}'.format(
                invalid_format)
Exemple #4
0
    def test_state_absent_non_existing_keyring(self, m_exec_commands, m_exit_json):
        set_module_args({"state": "absent",
                         "cluster": "ceph",
                         "name": "client.foo"
        })
        m_exit_json.side_effect = exit_json
        m_exec_commands.return_value = (1,
                                        ['ceph', 'auth', 'get', 'client.foo'] ,
                                        '', 'Error ENOENT: failed to find client.foo in keyring'
                                        )

        with pytest.raises(AnsibleExitJson) as result:
            ceph_key.run_module()

        result = result.value.args[0]
        assert result['changed'] == False
        assert result['stdout'] == ''
        assert result['stderr'] == 'Error ENOENT: failed to find client.foo in keyring'
        assert result['rc'] == 0
Exemple #5
0
    def test_state_absent_existing_keyring(self, m_exec_commands, m_exit_json):
        set_module_args({"state": "absent",
                         "cluster": "ceph",
                         "name": "client.foo"
        })
        m_exit_json.side_effect = exit_json
        m_exec_commands.return_value = (0,
                                        ['ceph', 'auth', 'rm', 'client.foo'] ,
                                        '', 'updated'
                                        )

        with pytest.raises(AnsibleExitJson) as result:
            ceph_key.run_module()

        result = result.value.args[0]
        assert result['changed'] == True
        assert result['stdout'] == ''
        assert result['stderr'] == 'updated'
        assert result['rc'] == 0