def test_get_from_manager_in_deleted_state(self): get_from_manager = utils.get_from_manager() manager = fakes.FakeManager() resource = fakes.FakeResource(manager=manager, status="DELETED") manager._cache(resource) self.assertRaises(exceptions.GetResourceNotFound, get_from_manager, resource)
def setUp(self): save_conf = client.BaseClient._configure_manager client.BaseClient._configure_manager = Mock() self.client = client.BaseClient() client.BaseClient._configure_manager = save_conf self.client._manager = fakes.FakeManager() self.id_svc = pyrax.identity
def test_get_from_manager_in_error_state(self): get_from_manager = utils.get_from_manager() manager = fakes.FakeManager() resource = fakes.FakeResource(manager=manager, status="ERROR") manager._cache(resource) self.assertRaises(exceptions.GetResourceFailure, get_from_manager, resource)
def _create_dummy_resource(self): mgr = fakes.FakeManager() info = { "name": "test_resource", "size": 42, "id": utils.random_unicode() } return resource.BaseResource(mgr, info)
def test_delete_network_fail(self): clt = self.client nm = "fake" net = fakes.FakeCloudNetwork(name=nm) net.manager = fakes.FakeManager() err = exc.Forbidden(403) net.manager.delete = Mock(side_effect=err) self.assertRaises(exc.NetworkInUse, net.delete)
def test_delete_network(self): clt = self.client nm = "fake" net = fakes.FakeCloudNetwork(name=nm) net.manager = fakes.FakeManager() net.manager.delete = Mock() net.delete() net.manager.delete.assert_called_once_with(net)
def test_instantiate_instance(self): inst = CloudDatabaseInstance(fakes.FakeManager(), { "id": 42, "volume": { "size": 1, "used": 0.2 } }) self.assertTrue(isinstance(inst, CloudDatabaseInstance))
def test_wait_until_fail(self): status_obj = fakes.FakeStatusChanger() self.assertRaises(exc.NoReloadError, utils.wait_until, status_obj, "status", "available") status_obj.manager = fakes.FakeManager() status_obj.manager.get = Mock(return_value=status_obj) status_obj.get = status_obj.manager.get ret = utils.wait_until(status_obj, "status", "fake", interval=0.1, attempts=2) self.assertFalse(ret.status == "fake")
def test_wait_until(self): status_obj = fakes.FakeStatusChanger() self.assertRaises(exc.NoReloadError, utils.wait_until, status_obj, "status", "available") status_obj.manager = fakes.FakeManager() status_obj.manager.get = Mock(return_value=status_obj) status_obj.get = status_obj.manager.get ret = utils.wait_until(status_obj, "status", "ready", interval=0.1) self.assertTrue(isinstance(ret, fakes.FakeStatusChanger)) self.assertEqual(ret.status, "ready")
def test_wait_until_callback(self): cback = Mock() status_obj = fakes.FakeStatusChanger() status_obj.manager = fakes.FakeManager() status_obj.manager.get = Mock(return_value=status_obj) status_obj.get = status_obj.manager.get thread = utils.wait_until(obj=status_obj, att="status", desired="ready", interval=0.1, callback=cback) thread.join() cback.assert_called_once_with(status_obj)
def test_manager_list_sizes(self): manager = fakes.FakeManager() def lst(): return [1] * 10 manager.list = lst manager_list_size = utils.manager_list_size([5]) self.assertFalse(manager_list_size(manager)) manager_list_size = utils.manager_list_size([10]) self.assertTrue(manager_list_size(manager))
def test_wait_until(self): status_obj = fakes.FakeStatusChanger() self.assertRaises(exc.NoReloadError, utils.wait_until, status_obj, "status", "available") status_obj.manager = fakes.FakeManager() status_obj.manager.get = Mock(return_value=status_obj) status_obj.get = status_obj.manager.get sav_out = sys.stdout out = StringIO.StringIO() sys.stdout = out ret = utils.wait_until(status_obj, "status", "ready", interval=0.01, verbose=True, verbose_atts="progress") self.assertTrue(isinstance(ret, fakes.FakeStatusChanger)) self.assertEqual(ret.status, "ready") self.assertTrue(len(out.getvalue()) > 0) sys.stdout = sav_out
def test_get_from_manager_with_uuid_field(self): get_from_manager = utils.get_from_manager() manager = fakes.FakeManager() resource = fakes.FakeResource(manager=manager) manager._cache(resource) self.assertEqual(resource, get_from_manager(resource, id_attr="uuid"))
def test_get_from_manager(self): get_from_manager = utils.get_from_manager() manager = fakes.FakeManager() resource = fakes.FakeResource(manager=manager) manager._cache(resource) self.assertEqual(resource, get_from_manager(resource))
class TestClient(object): _manager = fakes.FakeManager() @assure_volume def test_method(self, volume): return volume
class TestClient(object): _snaps_manager = fakes.FakeManager() @assure_snapshot def test_method(self, snapshot): return snapshot
class TestClient(object): _manager = fakes.FakeManager() @assure_instance def test_method(self, instance): return instance
def test_create_volume(self): vol = CloudBlockStorageVolume(fakes.FakeManager(), {}) self.assertTrue(isinstance(vol, CloudBlockStorageVolume))