summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Macken <lmacken@redhat.com>2008-01-17 22:34:40 -0500
committerLuke Macken <lmacken@redhat.com>2008-01-17 22:34:40 -0500
commit061db7282409b779290eddce8e969b8544642a58 (patch)
treed260ee8dac6d5690127a030482cede6ce82ea02d
parent2643cf6e852807489d9ad2b30803ea62fef28c01 (diff)
parentcca8b7f4dc8af9ef5411ca299700132c9af5b9c8 (diff)
downloadfunc-061db7282409b779290eddce8e969b8544642a58.tar.gz
func-061db7282409b779290eddce8e969b8544642a58.tar.xz
func-061db7282409b779290eddce8e969b8544642a58.zip
Merge branch 'master' of ssh+git://git.fedorahosted.org/git/func
-rw-r--r--func/minion/modules/networktest.py16
-rw-r--r--test/unittest/test_client.py147
2 files changed, 159 insertions, 4 deletions
diff --git a/func/minion/modules/networktest.py b/func/minion/modules/networktest.py
index 5f54c5e..0e6fbb2 100644
--- a/func/minion/modules/networktest.py
+++ b/func/minion/modules/networktest.py
@@ -38,12 +38,22 @@ class NetworkTest(func_module.FuncModule):
self.__args_to_list(args))
def isportopen(self, host, port):
+ # FIXME: the return api here needs some work... -akl
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.connect((host, int(port)))
- data = sock.recv(2048)
+ timeout = 3.0
+ sock.settimeout(timeout)
+ try:
+ sock.connect((host, int(port)))
+ except socket.error, e:
+ sock.close()
+ return [1, ("connection to %s:%s failed" % (host, port), "%s" % e)]
+ except socket.timeout:
+ sock.close()
+ return [2, ("connection to %s:%s timed out after %s seconds" % (host, port, timeout))]
+
sock.close()
- return [line for line in data.split('\n')]
+ return [0, "connection to %s:%s succeeded" % (host, port)]
def __args_to_list(self, args):
return [arg for arg in args]
diff --git a/test/unittest/test_client.py b/test/unittest/test_client.py
index ef4cc11..12cb40b 100644
--- a/test/unittest/test_client.py
+++ b/test/unittest/test_client.py
@@ -16,9 +16,28 @@ class BaseTest:
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)
@@ -34,6 +53,7 @@ class TestTest(BaseTest):
class TestCommand(BaseTest):
+ module = "command"
def test_echo(self):
result = self.client.command.run("echo -n foo")
@@ -50,6 +70,7 @@ 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)
@@ -72,6 +93,7 @@ class TestCopyfile(BaseTest):
class TestHardware(BaseTest):
+ module = "hardware"
def test_inventory(self):
result = self.client.hardware.inventory()
assert type(result[self.th]) != xmlrpclib.Fault
@@ -90,6 +112,7 @@ class TestHardware(BaseTest):
class TestFileTracker(BaseTest):
fn = "/etc/hosts"
+ module = "filetracker"
def test_track(self):
result = self.client.filetracker.track(self.fn)
assert result[self.th] == 1
@@ -113,6 +136,7 @@ class TestFileTracker(BaseTest):
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
@@ -120,3 +144,124 @@ class TestMount(BaseTest):
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
+
+
+