Skip to content

Commit a533df4

Browse files
committed
Fix Unit.resolved() not actually doing anything
The integration test for Unit.resolved() only confirmed that it doesn't error, but due to an issue with the format of the `tags` parameter, it wasn't actually affecting the desired unit. This fixes both the call and the test to confirm that it actually resolves the error. Fixes #484
1 parent 5e23162 commit a533df4

6 files changed

Lines changed: 43 additions & 11 deletions

File tree

juju/unit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async def resolved(self, retry=False):
125125
return await app_facade.ResolveUnitErrors(
126126
all_=False,
127127
retry=retry,
128-
tags={'tag': [self.tag]})
128+
tags={'entities': [{'tag': self.tag}]})
129129

130130
async def run(self, command, timeout=None):
131131
"""Run command on this unit.

tests/charm/dispatch

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
#!/bin/bash
22

3-
status-set "$(config-get status)"
3+
status="$(config-get status)"
4+
5+
if [[ "$status" == "error" ]]; then
6+
if [[ -e .errored ]]; then
7+
status="active"
8+
else
9+
touch .errored
10+
exit 1
11+
fi
12+
fi
13+
status-set "$status"

tests/integration/charm.charm

302 Bytes
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
options:
2+
status:
3+
type: string
4+
default: "active"

tests/integration/charm/dispatch

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
#!/bin/bash
22

3-
status-set active
3+
status="$(config-get status)"
4+
5+
if [[ "$status" == "error" ]]; then
6+
if [[ -e .errored ]]; then
7+
status="active"
8+
else
9+
touch .errored
10+
exit 1
11+
fi
12+
fi
13+
status-set "$status"

tests/integration/test_unit.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
from pathlib import Path
23
from tempfile import NamedTemporaryFile
34

45
import pytest
@@ -144,16 +145,23 @@ async def test_ssh(event_loop):
144145
@base.bootstrapped
145146
@pytest.mark.asyncio
146147
async def test_resolve(event_loop):
148+
charm_file = Path(__file__).absolute().parent / 'charm.charm'
147149

148150
async with base.CleanModel() as model:
149151
app = await model.deploy(
150-
'ubuntu-0',
151-
application_name='ubuntu',
152-
series='trusty',
153-
channel='stable',
152+
str(charm_file),
153+
config={'status': 'error'},
154154
)
155155

156-
# Resolving a hook not in an error state is not a great test but at
157-
# least it exercises the code.
158-
for unit in app.units:
159-
await unit.resolved()
156+
try:
157+
await model.wait_for_idle(raise_on_error=False)
158+
assert app.units[0].workload_status == 'error'
159+
160+
await app.units[0].resolved()
161+
162+
await model.wait_for_idle(raise_on_error=False)
163+
assert app.units[0].workload_status == 'active'
164+
finally:
165+
# Errored units won't get cleaned up unless we force them.
166+
await asyncio.gather(*(machine.destroy(force=True)
167+
for machine in model.machines.values()))

0 commit comments

Comments
 (0)