Esempio n. 1
0
 def test_process_deployment(self, popen, update_deployment):
     """Test process_deployment method."""
     process_mock = MagicMock()
     attrs = {
         'communicate.return_value': ('ouput', 'error'),
         'wait.return_value': 0
     }
     process_mock.configure_mock(**attrs)
     popen.return_value = process_mock
     res = process_deployment(deployment)
     assert res, res
     assert update_deployment.called_with(deployment, status='success')
Esempio n. 2
0
 def test_process_deployment_process_error(self, popen, update_deployment):
     """Test process_deployment process_error method."""
     process_mock = MagicMock()
     attrs = {
         'communicate.return_value': ('ouput', 'error'),
         'wait.return_value': 1
     }
     process_mock.configure_mock(**attrs)
     popen.return_value = process_mock
     res = process_deployment(deployment)
     assert res is False, res
     message = "command: %s ERROR: %s" % ('output', 'error')
     assert update_deployment.called_with(deployment,
                                          status='error',
                                          message=message)
Esempio n. 3
0
 def test_process_deployment_oserror(self, popen, update_deployment):
     """Test process_deployment fails method."""
     process_mock = MagicMock()
     attrs = {
         'communicate.return_value': ('ouput', 'error'),
         'wait.return_value': 1,
         'wait.side_effect': OSError
     }
     process_mock.configure_mock(**attrs)
     popen.return_value = process_mock
     res = process_deployment(deployment)
     assert res is False, res
     e = OSError()
     assert update_deployment.called_with(deployment,
                                          status='error',
                                          message=str(e))
Esempio n. 4
0
    def test_process_deployment_ansible_key_error(self, update_deployment,
                                                  run_ansible_playbook):
        """Test process_deployment ansible key_error method."""
        repo = {
            'user/ansible': {
                'nsible_hosts': 'ansible_hosts',
                'nsible_playbook': 'playbook.yml'
            }
        }

        with patch('config.REPOS', repo):
            run_ansible_playbook.side_effect = KeyError
            res = process_deployment(deployment_ansible)
            message = "ansible playbook or host file is missing in config file."
            assert update_deployment.called_with(deployment_ansible,
                                                 status='error',
                                                 message=message)
            assert res is False
Esempio n. 5
0
    def test_process_deployment_ansible(self, update_deployment,
                                        run_ansible_playbook):
        """Test process_deployment ansible method."""
        repo = {
            'user/ansible': {
                'ansible_hosts': 'ansible_hosts',
                'ansible_playbook': 'playbook.yml'
            }
        }

        with patch('config.REPOS', repo):
            res = process_deployment(deployment_ansible)
            assert res, res
            assert run_ansible_playbook.called_with(
                repo['user/ansible']['ansible_hosts'],
                repo['user/ansible']['ansible_playbook'])
            assert update_deployment.called_with(deployment_ansible,
                                                 status='success')
Esempio n. 6
0
    def test_process_deployment_ansible_error(self, update_deployment,
                                              run_ansible_playbook):
        """Test process_deployment ansible error method."""
        repo = {
            'user/ansible': {
                'ansible_hosts': 'wrong',
                'ansible_playbook': 'playook.yml'
            }
        }

        with patch('config.REPOS', repo):
            from ansible.errors import AnsibleError
            run_ansible_playbook.side_effect = AnsibleError('error')
            res = process_deployment(deployment_ansible)
            msg = str(AnsibleError('error'))
            assert update_deployment.called_with(deployment_ansible,
                                                 status='error',
                                                 message=msg)
            assert res is False, res