Exemplo n.º 1
0
 def set_interface_metric(self, value=0):
     cmd = [
         windows_safe_path(
             "C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
         ), "Set-NetIPInterface", "-InterfaceIndex",
         self.data['InterfaceIndex'], "-InterfaceMetric",
         str(value)
     ]
     check_subprocess(cmd)
     self.data['IPConnectionMetric'] = str(value)
class VPNApplicationBuilder(Builder):

    VPNs = {
        'express_vpn': {
            'macos': {
                'app': '/Applications/ExpressVPN.app',
            },
            'windows': {
                'app': windows_safe_path(
                    "C:\\Program Files (x86)\\ExpressVPN\\xvpn-ui\\ExpressVpn.exe"),
                'tap': "ExpressVPN Tap Adapter",
            },
            'linux': {
                'app': '/usr/bin/expressvpn',
            },
        },
    }

    @staticmethod
    def name():
        return 'vpn_application'

    def build(self, device, config):
        return GenericVPNBuilder(VPNApplicationBuilder.VPNs).build(device, config)
Exemplo n.º 3
0
def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]

    # Some of these command line args are also specified in the context. This is just for
    # convenience as certain of the arguments are changed often enough to warrant specifying them
    # on the command line.
    parser = argparse.ArgumentParser(
        description=
        'Run a set of tests locally on the current machine. The exit code of this '
        '"command will be the number of tests which failed or, if an unexpected error occured, -1.'
    )
    parser.add_argument(
        '-o',
        '--output-root',
        help='Root folder where all output for this test run will be '
        'written. Defaults to a system temp directory for the current user.')
    parser.add_argument(
        '-c',
        '--test-configs',
        default=[],
        nargs='+',
        help='Either: a python file with a module '
        'level list attribute TESTS is list of tests; a json file whose top level element is an '
        'array of tests; or a json string parsable to a list of tests.')
    parser.add_argument(
        '-d',
        '--test-devices',
        default=[],
        nargs='+',
        help='Either: a python file with a module '
        'level list attribute DEVICES is list of devices; a json file whose top level element is '
        'an array of devices; or a json string parsable to a list of tests.')
    parser.add_argument(
        '-r',
        '--run-directory',
        default=None,
        help='A unique subdirectory of the output_root '
        'where results for this specific run will go. If not specified then a unique one will be '
        "generated based on the run timestamp. The directory will be created if it doesn't exist"
    )
    parser.add_argument(
        '-m',
        '--allow-manual',
        default=None,
        action='store_true',
        help=
        'Allow manual tests. If this is not specified then any test which requires manual '
        'interaction will fail')
    parser.add_argument(
        '-s',
        '--stop-on-fail',
        default=None,
        action='store_true',
        help=
        'If specified, the test run will stop as soon as the first test fails.'
    )
    parser.add_argument('-t',
                        '--test-regex',
                        default=None,
                        help='If specified, only run tests whose test class '
                        'name matches the passed regex.')
    parser.add_argument('-x',
                        '--context',
                        default='default_context.py',
                        help='If specified, only run tests whose '
                        'test class name matches the passed regex.')
    parser.add_argument('-l',
                        '--log-level',
                        default=None,
                        help='Log level. Valid values ["ERROR", "WARNING", '
                        '"INFO", "DEBUG", "VERBOSE"].')
    parser.add_argument('-2',
                        '--v2',
                        default=False,
                        action='store_true',
                        help='DEPRECATED: Does nothing')
    args = parser.parse_args(argv)

    args.log_level = args.log_level.upper() if args.log_level else None
    # We'll reconfigure in a second but lets get logging going asap!
    inital_log_level = args.log_level if args.log_level else "INFO"
    TestRunner.configure_logger(level=inital_log_level)

    if args.output_root is None:
        if current_os() == "windows":
            args.output_root = tempfile.mkdtemp()
        else:
            # Don't make the folder as root else we'll get perms issues. This also ensures we use
            # the user's temp directory not root's temp directory.
            args.output_root = subprocess.check_output(
                ['sudo', '-u', tools_user()[1], 'mktemp',
                 '-d']).decode().strip()
        L.warning("You didn't specify an output folder. Using: {}".format(
            args.output_root))

    args.output_root = windows_safe_path(args.output_root)

    if not os.path.exists(args.output_root):
        makedirs_safe(args.output_root)

    if args.run_directory is None:
        args.run_directory = "Run_{}".format(time.time())

    # Just add output_directory to the args object as it makes life simpler.
    args.output_directory = os.path.join(args.output_root, args.run_directory)
    makedirs_safe(args.output_directory)

    context_dict = import_by_filename(args.context).CONTEXT
    cmd_line_overrides = [
        'run_directory',
        'output_directory',
        'allow_manual',
        'stop_on_fail',
        'log_level',
    ]

    for override in cmd_line_overrides:
        value = getattr(args, override)
        if value is not None:
            context_dict[override] = value

    # Log level might need updating based on config
    TestRunner.configure_logger(args.output_directory,
                                level=getattr(L, context_dict['log_level']))

    test_configs = []
    for test_config_file in args.test_configs:
        test_configs += object_from_command_line(test_config_file, 'TESTS')

    test_devices = []
    for test_device_file in args.test_devices:
        test_devices += object_from_command_line(test_device_file, 'DEVICES')

    if args.test_regex:
        test_configs = filter_tests(test_configs, args.test_regex)

    # This call shouldn't throw. If it does then we need to tweak the TestRunner.
    if args.v2:
        L.warning(
            "Argument -2 is DEPRECATED and will be ignored. Test runner v2 is the default now"
        )
    return TestRunner(TestRunContext(context_dict), test_devices,
                      test_configs).run()
 def open_app(self, app_path, root=False):  # pylint: disable=unused-argument
     cmd = ['run', "\"{}\"".format(windows_safe_path(app_path))]
     L.debug("Executing cmd '{}'".format(cmd))
     self._connector_helper.check_command(cmd)