diff options
| author | bnewbold <bnewbold@robocracy.org> | 2012-07-12 16:28:06 -0400 | 
|---|---|---|
| committer | bnewbold <bnewbold@robocracy.org> | 2012-07-12 16:28:06 -0400 | 
| commit | 47543de6fa707b8f82d9b7c9c8af0fda02971f0e (patch) | |
| tree | 01fd95c92633c79bb0bc1b222d0a595266e926f3 /test_exmachina.py | |
| parent | 420106d5a9823b81fe686789831dd2354bfaa678 (diff) | |
| download | exmachina-47543de6fa707b8f82d9b7c9c8af0fda02971f0e.tar.gz exmachina-47543de6fa707b8f82d9b7c9c8af0fda02971f0e.zip | |
documentation, cleanup
Diffstat (limited to 'test_exmachina.py')
| -rwxr-xr-x | test_exmachina.py | 59 | 
1 files changed, 59 insertions, 0 deletions
| diff --git a/test_exmachina.py b/test_exmachina.py new file mode 100755 index 0000000..6c2a97d --- /dev/null +++ b/test_exmachina.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python + +""" +To use with secret keys, do: + +    $ echo "<key>" | ./test.py -k + +""" + +import sys +import optparse +import logging +import socket + +import bjsonrpc +import bjsonrpc.connection +import augeas + +from exmachina import ExMachinaClient + +# ============================================================================= +# Command line handling +def main(): + +    socket_path="/tmp/exmachina.sock" +    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) +    sock.connect(socket_path) + +    secret_key = None +    if sys.argv[-1] == "-k": +        print "waiting for key on stdin..." +        secret_key = sys.stdin.readline() +        print "sent!" + +    print "========= Testing JSON-RPC connection" +    c = bjsonrpc.connection.Connection(sock) +    if secret_key: +        c.call.authenticate(secret_key) +    print "/*: %s" % c.call.augeas_match("/*") +    print "/augeas/*: %s" % c.call.augeas_match("/augeas/*") +    print "/etc/* files:" +    for name in c.call.augeas_match("/files/etc/*"): +        print "\t%s" % name +    print c.call.initd_status("bluetooth") +    print "hostname: %s" % c.call.augeas_get("/files/etc/hostname/*") +    print "localhost: %s" % c.call.augeas_get("/files/etc/hosts/1/canonical") +    sock.close() + +    print "========= Testing user client library" +    client = ExMachinaClient(secret_key=secret_key) +    print client.augeas.match("/files/etc/*") +    #print client.initd.restart("bluetooth") +    print client.initd.status("greentooth") +    print "(expect Error on the above line)" +    print client.initd.status("bluetooth") +    client.close() + +if __name__ == '__main__': +    main() | 
