def configure_logger(output_directory=None,
                         level=L.INFO,
                         describe=False,
                         report=False):
        trace_logfile = None
        if output_directory:
            trace_logfile = os.path.join(output_directory, 'log.txt')

        describe_logfile = None
        if describe and output_directory:
            describe_logfile = os.path.join(output_directory,
                                            'description.txt')

        report_logfile = None
        if report and output_directory:
            report_logfile = os.path.join(output_directory,
                                          'system_report.txt')

        L.configure({
            'trace': {
                'file_format': '%(asctime)s %(levelname)s: %(message)s',
                'logfile': trace_logfile,
                'level': level,
            },
            'describe': {
                'file_format': '%(message)s',
                'logfile': describe_logfile,
            },
            'report': {
                'stream_format': None,
                'file_format': '%(message)s',
                'logfile': report_logfile,
            },
        })
def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]

    parser = argparse.ArgumentParser(
        description=
        'Wrap tests which can be run entirely on one machine for remote execution'
    )
    parser.add_argument(
        'input_config',
        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('--device-id',
                        default=None,
                        help='Device to run the tests on.')
    parser.add_argument('--os-name',
                        default=None,
                        help='Device OS to run the tests on.')
    parser.add_argument('--os-version',
                        default=None,
                        help='Device OS version to run the tests on.')
    parser.add_argument(
        '--output_config',
        help='Root folder where all output for this test run will be written. '
        'You must create the folder first.')
    parser.add_argument(
        '--format',
        default='json',
        help='Output format of the generated config. Valid options '
        'are: json')
    args = parser.parse_args(argv)

    # TODO: I'm less and less happy with the logger now
    L.configure({
        'trace': {
            'level': L.INFO,
        },
        'describe': {
            'file_format': None,
        },
        'report': {
            'file_format': None,
        },
    })
    LocalTestWrapper.wrap(args)
Example #3
0
def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]

    scriptlet_args = argv[1:]
    argv = argv[0:1]

    parser = argparse.ArgumentParser(description='Execute a scriptlet locally for testing')
    parser.add_argument(
        'scriptlet', help='Name of the scriptlet in the xv_leak_tools/scriplets folder')

    args = parser.parse_args(argv)

    L.configure({
        'trace': {
            'level': L.INFO,
        },
        'describe': {
            'file_format': None,
        },
        'report': {
            'file_format': None,
        },
    })

    try:
        L.info("Running scriptlet {} with args {}".format(args.scriptlet, scriptlet_args))

        context = TestRunContext({'output_directory': 'output'})
        localhost = LocalhostDiscoverer(context, []).discover_device({})
        helper = ConnectorHelper(localhost)
        L.info("scriptlet returned {}".format(helper.execute_scriptlet(
            'remote_mac_ver.py', scriptlet_args)))

    except BaseException as ex:
        L.info("scriptlet raised {}".format(ex))

    return 0
#!/usr/bin/env python3

import os
import sys

# TODO: I think we solve this problem by making a proper pip module
# Add the root so we can import xv_leak_tools
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             '..'))

import fake_device
from xv_leak_tools.log import L
from xv_leak_tools.test_components.firewall.linux.linux_firewall import LinuxFirewall
from xv_leak_tools.test_components.firewall.macos.macos_firewall import MacOSFirewall

L.configure({
    'trace': {
        'level': L.DEBUG,
    },
    'describe': {
        'file_format': None,
    },
    'report': {
        'file_format': None,
    },
})

lf = MacOSFirewall(fake_device.get_fake_device(), {})
lf.block_ip("8.8.8.8")
lf.unblock_ip("8.8.8.8")