summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2008-01-23 12:38:46 -0500
committerMichael DeHaan <mdehaan@redhat.com>2008-01-23 12:38:46 -0500
commitce0eaca23fb42f77f67408e509bbe091f4c27e56 (patch)
treef0d331f83654869b619bd34e33a4fe1c884daa8a
parent504041eb26aba41092aa528e1a724fa5554063d7 (diff)
parentbf8fcc5ebd930a241ce56216e7e610d456be6a69 (diff)
downloadfunc-ce0eaca23fb42f77f67408e509bbe091f4c27e56.tar.gz
func-ce0eaca23fb42f77f67408e509bbe091f4c27e56.tar.xz
func-ce0eaca23fb42f77f67408e509bbe091f4c27e56.zip
Merge branch 'master' of ssh://git.fedoraproject.org/git/hosted/func
Conflicts: test/unittest/test_client.py
-rw-r--r--func/minion/modules/sysctl.py31
-rw-r--r--func/minion/modules/yumcmd.py4
-rwxr-xr-xscripts/func-create-module27
-rw-r--r--test/unittest/test_client.py90
4 files changed, 110 insertions, 42 deletions
diff --git a/func/minion/modules/sysctl.py b/func/minion/modules/sysctl.py
new file mode 100644
index 0000000..1f11d55
--- /dev/null
+++ b/func/minion/modules/sysctl.py
@@ -0,0 +1,31 @@
+# Copyright 2008, Red Hat, Inc
+# Luke Macken <lmacken@redhat.com>
+#
+# This software may be freely redistributed under the terms of the GNU
+# general public license.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+import func_module
+import sub_process
+
+class SysctlModule(func_module.FuncModule):
+
+ version = "0.0.1"
+ description = "Configure kernel parameters at runtime"
+
+ def __run(self, cmd):
+ cmd = sub_process.Popen(cmd.split(), stdout=sub_process.PIPE,
+ stderr=sub_process.PIPE, shell=False)
+ return [line for line in cmd.communicate()[0].strip().split('\n')]
+
+ def list(self):
+ return self.__run("/sbin/sysctl -a")
+
+ def get(self, name):
+ return self.__run("/sbin/sysctl -n %s" % name)
+
+ def set(self, name, value):
+ return self.__run("/sbin/sysctl -w %s=%s" % (name, value))
diff --git a/func/minion/modules/yumcmd.py b/func/minion/modules/yumcmd.py
index 7677c9a..f952372 100644
--- a/func/minion/modules/yumcmd.py
+++ b/func/minion/modules/yumcmd.py
@@ -11,7 +11,6 @@
import func_module
import yum
-from yum import repos
# XXX Use internal yum callback or write a useful one.
class DummyCallback(object):
@@ -46,5 +45,6 @@ class Yum(func_module.FuncModule):
ayum = yum.YumBase()
ayum.doConfigSetup()
ayum.doTsSetup()
- ayum.repos.enableRepo(repo)
+ if repo is not None:
+ ayum.repos.enableRepo(repo)
return map(str, ayum.doPackageLists('updates').updates)
diff --git a/scripts/func-create-module b/scripts/func-create-module
index cf05449..f2885e8 100755
--- a/scripts/func-create-module
+++ b/scripts/func-create-module
@@ -1,4 +1,6 @@
#!/usr/bin/env python
+#
+# Copyright 2008, Red Hat, Inc
# Steve 'Ashcrow' Milner <smilner@redhat.com>
# John Eckersberg <jeckersb@redhat.com>
#
@@ -10,6 +12,17 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
TEMPLATE = """\
+#
+# Copyright %s
+# %s <%s>
+#
+# This software may be freely redistributed under the terms of the GNU
+# general public license.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
import func_module
class %s(func_module.FuncModule):
@@ -32,19 +45,24 @@ METHOD_TEMPLATE = '''\
'''
-def populate_template(module_name, desc, methods):
+def populate_template(author_name, author_email, module_name, desc, methods):
"""
Makes the method strings and populates the template.
"""
+ from datetime import datetime
+
actual_methods = ""
for method in methods:
actual_methods += METHOD_TEMPLATE % method
- return TEMPLATE % (module_name, desc, actual_methods[:-2])
+ return TEMPLATE % (datetime.now().strftime("%Y"), author_name,
+ author_email, module_name, desc, actual_methods[:-2])
if __name__ == '__main__':
- module_name = raw_input("Name: ").capitalize()
+ module_name = raw_input("Module Name: ").capitalize()
desc = raw_input("Description: ")
+ author_name = raw_input("Author: ")
+ author_email = raw_input("Email: ")
methods = []
print "\nLeave blank to finish."
while True:
@@ -55,6 +73,7 @@ if __name__ == '__main__':
# Write it out to a file
file_name = "%s.py" % module_name.lower()
file_obj = open(file_name, "w")
- file_obj.write(populate_template(module_name, desc, methods))
+ file_obj.write(populate_template(author_name, author_email,
+ module_name, desc, methods))
file_obj.close()
print "Your module is ready to be hacked on. Wrote out to %s." % file_name
diff --git a/test/unittest/test_client.py b/test/unittest/test_client.py
index f4f2029..b7c5e7b 100644
--- a/test/unittest/test_client.py
+++ b/test/unittest/test_client.py
@@ -1,6 +1,7 @@
#!/usr/bin/python
import os
+import socket
import unittest
import xmlrpclib
@@ -10,7 +11,8 @@ import socket
class BaseTest:
- th = "mdehaan.rdu.redhat.com"
+ # assume we are talking to localhost
+ th = socket.gethostname()
def __init__(self):
pass
@@ -20,16 +22,20 @@ class BaseTest:
def test_module_version(self):
mod = getattr(self.client, self.module)
result = mod.module_version()
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
def test_module_api_version(self):
mod = getattr(self.client, self.module)
result = mod.module_api_version()
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
def test_module_description(self):
mod = getattr(self.client, self.module)
result = mod.module_description()
+ self.assert_on_fault(result)
+
+ # we do this all over the place...
+ def assert_on_fault(self, result):
assert type(result[self.th]) != xmlrpclib.Fault
test_module_version.intro = True
@@ -41,16 +47,14 @@ class TestTest(BaseTest):
module = "test"
def test_add(self):
result = self.client.test.add(1,5)
-
+ self.assert_on_fault(result)
assert result[self.th] == 6
def test_add_string(self):
result = self.client.test.add("foo", "bar")
-
+ self.assert_on_fault(result)
assert result[self.th] == "foobar"
- def tearDown(self):
- pass
class TestCommand(BaseTest):
@@ -58,11 +62,13 @@ class TestCommand(BaseTest):
def test_echo(self):
result = self.client.command.run("echo -n foo")
+ self.assert_on_fault(result)
assert result[self.th][1] == "foo"
def test_rpm(self):
result = self.client.command.run("rpm -q func")
+ self.assert_on_fault(result)
assert result[self.th][1].split("-")[0] == "func"
@@ -82,7 +88,9 @@ class TestCopyfile(BaseTest):
fb = open(self.fn,"r").read()
data = xmlrpclib.Binary(fb)
result = self.client.copyfile.copyfile(self.dest_fn, data)
+ self.assert_on_fault(result)
assert result[self.th] == 0
+
def test_checksum(self):
self.create_a_file()
@@ -90,6 +98,7 @@ class TestCopyfile(BaseTest):
data = xmlrpclib.Binary(fb)
result = self.client.copyfile.copyfile(self.dest_fn, data)
result = self.client.copyfile.checksum(self.dest_fn)
+ self.assert_on_fault(result)
assert result[self.th] == "b36a8040e44c16605d7784cdf1b3d9ed04ea7f55"
@@ -97,19 +106,20 @@ class TestHardware(BaseTest):
module = "hardware"
def test_inventory(self):
result = self.client.hardware.inventory()
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
def test_halinfo(self):
result = self.client.hardware.hal_info()
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
def test_info(self):
result = self.client.hardware.info()
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
+
def test_info_no_devices(self):
result = self.client.hardware.info(False)
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
class TestFileTracker(BaseTest):
fn = "/etc/hosts"
@@ -117,18 +127,19 @@ class TestFileTracker(BaseTest):
def test_track(self):
result = self.client.filetracker.track(self.fn)
assert result[self.th] == 1
+ self.assert_on_fault(result)
def test_inventory(self):
result = self.client.filetracker.track(self.fn)
result = self.client.filetracker.inventory(False)
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
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
+ self.assert_on_fault(result)
result_inv = self.client.filetracker.inventory(False)
tracked_files = result_inv[self.th]
for i in tracked_files:
@@ -140,9 +151,7 @@ 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
+ self.assert_on_fault(result)
# INSERT some clever way to test mount here
@@ -151,8 +160,8 @@ 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
-
+ self.assert_on_fault(result)
+
def test_ping_bad_arg(self):
result = self.client.networktest.ping(self.th)
# this should give us a FuncException
@@ -160,34 +169,34 @@ class TestNetworkTest(BaseTest):
def test_netstat(self):
result = self.client.networktest.netstat("-n")
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
def test_traceroute(self):
result = self.client.networktest.traceroute(self.th)
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
def test_dig(self):
result = self.client.networktest.dig("redhat.com")
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
def test_isportopen_closed_port(self):
result = self.client.networktest.isportopen(self.th, 34251)
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
def test_isportopen_open_port(self):
result = self.client.networktest.isportopen(self.th, 51234)
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
class TestProcess(BaseTest):
module = "process"
def test_info(self):
result = self.client.process.info()
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
def test_mem(self):
result = self.client.process.mem()
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
# FIXME: how to test kill/pkill? start a process with
# command and then kill it?
@@ -197,20 +206,20 @@ class TestService(BaseTest):
module = "service"
def test_inventory(self):
result = self.client.service.inventory()
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
def test_get_enabled(self):
result = self.client.service.get_enabled()
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
def test_get_running(self):
result = self.client.service.get_running()
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
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
+ self.assert_on_fault(result)
assert result[self.th] == 0
#FIXME: whats a good way to test starting/stoping services without
@@ -220,37 +229,46 @@ class TestRpm(BaseTest):
module = "rpms"
def test_inventory(self):
result = self.client.rpms.inventory()
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
class TestSmart(BaseTest):
module = "smart"
def test_info(self):
result = self.client.smart.info()
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
+class TestSysctl(BaseTest):
+ module = "sysctl"
+ def test_list(self):
+ result = self.client.sysctl.list()
+ self.assert_on_fault(result)
+
+ def test_get(self):
+ result = self.client.sysctl.get("kernel.max_lock_depth")
+ self.assert_on_fault(result)
+
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
+ self.assert_on_fault(result)
class TestSystem(BaseTest):
module = "system"
def test_list_methods(self):
result = self.client.system.list_methods()
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
def test_listMethods(self):
result = self.client.system.listMethods()
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
def test_list_modules(self):
result = self.client.system.list_modules()
- assert type(result[self.th]) != xmlrpclib.Fault
+ self.assert_on_fault(result)
#FIXME: we really should just implement these for the system stuff