-
-
Notifications
You must be signed in to change notification settings - Fork 647
/
CobblerCliTestDirect.py
194 lines (155 loc) · 6.13 KB
/
CobblerCliTestDirect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import os
import re
import shlex
import unittest
from cobbler import utils
dummy_file_path = "/root/dummy"
def run_cmd(cmd):
"""
Run a command
@param cmd str command
@return str output
@raise Exception if return code is not 0
"""
print("run cmd: %s" % cmd)
args = shlex.split(cmd)
(output, rc) = utils.subprocess_sp(None, args, shell=False)
if rc != 0:
raise Exception
return output
def get_last_line(lines):
i = len(lines) - 1
while lines[i] == '' and i > 0:
i -= 1
return lines[i]
class CobblerCliTestDirect(unittest.TestCase):
"""
Tests Cobbler CLI direct commands
"""
def setUp(self):
"""
Set up
"""
return
def tearDown(self):
"""
Cleanup here
"""
return
def test_cobbler_version(self):
"""Runs 'cobbler version'"""
output = run_cmd("cobbler version")
line = output.split("\n")[0]
match_obj = re.match(r"Cobbler \d+\.\d+\.\d+", line)
self.assertTrue(match_obj is not None)
def test_cobbler_status(self):
"""Runs 'cobbler status'"""
output = run_cmd("cobbler status")
lines = output.split("\n")
match_obj = re.match(r"ip\s+|target\s+|start\s+|state\s+", lines[0])
self.assertTrue(match_obj is not None)
def test_cobbler_sync(self):
"""Runs 'cobbler sync'"""
output = run_cmd("cobbler sync")
lines = output.split("\n")
self.assertEqual("*** TASK COMPLETE ***", get_last_line(lines))
def test_cobbler_signature_report(self):
"""Runs 'cobbler signature report'"""
output = run_cmd("cobbler signature report")
lines = output.split("\n")
self.assertTrue("Currently loaded signatures:" == lines[0])
expected_output = r"\d+ breeds with \d+ total signatures loaded"
match_obj = re.match(expected_output, get_last_line(lines))
self.assertTrue(match_obj is not None)
def test_cobbler_signature_update(self):
"""Runs 'cobbler signature update'"""
output = run_cmd("cobbler signature update")
lines = output.split("\n")
self.assertEqual("*** TASK COMPLETE ***", get_last_line(lines))
def test_cobbler_acl_adduser(self):
"""Runs 'cobbler aclsetup --adduser'"""
output = run_cmd("cobbler aclsetup --adduser=cobbler")
# TODO: verify user acl exists on directories
def test_cobbler_acl_addgroup(self):
"""Runs 'cobbler aclsetup --addgroup'"""
output = run_cmd("cobbler aclsetup --addgroup=cobbler")
# TODO: verify group acl exists on directories
def test_cobbler_acl_removeuser(self):
"""Runs 'cobbler aclsetup --removeuser'"""
output = run_cmd("cobbler aclsetup --removeuser=cobbler")
# TODO: verify user acl no longer exists on directories
def test_cobbler_acl_removegroup(self):
"""Runs 'cobbler aclsetup --removegroup'"""
output = run_cmd("cobbler aclsetup --removegroup=cobbler")
# TODO: verify group acl no longer exists on directories
def test_cobbler_reposync(self):
"""Runs 'cobbler reposync'"""
output = run_cmd("cobbler reposync")
output = run_cmd("cobbler reposync --tries=3")
output = run_cmd("cobbler reposync --no-fail")
def test_cobbler_buildiso(self):
"""Runs 'cobbler buildiso'"""
output = run_cmd("cobbler buildiso")
lines = output.split("\n")
self.assertEqual("*** TASK COMPLETE ***", get_last_line(lines))
self.assertTrue(os.path.isfile("/root/generated.iso"))
def _assert_list_section(self, lines, start_line, section_name):
i = start_line
self.assertEqual(lines[i], "%s:" % section_name)
i += 1
while lines[i] != "":
i += 1
i += 1
return i
def test_11_cobbler_list(self):
output = run_cmd("cobbler list")
lines = output.split("\n")
i = 0
i = self._assert_list_section(lines, i, "distros")
i = self._assert_list_section(lines, i, "profiles")
i = self._assert_list_section(lines, i, "systems")
i = self._assert_list_section(lines, i, "repos")
i = self._assert_list_section(lines, i, "images")
i = self._assert_list_section(lines, i, "mgmtclasses")
i = self._assert_list_section(lines, i, "packages")
i = self._assert_list_section(lines, i, "files")
def _assert_report_section(self, lines, start_line, section_name):
i = start_line
self.assertEqual(lines[i], "%s:" % section_name)
i += 1
match_obj = re.match(r"=+$", lines[i].strip())
self.assertTrue(match_obj is not None)
i += 1
while i < len(lines) - 1 and re.match(r"=+$", lines[i + 1]) is None:
while i < len(lines) and lines[i] != "":
i += 1
while i < len(lines) and lines[i] == "":
i += 1
return i
def test_cobbler_report(self):
output = run_cmd("cobbler report")
lines = output.split("\n")
i = 0
i = self._assert_report_section(lines, i, "distros")
i = self._assert_report_section(lines, i, "profiles")
i = self._assert_report_section(lines, i, "systems")
i = self._assert_report_section(lines, i, "repos")
i = self._assert_report_section(lines, i, "images")
i = self._assert_report_section(lines, i, "mgmtclasses")
i = self._assert_report_section(lines, i, "packages")
i = self._assert_report_section(lines, i, "files")
def test_cobbler_getloaders(self):
output = run_cmd("cobbler get-loaders")
lines = output.split("\n")
self.assertEqual("*** TASK COMPLETE ***", get_last_line(lines))
def test_cobbler_hardlink(self):
# TODO: test cobbler hardlink
raise NotImplemented()
def test_cobbler_replicate(self):
# TODO: test cobbler replicate. Requires 2 test cobbler servers
raise NotImplemented()
def test_cobbler_validate_autoinstalls(self):
# TODO: test cobbler validateks
raise NotImplemented()
if __name__ == '__main__':
unittest.main()