def test_wait_for_volume_attachment(self): vol_detached = {'volume': {'attachments': []}} vol_attached = { 'volume': { 'attachments': [{ 'attachment_id': uuids.attachment_id }] } } show_volume = mock.MagicMock( side_effect=[vol_attached, vol_attached, vol_detached]) client = mock.Mock(spec=volumes_client.VolumesClient, build_interval=1, build_timeout=5, show_volume=show_volume) self.patch('time.time') self.patch('time.sleep') waiters.wait_for_volume_attachment_remove(client, uuids.volume_id, uuids.attachment_id) # Assert that show volume is called until the attachment is removed. show_volume.assert_has_calls = [ mock.call(uuids.volume_id), mock.call(uuids.volume_id), mock.call(uuids.volume_id) ]
def test_wait_for_volume_attachment_not_present(self): show_volume = mock.MagicMock(return_value={ 'volume': {'attachments': []}}) client = mock.Mock(spec=volumes_client.VolumesClient, build_interval=1, build_timeout=1, show_volume=show_volume) self.patch('time.time', side_effect=[0., client.build_timeout + 1.]) self.patch('time.sleep') waiters.wait_for_volume_attachment_remove(client, uuids.volume_id, uuids.attachment_id) # Assert that show volume is only called once before we return show_volume.assert_called_once_with(uuids.volume_id)