예제 #1
0
 def test_run_mock_ko(self):
     m = mock.Mock()
     m.side_effect = AnsibleError('Problem!')
     with mock.patch(
             'ansible.executor.task_queue_manager.TaskQueueManager.run',
             m,
             create=True):
         t = pyansible.Role('test-role')
         self.assertFalse(t.run())
         self.assertIsNotNone(t.runtime_errors)
예제 #2
0
 def test_run_mock_ok(self):
     m = mock.Mock()
     m2 = mock.Mock()
     from ansible.playbook.play import Play
     m.return_value = Play().load({'hosts': 'localhost'})
     m2.return_value = True
     with mock.patch('ansible.playbook.play.Play.load', m, create=True):
         with mock.patch(
                 'ansible.executor.task_queue_manager.TaskQueueManager.run',
                 m2,
                 create=True):
             t = pyansible.Role('test-role')
             self.assertTrue(t.run())
             self.assertIsNone(t.runtime_errors)
예제 #3
0
 def test_wrong_module_path(self):
     t = pyansible.Role('test-role', basedir='wrong/path')
     self.assertFalse(t.run())
     self.assertIn("the role 'test-role' was not found in wrong/path/roles",
                   t.runtime_errors)
예제 #4
0
 def test_no_ssh_key(self):
     t = pyansible.Role('test-role')
     self.assertIsNone(t._tqm._options.private_key_file)
예제 #5
0
 def test_ssh_key(self):
     t = pyansible.Role('test-role')
     t.ssh_key = 'ssh.key'
     self.assertIn('ssh.key', t._tqm._options.private_key_file)
예제 #6
0
 def test_wrong_vault_file(self):
     ex = AnsibleFileNotFound if pyansible.version_info < (
         2, 5) else AnsibleError
     with self.assertRaises(ex):
         pyansible.Role('test-role', vault_password_file='foobar')
예제 #7
0
 def test_remote(self):
     t = pyansible.Role('test-role', host='192.168.0.1')
     self.assertEqual(t.play['connection'], 'smart')
     self.assertEqual(t.play['hosts'], 'all')
     self.assertIn('roles', t.play)
예제 #8
0
 def test_local(self):
     t = pyansible.Role('test-role')
     self.assertEqual(t.play['connection'], 'local')
     self.assertEqual(t.play['hosts'], 'localhost')
     self.assertIn('roles', t.play)
예제 #9
0
 def test_name(self):
     t = pyansible.Role('test-role')
     self.assertEqual(t.name, 'roles')
예제 #10
0
 def test_no_roles(self):
     with self.assertRaises(TypeError):
         pyansible.Role()