def startService(self): self.script_runner_thing = script_runner.ScriptRunner( debug_level=self.debug_level, mbus=self.messageBus) if config_data.getByPath('script_runner', 'web_interface_active') == True: self.webIf = ScriptRunnerWebInterface( debug_level=self.debug_level, script_runner=self.script_runner_thing) root = resource.Resource() root.putChild('newjob', self.webIf) site = server.Site(root) reactor.listenTCP(self.port, channel.HTTPFactory(site))
def testInit(self): self.timeout = 10 uri = config.uriForService(config_data, 'indexer') m = re.match(r'^http://(.*?)(:(\d+))?(/.*)$', uri) host = m.group(1) port = m.group(3) path = m.group(4) xx = sr.ScriptRunner(testing=True) self.assertEqual(xx.mbus, False) self.assertEqual(type(xx.db), models.db.MirObjectDB) self.assertEqual(xx.indexer.host, host) self.assertEqual(xx.indexer.port, (int)(port)) self.assertEqual(xx.indexer.path, path.encode()) self.assertEqual(type(xx.active_jobs), dict) self.assertEqual(len(xx.active_jobs), 0) self.assertEqual(xx.testing, True) self.assertEqual(xx.debug_level, 0) self.assertEqual(type(xx.configs), dict) self.assertEqual(len(xx.configs), 0) xx = sr.ScriptRunner(debug_level=4, mbus=False, db=False, indexer=False, testing=True, configs={'abc': 1}) self.assertEqual(xx.debug_level, 4) self.assertEqual(xx.mbus, False) self.assertEqual(xx.db, False) self.assertEqual(xx.indexer, False) self.assertEqual(type(xx.active_jobs), dict) self.assertEqual(len(xx.active_jobs), 0) self.assertEqual(xx.testing, True) self.assertEqual(type(xx.configs), dict) self.assertEqual(len(xx.configs), 1) self.assertEqual(xx.configs['abc'], 1) xx = sr.ScriptRunner(debug_level=2, mbus=self.mbus, db=config_data.getByPath('dbconn'), testing=True) self.assertEqual(xx.debug_level, 2) self.assertIdentical(xx.mbus, self.mbus) self.assertIn( config_data.getByPath('script_runner', 'queues', 'basequeue'), xx.mbus.queues) self.assertIn( config_data.getByPath('script_runner', 'queues', 'newjobqueue'), xx.mbus.queues) self.assertIn( config_data.getByPath('script_runner', 'queues', 'configqueue'), xx.mbus.queues) self.assertIdentical(type(xx.db), models.MirObjectDB) self.assertEqual(xx.indexer.host, host) self.assertEqual(xx.indexer.port, (int)(port)) self.assertEqual(xx.indexer.path, path.encode()) self.assertEqual(type(xx.active_jobs), dict) self.assertEqual(len(xx.active_jobs), 0) self.assertEqual(type(xx.configs), dict) self.assertEqual(len(xx.configs), 0)
def _setUp(self, scriptfile="implicit_chaining_1.xml"): self.job_script = file(self.database + "data/job_scripts/%s" % scriptfile).read() self.job_schedule = "now" self.job_input_uri_list = "<input><uri>/workspaces/1/hosts/resources/1/</uri>\n<uri>/workspaces/1/hosts/resources/2/</uri></input>" self.job_xml = '%s%s\n<when>%s</when>\n%s\n</JobDefinition>' % ( '<?xml version="1.0"?>\n<JobDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" href="/workspaces/1/jobs/234/">', re.sub(r'^<\?[^\?]+\?>', '', self.job_script), re.sub(r'^<\?[^\?]+\?>', '', self.job_schedule), re.sub(r'^<\?[^\?]+\?>', '', self.job_input_uri_list), ) self.script_runner = sr.ScriptRunner(db=False, indexer=False, mbus=self.mbus, testing=True) self.script_runner.db = testdb.ACTestObjectDB(scriptfile=scriptfile) self.session = self.script_runner.db.session self.script_runner.indexer = testindexer.ACTestIndexer() self.t_job = models.Job("ScriptRunner TestJob #1", schedule=self.job_schedule, input=self.job_input_uri_list, script=self.job_script, workspace_id=1, id=14) self.t_res = models.ResultSet( name="%s Results Container @ %s" % (self.t_job.name, mir_datetime.strISO_now()), job=self.t_job, workspace_id=self.t_job.workspace_id) self.t_job.results.append(self.t_res) self.t_res.status = models.Status("Status for ResultSet %s" % self.t_res.id, activity='Starting', state='pending', status=None, id=self.t_res.id) job_rec = { 'job_obj': self.t_job, 'result': self.t_res, 'job_identity': self.t_job.href, 'job_script': self.t_job.script, 'job_url': str(identity.identity_from_string(self.t_job.href)), 'script_dom': minidom.parseString(self.job_script), 'workspace_id': 1, 'input': self.t_job.input, 'job_elem': minidom.parseString('<?xml version="1.0" encoding="utf-8"?>%s' % self.t_job.dump_job_manifest()), 'executionMetaData': minidom.parseString('<?xml version="1.0" encoding="utf-8"?>%s' % self.t_res.dump_execution_manifest()), } self.job_rec = job_rec