summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xfunc/overlord/client.py26
-rw-r--r--func/overlord/groups.py95
-rwxr-xr-xtest/test-it.sh18
-rw-r--r--test/unittest/test_client.py26
4 files changed, 147 insertions, 18 deletions
diff --git a/func/overlord/client.py b/func/overlord/client.py
index 6e663ea..a848cb8 100755
--- a/func/overlord/client.py
+++ b/func/overlord/client.py
@@ -22,9 +22,11 @@ from func.config import read_config, CONFIG_FILE
import sslclient
import command
+import groups
import func.forkbomb as forkbomb
import func.jobthing as jobthing
+
# ===================================
# defaults
# TO DO: some of this may want to come from config later
@@ -68,6 +70,11 @@ def expand_servers(spec, port=51234, noglobs=None, verbose=None, just_fqdns=Fals
Given a regex/blob of servers, expand to a list
of server ids.
"""
+
+
+ # FIXME: we need to refactor expand_servers, it seems to do
+ # weird things, reload the config and groups config everytime it's
+ # called for one, which may or may not be bad... -akl
config = read_config(CONFIG_FILE, CMConfig)
if noglobs:
@@ -76,9 +83,23 @@ 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()
+
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
+
+ seperate_gloobs = seperate_gloobs + new_hosts
for each_gloob in seperate_gloobs:
actual_gloob = "%s/%s.cert" % (config.certroot, each_gloob)
certs = glob.glob(actual_gloob)
@@ -244,8 +265,9 @@ class Client(object):
else:
# globbing is not being used, but still need to make sure
# URI is well formed.
- expanded = expand_servers(self.server_spec, port=self.port, noglobs=True, verbose=self.verbose)[0]
- results = process_server(0, 0, expanded)
+ results = process_server(0, 0, self.servers)
+ #expanded = expand_servers(self.server_spec, port=self.port, noglobs=True, verbose=self.verbose)[0]
+# results = process_server(0, 0, expanded)
return results
diff --git a/func/overlord/groups.py b/func/overlord/groups.py
new file mode 100644
index 0000000..8eaf28e
--- /dev/null
+++ b/func/overlord/groups.py
@@ -0,0 +1,95 @@
+#!/usr/bin/python
+
+## func command line interface & client lib
+##
+## Copyright 2007,2008 Red Hat, Inc
+## Adrian Likins <alikins@redhat.com>
+## +AUTHORS
+##
+## 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.
+##
+
+
+# this module lets you define groups of systems to work with from the
+# commandline. It uses an "ini" style config parser like:
+
+#[groupname]
+#host = foobar, baz, blip
+#subgroup = blippy
+
+
+import ConfigParser
+import os
+
+
+class Groups(object):
+
+ def __init__(self, filename="/etc/func/groups"):
+ self.filename = filename
+ self.group_names = {}
+ self.groups = {}
+ self.__parse()
+
+ def __parse(self):
+
+ self.cp = ConfigParser.SafeConfigParser()
+ self.cp.read(self.filename)
+
+ for section in self.cp.sections():
+ self.add_group(section)
+ options = self.cp.options(section)
+ for option in options:
+ if option == "host":
+ self.add_hosts_to_group(section, self.cp.get(section, option))
+ if option == "subgroup":
+ pass
+
+
+ def show(self):
+ print self.cp.sections()
+ print self.groups
+
+ def add_group(self, group):
+ pass
+
+ def __parse_hoststrings(self, hoststring):
+ hosts = []
+ bits = hoststring.split(';')
+ for bit in bits:
+ blip = bit.strip().split(' ')
+ for host in blip:
+ if host not in hosts:
+ hosts.append(host.strip())
+
+ return hosts
+
+ def add_hosts_to_group(self, group, hoststring):
+ hosts = self.__parse_hoststrings(hoststring)
+ for host in hosts:
+ self.add_host_to_group(group, host)
+
+
+
+ def add_host_to_group(self, group, host):
+ if not self.groups.has_key(group):
+ self.groups[group] = []
+ self.groups[group].append(host)
+
+ def get_groups(self):
+ return self.groups
+
+
+
+def main():
+ g = Groups("/tmp/testgroups")
+ print g.show()
+
+
+
+if __name__ == "__main__":
+ main()
diff --git a/test/test-it.sh b/test/test-it.sh
index 72f3224..fd93d62 100755
--- a/test/test-it.sh
+++ b/test/test-it.sh
@@ -273,25 +273,13 @@ run_unittests
run_async_test
stop_the_func
-# see if funcd is running
-# see if certmaster is installed
-# see if cermtasterd is running
-
-# setup certs
-## see if we have certs set up properly
+# leaving the test cases with func not running is kind of
+# annoying, so restart it
+start_the_func
### probably do some stuff to test bad/no/malformed/unauthed certs as well
-# see if we can connect to funcd with the overloard
-
-# see what modules we have available
-# for each module, call the info stuff on them
-
-# / start walking over the modules, doing commandliney stuff to each, and
-# trying to check return data and return code as much as possible
-
-# test shut down of init scripts
diff --git a/test/unittest/test_client.py b/test/unittest/test_client.py
index b7c5e7b..f4d56cc 100644
--- a/test/unittest/test_client.py
+++ b/test/unittest/test_client.py
@@ -13,11 +13,16 @@ import socket
class BaseTest:
# assume we are talking to localhost
th = socket.gethostname()
+ nforks=1
+ async=False
+
def __init__(self):
pass
def setUp(self):
- self.client = fc.Client(self.th)
+ self.client = fc.Client(self.th,
+ nforks=self.nforks,
+ async=self.async)
def test_module_version(self):
mod = getattr(self.client, self.module)
@@ -284,3 +289,22 @@ class TestSystem(BaseTest):
+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