FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Trust example and integration tests · VariableDeclared/python-libjuju@38568a2 · GitHub

Repository navigation

Commit 38568a2

Browse files
Trust example and integration tests
1 parent d446661 commit 38568a2

4 files changed

Lines changed: 85 additions & 24 deletions

File tree

‎examples/deploy_bundle.py‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
This example:
3+
4+
1. Connects to the current model
5+
2. Deploy a bundle and waits until it reports itself active
6+
3. Destroys the units and applications
7+
8+
"""
9+
import asyncio
10+
11+
from juju import loop
12+
from juju.model import Model
13+
14+
15+
async def main():
16+
model = Model()
17+
print('Connecting to model')
18+
# connect to current model with current user, per Juju CLI
19+
await model.connect()
20+
21+
try:
22+
print('Deploying bundle')
23+
applications = await model.deploy(
24+
'cs:~juju-qa/bundle/basic-0',
25+
series='xenial',
26+
channel='beta',
27+
)
28+
29+
print('Waiting for active')
30+
await model.block_until(
31+
lambda: all(unit.workload_status == 'active'
32+
for application in applications
33+
for unit in application.units))
34+
35+
print('Removing bundle')
36+
for application in applications:
37+
await application.remove()
38+
finally:
39+
print('Disconnecting from model')
40+
await model.disconnect()
41+
42+
43+
if __name__ == '__main__':
44+
loop.run(main())
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
1. Connects to the current model
55
2. Deploy a bundle with trust and waits until it reports itself active
6-
3. Destroys the unit and application
6+
3. Destroys the units and applications
77
88
"""
99
from juju import loop
@@ -19,12 +19,11 @@ async def main():
1919
try:
2020
print('Deploying trusted bundle')
2121
applications = await model.deploy(
22-
'cs:~juju-qa/bundle/aws-integrator-trust-single-1',
23-
series='xenial',
22+
'cs:~juju-qa/bundle/basic-trusted-1',
23+
series='bionic',
2424
channel='beta',
2525
trust=True,
2626
)
27-
print("apps {}".format(applications))
2827

2928
print('Waiting for active')
3029
await model.block_until(
@@ -33,7 +32,8 @@ async def main():
3332
for unit in application.units))
3433

3534
print('Removing bundle')
36-
await (application.remove() for application in applications)
35+
for application in applications:
36+
await application.remove()
3737
finally:
3838
print('Disconnecting from model')
3939
await model.disconnect()

‎juju/model.py‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,22 @@ def __init__(self, model, trusted=False, forced=False):
19241924
self.ann_facade = client.AnnotationsFacade.from_connection(
19251925
model.connection())
19261926

1927+
async def _validate_bundle(self, bundle):
1928+
"""Validate the bundle for known issues, raises an error if it
1929+
encounters a known problem
1930+
"""
1931+
apps_dict = bundle.get('applications', bundle.get('services', {}))
1932+
for app_name in self.applications:
1933+
app_dict = apps_dict[app_name]
1934+
app_trusted = app_dict.get('trust')
1935+
if (not self.trusted and not self.forced) and app_trusted:
1936+
raise JujuError(
1937+
"Bundle cannot be deployed without trusting applications with your cloud credentials.\n"
1938+
"Please repeat the deploy command with the --trust argument if you consent to trust the following application\n"
1939+
" - {}\n".format(app_name)
1940+
)
1941+
return bundle
1942+
19271943
async def _handle_local_charms(self, bundle):
19281944
"""Search for references to local charms (i.e. filesystem paths)
19291945
in the bundle. Upload the local charms to the model, and replace
@@ -1953,14 +1969,6 @@ async def _handle_local_charms(self, bundle):
19531969
raise JujuError(
19541970
"Couldn't determine series for charm at {}. "
19551971
"Add a 'series' key to the bundle.".format(charm_dir))
1956-
1957-
app_trusted = app_dict.get('trust')
1958-
if (not self.trusted and not self.forced) and app_trusted:
1959-
raise JujuError(
1960-
"Bundle cannot be deployed without trusting applications with your cloud credentials. "
1961-
"Please repeat the deploy command with the --trust argument if you consent to trust the following application"
1962-
" - {}".format(app_name)
1963-
)
19641972
# Keep track of what we need to update. We keep a list of apps
19651973
# that need to be updated, and a corresponding list of args
19661974
# needed to update those apps.
@@ -1992,6 +2000,7 @@ async def fetch_plan(self, entity_id):
19922000
filename='bundle.yaml',
19932001
read_file=True)
19942002
self.bundle = yaml.safe_load(bundle_yaml)
2003+
self.bundle = await self._validate_bundle(self.bundle)
19952004
self.bundle = await self._handle_local_charms(self.bundle)
19962005

19972006
self.plan = await self.bundle_facade.GetChanges(

‎tests/integration/test_model.py‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
import asyncio
2-
import mock
2+
import os
3+
import time
4+
import uuid
35
from concurrent.futures import ThreadPoolExecutor
46
from pathlib import Path
5-
import paramiko
67

7-
from juju.client.client import ConfigValue, ApplicationFacade
8-
from juju.model import Model, ModelObserver
9-
from juju.utils import block_until, run_with_interrupt
10-
from juju.errors import JujuError
8+
import mock
9+
import paramiko
1110

12-
import os
1311
import pylxd
14-
import time
15-
import uuid
16-
1712
import pytest
13+
from juju.client.client import ApplicationFacade, ConfigValue
14+
from juju.errors import JujuError
15+
from juju.model import Model, ModelObserver
16+
from juju.utils import block_until, run_with_interrupt
1817

1918
from .. import base
2019

21-
2220
MB = 1
2321
GB = 1024
2422
SSH_KEY = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCsYMJGNGG74HAJha3n2CFmWYsOOaORnJK6VqNy86pj0MIpvRXBzFzVy09uPQ66GOQhTEoJHEqE77VMui7+62AcMXT+GG7cFHcnU8XVQsGM6UirCcNyWNysfiEMoAdZScJf/GvoY87tMEszhZIUV37z8PUBx6twIqMdr31W1J0IaPa+sV6FEDadeLaNTvancDcHK1zuKsL39jzAg7+LYjKJfEfrsQP+lj/EQcjtKqlhVS5kzsJVfx8ZEd0xhW5G7N6bCdKNalS8mKCMaBXJpijNQ82AiyqCIDCRrre2To0/i7pTjRiL0U9f9mV3S4NJaQaokR050w/ZLySFf6F7joJT mathijs@Qrama-Mathijs' # noqa
@@ -93,6 +91,16 @@ async def test_deploy_bundle(event_loop):
9391
assert app in model.applications
9492

9593

94+
@base.bootstrapped
95+
@pytest.mark.asyncio
96+
async def test_deploy_trusted_bundle(event_loop):
97+
async with base.CleanModel() as model:
98+
await model.deploy('cs:~juju-qa/bundle/basic-trusted-1', trust=True)
99+
100+
for app in ('ubuntu', 'ubuntu-lite'):
101+
assert app in model.applications
102+
103+
96104
@base.bootstrapped
97105
@pytest.mark.asyncio
98106
async def test_deploy_channels_revs(event_loop):

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL