| |
@@ -28,7 +28,15 @@
|
| |
taskotron_generic_task: true
|
| |
tasks:
|
| |
- debug:
|
| |
- msg: This is a sample debug printout
|
| |
+ msg: This is a sample debug printout from a Taskotron generic task
|
| |
+ '''
|
| |
+ PLAYBOOK_STI='''
|
| |
+ - hosts: localhost
|
| |
+ # this saves a lot of time when running in mock (without network)
|
| |
+ gather_facts: no
|
| |
+ tasks:
|
| |
+ - debug:
|
| |
+ msg: This is a sample debug printout from an STI task
|
| |
'''
|
| |
|
| |
|
| |
@@ -104,13 +112,9 @@
|
| |
self.arg_data
|
| |
|
| |
def test_report_results_missing_file(self, monkeypatch):
|
| |
- '''Don't try to report results when no results file exists'''
|
| |
- mock_rdb = mock.Mock()
|
| |
- monkeypatch.setattr(resultsdb_directive, 'ResultsdbDirective',
|
| |
- mock_rdb)
|
| |
-
|
| |
- self.executor._report_results('missing-playbook-dir')
|
| |
- mock_rdb.assert_not_called()
|
| |
+ '''Raise when no results file exists'''
|
| |
+ with pytest.raises(exc.TaskotronDirectiveError):
|
| |
+ self.executor._report_results('missing-playbook-dir')
|
| |
|
| |
def test_run_playbook(self, monkeypatch):
|
| |
'''A standard invocation of ansible-playbook'''
|
| |
@@ -122,7 +126,8 @@
|
| |
mock_popen = mock.Mock(return_value=('fake output', None))
|
| |
monkeypatch.setattr(os_utils, 'popen_rt', mock_popen)
|
| |
|
| |
- output = self.executor._run_playbook(self.playbook_name, self.ipaddr)
|
| |
+ output, _ = self.executor._run_playbook(self.playbook_name,
|
| |
+ self.ipaddr)
|
| |
|
| |
# must return playbook output
|
| |
assert output == 'fake output'
|
| |
@@ -214,7 +219,7 @@
|
| |
'''Execution using local mode'''
|
| |
mock_spawn_vm = mock.Mock()
|
| |
monkeypatch.setattr(executor.Executor, '_spawn_vm', mock_spawn_vm)
|
| |
- mock_run_playbook = mock.Mock()
|
| |
+ mock_run_playbook = mock.Mock(return_value=(None, True))
|
| |
monkeypatch.setattr(executor.Executor, '_run_playbook',
|
| |
mock_run_playbook)
|
| |
mock_report_results = mock.Mock()
|
| |
@@ -222,9 +227,9 @@
|
| |
mock_report_results)
|
| |
assert self.executor.arg_data['local'] == True
|
| |
|
| |
- finished = self.executor.execute()
|
| |
+ success = self.executor.execute()
|
| |
|
| |
- assert finished == True
|
| |
+ assert success == True
|
| |
mock_spawn_vm.assert_not_called()
|
| |
mock_run_playbook.assert_called_once()
|
| |
assert mock_run_playbook.call_args[0][1] == '127.0.0.1'
|
| |
@@ -234,7 +239,7 @@
|
| |
'''Execution using ssh mode'''
|
| |
mock_spawn_vm = mock.Mock()
|
| |
monkeypatch.setattr(executor.Executor, '_spawn_vm', mock_spawn_vm)
|
| |
- mock_run_playbook = mock.Mock()
|
| |
+ mock_run_playbook = mock.Mock(return_value=(None, True))
|
| |
monkeypatch.setattr(executor.Executor, '_run_playbook',
|
| |
mock_run_playbook)
|
| |
mock_report_results = mock.Mock()
|
| |
@@ -244,9 +249,9 @@
|
| |
self.executor.arg_data['ssh'] = True
|
| |
self.executor.arg_data['machine'] = '127.0.0.2'
|
| |
|
| |
- finished = self.executor.execute()
|
| |
+ success = self.executor.execute()
|
| |
|
| |
- assert finished == True
|
| |
+ assert success == True
|
| |
mock_spawn_vm.assert_not_called()
|
| |
mock_run_playbook.assert_called_once()
|
| |
assert mock_run_playbook.call_args[0][1] == '127.0.0.2'
|
| |
@@ -256,7 +261,7 @@
|
| |
'''Execution using libvirt mode'''
|
| |
mock_spawn_vm = mock.Mock(return_value='127.0.0.3')
|
| |
monkeypatch.setattr(executor.Executor, '_spawn_vm', mock_spawn_vm)
|
| |
- mock_run_playbook = mock.Mock()
|
| |
+ mock_run_playbook = mock.Mock(return_value=(None, True))
|
| |
monkeypatch.setattr(executor.Executor, '_run_playbook',
|
| |
mock_run_playbook)
|
| |
mock_report_results = mock.Mock()
|
| |
@@ -267,9 +272,9 @@
|
| |
self.executor.arg_data['local'] = False
|
| |
self.executor.arg_data['libvirt'] = True
|
| |
|
| |
- finished = self.executor.execute()
|
| |
+ success = self.executor.execute()
|
| |
|
| |
- assert finished == True
|
| |
+ assert success == True
|
| |
mock_spawn_vm.assert_called_once()
|
| |
mock_run_playbook.assert_called_once()
|
| |
assert mock_run_playbook.call_args[0][1] == '127.0.0.3'
|
| |
@@ -294,7 +299,7 @@
|
| |
|
| |
def test_execute_more_playbooks(self, monkeypatch):
|
| |
'''Should execute all found playbooks'''
|
| |
- mock_run_playbook = mock.Mock()
|
| |
+ mock_run_playbook = mock.Mock(return_value=(None, True))
|
| |
monkeypatch.setattr(executor.Executor, '_run_playbook',
|
| |
mock_run_playbook)
|
| |
mock_report_results = mock.Mock()
|
| |
@@ -302,9 +307,9 @@
|
| |
mock_report_results)
|
| |
self.playbook.copy(self.taskdir.join('tests_copy.yml'))
|
| |
|
| |
- finished = self.executor.execute()
|
| |
+ success = self.executor.execute()
|
| |
|
| |
- assert finished == True
|
| |
+ assert success == True
|
| |
assert mock_run_playbook.call_count == 2
|
| |
playbooks = [
|
| |
mock_run_playbook.call_args_list[0][0][0],
|
| |
@@ -321,7 +326,7 @@
|
| |
assert 'tests_copy.yml' in playbooks
|
| |
|
| |
def test_execute_error(self, monkeypatch):
|
| |
- '''Should ignore playbook errors'''
|
| |
+ '''Should raise on playbook errors'''
|
| |
mock_run_playbook = mock.Mock(side_effect=exc.TaskotronError)
|
| |
monkeypatch.setattr(executor.Executor, '_run_playbook',
|
| |
mock_run_playbook)
|
| |
@@ -329,10 +334,58 @@
|
| |
monkeypatch.setattr(executor.Executor, '_report_results',
|
| |
mock_report_results)
|
| |
|
| |
- finished = self.executor.execute()
|
| |
+ success = self.executor.execute()
|
| |
+
|
| |
+ assert success == False
|
| |
+ mock_run_playbook.assert_called_once()
|
| |
+ mock_report_results.assert_not_called()
|
| |
+
|
| |
+ def test_execute_more_playbooks_error(self, monkeypatch):
|
| |
+ '''Should execute all found playbooks even if some has error'''
|
| |
+ mock_run_playbook = mock.Mock(side_effect=[
|
| |
+ exc.TaskotronError,
|
| |
+ (None, True)])
|
| |
+ monkeypatch.setattr(executor.Executor, '_run_playbook',
|
| |
+ mock_run_playbook)
|
| |
+ mock_report_results = mock.Mock()
|
| |
+ monkeypatch.setattr(executor.Executor, '_report_results',
|
| |
+ mock_report_results)
|
| |
+ self.playbook.copy(self.taskdir.join('tests_copy.yml'))
|
| |
+
|
| |
+ success = self.executor.execute()
|
| |
+
|
| |
+ assert success == False
|
| |
+ assert mock_run_playbook.call_count == 2
|
| |
+ playbooks = [
|
| |
+ mock_run_playbook.call_args_list[0][0][0],
|
| |
+ mock_run_playbook.call_args_list[1][0][0]
|
| |
+ ]
|
| |
+ assert 'tests.yml' in playbooks
|
| |
+ assert 'tests_copy.yml' in playbooks
|
| |
+ assert mock_report_results.call_count == 1
|
| |
+ playbooks = [
|
| |
+ mock_report_results.call_args_list[0][0][0]
|
| |
+ ]
|
| |
+ assert 'tests.yml' in playbooks or 'tests_copy.yml' in playbooks
|
| |
|
| |
- assert finished == True
|
| |
+ def test_execute_sti_no_report(self, monkeypatch):
|
| |
+ '''Shouldn't try to report results for STI tasks'''
|
| |
+ self.playbook.write(PLAYBOOK_STI)
|
| |
+ mock_spawn_vm = mock.Mock()
|
| |
+ monkeypatch.setattr(executor.Executor, '_spawn_vm', mock_spawn_vm)
|
| |
+ mock_run_playbook = mock.Mock(return_value=(None, False))
|
| |
+ monkeypatch.setattr(executor.Executor, '_run_playbook',
|
| |
+ mock_run_playbook)
|
| |
+ mock_report_results = mock.Mock()
|
| |
+ monkeypatch.setattr(executor.Executor, '_report_results',
|
| |
+ mock_report_results)
|
| |
+
|
| |
+ success = self.executor.execute()
|
| |
+
|
| |
+ assert success == True
|
| |
+ mock_spawn_vm.assert_not_called()
|
| |
mock_run_playbook.assert_called_once()
|
| |
+ assert mock_run_playbook.call_args[0][1] == '127.0.0.1'
|
| |
mock_report_results.assert_not_called()
|
| |
|
| |
def test_execute_interrupted(self, monkeypatch):
|
| |
@@ -346,9 +399,9 @@
|
| |
mock_report_results)
|
| |
self.playbook.copy(self.taskdir.join('tests_copy.yml'))
|
| |
|
| |
- finished = self.executor.execute()
|
| |
+ success = self.executor.execute()
|
| |
|
| |
- assert finished == False
|
| |
+ assert success == False
|
| |
mock_run_playbook.assert_called_once()
|
| |
mock_report_results.assert_not_called()
|
| |
|
| |
We need to detect when a task hasn't finished properly. It's impossible
to do for STI, but for Taskotron generic tasks, we can check whether
results.yml exists. If it doesn't, the task clearly hasn't finished
successfuly. In that case, exit with non-zero exit code, so that our
tools (Buildbot) can inform us about a crashing task.
This code was written after all executions of task-rpmdeplint were
silently crashing every single time for a longer period of time. This
should help us detect such cases.
This will also detect cases when our playbooks are not working properly,
or when task playbooks are not syntactically correct.
Documentation was adjusted to explain that results.yml file must be
created, and how to create that file if you want no results to be
posted.