Beispiel #1
0
    def test_should_do_nothing_when_enclosure_group_not_exist(self):
        self.resource.get_by.return_value = []

        self.mock_ansible_module.params = yaml.load(
            YAML_ENCLOSURE_GROUP_ABSENT)

        EnclosureGroupModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False, msg=ENCLOSURE_GROUP_ALREADY_ABSENT)
Beispiel #2
0
    def test_should_remove_enclosure_group(self):
        self.resource.get_by.return_value = [DICT_DEFAULT_ENCLOSURE_GROUP]

        self.mock_ansible_module.params = yaml.load(
            YAML_ENCLOSURE_GROUP_ABSENT)

        EnclosureGroupModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True, msg=ENCLOSURE_GROUP_DELETED)
Beispiel #3
0
    def test_should_not_update_when_data_is_equals(self):
        self.resource.get_by.return_value = [DICT_DEFAULT_ENCLOSURE_GROUP]

        self.mock_ansible_module.params = yaml.load(YAML_ENCLOSURE_GROUP)

        EnclosureGroupModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=ENCLOSURE_GROUP_ALREADY_EXIST,
            ansible_facts=dict(enclosure_group=DICT_DEFAULT_ENCLOSURE_GROUP))
Beispiel #4
0
    def test_should_load_config_from_file(self, mock_ansible_module,
                                          mock_ov_client_from_env_vars,
                                          mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock({'config': 'config.json'})
        mock_ansible_module.return_value = mock_ansible_instance

        EnclosureGroupModule()

        mock_ov_client_from_json_file.assert_called_once_with('config.json')
        mock_ov_client_from_env_vars.not_been_called()
Beispiel #5
0
    def test_should_create_new_enclosure_group(self):
        self.resource.get_by.return_value = []
        self.resource.create.return_value = {"name": "name"}

        self.mock_ansible_module.params = yaml.load(YAML_ENCLOSURE_GROUP)

        EnclosureGroupModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ENCLOSURE_GROUP_CREATED,
            ansible_facts=dict(enclosure_group={"name": "name"}))
Beispiel #6
0
    def test_should_do_nothing_when_enclosure_group_not_exist(
            self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.enclosure_groups.get_by.return_value = []

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock_yaml(
            YAML_ENCLOSURE_GROUP_ABSENT)
        mock_ansible_module.return_value = mock_ansible_instance

        EnclosureGroupModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False, msg=ENCLOSURE_GROUP_ALREADY_ABSENT)
Beispiel #7
0
    def test_should_fail_when_create_raises_exception(
            self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.enclosure_groups.get_by.return_value = []
        mock_ov_instance.enclosure_groups.create.side_effect = Exception(
            FAKE_MSG_ERROR)

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock_yaml(YAML_ENCLOSURE_GROUP)
        mock_ansible_module.return_value = mock_ansible_instance

        self.assertRaises(Exception, EnclosureGroupModule().run())

        mock_ansible_instance.fail_json.assert_called_once_with(
            msg=FAKE_MSG_ERROR)
Beispiel #8
0
    def test_should_remove_enclosure_group(self, mock_ansible_module,
                                           mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.enclosure_groups.get_by.return_value = [
            DICT_DEFAULT_ENCLOSURE_GROUP
        ]

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock_yaml(
            YAML_ENCLOSURE_GROUP_ABSENT)
        mock_ansible_module.return_value = mock_ansible_instance

        EnclosureGroupModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=True, msg=ENCLOSURE_GROUP_DELETED)
Beispiel #9
0
    def test_update_when_data_has_modified_attributes(self):
        data_merged = DICT_DEFAULT_ENCLOSURE_GROUP.copy()
        data_merged['newName'] = 'New Name'

        self.resource.get_by.return_value = [DICT_DEFAULT_ENCLOSURE_GROUP]
        self.resource.update.return_value = data_merged

        self.mock_ansible_module.params = yaml.load(
            YAML_ENCLOSURE_GROUP_CHANGES)

        EnclosureGroupModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ENCLOSURE_GROUP_UPDATED,
            ansible_facts=dict(enclosure_group=data_merged))
Beispiel #10
0
    def test_should_not_update_when_data_is_equals(
            self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.enclosure_groups.get_by.return_value = [
            DICT_DEFAULT_ENCLOSURE_GROUP
        ]

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock_yaml(YAML_ENCLOSURE_GROUP)
        mock_ansible_module.return_value = mock_ansible_instance

        EnclosureGroupModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            msg=ENCLOSURE_GROUP_ALREADY_EXIST,
            ansible_facts=dict(enclosure_group=DICT_DEFAULT_ENCLOSURE_GROUP))
Beispiel #11
0
    def test_should_create_new_enclosure_group(self, mock_ansible_module,
                                               mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.enclosure_groups.get_by.return_value = []
        mock_ov_instance.enclosure_groups.create.return_value = {
            "name": "name"
        }

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock_yaml(YAML_ENCLOSURE_GROUP)
        mock_ansible_module.return_value = mock_ansible_instance

        EnclosureGroupModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=True,
            msg=ENCLOSURE_GROUP_CREATED,
            ansible_facts=dict(enclosure_group={"name": "name"}))
Beispiel #12
0
    def test_update_when_script_attribute_was_not_modified(self):
        data_merged = DICT_DEFAULT_ENCLOSURE_GROUP.copy()
        data_merged['newName'] = 'New Name'
        data_merged['uri'] = '/rest/uri'

        self.resource.get_by.return_value = [data_merged]
        self.resource.update_script.return_value = ""
        self.resource.get_script.return_value = "# test script "

        self.mock_ansible_module.params = yaml.load(
            YAML_ENCLOSURE_GROUP_CHANGE_SCRIPT)

        EnclosureGroupModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=ENCLOSURE_GROUP_ALREADY_EXIST,
            ansible_facts=dict(enclosure_group=data_merged))
Beispiel #13
0
    def test_update_when_script_attribute_was_modified(
            self, mock_ansible_module, mock_ov_client_from_json_file):
        data_merged = DICT_DEFAULT_ENCLOSURE_GROUP.copy()
        data_merged['newName'] = 'New Name'
        data_merged['uri'] = '/rest/uri'

        mock_ov_instance = mock.Mock()
        mock_ov_instance.enclosure_groups.get_by.return_value = [data_merged]
        mock_ov_instance.enclosure_groups.update_script.return_value = ""
        mock_ov_instance.enclosure_groups.get_by.get_script = "# test script"

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock_yaml(
            YAML_ENCLOSURE_GROUP_CHANGE_SCRIPT)
        mock_ansible_module.return_value = mock_ansible_instance

        EnclosureGroupModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=True,
            msg=ENCLOSURE_GROUP_UPDATED,
            ansible_facts=dict(enclosure_group=data_merged))