diff options
author | Adrian Likins <alikins@redhat.com> | 2008-07-16 13:05:02 -0400 |
---|---|---|
committer | Adrian Likins <alikins@redhat.com> | 2008-07-16 13:05:02 -0400 |
commit | cb311639535aa5a1bf80bfeb3cbf1954df472c5c (patch) | |
tree | ecbea965cf5abc4a3a90cbc0b0c4f9464c73334b | |
parent | 139d9ab8bc7deae4c1167bc5da1ffb478c433037 (diff) | |
download | func-cb311639535aa5a1bf80bfeb3cbf1954df472c5c.tar.gz func-cb311639535aa5a1bf80bfeb3cbf1954df472c5c.tar.xz func-cb311639535aa5a1bf80bfeb3cbf1954df472c5c.zip |
func-transmit: handle lists of client globs. Not sure this is the correct
approach, but it seems to mostly work for now
test_func_transmit.py:
more test cases for func-transmit
-rw-r--r-- | scripts/func-transmit | 21 | ||||
-rw-r--r-- | test/unittest/test_func_transmit.py | 52 |
2 files changed, 69 insertions, 4 deletions
diff --git a/scripts/func-transmit b/scripts/func-transmit index e43714f..677b1a6 100644 --- a/scripts/func-transmit +++ b/scripts/func-transmit @@ -30,8 +30,10 @@ method: run parameters: "/bin/echo Hello World" """ +import string import sys import distutils.sysconfig +import optparse import func.yaml as yaml # FIXME: need to subpackage this as part of Func import func.overlord.func_command as func_command @@ -44,12 +46,25 @@ params = yaml.load(input).next() # scan arguments +def is_a_list(item): + if type(item) in [type([]), type(())]: + return True + return False + +# slightly odd, but we expect clients to be a string we parse +# out later (glob and group expansion, etc). So if it is a list, +# flatten it into a string. clients = params.get('clients', "*") +if is_a_list(clients): + clients = string.join(clients,';') + + method = params.get('method','unknown') if method == "list_minions": - server_spec = "*" - minion_set = fc.Minions(server_spec) + # clients will default to * if not specified, and specifing is a good + # way to see who is in what group, etc, so pass it though + minion_set = fc.Minions(clients) servers = minion_set.get_all_hosts() servers.sort() results = servers @@ -68,7 +83,7 @@ else: method_handle = getattr(module_handle, method) if parameters is not None: # listify if we get something thats not a list - if type(parameters) not in [type([]), type(())]: + if not is_a_list(parameters): parameters = [parameters] results = method_handle(*parameters) else: diff --git a/test/unittest/test_func_transmit.py b/test/unittest/test_func_transmit.py index 70578ec..2c5fa23 100644 --- a/test/unittest/test_func_transmit.py +++ b/test/unittest/test_func_transmit.py @@ -69,7 +69,57 @@ class TestListMinion(BaseTest): out = self.call({'clients': '*', 'method': 'list_minions'}) - print out + def test_list_minions_no_match(self): + out = self.call({'clients': 'somerandom-name-that-shouldnt-be-a_real_host_name', + 'method': 'list_minions'}) + assert out == [] + + def test_list_minions_group_name(self): + out = self.call({'clients': '@test', + 'method': 'list_minions'}) + + def test_list_minions_no_clients(self): + out = self.call({'method': 'list_minions'}) + + + +class TestClientGlob(BaseTest): + + def _test_add(self, client): + result = self.call({'clients': client, + 'method': 'add', + 'module': 'test', + 'parameters': [1,2]}) + self.assert_on_fault(result) + return result + + def test_single_client(self): + result = self._test_add(self.th) + + def test_glob_client(self): + result = self._test_add("*") + + def test_glob_list(self): + result = self._test_add([self.th, self.th]) + + def test_glob_string_list(self): + result = self._test_add("%s;*" % self.th) + + # note, needs a /etc/func/group setup with the proper groups defined + # need to figure out a good way to test this... -akl + def test_group(self): + result = self._test_add("@test") + + def test_group_and_glob(self): + result = self._test_add("@test;*") + + def test_list_of_groups(self): + result = self._test_add(["@test", "@test2"]) + + def test_string_list_of_groups(self): + result = self._test_add("@test;@test2") + + class TestTest(BaseTest): |