def test_wait_for_volume_attachment_remove_from_server(self): volume_attached = { "volumeAttachments": [{ "volumeId": uuids.volume_id }] } volume_not_attached = {"volumeAttachments": []} mock_list_volume_attachments = mock.Mock( side_effect=[volume_attached, volume_not_attached]) mock_client = mock.Mock( spec=servers_client.ServersClient, build_interval=1, build_timeout=1, list_volume_attachments=mock_list_volume_attachments) self.patch('time.time', side_effect=[0., 0.5, mock_client.build_timeout + 1.]) self.patch('time.sleep') waiters.wait_for_volume_attachment_remove_from_server( mock_client, uuids.server_id, uuids.volume_id) # Assert that list_volume_attachments is called until the attachment is # removed. mock_list_volume_attachments.assert_has_calls( [mock.call(uuids.server_id), mock.call(uuids.server_id)])
def test_wait_for_volume_attachment_remove_from_server_not_found(self): mock_list_volume_attachments = mock.Mock(side_effect=lib_exc.NotFound) mock_client = mock.Mock( spec=servers_client.ServersClient, list_volume_attachments=mock_list_volume_attachments) # Assert that nothing is raised when lib_exc_NotFound is raised # by the client call to list_volume_attachments waiters.wait_for_volume_attachment_remove_from_server( mock_client, mock.sentinel.server_id, mock.sentinel.volume_id) # Assert that list_volume_attachments was actually called mock_list_volume_attachments.assert_called_once_with( mock.sentinel.server_id)
def test_attach_scsi_disk_with_config_drive(self): """Test the attach/detach volume with config drive/scsi disk Enable the config drive, followed by booting an instance from an image with meta properties hw_cdrom: scsi and use virtio-scsi mode with further asserting list volume attachments in instance after attach and detach of the volume. """ custom_img = self._create_image_with_custom_property( hw_scsi_model='virtio-scsi', hw_disk_bus='scsi', hw_cdrom_bus='scsi') validation_resources = self.get_test_validation_resources( self.os_primary) server = self.create_test_server( image_id=custom_img, config_drive=True, validatable=True, validation_resources=validation_resources, wait_until="SSHABLE") # NOTE(lyarwood): self.create_test_server delete the server # at class level cleanup so add server cleanup to ensure that # the instance is deleted first before created image. This # avoids failures when using the rbd backend is used for both # Glance and Nova ephemeral storage. Also wait until server is # deleted otherwise image deletion can start before server is # deleted. self.addCleanup(waiters.wait_for_server_termination, self.servers_client, server['id']) self.addCleanup(self.servers_client.delete_server, server['id']) volume = self.create_volume() attachment = self.attach_volume(server, volume) waiters.wait_for_volume_resource_status(self.volumes_client, attachment['volumeId'], 'in-use') volume_after_attach = self.servers_client.list_volume_attachments( server['id'])['volumeAttachments'] self.assertEqual(1, len(volume_after_attach), "Failed to attach volume") self.servers_client.detach_volume(server['id'], attachment['volumeId']) waiters.wait_for_volume_resource_status(self.volumes_client, attachment['volumeId'], 'available') waiters.wait_for_volume_attachment_remove_from_server( self.servers_client, server['id'], attachment['volumeId'])