def test_detach_interface(self, mock_detach_interface): fake_server = db_utils.get_test_server(user_id=self.user_id, project_id=self.project_id) fake_server_obj = self._create_fake_server_obj(fake_server) self.engine_api.detach_interface(self.context, fake_server_obj, fake_server_obj['nics'][0]['port_id']) self.assertTrue(mock_detach_interface.called)
def test_lock_by_admin(self): fake_server = db_utils.get_test_server(user_id=self.user_id, project_id=self.project_id) fake_server_obj = self._create_fake_server_obj(fake_server) admin_context = context.get_admin_context() self.engine_api.lock(admin_context, fake_server_obj) self.assertEqual('admin', fake_server_obj.locked_by)
def test_lock_by_owner(self): fake_server = db_utils.get_test_server(user_id=self.user_id, project_id=self.project_id) fake_server_obj = self._create_fake_server_obj(fake_server) self.engine_api.lock(self.context, fake_server_obj) self.assertTrue(fake_server_obj.locked) self.assertEqual('owner', fake_server_obj.locked_by)
def test_unlock_by_owner(self): fake_server = db_utils.get_test_server(user_id=self.user_id, project_id=self.project_id, locked_by='owner') fake_server_obj = self._create_fake_server_obj(fake_server) self.engine_api.unlock(self.context, fake_server_obj) self.assertIsNone(fake_server_obj.locked_by)
def test_rebuild_server(self, mock_rebuild, mock_get_image): fake_server = db_utils.get_test_server(user_id=self.user_id, project_id=self.project_id) fake_server_obj = self._create_fake_server_obj(fake_server) mock_get_image.side_effect = None self.engine_api.rebuild(self.context, fake_server_obj) self.assertTrue(mock_get_image.called) self.assertTrue(mock_rebuild.called)
def test_rebuild_locked_server_with_non_admin(self, mock_rebuild): fake_server = db_utils.get_test_server(user_id=self.user_id, project_id=self.project_id, locked_by='owner') fake_server_obj = self._create_fake_server_obj(fake_server) self.assertRaises(exception.ServerIsLocked, self.engine_api.rebuild, self.context, fake_server_obj) mock_rebuild.assert_not_called()
def test_power_locked_server_with_admin(self, mock_powered): fake_server = db_utils.get_test_server(user_id=self.user_id, project_id=self.project_id, locked_by='owner') fake_server_obj = self._create_fake_server_obj(fake_server) admin_context = context.get_admin_context() self.engine_api.power(admin_context, fake_server_obj, 'reboot') self.assertTrue(mock_powered.called)
def test_rebuild_locked_server_with_admin(self, mock_rebuild): fake_server = db_utils.get_test_server(user_id=self.user_id, project_id=self.project_id, locked=True, locked_by='owner') fake_server_obj = self._create_fake_server_obj(fake_server) admin_context = context.get_admin_context() self.engine_api.rebuild(admin_context, fake_server_obj) self.assertTrue(mock_rebuild.called)
def setUp(self): super(RPCAPITestCase, self).setUp() self.fake_server = dbutils.get_test_server() self.fake_server_obj = objects.Server._from_db_object( objects.Server(self.context), self.fake_server) self.fake_type = dbutils.get_test_flavor() self.fake_type['extra_specs'] = {} self.fake_type_obj = objects.Flavor._from_db_object( self.context, objects.Flavor(self.context), self.fake_type)
def test_unlock_by_admin(self): fake_server = db_utils.get_test_server(user_id=self.user_id, project_id=self.project_id, locked=True, locked_by='owner') fake_server_obj = self._create_fake_server_obj(fake_server) admin_context = context.get_admin_context() self.engine_api.unlock(admin_context, fake_server_obj) self.assertFalse(fake_server_obj.locked) self.assertIsNone(fake_server_obj.locked_by)
def setUp(self): super(TestServerObject, self).setUp() self.ctxt = context.get_admin_context() self.fake_server = utils.get_test_server(context=self.ctxt) self.server = obj_utils.get_test_server(self.ctxt, **self.fake_server)