From a6efb74bfb7f13a2c3149dda21c09e1f8ce4208e Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Fri, 18 Jan 2008 17:18:05 -0500 Subject: do some refactoring talk to localhost by default instead of "grimlock.devel.redhat.com" --- test/unittest/test_client.py | 79 ++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/test/unittest/test_client.py b/test/unittest/test_client.py index 12cb40b..d5e3d87 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 @@ -9,7 +10,8 @@ import func.overlord.client as fc class BaseTest: - th = "grimlock.devel.redhat.com" + # assume we are talking to localhost + th = socket.gethostname() def __init__(self): pass @@ -19,16 +21,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 @@ -40,16 +46,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): @@ -57,11 +61,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" @@ -81,7 +87,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() @@ -89,6 +97,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" @@ -96,19 +105,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" @@ -116,18 +126,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: @@ -139,9 +150,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 @@ -150,8 +159,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 @@ -159,34 +168,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? @@ -196,20 +205,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 @@ -219,37 +228,37 @@ 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 TestYum(BaseTest): module = "yumcmd" def test_check_update(self): result = self.client.yumcmd.check_update() - assert type(result[self.th]) != xmlrpclib.Fault + self.assert_on_fault(result) 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 + 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 -- cgit From 705fee9daec0f056af8eff869498bedc9398face Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Fri, 18 Jan 2008 17:27:20 -0500 Subject: remove a seemingly unneeded import that was causing this module to fail on fc7 also, allow no repos to be specified in check_update() --- func/minion/modules/yumcmd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) -- cgit From 03ae1fa69c8c364be9aca2ac5eb1745383c8910d Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Fri, 18 Jan 2008 17:27:55 -0500 Subject: removed unneeded print statement --- test/unittest/test_client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unittest/test_client.py b/test/unittest/test_client.py index d5e3d87..f201da5 100644 --- a/test/unittest/test_client.py +++ b/test/unittest/test_client.py @@ -243,7 +243,6 @@ class TestYum(BaseTest): def test_check_update(self): result = self.client.yumcmd.check_update() self.assert_on_fault(result) - print result class TestSystem(BaseTest): module = "system" -- cgit From beba6363a0d81196f8ccc5d5a84084447e5c09d7 Mon Sep 17 00:00:00 2001 From: Steve 'Ashcrow' Milner Date: Sun, 20 Jan 2008 20:10:09 -0500 Subject: Added in copyright and traditional comment header for new modules. --- scripts/func-create-module | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) 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 # John Eckersberg # @@ -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 -- cgit From 383af275af983f3aceed941b457eb27fac6518d4 Mon Sep 17 00:00:00 2001 From: Luke Macken Date: Mon, 21 Jan 2008 21:46:23 -0500 Subject: SysctlModule. This allows you to tweak your minions kernel parameters at runtime. --- func/minion/modules/sysctl.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 func/minion/modules/sysctl.py 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 +# +# 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)) -- cgit From bf8fcc5ebd930a241ce56216e7e610d456be6a69 Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Wed, 23 Jan 2008 09:19:04 -0500 Subject: some unit tests for the sysctl module --- test/unittest/test_client.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/unittest/test_client.py b/test/unittest/test_client.py index f201da5..d5d0e73 100644 --- a/test/unittest/test_client.py +++ b/test/unittest/test_client.py @@ -238,6 +238,16 @@ class TestSmart(BaseTest): 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): -- cgit