-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #957 from cderici/deploy-by-revision-2.9
#957 #### Description This backports the support for deploy by revision from master branch (3.x track) (#830) onto the 2.9 track. #### QA Steps So we have 1 example and 2 integration tests for this, all of them should work well (I tested it against 2.9.45 on lxd). ```sh $ python examples/deploywithrevision.py ``` ``` tox -e integration -- tests/integration/test_model.py::test_deploy_by_revision ``` ``` tox -e integration -- tests/integration/test_model.py::test_deploy_by_revision_validate_flags ``` All the rest of the CI tests need to pass. #### Notes & Discussion JUJU-4716
- Loading branch information
Showing
4 changed files
with
165 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/python3 | ||
|
||
# Copyright 2023 Canonical Ltd. | ||
# Licensed under the Apache V2, see LICENCE file for details. | ||
|
||
import asyncio | ||
import argparse | ||
import logging | ||
import sys | ||
|
||
# from juju import jasyncio | ||
import juju.model | ||
|
||
|
||
async def get_annotations(model, args): | ||
logging.info('getting annotations') | ||
annotations = await model.get_annotations() | ||
if args.key is None: | ||
for key, value in annotations.items(): | ||
print(f'{key}: {value!r}') | ||
else: | ||
value = annotations[args.key] | ||
print(value) | ||
|
||
|
||
async def set_annotation(model, args): | ||
logging.info(f'setting annotation for {args.key!r}') | ||
await model.set_annotations({args.key: args.value}) | ||
|
||
|
||
async def get_model(): | ||
logging.info('getting model') | ||
model = juju.model.Model() | ||
await model.connect() | ||
return model | ||
|
||
|
||
async def run_func(args): | ||
model = await get_model() | ||
try: | ||
await args.func(model, args) | ||
finally: | ||
logging.info('disconnecting the model') | ||
await model.disconnect() | ||
|
||
|
||
def parse_args(args): | ||
p = argparse.ArgumentParser() | ||
p.add_argument('--debug', action="store_const", dest="loglevel", const=logging.DEBUG, default=logging.WARNING) | ||
p.add_argument('--verbose', '-v', action="store_const", dest="loglevel", const=logging.INFO) | ||
p.add_argument('--quiet', action="store_const", dest="loglevel", const=logging.CRITICAL) | ||
sub = p.add_subparsers() | ||
getp = sub.add_parser('get') | ||
getp.set_defaults(func=get_annotations) | ||
getp.add_argument("key", help='the key to set', nargs='?') | ||
setp = sub.add_parser('set') | ||
setp.set_defaults(func=set_annotation) | ||
setp.add_argument("key", help='the key to set') | ||
setp.add_argument("value", help='set the value of key to this value, empty string removes the annotation') | ||
return p.parse_args(args) | ||
|
||
|
||
def main(): | ||
args = parse_args(sys.argv[1:]) | ||
rootLogger = logging.getLogger() | ||
rootLogger.setLevel(args.loglevel) | ||
asyncio.run(run_func(args)) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() | ||
|
||
# vim: expandtab ts=4 sts=4 shiftwidth=4 autoindent: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from juju import jasyncio | ||
from juju.model import Model | ||
|
||
|
||
async def main(): | ||
charm = 'juju-qa-test' | ||
|
||
model = Model() | ||
print('Connecting to model') | ||
# connect to current model with current user, per Juju CLI | ||
await model.connect() | ||
|
||
try: | ||
print(f'Deploying {charm} --channel latest/edge --revision 19') | ||
application = await model.deploy( | ||
'juju-qa-test', | ||
application_name='test', | ||
channel='latest/edge', | ||
series='xenial', | ||
revision=19, | ||
) | ||
|
||
print('Waiting for active') | ||
await model.wait_for_idle(status='active') | ||
|
||
print(f'Removing {charm}') | ||
await application.remove() | ||
finally: | ||
print('Disconnecting from model') | ||
await model.disconnect() | ||
|
||
|
||
if __name__ == '__main__': | ||
jasyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters