Esempio n. 1
0
def init_test(args):
    """Setup fixture."""
    env = os.getenv("AUTOPUSH_ENV", "stage")
    config = configparser.ConfigParser()
    ini_path = os.path.join(os.getcwd(), "config.ini")
    config.read(ini_path)
    set_var("config", config[env])
def system_setup(args):
    """Set up test system.

    This is called before anything runs.

    """
    global SCHEMA
    # This is a copy of the one in the tecken repo
    schema_path = pathlib.Path("schemas/symbolicate_api_response_v5.json")
    SCHEMA = load_schema(schema_path)
    print("Schema loaded.")

    # Stacks are in the parent directory
    stacks_dir = pathlib.Path("stacks/")
    for path in stacks_dir.glob("*.json"):
        path = path.resolve()
        stack = load_stack(path)
        PAYLOADS.append((str(path), stack))

    # Set the API url
    api_url = os.environ.get("API_URL", DEFAULT_API_URL)
    set_var("api_url", api_url)

    print(f"Stacks loaded: {len(PAYLOADS)}")
    print(f"Running tests against: {api_url}")
Esempio n. 3
0
def init_test(args):  #pylint: disable=W0613
    """ Adding test fixtures """
    molotov.set_var('url', get_api_url())
    config = get_config()['riot_firmwares']
    generate_riot_firmwares(config['firmwares'], config['nb_firmwares'])
    firmwares = get_test_firmwares(config['firmwares'])
    molotov.set_var('firmwares', firmwares)
    molotov.set_var('sshkey', get_test_ssh_key())
    molotov.set_var('exp', get_test_experiments())
    molotov.set_var('ipv6', get_ipv6_prefix())
Esempio n. 4
0
def _setup(args):
    _HEADERS['Authorization'] = "Bearer %s" % _ACCESS_TOKEN
    calendar = molotov.json_request("%s/me/calendar" % _GCAPI, headers=_HEADERS)['content']
    molotov.set_var('calendar', calendar)
    if _NOW:
        now = dateutil.parser.parse(_NOW)
    else:
        now = datetime.now()
    print("\nBase datetime: %s (%s)\n" % (now, _LOCAL_TZ))
    molotov.set_var('now', now)
Esempio n. 5
0
def init_test(args):
    """
    Called once when the test starts.Set up some fixtures that are shared by all workers
    :param args: args arguments used to start Molotov
    :return: None
    """
    molotov.set_var(
        'User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
        'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36'
    )
    molotov.set_var('endpoint', 'https://www.dy2018.com')
Esempio n. 6
0
def init_test(args): #pylint: disable=W0613
    """ Adding test fixtures """
    config = get_config()
    molotov.set_var('config', config)
    molotov.set_var('url', get_api_url())
    molotov.set_var('site', get_test_site(config))
    molotov.set_var('users', get_test_users(config['users']))
Esempio n. 7
0
def init_test(args):  #pylint: disable=W0613
    """ Adding test fixtures """
    config = get_config()['serial_port']
    molotov.set_var('config', config)
    molotov.set_var('url', get_api_url())
    molotov.set_var('sshkey', get_test_ssh_key())
    molotov.set_var('exp', get_test_experiments())
def test_starts(args):
    """ This functions is called before anything starts.

    Notice that it's not a coroutine.

    Here we configure various things:
    * we configure the API endpoint we'll use in the tests.
    * we generate the various files to be sent in the tests.
    """
    setup_api_endpoint()
    # "512" instead of "1024" because writing in hexadecimal takes 2 bytes.
    files = {x: gzip.compress(
                 os.urandom(x * 512).hex().encode(),
                 compresslevel=0)
             for x in _FILE_SIZES}
    set_var("files", files)
Esempio n. 9
0
async def init_worker(worker_num, args):
    headers = {}

    content_type = molotov.get_var("content_type")
    if content_type:
        headers["Content-Type"] = content_type

    auth = molotov.get_var("auth")
    if auth is not None:
        basic = base64.b64encode(auth.encode())
        headers["Authorization"] = "Basic %s" % basic.decode()

    data = molotov.get_var("data")
    if data and data.startswith("py:"):
        method = molotov.get_var("method")
        url = molotov.get_var("url")
        func = resolve(data.split(":")[1])
        molotov.set_var("data", func(method, url, args))

    return {"headers": headers}
Esempio n. 10
0
def init_test(args):
    molotov.set_var("SomeHeader", "1")
    molotov.set_var("endpoint", "http://localhost:8080")
Esempio n. 11
0
def init_test(args):
    molotov.set_var('SomeHeader', '1')
    molotov.set_var('endpoint', 'http://localhost:8080')
