Browse Source

Updating failure handling

Change-Id: Ib425bb6b4c6d824e3623d6a87a9d14575d32f19a
Dan Radez 7 months ago
parent
commit
8362fa3ebd
2 changed files with 13 additions and 2 deletions
  1. 2
    2
      networking_ansible/api.py
  2. 11
    0
      networking_ansible/tests/unit/test_api.py

+ 2
- 2
networking_ansible/api.py View File

@@ -66,8 +66,8 @@ class NetworkingAnsible(object):
66 66
         result = ansible_runner.run(playbook=playbook,
67 67
                                     inventory=self.inventory,
68 68
                                     settings={'pexpect_use_poll': False})
69
-        failures = result.stats['failures']
70
-        if failures:
69
+        if result.status == 'failed' or \
70
+                (result.stats and result.stats.get('failures', [])):
71 71
             raise exceptions.AnsibleRunnerException(' '.join(result.stdout))
72 72
         return result
73 73
 

+ 11
- 0
networking_ansible/tests/unit/test_api.py View File

@@ -78,6 +78,17 @@ class TestRunTask(base.NetworkingAnsibleTestCase):
78 78
                                          [0]['vars']['port_description'])
79 79
 
80 80
     def test_run_task_failures(self, mock_ans_runner):
81
+        mock_result = mock_ans_runner.run.return_value
82
+        mock_result.status = 'failed'
83
+        self.assertRaises(exceptions.AnsibleRunnerException,
84
+                          self.mech.ansnet._run_task,
85
+                          'fake_task',
86
+                          self.testhost,
87
+                          self.testsegid,
88
+                          'fake_switchport')
89
+
90
+        mock_result.status = ''
91
+        mock_result.stats = {'failures': ['I got some failure']}
81 92
         self.assertRaises(exceptions.AnsibleRunnerException,
82 93
                           self.mech.ansnet._run_task,
83 94
                           'fake_task',

Loading…
Cancel
Save