def imediately_terminate_facorty_with_running_pgm_test(self): tempdir = tempfile.mkdtemp() factory = SupDPidanticFactory(directory=tempdir, name="tester") pidantic = factory.get_pidantic(command="/bin/cat", process_name="cat", directory=tempdir) pidantic.start() factory.terminate()
def simple_get_cancel_test(self): tempdir = tempfile.mkdtemp() factory = SupDPidanticFactory(directory=tempdir, name="tester") pidantic = factory.get_pidantic(command="/bin/sleep 1", process_name="sleep", directory=tempdir) state = pidantic.get_state() self.assertEquals(state, PIDanticState.STATE_PENDING) pidantic.cancel_request()
def simple_get_state_start_test(self): name = "cat" + str(uuid.uuid4()).split("-")[0] tempdir = tempfile.mkdtemp() factory = SupDPidanticFactory(directory=tempdir, name="tester") pidantic = factory.get_pidantic(command="/bin/cat", process_name=name, directory=tempdir) pidantic.start() state = pidantic.get_state() self.assertEquals(state, PIDanticState.STATE_STARTING) factory.terminate()
def simple_api_walk_through_test(self): tempdir = tempfile.mkdtemp() factory = SupDPidanticFactory(directory=tempdir, name="tester") pidantic = factory.get_pidantic(command="/bin/sleep 1", process_name="sleep", directory=tempdir) pidantic.start() state = pidantic.get_state() while not pidantic.is_done(): factory.poll() factory.terminate()
def simple_get_state_exit_test(self): tempdir = tempfile.mkdtemp() factory = SupDPidanticFactory(directory=tempdir, name="tester") pidantic = factory.get_pidantic(command="/bin/sleep 1", process_name="sleep", directory=tempdir) pidantic.start() while not pidantic.is_done(): factory.poll() state = pidantic.get_state() self.assertEquals(state, PIDanticState.STATE_EXITED) factory.terminate()
def simple_return_code_success_test(self): tempdir = tempfile.mkdtemp() factory = SupDPidanticFactory(directory=tempdir, name="tester") pidantic = factory.get_pidantic(command="false", process_name="false", directory=tempdir) pidantic.start() while not pidantic.is_done(): factory.poll() rc = pidantic.get_result_code() self.assertNotEqual(rc, 0) factory.terminate()
def _setup_factory(self): if self.factory: return try: self.factory = SupDPidanticFactory(directory=self.pidantic_dir, name="epu-harness") except Exception: log.debug("Problem Connecting to SupervisorD", exc_info=True) raise HarnessException( "Could not connect to supervisord. Was epu-harness started?")
def terminate_done_test(self): tempdir = tempfile.mkdtemp() factory = SupDPidanticFactory(directory=tempdir, name="tester") pidantic = factory.get_pidantic(command="/bin/sleep 1", process_name="sleep", directory=tempdir) pidantic.start() while not pidantic.is_done(): factory.poll() try: pidantic.terminate() self.assertFalse(True, "should not get here") except PIDanticStateException: pass factory.terminate()
def simple_terminate_test(self): process_name = str(uuid.uuid4()).split("-")[0] tempdir = tempfile.mkdtemp() factory = SupDPidanticFactory(directory=tempdir, name="tester") pidantic = factory.get_pidantic(command="/bin/sleep 5000", process_name=process_name, directory=tempdir) pidantic.start() factory.poll() pidantic.terminate() while not pidantic.is_done(): factory.poll() rc = pidantic.get_result_code() self.assertNotEqual(rc, 0) factory.terminate()
def two_processes_one_sup_test(self): tempdir = tempfile.mkdtemp() factory = SupDPidanticFactory(directory=tempdir, name="tester") true_pid = factory.get_pidantic(command="true", process_name="true", directory=tempdir) true_pid.start() false_pid = factory.get_pidantic(command="false", process_name="false", directory=tempdir) false_pid.start() while not false_pid.is_done() or not true_pid.is_done(): factory.poll() rc = false_pid.get_result_code() self.assertNotEqual(rc, 0) rc = true_pid.get_result_code() self.assertEqual(rc, 0) factory.terminate()
def simple_double_terminate_kill_test(self): tempdir = tempfile.mkdtemp() factory = SupDPidanticFactory(directory=tempdir, name="tester") pidantic = factory.get_pidantic(command="/bin/sleep 5000", process_name="longnap", directory=tempdir) pidantic.start() factory.poll() pidantic.terminate() try: pidantic.terminate() self.fail("The terminate call should raise an error") except: pass while not pidantic.is_done(): factory.poll() rc = pidantic.get_result_code() self.assertNotEqual(rc, 0) factory.terminate()
def restart_test(self): from time import sleep tempdir = tempfile.mkdtemp() factory = SupDPidanticFactory(directory=tempdir, name="tester") pidantic = factory.get_pidantic(command="/bin/cat", process_name="cat", directory=tempdir) pidantic.start() while not pidantic.get_state() == PIDanticState.STATE_RUNNING: factory.poll() sleep(1) original_pid = pidantic._supd.get_all_state()[0]['pid'] pidantic.restart() while not pidantic.get_state() == PIDanticState.STATE_RUNNING: factory.poll() sleep(1) new_pid = pidantic._supd.get_all_state()[0]['pid'] assert int(new_pid) != 0 assert new_pid != original_pid
def __init__(self, eeagent_cfg, log=logging): self.log = log self.log.debug("Starting SupDExe") self._working_dir = eeagent_cfg.launch_type.supd_directory self._eename = eeagent_cfg.name supdexe = _set_param_or_default(eeagent_cfg.launch_type, 'supdexe', None) self._slots = int(eeagent_cfg.slots) self._factory = SupDPidanticFactory(directory=self._working_dir, name=self._eename, supdexe=supdexe) pidantic_instances = self._factory.reload_instances() self._known_pws = {} for name in pidantic_instances: pidantic = pidantic_instances[name] pw = PidWrapper(self, name) pw.set_pidantic(pidantic) self._known_pws[name] = pw self._state_change_cb = None self._state_change_cb_arg = None
def state_change_callback_test(self): global cb_called cb_called = False def my_callback(arg): print "callback" global cb_called cb_called = True tempdir = tempfile.mkdtemp() factory = SupDPidanticFactory(directory=tempdir, name="tester") pidantic = factory.get_pidantic(command="/bin/sleep 1", process_name="sleep", directory=tempdir) pidantic.set_state_change_callback(my_callback, None) pidantic.start() state = pidantic.get_state() while not pidantic.is_done(): factory.poll() factory.terminate() assert cb_called
def _configure_workers(self): # TODO: if num_workers == 1, simply run one in-line (runs in a greenlet anyhow) if self.is_single_worker: from brick_worker import run_worker worker = run_worker(self.prov_port, self.resp_port) self.workers.append(worker) else: if os.path.exists(self.pidantic_dir): bdp = os.path.join(self.pidantic_dir, 'brick_dispatch') if os.path.exists(bdp): import zipfile, zlib with zipfile.ZipFile( os.path.join(bdp, 'archived_worker_logs.zip'), 'a', zipfile.ZIP_DEFLATED) as f: names = f.namelist() for x in [ x for x in os.listdir(bdp) if x.startswith('worker_') and x not in names ]: fn = os.path.join(bdp, x) f.write(filename=fn, arcname=x) os.remove(fn) else: os.makedirs(self.pidantic_dir) self.factory = SupDPidanticFactory(name='brick_dispatch', directory=self.pidantic_dir) # Check for old workers - FOR NOW, TERMINATE THEM TODO: These should be reusable... old_workers = self.factory.reload_instances() for x in old_workers: old_workers[x].cleanup() worker_cmd = 'bin/python coverage_model/brick_worker.py {0} {1}'.format( self.prov_port, self.resp_port) for x in xrange(self.num_workers): w = self.factory.get_pidantic( command=worker_cmd, process_name='worker_{0}'.format(x), directory=os.path.realpath(self.working_dir)) w.start() self.workers.append(w) ready = False while not ready: self.factory.poll() for x in self.workers: s = x.get_state() if s is PIDanticState.STATE_STARTING: break elif s is PIDanticState.STATE_RUNNING: continue elif s is PIDanticState.STATE_EXITED: self.shutdown() raise SystemError( 'Error starting worker - cannot continue') else: raise SystemError( 'Problem starting worker - cannot continue') ready = True