summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/func.pod2
-rwxr-xr-xfunc/minion/module_loader.py10
-rw-r--r--func/minion/modules/rpms.py18
-rwxr-xr-xfunc/overlord/client.py32
-rw-r--r--test/unittest/test_client.py40
-rw-r--r--test/unittest/test_groups.py22
6 files changed, 78 insertions, 46 deletions
diff --git a/docs/func.pod b/docs/func.pod
index ead976d..5ee594b 100644
--- a/docs/func.pod
+++ b/docs/func.pod
@@ -4,7 +4,7 @@ Func -- Fedora Unified Network Controller.
=head1 SYNOPSIS
-func "*" list_minons
+func "*" list_minions
func target.example.org call module method [args ...]
diff --git a/func/minion/module_loader.py b/func/minion/module_loader.py
index 37bc515..3068ea8 100755
--- a/func/minion/module_loader.py
+++ b/func/minion/module_loader.py
@@ -32,9 +32,6 @@ def module_walker(topdir):
for filename in files:
# ASSUMPTION: all module files will end with .py, .pyc, .pyo
if filename[-3:] == ".py" or filename[-4:] == ".pyc" or filename[-4:] == ".pyo":
- # we don't really care about __init__ files, though we do requure them
- if filename[:8] == "__init__":
- continue
# the normpath is important, since we eventually replace /'s with .'s
# in the module name, and foo..bar doesnt work -akl
module_files.append(os.path.normpath("%s/%s" % (root, filename)))
@@ -59,9 +56,10 @@ def load_modules(blacklist=None):
module_name_part = fn[len(module_file_path):]
dirname, basename = os.path.split(module_name_part)
- if basename == "__init__.py":
- continue
- if basename[-3:] == ".py":
+ if basename[:8] == "__init__":
+ modname = dirname
+ dirname = ""
+ elif basename[-3:] == ".py":
modname = basename[:-3]
elif basename[-4:] in [".pyc", ".pyo"]:
modname = basename[:-4]
diff --git a/func/minion/modules/rpms.py b/func/minion/modules/rpms.py
index 34c4d50..ae26cb4 100644
--- a/func/minion/modules/rpms.py
+++ b/func/minion/modules/rpms.py
@@ -20,23 +20,25 @@ class RpmModule(func_module.FuncModule):
def inventory(self, flatten=True):
"""
Returns information on all installed packages.
- By default, 'flatten' is passed in as True, which makes printouts very clean in diffs
- for use by func-inventory. If you are writting another software application, using flatten=False will
- prevent the need to parse the returns.
+ By default, 'flatten' is passed in as True, which makes printouts very
+ clean in diffs for use by func-inventory. If you are writting another
+ software application, using flatten=False will prevent the need to
+ parse the returns.
"""
+ # I have not been able to get flatten=False to work if there
+ # is more than 491 entries in the dict -- ashcrow
ts = rpm.TransactionSet()
mi = ts.dbMatch()
results = []
for hdr in mi:
name = hdr['name']
- epoch = hdr['epoch']
- if epoch is None:
- epoch = 0
+ epoch = (hdr['epoch'] or 0)
version = hdr['version']
release = hdr['release']
arch = hdr['arch']
if flatten:
- results.append("%s %s %s %s %s" % (name,epoch,version,release,arch))
+ results.append("%s %s %s %s %s" % (name, epoch, version,
+ release, arch))
else:
- results.append([name,epoch,version,release,arch])
+ results.append([name, epoch, version, release, arch])
return results
diff --git a/func/overlord/client.py b/func/overlord/client.py
index e293f1c..3d00302 100755
--- a/func/overlord/client.py
+++ b/func/overlord/client.py
@@ -62,6 +62,23 @@ class CommandAutomagic(object):
return self.clientref.run(module,method,args,nforks=self.nforks)
+def get_groups():
+ group_class = groups.Groups()
+ return group_class.get_groups()
+
+
+def get_hosts_by_groupgoo(groups, groupgoo):
+ group_gloobs = groupgoo.split(':')
+ hosts = []
+ for group_gloob in group_gloobs:
+ if not group_gloob[0] == "@":
+ continue
+ if groups.has_key(group_gloob[1:]):
+ hosts = hosts + groups[group_gloob[1:]]
+ else:
+ print "group %s not defined" % each_gloob
+ return hosts
+
# ===================================
# this is a module level def so we can use it and isServer() from
# other modules with a Client class
@@ -83,22 +100,15 @@ def expand_servers(spec, port=51234, noglobs=None, verbose=None, just_fqdns=Fals
else:
return spec
- group_class = groups.Groups()
- group_dict = group_class.get_groups()
+ group_dict = get_groups()
all_hosts = []
all_certs = []
seperate_gloobs = spec.split(";")
- new_hosts = []
-
- # we notate groups with @foo annotation, so look for that in the hostnamegoo
- for each_gloob in seperate_gloobs:
- if each_gloob[0] == '@':
- if group_dict.has_key(each_gloob[1:]):
- new_hosts = new_hosts + group_dict[each_gloob[1:]]
- else:
- print "group %s not defined" % each_gloob
+
+ new_hosts = get_hosts_by_groupgoo(group_dict, spec)
+ seperate_gloobs = spec.split(";")
seperate_gloobs = seperate_gloobs + new_hosts
for each_gloob in seperate_gloobs:
actual_gloob = "%s/%s.cert" % (config.certroot, each_gloob)
diff --git a/test/unittest/test_client.py b/test/unittest/test_client.py
index f4d56cc..ed13c6a 100644
--- a/test/unittest/test_client.py
+++ b/test/unittest/test_client.py
@@ -288,23 +288,23 @@ class TestSystem(BaseTest):
pass
-
-class TestAsyncTest(BaseTest):
- module = "async.test"
- nforks=4
- async=True
- def test_sleep_async(self):
- job_id = self.client.test.sleep(5)
- print "job_id", job_id
- (return_code, results) = self.client.job_status(job_id)
-# self.assert_on_fault(results)
- print "return_code", return_code
- print "results", results
-
- def test_add_async(self):
- job_id = self.client.test.add(1,5)
- print "job_id", job_id
- (return_code, results) = self.client.job_status(job_id)
-# self.assert_on_fault(results)
- print "return_code", return_code
- print "results", results
+#import time
+#class TestAsyncTest(BaseTest):
+# module = "async.test"
+# nforks=1
+# async=True
+# def test_sleep_async(self):
+# job_id = self.client.test.sleep(5)
+# print "job_id", job_id
+# time.sleep(5)
+# (return_code, results) = self.client.job_status(job_id)
+# print "return_code", return_code
+# print "results", results
+#
+# def test_add_async(self):
+# job_id = self.client.test.add(1,5)
+# print "job_id", job_id
+# time.sleep(6)
+# (return_code, results) = self.client.job_status(job_id)
+# print "return_code", return_code
+ # print "results", results
diff --git a/test/unittest/test_groups.py b/test/unittest/test_groups.py
new file mode 100644
index 0000000..639022a
--- /dev/null
+++ b/test/unittest/test_groups.py
@@ -0,0 +1,22 @@
+#!/usr/bin/python
+
+# unit tests for group functionality in func
+
+import func.overlord.client as fc
+
+
+
+class TestGroups(object):
+
+ def test_expand_servers(self):
+ result = fc.expand_servers("*")
+ print result
+
+ def test_get_groups(self):
+ result = fc.get_groups()
+ print result
+
+ def test_get_hosts_by_groupgoo(self):
+ group_dict = fc.get_groups()
+ hosts = fc.get_hosts_by_groupgoo(group_dict, "@blippy")
+ print hosts