def __check_mem(self): ''' raise exception on RAM exceeded ''' cmd = "free -m | awk '$1==\"-/+\" {print $4}'" mem_free = int(tankcore.execute(cmd, True, 0.1, True)[1].strip()) self.log.debug("Memory free: %s/%s", mem_free, self.mem_limit) if mem_free < self.mem_limit: raise RuntimeError("Not enough resources: free memory less than %sMB: %sMB" % (self.mem_limit, mem_free))
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) if retcode: raise RuntimeError("Subprocess returned %s", )
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) if retcode: raise RuntimeError("Subprocess returned %s",)
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 = "df --no-sync -m -P -l -x fuse -x tmpfs -x devtmpfs " cmd += self.core.artifacts_base_dir cmd += " | tail -n 1 | awk '{print $4}'" disk_free = tankcore.execute(cmd, True, 0.1, True)[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_mem(self): ''' raise exception on RAM exceeded ''' cmd = "free -m | awk '$1==\"-/+\" {print $4}'" mem_free = int(tankcore.execute(cmd, True, 0.1, True)[1].strip()) self.log.debug("Memory free: %s/%s", mem_free, self.mem_limit) if mem_free < self.mem_limit: raise RuntimeError( "Not enough resources: free memory less than %sMB: %sMB" % (self.mem_limit, mem_free))
def __check_disk(self): ''' raise exception on disk space exceeded ''' cmd = "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}'" disk_free = tankcore.execute(cmd, True, 0.1, True)[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())))
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 ''' SECTION = 'phantom' def __init__(self, core): AbstractPlugin.__init__(self, core) self.process = None self.phout_import_mode = 0 self.did_phout_import_try = False self.phantom_path = None self.eta_file = None self.processed_ammo_count = 0 self.config = None self.stepper = None self.phantom = None self.phantom_start_time = time.time() self.buffered_seconds = "2" @staticmethod def get_key(): return __file__ def configure(self): # plugin part self.config = self.get_option("config", '') self.eta_file = self.get_option("eta_file", '') self.phantom_path = self.get_option("phantom_path", 'phantom') self.buffered_seconds = int( self.get_option("buffered_seconds", self.buffered_seconds)) self.core.add_artifact_file(self.eta_file) self.core.add_artifact_file(self.config) self.phout_import_mode = self.get_option(PhantomConfig.OPTION_PHOUT, '') 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") if not self.config and not self.phout_import_mode: self.phantom = PhantomConfig(self) self.phantom.read_config() self.stepper = StepperWrapper(self) self.stepper.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.timeout = aggregator.get_timeout() aggregator.add_result_listener(self) if not self.phout_import_mode: self.stepper.prepare_stepper() self.phantom.stpd = self.stepper.stpd if not self.config: self.config = self.phantom.compose_config() args = [self.phantom_path, 'check', self.config] retcode = tankcore.execute(args, catch_out=True)[0] if retcode: raise RuntimeError("Subprocess returned %s" % retcode) try: console = self.core.get_plugin_of_type(ConsoleOnlinePlugin) except Exception, ex: self.log.debug("Console not found: %s", ex) console = None
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.phantom = None self.cached_info = None self.phantom_stderr = None @staticmethod def get_key(): return __file__ def get_available_options(self): opts = ["eta_file", "phantom_path", "buffered_seconds", ] 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.buffered_seconds = int( self.get_option("buffered_seconds", self.buffered_seconds)) 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] result = tankcore.execute(args, catch_out=True) 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