def test_calls_which(self): mock_call_and_check = self.patch(shell_module, "call_and_check") cmd = factory.make_name("cmd") has_command_available(cmd) self.assertThat( mock_call_and_check, MockCalledOnceWith(["which", cmd]) )
def scan_networks(args, to_scan, stderr, stdout): """Interprets the specified `args` and `to_scan` dict to perform the scan. Uses the specified `stdout` and `stderr` for output. """ # Start the clock. (We want to measure how long the scan takes.) clock = time.monotonic() # The user must explicitly opt out of using `nmap` by selecting --ping, # unless `nmap` is not installed. use_nmap = has_command_available("nmap") use_ping = args.ping if use_nmap and not use_ping: tool = "nmap" scanner = nmap_scan(to_scan, slow=args.slow, threads=args.threads) count = 0 for count, event in enumerate(scanner, 1): write_event(event, stdout) clock_diff = time.monotonic() - clock if count > 0: stderr.write( "%d nmap scan(s) completed in %d second(s).\n" % (count, clock_diff) ) stderr.flush() else: tool = "ping" # For a ping scan, we can easily get a count of the number of hosts, # and whether or not the ping was successful. It will be printed to # stderr for informational purposes. count = 0 hosts = 0 for event in ping_scan(to_scan, threads=args.threads): count += 1 if event["result"] is True: hosts += 1 write_event(event, stdout) clock_diff = time.monotonic() - clock if count > 0: stderr.write( "Pinged %d hosts (%d up) in %d second(s).\n" % (count, hosts, clock_diff) ) stderr.flush() return {"count": count, "tool": tool, "seconds": clock_diff}
def detect_missing_packages(self): missing_packages = set() for binary, package in REQUIRED_PACKAGES: if not shell.has_command_available(binary): missing_packages.add(package) return list(missing_packages)
def detect_missing_packages(self): binary, package = ['snmpset', 'snmp'] if not shell.has_command_available(binary): return [package] return []
def test_returns_True_when_ExternalProcessError_not_raised(self): self.patch(shell_module, "call_and_check") self.assertTrue(has_command_available(factory.make_name("cmd")))
def test_returns_False_when_ExternalProcessError_raised(self): self.patch( shell_module, "call_and_check" ).side_effect = ExternalProcessError(1, "cmd") self.assertFalse(has_command_available(factory.make_name("cmd")))
def detect_missing_packages(self): if not shell.has_command_available('fence_cdu'): return ['fence-agents'] return []
def detect_missing_packages(self): if not shell.has_command_available("ipmitool"): return ["ipmitool"] return []
def detect_missing_packages(self): if not shell.has_command_available('ipmipower'): return ['freeipmi-tools'] return []
def detect_missing_packages(self): if not shell.has_command_available("ipmipower"): return ["freeipmi-tools"] return []
def detect_missing_packages(self): missing_packages = [] for binary, package in REQUIRED_PACKAGES: if not shell.has_command_available(binary): missing_packages.append(package) return missing_packages
def detect_missing_packages(self): missing_packages = set() for binary, package in REQUIRED_PACKAGES: if not shell.has_command_available(binary): missing_packages.add(package) return list(missing_packages)
def detect_missing_packages(self): if not shell.has_command_available('ipmitool'): return ['ipmitool'] return []
def detect_missing_packages(self): if not shell.has_command_available("wget"): return ["wget"] return []
def detect_missing_packages(self): if not shell.has_command_available("fence_cdu"): return ["fence-agents"] return []
def detect_missing_packages(self): if not shell.has_command_available('wget'): return ['wget'] return []