jumpserver/apps/ops/ansible/test_runner.py

59 lines
1.5 KiB
Python
Raw Normal View History

2017-12-06 10:31:51 +00:00
# -*- coding: utf-8 -*-
#
import unittest
import sys
sys.path.insert(0, "../..")
from ops.ansible.runner import AdHocRunner, CommandRunner
2017-12-10 16:29:25 +00:00
from ops.ansible.inventory import BaseInventory
2017-12-06 10:31:51 +00:00
class TestAdHocRunner(unittest.TestCase):
def setUp(self):
host_data = [
{
"hostname": "testserver",
"ip": "192.168.244.185",
2017-12-06 10:31:51 +00:00
"port": 22,
"username": "root",
"password": "redhat",
},
]
2017-12-10 16:29:25 +00:00
inventory = BaseInventory(host_data)
self.runner = AdHocRunner(inventory)
2017-12-06 10:31:51 +00:00
def test_run(self):
tasks = [
2017-12-07 05:01:33 +00:00
{"action": {"module": "shell", "args": "ls"}, "name": "run_cmd"},
{"action": {"module": "shell", "args": "whoami"}, "name": "run_whoami"},
2017-12-06 10:31:51 +00:00
]
ret = self.runner.run(tasks, "all")
print(ret.results_summary)
print(ret.results_raw)
class TestCommandRunner(unittest.TestCase):
def setUp(self):
host_data = [
{
"hostname": "testserver",
"ip": "192.168.244.168",
"port": 22,
"username": "root",
"password": "redhat",
},
]
2017-12-10 16:29:25 +00:00
inventory = BaseInventory(host_data)
self.runner = CommandRunner(inventory)
2017-12-06 10:31:51 +00:00
def test_execute(self):
res = self.runner.execute('ls', 'all')
print(res.results_command)
2017-12-07 05:01:33 +00:00
print(res.results_raw)
2017-12-06 10:31:51 +00:00
if __name__ == "__main__":
unittest.main()