def test_should_fail_when_sas_logical_interconnect_not_found(self):
        self.resource.get_by.return_value = []
        self.mock_ansible_module.params = yaml.load(YAML_CONFIGURATION)

        SasLogicalInterconnectModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=SasLogicalInterconnectModule.MSG_NOT_FOUND)
    def test_should_fail_when_compliance_cannot_resolve_names(self):
        self.resource.get_by.return_value = []
        self.mock_ansible_module.params = yaml.load(YAML_PARAMS_COMPLIANCE_NAMES)

        SasLogicalInterconnectModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=SasLogicalInterconnectModule.MSG_NOT_FOUND)
    def test_should_fail_when_no_uris_provided(self):
        self.resource.get_by.return_value = None
        self.mock_ansible_module.params = yaml.load(YAML_PARAMS_COMPLIANCE_INVALID)

        SasLogicalInterconnectModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=SasLogicalInterconnectModule.MSG_NO_OPTIONS_PROVIDED)
    def test_should_fail_when_firmware_sas_logical_interconnect_not_found(self):
        self.resource.get_by.return_value = []
        self.resource.update_firmware.return_value = response
        self.mock_ansible_module.params = yaml.load(YAML_FIRMWARE_WITH_SPP_URI)

        SasLogicalInterconnectModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=SasLogicalInterconnectModule.MSG_NOT_FOUND)
    def test_should_update_firmware_when_spp_uri_set(self):
        self.resource.data = SAS_LOGICAL_INTERCONNECT
        self.resource.update_firmware.return_value = response
        self.mock_ansible_module.params = yaml.load(YAML_FIRMWARE_WITH_SPP_URI)

        SasLogicalInterconnectModule().run()

        self.resource.update_firmware.assert_called_once_with(expected_data)
        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=SasLogicalInterconnectModule.MSG_FIRMWARE_UPDATED,
            ansible_facts=dict(li_firmware=response))
    def test_should_update_configuration(self):
        self.resource.data = SAS_LOGICAL_INTERCONNECT
        self.resource.update_configuration.return_value = SAS_LOGICAL_INTERCONNECT
        self.mock_ansible_module.params = yaml.load(YAML_CONFIGURATION)

        SasLogicalInterconnectModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=SasLogicalInterconnectModule.MSG_CONFIGURATION_UPDATED,
            ansible_facts=dict(
                sas_logical_interconnect=SAS_LOGICAL_INTERCONNECT))
    def test_should_return_to_a_consistent_state_by_names(self):
        self.resource.get_by.side_effect = [[{"uri": "/rest/resource1"}], [{"uri": "/rest/resource2"}]]
        self.resource.update_compliance_all.return_value = [SAS_LOGICAL_INTERCONNECT]
        self.mock_ansible_module.params = yaml.load(YAML_PARAMS_COMPLIANCE_NAMES)

        SasLogicalInterconnectModule().run()

        self.resource.update_compliance_all.assert_called_once_with(EXPECTED_UPDATE_COMPLIANCE_CALL)
        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=SasLogicalInterconnectModule.MSG_CONSISTENT,
            ansible_facts={}
        )
    def test_should_replace_drive_enclosure(self):
        self.resource.get_by.return_value = [SAS_LOGICAL_INTERCONNECT]
        self.resource.replace_drive_enclosure.return_value = {"name": "replaced"}
        self.mock_ansible_module.params = yaml.load(YAML_REPLACE_DRIVE_ENCLOSURE)

        SasLogicalInterconnectModule().run()

        self.resource.replace_drive_enclosure.assert_called_once_with(
            self.mock_ansible_module.params['data']['replace_drive_enclosure'],
            SAS_LOGICAL_INTERCONNECT['uri'])

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=SasLogicalInterconnectModule.MSG_DRIVE_ENCLOSURE_REPLACED,
            ansible_facts={"sas_logical_interconnect": {"name": "replaced"}})