Ejemplo n.º 1
0
    def test_state_present_nothing_to_update(self, m_exec_command, m_exit_json,
                                             m_fail_json):
        ca_test_common.set_module_args({
            "state": "present",
            "name": "foo",
            "k": 2,
            "m": 4,
            "stripe_unit": 32,
        })
        m_exit_json.side_effect = ca_test_common.exit_json
        m_fail_json.side_effect = ca_test_common.fail_json
        m_exec_command.return_value = (
            0,
            [
                'ceph', 'osd', 'erasure-code-profile', 'get', 'foo',
                '--format', 'json'
            ],
            '{"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
            '')

        with pytest.raises(ca_test_common.AnsibleExitJson) as r:
            ceph_ec_profile.run_module()

        result = r.value.args[0]
        assert not 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']
        assert result['rc'] == 0
Ejemplo n.º 2
0
    def test_state_present_profile_doesnt_exist(self, m_exec_command,
                                                m_exit_json, m_fail_json):
        ca_test_common.set_module_args({
            "state": "present",
            "name": "foo",
            "k": 2,
            "m": 4,
            "stripe_unit": 32
        })
        m_exit_json.side_effect = ca_test_common.exit_json
        m_fail_json.side_effect = ca_test_common.fail_json
        m_exec_command.side_effect = [
            (2, [
                'ceph', 'osd', 'erasure-code-profile', 'get', 'foo',
                '--format', 'json'
            ], '', "Error ENOENT: unknown erasure code profile 'foo'"),
            (0, [
                'ceph', 'osd', 'erasure-code-profile', 'set', 'foo', 'k=2',
                'm=4', 'stripe_unit=32', '--force'
            ], '', '')
        ]

        with pytest.raises(ca_test_common.AnsibleExitJson) as r:
            ceph_ec_profile.run_module()

        result = r.value.args[0]
        assert result['changed']
        assert result['cmd'] == [
            'ceph', 'osd', 'erasure-code-profile', 'set', 'foo', 'k=2', 'm=4',
            'stripe_unit=32', '--force'
        ]
        assert not result['stdout']
        assert not result['stderr']
        assert result['rc'] == 0
Ejemplo n.º 3
0
    def test_check_mode(self, m_exit_json):
        ca_test_common.set_module_args({
            'name': 'foo',
            'k': 2,
            'm': 4,
            '_ansible_check_mode': True
        })
        m_exit_json.side_effect = ca_test_common.exit_json

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

        result = result.value.args[0]
        assert not result['changed']
        assert result['rc'] == 0
        assert not result['stdout']
        assert not result['stderr']
Ejemplo n.º 4
0
    def test_state_absent_on_nonexisting_profile(self, m_exec_command,
                                                 m_exit_json, m_fail_json):
        ca_test_common.set_module_args({"state": "absent", "name": "foo"})
        m_exit_json.side_effect = ca_test_common.exit_json
        m_fail_json.side_effect = ca_test_common.fail_json
        m_exec_command.return_value = (0, [
            'ceph', 'osd', 'erasure-code-profile', 'rm', 'foo'
        ], '', 'erasure-code-profile foo does not exist')

        with pytest.raises(ca_test_common.AnsibleExitJson) as r:
            ceph_ec_profile.run_module()

        result = r.value.args[0]
        assert not result['changed']
        assert result['cmd'] == [
            'ceph', 'osd', 'erasure-code-profile', 'rm', 'foo'
        ]
        assert result['stdout'] == "Skipping, the profile foo doesn't exist"
        assert result['stderr'] == 'erasure-code-profile foo does not exist'
        assert result['rc'] == 0