taler-deployment

Deployment scripts and configuration files
Log | Files | Refs | README

commit ec3b3853b9e60567ccbba5fc76dd5a27d292b465
parent 1c1882619c05eb5f48e0e78001e263d0c9814fd8
Author: ms <ms@taler.net>
Date:   Thu,  1 Jul 2021 15:01:57 +0200

checking tip money is allocated

Diffstat:
Abuildbot/check_tip_reserve.py | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abuildbot/check_tip_reserve.sh | 7+++++++
Mbuildbot/master.cfg | 37+++++++++++++++++++++++++++++++++++++
3 files changed, 131 insertions(+), 0 deletions(-)

diff --git a/buildbot/check_tip_reserve.py b/buildbot/check_tip_reserve.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python3 + +""" +This script makes sure that the merchant backend instances used by the +test/demo environment are created. + +We assume that the merchant backend is running, and that the "~/activate" +file has been sourced to provide the right environment variables. +""" + +import requests +from os import environ +from sys import exit +from urllib.parse import urljoin +from taler.util.amount import Amount + +def expect_env(name): + val = environ.get(name) + if not val: + print(f"{name} not defined. Please source the ~/activate file.") + exit(1) + return val + +def wait_merchant_up(): + # Check it started correctly and it is ready to serve requests. + checks = 10 + url = urljoin(MERCHANT_BACKEND_BASE_URL, "/config") + print("Check URL: {}".format(url)) + while checks > 0: + + try: + resp = requests.get(url, timeout=1.5) + except Exception: + print("Merchant unreachable") + sleep(1) + checks -= 1 + continue + + if resp.status_code != 200: + sleep(1) + checks -= 1 + continue + + # Ready. + print("Merchant is up and running") + return True + + if checks == 0: + print("Merchant is not correctly serving requests.") + return False + + +MERCHANT_BACKEND_BASE_URL = expect_env("TALER_ENV_MERCHANT_BACKEND") +TALER_ENV_NAME = expect_env("TALER_ENV_NAME") +TALER_CONFIG_CURRENCY = expect_env("TALER_CONFIG_CURRENCY") +TALER_ENV_FRONTENDS_APITOKEN = expect_env("TALER_ENV_FRONTENDS_APITOKEN") +authorization_header = {"Authorization": f"Bearer {TALER_ENV_FRONTENDS_APITOKEN}"} + +def request_tip_reserves(): + resp = requests.get( + urljoin(MERCHANT_BACKEND_BASE_URL, + "instances/survey/private/reserves"), + headers = authorization_header + ) + + # Instance exists, we PATCH the auth just in case it changed. + if resp.status_code != 200: + report("merchant backend failed at providing a list of tip reserves!") + sys.exit(1) + + reserves = resp.json().get("reserves") + + if len(reserves) == 0: + report("merchant backend has NO tip reserves active!") + sys.exit(1) + + total_amount = Amount.parse(reserves[0].get("committed_amount") + for item in reserves[1:]: + item_amount = Amount.parse(item.get("committed_amount")) + total_amount += item_amount + + if total_amount.is_zero(): + report("tip money reached zero") + sys.exit(1) + + # FIXME, eventually, just check the largest amount left through + # all the reserves. diff --git a/buildbot/check_tip_reserve.sh b/buildbot/check_tip_reserve.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# Step for the BUILD_FACTORY running the 'test.taler.net' site. +set -eu + +source "${HOME}/activate" +./check_tip_reserve.py diff --git a/buildbot/master.cfg b/buildbot/master.cfg @@ -54,6 +54,23 @@ WORKERS = [] # targets. The status of each build will be pushed to these # targets. buildbot/reporters/*.py has a variety to choose from, # like IRC bots. + +tipReserveEmails = reporters.MailNotifier( + fromaddr="buildbot@taler.net", # to be sent to a dedicate alias + sendToInterestedUsers=False, + mode=("always"), + builders=("check-tips-builder"), + extraRecipients=["tips@taler.net"], + dumpMailsToLog=True, # debug, to remove + messageFormatter=reporters.MessageFormatter( + wantSteps=True, + wantLogs=True, + template="""{% for step in build['steps'] %} + {{ step['logs'] }} + {% endfor %}""", # usually one step + subject="tips availability on demo") +) + SERVICES = [] # The 'builders' list defines the Builders, which tell Buildbot @@ -757,6 +774,7 @@ SERVICES.append(reporters.MailNotifier( useTls=True, extraRecipients=['linkcheck@taler.net'] )) +SERVICES.append(tipReserveEmails) NIGHTLY_TRIGGERS.append("linkchecker-builder") @@ -866,6 +884,20 @@ CODECHANGE_TRIGGERS.append("codespell-builder") # 'demo' deployment are up&running. WORKERS.append(worker.Worker("demo-worker", "demo-pass")) +DEMO_CHECK_TIPS_FACTORY = create_factory_with_deployment() +DEMO_CHECK_TIPS_FACTORY.addStep( + ShellCommand( + name="demo tip reserves checker", + description="Checking that demo allocated tip money", + descriptionDone="Demo can tip visitors!.", + command=["./check_tip_reserve.sh"], + workdir="../../deployment/buildbot", + haltOnFailure=True, + # Needed to test the 'demo' deployment. + env={"DEPLOYMENT": "demo"} + ) +) + DEMO_SERVICES_INTEGRATIONTEST_FACTORY = create_factory_with_deployment() DEMO_SERVICES_INTEGRATIONTEST_FACTORY.addStep( ShellCommand( @@ -884,6 +916,11 @@ BUILDERS.append(util.BuilderConfig( workernames="demo-worker", factory=DEMO_SERVICES_INTEGRATIONTEST_FACTORY )) +BUILDERS.append(util.BuilderConfig( + name="check-tips-builder", + workernames="demo-worker", + factory=DEMO_CHECK_TIPS_FACTORY +)) EMAIL_ALERTS.append("demo-services-checker-builder") # We check demo once per hour.