def test_should_fail_when_profile_name_not_found(self): self.mock_ov_client.server_profiles.get_by_name.return_value = None self.mock_ov_client.storage_volume_attachments.remove_extra_presentations.return_value = MOCK_SERVER_PROFILE self.mock_ansible_module.params = yaml.load(YAML_EXTRA_REMOVED_BY_NAME) StorageVolumeAttachmentModule().run() self.mock_ansible_module.fail_json.assert_called_once_with( msg=PROFILE_NOT_FOUND)
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 StorageVolumeAttachmentModule() mock_ov_client_from_json_file.assert_called_once_with('config.json') mock_ov_client_from_env_vars.not_been_called()
def test_should_fail_when_get_profile_by_name_raises_exception(self, mock_ansible_module, mock_from_json): mock_ov_instance = mock.Mock() mock_ov_instance.server_profiles.get_by_name.side_effect = Exception(FAKE_MSG_ERROR) mock_from_json.return_value = mock_ov_instance mock_ansible_instance = create_ansible_mock_yaml(YAML_EXTRA_REMOVED_BY_NAME) mock_ansible_module.return_value = mock_ansible_instance self.assertRaises(Exception, StorageVolumeAttachmentModule().run()) mock_ansible_instance.fail_json.assert_called_once_with(msg=FAKE_MSG_ERROR)
def test_should_fail_when_profile_name_not_found(self, mock_ansible_module, mock_from_json): mock_ov_instance = mock.Mock() mock_ov_instance.server_profiles.get_by_name.return_value = None mock_ov_instance.storage_volume_attachments.remove_extra_presentations.return_value = MOCK_SERVER_PROFILE mock_from_json.return_value = mock_ov_instance mock_ansible_instance = create_ansible_mock_yaml(YAML_EXTRA_REMOVED_BY_NAME) mock_ansible_module.return_value = mock_ansible_instance StorageVolumeAttachmentModule().run() mock_ansible_instance.fail_json.assert_called_once_with(msg=PROFILE_NOT_FOUND)
def test_should_remove_extra_presentation_by_profile_uri(self): self.mock_ov_client.storage_volume_attachments.remove_extra_presentations.return_value = MOCK_SERVER_PROFILE self.mock_ansible_module.params = yaml.load(YAML_EXTRA_REMOVED_BY_URI) StorageVolumeAttachmentModule().run() self.mock_ov_client.storage_volume_attachments.remove_extra_presentations.assert_called_once_with( REPAIR_DATA) self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=PRESENTATIONS_REMOVED, ansible_facts=dict(server_profile=MOCK_SERVER_PROFILE))
def test_should_remove_extra_presentation_by_profile_uri(self, mock_ansible_module, mock_from_json): mock_ov_instance = mock.Mock() mock_ov_instance.storage_volume_attachments.remove_extra_presentations.return_value = MOCK_SERVER_PROFILE mock_from_json.return_value = mock_ov_instance mock_ansible_instance = create_ansible_mock_yaml(YAML_EXTRA_REMOVED_BY_URI) mock_ansible_module.return_value = mock_ansible_instance StorageVolumeAttachmentModule().run() mock_ov_instance.storage_volume_attachments.remove_extra_presentations.assert_called_once_with(REPAIR_DATA) mock_ansible_instance.exit_json.assert_called_once_with( changed=True, msg=PRESENTATIONS_REMOVED, ansible_facts=dict(server_profile=MOCK_SERVER_PROFILE) )