def test_should_raise_exception_when_resource_not_found(self):
        self.drive_enclosures.get_by.return_value = []
        self.mock_ansible_module.params = yaml.load(YAML_DRIVE_ENCLOSURE_POWER_STATE)

        DriveEnclosureModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=DriveEnclosureModule.MSG_NOT_FOUND)
Example #2
0
    def test_should_raise_exception_when_name_not_defined(self):
        self.mock_ansible_module.params = yaml.load(YAML_WITHOUT_NAME)

        DriveEnclosureModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            msg=DriveEnclosureModule.MSG_NAME_REQUIRED
        )
Example #3
0
    def test_should_not_turn_uid_off_when_already_on(self):
        drive_enclosure = DICT_DEFAULT_DRIVE_ENCLOSURE.copy()
        drive_enclosure['uidState'] = 'On'

        self.drive_enclosures.get_by.return_value = [drive_enclosure]
        self.mock_ansible_module.params = yaml.load(YAML_DRIVE_ENCLOSURE_UID_STATE)

        DriveEnclosureModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(drive_enclosure=drive_enclosure)
        )
Example #4
0
    def test_should_refresh(self):
        mock_return_refresh = {'name': 'mock return'}

        self.drive_enclosures.get_by.return_value = [DICT_DEFAULT_DRIVE_ENCLOSURE]
        self.drive_enclosures.refresh_state.return_value = mock_return_refresh
        self.mock_ansible_module.params = yaml.load(YAML_DRIVE_ENCLOSURE_REFRESH_STATE)

        DriveEnclosureModule().run()

        self.drive_enclosures.refresh_state.assert_called_once_with(
            DRIVE_ENCLOSURE_URI, {'refreshState': 'RefreshPending'})

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            ansible_facts=dict(drive_enclosure=mock_return_refresh)
        )
Example #5
0
    def test_should_request_hard_reset(self):
        mock_return_patch = {'name': 'mock return'}

        self.drive_enclosures.get_by.return_value = [DICT_DEFAULT_DRIVE_ENCLOSURE]
        self.drive_enclosures.patch.return_value = mock_return_patch
        self.mock_ansible_module.params = yaml.load(YAML_DRIVE_ENCLOSURE_HARD_RESET_STATE)

        DriveEnclosureModule().run()

        self.drive_enclosures.patch.assert_called_once_with(
            DRIVE_ENCLOSURE_URI, operation='replace', path='/hardResetState', value='Reset')

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            ansible_facts=dict(drive_enclosure=mock_return_patch)
        )
Example #6
0
    def test_should_power_off(self):
        mock_return_patch = {'name': 'mock return'}

        self.resource.get_by.return_value = [DICT_DEFAULT_DRIVE_ENCLOSURE]
        self.resource.patch.return_value = mock_return_patch
        self.mock_ansible_module.params = yaml.load(YAML_DRIVE_ENCLOSURE_POWER_STATE)

        DriveEnclosureModule().run()

        self.resource.patch.assert_called_once_with(
            DRIVE_ENCLOSURE_URI, operation='replace', path='/powerState', value='Off')

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            ansible_facts=dict(drive_enclosure=mock_return_patch)
        )