Squashed 'modules/libjuju/' changes from c50c361..c127833
c127833 Bump version and changelog for release
6aff679 k8s bundles no longer have application placement (#293)
1de9ad1 Add retry for connection if all endpoints fail (#288)
8cb8d75 Support generation of registration string for model sharing. (#279)
a9e2fd6 Add Twine for dist upload on release (#284)
407a6a6 Update and prepare for 0.11.2 release (#282)
d102620 call related update credential cloud facade methods based on facade version (#281)
2acbdc4 Add test case for redirect during connect (#275)
35fb43e Implement App.get_resources and pinned resources in bundles (#278)
b5ba51a Bump version and changelog for release
7a73a0a Fix bundles with subordinates for Juju <2.5 (#277)
a0f950f Bump version and changelog for release
01125e2 Updates for new Juju version (#274)
87d9388 Fix wrong variable name in revoke_model function (#271)
2b43065 Bump version and changelog for release
98ee524 set include_stats to false to reduce request time (#266)
61e1d69 Update version and changelog for 0.10.1
82f9968 Retry ssh in manual provision test (#265)
d64bfff Clean up lint and add lint coverage to travis config (#263)
c7c5c54 Increase the timeout for charmstore connections (#262)
4a6e398 Fix log level of `Driver connected to juju` message (#258)
514e479 Update version and changelog for 0.10.0
ec2c493 Reorder scp parameters (#259) (#260)
26c86c8 Implement set/get model constraints (#253)
c6b4ab4 Update version and changelog for 0.9.1
e863746 Update websockets to 6.0 (#254)
567bc1a Update version and changelog for 0.9.0
b275ced python3.7 compatibility updates (#251)
bc7336a Handle juju not installed in is_bootstrapped. (#250)
1ce8e0b Add app.reset_config(list). (#249)
c620d4f Implement model.get_action_status (#248)
96ea3c4 Fix `make client` in Python 3.6 (#247)
61969ea Update version and changelog for release
ebf6882 Add support for adding a manual (ssh) machine (#240)
18422f4 Backwards compatibility fixes (#213)
40c0211 Implement model.get_action_output (#242)
c6b8ac5 Fix JSON serialization error for bundle with lxd to unit placement (#243)
5014fc3 Fix reference in docs to connect_current (#239)
ebe0193 Wrap machine agent status workaround in version check (#238)
462989b Convert seconds to nanoseconds for juju.unit.run (#237)
0f413e6 Fix spurious intermittent failure in test_machines.py::test_status (#236)
ce36b60 Define an unused juju-zfs lxd storage pool (#235)
dfc2e8d Add support for Application get_actions (#234)
e7e8c13 Update version and changelog for release
499337b Surface errors from bundle plan (#233)
2d94186 Always send auth-tag even with macaroon auth (#217)
000355c Inline jsonfile credential when sending to controller (#231)
9805123 Bump VERSION and changelog for release
27d723b Always parse tags and spaces constraints to lists (#228)
668945a Doc index improvements (#211)
65e6b5e Add doc req to force newer pymacaroons to fix RTD builds
e2abd47 Fix dependency conflict for building docs
2907a6e Bump VERSION and changelog for 0.7.3 release
37a7500 Full macaroon bakery support (#206)
a06e313 Fix regression with deploying local charm, add test case (#209)
75e9a2b Expose a machines series (#208)
46c98f5 Revert non-functional switch to Py3.6, just specify Py3 instead (#205)
8a99ad1 Cherry-pick VERSION and changelog bump from 0.7.2 release branch
88121d6 Support deploying bundle YAML file directly (rather than just directory) (#202)
57c0dbf Cherry-pick #197 into master (#198)
0973edc Update VERSION and changelog for 0.7.0
f5a4108 Add deprecated placeholder for Controller.get_models
17dffa4 JujuData abstract base class (#194)
76f22cc Make Model and Controller connect methods backwardly compatible (#196)
19b5658 Fix race condition in adding relations (#192)
978f35c refactor connections prior to bakery authentication (#187)
77c0f04 sort all imports; lint tests (#188)
4740935 juju.client.gocookies: new module (#186)
2c4de22 all: use pyrfc3339 instead of dateutil (#185)
7133ffe juju/client: factor out JujuData class (#182)
476b832 Fix race condition in connection monitor test (#183)
e64a5d1 Fix example in README (#178)
97355cc Fix rare hang during Unit.run (#177)
ae0b091 #176: Fix licensing quirks
c0d001b Refactor model handling (#171)
ab807c8 Refactor users handling, add get_users (#170)
5270db5 Upload credential to controller when adding model (#168)
16d8390 Support 'applications' key in bundles (#165)
2de3eed Improve handling of thread error handling for loop.run() (#169)
7807023 Fix encoding when using to_json() (#166)
73effb1 Fix intermittent test failures (#167)
46da148 Update VERSION and changelog for release
3dda1dc Fix test failures (#163)
14392af removing cli command to add ssh keys (#161)
ce68170 Make Application.upgrade_charm upgrade resources (#158)
git-subtree-dir: modules/libjuju
git-subtree-split: c12783304945fdff5c28397b82b535a9cc065ca3
diff --git a/tests/integration/test_controller.py b/tests/integration/test_controller.py
index f3840cc..6423a98 100644
--- a/tests/integration/test_controller.py
+++ b/tests/integration/test_controller.py
@@ -1,20 +1,35 @@
-import pytest
+import asyncio
+import subprocess
import uuid
-from .. import base
+from juju.client.connection import Connection
+from juju.client.jujudata import FileJujuData
from juju.controller import Controller
from juju.errors import JujuAPIError
+import pytest
+
+from .. import base
+
@base.bootstrapped
@pytest.mark.asyncio
-async def test_add_user(event_loop):
+async def test_add_remove_user(event_loop):
async with base.CleanController() as controller:
username = 'test{}'.format(uuid.uuid4())
- await controller.add_user(username)
- result = await controller.get_user(username)
- res_ser = result.serialize()['results'][0].serialize()
- assert res_ser['result'] is not None
+ user = await controller.get_user(username)
+ assert user is None
+ user = await controller.add_user(username)
+ assert user is not None
+ assert user.secret_key is not None
+ assert user.username == username
+ users = await controller.get_users()
+ assert any(u.username == username for u in users)
+ await controller.remove_user(username)
+ user = await controller.get_user(username)
+ assert user is None
+ users = await controller.get_users()
+ assert not any(u.username == username for u in users)
@base.bootstrapped
@@ -22,15 +37,23 @@
async def test_disable_enable_user(event_loop):
async with base.CleanController() as controller:
username = 'test-disable{}'.format(uuid.uuid4())
- await controller.add_user(username)
- await controller.disable_user(username)
- result = await controller.get_user(username)
- res_ser = result.serialize()['results'][0].serialize()
- assert res_ser['result'].serialize()['disabled'] is True
- await controller.enable_user(username)
- result = await controller.get_user(username)
- res_ser = result.serialize()['results'][0].serialize()
- assert res_ser['result'].serialize()['disabled'] is False
+ user = await controller.add_user(username)
+
+ await user.disable()
+ assert not user.enabled
+ assert user.disabled
+
+ fresh = await controller.get_user(username) # fetch fresh copy
+ assert not fresh.enabled
+ assert fresh.disabled
+
+ await user.enable()
+ assert user.enabled
+ assert not user.disabled
+
+ fresh = await controller.get_user(username) # fetch fresh copy
+ assert fresh.enabled
+ assert not fresh.disabled
@base.bootstrapped
@@ -38,40 +61,168 @@
async def test_change_user_password(event_loop):
async with base.CleanController() as controller:
username = 'test-password{}'.format(uuid.uuid4())
- await controller.add_user(username)
- await controller.change_user_password(username, 'password')
+ user = await controller.add_user(username)
+ await user.set_password('password')
+ # Check that we can connect with the new password.
+ new_connection = None
try:
- new_controller = Controller()
- await new_controller.connect(
- controller.connection.endpoint, username, 'password')
- result = True
- await new_controller.disconnect()
+ kwargs = controller.connection().connect_params()
+ kwargs['username'] = username
+ kwargs['password'] = 'password'
+ new_connection = await Connection.connect(**kwargs)
except JujuAPIError:
- result = False
- assert result is True
+ raise AssertionError('Unable to connect with new password')
+ finally:
+ if new_connection:
+ await new_connection.close()
@base.bootstrapped
@pytest.mark.asyncio
-async def test_grant(event_loop):
+async def test_reset_user_password(event_loop):
+ async with base.CleanController() as controller:
+ username = 'test{}'.format(uuid.uuid4())
+ user = await controller.add_user(username)
+ origin_secret_key = user.secret_key
+ await user.set_password('password')
+ await controller.reset_user_password(username)
+ user = await controller.get_user(username)
+ new_secret_key = user.secret_key
+ # Check secret key is different after the reset.
+ assert origin_secret_key != new_secret_key
+ # Check that we can't connect with the old password.
+ new_connection = None
+ try:
+ kwargs = controller.connection().connect_params()
+ kwargs['username'] = username
+ kwargs['password'] = 'password'
+ new_connection = await Connection.connect(**kwargs)
+ except JujuAPIError:
+ pass
+ finally:
+ # No connection with old password
+ assert new_connection is None
+
+
+@base.bootstrapped
+@pytest.mark.asyncio
+async def test_grant_revoke(event_loop):
async with base.CleanController() as controller:
username = 'test-grant{}'.format(uuid.uuid4())
- await controller.add_user(username)
- await controller.grant(username, 'superuser')
- result = await controller.get_user(username)
- result = result.serialize()['results'][0].serialize()['result']\
- .serialize()
- assert result['access'] == 'superuser'
- await controller.grant(username, 'login')
- result = await controller.get_user(username)
- result = result.serialize()['results'][0].serialize()['result']\
- .serialize()
- assert result['access'] == 'login'
+ user = await controller.add_user(username)
+ await user.grant('superuser')
+ assert user.access == 'superuser'
+ fresh = await controller.get_user(username) # fetch fresh copy
+ assert fresh.access == 'superuser'
+ await user.grant('login') # already has 'superuser', so no-op
+ assert user.access == 'superuser'
+ fresh = await controller.get_user(username) # fetch fresh copy
+ assert fresh.access == 'superuser'
+ await user.revoke()
+ assert user.access == ''
+ fresh = await controller.get_user(username) # fetch fresh copy
+ assert fresh.access == ''
@base.bootstrapped
@pytest.mark.asyncio
-async def test_get_models(event_loop):
+async def test_list_models(event_loop):
async with base.CleanController() as controller:
- result = await controller.get_models()
- assert isinstance(result.serialize()['user-models'], list)
+ async with base.CleanModel() as model:
+ result = await controller.list_models()
+ assert model.info.name in result
+
+
+@base.bootstrapped
+@pytest.mark.asyncio
+async def test_get_model(event_loop):
+ async with base.CleanController() as controller:
+ by_name, by_uuid = None, None
+ model_name = 'test-{}'.format(uuid.uuid4())
+ model = await controller.add_model(model_name)
+ model_uuid = model.info.uuid
+ await model.disconnect()
+ try:
+ by_name = await controller.get_model(model_name)
+ by_uuid = await controller.get_model(model_uuid)
+ assert by_name.info.name == model_name
+ assert by_name.info.uuid == model_uuid
+ assert by_uuid.info.name == model_name
+ assert by_uuid.info.uuid == model_uuid
+ finally:
+ if by_name:
+ await by_name.disconnect()
+ if by_uuid:
+ await by_uuid.disconnect()
+ await controller.destroy_model(model_name)
+
+
+async def _wait_for_model(controller, model_name):
+ while model_name not in await controller.list_models():
+ await asyncio.sleep(0.5, loop=controller.loop)
+
+
+async def _wait_for_model_gone(controller, model_name):
+ while model_name in await controller.list_models():
+ await asyncio.sleep(0.5, loop=controller.loop)
+
+
+@base.bootstrapped
+@pytest.mark.asyncio
+async def test_destroy_model_by_name(event_loop):
+ async with base.CleanController() as controller:
+ model_name = 'test-{}'.format(uuid.uuid4())
+ model = await controller.add_model(model_name)
+ await model.disconnect()
+ await asyncio.wait_for(_wait_for_model(controller,
+ model_name),
+ timeout=60)
+ await controller.destroy_model(model_name)
+ await asyncio.wait_for(_wait_for_model_gone(controller,
+ model_name),
+ timeout=60)
+
+
+@base.bootstrapped
+@pytest.mark.asyncio
+async def test_add_destroy_model_by_uuid(event_loop):
+ async with base.CleanController() as controller:
+ model_name = 'test-{}'.format(uuid.uuid4())
+ model = await controller.add_model(model_name)
+ model_uuid = model.info.uuid
+ await model.disconnect()
+ await asyncio.wait_for(_wait_for_model(controller,
+ model_name),
+ timeout=60)
+ await controller.destroy_model(model_uuid)
+ await asyncio.wait_for(_wait_for_model_gone(controller,
+ model_name),
+ timeout=60)
+
+
+# this test must be run serially because it modifies the login password
+@pytest.mark.serial
+@base.bootstrapped
+@pytest.mark.asyncio
+async def test_macaroon_auth(event_loop):
+ jujudata = FileJujuData()
+ account = jujudata.accounts()[jujudata.current_controller()]
+ with base.patch_file('~/.local/share/juju/accounts.yaml'):
+ if 'password' in account:
+ # force macaroon auth by "changing" password to current password
+ result = subprocess.run(
+ ['juju', 'change-user-password'],
+ input='{0}\n{0}\n'.format(account['password']),
+ universal_newlines=True,
+ stderr=subprocess.PIPE)
+ assert result.returncode == 0, ('Failed to change password: '
+ '{}'.format(result.stderr))
+ controller = Controller()
+ try:
+ await controller.connect()
+ assert controller.is_connected()
+ finally:
+ if controller.is_connected():
+ await controller.disconnect()
+ async with base.CleanModel():
+ pass # create and login to model works