Debian Codegraph @

test/units/modules/test_service_facts.py

raw
1 # -*- coding: utf-8 -*-
2 # Copyright (c) 2020 Ansible Project
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 from __future__ import annotations
6
7 import unittest
8 from unittest.mock import patch
9
10 from ansible.module_utils import basic
11 from ansible.modules.service_facts import AIXScanService
12
13
14 # AIX # lssrc -a
15 LSSRC_OUTPUT = """
16 Subsystem Group PID Status
17 sendmail mail 5243302 active
18 syslogd ras 5636528 active
19 portmap portmap 5177768 active
20 snmpd tcpip 5308844 active
21 hostmibd tcpip 5374380 active
22 snmpmibd tcpip 5439918 active
23 aixmibd tcpip 5505456 active
24 nimsh nimclient 5571004 active
25 aso 6029758 active
26 biod nfs 6357464 active
27 nfsd nfs 5701906 active
28 rpc.mountd nfs 6488534 active
29 rpc.statd nfs 7209216 active
30 rpc.lockd nfs 7274988 active
31 qdaemon spooler 6816222 active
32 writesrv spooler 6685150 active
33 clcomd caa 7471600 active
34 sshd ssh 7602674 active
35 pfcdaemon 7012860 active
36 ctrmc rsct 6947312 active
37 IBM.HostRM rsct_rm 14418376 active
38 IBM.ConfigRM rsct_rm 6160674 active
39 IBM.DRM rsct_rm 14680550 active
40 IBM.MgmtDomainRM rsct_rm 14090676 active
41 IBM.ServiceRM rsct_rm 13828542 active
42 cthats cthats 13959668 active
43 cthags cthags 14025054 active
44 IBM.StorageRM rsct_rm 12255706 active
45 inetd tcpip 12517828 active
46 lpd spooler inoperative
47 keyserv keyserv inoperative
48 ypbind yp inoperative
49 gsclvmd inoperative
50 cdromd inoperative
51 ndpd-host tcpip inoperative
52 ndpd-router tcpip inoperative
53 netcd netcd inoperative
54 tftpd tcpip inoperative
55 routed tcpip inoperative
56 mrouted tcpip inoperative
57 rsvpd qos inoperative
58 policyd qos inoperative
59 timed tcpip inoperative
60 iptrace tcpip inoperative
61 dpid2 tcpip inoperative
62 rwhod tcpip inoperative
63 pxed tcpip inoperative
64 binld tcpip inoperative
65 xntpd tcpip inoperative
66 gated tcpip inoperative
67 dhcpcd tcpip inoperative
68 dhcpcd6 tcpip inoperative
69 dhcpsd tcpip inoperative
70 dhcpsdv6 tcpip inoperative
71 dhcprd tcpip inoperative
72 dfpd tcpip inoperative
73 named tcpip inoperative
74 automountd autofs inoperative
75 nfsrgyd nfs inoperative
76 gssd nfs inoperative
77 cpsd ike inoperative
78 tmd ike inoperative
79 isakmpd inoperative
80 ikev2d inoperative
81 iked ike inoperative
82 clconfd caa inoperative
83 ksys_vmmon inoperative
84 nimhttp inoperative
85 IBM.SRVPROXY ibmsrv inoperative
86 ctcas rsct inoperative
87 IBM.ERRM rsct_rm inoperative
88 IBM.AuditRM rsct_rm inoperative
89 isnstgtd isnstgtd inoperative
90 IBM.LPRM rsct_rm inoperative
91 cthagsglsm cthags inoperative
92 """
93
94
95 class TestAIXScanService(unittest.TestCase):
96
97 def setUp(self):
98 self.mock1 = patch.object(basic.AnsibleModule, 'get_bin_path', return_value='/usr/sbin/lssrc')
99 self.mock1.start()
100 self.addCleanup(self.mock1.stop)
101 self.mock2 = patch.object(basic.AnsibleModule, 'run_command', return_value=(0, LSSRC_OUTPUT, ''))
102 self.mock2.start()
103 self.addCleanup(self.mock2.stop)
104 self.mock3 = patch('platform.system', return_value='AIX')
105 self.mock3.start()
106 self.addCleanup(self.mock3.stop)
107
108 def test_gather_services(self):
109 svcmod = AIXScanService(basic.AnsibleModule)
110 result = svcmod.gather_services()
111
112 self.assertIsInstance(result, dict)
113
114 self.assertIn('IBM.HostRM', result)
115 self.assertEqual(result['IBM.HostRM'], {
116 'name': 'IBM.HostRM',
117 'source': 'src',
118 'state': 'running',
119 })
120 self.assertIn('IBM.AuditRM', result)
121 self.assertEqual(result['IBM.AuditRM'], {
122 'name': 'IBM.AuditRM',
123 'source': 'src',
124 'state': 'stopped',
125 })