def test_check_for_setup_error_fails(self): d = driver.LunrDriver(configuration=self.configuration) # three unable to connects err = URLError( OSError( errno.ECONNREFUSED, os.strerror(errno.ECONNREFUSED) ) ) self.resp = [err for i in range(3)] with patch(driver, 'sleep', no_sleep): d.check_for_setup_error() # two errors, and one success! vtype = { 'name': 'new_type', 'status': 'ACTIVE', 'read_iops': 1000, 'write_iops': 1000, 'min_size': 0, 'max_size': 100, 'created_at': date_string(-10), 'last_modified': date_string(-2), } self.resp = [err, err, json.dumps([vtype])] with patch(driver, 'sleep', no_sleep): d.check_for_setup_error() self.assert_('new_type' in self.volume_types.store)
def test_clone_image(self): volume = {'name': 'vol1', 'size': 5, 'project_id': 100, 'id': '123-456', 'volume_type': {'name': 'vtype'}} image_location = "somewhere over the rainbow" image_meta = {'id': 'image_id_1'} def callback(req): if len(self.request_callback.called) > 1: self.assertEquals(req.get_method(), 'GET') return self.assertEquals(req.get_method(), 'PUT') url = urlparse(req.get_full_url()) self.assertEquals(url.path, '/v1.0/100/volumes/%s' % volume['id']) data = urldecode(url.query) self.assertEquals(data['image_id'], image_meta['id']) self.request_callback = callback building_status = json.dumps({ 'status': 'BUILDING', }) active_status = json.dumps({ 'status': 'ACTIVE', }) self.resp = [json.dumps({'size': 1}), building_status, active_status] d = driver.LunrDriver(configuration=self.configuration) with patch(client, 'sleep', no_sleep): d.clone_image('unused', volume, image_location, image_meta, 'image_service') self.assertEquals(len(self.request_callback.called), 3)
def test_create_cloned_volume(self): volume = {'name': 'vol1', 'size': 5, 'project_id': 100, 'id': '123-456', 'volume_type': {'name': 'vtype'}} source = {'name': 'vol2', 'size': 5, 'project_id': 100, 'id': '234-567', 'volume_type': {'name': 'vtype'}} def callback(req): if len(self.request_callback.called) > 1: self.assertEquals(req.get_method(), 'GET') return self.assertEquals(req.get_method(), 'PUT') url = urlparse(req.get_full_url()) self.assertEquals(url.path, '/v1.0/100/volumes/%s' % volume['id']) data = urldecode(url.query) self.assertEquals(data['volume_type_name'], 'vtype') self.assertEquals(data['source_volume'], '234-567') self.request_callback = callback building_status = json.dumps({ 'status': 'BUILDING', }) active_status = json.dumps({ 'status': 'ACTIVE', }) self.resp = [json.dumps({'size': 1}), building_status, active_status] d = driver.LunrDriver(configuration=self.configuration) with patch(client, 'sleep', no_sleep): d.create_cloned_volume(volume, source) self.assertEquals(len(self.request_callback.called), 3)
def test_create_volume_from_snapshot(self): volume = {'name': 'vol1', 'size': 5, 'project_id': 100, 'id': '123-456', 'volume_type': {'name': 'vtype'}} snapshot = {'name': 'backup1', 'id': '456-789'} def callback(req): if len(self.request_callback.called) > 1: self.assertEquals(req.get_method(), 'GET') return self.assertEquals(req.get_method(), 'PUT') url = urlparse(req.get_full_url()) self.assertEquals(url.path, '/v1.0/100/volumes/%s' % '123-456') data = urldecode(url.query) self.assertEquals(data['volume_type_name'], 'vtype') self.assertEquals(data['backup'], snapshot['id']) self.request_callback = callback building_status = json.dumps({ 'status': 'BUILDING', }) active_status = json.dumps({ 'status': 'ACTIVE', }) self.resp = [json.dumps({'size': 1, 'cinder_host': 'foo'}), building_status, active_status] d = driver.LunrDriver(configuration=self.configuration) with patch(client, 'sleep', no_sleep): update = d.create_volume_from_snapshot(volume, snapshot) self.assertEquals(len(self.request_callback.called), 3) self.assertEquals(update, {'size': 1, 'host': 'foo'})
def test_delete_snapshot_success(self): # args snapshot = {"id": "0000-0000", "volume_id": "0000-0001", "project_id": "dev"} # mock response chain delete_response = {"id": "0000-0000", "volume_id": "0000-0001", "status": "DELETING"} resp = [json.dumps(delete_response)] get_response = {"id": "0000-0000", "volume_id": "0000-0001", "status": "DELETING"} resp.append(json.dumps(get_response)) get_response = {"id": "0000-0000", "volume_id": "0000-0001", "status": "AUDITING"} resp.append(json.dumps(get_response)) self.resp = resp # setup request verification stack def delete_callback(req): self.assertEquals(req.get_method(), "DELETE") url = urlparse(req.get_full_url()) self.assertEquals(url.path, "/v1.0/dev/backups/0000-0000") data = urldecode(url.query) self.assertEquals(data["volume_id"], "0000-0001") callbacks = [delete_callback] def request_callback(req): callback = callbacks.pop(0) callback(req) d = driver.LunrDriver(configuration=self.configuration) with patch(client, "sleep", no_sleep): d.delete_snapshot(snapshot) self.assertEquals(len(self.request_callback.called), 3)
def test_create_snapshot_errors(self): # args snapshot = { 'id': '0000-0000', 'volume_id': '0000-0001', 'project_id': 'dev' } # mock response chain create_response = { 'id': '0000-0000', 'volume_id': '0000-0001', 'status': 'SAVING', } saving_response = { 'id': '0000-0000', 'volume_id': '0000-0001', 'status': 'SAVING', } error_response = { 'id': '0000-0000', 'volume_id': '0000-0001', 'status': 'ERROR', } self.resp = [json.dumps(resp) for resp in ( create_response, saving_response, error_response)] # setup request verification stack def create_callback(req): self.assertEquals(req.get_method(), 'PUT') url = urlparse(req.get_full_url()) self.assertEquals(url.path, '/v1.0/dev/backups/0000-0000') data = urldecode(url.query) self.assertEquals(data['volume_id'], '0000-0001') def saving_callback(req): self.assertEquals(req.get_method(), 'GET') url = urlparse(req.get_full_url()) self.assertEquals(url.path, '/v1.0/dev/backups/0000-0000') def ready_callback(req): self.assertEquals(req.get_method(), 'GET') url = urlparse(req.get_full_url()) self.assertEquals(url.path, '/v1.0/dev/backups/0000-0000') callbacks = [create_callback, saving_callback, ready_callback] def request_callback(req): callback = callbacks.pop(0) callback(req) class MockDB: def volume_get(self, ctx, volume_id): return {'id': volume_id} d = driver.LunrDriver(configuration=self.configuration) d.db = MockDB() with patch(client, 'sleep', no_sleep): self.assertRaises(client.StatusError, d.create_snapshot, snapshot) self.assertEquals(len(self.request_callback.called), 3)
def test_volume_type_already_exists(self): # setup mock response vtype1 = { 'name': 'vtype1', 'status': 'ACTIVE', 'min_size': 0, 'max_size': 10, 'created_at': date_string(-10), 'last_modified': date_string(-2), } vtype2 = { 'name': 'vtype2', 'status': 'ACTIVE', 'min_size': 0, 'max_size': 100, 'created_at': date_string(-10), 'last_modified': date_string(-2), } self.resp = json.dumps([vtype1, vtype2]) # mock out volume type api calls class MockVolumeTypeApi(object): def __init__(self): self.types = ['vtype1'] self.duplicate_create_types = [] def create(self, context, name, extra_specs={}): if name in self.types: self.duplicate_create_types.append(name) raise driver.exception.VolumeTypeExists( 'volume type %s already exists' % name) self.types.append(name) mock_volume_type_api = MockVolumeTypeApi() d = driver.LunrDriver(configuration=self.configuration) with patch(driver, 'volume_types', mock_volume_type_api): d.check_for_setup_error() self.assert_(self.request_callback.called) self.assert_(mock_volume_type_api.types, ['vtype1', 'vtype2']) self.assert_(mock_volume_type_api.duplicate_create_types, ['vtype1']) # call again self.resp = json.dumps([vtype1, vtype2]) d.check_for_setup_error() self.assert_(mock_volume_type_api.types, ['vtype1', 'vtype2']) expected = [ 'vtype1', # from first run 'vtype1', 'vtype2' ] # second time both raise self.assert_(mock_volume_type_api.duplicate_create_types, expected)
def test_check_for_setup_error_fails(self): d = driver.LunrDriver(configuration=self.configuration) # three unable to connects err = URLError(OSError(errno.ECONNREFUSED, os.strerror(errno.ECONNREFUSED))) self.resp = [err for i in range(3)] with patch(driver, "sleep", no_sleep): d.check_for_setup_error() # two errors, and one success! vtype = { "name": "new_type", "status": "ACTIVE", "read_iops": 1000, "write_iops": 1000, "min_size": 0, "max_size": 100, "created_at": date_string(-10), "last_modified": date_string(-2), } self.resp = [err, err, json.dumps([vtype])] with patch(driver, "sleep", no_sleep): d.check_for_setup_error() self.assert_("new_type" in self.volume_types.store)
def test_check_for_setup_error_fails(self): d = driver.LunrDriver(configuration=self.configuration) # three unable to connects err = URLError( OSError(errno.ECONNREFUSED, os.strerror(errno.ECONNREFUSED))) self.resp = [err for i in range(3)] with patch(driver, 'sleep', no_sleep): d.check_for_setup_error() # two errors, and one success! vtype = { 'name': 'new_type', 'status': 'ACTIVE', 'read_iops': 1000, 'write_iops': 1000, 'min_size': 0, 'max_size': 100, 'created_at': date_string(-10), 'last_modified': date_string(-2), } self.resp = [err, err, json.dumps([vtype])] with patch(driver, 'sleep', no_sleep): d.check_for_setup_error() self.assert_('new_type' in self.volume_types.store)
def test_volume_type_already_exists(self): # setup mock response vtype1 = { 'name': 'vtype1', 'status': 'ACTIVE', 'min_size': 0, 'max_size': 10, 'created_at': date_string(-10), 'last_modified': date_string(-2), } vtype2 = { 'name': 'vtype2', 'status': 'ACTIVE', 'min_size': 0, 'max_size': 100, 'created_at': date_string(-10), 'last_modified': date_string(-2), } self.resp = json.dumps([vtype1, vtype2]) # mock out volume type api calls class MockVolumeTypeApi(object): def __init__(self): self.types = ['vtype1'] self.duplicate_create_types = [] def create(self, context, name, extra_specs={}): if name in self.types: self.duplicate_create_types.append(name) raise driver.exception.VolumeTypeExists( 'volume type %s already exists' % name) self.types.append(name) mock_volume_type_api = MockVolumeTypeApi() d = driver.LunrDriver(configuration=self.configuration) with patch(driver, 'volume_types', mock_volume_type_api): d.check_for_setup_error() self.assert_(self.request_callback.called) self.assert_(mock_volume_type_api.types, ['vtype1', 'vtype2']) self.assert_(mock_volume_type_api.duplicate_create_types, ['vtype1']) # call again self.resp = json.dumps([vtype1, vtype2]) d.check_for_setup_error() self.assert_(mock_volume_type_api.types, ['vtype1', 'vtype2']) expected = ['vtype1', # from first run 'vtype1', 'vtype2'] # second time both raise self.assert_(mock_volume_type_api.duplicate_create_types, expected)
def test_delete_snapshot_success(self): # args snapshot = { 'id': '0000-0000', 'volume_id': '0000-0001', 'project_id': 'dev' } # mock response chain delete_response = { 'id': '0000-0000', 'volume_id': '0000-0001', 'status': 'DELETING', } resp = [json.dumps(delete_response)] get_response = { 'id': '0000-0000', 'volume_id': '0000-0001', 'status': 'DELETING', } resp.append(json.dumps(get_response)) get_response = { 'id': '0000-0000', 'volume_id': '0000-0001', 'status': 'AUDITING', } resp.append(json.dumps(get_response)) self.resp = resp # setup request verification stack def delete_callback(req): self.assertEquals(req.get_method(), 'DELETE') url = urlparse(req.get_full_url()) self.assertEquals(url.path, '/v1.0/dev/backups/0000-0000') data = urldecode(url.query) self.assertEquals(data['volume_id'], '0000-0001') callbacks = [delete_callback] def request_callback(req): callback = callbacks.pop(0) callback(req) d = driver.LunrDriver(configuration=self.configuration) with patch(client, 'sleep', no_sleep): d.delete_snapshot(snapshot) self.assertEquals(len(self.request_callback.called), 3)
def test_volume_type_already_exists(self): # setup mock response vtype1 = { "name": "vtype1", "status": "ACTIVE", "min_size": 0, "max_size": 10, "created_at": date_string(-10), "last_modified": date_string(-2), } vtype2 = { "name": "vtype2", "status": "ACTIVE", "min_size": 0, "max_size": 100, "created_at": date_string(-10), "last_modified": date_string(-2), } self.resp = json.dumps([vtype1, vtype2]) # mock out volume type api calls class MockVolumeTypeApi(object): def __init__(self): self.types = ["vtype1"] self.duplicate_create_types = [] def create(self, context, name, extra_specs={}): if name in self.types: self.duplicate_create_types.append(name) raise driver.exception.VolumeTypeExists("volume type %s already exists" % name) self.types.append(name) mock_volume_type_api = MockVolumeTypeApi() d = driver.LunrDriver(configuration=self.configuration) with patch(driver, "volume_types", mock_volume_type_api): d.check_for_setup_error() self.assert_(self.request_callback.called) self.assert_(mock_volume_type_api.types, ["vtype1", "vtype2"]) self.assert_(mock_volume_type_api.duplicate_create_types, ["vtype1"]) # call again self.resp = json.dumps([vtype1, vtype2]) d.check_for_setup_error() self.assert_(mock_volume_type_api.types, ["vtype1", "vtype2"]) expected = ["vtype1", "vtype1", "vtype2"] # from first run # second time both raise self.assert_(mock_volume_type_api.duplicate_create_types, expected)
def test_create_snapshot_errors(self): # args snapshot = {"id": "0000-0000", "volume_id": "0000-0001", "project_id": "dev"} # mock response chain create_response = {"id": "0000-0000", "volume_id": "0000-0001", "status": "SAVING"} saving_response = {"id": "0000-0000", "volume_id": "0000-0001", "status": "SAVING"} error_response = {"id": "0000-0000", "volume_id": "0000-0001", "status": "ERROR"} self.resp = [json.dumps(resp) for resp in (create_response, saving_response, error_response)] # setup request verification stack def create_callback(req): self.assertEquals(req.get_method(), "PUT") url = urlparse(req.get_full_url()) self.assertEquals(url.path, "/v1.0/dev/backups/0000-0000") data = urldecode(url.query) self.assertEquals(data["volume_id"], "0000-0001") def saving_callback(req): self.assertEquals(req.get_method(), "GET") url = urlparse(req.get_full_url()) self.assertEquals(url.path, "/v1.0/dev/backups/0000-0000") def ready_callback(req): self.assertEquals(req.get_method(), "GET") url = urlparse(req.get_full_url()) self.assertEquals(url.path, "/v1.0/dev/backups/0000-0000") callbacks = [create_callback, saving_callback, ready_callback] def request_callback(req): callback = callbacks.pop(0) callback(req) class MockDB: def volume_get(self, ctx, volume_id): return {"id": volume_id} d = driver.LunrDriver(configuration=self.configuration) d.db = MockDB() with patch(client, "sleep", no_sleep): self.assertRaises(client.StatusError, d.create_snapshot, snapshot) self.assertEquals(len(self.request_callback.called), 3)
def test_check_for_setup_error(self): # setup mock response vtype1 = { 'name': 'vtype1', 'status': 'ACTIVE', 'min_size': 0, 'max_size': 10, 'created_at': date_string(-10), 'last_modified': date_string(-2), } vtype2 = { 'name': 'vtype2', 'status': 'DELETED', 'min_size': 100, 'max_size': 0, 'created_at': date_string(-20), 'last_modified': date_string(-10), } self.resp = [json.dumps([vtype1, vtype2])] # setup verify request callback def request_callback(req): self.assertEquals(req.get_method(), 'GET') url = urlparse(req.get_full_url()) self.assertEquals(url.path, '/v1.0/admin/volume_types') self.request_callback = request_callback d = driver.LunrDriver(configuration=self.configuration) # mock cinder db call class MockVolumeTypeApi(object): def __init__(self): self.types = [] def create(self, context, name, extra_specs={}): self.types.append(name) mock_volume_type_api = MockVolumeTypeApi() with patch(driver, 'volume_types', mock_volume_type_api): d.check_for_setup_error() self.assert_(self.request_callback.called) self.assert_(mock_volume_type_api.types, ['vtype1'])
def test_create_cloned_volume(self): volume = { 'name': 'vol1', 'size': 5, 'project_id': 100, 'id': '123-456', 'volume_type': { 'name': 'vtype' } } source = { 'name': 'vol2', 'size': 5, 'project_id': 100, 'id': '234-567', 'volume_type': { 'name': 'vtype' } } def callback(req): if len(self.request_callback.called) > 1: self.assertEquals(req.get_method(), 'GET') return self.assertEquals(req.get_method(), 'PUT') url = urlparse(req.get_full_url()) self.assertEquals(url.path, '/v1.0/100/volumes/%s' % volume['id']) data = urldecode(url.query) self.assertEquals(data['volume_type_name'], 'vtype') self.assertEquals(data['source_volume'], '234-567') self.request_callback = callback building_status = json.dumps({ 'status': 'BUILDING', }) active_status = json.dumps({ 'status': 'ACTIVE', }) self.resp = [json.dumps({'size': 1}), building_status, active_status] d = driver.LunrDriver(configuration=self.configuration) with patch(client, 'sleep', no_sleep): d.create_cloned_volume(volume, source) self.assertEquals(len(self.request_callback.called), 3)
def test_create_volume_from_snapshot(self): volume = { 'name': 'vol1', 'size': 5, 'project_id': 100, 'id': '123-456', 'volume_type': { 'name': 'vtype' } } snapshot = {'name': 'backup1', 'id': '456-789'} def callback(req): if len(self.request_callback.called) > 1: self.assertEquals(req.get_method(), 'GET') return self.assertEquals(req.get_method(), 'PUT') url = urlparse(req.get_full_url()) self.assertEquals(url.path, '/v1.0/100/volumes/%s' % '123-456') data = urldecode(url.query) self.assertEquals(data['volume_type_name'], 'vtype') self.assertEquals(data['backup'], snapshot['id']) self.request_callback = callback building_status = json.dumps({ 'status': 'BUILDING', }) active_status = json.dumps({ 'status': 'ACTIVE', }) self.resp = [ json.dumps({ 'size': 1, 'cinder_host': 'foo' }), building_status, active_status ] d = driver.LunrDriver(configuration=self.configuration) with patch(client, 'sleep', no_sleep): update = d.create_volume_from_snapshot(volume, snapshot) self.assertEquals(len(self.request_callback.called), 3) self.assertEquals(update, {'size': 1, 'host': 'foo'})
def test_check_for_setup_error(self): # setup mock response vtype1 = { "name": "vtype1", "status": "ACTIVE", "min_size": 0, "max_size": 10, "created_at": date_string(-10), "last_modified": date_string(-2), } vtype2 = { "name": "vtype2", "status": "DELETED", "min_size": 100, "max_size": 0, "created_at": date_string(-20), "last_modified": date_string(-10), } self.resp = [json.dumps([vtype1, vtype2])] # setup verify request callback def request_callback(req): self.assertEquals(req.get_method(), "GET") url = urlparse(req.get_full_url()) self.assertEquals(url.path, "/v1.0/admin/volume_types") self.request_callback = request_callback d = driver.LunrDriver(configuration=self.configuration) # mock cinder db call class MockVolumeTypeApi(object): def __init__(self): self.types = [] def create(self, context, name, extra_specs={}): self.types.append(name) mock_volume_type_api = MockVolumeTypeApi() with patch(driver, "volume_types", mock_volume_type_api): d.check_for_setup_error() self.assert_(self.request_callback.called) self.assert_(mock_volume_type_api.types, ["vtype1"])
def test_clone_image(self): volume = {"name": "vol1", "size": 5, "project_id": 100, "id": "123-456", "volume_type": {"name": "vtype"}} image_location = "somewhere over the rainbow" image_meta = {"id": "image_id_1"} def callback(req): if len(self.request_callback.called) > 1: self.assertEquals(req.get_method(), "GET") return self.assertEquals(req.get_method(), "PUT") url = urlparse(req.get_full_url()) self.assertEquals(url.path, "/v1.0/100/volumes/%s" % volume["id"]) data = urldecode(url.query) self.assertEquals(data["image_id"], image_meta["id"]) self.request_callback = callback building_status = json.dumps({"status": "BUILDING"}) active_status = json.dumps({"status": "ACTIVE"}) self.resp = [json.dumps({"size": 1}), building_status, active_status] d = driver.LunrDriver(configuration=self.configuration) with patch(client, "sleep", no_sleep): d.clone_image("unused", volume, image_location, image_meta, "image_service") self.assertEquals(len(self.request_callback.called), 3)
def test_create_cloned_volume(self): volume = {"name": "vol1", "size": 5, "project_id": 100, "id": "123-456", "volume_type": {"name": "vtype"}} source = {"name": "vol2", "size": 5, "project_id": 100, "id": "234-567", "volume_type": {"name": "vtype"}} def callback(req): if len(self.request_callback.called) > 1: self.assertEquals(req.get_method(), "GET") return self.assertEquals(req.get_method(), "PUT") url = urlparse(req.get_full_url()) self.assertEquals(url.path, "/v1.0/100/volumes/%s" % volume["id"]) data = urldecode(url.query) self.assertEquals(data["volume_type_name"], "vtype") self.assertEquals(data["source_volume"], "234-567") self.request_callback = callback building_status = json.dumps({"status": "BUILDING"}) active_status = json.dumps({"status": "ACTIVE"}) self.resp = [json.dumps({"size": 1}), building_status, active_status] d = driver.LunrDriver(configuration=self.configuration) with patch(client, "sleep", no_sleep): d.create_cloned_volume(volume, source) self.assertEquals(len(self.request_callback.called), 3)
def test_create_volume_from_snapshot(self): volume = {"name": "vol1", "size": 5, "project_id": 100, "id": "123-456", "volume_type": {"name": "vtype"}} snapshot = {"name": "backup1", "id": "456-789"} def callback(req): if len(self.request_callback.called) > 1: self.assertEquals(req.get_method(), "GET") return self.assertEquals(req.get_method(), "PUT") url = urlparse(req.get_full_url()) self.assertEquals(url.path, "/v1.0/100/volumes/%s" % "123-456") data = urldecode(url.query) self.assertEquals(data["volume_type_name"], "vtype") self.assertEquals(data["backup"], snapshot["id"]) self.request_callback = callback building_status = json.dumps({"status": "BUILDING"}) active_status = json.dumps({"status": "ACTIVE"}) self.resp = [json.dumps({"size": 1, "cinder_host": "foo"}), building_status, active_status] d = driver.LunrDriver(configuration=self.configuration) with patch(client, "sleep", no_sleep): update = d.create_volume_from_snapshot(volume, snapshot) self.assertEquals(len(self.request_callback.called), 3) self.assertEquals(update, {"size": 1, "host": "foo"})
def test_clone_image(self): volume = { 'name': 'vol1', 'size': 5, 'project_id': 100, 'id': '123-456', 'volume_type': { 'name': 'vtype' } } image_location = "somewhere over the rainbow" image_meta = {'id': 'image_id_1'} def callback(req): if len(self.request_callback.called) > 1: self.assertEquals(req.get_method(), 'GET') return self.assertEquals(req.get_method(), 'PUT') url = urlparse(req.get_full_url()) self.assertEquals(url.path, '/v1.0/100/volumes/%s' % volume['id']) data = urldecode(url.query) self.assertEquals(data['image_id'], image_meta['id']) self.request_callback = callback building_status = json.dumps({ 'status': 'BUILDING', }) active_status = json.dumps({ 'status': 'ACTIVE', }) self.resp = [json.dumps({'size': 1}), building_status, active_status] d = driver.LunrDriver(configuration=self.configuration) with patch(client, 'sleep', no_sleep): d.clone_image('unused', volume, image_location, image_meta, 'image_service') self.assertEquals(len(self.request_callback.called), 3)
def test_create_snapshot_errors(self): # args snapshot = { 'id': '0000-0000', 'volume_id': '0000-0001', 'project_id': 'dev' } # mock response chain create_response = { 'id': '0000-0000', 'volume_id': '0000-0001', 'status': 'SAVING', } saving_response = { 'id': '0000-0000', 'volume_id': '0000-0001', 'status': 'SAVING', } error_response = { 'id': '0000-0000', 'volume_id': '0000-0001', 'status': 'ERROR', } self.resp = [ json.dumps(resp) for resp in (create_response, saving_response, error_response) ] # setup request verification stack def create_callback(req): self.assertEquals(req.get_method(), 'PUT') url = urlparse(req.get_full_url()) self.assertEquals(url.path, '/v1.0/dev/backups/0000-0000') data = urldecode(url.query) self.assertEquals(data['volume_id'], '0000-0001') def saving_callback(req): self.assertEquals(req.get_method(), 'GET') url = urlparse(req.get_full_url()) self.assertEquals(url.path, '/v1.0/dev/backups/0000-0000') def ready_callback(req): self.assertEquals(req.get_method(), 'GET') url = urlparse(req.get_full_url()) self.assertEquals(url.path, '/v1.0/dev/backups/0000-0000') callbacks = [create_callback, saving_callback, ready_callback] def request_callback(req): callback = callbacks.pop(0) callback(req) class MockDB: def volume_get(self, ctx, volume_id): return {'id': volume_id} d = driver.LunrDriver(configuration=self.configuration) d.db = MockDB() with patch(client, 'sleep', no_sleep): self.assertRaises(client.StatusError, d.create_snapshot, snapshot) self.assertEquals(len(self.request_callback.called), 3)