def test_should_get_one_and_path_uri(self): self.resource.get_paths.return_value = {'subresource': 'value'} obj = mock.Mock() obj.data = RETURN_GET_BY_PROFILE_AND_VOLUME self.resource.get_by_uri.return_value = obj self.resource.URI = "/rest/storage-volume-attachments" params_get_path = dict( config='config.json', serverProfileName="ProfileTest", storageVolumeUri= "/rest/storage-volumes/12345-AAA-BBBB-CCCC-121212AA", options=[{ 'paths': { 'pathUri': '/test/uri/AAA-NNN-878787H' } }]) self.mock_ansible_module.params = params_get_path StorageVolumeAttachmentFactsModule().run() self.resource.get_by_uri.assert_called_once_with(URI) self.resource.get_paths.assert_called_once_with( '/test/uri/AAA-NNN-878787H') self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(storage_volume_attachments=[ATTACHMENT], storage_volume_attachment_paths=[{ 'subresource': 'value' }]))
def test_should_get_all_and_unmanaged_volumes(self): attachments = [ATTACHMENT, ATTACHMENT] self.resource.get_all.return_value = attachments self.resource.get_extra_unmanaged_storage_volumes.return_value = { 'subresource': 'value' } params = dict(config='config.json', options=[{ 'extraUnmanagedStorageVolumes': { 'start': 1, 'count': 5, 'filter': 'test', 'sort': 'test' } }]) self.mock_ansible_module.params = params StorageVolumeAttachmentFactsModule().run() self.resource.get_extra_unmanaged_storage_volumes.assert_called_once_with( start=1, count=5, filter='test', sort='test') self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict( storage_volume_attachments=attachments, extra_unmanaged_storage_volumes={'subresource': 'value'}))
def test_should_get_one_with_options(self): self.resource.URI = "/rest/storage-volume-attachments" obj = mock.Mock() obj.data = RETURN_GET_BY_PROFILE_AND_VOLUME self.resource.get_by_uri.return_value = obj params_get_all_options = dict( config='config.json', serverProfileName="ProfileTest", storageVolumeUri= "/rest/storage-volumes/12345-AAA-BBBB-CCCC-121212AA", options=['extraUnmanagedStorageVolumes', 'paths']) self.mock_ansible_module.params = params_get_all_options self.resource.get_extra_unmanaged_storage_volumes.return_value = { 'subresource': 'value' } self.resource.get_paths.return_value = {'subresource': 'value'} StorageVolumeAttachmentFactsModule().run() self.resource.get_by_uri.assert_called_once_with(URI) self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict( storage_volume_attachments=([ATTACHMENT]), storage_volume_attachment_paths={'subresource': 'value'}, extra_unmanaged_storage_volumes={'subresource': 'value'}))
def test_should_get_one_and_paths(self): self.resource.get_paths.return_value = [{'subresource': 'value'}] self.resource.get.return_value = RETURN_GET_BY_PROFILE_AND_VOLUME self.resource.URI = "/rest/storage-volume-attachments" params_get_paths = dict( config='config.json', serverProfileName="ProfileTest", storageVolumeUri="/rest/storage-volumes/12345-AAA-BBBB-CCCC-121212AA", options=['paths'] ) self.mock_ansible_module.params = params_get_paths StorageVolumeAttachmentFactsModule().run() self.resource.get.assert_called_once_with(URI) self.resource.get_paths.assert_called_once_with( "/rest/storage-volume-attachments/ED247E27") self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict( storage_volume_attachments=[ATTACHMENT], storage_volume_attachment_paths=[{'subresource': 'value'}] ) )
def test_should_get_all(self): attachments = [ATTACHMENT, ATTACHMENT] self.resource.get_all.return_value = attachments self.mock_ansible_module.params = PARAMS_GET_ALL StorageVolumeAttachmentFactsModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(storage_volume_attachments=attachments))
def test_should_fail_when_get_by_server_name_and_not_inform_volume(self): self.resource.get.return_value = RETURN_GET_BY_PROFILE_AND_VOLUME params = PARAMS_GET_ONE_VOLUME_NAME.copy() params['storageVolumeName'] = None self.mock_ansible_module.params = params StorageVolumeAttachmentFactsModule().run() self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=StorageVolumeAttachmentFactsModule.ATTACHMENT_KEY_REQUIRED)
def test_should_get_by_server_name_and_volume_uri(self): self.resource.get.return_value = RETURN_GET_BY_PROFILE_AND_VOLUME self.resource.URI = "/rest/storage-volume-attachments" self.mock_ansible_module.params = PARAMS_GET_ONE StorageVolumeAttachmentFactsModule().run() self.resource.get.assert_called_once_with(URI) self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(storage_volume_attachments=([ATTACHMENT])))
def test_should_get_by_storage_volume_attachment_uri(self): self.resource.get.return_value = {"name": "Storage Volume Attachment Name"} self.resource.URI = "/rest/storage-volume-attachments" params_get_by_uri = dict( config='config.json', storageVolumeAttachmentUri="/rest/storage-volume-attachments/ED247E27-011B-44EB-9E1B-5891011" ) self.mock_ansible_module.params = params_get_by_uri StorageVolumeAttachmentFactsModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(storage_volume_attachments=([{"name": "Storage Volume Attachment Name"}])) )
def test_should_get_by_server_name_and_volume_name(self): self.resource.get.return_value = RETURN_GET_BY_PROFILE_AND_VOLUME self.resource.URI = "/rest/storage-volume-attachments" self.mock_ov_client.volumes.get_by.return_value = [ {"uri": "/rest/storage-volumes/12345-AAA-BBBB-CCCC-121212AA"} ] self.mock_ansible_module.params = PARAMS_GET_ONE_VOLUME_NAME StorageVolumeAttachmentFactsModule().run() self.mock_ov_client.volumes.get_by.assert_called_once_with('name', 'VolumeTest') self.resource.get.assert_called_once_with(URI) self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(storage_volume_attachments=([ATTACHMENT])) )
def test_should_get_all_and_unmanaged_volumes_without_params(self): attachments = [ATTACHMENT, ATTACHMENT] self.resource.get_all.return_value = attachments self.resource.get_extra_unmanaged_storage_volumes.return_value = { 'subresource': 'value' } params = dict(config='config.json', options=['extraUnmanagedStorageVolumes']) self.mock_ansible_module.params = params StorageVolumeAttachmentFactsModule().run() self.resource.get_extra_unmanaged_storage_volumes.assert_called_once_with( ) self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict( storage_volume_attachments=attachments, extra_unmanaged_storage_volumes={'subresource': 'value'}))