added plcapi_urls step
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 5 Feb 2013 12:40:02 +0000 (13:40 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 5 Feb 2013 12:40:02 +0000 (13:40 +0100)
system/PlcapiUrlScanner.py [new file with mode: 0755]
system/TestPlc.py
system/url_scanner.py [deleted file]

diff --git a/system/PlcapiUrlScanner.py b/system/PlcapiUrlScanner.py
new file mode 100755 (executable)
index 0000000..d763557
--- /dev/null
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+#
+# this checks various forms of URLS for reaching a PLCAPI
+# i.e. with http:// or https:// (only the latter is expected to work)
+# with or without a trailing slash
+# using a hostname or an IP
+
+import socket
+import xmlrpclib
+import traceback
+
+class PlcapiUrlScanner:
+
+    # turns out the config has an ip but no name..
+    def __init__ (self, auth, hostname=None, ip=None, verbose=False):
+        self.auth=auth
+        if not hostname and not ip:
+            raise Exception,"PlcapiUrlScanner needs _some_ input"
+        if hostname:
+            if not ip: 
+                try:    ip=socket.gethostbyname(hostname)
+                except: 
+                    hostname="%s.pl.sophia.inria.fr"%hostname
+                    ip=socket.gethostbyname(hostname)
+        else:
+            if not hostname: hostname=socket.gethostbyaddr(ip)[0]
+        self.hostname=hostname
+        self.ip=ip
+        self.verbose=verbose
+        
+    def try_url (self,url):
+        try:
+            xmlrpclib.ServerProxy (url, verbose=self.verbose, allow_none=True).GetNodes(self.auth)
+            print 'YES',url
+            return True
+        except xmlrpclib.ProtocolError as e:
+            print '... (http error %s)'%e.errcode,url
+            return False
+        except Exception as e:
+            print '---',type(e).__name__,url
+            if self.verbose: traceback.print_exc()
+            return False
+
+    def try_url_expected (self, url, expected):
+        return self.try_url(url)==expected
+
+    def scan(self):
+        overall=True
+        for protocol in ['http','https']:
+            expected= protocol=='https'
+            for dest in [ self.hostname, self.ip ]:
+                for port in [ '',':80',':443']:
+                    for path in ['PLCAPI','PLCAPI/']:
+                        if protocol=='http' and port==':443': continue
+                        if protocol=='https' and port==':80': continue
+                        url="%s://%s%s/%s"%(protocol,dest,port,path)
+                        if not self.try_url_expected (url,expected): overall=False
+        return overall
+
+from optparse import OptionParser
+import sys
+
+auth={'AuthMethod':'password','Username':'root@test.onelab.eu','AuthString':'test++'}
+
+def main ():
+    usage="%prog hostname"
+    parser=OptionParser()
+    parser.add_option("-v","--verbose",dest='verbose',action='store_true',default=False)
+    (options,args)=parser.parse_args()
+    if len(args)!=1:
+        parser.print_help()
+        sys.exit(1)
+    hostname=args[0]
+    success=PlcapiUrlScanner (auth=auth, hostname=hostname,verbose=options.verbose).scan()
+    sys.exit(0 if success else -1)
+
+if __name__ == '__main__':
+    main()
index e3bd111..c6b8e90 100644 (file)
@@ -20,6 +20,7 @@ from TestBoxQemu import TestBoxQemu
 from TestSsh import TestSsh
 from TestApiserver import TestApiserver
 from TestAuthSfa import TestAuthSfa
+from PlcapiUrlScanner import PlcapiUrlScanner
 
 # step methods must take (self) and return a boolean (options is a member of the class)
 
@@ -83,7 +84,8 @@ class TestPlc:
         'show', SEP,
         'vs_delete','timestamp_vs','vs_create', SEP,
         'plc_install', 'plc_configure', 'plc_start', SEP,
-        'keys_fetch', 'keys_store', 'keys_clear_known_hosts', 'speed_up_slices', SEP,
+        'keys_fetch', 'keys_store', 'keys_clear_known_hosts', SEP,
+        'plcapi_urls','speed_up_slices', SEP,
         'initscripts', 'sites', 'nodes', 'slices', 'nodegroups', 'leases', SEP,
 # slices created under plcsh interactively seem to be fine but these ones don't have the tags
 # keep this our of the way for now
@@ -1139,6 +1141,9 @@ class TestPlc:
     @node_mapper
     def keys_clear_known_hosts (self): pass
     
+    def plcapi_urls (self):
+        return PlcapiUrlScanner (self.auth_root(),ip=self.vserverip).scan()
+
     def speed_up_slices (self):
         "tweak nodemanager settings on all nodes using a conf file"
         # create the template on the server-side 
diff --git a/system/url_scanner.py b/system/url_scanner.py
deleted file mode 100644 (file)
index fe73bf5..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-# a rough utility for testing xmlrpclib URL's
-import xmlrpclib
-auth={'AuthMethod':'password','Username':'root@test.onelab.eu','AuthString':'test++'}
-
-host='vplc21'
-
-import socket
-hostname="%s.pl.sophia.inria.fr"%host
-ip=socket.gethostbyname(hostname)
-
-import traceback
-verbose=True
-
-def try_url (url,xmlrpclib_verbose=False):
-    try:
-        xmlrpclib.ServerProxy (url, verbose=xmlrpclib_verbose, allow_none=True).GetNodes(auth)
-        print 'YES',url
-    except xmlrpclib.ProtocolError as e:
-        print '... (http error %s)'%e.errcode,url
-    except Exception as e:
-        print '---',type(e).__name__,url
-        if verbose: traceback.print_exc()
-
-def scan():
-    for protocol in ['http','https']:
-        for dest in [ hostname, ip ]:
-            for port in [ '',':80',':443']:
-#            for port in [ ':80',':443']:
-                for path in ['PLCAPI','PLCAPI/']:
-                    if protocol=='http' and port==':443': continue
-                    if protocol=='https' and port==':80': continue
-                    url="%s://%s%s/%s"%(protocol,dest,port,path)
-                    try_url (url)
-