-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JUJU-367] Improve get_charm_series
to check the model for series for a local charm
#607
Changes from 1 commit
1ecc335
7014ace
c96e82c
68af102
2c9e270
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
This example: | ||
|
||
1. Connects to the current model | ||
2. Deploy a bundle and waits until it reports itself active | ||
3. Destroys the units and applications | ||
|
||
""" | ||
from juju import jasyncio | ||
from juju.model import Model | ||
|
||
|
||
async def main(): | ||
model = Model() | ||
print('Connecting to model') | ||
# Connect to current model with current user, per Juju CLI | ||
await model.connect() | ||
|
||
try: | ||
print('Deploying bundle') | ||
applications = await model.deploy( | ||
'./examples/k8s-local-bundle/bundle.yaml', | ||
) | ||
|
||
print('Waiting for active') | ||
await model.wait_for_idle(status='active') | ||
print("Successfully deployed!") | ||
|
||
await applications[0].upgrade_charm(path='./examples/charms/onos.charm') | ||
|
||
await model.wait_for_idle(status='active') | ||
|
||
print('Removing bundle') | ||
for application in applications: | ||
await application.remove() | ||
finally: | ||
print('Disconnecting from model') | ||
await model.disconnect() | ||
print("Success") | ||
|
||
|
||
if __name__ == '__main__': | ||
jasyncio.run(main()) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,13 +125,8 @@ async def _handle_local_charms(self, bundle, bundle_dir): | |
series = ( | ||
app_dict.get('series') or | ||
default_series or | ||
get_charm_series(charm_dir) | ||
await get_charm_series(charm_dir, self.model) | ||
) | ||
if not series: | ||
model_config = await self.model.get_config() | ||
default_series = model_config.get("default-series") | ||
if default_series: | ||
default_series = series = default_series.value | ||
if not series: | ||
raise JujuError( | ||
"Couldn't determine series for charm at {}. " | ||
|
@@ -410,11 +405,14 @@ def is_local_charm(charm_url): | |
return charm_url.startswith('.') or charm_url.startswith('local:') or os.path.isabs(charm_url) | ||
|
||
|
||
def get_charm_series(path): | ||
async def get_charm_series(path, model): | ||
"""Inspects the charm directory at ``path`` and returns a default | ||
series from its metadata.yaml (the first item in the 'series' list). | ||
|
||
Tries to extract the informiation from the given model if no | ||
series is determined from the path. | ||
Returns None if no series can be determined. | ||
|
||
""" | ||
path = Path(path) | ||
try: | ||
|
@@ -432,8 +430,16 @@ def get_charm_series(path): | |
mark = exc.problem_mark | ||
log.error("Error parsing YAML file {}, line {}, column: {}".format(md, mark.line, mark.column)) | ||
raise | ||
series = data.get('series') | ||
return series[0] if series else None | ||
_series = data.get('series') | ||
series = _series[0] if _series else None | ||
|
||
if series is None: | ||
model_config = await model.get_config() | ||
default_series = model_config.get("default-series") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my case I have a k8s charm, but the "default-series" it has stored is: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that's normal, that's why we get the |
||
if default_series: | ||
series = default_series.value | ||
|
||
return series | ||
|
||
|
||
class ChangeSet: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing: upgrades the charm from local path.