Example #1
0
def install_private_testing_pack(build: Build, test_pack_zip_path: str):
    """
    Creates and installs the test pack used in the private build. This pack contains the test
    playbooks and test scripts that will be used for the tests.

    :param build: Build object containing the build settings.
    :param test_pack_zip_path: Path to test_pack zip.
    :return: No object is returned. concurrently_run_function_on_servers will wait for the process to finish.
    """
    build.concurrently_run_function_on_servers(function=upload_zipped_packs,
                                               pack_path=test_pack_zip_path)
Example #2
0
def main():
    install_logging('Install_Packs.log')
    options = options_handler()

    # Get the host by the ami env
    hosts, _ = Build.get_servers(ami_env=options.ami_env)

    logging.info('Retrieving the credentials for Cortex XSOAR server')
    secret_conf_file = get_json_file(path=options.secret)
    username: str = secret_conf_file.get('username')
    password: str = secret_conf_file.get('userPassword')

    # Configure the Servers
    for host in hosts:
        server = Server(host=host, user_name=username, password=password)
        logging.info(f'Adding Marketplace configuration to {host}')
        error_msg: str = 'Failed to set marketplace configuration.'
        server.add_server_configuration(config_dict=MARKET_PLACE_CONFIGURATION, error_msg=error_msg)
        set_marketplace_url(servers=[server], branch_name=options.branch, ci_build_number=options.build_number)

        # Acquire the server's host and install all content packs (one threaded execution)
        logging.info(f'Starting to install all content packs in {host}')
        server_host: str = server.client.api_client.configuration.host
        install_all_content_packs(client=server.client, host=server_host)
        logging.success(f'Finished installing all content packs in {host}')
Example #3
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)
def main():
    build = Build(options_handler())
    prints_manager = ParallelPrintsManager(1)

    configure_servers_and_restart(build, prints_manager)
    #  Get a list of the test we need to run.
    tests_for_iteration = get_tests(build.server_numeric_version,
                                    prints_manager, build.tests)
    #  Installing the packs.
    installed_content_packs_successfully = install_packs_private(
        build, prints_manager)
    #  Get a list of the integrations that have changed.
    new_integrations, modified_integrations = get_changed_integrations(
        build, prints_manager)
    #  Configuring the instances which are used in testing.
    all_module_instances, brand_new_integrations = \
        configure_server_instances(build, tests_for_iteration, new_integrations,
                                   modified_integrations, prints_manager)

    #  Running the instance tests (pushing the test button)
    successful_tests_pre, failed_tests_pre = instance_testing(
        build, all_module_instances, prints_manager, pre_update=True)
    #  Adding the new integrations to the instance test list and testing them.
    all_module_instances.extend(brand_new_integrations)
    successful_tests_post, failed_tests_post = instance_testing(
        build, all_module_instances, prints_manager, pre_update=False)
    #  Done running tests so we are disabling the instances.
    disable_instances(build, all_module_instances, prints_manager)
    #  Gather tests to add to test pack
    test_playbooks_from_id_set = build.id_set.get('TestPlaybooks', [])
    tests_to_add_to_test_pack = find_needed_test_playbook_paths(
        test_playbooks=test_playbooks_from_id_set,
        tests_to_run=build.tests_to_run,
        path_to_content=build.content_root)
    #  Write the test pack
    private_content_test_zip = write_test_pack_zip(
        zip_destination_dir=build.test_pack_path,
        tests_file_paths=tests_to_add_to_test_pack,
        path_to_content=build.content_root)
    # Create and install private test pack
    install_private_testing_pack(build, prints_manager,
                                 private_content_test_zip)

    success = report_tests_status(failed_tests_pre, failed_tests_post,
                                  successful_tests_pre, successful_tests_post,
                                  new_integrations, prints_manager)
    sleep(30)
    if not success or not installed_content_packs_successfully:
        sys.exit(2)
Example #5
0
def main():
    install_logging('Install_Packs.log', logger=logging)
    options = options_handler()

    # Get the host by the ami env
    server_to_port_mapping, server_version = Build.get_servers(
        ami_env=options.ami_env)

    logging.info('Retrieving the credentials for Cortex XSOAR server')
    secret_conf_file = get_json(file_path=options.secret)
    username: str = secret_conf_file.get('username')
    password: str = secret_conf_file.get('userPassword')
    branch_name: str = options.branch
    build_number: str = options.build_number

    # Configure the Servers
    for server_url, port in server_to_port_mapping.items():
        server = Server(internal_ip=server_url,
                        port=port,
                        user_name=username,
                        password=password)
        logging.info(f'Adding Marketplace configuration to {server_url}')
        error_msg: str = 'Failed to set marketplace configuration.'
        server.add_server_configuration(config_dict=MARKET_PLACE_CONFIGURATION,
                                        error_msg=error_msg)
        set_marketplace_url(servers=[server],
                            branch_name=branch_name,
                            ci_build_number=build_number)

        # Acquire the server's host and install all content packs (one threaded execution)
        logging.info(f'Starting to install all content packs in {server_url}')
        server_host: str = server.client.api_client.configuration.host
        success_flag = install_all_content_packs_from_build_bucket(
            client=server.client,
            host=server_host,
            server_version=server_version,
            bucket_packs_root_path=GCPConfig.
            BUILD_BUCKET_PACKS_ROOT_PATH.format(branch=branch_name,
                                                build=build_number,
                                                marketplace='xsoar'),
            service_account=options.service_account,
            extract_destination_path=options.extract_path)

        if success_flag:
            logging.success(
                f'Finished installing all content packs in {server_url}')
        else:
            logging.error('Failed to install all packs.')
            sys.exit(1)
Example #6
0
def install_packs_from_content_packs_to_install_path(servers,
                                                     pack_ids_to_install_path,
                                                     hostname=''):
    """
    Install pack_ids from "$ARTIFACTS_FOLDER/content_packs_to_install.txt" file, and packs dependencies.
    Args:
        hostname:
        pack_ids_to_install_path: "$ARTIFACTS_FOLDER/content_packs_to_install.txt" path
        servers: XSIAM or XSOAR Servers to install packs on it.
    """
    pack_ids = Build.fetch_pack_ids_to_install(pack_ids_to_install_path)
    for server in servers:
        logging.info(
            f'Starting to install all content packs in {hostname if hostname else server.internal_ip}'
        )
        _, success = search_and_install_packs_and_their_dependencies(
            pack_ids, server.client, hostname)
        if not success:
            raise Exception(
                'Failed to search and install packs and their dependencies.')