taler-deployment

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

commit a326dd208c45aadf67c0083756ba01fa4239bd8e
parent 13b78b19d974c5263a712bfe46153c9de9d68c56
Author: ms <ms@taler.net>
Date:   Thu,  1 Jul 2021 17:49:34 +0200

fix syntax errors

Diffstat:
Mbuildbot/check_tip_reserve.py | 88+++++++++++++++++++++++++------------------------------------------------------
1 file changed, 28 insertions(+), 60 deletions(-)

diff --git a/buildbot/check_tip_reserve.py b/buildbot/check_tip_reserve.py @@ -21,67 +21,35 @@ def expect_env(name): 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. +resp = requests.get( + urljoin(MERCHANT_BACKEND_BASE_URL, + "instances/survey/private/reserves"), + headers = {"Authorization": f"Bearer {TALER_ENV_FRONTENDS_APITOKEN}"} +) + +# Instance exists, we PATCH the auth just in case it changed. +if resp.status_code != 200: + print("merchant backend failed at providing a list of tip reserves!") + exit(1) + +reserves = resp.json().get("reserves") +if len(reserves) == 0: + print("merchant backend has NO tip reserves active!") + 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(): + print("tip money reached zero") + exit(1) + +# FIXME, eventually, just check the largest amount left through +# all the reserves. +print(f"Tip money is available: {total_amount}")