def signal_handler(signal, frame): kill_it = False now = time.time() if now - test.last_kill_sig < 2: kill_it = True test.last_kill_sig = now sys.stderr.write(red('\n\nReceived SIGINT, dumping results. (Press ctrl+c twice quickly to end test now)\n\n')) sys.stderr.flush() test.show_results() if kill_it: sys.stderr.write(red('\n\nReceived SIGINT twice within 2 seconds killing test...!\n\n')) sys.stderr.flush() sys.exit(0) signal.signal(signal.SIGINT, signal_handler)
def subnet(self, subnet): if subnet is None or isinstance(subnet, Subnet): self._subnet = subnet else: self.log.error( red('Unsupported type for subnet:{0}/{1}, must be None or type Subnet' .format(subnet, type(subnet))))
def print_debug(msg): msg = red(msg) if print_method: print_method(msg) else: stderr.write("{0}\n".format(msg)) stderr.flush()
def run_remote_commands( self, ips=None, command=None, ): command = command or self.command ips = ips or self.ips self.results = {} if not ips: self.logger.warning('No IPs provided to run_remote_commands!') return self.results command = command or "" iq = Queue() #if not ips: # raise ValueError('run_remote_commands: IP list was empty:"{0}"'.format(ips)) for ip in ips: ip = str(ip).strip().rstrip() iq.put(ip) tlock = Lock() threadcount = self.args.thread_count if threadcount > iq.qsize(): threadcount = iq.qsize() if not iq: return self.results = {} for i in range(threadcount): t = Thread(target=self.do_ssh, args=(iq, tlock, i, command)) t.daemon = True t.start() self.logger.debug('Threads started now waiting for join') if not self.args.batch_timeout: iq.join() else: start = time.time() while iq.unfinished_tasks and (time.time() - start < int( self.args.batch_timeout)): time.sleep(.5) if iq.unfinished_tasks: self.logger.warning( red('Possible unfinished tasks detected ' 'after elapsed:{0}. Queue:{1}'.format( time.time() - start, iq.queue))) time.sleep(.1 * len(ips)) for ip in ips: with tlock: if ip not in self.results.keys(): self.results[ip] = { 'status': -1, 'output': [ 'Timed out after {0} ' 'seconds'.format( int(self.args.batch_timeout)) ], 'elapsed': int(self.args.batch_timeout) } self.logger.debug('Done with join') time.sleep(self.maxwait + .1) return self.results
def signal_handler(signal, frame): kill_it = False now = time.time() if now - test.last_kill_sig < 2: kill_it = True test.last_kill_sig = now sys.stderr.write( red('\n\nReceived SIGINT, dumping results. (Press ctrl+c twice quickly to end test now)\n\n' )) sys.stderr.flush() test.show_results() if kill_it: sys.stderr.write( red('\n\nReceived SIGINT twice within 2 seconds killing test...!\n\n' )) sys.stderr.flush() sys.exit(0) signal.signal(signal.SIGINT, signal_handler)
def subnet(self): if self._subnet is None: if self.args.subnet: try: self._subnet = self.user.ec2.get_subnet(self.args.subnet) except Exception as E: self.log.error( red('{0}\nFailed to fetch CLI provided subnet:"{1}", ERR:"{2}"' .format(get_traceback(), self.args.subnet, E))) return self._subnet
def boto3(self): if not self._b3_connection: try: self._b3_connection = B3Session(ops=self, connection_kwargs=self._connection_kwargs, verbose=self._connection_kwargs.get('verbose')) except Exception as CE: self.log.error(red('{0}\nFailed to create boto3 "{1}" session. Err:"{2}"' .format(get_traceback(), self.__class__.__name__, CE))) raise return self._b3_connection
def boto2(self): if not self._b2_connection: try: self._b2_connection = self.boto2_connect( verbose=self._connection_kwargs.get('verbose'), conn_kwargs=self._connection_kwargs) except Exception as CE: self.log.error(red('{0}\nFailed to create boto2 "{1}" connection. Err:"{2}"' .format(get_traceback(), self.__class__.__name__, CE))) raise return self._b2_connection
def _scrub_ip_list(self, value): value = value or [] ip_list = [] if isinstance(value, basestring): value = value.split(',') if not isinstance(value, list): self.log.error(red('ip_list must be a list of IPs or comma separated string of IPs')) raise ValueError('ip_list must be a list of IPs or comma separated string of IPs') for ip in value: ip_list.append(str(ip).strip()) return ip_list
def clean_method(self): errors = [] try: if self.instances: self.user.ec2.terminate_instances(self.instances) except Exception as E: self.log.error(red(get_traceback())) errors.append(E) try: if self.volumes: delete = [] for volume in self.volumes: try: volume.update() if volume.status != 'deleted': delete.append(volume) except EC2ResponseError as ER: if ER.status == 400 and ER.error_code == 'InvalidVolume.NotFound': pass if delete: self.user.ec2.delete_volumes(delete) except Exception as E: self.log.error(red(get_traceback())) errors.append(E) try: if self._keypair: self.user.ec2.delete_keypair(self.keypair) except Exception as E: self.log.error(red(get_traceback())) errors.append(E) try: if self._group: self.user.ec2.delete_group(self.group) except Exception as E: self.log.error(red(get_traceback())) errors.append(E) if errors: buf = "The following errors occurred during test cleanup:" for error in errors: buf += "\n{0}".format(error) raise RuntimeError(buf)
def image_utils(self): iu = getattr(self, '_image_utils', None) if iu is None: if not self.user: self.log.warning(red('Cant create image utils w/o user, create user first')) return None # Create an ImageUtils helper from the arguments provided in this testcase... setattr(self.args, 'worker_machine', self.tc.sysadmin.clc_machine) setattr(self.args, 'user_context', self.user) iu = self.do_with_args(Euca2oolsImageUtils) setattr(self, '_image_utils', iu) return iu
def boto2(self): if not self._b2_connection: try: self._b2_connection = self.boto2_connect( verbose=self._connection_kwargs.get('verbose'), conn_kwargs=self._connection_kwargs) except Exception as CE: self.log.error( red('{0}\nFailed to create boto2 "{1}" connection. Err:"{2}"' .format(get_traceback(), self.__class__.__name__, CE))) raise return self._b2_connection
def test1_BasicInstanceChecks(self, zone=None): """ This case was developed to run through a series of basic instance tests. The tests are as follows: - execute run_instances command - make sure that public DNS name and private IP aren't the same (This is for Managed/Managed-NOVLAN networking modes) - test to see if instance is ping-able - test to make sure that instance is accessible via ssh (ssh into instance and run basic ls command) If any of these tests fail, the test case will error out, logging the results. """ instances = self.run_image(zone=zone, **self.run_instance_params) self.instances += instances for instance in instances: if instance.virtualization_type == "paravirtual": paravirtual_ephemeral = "/dev/" + instance.rootfs_device + "2" try: instance.sys("ls -1 " + paravirtual_ephemeral, code=0) self.log.debug('Found ephemeral storage at: "{0}"'.format( paravirtual_ephemeral)) except CommandExitCodeException as CE: self.log.error( red("Did not find ephemeral storage at " + paravirtual_ephemeral)) elif instance.virtualization_type == "hvm" and instance.root_device_type != 'ebs': hvm_ephemeral = "/dev/" + instance.block_device_prefix + "b" try: instance.sys("ls -1 " + hvm_ephemeral, code=0) except CommandExitCodeException as CE: self.log.error( red("Did not find ephemeral storage at " + hvm_ephemeral)) raise CE self.log.debug("Pinging instance public IP from inside instance") instance.sys('ping -c 1 ' + instance.ip_address, code=0) self.log.debug("Pinging instance private IP from inside instance") instance.sys('ping -c 1 ' + instance.private_ip_address, code=0) self.set_instances(instances) return instances
def boto3(self): if not self._b3_connection: try: self._b3_connection = B3Session( ops=self, connection_kwargs=self._connection_kwargs, verbose=self._connection_kwargs.get('verbose')) except Exception as CE: self.log.error( red('{0}\nFailed to create boto3 "{1}" session. Err:"{2}"'. format(get_traceback(), self.__class__.__name__, CE))) raise return self._b3_connection
def image_utils(self): iu = getattr(self, '_image_utils', None) if iu is None: if not self.user: self.log.warning( red('Cant create image utils w/o user, create user first')) return None # Create an ImageUtils helper from the arguments provided in this testcase... setattr(self.args, 'worker_machine', self.tc.sysadmin.clc_machine) setattr(self.args, 'user_context', self.user) iu = self.do_with_args(Euca2oolsImageUtils) setattr(self, '_image_utils', iu) return iu
def _start_session(self, connection_kwargs=None): if self._ops._user_context: self._session = self._ops._user_context.session else: try: region = self._region self._session = Session(aws_access_key_id=self._access_key, aws_secret_access_key=self._secret_key, region_name=region) except Exception as SE: self._log.error(red('{0}\nError creating boto3 {1} session. Error:{2}' .format(get_traceback(), self.__class__.__name__, SE))) raise return self._session
def test1_BasicInstanceChecks(self, zone=None): """ This case was developed to run through a series of basic instance tests. The tests are as follows: - execute run_instances command - make sure that public DNS name and private IP aren't the same (This is for Managed/Managed-NOVLAN networking modes) - test to see if instance is ping-able - test to make sure that instance is accessible via ssh (ssh into instance and run basic ls command) If any of these tests fail, the test case will error out, logging the results. """ instances = self.run_image(zone=zone, **self.run_instance_params) self.instances += instances for instance in instances: if instance.virtualization_type == "paravirtual": paravirtual_ephemeral = "/dev/" + instance.rootfs_device + "2" try: instance.sys("ls -1 " + paravirtual_ephemeral, code=0) self.log.debug('Found ephemeral storage at: "{0}"' .format(paravirtual_ephemeral)) except CommandExitCodeException as CE: self.log.error(red("Did not find ephemeral storage at " + paravirtual_ephemeral)) elif instance.virtualization_type == "hvm" and instance.root_device_type != 'ebs': hvm_ephemeral = "/dev/" + instance.block_device_prefix + "b" try: instance.sys("ls -1 " + hvm_ephemeral, code=0) except CommandExitCodeException as CE: self.log.error(red("Did not find ephemeral storage at " + hvm_ephemeral)) raise CE self.log.debug("Pinging instance public IP from inside instance") instance.sys('ping -c 1 ' + instance.ip_address, code=0) self.log.debug("Pinging instance private IP from inside instance") instance.sys('ping -c 1 ' + instance.private_ip_address, code=0) self.set_instances(instances) return instances
def cloudformation(self): ops_class = CFNops name = self.CLASS_MAP[ops_class.__name__] if not self._connections.get(name, None): if getattr(self, ops_class.EUCARC_URL_NAME, None): try: self._connections[name] = ops_class( **self._connection_kwargs) except Exception as CE: self.log.error( red('{0}\nFailed to created "{1}" interface.\n' 'Connection kwargs:\n{2}\nError:{3}'.format( get_traceback(), ops_class.__name__, self._connection_kwargs, CE))) return self._connections.get(name, None)
def cloudformation(self): ops_class = CFNops name = self.CLASS_MAP[ops_class.__name__] if not self._connections.get(name, None): if getattr(self, ops_class.EUCARC_URL_NAME, None): try: self._connections[name] = ops_class(**self._connection_kwargs) except Exception as CE: self.log.error(red('{0}\nFailed to created "{1}" interface.\n' 'Connection kwargs:\n{2}\nError:{3}' .format(get_traceback(), ops_class.__name__, self._connection_kwargs, CE))) return self._connections.get(name, None)
def _start_session(self, connection_kwargs=None): if self._ops._user_context: self._session = self._ops._user_context.session else: try: region = self._region self._session = Session(aws_access_key_id=self._access_key, aws_secret_access_key=self._secret_key, region_name=region) except Exception as SE: self._log.error( red('{0}\nError creating boto3 {1} session. Error:{2}'. format(get_traceback(), self.__class__.__name__, SE))) raise return self._session
def _scrub_ip_list(self, value): value = value or [] ip_list = [] if isinstance(value, basestring): value = value.split(',') if not isinstance(value, list): self.log.error( red('ip_list must be a list of IPs or comma separated string of IPs' )) raise ValueError( 'ip_list must be a list of IPs or comma separated string of IPs' ) for ip in value: ip_list.append(str(ip).strip()) return ip_list
def run_remote_commands(self, ips=None, command=None, ): command = command or self.command ips = ips or self.ips self.results = {} if not ips: self.logger.warning('No IPs provided to run_remote_commands!') return self.results command = command or "" iq = Queue() #if not ips: # raise ValueError('run_remote_commands: IP list was empty:"{0}"'.format(ips)) for ip in ips: ip = str(ip).strip().rstrip() iq.put(ip) tlock = Lock() threadcount = self.args.thread_count if threadcount > iq.qsize(): threadcount = iq.qsize() if not iq: return self.results = {} for i in range(threadcount): t = Thread(target=self.do_ssh, args=(iq, tlock, i, command)) t.daemon = True t.start() self.logger.debug('Threads started now waiting for join') if not self.args.batch_timeout: iq.join() else: start = time.time() while iq.unfinished_tasks and (time.time()-start < int(self.args.batch_timeout)): time.sleep(.5) if iq.unfinished_tasks: self.logger.warning(red('Possible unfinished tasks detected ' 'after elapsed:{0}. Queue:{1}' .format(time.time() - start, iq.queue))) time.sleep(.1 * len(ips)) for ip in ips: with tlock: if ip not in self.results.keys(): self.results[ip] = { 'status': -1, 'output': ['Timed out after {0} ' 'seconds'.format(int(self.args.batch_timeout))], 'elapsed': int(self.args.batch_timeout)} self.logger.debug('Done with join') time.sleep(self.maxwait + .1) return self.results
def printOpenFiles(): print red("\n\n### %d OPEN FILES: [%s]\n\n" % (len(openfiles), ", ".join(f.x for f in openfiles)))
class SOSReports(CliTestRunner): _DEFAULT_CLI_ARGS = copy.copy(CliTestRunner._DEFAULT_CLI_ARGS) _DEFAULT_CLI_ARGS['ticket_number'] = { 'args': ['--ticket-number'], 'kwargs': { 'dest': 'ticket_number', 'help': 'Issue, bug, ticket number or identifier to use (defaults to time)', 'default': None } } _DEFAULT_CLI_ARGS['timeout'] = { 'args': ['--timeout'], 'kwargs': { 'dest': 'timeout', 'help': 'Timeout for the sos gathering operation', 'default': 1200 } } _DEFAULT_CLI_ARGS['remote_dir'] = { 'args': ['--remote-dir'], 'kwargs': { 'dest': 'remote_dir', 'help': 'Directory on remote host(s)', 'default': '/root/' } } _DEFAULT_CLI_ARGS['local_dir'] = { 'args': ['--local-dir'], 'kwargs': { 'dest': 'local_dir', 'help': 'Local directory to use for gathering sos reports', 'default': '' } } _DEFAULT_CLI_ARGS['ip_list'] = { 'args': ['--ip-list'], 'kwargs': { 'dest': 'ip_list', 'help': 'Comma separated list of ips or hostnames to gather sos reports from', 'default': None } } _DEFAULT_CLI_ARGS['package_url'] = { 'args': ['--package-url'], 'kwargs': { 'dest': 'package_url', 'help': 'Url to use for eucalyptus sos plugin package', 'default': "http://downloads.eucalyptus.com/software/tools/centos/6/x86_64/" "eucalyptus-sos-plugins-0.1.5-0.el6.noarch.rpm" } } def post_init(self, *args, **kwargs): self.start_time = int(time.time()) self.ticket_number = self.args.ticket_number or self.start_time self.remote_dir = os.path.join( self.args.remote_dir, 'euca-sosreport-{0}'.format(self.ticket_number)) self._ip_list = [] def _scrub_ip_list(self, value): value = value or [] ip_list = [] if isinstance(value, basestring): value = value.split(',') if not isinstance(value, list): self.log.error( red('ip_list must be a list of IPs or comma separated string of IPs' )) raise ValueError( 'ip_list must be a list of IPs or comma separated string of IPs' ) for ip in value: ip_list.append(str(ip).strip()) return ip_list @property def ip_list(self): if not self._ip_list: ip_list = self.args.ip_list or self.tc.sysadmin.eucahosts.keys() self._ip_list = self._scrub_ip_list(ip_list) return self._ip_list @ip_list.setter def ip_list(self, value): self._ip_list = self._scrub_ip_list(value) @property def tc(self): tc = getattr(self, '__tc', None) if not tc: self.log.debug('Attempting to create TestController...') tc = TestController(hostname=self.args.clc, environment_file=self.args.environment_file, password=self.args.password, timeout=self.args.timeout, log_level=self.args.log_level) setattr(self, '__tc', tc) return tc @property def rc(self): rc = getattr(self, '__rc', None) if not rc: ip_list = self.ip_list self.log.debug( 'Attempting to create remote command driver with ip list: {0}'. format(ip_list)) rc = RemoteCommands(ips=self.ip_list, username='******', password=self.args.password, timeout=600) setattr(self, '__rc', rc) return rc def clean_method(self): pass def test1_install_sos_and_plugins(self): """ Attempts to install the SOS and Eucalyptus-sos-plugins on each machine in the cloud. """ rc = self.rc rc.results = {} self.log.debug('Running install on ips:{0}'.format(rc.ips)) rc.run_remote_commands( command='yum install sos eucalyptus-sos-plugins -y --nogpg') rc.show_results() failed = 0 for host, result in rc.results.iteritems(): if result.get('status') != 0: failed += 1 if failed: raise RuntimeError( '{0}/{1} hosts had errors during install sos and plugin packages' .format(failed / len(rc.ips))) def test2_run(self): """ Attempts to run SOS on each host in the cloud to create and gather SOS reports. """ command = "mkdir -p " + self.remote_dir command += "; sosreport --batch --tmp-dir {0} --ticket-number {1} "\ .format(self.remote_dir, self.ticket_number) rc = self.rc rc.results = {} rc.run_remote_commands(command=command) rc.show_results() failed = 0 for host, result in rc.results.iteritems(): if result.get('status') != 0: failed += 1 if failed: raise RuntimeError( '{0}/{1} hosts had errors while attempting to run SOS'.format( failed, len(rc.ips))) def test3_download(self): """ Attempts to download the SOS reports from each host in the cloud and store in a local directory """ error_msg = "" count = 0 err_count = 0 host_count = len(self.ip_list) for ip in self.ip_list: if self.tc: if ip in self.tc.sysadmin.eucahosts.keys(): host = self.tc.sysadmin.eucahosts.get(ip) ssh = host.ssh else: ssh = SshConnection(host=ip, password=self.args.password) try: remote_tarball_path = ssh.sys( "ls -1 {0}/*.xz | grep {1}".format(self.remote_dir, self.ticket_number), code=0)[0] tarball_name = os.path.basename(remote_tarball_path) local_name = "sosreport-{0}.{1}{2}".format( ip, self.ticket_number, tarball_name.split(str(self.ticket_number))[1]) local_tarball_path = os.path.join(self.args.local_dir, local_name) self.log.debug("Downloading file to: " + local_tarball_path) ssh.sftp_get(localfilepath=local_tarball_path, remotefilepath=remote_tarball_path) except Exception, e: err_count += 1 msg = '\nError Downloading from: {0}. Error:"{0}"\n'.format( ip, e) self.log.error("{0}\n{1}".format(get_traceback(), msg)) error_msg += msg else: count += 1 self.log.info( markup('Downloaded SOS report {0}/{1} to:{2}'.format( count, host_count, local_tarball_path), markups=[ ForegroundColor.WHITE, BackGroundColor.BG_GREEN ])) if error_msg: self.log.error(red(error_msg)) raise Exception('Error during download on {0}/{1} hosts'.format( err_count, host_count))
def _completer_display(self, substitution, matches, longest_match_length): try: completer = None if self.env: completer = self.env.completer_context completer = completer or self linebuffer = readline.get_line_buffer() height, width = self._get_terminal_size() columns = int((width - 12) / longest_match_length) or 1 column_width = longest_match_length def create_table(): header = [] for x in xrange(0, columns): header.append(x) pt = PrettyTable(header) pt.header = False pt.border = False pt.align = 'l' pt.max_width = column_width return pt menu_pt = None cmd_pt = None base_pt = None menus = [""] * columns cmds = [""] * columns basecmds = [""] * columns cmd_count = 0 menu_count = 0 basecmd_count = 0 total = [] base_dir = dir(BaseMenu) for match in matches: if True: #not substitution or str(match).startswith(substitution): if not match.strip(): continue total.append(match) if match in completer.submenu_names: if menu_pt is None: menu_pt = create_table() if menu_count > columns: menu_pt.add_row(menus) menu_count = 0 menus = [""] * columns menus[menu_count] = match menu_count += 1 elif 'do_{0}'.format(match) in base_dir: if base_pt is None: base_pt = create_table() if basecmd_count >= columns: base_pt.add_row(basecmds) basecmd_count = 0 basecmds = [""] * columns basecmds[basecmd_count] = match basecmd_count += 1 else: if cmd_pt is None: cmd_pt = create_table() if cmd_count >= columns: cmd_pt.add_row(cmds) cmd_count = 0 cmds = [""] * columns cmds[cmd_count] = match cmd_count += 1 if menu_count: menu_pt.add_row(menus) if cmd_count: cmd_pt.add_row(cmds) if basecmd_count: base_pt.add_row(basecmds) cli_text = "" if substitution == completer.name: self.dprint('sub matches self.name, Inserting white space') readline.insert_text(" ") linebuffer = "{0} ".format(linebuffer) else: self.dprint('sub:"{0}" doesnt match self.name:"{1}"'.format( substitution, self.name)) cli_text = "{0}{1}".format(self.prompt, linebuffer) newline = readline.get_line_buffer() self.dprint( "\nCompleter_display():\n\tsubstitution:{0}\n\tmatches:{1}" "\n\tlongest_match_length:{2}\n\tlen total:{3}\n\torig line buffer:\"{4}\"" "\n\tsubtype:{5}\n\ttotal:{6}\n\tsubstitution:\"{7}\"\n\tcolumns:{8}" "\n\tcolumn width:{9}\n\tcurrent menu:{10}\n\tcurrent menu path from home:'{11}'" "\n\tnew line buffer:'{12}'\n\tcli text:'{13}'" "\n\tcompleter_context:{14}\n\tcompleter path from home:{15}" "\nmenu_pt:\n{16}\ncmds_pt:\n{17}\n".format( substitution, matches, longest_match_length, len(total), linebuffer, type(substitution), total, substitution, columns, column_width, self, self.path_from_home, newline, cli_text, completer, completer.path_from_home, menu_pt, cmd_pt)) self.stdout.seek(0) self.stdout.write("") self.stdout.flush() readline.redisplay() line_sep = "---------------------------------" buf = "\n" if cmd_pt: buf += yellow("\n{0}".format(cmd_pt), bold=True) if menu_pt: buf += blue("\n{0}\n{1}".format(line_sep, menu_pt), bold=True) if base_pt: buf += "\n{0}".format( cyan("{0}\n{1}".format(line_sep, base_pt))) self.oprint(buf) self.stdout.write(cli_text) self.stdout.flush() readline.redisplay() except Exception as E: self.stderr.write( red("{0}\nError in completer_display:\nerror:{1}".format( get_traceback(), E))) self.stderr.flush() finally: if self.env: self.env.completer_context = None
def clean_method(self): if not self.args.no_clean: self.log.info('Terminating all instances for user:{0}/{1}' .format(self.tc.user.account_name, self.tc.user.user_name)) self.tc.user.ec2.terminate_instances() if __name__ == "__main__": errors =[] test = InstanceBatchTest() try: # In the case we want to keep each instance connection open?... resource.setrlimit(resource.RLIMIT_NOFILE, (10 * test.args.vm_max ,-1)) except Exception as RE: test.log.warning(red('Unable to set resource limit to:"{0}", err:"{1}"' .format(10 * test.args.vm_max, RE))) def signal_handler(signal, frame): kill_it = False now = time.time() if now - test.last_kill_sig < 2: kill_it = True test.last_kill_sig = now sys.stderr.write(red('\n\nReceived SIGINT, dumping results. (Press ctrl+c twice quickly to end test now)\n\n')) sys.stderr.flush() test.show_results() if kill_it: sys.stderr.write(red('\n\nReceived SIGINT twice within 2 seconds killing test...!\n\n')) sys.stderr.flush() sys.exit(0) signal.signal(signal.SIGINT, signal_handler)
def _completer_display(self, substitution, matches, longest_match_length): try: completer = None if self.env: completer = self.env.completer_context completer = completer or self linebuffer = readline.get_line_buffer() height, width = self._get_terminal_size() columns = int((width - 12) / longest_match_length) or 1 column_width = longest_match_length def create_table(): header = [] for x in xrange(0, columns): header.append(x) pt = PrettyTable(header) pt.header = False pt.border = False pt.align = 'l' pt.max_width = column_width return pt menu_pt = None cmd_pt = None base_pt = None menus = [""]*columns cmds = [""]*columns basecmds = [""]*columns cmd_count = 0 menu_count = 0 basecmd_count = 0 total = [] base_dir = dir(BaseMenu) for match in matches: if True: #not substitution or str(match).startswith(substitution): if not match.strip(): continue total.append(match) if match in completer.submenu_names: if menu_pt is None: menu_pt = create_table() if menu_count > columns: menu_pt.add_row(menus) menu_count = 0 menus = [""]*columns menus[menu_count] = match menu_count += 1 elif 'do_{0}'.format(match) in base_dir: if base_pt is None: base_pt = create_table() if basecmd_count >= columns: base_pt.add_row(basecmds) basecmd_count = 0 basecmds = [""]*columns basecmds[basecmd_count] = match basecmd_count +=1 else: if cmd_pt is None: cmd_pt = create_table() if cmd_count >= columns: cmd_pt.add_row(cmds) cmd_count = 0 cmds = [""]*columns cmds[cmd_count] = match cmd_count +=1 if menu_count: menu_pt.add_row(menus) if cmd_count: cmd_pt.add_row(cmds) if basecmd_count: base_pt.add_row(basecmds) cli_text = "" if substitution == completer.name: self.dprint('sub matches self.name, Inserting white space') readline.insert_text(" ") linebuffer = "{0} ".format(linebuffer) else: self.dprint('sub:"{0}" doesnt match self.name:"{1}"' .format(substitution, self.name)) cli_text = "{0}{1}".format(self.prompt, linebuffer) newline = readline.get_line_buffer() self.dprint("\nCompleter_display():\n\tsubstitution:{0}\n\tmatches:{1}" "\n\tlongest_match_length:{2}\n\tlen total:{3}\n\torig line buffer:\"{4}\"" "\n\tsubtype:{5}\n\ttotal:{6}\n\tsubstitution:\"{7}\"\n\tcolumns:{8}" "\n\tcolumn width:{9}\n\tcurrent menu:{10}\n\tcurrent menu path from home:'{11}'" "\n\tnew line buffer:'{12}'\n\tcli text:'{13}'" "\n\tcompleter_context:{14}\n\tcompleter path from home:{15}" "\nmenu_pt:\n{16}\ncmds_pt:\n{17}\n" .format(substitution, matches, longest_match_length, len(total), linebuffer, type(substitution), total, substitution, columns, column_width, self, self.path_from_home, newline, cli_text, completer, completer.path_from_home, menu_pt, cmd_pt)) self.stdout.seek(0) self.stdout.write("") self.stdout.flush() readline.redisplay() line_sep = "---------------------------------" buf = "\n" if cmd_pt: buf += yellow("\n{0}".format(cmd_pt), bold=True) if menu_pt: buf += blue("\n{0}\n{1}".format(line_sep, menu_pt), bold=True) if base_pt: buf += "\n{0}".format(cyan("{0}\n{1}".format(line_sep, base_pt))) self.oprint(buf) self.stdout.write(cli_text) self.stdout.flush() readline.redisplay() except Exception as E: self.stderr.write(red("{0}\nError in completer_display:\nerror:{1}" .format(get_traceback(), E))) self.stderr.flush() finally: if self.env: self.env.completer_context = None
def __init__(self, *args): self.x = args[0] print red("### OPENING %s ###" % str(self.x)) oldfile.__init__(self, *args) openfiles.add(self) printOpenFiles()
def close(self): print red("### CLOSING %s ###" % str(self.x)) oldfile.close(self) openfiles.remove(self) printOpenFiles()
if not self.args.no_clean: self.log.info('Terminating all instances for user:{0}/{1}'.format( self.tc.user.account_name, self.tc.user.user_name)) self.tc.user.ec2.terminate_instances() if __name__ == "__main__": errors = [] test = InstanceBatchTest() try: # In the case we want to keep each instance connection open?... resource.setrlimit(resource.RLIMIT_NOFILE, (10 * test.args.vm_max, -1)) except Exception as RE: test.log.warning( red('Unable to set resource limit to:"{0}", err:"{1}"'.format( 10 * test.args.vm_max, RE))) def signal_handler(signal, frame): kill_it = False now = time.time() if now - test.last_kill_sig < 2: kill_it = True test.last_kill_sig = now sys.stderr.write( red('\n\nReceived SIGINT, dumping results. (Press ctrl+c twice quickly to end test now)\n\n' )) sys.stderr.flush() test.show_results() if kill_it: sys.stderr.write( red('\n\nReceived SIGINT twice within 2 seconds killing test...!\n\n'