def run_test_instance(self, iss, tag): _port = self.assigned_ports.register_port(iss, tag) args = [ self.test_script, "-i", unquote_plus(iss), "-t", unquote_plus(tag), "-p", str(_port), "-M", self.mako_dir, "-f", self.flowdir ] if self.path2port: args.extend(["-m", self.path2port]) ppmap = read_path2port_map(self.path2port) try: _path = ppmap[str(_port)] except KeyError: _errtxt = 'Port not in path2port map file {}'.format( self.path2port) logger.error(_errtxt) return ServiceError(_errtxt) url = '{}{}'.format(self.test_tool_base, _path) else: url = '{}:{}'.format(self.test_tool_base[:-1], _port) typ, _econf = self.rest.read_conf(iss, tag) if _econf['tool']['insecure']: args.append('-k') args.append(self.test_tool_conf) # If already running - kill try: pid = isrunning(unquote_plus(iss), unquote_plus(tag)) except KeyError: pass else: if pid: logger.info('kill {}'.format(pid)) subprocess.call(['kill', str(pid)]) # Now get it running args.append('&') logger.info("Test tool command: {}".format(" ".join(args))) # spawn independent process os.system(" ".join(args)) pid = 0 for i in range(0, 10): time.sleep(1) pid = isrunning(unquote_plus(iss), unquote_plus(tag)) if pid: break if pid: logger.info("process id: {}".format(pid)) self.running_processes[self.key(iss, tag)] = pid return url else: return None
def list_tag(self, iiss): uqp, qp = unquote_quote(iiss) logger.info('List all tags for "{}"'.format(uqp[0])) iss = uqp[0] qiss = qp[0] try: fils = os.listdir(os.path.join(self.entpath, qiss)) except FileNotFoundError: logger.warning('No such Issuer exists') return b"No such Issuer exists" active = dict() tags = [] for fil in fils: tag = unquote_plus(fil) active[tag] = isrunning(iss, tag) tags.append(tag) logger.info('tags: {}'.format(tags)) self.assigned_ports.load() _msg = self.prehtml['list_tag.html'].format(item_table=item_table( qiss, tags, active, self.assigned_ports, self.test_tool_base), iss=iss, version=self.version) return as_bytes(_msg)
def list_tag(self, iiss): uqp, qp = unquote_quote(iiss) logger.info('List all tags for "{}"'.format(uqp[0])) iss = uqp[0] qiss = qp[0] try: fils = os.listdir(os.path.join(self.entpath, qiss)) except FileNotFoundError: logger.warning('No such Issuer exists') return b"No such Issuer exists" active = dict() tags = [] for fil in fils: tag = unquote_plus(fil) active[tag] = isrunning(iss, tag) tags.append(tag) logger.info('tags: {}'.format(tags)) self.assigned_ports.load() _msg = self.prehtml['list_tag.html'].format( item_table=item_table(qiss, tags, active, self.assigned_ports, self.test_tool_base), iss=iss, version=self.version ) return as_bytes(_msg)
def list_tag(self, iss): resp = Response(mako_template="list_tag.mako", template_lookup=self.lookup, headers=[]) _iss = unquote_plus(iss) qiss = quote_plus(_iss) fils = os.listdir(os.path.join(self.entpath, qiss)) active = dict([(fil, isrunning(_iss, fil)) for fil in fils]) args = {'base': self.baseurl, 'items': fils, "qiss": qiss, "iss": _iss, 'active': active} return resp(self.environ, self.start_response, **args)
def kill(self, iss, tag, ev): uqp, qp = unquote_quote(iss, tag) _key = self.app.assigned_ports.make_key(*uqp) try: pid = isrunning(unquote_plus(iss), unquote_plus(tag)) except KeyError: pass else: if pid: # logger.info('kill {}'.format(pid)) # subprocess.call(['kill', str(pid)]) kill_process(pid) try: del self.app.running_processes[_key] except KeyError: pass
def list_tag(self, iss): resp = Response(mako_template="list_tag.mako", template_lookup=self.lookup, headers=[]) _iss = unquote_plus(iss) qiss = quote_plus(_iss) fils = os.listdir(os.path.join(self.entpath, qiss)) active = dict([(fil, isrunning(_iss, fil)) for fil in fils]) args = { 'base': self.baseurl, 'items': fils, "qiss": qiss, "iss": _iss, 'active': active } return resp(self.environ, self.start_response, **args)
def stop(self, iss, tag, ev): logger.info('stop test tool') uqp, qp = unquote_quote(iss, tag) _key = self.app.assigned_ports.make_key(*uqp) # If already running - kill try: pid = isrunning(unquote_plus(iss), unquote_plus(tag)) except KeyError: pass else: if pid: #logger.info('kill {}'.format(pid)) #subprocess.call(['kill', str(pid)]) kill_process(pid) try: del self.app.running_processes[_key] except KeyError: pass # redirect back to entity page loc = '{}entity/{}'.format(self.rest.base_url, qp[0]) raise cherrypy.HTTPRedirect(loc)
def run_test_instance(self, iss, tag): _port = self.assigned_ports.register_port(iss, tag) args = [self.test_script] args.extend(["-i", shlex.quote(unquote_plus(iss))]) args.extend(["-t", shlex.quote(unquote_plus(tag))]) args.extend(["-p", str(_port)]) args.extend(["-f", self.flowdir]) args.append("-s") if self.path2port: args.extend(["-m", self.path2port]) ppmap = read_path2port_map(self.path2port) try: _path = ppmap[str(_port)] except KeyError: _errtxt = 'Port not in path2port map file {}'.format( self.path2port) logger.error(_errtxt) return ServiceError(_errtxt) url = '{}{}'.format(self.test_tool_base, _path) else: url = '{}:{}'.format(self.test_tool_base, _port) typ, _econf = self.rest.read_conf(iss, tag) try: _insecure = _econf['tool']['insecure'] except KeyError: pass else: if _insecure: args.append('-k') args.append(self.test_tool_conf) # If already running - kill try: pid = isrunning(unquote_plus(iss), unquote_plus(tag)) except KeyError: pass else: if pid: logger.info('kill {}'.format(pid)) subprocess.call(['kill', str(pid)]) # Now get it running args.append('&') cmd = " ".join(args) logger.info("Test tool command: {}".format(cmd)) # spawn independent process, leaping blindly here os.system(cmd) pid = 0 for i in range(0, 10): time.sleep(1) pid = isrunning(unquote_plus(iss), unquote_plus(tag)) if pid: break if pid: logger.info("{} {} - process id: {}".format(iss, tag, pid)) self.running_processes['{}:{}'.format(iss, tag)] = pid return url else: logger.error('Failed to start the test tool') return None