Exemple #1
0
def main():
    install_logging("Validate Premium Packs.log")
    options = options_handler()
    exit_code = 0
    index_data, index_file_path = get_index_json_data(
        service_account=options.service_account, production_bucket_name=options.production_bucket_name,
        extract_path=options.extract_path, storage_base_path=options.storage_base_path
    )

    # Get the first host by the ami env
    hosts, _ = Build.get_servers(ami_env=options.ami_env)
    internal_ip, tunnel_port = list(hosts.items())[0]
    username, password = extract_credentials_from_secret(options.secret)
    server = Server(internal_ip=internal_ip, port=tunnel_port, user_name=username, password=password)

    # Verify premium packs in the server
    paid_packs = get_premium_packs(client=server.client)
    if paid_packs:
        logging.info(f"Verifying premium packs in {server.internal_ip}")
        paid_packs_are_identical = verify_server_paid_packs_by_index(paid_packs, index_data["packs"])
        log_message_if_statement(statement=paid_packs_are_identical,
                                 error_message=f"Test failed on host: {server.internal_ip}.",
                                 success_message=f"All premium packs in host: {server.internal_ip} are valid")
        if not paid_packs_are_identical:
            exit_code = 1
    else:
        logging.critical(f"Missing all premium packs in host: {server.internal_ip}")
        exit_code = 1

    # Deleting GCS PATH before exit
    if os.path.exists(options.service_account):
        os.remove(options.service_account)
    sys.exit(exit_code)
Exemple #2
0
def verify_outer_contains_inner(inner_packs: list, outer_packs: list,
                                inner_packs_name: str,
                                outer_packs_name: str) -> bool:
    """Verify inner_packs are all inside outer_packs.

    Args:
        inner_packs: List of packs to verify.
        outer_packs: List of packs to verify from.
        inner_packs_name: Name of inner packs for better logging.
        outer_packs_name: Name of outer packs for better logging.

    Returns: True if all inner_packs are inside, false otherwise.
    """
    missing_packs = []
    for inner_pack in inner_packs:
        pack_inside = verify_pack_in_list(inner_pack, outer_packs,
                                          outer_packs_name)
        if not pack_inside:
            missing_packs.append({
                "id": inner_pack["id"],
                "price": inner_pack["price"]
            })

    return log_message_if_statement(
        statement=(len(missing_packs) == 0),
        error_message=f"The following {inner_packs_name} were"
        f" not found exactly the same as in the {outer_packs_name}:"
        f" \n{pformat(missing_packs)}")
Exemple #3
0
def verify_pack_in_list(pack: dict, pack_list: list, pack_list_name: str = "pack list") -> bool:
    """Verify pack is in the pack list with same id and price.

    Args:
        pack: (Dict) pack containing an id and a price.
        pack_list: (List[Dict]) list of packs containing id and a price.
        pack_list_name: Name of the list for better logs.

    Returns: True if pack is in list, False otherwise.
    """
    for pack_from_list in pack_list:
        if pack["id"] == pack_from_list["id"]:
            price_matches = log_message_if_statement(statement=(pack["price"] == pack_from_list["price"]),
                                                     error_message=f'Price in pack {pack["id"]} does not match the'
                                                                   f' price in the list. '
                                                                   f'{pack["price"]} != {pack_from_list["price"]}',
                                                     success_message=f'Pack {pack["id"]} is valid.')
            return price_matches

    logging.error(f'Pack {pack["id"]} is not in {pack_list_name}')
    return False