diff options
-rw-r--r-- | examples/drive_checker.py | 2 | ||||
-rw-r--r-- | examples/find_recalled_parts.py | 2 | ||||
-rw-r--r-- | examples/service_checker.py | 2 | ||||
-rw-r--r-- | func/minion/modules/jobs.py | 2 | ||||
-rwxr-xr-x | func/overlord/client.py | 22 | ||||
-rw-r--r-- | func/overlord/cmd_modules/call.py | 14 | ||||
-rw-r--r-- | func/overlord/cmd_modules/check.py | 7 | ||||
-rw-r--r-- | func/overlord/cmd_modules/copyfile.py | 12 | ||||
-rw-r--r-- | func/overlord/cmd_modules/listminions.py | 12 | ||||
-rw-r--r-- | func/overlord/cmd_modules/ping.py | 9 | ||||
-rw-r--r-- | func/overlord/cmd_modules/show.py | 12 | ||||
-rwxr-xr-x | func/overlord/inventory.py | 6 | ||||
-rwxr-xr-x | func/overlord/test_func.py | 10 | ||||
-rw-r--r-- | funcweb/funcweb/controllers.py | 6 | ||||
-rw-r--r-- | test/async_test.py | 20 | ||||
-rw-r--r-- | test/unittest/test_client.py | 104 |
16 files changed, 130 insertions, 112 deletions
diff --git a/examples/drive_checker.py b/examples/drive_checker.py index f563c76..e51e378 100644 --- a/examples/drive_checker.py +++ b/examples/drive_checker.py @@ -7,7 +7,7 @@ import func.overlord.client as fc import func.utils as utils -info = fc.Client("*").smart.info() +info = fc.Overlord("*").smart.info() failures = 0 for (host,details) in info.iteritems(): diff --git a/examples/find_recalled_parts.py b/examples/find_recalled_parts.py index 45eb48e..36c4a7c 100644 --- a/examples/find_recalled_parts.py +++ b/examples/find_recalled_parts.py @@ -8,7 +8,7 @@ import func.utils as utils bad = open("./part_data.txt").read().split() -info = fc.Client("*").hardware.hal_info() +info = fc.Overlord("*").hardware.hal_info() for (host,details) in info.iteritems(): diff --git a/examples/service_checker.py b/examples/service_checker.py index 5541619..3dc683f 100644 --- a/examples/service_checker.py +++ b/examples/service_checker.py @@ -29,7 +29,7 @@ if __name__ == '__main__': sys.exit(1) # Get the information from the systems - info = fc.Client("*").service.status(service) + info = fc.Overlord("*").service.status(service) for (host, details) in info.iteritems(): status = "OFF" if details == 0: diff --git a/func/minion/modules/jobs.py b/func/minion/modules/jobs.py index 90c7421..97d203f 100644 --- a/func/minion/modules/jobs.py +++ b/func/minion/modules/jobs.py @@ -1,5 +1,5 @@ ## (Largely internal) module for access to asynchoronously dispatched -## module job ID's. The Func Client() module wraps most of this usage +## module job ID's. The Func Overlord() module wraps most of this usage ## so it's not entirely relevant to folks using the CLI or Func API ## directly. ## diff --git a/func/overlord/client.py b/func/overlord/client.py index 26b1cca..299fb5d 100755 --- a/func/overlord/client.py +++ b/func/overlord/client.py @@ -83,7 +83,7 @@ class CommandAutomagic(object): # =================================== # this is a module level def so we can use it and isServer() from -# other modules with a Client class +# other modules with a Overlord class class Minions(object): def __init__(self, spec, port=51234, @@ -153,7 +153,9 @@ def is_minion(minion_string): return minions.is_minion() -class Client(object): + + +class Overlord(object): def __init__(self, server_spec, port=DEFAULT_PORT, interactive=False, verbose=False, noglobs=False, nforks=1, config=None, async=False, init_ssl=True): @@ -225,9 +227,9 @@ class Client(object): So, it enables stuff like this: - Client("*.example.org").yum.install("foo") + Overlord("*.example.org").yum.install("foo") - # WARNING: any missing values in Client's source will yield + # WARNING: any missing values in Overlord's source will yield # strange errors with this engaged. Be aware of that. """ @@ -239,7 +241,7 @@ class Client(object): """ Use this to acquire status from jobs when using run with async client handles """ - return jobthing.job_status(jobid, client_class=Client) + return jobthing.job_status(jobid, client_class=Overlord) # ----------------------------------------------- @@ -250,7 +252,7 @@ class Client(object): returns. The returns may include exception objects. - If Client() was constructed with noglobs=True, the return is instead + If Overlord() was constructed with noglobs=True, the return is instead just a single value, not a hash. """ @@ -352,3 +354,11 @@ class Client(object): if x > max: max = x return max + + +class Client(Overlord): + def __init__(self, *args, **kwargs): + Overlord.__init__(self, *args, **kwargs) + # we can remove this if folks want -akl + print "Client() class is deprecated, please use the Overlord() class." + diff --git a/func/overlord/cmd_modules/call.py b/func/overlord/cmd_modules/call.py index 7add5bf..ea16975 100644 --- a/func/overlord/cmd_modules/call.py +++ b/func/overlord/cmd_modules/call.py @@ -77,8 +77,8 @@ class Call(client.command.Command): if self.options.rawprint: return data - - return pprint.pformat(data) + + return pprint.pformat(data) def do(self, args): @@ -103,9 +103,13 @@ class Call(client.command.Command): # or some sort of shared datastruct? self.server_spec = self.parentCommand.server_spec - client_obj = client.Client(self.server_spec,port=self.port,interactive=True, - verbose=self.verbose, config=self.config, nforks=self.options.forks) - results = client_obj.run(self.module, self.method, self.method_args) + overlord_obj = client.Overlord(self.server_spec,port=self.port, + interactive=True, + verbose=self.verbose, + config=self.config, + nforks=self.options.forks) + results = overlord_obj.run(self.module, self.method, self.method_args) + # TO DO: add multiplexer support # probably as a higher level module. diff --git a/func/overlord/cmd_modules/check.py b/func/overlord/cmd_modules/check.py index 446e6de..b360df6 100644 --- a/func/overlord/cmd_modules/check.py +++ b/func/overlord/cmd_modules/check.py @@ -82,14 +82,15 @@ class CheckAction(client.command.Command): # construct a client handle and see if any hosts are reachable self.server_spec = self.parentCommand.server_spec - client_obj = client.Client( + overlord_obj = client.Overlord( self.server_spec, port=self.port, interactive=False, verbose=False, config=self.config - ) - results = client_obj.test.add(1,2) + ) + + results = overlord_obj.test.add(1,2) hosts = results.keys() if len(hosts) == 0: print "* no systems have signed certs" diff --git a/func/overlord/cmd_modules/copyfile.py b/func/overlord/cmd_modules/copyfile.py index 295aeab..a149d5d 100644 --- a/func/overlord/cmd_modules/copyfile.py +++ b/func/overlord/cmd_modules/copyfile.py @@ -49,11 +49,11 @@ class CopyFile(client.command.Command): def do(self, args): self.server_spec = self.parentCommand.server_spec - client_obj = client.Client(self.server_spec, - port=self.port, - interactive=False, - verbose=self.options.verbose, - config=self.config) + overlord_obj = client.Overlord(self.server_spec, + port=self.port, + interactive=False, + verbose=self.options.verbose, + config=self.config) try: @@ -69,5 +69,5 @@ class CopyFile(client.command.Command): data = xmlrpclib.Binary(fb) - results = client_obj.run("copyfile", "copyfile", [self.options.remotepath, data, + results = overlord_obj.run("copyfile", "copyfile", [self.options.remotepath, data, mode, uid, gid]) diff --git a/func/overlord/cmd_modules/listminions.py b/func/overlord/cmd_modules/listminions.py index 9421b8d..fbfc282 100644 --- a/func/overlord/cmd_modules/listminions.py +++ b/func/overlord/cmd_modules/listminions.py @@ -37,13 +37,13 @@ class ListMinions(client.command.Command): def do(self, args): self.server_spec = self.parentCommand.server_spec - client_obj = client.Client(self.server_spec, - port=self.port, - interactive=False, - verbose=self.options.verbose, - config=self.config) + overlord_obj = client.Overlord(self.server_spec, + port=self.port, + interactive=False, + verbose=self.options.verbose, + config=self.config) - results = client_obj.test.add(1,2) + results = overlord_obj.test.add(1,2) servers = results.keys() servers.sort() diff --git a/func/overlord/cmd_modules/ping.py b/func/overlord/cmd_modules/ping.py index 438e2a9..a94fa70 100644 --- a/func/overlord/cmd_modules/ping.py +++ b/func/overlord/cmd_modules/ping.py @@ -57,10 +57,13 @@ class Ping(client.command.Command): for server in servers: - client_obj = client.Client(server,port=self.options.port,interactive=False, - verbose=self.options.verbose,config=self.config, noglobs=True) + overlord_obj = client.Overlord(server,port=self.options.port, + interactive=False, + verbose=self.options.verbose, + config=self.config, noglobs=True) - results = client_obj.run("test", "ping", []) + results = overlord_obj.run("test", "ping", []) + print "results", results, type(results) if results == 1: print "[ ok ... ] %s" % server else: diff --git a/func/overlord/cmd_modules/show.py b/func/overlord/cmd_modules/show.py index e1df554..8963082 100644 --- a/func/overlord/cmd_modules/show.py +++ b/func/overlord/cmd_modules/show.py @@ -48,13 +48,13 @@ class ShowHardware(client.command.Command): self.server_spec = self.parentCommand.parentCommand.server_spec - client_obj = client.Client(self.server_spec, - port=self.port, - interactive=False, - verbose=self.options.verbose, - config=self.config) + overlord_obj = client.Overlord(self.server_spec, + port=self.port, + interactive=False, + verbose=self.options.verbose, + config=self.config) - results = client_obj.run("hardware", "info", []) + results = overlord_obj.run("hardware", "info", []) # if the user top_options = ["port","verbose"] diff --git a/func/overlord/inventory.py b/func/overlord/inventory.py index 8302a1c..d1dcf67 100755 --- a/func/overlord/inventory.py +++ b/func/overlord/inventory.py @@ -76,7 +76,7 @@ class FuncInventory(object): self.git_setup(options) # see what modules each host provides (as well as what hosts we have) - host_methods = func_client.Client(options.server_spec).system.list_methods() + host_methods = func_client.Overlord(options.server_spec).system.list_methods() # call all remote info methods and handle them if options.verbose: @@ -106,8 +106,8 @@ class FuncInventory(object): if not "all" in filtered_function_list and not method_name in filtered_function_list: continue - client = func_client.Client(host,noglobs=True) # ,noglobs=True) - results = getattr(getattr(client,module_name),method_name)() + overlord = func_client.Overlord(host,noglobs=True) # ,noglobs=True) + results = getattr(getattr(overlord,module_name),method_name)() if self.options.verbose: print "-- %s: running: %s %s" % (host, module_name, method_name) self.save_results(options, host, module_name, method_name, results) diff --git a/func/overlord/test_func.py b/func/overlord/test_func.py index 2b3f041..4c08a56 100755 --- a/func/overlord/test_func.py +++ b/func/overlord/test_func.py @@ -15,11 +15,11 @@ TEST_SMART = True if TEST_GETATTR: import func.overlord.client as func_client - print func_client.Client("*").hardware.pci_info() - #print func_client.Client("*").test.add(1,2) - #print func_client.Client("*").hardware.info() - #print func_client.Client("*").run("hardware","info",[]) - #print func_client.Client(socket.gethostname(),noglobs=True).test.add("1","2") + print func_client.Overlord("*").hardware.pci_info() + #print func_client.Overlord("*").test.add(1,2) + #print func_client.Overlord("*").hardware.info() + #print func_client.Overlord("*").run("hardware","info",[]) + #print func_client.Overlord(socket.gethostname(),noglobs=True).test.add("1","2") sys.exit(1) # get a connecton (to be replaced by client lib logic) diff --git a/funcweb/funcweb/controllers.py b/funcweb/funcweb/controllers.py index eb2327f..b45d81b 100644 --- a/funcweb/funcweb/controllers.py +++ b/funcweb/funcweb/controllers.py @@ -2,7 +2,7 @@ import logging log = logging.getLogger(__name__) from turbogears import controllers, expose, flash, identity, redirect -from func.overlord.client import Client, Minions +from func.overlord.client import Overlord, Minions class Root(controllers.RootController): @@ -24,7 +24,7 @@ class Root(controllers.RootController): methods. If a method is supplied, it will display a method execution form. """ - fc = Client(name) + fc = Overlord(name) if not module: # list all modules modules = fc.system.list_modules() return dict(modules=modules) @@ -41,7 +41,7 @@ class Root(controllers.RootController): @expose(template="funcweb.templates.run") @identity.require(identity.not_anonymous()) def run(self, minion="*", module=None, method=None, arguments=''): - fc = Client(minion) + fc = Overlord(minion) results = getattr(getattr(fc, module), method)(*arguments.split()) cmd = "%s.%s.%s(%s)" % (minion, module, method, arguments) return dict(cmd=cmd, results=results) diff --git a/test/async_test.py b/test/async_test.py index 04f6fd5..8e6961d 100644 --- a/test/async_test.py +++ b/test/async_test.py @@ -1,4 +1,4 @@ -from func.overlord.client import Client +from func.overlord.client import Overlord import func.jobthing as jobthing import time import sys @@ -14,28 +14,28 @@ TESTS = [ SLOW_COMMAND, QUICK_COMMAND, RAISES_EXCEPTION_COMMAND, FAKE_COMMAND ] def __tester(async,test): if async: - client = Client("*",nforks=10,async=True) + overlord= Overlord("*",nforks=10,async=True) oldtime = time.time() job_id = -411 print "======================================================" if test == SLOW_COMMAND: print "TESTING command that sleeps %s seconds" % TEST_SLEEP - job_id = client.test.sleep(TEST_SLEEP) + job_id = overlord.test.sleep(TEST_SLEEP) elif test == QUICK_COMMAND: print "TESTING a quick command" - job_id = client.test.add(1,2) + job_id = overlord.test.add(1,2) elif test == RAISES_EXCEPTION_COMMAND: print "TESTING a command that deliberately raises an exception" - job_id = client.test.explode() # doesn't work yet + job_id = overlord.test.explode() # doesn't work yet elif test == FAKE_COMMAND: print "TESTING a command that does not exist" - job_id = client.test.does_not_exist(1,2) # ditto + job_id = overlord.test.does_not_exist(1,2) # ditto print "======================================================" print "job_id = %s" % job_id while True: - status = client.job_status(job_id) + status = overlord.job_status(job_id) (code, results) = status nowtime = time.time() delta = int(nowtime - oldtime) @@ -56,9 +56,9 @@ def __tester(async,test): print "job not found: %s, %s elapased" % (code, delta) time.sleep(1) else: - print Client("*",nforks=10,async=False).test.sleep(5) - print Client("*",nforks=10,async=False).test.bork(5) - print Client("*",nforks=1,async=False).test.bork(5) + print Overlord("*",nforks=10,async=False).test.sleep(5) + print Overlord("*",nforks=10,async=False).test.bork(5) + print Overlord("*",nforks=1,async=False).test.bork(5) for t in TESTS: __tester(True,t) diff --git a/test/unittest/test_client.py b/test/unittest/test_client.py index 302c101..5e885cd 100644 --- a/test/unittest/test_client.py +++ b/test/unittest/test_client.py @@ -22,32 +22,32 @@ class BaseTest: pass def setUp(self): - self.client = fc.Client(self.th, - nforks=self.nforks, - async=self.async) + self.overlord = fc.Overlord(self.th, + nforks=self.nforks, + async=self.async) def test_module_version(self): - mod = getattr(self.client, self.module) + mod = getattr(self.overlord, self.module) result = mod.module_version() self.assert_on_fault(result) def test_module_api_version(self): - mod = getattr(self.client, self.module) + mod = getattr(self.overlord, self.module) result = mod.module_api_version() self.assert_on_fault(result) def test_module_description(self): - mod = getattr(self.client, self.module) + mod = getattr(self.overlord, self.module) result = mod.module_description() self.assert_on_fault(result) def test_module_list_methods(self): - mod = getattr(self.client, self.module) + mod = getattr(self.overlord, self.module) result = mod.list_methods() self.assert_on_fault(result) def test_module_inventory(self): - mod = getattr(self.client, self.module) + mod = getattr(self.overlord, self.module) result = mod.list_methods() res = result[self.th] @@ -74,12 +74,12 @@ class BaseTest: class TestTest(BaseTest): module = "test" def test_add(self): - result = self.client.test.add(1,5) + result = self.overlord.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") + result = self.overlord.test.add("foo", "bar") self.assert_on_fault(result) assert result[self.th] == "foobar" @@ -88,7 +88,7 @@ class TestTest(BaseTest): class TestCommand(BaseTest): module = "command" def test_echo(self): - result = self.client.command.run("echo -n foo") + result = self.overlord.command.run("echo -n foo") self.assert_on_fault(result) assert result[self.th][1] == "foo" @@ -96,7 +96,7 @@ class TestCommand(BaseTest): def test_rpm(self): # looksing for some package that should be there, rh specific # ish at the moment - result = self.client.command.run("rpm -q filesystem") + result = self.overlord.command.run("rpm -q filesystem") self.assert_on_fault(result) assert result[self.th][1].split("-")[0] == "filesystem" @@ -117,7 +117,7 @@ class TestCopyfile(BaseTest): self.create_a_file() fb = open(self.fn,"r").read() data = xmlrpclib.Binary(fb) - result = self.client.copyfile.copyfile(self.dest_fn, data) + result = self.overlord.copyfile.copyfile(self.dest_fn, data) self.assert_on_fault(result) assert result[self.th] == 0 @@ -126,8 +126,8 @@ class TestCopyfile(BaseTest): self.create_a_file() fb = open(self.fn,"r").read() data = xmlrpclib.Binary(fb) - result = self.client.copyfile.copyfile(self.dest_fn, data) - result = self.client.copyfile.checksum(self.dest_fn) + result = self.overlord.copyfile.copyfile(self.dest_fn, data) + result = self.overlord.copyfile.checksum(self.dest_fn) self.assert_on_fault(result) assert result[self.th] == "b36a8040e44c16605d7784cdf1b3d9ed04ea7f55" @@ -135,42 +135,42 @@ class TestCopyfile(BaseTest): class TestHardware(BaseTest): module = "hardware" def test_inventory(self): - result = self.client.hardware.inventory() + result = self.overlord.hardware.inventory() self.assert_on_fault(result) def test_halinfo(self): - result = self.client.hardware.hal_info() + result = self.overlord.hardware.hal_info() self.assert_on_fault(result) def test_info(self): - result = self.client.hardware.info() + result = self.overlord.hardware.info() self.assert_on_fault(result) def test_info_no_devices(self): - result = self.client.hardware.info(False) + result = self.overlord.hardware.info(False) self.assert_on_fault(result) class TestFileTracker(BaseTest): fn = "/etc/hosts" module = "filetracker" def test_track(self): - result = self.client.filetracker.track(self.fn) + result = self.overlord.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) + result = self.overlord.filetracker.track(self.fn) + result = self.overlord.filetracker.inventory(False) self.assert_on_fault(result) assert self.fn in result[self.th][0] # 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) + result = self.overlord.filetracker.track(self.fn) + result = self.overlord.filetracker.untrack(self.fn) self.assert_on_fault(result) - result_inv = self.client.filetracker.inventory(False) + result_inv = self.overlord.filetracker.inventory(False) tracked_files = result_inv[self.th] for i in tracked_files: if i[0] == self.fn: @@ -180,7 +180,7 @@ class TestFileTracker(BaseTest): class TestMount(BaseTest): module = "mount" def test_mount_list(self): - result = self.client.mount.list() + result = self.overlord.mount.list() self.assert_on_fault(result) # INSERT some clever way to test mount here @@ -189,43 +189,43 @@ class TestMount(BaseTest): class TestNetworkTest(BaseTest): module = "networktest" def test_ping(self): - result = self.client.networktest.ping(self.th, "-c", "2") + result = self.overlord.networktest.ping(self.th, "-c", "2") self.assert_on_fault(result) def test_ping_bad_arg(self): - result = self.client.networktest.ping(self.th) + result = self.overlord.networktest.ping(self.th) # this should give us a FuncException foo = func.utils.is_error(result[self.th]) def test_netstat(self): - result = self.client.networktest.netstat("-n") + result = self.overlord.networktest.netstat("-n") self.assert_on_fault(result) def test_traceroute(self): - result = self.client.networktest.traceroute(self.th) + result = self.overlord.networktest.traceroute(self.th) self.assert_on_fault(result) def test_dig(self): - result = self.client.networktest.dig("redhat.com") + result = self.overlord.networktest.dig("redhat.com") self.assert_on_fault(result) def test_isportopen_closed_port(self): - result = self.client.networktest.isportopen(self.th, 34251) + result = self.overlord.networktest.isportopen(self.th, 34251) self.assert_on_fault(result) def test_isportopen_open_port(self): - result = self.client.networktest.isportopen(self.th, 51234) + result = self.overlord.networktest.isportopen(self.th, 51234) self.assert_on_fault(result) class TestProcess(BaseTest): module = "process" def test_info(self): - result = self.client.process.info() + result = self.overlord.process.info() self.assert_on_fault(result) def test_mem(self): - result = self.client.process.mem() + result = self.overlord.process.mem() self.assert_on_fault(result) # FIXME: how to test kill/pkill? start a process with @@ -235,20 +235,20 @@ class TestProcess(BaseTest): class TestService(BaseTest): module = "service" def test_inventory(self): - result = self.client.service.inventory() + result = self.overlord.service.inventory() self.assert_on_fault(result) def test_get_enabled(self): - result = self.client.service.get_enabled() + result = self.overlord.service.get_enabled() self.assert_on_fault(result) def test_get_running(self): - result = self.client.service.get_running() + result = self.overlord.service.get_running() 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]) + running_data = self.overlord.service.get_running()[self.th] + result = self.overlord.service.status(running_data[0][0]) self.assert_on_fault(result) #FIXME: whats a good way to test starting/stoping services without @@ -257,46 +257,46 @@ class TestService(BaseTest): class TestRpm(BaseTest): module = "rpms" def test_inventory(self): - result = self.client.rpms.inventory() + result = self.overlord.rpms.inventory() self.assert_on_fault(result) class TestSmart(BaseTest): module = "smart" def test_info(self): - result = self.client.smart.info() + result = self.overlord.smart.info() self.assert_on_fault(result) class TestSysctl(BaseTest): module = "sysctl" def test_list(self): - result = self.client.sysctl.list() + result = self.overlord.sysctl.list() self.assert_on_fault(result) def test_get(self): - result = self.client.sysctl.get("kernel.max_lock_depth") + result = self.overlord.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() + result = self.overlord.yumcmd.check_update() self.assert_on_fault(result) class TestSystem(BaseTest): module = "system" def test_list_methods(self): - result = self.client.system.list_methods() + result = self.overlord.system.list_methods() self.assert_on_fault(result) def test_listMethods(self): - result = self.client.system.listMethods() + result = self.overlord.system.listMethods() self.assert_on_fault(result) def test_list_modules(self): - result = self.client.system.list_modules() + result = self.overlord.system.list_modules() self.assert_on_fault(result) @@ -319,17 +319,17 @@ class TestSystem(BaseTest): # nforks=1 # async=True # def test_sleep_async(self): -# job_id = self.client.test.sleep(5) +# job_id = self.overlord.test.sleep(5) # print "job_id", job_id # time.sleep(5) -# (return_code, results) = self.client.job_status(job_id) +# (return_code, results) = self.overlord.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) +# job_id = self.overlord.test.add(1,5) # print "job_id", job_id # time.sleep(6) -# (return_code, results) = self.client.job_status(job_id) +# (return_code, results) = self.overlord.job_status(job_id) # print "return_code", return_code # print "results", results |