def test_jobs(): """ Test the jobs function """ jobs = Jobs() assert isinstance(jobs, tuple) path = PathDirs() status = path.host_config() assert isinstance(status, tuple) assert status[0] # run test job with open('/opt/vent_files/foo.matrix', 'w') as f: f.write('24,23\n10,22') pcap = 'https://s3.amazonaws.com/tcpreplay-pcap-files/test.pcap' r = requests.get(pcap, stream=True) if r.status_code == 200: with open('/opt/vent_files/foo.pcap', 'wb') as f: r.raw.decode_content = True shutil.copyfileobj(r.raw, f) services = Services(True) assert isinstance(services, list) jobs = Jobs() assert isinstance(jobs, tuple)
def test_jobs(): """ Test the jobs function """ jobs = Jobs() assert isinstance(jobs, tuple) path = PathDirs() status = path.host_config() assert isinstance(status, tuple) assert status[0] m_helper = MenuHelper() status = m_helper.cores('install') assert isinstance(status, tuple) assert status[0] status = m_helper.cores('build') assert isinstance(status, tuple) assert status[0] status = m_helper.cores('start') assert isinstance(status, tuple) assert status[0] status = m_helper.api_action.add( 'https://github.com/cyberreboot/vent-plugins', tools=[('tcpdump_hex_parser', ''), ('gpu_example', '')]) assert isinstance(status, tuple) assert status[0] # run test job with open('/opt/vent_files/foo.matrix', 'w') as f: f.write('24,23\n10,22') pcap = 'https://s3.amazonaws.com/tcpreplay-pcap-files/test.pcap' r = requests.get(pcap, stream=True) if r.status_code == 200: with open('/opt/vent_files/foo.pcap', 'wb') as f: r.raw.decode_content = True shutil.copyfileobj(r.raw, f) services = Services(True) assert isinstance(services, list) jobs = Jobs() assert isinstance(jobs, tuple)
def while_waiting(self): """ Update fields periodically if nothing is happening """ # give a little extra time for file descriptors to close time.sleep(0.1) self.addfield.value = Timestamp() self.addfield.display() self.addfield2.value = Uptime() self.addfield2.display() self.addfield3.value = str(len(Containers())) + ' running' if len(Containers()) > 0: self.addfield3.labelColor = 'GOOD' else: self.addfield3.labelColor = 'DEFAULT' self.addfield3.display() # update core tool status self.addfield5.value, values = MainForm.t_status(True) if values[0] + values[1] == 0: color = 'DANGER' self.addfield4.labelColor = 'CAUTION' self.addfield4.value = 'Idle' elif values[0] >= int(values[2]): color = 'GOOD' self.addfield4.labelColor = color self.addfield4.value = 'Ready to start jobs' else: color = 'CAUTION' self.addfield4.labelColor = color self.addfield4.value = 'Ready to start jobs' self.addfield5.labelColor = color # update plugin tool status plugin_str, values = MainForm.t_status(False) plugin_str += ', ' + str(values[3]) + ' plugin(s) installed' self.addfield6.value = plugin_str # get jobs jobs = Jobs() # number of jobs, number of tool containers self.addfield7.value = str(jobs[0]) + ' jobs running (' + str(jobs[1]) self.addfield7.value += ' tool containers), ' + str(jobs[2]) self.addfield7.value += ' completed jobs' if jobs[0] > 0: self.addfield4.labelColor = 'GOOD' self.addfield4.value = 'Processing jobs' self.addfield7.labelColor = 'GOOD' else: self.addfield7.labelColor = 'DEFAULT' self.addfield4.display() self.addfield5.display() self.addfield6.display() self.addfield7.display() # if file drop location changes deal with it logger = Logger(__name__) status = (False, None) if self.file_drop.value != DropLocation()[1]: logger.info('Starting: file drop restart') try: self.file_drop.value = DropLocation()[1] logger.info('Path given: ' + str(self.file_drop.value)) # restart if the path is valid if DropLocation()[0]: status = self.api_action.clean(name='file_drop') status = self.api_action.prep_start(name='file_drop') else: logger.error('file drop path name invalid' + DropLocation()[1]) if status[0]: tool_d = status[1] status = self.api_action.start(tool_d) logger.info('Status of file drop restart: ' + str(status[0])) except Exception as e: # pragma no cover logger.error('file drop restart failed with error: ' + str(e)) logger.info('Finished: file drop restart') self.file_drop.display() return
def test_jobs(): """ Test the jobs function """ jobs = Jobs() assert type(jobs) == tuple
def while_waiting(self): """ Update fields periodically if nothing is happening """ def popup(message): npyscreen.notify_confirm(str(message), title="Docker Error", form_color='DANGER', wrap=True) self.exit() # clean up forms with dynamic data self.parentApp.remove_forms() self.parentApp.add_forms() if not self.triggered: self.triggered = True try: self.api_action = Action() except DockerException as de: # pragma: no cover popup(de) # give a little extra time for file descriptors to close time.sleep(0.1) try: current_path = os.getcwd() except Exception as e: # pragma: no cover self.exit() self.addfield.value = Timestamp() self.addfield.display() self.addfield2.value = Uptime() self.addfield2.display() self.addfield3.value = str(len(Containers())) + " running" if len(Containers()) > 0: self.addfield3.labelColor = "GOOD" else: self.addfield3.labelColor = "DEFAULT" self.addfield3.display() # set core value string core = Core() installed = 0 custom_installed = 0 built = 0 custom_built = 0 running = 0 custom_running = 0 normal = str(len(core['normal'])) for tool in core['running']: if tool in core['normal']: running += 1 else: custom_running += 1 for tool in core['built']: if tool in core['normal']: built += 1 else: custom_built += 1 for tool in core['installed']: if tool in core['normal']: installed += 1 else: custom_installed += 1 core_str = str(running + custom_running) + "/" + normal + " running" if custom_running > 0: core_str += " (" + str(custom_running) + " custom)" core_str += ", " + str(built + custom_built) + "/" + normal + " built" if custom_built > 0: core_str += " (" + str(custom_built) + " custom)" core_str += ", " + str(installed + custom_installed) + "/" + normal + " installed" if custom_built > 0: core_str += " (" + str(custom_installed) + " custom)" self.addfield5.value = core_str if running + custom_running == 0: color = "DANGER" self.addfield4.labelColor = "CAUTION" self.addfield4.value = "Idle" elif running >= int(normal): color = "GOOD" self.addfield4.labelColor = color self.addfield4.value = "Ready to start jobs" else: color = "CAUTION" self.addfield4.labelColor = color self.addfield4.value = "Ready to start jobs" self.addfield5.labelColor = color # get jobs jobs = Jobs() # number of jobs, number of tool containers self.addfield6.value = str(jobs[0]) + " jobs running (" + str( jobs[1]) + " tool containers), " + str(jobs[2]) + " completed jobs" # TODO check if there are jobs running and update addfield4 if jobs[0] > 0: self.addfield4.labelColor = "GOOD" self.addfield4.value = "Processing jobs" self.addfield6.labelColor = "GOOD" else: self.addfield6.labelColor = "DEFAULT" self.addfield4.display() self.addfield5.display() self.addfield6.display() os.chdir(current_path) return