def connect(location=None, default=None): if location: with local.as_root(): wg_quick('up', f'azirevpn-{location}1') else: try: choice = choose("Where to?", LOCATIONS, default) except KeyboardInterrupt: print() else: with local.as_root(): wg_quick('up', f'azirevpn-{choice}1')
def main(self): # if (vpn := current()): vpn = current() # if vpn: # with local.as_root(): wg_quick('down', vpn) print_status()
def update_pkgfile(self): pkgfile = sh['pkgfile'] print_banner('pkgfile') with sh.as_root(): pkgfile['-u'] & FG self.updated = True
def update_pacman(self): pacman = sh['pacman'] print_banner('pacman') with sh.as_root(): pacman['-Syu', '--overwrite', '--noconfirm'] & FG self.updated = True
def test_sshpass(self): with local.as_root(): local["useradd"]("-m", "-b", "/tmp", "testuser") try: with local.as_root(): try: (local["passwd"] << "123456")("--stdin", "testuser") except ProcessExecutionError: # some versions of passwd don't support --stdin, nothing to do in this case logging.warn("passwd failed") return with SshMachine("localhost", user = "******", password = "******") as rem: self.assertEqual(rem["pwd"]().strip(), "/tmp/testuser") finally: with local.as_root(): local["userdel"]("-r", "testuser")
def update_aur(self): yaourt = sh['yaourt'] print_banner('aur') yaourt['-Syu', '--aur', '--noconfirm'] & FG for yaourt_dir in sh.path('/tmp').glob('yaourt-*'): with sh.as_root(): yaourt_dir.delete() self.updated = True
def update_pacmandb(self): # We have to use the Python module directly using the host interpreter. reflector = sh['/bin/python3']['-m', 'Reflector'] print_banner('pacmandb') with sh.as_root(): reflector[ '--verbose', '--threads', os.cpu_count(), '--sort', 'score', '--save', '/etc/pacman.d/mirrorlist', '--country', 'US', '--fastest', 10, ] & FG self.updated = True
def test_as_user(self): with local.as_root(): local["date"]()
def current(): try: with local.as_root(): return wg('show').splitlines()[0].split(': ')[-1] except IndexError: return None
def run(self) -> actions.StepResult: """Capture instrumentation stats by running the binary with a workload and attaching the UsdtExecutionStats.bt.""" project: Project = self.obj vara_result_folder = get_varats_result_folder(project) binary: ProjectBinaryWrapper for binary in project.binaries: if binary.type != BinaryType.EXECUTABLE: continue # Get workload to use. # TODO (se-sic/VaRA#841): refactor to bb workloads if possible workload_provider = WorkloadProvider.create_provider_for_project( project ) if not workload_provider: print( f"No workload provider for project={project.name}. " \ "Skipping." ) return actions.StepResult.CAN_CONTINUE workload = workload_provider.get_workload_for_binary(binary.name) if workload is None: print( f"No workload for project={project.name} " \ f"binary={binary.name}. Skipping." ) continue # Assemble Path for report. report_file_name = create_new_success_result_filename( self.__experiment_handle, VaraInstrumentationStatsReport, project, binary ) report_file = Path(vara_result_folder, str(report_file_name)) # Execute binary. with local.cwd(project.source_of_primary): run_cmd = binary[workload] # attach bpftrace to binary to allow tracing it via USDT bpftrace_script = Path( VaRA.install_location(), "share/vara/perf_bpf_tracing/UsdtExecutionStats.bt" ) # Assertion: Can be run without sudo password prompt. To # guarentee this, add an entry to /etc/sudoers. bpftrace_cmd = bpftrace["-o", report_file, bpftrace_script, binary.path] bpftrace_runner: Future with local.as_root(): bpftrace_runner = bpftrace_cmd & BG sleep(3) # give bpftrace time to start up # Run. run_cmd & FG # pylint: disable=W0104 # Wait for bpftrace running in background to exit. bpftrace_runner.wait() return actions.StepResult.OK