Ejemplo n.º 1
0
def run(args, network_config):
    print("got {}, {}".format(args, network_config))
    procs = []

    if 'family' in args:
        if args['family'] not in FAMILY:
            raise LrException("Unkown load family: {}".format(family))
        family = FAMILY[args['family']]

    else:
        family = FAMILY['intkey']

    if 'sawtooth_path' in network_config:
        src_dir = network_config['sawtooth_path']
        if not os.path.exists(src_dir):
            raise LrException("Sawtooth not found at: {}", src_dir)
    else:
        raise LrException(
            "Network config does not contain `sawtooth_path`."
            " Cannot load without access to sawtooth-core."
        )

    if 'duration' in args:
        try:
            duration = sim.timeline.parse_time(args['duration'])
        except:
            raise LrException(
                "Duration must be integral, {} is invalid".format(duration)
            )
    else:
        duration = -1

    for node in args['nodes']:
        node_url = "http://{}:8800".format(
            tf.get_node_ip(node, network_config))

        rate = args['nodes'][node]

        print("Starting {} workload: {} TPM => {} for {} seconds...".format(
            family, rate, node_url, duration))

        procs.append(
            runner.spawn([
                PYTHON, HELPER, node_url, str(rate), src_dir, family, str(duration)
            ])
        )

    return procs
Ejemplo n.º 2
0
def _check_environment():
    for evar in ('AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY'):
        try:
            os.environ[evar]
        except KeyError:
            raise LrException(
                "Required environment variable `{}` not set.".format(evar))
Ejemplo n.º 3
0
def create_dir(network_id):
    network_dir = get_dir(network_id)
    try:
        if not os.path.exists(network_dir):
            os.makedirs(network_dir)
    except OSError:
        raise LrException("Failed to create directory: {}".format(network_id))
Ejemplo n.º 4
0
def destroy_dir(network_id):
    network_dir = get_dir(network_id)
    try:
        shutil.rmtree(network_dir)
    except OSError:
        raise LrException("Failed to remove directory and its contents: {}".format(
            network_dir))
Ejemplo n.º 5
0
def load(path_to_config):
    try:
        fd = open(path_to_config)
        contents = yaml.load(fd.read())
        fd.close()
        return contents
    except FileNotFoundError as err:
        raise LrException("Could not load timeline: {}".format(path_to_config))
Ejemplo n.º 6
0
def get_node_ip(node, network_config):
    output = _get_output(network_config)
    node_name = get_node_name(node, network_config)
    i = 0
    for node in output['tags']['value']:
        if node['Name'] == node_name:
            return output['ips']['value'][i]
        i += 1
    raise LrException("Node `{}` not found.".format(node_name))
Ejemplo n.º 7
0
def load(network_id):
    config_file = os.path.join(get_dir(network_id), "config.yaml")
    try:
        fd = open(config_file)
        contents = yaml.load(fd.read())
        fd.close()
        return contents
    except FileNotFoundError as err:
        raise LrException(
            "Unknown network, could not load config: {}".format(network_id))
Ejemplo n.º 8
0
def _run(args, capture_stdout):
    try:
        if capture_stdout:
            process = subprocess.run(args, stdout=subprocess.PIPE, check=True)

            return process.stdout.decode()
        else:
            process = subprocess.run(args, check=True)
            return ""

    except subprocess.CalledProcessError as err:

        raise LrException("Failed to execute subprocess, exit code: {}"
                          "`{}`".format(err.returncode, args))
Ejemplo n.º 9
0
def get_node_ip(node, network_id):
    instance_tag = "tag_Name_{}_node{}".format(network_id, node)

    cwd = os.getcwd()
    os.chdir(ANSIBLE_PATH)

    instances = yaml.load(runner.run(
        ['./ec2.py', '--list'],
        capture_stdout=True
    ))

    os.chdir(cwd)
    
    if instance_tag in instances:
        if len(instances[instance_tag]) > 0:
            return instances[instance_tag][0]

    raise LrException("Instance tag not found: {}".format(instance_tag))
Ejemplo n.º 10
0
def get_random_name():
    try:
        with open(os.path.join(DATA_DIR, "names")) as fd:
            return random.choice(fd.read().split("\n"))
    except OSError:
        raise LrException("Failed to generate random name")
Ejemplo n.º 11
0
def _raise_invalid(string, reason=""):
    raise LrException("Invalid time: {}. {}".format(string, reason))
Ejemplo n.º 12
0
def run(args, network_config):
    print("Load: {}, {}".format(args, network_config))
    procs = []

    if 'family' not in args:
        raise LrException("No family specified for load command")
    else:
        family = args['family']
        if family not in FAMILIES:
            raise LrException("Unkown load family: {}".format(family))

    if 'sawtooth_path' in network_config:
        src_dir = network_config['sawtooth_path']
        if not os.path.exists(src_dir):
            raise LrException("Sawtooth not found at: {}".format(src_dir))
    else:
        raise LrException("Network config does not contain `sawtooth_path`."
                          " Cannot load without access to sawtooth-core.")

    if 'duration' in args:
        try:
            duration = sim.timeline.parse_time(args['duration'])
        except:
            raise LrException("Duration {} is invalid".format(
                args['duration']))
    else:
        duration = -1

    if 'transactor_key' not in args:
        raise LrException("No transactor signing key specified")

    key = args['transactor_key']

    if 'rate' not in args:
        raise LrException("No rate specified")

    try:
        rate = int(args['rate'])
    except:
        raise LrException("Rate {} is invalid".format(args['rate']))

    if 'batch_size' in args:
        if family != 'smallbank':
            raise LrException("Batch size only supported in smallbank")
        batch_size = int(args['batch_size'])
    else:
        batch_size = 1

    urls = ",".join([
        "http://{}:8080".format(tf.get_node_ip(node, network_config))
        for node in args['nodes']
    ])

    print("Starting {} workload: {} TPS => {} for {} seconds...".format(
        family, rate, urls, duration))

    procs.append(
        runner.spawn([
            PYTHON, HELPER, family, urls,
            str(rate),
            str(batch_size), src_dir,
            str(duration), key
        ]))

    return procs