Skip to content

Commit 0d1d0a8

Browse files
authored
Merge pull request #1035 from Aflynn50/bugfix-NoneType
#1035 #### Description *<Please add why this change is needed and what it does.>* Fix for #1028 The logger is not passed to calls of `utils.run_with_interupt` from model.py and controller.py. The default value is `None`, so when it is later used we get the error. *<Fixes: >* #### QA Steps Added a `raise Exception("my random exception")` to the `Next` method of `ModelSummeryWatcherFacade`. This is hit by the `run_with_interupt` in controller and we can observe that when we run the file `modelsummaries.py`, if the log arguments added in this PR are not there then we get the None Type error and if they are there, we do not. Jira: JUJU-5610
2 parents f28a591 + 4f164a3 commit 0d1d0a8

17 files changed

Lines changed: 152 additions & 179 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ pytestdebug.log
1515
.vscode/
1616
deb_dist
1717
*.tar.gz
18+
.idea/

juju/controller.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,8 @@ async def _watcher(stop_event):
828828
try:
829829
results = await utils.run_with_interrupt(
830830
watcher.Next(),
831-
stop_event)
831+
stop_event,
832+
log=log)
832833
except JujuAPIError as e:
833834
if 'watcher was stopped' not in str(e):
834835
raise

juju/model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,8 @@ async def _all_watcher():
11151115
try:
11161116
results = await utils.run_with_interrupt(
11171117
allwatcher.Next(),
1118-
self._watch_stopping)
1118+
self._watch_stopping,
1119+
log=log)
11191120
except JujuAPIError as e:
11201121
if 'watcher was stopped' not in str(e):
11211122
raise

