summaryrefslogtreecommitdiffstats
path: root/test/unittest/test_client.py
blob: 12cb40bfccb957bf22f362cedbedd3239ebdd93c (plain)
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/usr/bin/python

import os
import unittest
import xmlrpclib

import func.overlord.client as fc



class BaseTest:
    th = "grimlock.devel.redhat.com"
    def __init__(self):
        pass

    def setUp(self):
        self.client = fc.Client(self.th)

    def test_module_version(self):
        mod = getattr(self.client, self.module)
        result = mod.module_version()
        assert type(result[self.th]) != xmlrpclib.Fault

    def test_module_api_version(self):
        mod = getattr(self.client, self.module)
        result = mod.module_api_version()        
        assert type(result[self.th]) != xmlrpclib.Fault

    def test_module_description(self):
        mod = getattr(self.client, self.module)
        result = mod.module_description()
        assert type(result[self.th]) != xmlrpclib.Fault

    test_module_version.intro = True
    test_module_api_version.intro = True
    test_module_description.intro = True


class TestTest(BaseTest):
    module = "test"
    def test_add(self):
        result = self.client.test.add(1,5)

        assert result[self.th] == 6

    def test_add_string(self):
        result = self.client.test.add("foo", "bar")

        assert result[self.th] == "foobar"

    def tearDown(self):
        pass


class TestCommand(BaseTest):
    module = "command"
    def test_echo(self):
        result = self.client.command.run("echo -n foo")

        assert result[self.th][1] == "foo"

    def test_rpm(self):
        result = self.client.command.run("rpm -q func")

        assert result[self.th][1].split("-")[0] == "func"



class TestCopyfile(BaseTest):
    fn = "/tmp/func_test_file"
    dest_fn = "/tmp/func_test_file_dest"
    content = "this is a func test file"
    module = "copyfile"
    def create_a_file(self):
        f = open(self.fn, "w")
        f.write(self.content)
        f.close()

    def test_copyfile(self):
        self.create_a_file()
        fb = open(self.fn,"r").read()
        data = xmlrpclib.Binary(fb)
        result = self.client.copyfile.copyfile(self.dest_fn, data)
        assert result[self.th]  == 0
 
    def test_checksum(self):
        self.create_a_file()
        fb = open(self.fn,"r").read()
        data = xmlrpclib.Binary(fb)
        result = self.client.copyfile.copyfile(self.dest_fn, data)
        result = self.client.copyfile.checksum(self.dest_fn)
        assert result[self.th] == "b36a8040e44c16605d7784cdf1b3d9ed04ea7f55"
        

class TestHardware(BaseTest):
    module = "hardware"
    def test_inventory(self):
        result = self.client.hardware.inventory()
        assert type(result[self.th]) != xmlrpclib.Fault

    def test_halinfo(self):
        result = self.client.hardware.hal_info()
        assert type(result[self.th]) != xmlrpclib.Fault

    def test_info(self):
        result = self.client.hardware.info()
        assert type(result[self.th]) != xmlrpclib.Fault

    def test_info_no_devices(self):
        result = self.client.hardware.info(False)
        assert type(result[self.th]) != xmlrpclib.Fault

class TestFileTracker(BaseTest):
    fn = "/etc/hosts"
    module = "filetracker"
    def test_track(self):
        result = self.client.filetracker.track(self.fn)
        assert result[self.th] == 1

    def test_inventory(self):
        result = self.client.filetracker.track(self.fn)
        result = self.client.filetracker.inventory(False)
        assert type(result[self.th]) != xmlrpclib.Fault 
        assert result[self.th][0][0] == "/etc/hosts"
        assert result[self.th][0][3] == 0

    def test_untrack(self):
        result = self.client.filetracker.track(self.fn)
        result = self.client.filetracker.untrack(self.fn)
        assert type(result[self.th]) != xmlrpclib.Fault
        result_inv = self.client.filetracker.inventory(False)
        tracked_files = result_inv[self.th]
        for i in tracked_files:
            if i[0] == self.fn:
                assert "%s was not properly untracked" % self.fn


