← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/rutabaga:charm-fix-proxy-check into rutabaga:master

 

Colin Watson has proposed merging ~cjwatson/rutabaga:charm-fix-proxy-check into rutabaga:master.

Commit message:
charm: Fix check_rutabaga_proxy to avoid double slashes

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/rutabaga/+git/rutabaga/+merge/441679

The default value of `api_url` is `"http://localhost:8080/"`.  This means that just appending `"/tokens"` to it results in `"http://localhost:8080//tokens"`, which 404s.  Use `urljoin` to avoid this problem.

Also tweak the charm's reactive handlers slightly so that Nagios checks are reinstalled when the charm is upgraded.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/rutabaga:charm-fix-proxy-check into rutabaga:master.
diff --git a/charm/rutabaga/reactive/rutabaga.py b/charm/rutabaga/reactive/rutabaga.py
index d355728..f717117 100644
--- a/charm/rutabaga/reactive/rutabaga.py
+++ b/charm/rutabaga/reactive/rutabaga.py
@@ -96,7 +96,7 @@ def nrpe_available():
 
 
 @when('rutabaga.nrpe-api-check.published')
-@when_not('nrpe-external-master.available')
+@when_not_all('nrpe-external-master.available', 'rutabaga.configured')
 def nrpe_unavailable():
     clear_flag('rutabaga.nrpe-api-check.published')
 
@@ -113,7 +113,10 @@ def nrpe_and_squid_available():
 
 
 @when('rutabaga.nrpe-proxy-check.published')
-@when_not_all('nrpe-external-master.available', 'squid.available')
+@when_not_all(
+    'nrpe-external-master.available',
+    'rutabaga.configured',
+    'squid.available')
 def nrpe_or_squid_unavailable():
     clear_flag('rutabaga.nrpe-proxy-check.published')
 
diff --git a/charm/rutabaga/scripts/nrpe/check_rutabaga_proxy b/charm/rutabaga/scripts/nrpe/check_rutabaga_proxy
index 158d270..5d0b6e2 100755
--- a/charm/rutabaga/scripts/nrpe/check_rutabaga_proxy
+++ b/charm/rutabaga/scripts/nrpe/check_rutabaga_proxy
@@ -5,14 +5,14 @@ import json
 from pathlib import Path
 from random import randint
 import sys
-from urllib.parse import urlparse
+from urllib.parse import urljoin, urlparse
 from time import sleep
 
 import requests
 
 
 def create_token(username, admin_username, admin_secret, api_url):
-    token_endpoint = f'{api_url}/tokens'
+    token_endpoint = urljoin(api_url, '/tokens')
     payload = json.dumps({'username': username})
     r = requests.post(
         token_endpoint, data=payload, auth=(admin_username, admin_secret))
@@ -29,7 +29,7 @@ def create_token(username, admin_username, admin_secret, api_url):
 
 
 def revoke_token(token, admin_username, admin_secret, api_url):
-    token_endpoint = f'{api_url}/tokens/{token["username"]}'
+    token_endpoint = urljoin(api_url, f'/tokens/{token["username"]}')
     r = requests.delete(token_endpoint, auth=(admin_username, admin_secret))
     return r.status_code == 200