def test_should_not_delete_snapshot_when_resource_not_exist(self): self.resource.get_by.return_value = [] self.mock_ansible_module.params = PARAMS_FOR_SNAPSHOT_DELETED VolumeModule().run() self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=VolumeModule.MSG_NOT_FOUND)
def test_should_raise_exception_when_new_name_already_used(self): self.resource.get_by.side_effect = [[EXISTENT_VOLUME], [EXISTENT_VOLUME_WITH_NEW_NAME]] self.mock_ansible_module.params = PARAMS_FOR_UPDATE_EXISTING VolumeModule().run() self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=VolumeModule.MSG_NEW_NAME_INVALID)
def test_should_do_nothing_when_volume_not_exist(self): self.resource.get_by_name.return_value = None self.mock_ansible_module.params = PARAMS_FOR_ABSENT VolumeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=VolumeModule.MSG_ALREADY_ABSENT)
def test_should_repair_volume(self): self.resource.get_by.return_value = [EXISTENT_VOLUME] self.mock_ansible_module.params = PARAMS_FOR_REPAIR VolumeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=VolumeModule.MSG_REPAIRED)
def test_should_create_snapshot(self): self.resource.get_by.return_value = [EXISTENT_VOLUME] self.mock_ansible_module.params = PARAMS_FOR_SNAPSHOT_CREATED VolumeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=VolumeModule.MSG_SNAPSHOT_CREATED)
def test_should_find_from_name_in_properties(self): self.resource.data = {"name": "Volume with Storage Pool"} self.resource.get_by_name.return_value = self.resource self.mock_ansible_module.params = PARAMS_FOR_PROPERTY_NAME VolumeModule().run() self.resource.get_by_name.assert_called_once_with( "Volume with Storage Pool")
def test_should_not_add_already_managed_volume(self): self.resource.get_by.return_value = [EXISTENT_VOLUME] self.mock_ansible_module.params = PARAMS_FOR_MANAGED.copy() VolumeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=VolumeModule.MSG_ALREADY_MANAGED, ansible_facts=dict(storage_volume=EXISTENT_VOLUME))
def test_should_fail_when_is_missing_data_attributes_on_snapshot_creation(self): self.resource.get_by.return_value = [EXISTENT_VOLUME] params = deepcopy(PARAMS_FOR_SNAPSHOT_CREATED) del params['data']['snapshotParameters'] self.mock_ansible_module.params = params VolumeModule().run() self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=VolumeModule.MSG_NO_OPTIONS_PROVIDED)
def test_should_update_volume_when_already_exist(self): self.resource.get_by.side_effect = [EXISTENT_VOLUME], [] self.resource.update.return_value = EXISTENT_VOLUME.copy() self.mock_ansible_module.params = PARAMS_FOR_UPDATE VolumeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=VolumeModule.MSG_UPDATED, ansible_facts=dict(storage_volume=EXISTENT_VOLUME.copy()))
def test_should_remove_volume(self): self.resource.get_by.return_value = [EXISTENT_VOLUME] self.mock_ansible_module.params = PARAMS_FOR_ABSENT_EXPORT_ONLY VolumeModule().run() self.resource.delete.assert_called_once_with(EXISTENT_VOLUME, export_only=True) self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=VolumeModule.MSG_DELETED)
def test_should_remove_volume_with_suppress_device_updates(self): self.resource.data = EXISTENT_VOLUME self.resource.get_by_name.return_value = self.resource self.mock_ansible_module.params = PARAMS_FOR_ABSENT_SUPPRESS VolumeModule().run() self.resource.delete.assert_called_once_with() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=VolumeModule.MSG_DELETED)
def test_should_update_volume_when_already_exist(self): self.resource.data = EXISTENT_VOLUME self.resource.get_by_name.side_effect = [self.resource, None] self.mock_ansible_module.params = PARAMS_FOR_UPDATE_OK VolumeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=VolumeModule.MSG_UPDATED, ansible_facts=dict(storage_volume=EXISTENT_VOLUME))
def test_should_add_for_management(self): self.resource.get_by_name.return_value = None self.resource.add_from_existing.return_value = EXISTENT_VOLUME self.mock_ansible_module.params = PARAMS_FOR_MANAGED VolumeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=VolumeModule.MSG_ADDED, ansible_facts=dict(storage_volume=EXISTENT_VOLUME))
def test_should_create_new_volume_when_not_exist(self): self.resource.get_by.return_value = [] self.resource.create.return_value = EXISTENT_VOLUME self.mock_ansible_module.params = PARAMS_FOR_CREATE VolumeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=VolumeModule.MSG_CREATED, ansible_facts=dict(storage_volume=EXISTENT_VOLUME))
def test_update_should_do_nothing_when_volume_already_exists_and_is_equal( self): self.resource.data = PARAMS_FOR_PRESENT["data"] self.resource.get_by_name.return_value = self.resource self.mock_ansible_module.params = PARAMS_FOR_PRESENT VolumeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=VolumeModule.MSG_NO_CHANGES_PROVIDED, ansible_facts=dict(storage_volume=self.resource.data))
def test_should_create_from_snapshot(self): self.resource.get_by_name.return_value = [] self.resource.create_from_snapshot.return_value = self.resource self.resource.data = EXISTENT_VOLUME self.mock_ansible_module.params = PARAMS_FOR_CREATE_FROM_SNAPSHOT VolumeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=VolumeModule.MSG_CREATED, ansible_facts=dict(storage_volume=EXISTENT_VOLUME))
def test_update_should_do_nothing_when_volume_already_exists_with_template( self): self.resource.data = PARAMS_FOR_PRESENT["data"] self.resource.get_by_name.return_value = self.resource self.mock_ansible_module.params = PARAMS_FOR_UPDATE_template VolumeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=VolumeModule.MSG_UPDATED, ansible_facts=dict(storage_volume=self.resource.data))
def test_should_fail_when_name_is_missing_on_snapshot_deletion(self): self.resource.get_by.return_value = [EXISTENT_VOLUME] self.resource.get_snapshot_by.return_value = [{'uri': SNAPSHOT_URI}] params = deepcopy(PARAMS_FOR_SNAPSHOT_DELETED) del params['data']['snapshotParameters']['name'] self.mock_ansible_module.params = params VolumeModule().run() self.mock_ansible_module.fail_json.assert_called_once_with( msg=VolumeModule.MSG_NO_OPTIONS_PROVIDED)