Beispiel #1
0
    def test_should_not_update_from_group_when_resource_not_found(self):
        self.mock_ov_client.logical_enclosures.get_by_name.return_value = None
        self.mock_ansible_module.params = yaml.load(YAML_LOGICAL_ENCLOSURE_UPDATE_FROM_GROUP)

        LogicalEnclosureModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(msg=LogicalEnclosureModule.MSG_REQUIRED)
    def test_should_not_reconfigure_when_resource_not_found(self):
        self.resource.get_by_name.return_value = None
        self.mock_ansible_module.params = yaml.load(
            YAML_LOGICAL_ENCLOSURE_CONFIGURE)

        LogicalEnclosureModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            exception=mock.ANY, msg=LogicalEnclosureModule.MSG_REQUIRED)
    def test_should_not_generate_support_dump_when_resource_not_found(self):
        self.mock_ov_client.logical_enclosures.get_by_name.return_value = None
        self.mock_ansible_module.params = yaml.load(
            YAML_LOGICAL_ENCLOSURE_DUMP)

        LogicalEnclosureModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            exception=mock.ANY, msg=LogicalEnclosureModule.MSG_REQUIRED)
    def test_should_do_nothing_when_resource_already_absent(self):
        self.resource.get_by_name.return_value = None
        self.mock_ansible_module.params = yaml.load(
            YAML_LOGICAL_ENCLOSURE_ABSENT)

        LogicalEnclosureModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=LogicalEnclosureModule.MSG_ALREADY_ABSENT,
            ansible_facts=dict(logical_enclosure=None))
    def test_should_update_script_when_resource_exists(self):
        self.resource.data = DICT_DEFAULT_LOGICAL_ENCLOSURE
        self.mock_ansible_module.params = yaml.load(
            YAML_LOGICAL_ENCLOSURE_UPDATE_SCRIPT)

        LogicalEnclosureModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalEnclosureModule.MSG_CONFIGURATION_SCRIPT_UPDATED,
            ansible_facts=dict(configuration_script='# script (updated)'))
Beispiel #6
0
    def test_should_not_update_when_existing_data_is_equals(self):
        self.mock_ov_client.logical_enclosures.get_by_name.return_value = DICT_DEFAULT_LOGICAL_ENCLOSURE
        self.mock_ansible_module.params = yaml.load(YAML_LOGICAL_ENCLOSURE_NO_RENAME)

        LogicalEnclosureModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=LogicalEnclosureModule.MSG_ALREADY_PRESENT,
            ansible_facts=dict(logical_enclosure=DICT_DEFAULT_LOGICAL_ENCLOSURE)
        )
    def test_should_delete_logical_enclosure_when_resource_exist(self):
        self.resource.data = DICT_DEFAULT_LOGICAL_ENCLOSURE
        self.resource.delete.return_value = True
        self.mock_ansible_module.params = yaml.load(
            YAML_LOGICAL_ENCLOSURE_ABSENT)

        LogicalEnclosureModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalEnclosureModule.MSG_DELETED,
            ansible_facts=dict(logical_enclosure=None))
    def test_should_update_from_group_when_resource_exist(self):
        self.resource.data = DICT_DEFAULT_LOGICAL_ENCLOSURE
        self.resource.update_from_group.return_value = {'Updated from group'}
        self.mock_ansible_module.params = yaml.load(
            YAML_LOGICAL_ENCLOSURE_UPDATE_FROM_GROUP)

        LogicalEnclosureModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalEnclosureModule.MSG_UPDATED_FROM_GROUP,
            ansible_facts=dict(logical_enclosure={'Updated from group'}))
Beispiel #9
0
    def test_should_reconfigure_when_resource_exist(self):
        self.mock_ov_client.logical_enclosures.get_by_name.return_value = DICT_DEFAULT_LOGICAL_ENCLOSURE
        self.mock_ov_client.logical_enclosures.update_configuration.return_value = {'Configuration', 'Updated'}
        self.mock_ansible_module.params = yaml.load(YAML_LOGICAL_ENCLOSURE_CONFIGURE)

        LogicalEnclosureModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalEnclosureModule.MSG_RECONFIGURED,
            ansible_facts=dict(logical_enclosure={'Configuration', 'Updated'})
        )
Beispiel #10
0
    def test_should_generate_support_dump_when_resource_exist(self):
        self.mock_ov_client.logical_enclosures.get_by_name.return_value = DICT_DEFAULT_LOGICAL_ENCLOSURE
        self.mock_ov_client.logical_enclosures.generate_support_dump.return_value = '/rest/appliance/dumpedfile'
        self.mock_ansible_module.params = yaml.load(YAML_LOGICAL_ENCLOSURE_DUMP)

        LogicalEnclosureModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalEnclosureModule.MSG_DUMP_GENERATED,
            ansible_facts=dict(generated_dump_uri='/rest/appliance/dumpedfile')
        )
Beispiel #11
0
    def test_should_update_firmware_when_resource_exists(self):
        self.mock_ov_client.logical_enclosures.get_by_name.return_value = DICT_DEFAULT_LOGICAL_ENCLOSURE
        self.mock_ov_client.logical_enclosures.patch.return_value = {'PATCH', 'EXECUTED'}
        self.mock_ansible_module.params = yaml.load(YAML_LOGICAL_ENCLOSURE_FIRMWARE_UPDATE)

        LogicalEnclosureModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalEnclosureModule.MSG_FIRMWARE_UPDATED,
            ansible_facts=dict(logical_enclosure={'PATCH', 'EXECUTED'})
        )
Beispiel #12
0
    def test_should_create_when_resource_not_exist(self):
        self.mock_ov_client.logical_enclosures.get_by_name.return_value = None
        self.mock_ov_client.logical_enclosures.create.return_value = DICT_DEFAULT_LOGICAL_ENCLOSURE
        self.mock_ansible_module.params = yaml.load(YAML_LOGICAL_ENCLOSURE_PRESENT)

        LogicalEnclosureModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalEnclosureModule.MSG_CREATED,
            ansible_facts=dict(logical_enclosure=DICT_DEFAULT_LOGICAL_ENCLOSURE)
        )
    def test_should_update_when_data_has_modified_attributes(self):
        data_merged = DICT_DEFAULT_LOGICAL_ENCLOSURE.copy()
        data_merged['newName'] = 'New Name'

        self.resource.data = DICT_DEFAULT_LOGICAL_ENCLOSURE
        self.mock_ansible_module.params = yaml.load(
            YAML_LOGICAL_ENCLOSURE_RENAME)

        LogicalEnclosureModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalEnclosureModule.MSG_UPDATED,
            ansible_facts=dict(
                logical_enclosure=DICT_DEFAULT_LOGICAL_ENCLOSURE))