def test_tools_status(): """ Test the tools_status function """ instance = MenuHelper() core = instance.tools_status(True) assert isinstance(core, tuple) plugins = instance.tools_status(False) assert isinstance(plugins, tuple)
def test_repo_tools(): """ Test the repo_tools function """ instance = MenuHelper() status = instance.repo_tools('https://github.com/cyberreboot/vent', 'master', 'HEAD') assert isinstance(status, tuple) assert status[0] == True
def test_repo_commits(): """ Test the repo_commits function """ instance = Plugin() status = instance.add('https://github.com/cyberreboot/vent', build=False) assert isinstance(status, tuple) assert status[0] == True instance = MenuHelper() status = instance.repo_commits('https://github.com/cyberreboot/vent') assert isinstance(status, tuple)
def repo_tools(self, branch): """ Set the appropriate repo dir and get the tools available of it """ tools = [] m_helper = MenuHelper() repo = self.parentApp.repo_value['repo'] version = self.parentApp.repo_value['versions'][branch] status = m_helper.repo_tools(repo, branch, version) if status[0]: r_tools = status[1] for tool in r_tools: tools.append(tool[0]) return tools
def test_cores(): """ Test the cores function """ instance = MenuHelper() cores = instance.cores('install') assert cores[0] == True cores = instance.cores('build') assert cores[0] == True cores = instance.cores('start') assert cores[0] == True cores = instance.cores('stop') assert cores[0] == True cores = instance.cores('clean') assert cores[0] == True
def t_status(core): """ Get status of tools for either plugins or core """ m_helper = MenuHelper() repos, tools = m_helper.tools_status(core) installed = 0 custom_installed = 0 built = 0 custom_built = 0 running = 0 custom_running = 0 normal = str(len(tools['normal'])) # determine how many extra instances should be shown for running norm = set(tools['normal']) inst = set(tools['installed']) run_str = str(len(tools['normal']) + len(inst - norm)) for tool in tools['running']: # check for multi instances too for running if tool in tools['normal']: running += 1 elif re.sub(r'\d+$', '', tool) in tools['normal']: running += 1 else: custom_running += 1 for tool in tools['built']: if tool in tools['normal']: built += 1 else: custom_built += 1 for tool in tools['installed']: if tool in tools['normal']: installed += 1 elif re.sub(r'\d+$', '', tool) not in tools['normal']: custom_installed += 1 tools_str = str(running + custom_running) + '/' + run_str + ' running' if custom_running > 0: tools_str += ' (' + str(custom_running) + ' custom)' tools_str += ', ' + str(built + custom_built) + '/' + normal + ' built' if custom_built > 0: tools_str += ' (' + str(custom_built) + ' custom)' tools_str += ', ' + str(installed + custom_installed) + '/' + normal tools_str += ' installed' if custom_built > 0: tools_str += ' (' + str(custom_installed) + ' custom)' return tools_str, (running, custom_running, normal, repos)
def core_tools(action): """ Perform actions for core tools """ def diff(first, second): """ Get the elements that exist in the first list and not in the second """ second = set(second) return [item for item in first if item not in second] def popup(original, orig_type, thr, title): """ Start the thread and display a popup of info until the thread is finished """ thr.start() info_str = '' while thr.is_alive(): if orig_type == 'containers': info = diff(Containers(), original) elif orig_type == 'images': info = diff(Images(), original) if info: info_str = '' for entry in info: # TODO limit length of info_str to fit box info_str += entry[0] + ': ' + entry[1] + '\n' npyscreen.notify_wait(info_str, title=title) time.sleep(1) return if action == 'install': original_images = Images() m_helper = MenuHelper() thr = Thread(target=m_helper.cores, args=(), kwargs={'action': 'install'}) popup(original_images, 'images', thr, 'Please wait, installing core containers...') notify_confirm( 'Done installing core containers (any' ' already installed tools untouched).', title='Installed core containers') return
def __init__(self, *args, **keywords): """ Initialize tool form objects """ self.logger = Logger(__name__) self.logger.info(str(keywords['names'])) self.api_action = Action() self.m_helper = MenuHelper() action = {'api_action': self.api_action} self.tools_tc = {} self.repo_widgets = {} if keywords['action_dict']: action.update(keywords['action_dict']) if keywords['names']: i = 1 for name in keywords['names']: action['action_object' + str(i)] = getattr( self.api_action, name) i += 1 self.action = action # get list of all possible group views to display self.views = deque() possible_groups = set() manifest = Template(self.api_action.plugin.manifest) if self.action['cores']: tools = self.api_action.inventory(choices=['core'])[1]['core'] else: tools = self.api_action.inventory(choices=['tools'])[1]['tools'] for tool in tools: groups = manifest.option(tool, 'groups')[1].split(',') for group in groups: # don't do core because that's the purpose of all in views if group != '' and group != 'core': possible_groups.add(group) self.manifest = manifest self.views += possible_groups self.views.append('all groups') self.no_instance = ['build', 'remove'] super(ToolForm, self).__init__(*args, **keywords)
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 repo_values(self): """ Set the appropriate repo dir and get the branches and commits of it """ branches = [] commits = {} m_helper = MenuHelper() status = m_helper.repo_branches(self.parentApp.repo_value['repo']) # branches and commits must both be retrieved successfully if status[0]: branches = status[1] status = m_helper.repo_commits(self.parentApp.repo_value['repo']) if status[0]: r_commits = status[1] for commit in r_commits: commits[commit[0]] = commit[1] else: # if commits failed, return commit errors return status else: # if branch failed, return branch errors return status # if everything is good, return branches with commits return branches, commits