-
Notifications
You must be signed in to change notification settings - Fork 93
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
Surpress KeyError when applications are missing #367
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,30 @@ | ||
""" | ||
This example shows how to reconnect to a model if you encounter an error | ||
|
||
1. Connects to current model. | ||
2. Attempts to get an application that doesn't exist. | ||
3. Disconnect then reconnect. | ||
|
||
""" | ||
from juju import loop | ||
from juju.model import Model | ||
from juju.errors import JujuEntityNotFoundError | ||
|
||
|
||
async def main(): | ||
model = Model() | ||
|
||
retryCount = 3 | ||
for i in range(0, retryCount): | ||
await model.connect_current() | ||
try: | ||
model.applications['foo'].relations | ||
except JujuEntityNotFoundError as e: | ||
print(e.entity_name) | ||
finally: | ||
await model.disconnect() | ||
# Everything worked out, continue on wards. | ||
|
||
|
||
if __name__ == '__main__': | ||
loop.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2019 Canonical Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import logging | ||
|
||
from . import model | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class Charm(model.ModelEntity): | ||
pass |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import unittest | ||
|
||
import mock | ||
|
||
from juju.model import Model | ||
from juju.relation import Relation | ||
from juju.errors import JujuEntityNotFoundError | ||
|
||
|
||
def _make_delta(entity, type_, data=None): | ||
from juju.client.client import Delta | ||
from juju.delta import get_entity_delta | ||
|
||
delta = Delta([entity, type_, data]) | ||
return get_entity_delta(delta) | ||
|
||
|
||
class TestRelation(unittest.TestCase): | ||
def test_relation_does_not_match(self): | ||
model = Model() | ||
model._connector = mock.MagicMock() | ||
|
||
delta = _make_delta('application', 'add', dict(name='foo')) | ||
model.state.apply_delta(delta) | ||
delta = _make_delta('relation', 'bar', dict(id="uuid-1234", name='foo', endpoints=[{"application-name": "foo"}])) | ||
model.state.apply_delta(delta) | ||
|
||
rel = Relation("uuid-1234", model) | ||
self.assertFalse(rel.matches(["endpoint"])) | ||
|
||
def test_relation_does_match(self): | ||
model = Model() | ||
model._connector = mock.MagicMock() | ||
|
||
delta = _make_delta('application', 'add', dict(name='foo')) | ||
model.state.apply_delta(delta) | ||
delta = _make_delta('relation', 'bar', dict(id="uuid-1234", name='foo', endpoints=[{"application-name": "foo"}])) | ||
model.state.apply_delta(delta) | ||
|
||
rel = Relation("uuid-1234", model) | ||
self.assertFalse(rel.matches(["foo"])) | ||
|
||
def test_relation_does_match_remote_app(self): | ||
model = Model() | ||
model._connector = mock.MagicMock() | ||
|
||
delta = _make_delta('remoteApplication', 'add', dict(name='foo')) | ||
model.state.apply_delta(delta) | ||
delta = _make_delta('relation', 'bar', dict(id="uuid-1234", name='foo', endpoints=[{"application-name": "foo"}])) | ||
model.state.apply_delta(delta) | ||
|
||
rel = Relation("uuid-1234", model) | ||
self.assertFalse(rel.matches(["foo"])) | ||
|
||
def test_relation_does_not_match_anything(self): | ||
model = Model() | ||
model._connector = mock.MagicMock() | ||
|
||
delta = _make_delta('relation', 'bar', dict(id="uuid-1234", name='foo', endpoints=[{"application-name": "foo"}])) | ||
model.state.apply_delta(delta) | ||
|
||
rel = Relation("uuid-1234", model) | ||
self.assertRaises(JujuEntityNotFoundError, rel.matches, ["xxx"]) |
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 |
---|---|---|
|
@@ -35,7 +35,7 @@ deps = | |
# default tox env excludes integration and serial tests | ||
commands = | ||
# These need to be installed in a specific order | ||
pip install urllib3==1.22 | ||
pip install urllib3==1.25.7 | ||
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. This is to surpress the 3.8 warnings:
|
||
pip install pylxd | ||
py.test --tb native -ra -v -s -n auto -k 'not integration' -m 'not serial' {posargs} | ||
|
||
|
@@ -50,7 +50,7 @@ deps = | |
envdir = {toxworkdir}/py3 | ||
commands = | ||
# These need to be installed in a specific order | ||
pip install urllib3==1.22 | ||
pip install urllib3==1.25.7 | ||
pip install pylxd | ||
py.test --tb native -ra -v -n auto -k 'integration' -m 'not serial' {posargs} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
newline from here