def execute(self, cmd): ''' Execute and check exit code ''' self.log.info("Executing: %s", cmd) retcode = tankcore.execute(cmd, shell=True, poll_period=0.1)[0] if retcode: raise RuntimeError("Subprocess returned %s" % retcode)
def is_test_finished(self): if self.poll: self.log.info("Executing: %s", self.poll) retcode = tankcore.execute(self.poll, shell=True, poll_period=0.1)[0] if retcode: self.log.warn("Non-zero exit code, interrupting test: %s", retcode) return retcode return -1
def __check_disk(self): ''' raise exception on disk space exceeded ''' cmd = "sh -c \"df --no-sync -m -P -l -x fuse -x tmpfs -x devtmpfs -x davfs -x nfs " cmd += self.core.artifacts_base_dir cmd += " | tail -n 1 | awk '{print \$4}' \"" res = tankcore.execute(cmd, True, 0.1, True) logging.debug("Result: %s", res) if not len(res[1]): self.log.debug("No disk usage info: %s", res[2]) return disk_free = res[1] self.log.debug("Disk free space: %s/%s", disk_free.strip(), self.disk_limit) if int(disk_free.strip()) < self.disk_limit: raise RuntimeError("Not enough local resources: disk space less than %sMB in %s: %sMB" % ( self.disk_limit, self.core.artifacts_base_dir, int(disk_free.strip())))
def __check_disk(self): ''' raise exception on disk space exceeded ''' cmd = "sh -c \"df --no-sync -m -P -l -x fuse -x tmpfs -x devtmpfs -x davfs -x nfs " cmd += self.core.artifacts_base_dir cmd += " | tail -n 1 | awk '{print \$4}' \"" res = tankcore.execute(cmd, True, 0.1, True) logging.debug("Result: %s", res) if not len(res[1]): self.log.debug("No disk usage info: %s", res[2]) return disk_free = res[1] self.log.debug("Disk free space: %s/%s", disk_free.strip(), self.disk_limit) if int(disk_free.strip()) < self.disk_limit: raise RuntimeError( "Not enough local resources: disk space less than %sMB in %s: %sMB" % (self.disk_limit, self.core.artifacts_base_dir, int(disk_free.strip())))
class PhantomPlugin(AbstractPlugin, AggregateResultListener): """ Plugin for running phantom tool """ OPTION_CONFIG = "config" SECTION = PhantomConfig.SECTION def __init__(self, core): AbstractPlugin.__init__(self, core) self.config = None self.process = None self.predefined_phout = None self.phout_import_mode = False self.did_phout_import_try = False self.phantom_path = None self.eta_file = None self.processed_ammo_count = 0 self.phantom_start_time = time.time() self.buffered_seconds = "2" self.taskset_affinity = None self.cpu_count = mp.cpu_count() self.phantom = None self.cached_info = None self.phantom_stderr = None self.enum_ammo = False @staticmethod def get_key(): return __file__ def get_available_options(self): opts = [ "eta_file", "phantom_path", "buffered_seconds", "exclude_markers" ] opts += 'affinity' opts += [PhantomConfig.OPTION_PHOUT, self.OPTION_CONFIG] opts += PhantomConfig.get_available_options() return opts def configure(self): # plugin part self.config = self.get_option(self.OPTION_CONFIG, '') self.eta_file = self.get_option("eta_file", '') self.core.add_artifact_file(self.eta_file) self.phantom_path = self.get_option("phantom_path", 'phantom') self.enum_ammo = self.get_option("enum_ammo", False) self.buffered_seconds = int( self.get_option("buffered_seconds", self.buffered_seconds)) self.exclude_markers = set( filter((lambda marker: marker != ''), self.get_option('exclude_markers', []).split(' '))) self.taskset_affinity = self.get_option('affinity', '') try: autostop = self.core.get_plugin_of_type(AutostopPlugin) autostop.add_criteria_class(UsedInstancesCriteria) except KeyError: self.log.debug( "No autostop plugin found, not adding instances criteria") self.predefined_phout = self.get_option(PhantomConfig.OPTION_PHOUT, '') if not self.get_option(self.OPTION_CONFIG, '') and self.predefined_phout: self.phout_import_mode = True if not self.config and not self.phout_import_mode: self.phantom = PhantomConfig(self.core) self.phantom.read_config() def prepare_test(self): aggregator = None try: aggregator = self.core.get_plugin_of_type(AggregatorPlugin) except Exception, ex: self.log.warning("No aggregator found: %s", ex) if aggregator: aggregator.reader = PhantomReader(aggregator, self) aggregator.reader.buffered_seconds = self.buffered_seconds if self.phantom: self.phantom.set_timeout(aggregator.get_timeout()) aggregator.add_result_listener(self) if not self.config and not self.phout_import_mode: if aggregator: aggregator.reader.phout_file = self.phantom.phout_file # generate config self.config = self.phantom.compose_config() args = [self.phantom_path, 'check', self.config] try: result = tankcore.execute(args, catch_out=True) except OSError: raise RuntimeError("Phantom I/O engine is not installed!") retcode = result[0] if retcode: raise RuntimeError( "Config check failed. Subprocess returned code %s" % retcode) if result[2]: raise RuntimeError("Subprocess returned message: %s" % result[2]) else: if aggregator: aggregator.reader.phout_file = self.predefined_phout try: console = self.core.get_plugin_of_type(ConsoleOnlinePlugin) except Exception, ex: self.log.debug("Console not found: %s", ex) console = None