tests/integration/test_application.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
@base.bootstrapped
2121
@pytest.mark.asyncio
22-
async def test_action(event_loop):
22+
async def test_action():
2323
async with base.CleanModel() as model:
2424
ubuntu_app = await model.deploy(
2525
'percona-cluster',
@@ -57,7 +57,7 @@ async def test_action(event_loop):
5757

5858
@base.bootstrapped
5959
@pytest.mark.asyncio
60-
async def test_get_set_config(event_loop):
60+
async def test_get_set_config():
6161
async with base.CleanModel() as model:
6262
ubuntu_app = await model.deploy(
6363
'percona-cluster',
@@ -82,7 +82,7 @@ async def test_get_set_config(event_loop):
8282

8383
@base.bootstrapped
8484
@pytest.mark.asyncio
85-
async def test_status_is_not_unset(event_loop):
85+
async def test_status_is_not_unset():
8686
async with base.CleanModel() as model:
8787
app = await model.deploy(
8888
'ubuntu',
@@ -96,7 +96,7 @@ async def test_status_is_not_unset(event_loop):
9696

9797
@base.bootstrapped
9898
@pytest.mark.asyncio
99-
async def test_status(event_loop):
99+
async def test_status():
100100
async with base.CleanModel() as model:
101101
app = await model.deploy('cs:~juju-qa/blocked-0')
102102

@@ -111,7 +111,7 @@ def app_ready():
111111

112112
@base.bootstrapped
113113
@pytest.mark.asyncio
114-
async def test_add_units(event_loop):
114+
async def test_add_units():
115115
from juju.unit import Unit
116116

117117
async with base.CleanModel() as model:
@@ -130,7 +130,7 @@ async def test_add_units(event_loop):
130130

131131
@base.bootstrapped
132132
@pytest.mark.asyncio
133-
async def test_deploy_charmhub_charm(event_loop):
133+
async def test_deploy_charmhub_charm():
134134
async with base.CleanModel() as model:
135135
app = await model.deploy('ch:hello-juju')
136136
await model.block_until(lambda: (len(app.units) > 0 and
@@ -140,7 +140,7 @@ async def test_deploy_charmhub_charm(event_loop):
140140

141141
@base.bootstrapped
142142
@pytest.mark.asyncio
143-
async def test_upgrade_charm_switch_channel(event_loop):
143+
async def test_upgrade_charm_switch_channel():
144144
# Note for future:
145145
# This test requires a charm that has different
146146
# revisions for different channels/risks.
@@ -184,7 +184,7 @@ async def test_upgrade_charm_switch_channel(event_loop):
184184

185185
@base.bootstrapped
186186
@pytest.mark.asyncio
187-
async def test_upgrade_local_charm(event_loop):
187+
async def test_upgrade_local_charm():
188188
# Skip temporarily due to a known problem:
189189
pytest.skip('cannot upgrade application "ubuntu" to charm "local:focal/ubuntu-0": required storage "files" removed')
190190
async with base.CleanModel() as model:
@@ -201,7 +201,7 @@ async def test_upgrade_local_charm(event_loop):
201201

202202
@base.bootstrapped
203203
@pytest.mark.asyncio
204-
async def test_upgrade_switch_charmstore_to_charmhub(event_loop):
204+
async def test_upgrade_switch_charmstore_to_charmhub():
205205
async with base.CleanModel() as model:
206206
app = await model.deploy('cs:ubuntu', series='focal')
207207
await model.wait_for_idle(status="active")
@@ -213,7 +213,7 @@ async def test_upgrade_switch_charmstore_to_charmhub(event_loop):
213213

214214
@base.bootstrapped
215215
@pytest.mark.asyncio
216-
async def test_upgrade_charm_resource(event_loop):
216+
async def test_upgrade_charm_resource():
217217
async with base.CleanModel() as model:
218218
app = await model.deploy('cs:~juju-qa/bionic/upgrade-charm-resource-test-0')
219219

@@ -233,7 +233,7 @@ async def test_upgrade_charm_resource(event_loop):
233233

234234
@base.bootstrapped
235235
@pytest.mark.asyncio
236-
async def test_refresh_with_resource_argument(event_loop):
236+
async def test_refresh_with_resource_argument():
237237
async with base.CleanModel() as model:
238238
app = await model.deploy('juju-qa-test', resources={'foo-file': 2})
239239
res2 = await app.get_resources()
@@ -245,7 +245,7 @@ async def test_refresh_with_resource_argument(event_loop):
245245

246246
@base.bootstrapped
247247
@pytest.mark.asyncio
248-
async def test_upgrade_charm_resource_same_rev_no_update(event_loop):
248+
async def test_upgrade_charm_resource_same_rev_no_update():
249249
async with base.CleanModel() as model:
250250
app = await model.deploy('keystone', channel='victoria/stable')
251251
ress = await app.get_resources()
@@ -256,7 +256,7 @@ async def test_upgrade_charm_resource_same_rev_no_update(event_loop):
256256

257257
@base.bootstrapped
258258
@pytest.mark.asyncio
259-
async def test_refresh_charmhub_to_local(event_loop):
259+
async def test_refresh_charmhub_to_local():
260260
charm_path = INTEGRATION_TEST_DIR / 'charm'
261261
async with base.CleanModel() as model:
262262
app = await model.deploy('ubuntu', application_name='ubu-path')
@@ -270,7 +270,7 @@ async def test_refresh_charmhub_to_local(event_loop):
270270

271271
@base.bootstrapped
272272
@pytest.mark.asyncio
273-
async def test_local_refresh(event_loop):
273+
async def test_local_refresh():
274274
charm_path = INTEGRATION_TEST_DIR / 'charm'
275275
async with base.CleanModel() as model:
276276
app = await model.deploy('ubuntu')
@@ -286,7 +286,7 @@ async def test_local_refresh(event_loop):
286286

287287
@base.bootstrapped
288288
@pytest.mark.asyncio
289-
async def test_upgrade_local_charm_with_resource(event_loop):
289+
async def test_upgrade_local_charm_with_resource():
290290
charm_path = INTEGRATION_TEST_DIR / 'file-resource-charm'
291291
async with base.CleanModel() as model:
292292
app = await model.deploy(str(charm_path))
@@ -308,7 +308,7 @@ async def test_upgrade_local_charm_with_resource(event_loop):
308308

309309
@base.bootstrapped
310310
@pytest.mark.asyncio
311-
async def test_trusted(event_loop):
311+
async def test_trusted():
312312
async with base.CleanModel() as model:
313313
await model.deploy('ubuntu', trust=True)
314314

@@ -323,7 +323,7 @@ async def test_trusted(event_loop):
323323

324324
@base.bootstrapped
325325
@pytest.mark.asyncio
326-
async def test_app_remove_wait_flag(event_loop):
326+
async def test_app_remove_wait_flag():
327327
async with base.CleanModel() as model:
328328
app = await model.deploy('ubuntu')
329329
a_name = app.name
@@ -335,7 +335,7 @@ async def test_app_remove_wait_flag(event_loop):
335335

336336
@base.bootstrapped
337337
@pytest.mark.asyncio
338-
async def test_app_charm_name(event_loop):
338+
async def test_app_charm_name():
339339
async with base.CleanModel() as model:
340340
app = await model.deploy('ubuntu')
341341
await model.wait_for_idle(status="active")

tests/integration/test_charmhub.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@base.bootstrapped
1212
@pytest.mark.asyncio
13-
async def test_info(event_loop):
13+
async def test_info():
1414
async with base.CleanModel() as model:
1515
result = await model.charmhub.info("hello-juju")
1616

@@ -19,7 +19,7 @@ async def test_info(event_loop):
1919

2020
@base.bootstrapped
2121
@pytest.mark.asyncio
22-
async def test_info_with_channel(event_loop):
22+
async def test_info_with_channel():
2323
async with base.CleanModel() as model:
2424
result = await model.charmhub.info("hello-juju", "latest/stable")
2525

@@ -29,7 +29,7 @@ async def test_info_with_channel(event_loop):
2929

3030
@base.bootstrapped
3131
@pytest.mark.asyncio
32-
async def test_info_not_found(event_loop):
32+
async def test_info_not_found():
3333
async with base.CleanModel() as model:
3434
try:
3535
await model.charmhub.info("badnameforapp")
@@ -41,7 +41,7 @@ async def test_info_not_found(event_loop):
4141

4242
@base.bootstrapped
4343
@pytest.mark.asyncio
44-
async def test_find(event_loop):
44+
async def test_find():
4545
async with base.CleanModel() as model:
4646
result = await model.charmhub.find("kube")
4747

@@ -53,7 +53,7 @@ async def test_find(event_loop):
5353

5454
@base.bootstrapped
5555
@pytest.mark.asyncio
56-
async def test_find_bundles(event_loop):
56+
async def test_find_bundles():
5757
async with base.CleanModel() as model:
5858
result = await model.charmhub.find("kube", charm_type="bundle")
5959

@@ -65,7 +65,7 @@ async def test_find_bundles(event_loop):
6565

6666
@base.bootstrapped
6767
@pytest.mark.asyncio
68-
async def test_find_all(event_loop):
68+
async def test_find_all():
6969
async with base.CleanModel() as model:
7070
result = await model.charmhub.find("")
7171

@@ -77,7 +77,7 @@ async def test_find_all(event_loop):
7777

7878
@base.bootstrapped
7979
@pytest.mark.asyncio
80-
async def test_subordinate_charm_zero_units(event_loop):
80+
async def test_subordinate_charm_zero_units():
8181
# normally in pylibjuju deploy num_units defaults to 1, we switch
8282
# that to 0 behind the scenes if we see that the charmhub charm
8383
# we're deploying is a subordinate charm
@@ -104,7 +104,7 @@ async def test_subordinate_charm_zero_units(event_loop):
104104

105105
@base.bootstrapped
106106
@pytest.mark.asyncio
107-
async def test_list_resources(event_loop):
107+
async def test_list_resources():
108108
async with base.CleanModel() as model:
109109
resources = await model.charmhub.list_resources('hello-kubecon')
110110
assert isinstance(resources, list) and len(resources) > 0

tests/integration/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@base.bootstrapped
1212
@pytest.mark.asyncio
13-
async def test_user_info(event_loop):
13+
async def test_user_info():
1414
async with base.CleanModel() as model:
1515
controller_conn = await model.connection().controller()
1616

tests/integration/test_connection.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
@base.bootstrapped
2828
@pytest.mark.asyncio
29-
async def test_connection_happy_path(event_loop):
29+
async def test_connection_happy_path():
3030
async with base.CleanController() as contr:
3131
conn = contr.connection()
3232
new_cont = Controller()
@@ -40,7 +40,7 @@ async def test_connection_happy_path(event_loop):
4040

4141
@base.bootstrapped
4242
@pytest.mark.asyncio
43-
async def test_monitor(event_loop):
43+
async def test_monitor():
4444
async with base.CleanModel() as model:
4545
conn = model.connection()
4646
assert conn.monitor.status == 'connected'
@@ -51,7 +51,7 @@ async def test_monitor(event_loop):
5151

5252
@base.bootstrapped
5353
@pytest.mark.asyncio
54-
async def test_monitor_catches_error(event_loop):
54+
async def test_monitor_catches_error():
5555

5656
async with base.CleanModel() as model:
5757
conn = model.connection()
@@ -72,7 +72,7 @@ async def test_monitor_catches_error(event_loop):
7272

7373
@base.bootstrapped
7474
@pytest.mark.asyncio
75-
async def test_full_status(event_loop):
75+
async def test_full_status():
7676
async with base.CleanModel() as model:
7777
await model.deploy(
7878
'ubuntu',
@@ -88,7 +88,7 @@ async def test_full_status(event_loop):
8888

8989
@base.bootstrapped
9090
@pytest.mark.asyncio
91-
async def test_reconnect(event_loop):
91+
async def test_reconnect():
9292
async with base.CleanModel() as model:
9393
kwargs = model.connection().connect_params()
9494
conn = await Connection.connect(**kwargs)
@@ -105,7 +105,7 @@ async def test_reconnect(event_loop):
105105
@base.bootstrapped
106106
@pytest.mark.asyncio
107107
@pytest.mark.skip('tests the websocket protocol, not pylibjuju, needs to be revised')
108-
async def test_redirect(event_loop):
108+
async def test_redirect():
109109
controller = Controller()
110110
await controller.connect()
111111
kwargs = controller.connection().connect_params()
@@ -258,7 +258,7 @@ def _find_free_port(self):
258258

259259
@base.bootstrapped
260260
@pytest.mark.asyncio
261-
async def test_verify_controller_cert(event_loop):
261+
async def test_verify_controller_cert():
262262
jujudata = FileJujuData()
263263
controller_name = jujudata.current_controller()
264264
endpoint = jujudata.controllers()[controller_name]['api-endpoints'][0]

0 commit comments

Comments
 (0)