class TestMount(BaseTest):
    module = "mount"
    def test_mount_list(self):
        result = self.client.mount.list()
        #FIXME: I probably should make the test for xmlrpclib faults a bit
        #       more automagic
        assert type(result[self.th]) != xmlrpclib.Fault

    # INSERT some clever way to test mount here


class TestNetworkTest(BaseTest):
    module = "networktest"
    def test_ping(self):
        result = self.client.networktest.ping(self.th, "-c", "2")
        assert type(result[self.th]) != xmlrpclib.Fault
    
    def test_ping_bad_arg(self):
         result = self.client.networktest.ping(self.th)
         # this should give us a FuncException
         assert type(result[self.th]) == xmlrpclib.Fault
         
    def test_netstat(self):
        result = self.client.networktest.netstat("-n")
        assert type(result[self.th]) != xmlrpclib.Fault

    def test_traceroute(self):
        result = self.client.networktest.traceroute(self.th)
        assert type(result[self.th]) != xmlrpclib.Fault

    def test_dig(self):
        result = self.client.networktest.dig("redhat.com")
        assert type(result[self.th]) != xmlrpclib.Fault

    def test_isportopen_closed_port(self):
        result = self.client.networktest.isportopen(self.th, 34251)
        assert type(result[self.th]) != xmlrpclib.Fault

    def test_isportopen_open_port(self):
        result = self.client.networktest.isportopen(self.th, 51234)
        assert type(result[self.th]) != xmlrpclib.Fault


class TestProcess(BaseTest):
    module = "process"
    def test_info(self):
        result = self.client.process.info()
        assert type(result[self.th]) != xmlrpclib.Fault

    def test_mem(self):
        result = self.client.process.mem()
        assert type(result[self.th]) != xmlrpclib.Fault

    # FIXME: how to test kill/pkill? start a process with
    #        command and then kill it?


class TestService(BaseTest):
    module = "service"
    def test_inventory(self):
        result = self.client.service.inventory()
        assert type(result[self.th]) != xmlrpclib.Fault
    
    def test_get_enabled(self):
        result = self.client.service.get_enabled()
        assert type(result[self.th]) != xmlrpclib.Fault

    def test_get_running(self):
        result = self.client.service.get_running()
        assert type(result[self.th]) != xmlrpclib.Fault

    def test_get_status(self):
        running_data = self.client.service.get_running()[self.th]
        result = self.client.service.status(running_data[0][0])
        assert type(result[self.th]) != xmlrpclib.Fault
        assert result[self.th] == 0

        #FIXME: whats a good way to test starting/stoping services without
        #       doing bad things? -akl

class TestRpm(BaseTest):
    module = "rpms"
    def test_inventory(self):
        result = self.client.rpms.inventory()
        assert type(result[self.th]) != xmlrpclib.Fault


class TestSmart(BaseTest):
    module = "smart"
    def test_info(self):
        result = self.client.smart.info()
        assert type(result[self.th]) != xmlrpclib.Fault
    

class TestYum(BaseTest):
    module = "yumcmd"
    def test_check_update(self):
        result = self.client.yumcmd.check_update()
        assert type(result[self.th]) != xmlrpclib.Fault
        print result

class TestSystem(BaseTest):
    module = "system"
    def test_list_methods(self):
        result = self.client.system.list_methods()
        assert type(result[self.th]) != xmlrpclib.Fault

    
    def test_listMethods(self):
        result = self.client.system.listMethods()
        assert type(result[self.th]) != xmlrpclib.Fault
    
    def test_list_modules(self):
        result = self.client.system.list_modules()
        assert type(result[self.th]) != xmlrpclib.Fault


    #FIXME: we really should just implement these for the system stuff
    #       as well
    def test_module_version(self):
        pass

    def test_module_api_version(self):
        pass

    def test_module_description(self):
        pass