Esempio n. 12
0
def run_test(url, results, salvoargs):
    args = namedtuple("args", "")
    args.force_shutdown = False
    args.ramp_up = 0.0
    args.verbose = salvoargs.verbose
    args.quiet = salvoargs.quiet
    args.exception = False
    args.processes = 1
    args.debug = False
    args.workers = salvoargs.concurrency
    args.console = True
    args.statsd = False
    args.single_mode = None
    args.max_runs = salvoargs.requests
    if salvoargs.duration:
        args.duration = salvoargs.duration
    else:
        args.duration = 9999
    args.delay = 0.0
    args.sizing = False
    args.sizing_tolerance = 0.0
    args.console_update = 0.1
    args.use_extension = []
    args.fail = None
    args.force_reconnection = False
    args.scenario = "salvo.scenario"
    args.disable_dns_resolve = False
    args.single_run = False

    molotov.set_var("method", salvoargs.method)
    molotov.set_var("url", url)
    molotov.set_var("results", results)
    molotov.set_var("auth", salvoargs.auth)
    molotov.set_var("content_type", salvoargs.content_type)
    molotov.set_var("data", salvoargs.data)
    if salvoargs.pre_hook is not None:
        molotov.set_var("pre_hook", resolve(salvoargs.pre_hook))
    if salvoargs.post_hook is not None:
        molotov.set_var("post_hook", resolve(salvoargs.post_hook))

    class Stream:
        def __init__(self):
            self.buffer = []

        def write(self, msg):
            self.buffer.append(msg)

        def flush(self):
            pass

    stream = Stream()
    res = run(args, stream=stream)

    if res["SETUP_FAILED"] > 0 or res["SESSION_SETUP_FAILED"] > 0:
        print("Setup failed. read the Molotov session below to get the error")
        print("".join(stream.buffer))

    return res
Esempio n. 13
0
def init_test(args):  #pylint: disable=W0613
    """ Adding test fixtures """
    molotov.set_var('config', get_config()['flash_firmware'])
    molotov.set_var('url', get_api_url())
    molotov.set_var('exp', get_test_experiments())
Esempio n. 14
0
def init_test(args):
    molotov.set_var('SomeHeader', '1')
    molotov.set_var('endpoint', 'http://localhost:8080')
Esempio n. 15
0
def init_test(args):  #pylint: disable=W0613
    """ Adding test fixtures """
    molotov.set_var('url', get_api_url())
    molotov.set_var('exp', get_test_experiments())
Esempio n. 16
0
def init_test(args):
    _HEADERS['Authorization'] = "Bearer %s" % _ACCESS_TOKEN
    me = molotov.json_request("%s/me" % _GCAPI, headers=_HEADERS)['content']
    molotov.set_var('me', me)
Esempio n. 17
0
def run_test(url, results, salvoargs):
    args = namedtuple("args", "")
    args.force_shutdown = False
    args.ramp_up = 0.0
    args.verbose = salvoargs.verbose
    args.quiet = salvoargs.quiet
    args.exception = False
    args.processes = 1
    args.debug = False
    args.workers = salvoargs.concurrency
    args.console = True
    args.statsd = False
    args.single_mode = None
    if salvoargs.duration:
        args.duration = salvoargs.duration
        args.max_runs = None
    else:
        args.duration = 9999
        args.max_runs = salvoargs.requests
    args.delay = 0.0
    args.sizing = False
    args.sizing_tolerance = 0.0
    args.console_update = 0.1
    args.use_extension = []
    args.fail = None
    args.force_reconnection = False
    args.scenario = __file__
    args.disable_dns_resolve = False
    args.single_run = False

    molotov.set_var("method", salvoargs.method)
    molotov.set_var("url", url)
    molotov.set_var("results", results)
    molotov.set_var("auth", salvoargs.auth)
    molotov.set_var("content_type", salvoargs.content_type)

    data = salvoargs.data
    if data and data.startswith("py:"):
        data = resolve(data.split(":")[1])
    molotov.set_var("data", data)

    if salvoargs.pre_hook is not None:
        molotov.set_var("pre_hook", resolve(salvoargs.pre_hook))
    else:
        molotov.set_var("pre_hook", None)

    if salvoargs.post_hook is not None:
        post_hook = resolve(salvoargs.post_hook)
        if not asyncio.iscoroutinefunction(post_hook):
            raise Exception("The post hook needs to be a coroutine")
        molotov.set_var("post_hook", post_hook)
    else:
        molotov.set_var("post_hook", None)

    class Stream:
        def __init__(self):
            self.buffer = []

        def write(self, msg):
            self.buffer.append(msg)

        def flush(self):
            pass

    # this module is going to be loaded by molotov,
    # so we need to clear up its internal state
    # XXX we should have a better way to do this
    util._STOP = False
    util._STOP_WHY = []
    util._TIMER = None
    api._SCENARIO.clear()
    api._FIXTURES.clear()

    stream = Stream()
    res = run(args, stream=stream)

    if res["SETUP_FAILED"] > 0 or res["SESSION_SETUP_FAILED"] > 0:
        print("Setup failed. read the Molotov session below to get the error")
        print("".join(stream.buffer))

    return res
Esempio n. 18
0
def init_test(args):
    BASE_URL=os.getenv('BASE_URL', '')
    molotov.set_var('base_url', BASE_URL)
Esempio n. 19
0
def init_test(args): #pylint: disable=W0613
    """ Adding test fixtures """
    molotov.set_var('url', get_api_url())
    molotov.set_var('auth', get_auth())