def create_task_entry(self, context): test = {} test['state'] = 'created' test['testtype'] = 'periodic' test['name'] = self.task test['uuid'] = utils.generate_uuid() new_test = objects.Cpulse(context, **test) with cpulse_lock.thread_lock(new_test, self.conductor_id): new_test.create() return new_test
def create_task_entry(self, context): test = {} test['state'] = 'scheduled' test['testtype'] = 'periodic' test['name'] = self.task test['uuid'] = utils.generate_uuid() new_test = objects.Cpulse(context, **test) with cpulse_lock.thread_lock(new_test, self.conductor_id): LOG.info(('Creating db entry for the test %s') % test['name']) new_test.create() return new_test
def create_test(self, values): # ensure defaults are present for new tests if not values.get('uuid'): values['uuid'] = utils.generate_uuid() cpulse = models.cpulse() cpulse.update(values) # TODO(VINOD) try: cpulse.save() except db_exc.DBDuplicateEntry: raise exception.TestAlreadyExists(uuid=values['uuid']) return cpulse
def test_refresh(self): uuid = self.cpulsetest['uuid'] new_uuid = cloudpulse_utils.generate_uuid() returns = [dict(self.cpulsetest, uuid=uuid), dict(self.cpulsetest, uuid=new_uuid)] expected = [mock.call(self.context, uuid), mock.call(self.context, uuid)] with mock.patch.object(self.dbapi, 'get_test_by_uuid', side_effect=returns, autospec=True) as mock_get_cpulse: cpulse = objects.Cpulse.get_by_uuid(self.context, uuid) self.assertEqual(uuid, cpulse.uuid) cpulse.refresh() self.assertEqual(new_uuid, cpulse.uuid) self.assertEqual(expected, mock_get_cpulse.call_args_list) self.assertEqual(self.context, cpulse._context)
def create_test(self, values): # ensure that the test name is valid discover.import_modules_from_package("cloudpulse.scenario.plugins") plugins = discover.itersubclasses(base.Scenario) if not any(values['name'] in dir(scenario) for scenario in plugins): raise exception.TestInvalid(test=values['name']) # ensure defaults are present for new tests if not values.get('uuid'): values['uuid'] = utils.generate_uuid() cpulse = models.cpulse() cpulse.update(values) # TODO(VINOD) try: cpulse.save() except db_exc.DBDuplicateEntry: raise exception.TestAlreadyExists(uuid=values['uuid']) return cpulse
def test_get_cpulse_test_by_uuid_not_found(self): uuid = cloudpulse_utils.generate_uuid() self.assertRaises(exception.TestNotFound, self.dbapi.get_test_by_uuid, self.context, uuid)
def test_destroy_cloudpulse_not_found(self): uuid = cloudpulse_utils.generate_uuid() self.assertRaises(exception.TestNotFound, self.dbapi.destroy_test, uuid)
def test_update_cloudpulse_not_found(self): uuid = cloudpulse_utils.generate_uuid() new_state = 'running' self.assertRaises(exception.TestNotFound, self.dbapi.update_test, uuid, {'state': new_state})
def test_update_cloudpulse_test_uuid(self): cpulse = utils.create_cpulse_test() new_uuid = cloudpulse_utils.generate_uuid() self.assertRaises(exception.InvalidParameterValue, self.dbapi.update_test, cpulse.uuid, {'uuid': new_uuid})