Merge ~peter-sabaini/charm-grafana:fix-create-user into charm-grafana:master

Proposed by Peter Sabaini
Status: Merged
Approved by: Alvaro Uria
Approved revision: 65093fd38bb6f43ae49b30f5acda0cbf58bb375b
Merged at revision: b1ef22aab6285084ee2af7314ccfd6699225124a
Proposed branch: ~peter-sabaini/charm-grafana:fix-create-user
Merge into: charm-grafana:master
Diff against target: 83 lines (+44/-6)
2 files modified
actions/create-user (+1/-2)
tests/functional/test_deploy.py (+43/-4)
Reviewer Review Type Date Requested Status
Alvaro Uria (community) Approve
Wouter van Bommel (community) Approve
Review via email: mp+382423@code.launchpad.net

Commit message

Fix create-user action

Closes-Bug: #1868869

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Wouter van Bommel (woutervb) wrote :

lgtm, ideally you would also test that the created account can also login

review: Approve
Revision history for this message
Alvaro Uria (aluria) wrote :

lgtm

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision b1ef22aab6285084ee2af7314ccfd6699225124a

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/actions/create-user b/actions/create-user
2index 7abd043..728c994 100755
3--- a/actions/create-user
4+++ b/actions/create-user
5@@ -97,8 +97,7 @@ else:
6 sys.exit(0)
7
8 if r_org.status_code == 200:
9- org_data = r_org.json
10- org_id = org_data['id']
11+ org_data = r_org.json()
12 org_name = org_data['name']
13 org_user_data = '''{
14 "role": %s,
15diff --git a/tests/functional/test_deploy.py b/tests/functional/test_deploy.py
16index 11447b7..5b18eab 100644
17--- a/tests/functional/test_deploy.py
18+++ b/tests/functional/test_deploy.py
19@@ -14,9 +14,16 @@ pytestmark = pytest.mark.asyncio
20 OPENSTACK_TIMEOUT = 3600
21 APP_TIMEOUT = 900
22
23-CHARM_BUILD_DIR = os.getenv('JUJU_REPOSITORY', '/tmp/charm-builds/grafana').rstrip('/')
24-BUNDLE_PATH = os.path.join(CHARM_BUILD_DIR, "..", "bundle.yaml")
25-OVERLAY_PATH = os.path.join(CHARM_BUILD_DIR, "..", "overlay.yaml")
26+CHARM_BUILD_DIR = os.getenv('CHARM_BUILD_DIR')
27+JUJU_REPOSITORY = os.getenv('JUJU_REPOSITORY')
28+if CHARM_BUILD_DIR is not None:
29+ GRAFANA_BUILD_DIR = os.path.join(CHARM_BUILD_DIR.rstrip('/'), "grafana")
30+elif JUJU_REPOSITORY is not None:
31+ GRAFANA_BUILD_DIR = os.path.join(JUJU_REPOSITORY.rstrip('/'), "builds", "grafana")
32+else:
33+ GRAFANA_BUILD_DIR = "/tmp/charm-builds/grafana"
34+BUNDLE_PATH = os.path.join(GRAFANA_BUILD_DIR, "..", "bundle.yaml")
35+OVERLAY_PATH = os.path.join(GRAFANA_BUILD_DIR, "..", "overlay.yaml")
36
37 APP_SERIES = [
38 "xenial",
39@@ -133,7 +140,7 @@ async def deploy_app(request, model):
40 'appname': app_name,
41 'series': series,
42 'install_method': install_method,
43- 'charm_path': CHARM_BUILD_DIR,
44+ 'charm_path': GRAFANA_BUILD_DIR,
45 'openstack_origin': OPENSTACK_VERSIONS[ubuntu_os_version],
46 }
47 # render bundle config file
48@@ -236,3 +243,35 @@ async def test_grafana_imported_dashboards(deploy_app, model):
49 assert req.status_code == 200
50
51 assert len(units) > 0
52+
53+
54+async def test_grafana_create_user(deploy_app, model):
55+ config = await deploy_app.get_config()
56+ install_method = config['install_method']['value']
57+ if install_method == FAKE_INSTALL_METHOD:
58+ status = 'blocked'
59+ message = 'Unsupported install_method'
60+ else:
61+ status = 'active'
62+ message = INSTALL_METHOD[install_method].get("message")
63+
64+ units = deploy_app.units
65+ for grafana_unit in units:
66+ await model.block_until(lambda: (grafana_unit.workload_status == status
67+ and grafana_unit.agent_status == 'idle'
68+ and grafana_unit.workload_status_message == message),
69+ timeout=APP_TIMEOUT)
70+ if install_method == FAKE_INSTALL_METHOD:
71+ # no further checks
72+ continue
73+ action = await grafana_unit.run_action("create-user", name="FooUser", login="foouser", email="foo@example.com",
74+ password="sikkrit", role="Viewer")
75+ action = await action.wait()
76+ assert action.results["Code"] == '0'
77+ port = config['port']['value']
78+ host = grafana_unit.public_address
79+ req = requests.get('http://{host}:{port}/api/org/'.format(host=host, port=port),
80+ auth=('foouser', 'sikkrit'))
81+ assert req.status_code == 200
82+ assert 'name' in req.json()
83+ assert len(units) > 0

Subscribers

People subscribed via source and target branches

to all changes: