@@ -135,17 +135,9 @@ class TestPolicies:
135135 async def test_list_no_violations (self , ops_test ):
136136 """This will run before the resources have been audited"""
137137 unit = list (ops_test .model .units .values ())[0 ]
138- unit_name = unit .name
139- res = await ops_test .juju (
140- "run-action" ,
141- unit_name ,
142- "list-violations" ,
143- "--wait" ,
144- "-m" ,
145- ops_test .model .info .name ,
146- )
147- res = yaml .full_load (res [1 ])[unit .tag ]
148- violations = json .loads (res ["results" ]["constraint-violations" ])
138+ action = await unit .run_action ("list-violations" )
139+ res = await action .wait ()
140+ violations = yaml .safe_load (res .results ["constraint-violations" ])
149141 assert len (violations ) == 2 , json .dumps (violations , indent = 2 )
150142 assert any (
151143 v
@@ -191,18 +183,11 @@ async def test_audit(self, ops_test, client):
191183
192184 async def test_list_violations (self , ops_test ):
193185 unit = list (ops_test .model .units .values ())[0 ]
194- unit_name = unit .name
195- res = await ops_test .juju (
196- "run-action" ,
197- unit_name ,
198- "list-violations" ,
199- "--wait" ,
200- "-m" ,
201- ops_test .model .info .name ,
202- )
203- res = yaml .full_load (res [1 ])[unit .tag ]
204- violations = json .loads (res ["results" ]["constraint-violations" ])
205- assert res ["status" ] == "completed"
186+ action = await unit .run_action ("list-violations" )
187+ res = await action .wait ()
188+ violations = yaml .safe_load (res .results ["constraint-violations" ])
189+
190+ assert res .status == "completed"
206191 assert len (violations ) == 2
207192 assert any (
208193 violation ["constraint" ] == "ns-must-have-gk"
@@ -228,21 +213,19 @@ async def test_get_violations(self, ops_test):
228213 }
229214
230215 unit = list (ops_test .model .units .values ())[0 ]
231- unit_name = unit .name
232- res = await ops_test .juju (
233- "run-action" ,
234- unit_name ,
216+ action = await unit .run_action (
235217 "get-violation" ,
236- "constraint-template=K8sRequiredLabels" ,
237- "constraint=ns-must-have-gk" ,
238- "--wait" ,
239- "-m" ,
240- ops_test .model .info .name ,
218+ ** {
219+ "constraint-template" : "K8sRequiredLabels" ,
220+ "constraint" : "ns-must-have-gk" ,
221+ },
222+ )
223+ res = await action .wait ()
224+ violations = yaml .safe_load (res .results ["violations" ])
225+ assert res .status == "completed"
226+ assert any (v == expected_model_violation for v in violations ), json .dumps (
227+ violations , indent = 2
241228 )
242- res = yaml .full_load (res [1 ])[unit .tag ]
243- violations = json .loads (res ["results" ]["violations" ])
244- assert res ["status" ] == "completed"
245- assert any (v == expected_model_violation for v in violations )
246229
247230 async def test_reconciliation_required (self , ops_test , client ):
248231 model = ops_test .model
@@ -254,18 +237,9 @@ async def test_reconciliation_required(self, ops_test, client):
254237 )
255238
256239 unit = list (ops_test .model .units .values ())[0 ]
257- unit_name = unit .name
258- res = await ops_test .juju (
259- "run-action" ,
260- unit_name ,
261- "reconcile-resources" ,
262- "--wait" ,
263- "-m" ,
264- ops_test .model .info .name ,
265- )
266-
267- res = yaml .full_load (res [1 ])[unit .tag ]
268- assert res ["status" ] == "completed"
240+ action = await unit .run_action ("reconcile-resources" )
241+ res = await action .wait ()
242+ assert res .status == "completed"
269243 await model .wait_for_idle (
270244 apps = ["gatekeeper-audit" ], status = "active" , timeout = 60
271245 )
0 commit comments