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
diff --git a/actions/create-user b/actions/create-user
index 7abd043..728c994 100755
--- a/actions/create-user
+++ b/actions/create-user
@@ -97,8 +97,7 @@ else:
97 sys.exit(0)97 sys.exit(0)
9898
99if r_org.status_code == 200:99if r_org.status_code == 200:
100 org_data = r_org.json100 org_data = r_org.json()
101 org_id = org_data['id']
102 org_name = org_data['name']101 org_name = org_data['name']
103 org_user_data = '''{102 org_user_data = '''{
104"role": %s,103"role": %s,
diff --git a/tests/functional/test_deploy.py b/tests/functional/test_deploy.py
index 11447b7..5b18eab 100644
--- a/tests/functional/test_deploy.py
+++ b/tests/functional/test_deploy.py
@@ -14,9 +14,16 @@ pytestmark = pytest.mark.asyncio
14OPENSTACK_TIMEOUT = 360014OPENSTACK_TIMEOUT = 3600
15APP_TIMEOUT = 90015APP_TIMEOUT = 900
1616
17CHARM_BUILD_DIR = os.getenv('JUJU_REPOSITORY', '/tmp/charm-builds/grafana').rstrip('/')17CHARM_BUILD_DIR = os.getenv('CHARM_BUILD_DIR')
18BUNDLE_PATH = os.path.join(CHARM_BUILD_DIR, "..", "bundle.yaml")18JUJU_REPOSITORY = os.getenv('JUJU_REPOSITORY')
19OVERLAY_PATH = os.path.join(CHARM_BUILD_DIR, "..", "overlay.yaml")19if CHARM_BUILD_DIR is not None:
20 GRAFANA_BUILD_DIR = os.path.join(CHARM_BUILD_DIR.rstrip('/'), "grafana")
21elif JUJU_REPOSITORY is not None:
22 GRAFANA_BUILD_DIR = os.path.join(JUJU_REPOSITORY.rstrip('/'), "builds", "grafana")
23else:
24 GRAFANA_BUILD_DIR = "/tmp/charm-builds/grafana"
25BUNDLE_PATH = os.path.join(GRAFANA_BUILD_DIR, "..", "bundle.yaml")
26OVERLAY_PATH = os.path.join(GRAFANA_BUILD_DIR, "..", "overlay.yaml")
2027
21APP_SERIES = [28APP_SERIES = [
22 "xenial",29 "xenial",
@@ -133,7 +140,7 @@ async def deploy_app(request, model):
133 'appname': app_name,140 'appname': app_name,
134 'series': series,141 'series': series,
135 'install_method': install_method,142 'install_method': install_method,
136 'charm_path': CHARM_BUILD_DIR,143 'charm_path': GRAFANA_BUILD_DIR,
137 'openstack_origin': OPENSTACK_VERSIONS[ubuntu_os_version],144 'openstack_origin': OPENSTACK_VERSIONS[ubuntu_os_version],
138 }145 }
139 # render bundle config file146 # render bundle config file
@@ -236,3 +243,35 @@ async def test_grafana_imported_dashboards(deploy_app, model):
236 assert req.status_code == 200243 assert req.status_code == 200
237244
238 assert len(units) > 0245 assert len(units) > 0
246
247
248async def test_grafana_create_user(deploy_app, model):
249 config = await deploy_app.get_config()
250 install_method = config['install_method']['value']
251 if install_method == FAKE_INSTALL_METHOD:
252 status = 'blocked'
253 message = 'Unsupported install_method'
254 else:
255 status = 'active'
256 message = INSTALL_METHOD[install_method].get("message")
257
258 units = deploy_app.units
259 for grafana_unit in units:
260 await model.block_until(lambda: (grafana_unit.workload_status == status
261 and grafana_unit.agent_status == 'idle'
262 and grafana_unit.workload_status_message == message),
263 timeout=APP_TIMEOUT)
264 if install_method == FAKE_INSTALL_METHOD:
265 # no further checks
266 continue
267 action = await grafana_unit.run_action("create-user", name="FooUser", login="foouser", email="foo@example.com",
268 password="sikkrit", role="Viewer")
269 action = await action.wait()
270 assert action.results["Code"] == '0'
271 port = config['port']['value']
272 host = grafana_unit.public_address
273 req = requests.get('http://{host}:{port}/api/org/'.format(host=host, port=port),
274 auth=('foouser', 'sikkrit'))
275 assert req.status_code == 200
276 assert 'name' in req.json()
277 assert len(units) > 0

Subscribers

People subscribed via source and target branches

to all changes: