Merge branch 'master' of ssh://git.planet-lab.org/git/sfa
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Wed, 6 Oct 2010 18:30:19 +0000 (14:30 -0400)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Wed, 6 Oct 2010 18:30:19 +0000 (14:30 -0400)
20 files changed:
Makefile
sfa/client/sfi.py
sfa/managers/registry_manager_pl.py
sfa/methods/GetCredential.py
sfa/methods/GetSelfCredential.py
sfa/methods/__init__.py
sfa/plc/api-dev.py
sfa/plc/api.py
sfa/server/sfa-server.py
sfa/server/sfa_component_setup.py
sfa/trust/auth.py
sfa/trust/credential.py
sfa/trust/credential_legacy.py
sfa/trust/hierarchy.py
sfa/trust/rights.py
sfa/util/xmlrpcprotocol.py
tests/testAll.py
tests/testNamespace.py [new file with mode: 0755]
tests/testRecord.py
tests/testRights.py

index 06f184c..1e0992b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -88,6 +88,7 @@ ifeq (,$(SSHURL))
        @exit 1
 else
        +$(RSYNC) ./sfa/ $(SSHURL)/usr/lib/python2.5/site-packages/sfa/
+       +$(RSYNC) ./tests/ $(SSHURL)/root/tests-sfa
        +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin
        $(SSHCOMMAND) exec service sfa restart
 endif
index d25c172..f7eecb3 100755 (executable)
@@ -313,6 +313,8 @@ class Sfi:
        self.key_file = key_file
        self.cert_file = cert_file
        self.cert = Certificate(filename=cert_file) 
+       # instruct xmlrpcprotocol to redirect logs to console_logger
+       self.options.client=True
        # Establish connection to server(s)
        self.logger.info("Contacting Registry at: %s"%reg_url)
        self.registry = xmlrpcprotocol.get_server(reg_url, key_file, cert_file, self.options)  
@@ -433,11 +435,11 @@ class Sfi:
                 if user_name.count(".") > 0:
                     user_name = user_name.replace(".", '_')
                     self.user = self.authority + "." + user_name
-                cred_str = self.registry.get_self_credential(cert_string, "user", hrn)
+                cred_str = self.registry.GetSelfCredential(cert_string, hrn, "user")
             else:
                 # bootstrap slice credential from user credential
                 user_cred = self.get_user_cred().save_to_string(save_parents=True)
-                cred_str = self.registry.get_credential(user_cred, type, hrn)
+                cred_str = self.registry.GetCredential(user_cred, hrn, type)
             
             if not cred_str:
                 self.logger.critical("Failed to get %s credential" % type)
index 1636eda..f5f4b48 100644 (file)
@@ -9,6 +9,7 @@ from sfa.util.namespace import *
 from sfa.trust.credential import *
 from sfa.trust.certificate import *
 from sfa.util.faults import *
+from sfa.trust.gid import create_uuid
 
 def get_version(api):
     version = {}
index 3acc3b1..9bd5cd1 100644 (file)
@@ -1,6 +1,4 @@
-### $Id: get_credential.py 17576 2010-04-05 20:56:15Z tmack $
-### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/get_credential.py $
-
+#
 from sfa.trust.credential import *
 from sfa.trust.rights import *
 from sfa.util.faults import *
@@ -12,7 +10,7 @@ from sfa.trust.credential import Credential
 class GetCredential(Method):
     """
     Retrive a credential for an object
-    If cred == None then the behavior reverts to get_self_credential
+    If cred == None then the behavior reverts to GetSelfCredential
 
     @param hrn human readable name of object (hrn or urn)
     @param cred credential object specifying rights of the caller
index 6bdc63d..fa8c3a1 100644 (file)
@@ -1,5 +1,3 @@
-### $Id: get_credential.py 15321 2009-10-15 05:01:21Z tmack $
-### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/get_credential.py $
 
 from sfa.trust.credential import *
 from sfa.trust.rights import *
@@ -33,7 +31,7 @@ class GetSelfCredential(Method):
 
     def call(self, cert, xrn, type):
         """
-        get_self_credential a degenerate version of get_credential used by a client
+        GetSelfCredential a degenerate version of GetCredential used by a client
         to get his initial credential when de doesnt have one. This is the same as
         get_credetial(..., cred = None, ...)
 
index fa26aa0..7c5ecf5 100644 (file)
@@ -1,4 +1,7 @@
 all = """
+GetCredential
+GetSelfCredential
+GetGids
 get_aggregates
 get_key
 get_registries
index 41ae35c..4a6d7a2 100644 (file)
@@ -360,9 +360,9 @@ class SfaAPI(BaseAPI):
             registry = registries[self.hrn]
             cert_string=self.cert.save_to_string(save_parents=True)
             # get self credential
-            self_cred = registry.get_self_credential(cert_string, type, self.hrn)
+            self_cred = registry.GetSelfCredential(cert_string, self.hrn, type)
             # get credential
-            cred = registry.get_credential(self_cred, type, self.hrn)
+            cred = registry.GetCredential(self_cred, type, self.hrn)
             
             # save cred to file
             Credential(string=cred).save_to_file(cred_filename, save_parents=True)
index 6da1188..8707405 100644 (file)
@@ -162,9 +162,9 @@ class SfaAPI(BaseAPI):
             registry = registries[self.hrn]
             cert_string=self.cert.save_to_string(save_parents=True)
             # get self credential
-            self_cred = registry.get_self_credential(cert_string, type, self.hrn)
+            self_cred = registry.GetSelfCredential(cert_string, self.hrn, type)
             # get credential
-            cred = registry.get_credential(self_cred, type, self.hrn)
+            cred = registry.GetCredential(self_cred, self.hrn, type)
             
             # save cred to file
             Credential(string=cred).save_to_file(cred_filename, save_parents=True)
@@ -654,7 +654,7 @@ class ComponentAPI(BaseAPI):
             # get credential from registry
             cert_str = Certificate(filename=cert_filename).save_to_string(save_parents=True)
             registry = self.get_registry()
-            cred = registry.get_self_credential(cert_str, 'node', hrn)
+            cred = registry.GetSelfCredential(cert_str, hrn, 'node')
             Credential(string=cred).save_to_file(credfile, save_parents=True)            
 
             return cred
@@ -670,7 +670,7 @@ class ComponentAPI(BaseAPI):
                 os.unlink(f)
 
         # install the new key pair
-        # get_credential will take care of generating the new keypair
+        # GetCredential will take care of generating the new keypair
         # and credential
         self.get_node_key()
         self.getCredential()
index 2685530..e3ad1a2 100755 (executable)
@@ -1,8 +1,5 @@
 #!/usr/bin/python
 #
-### $Id$
-### $URL$
-#
 # SFA PLC Wrapper
 #
 # This wrapper implements the SFA Registry and Slice Interfaces on PLC.
index 628ae7a..db1c965 100755 (executable)
@@ -146,7 +146,7 @@ def get_credential(registry=None, force=False, verbose=False):
         registry = get_server(url=registry, keyfile=keyfile, certfile=certfile)
         cert = Certificate(filename=certfile)
         cert_str = cert.save_to_string(save_parents=True)
-        cred = registry.GetSelfCredential(cert_str, hrn, 'node')    
+        cred = registry.GetSelfCredential(cert_str, 'node', hrn)
         Credential(string=cred).save_to_file(credfile, save_parents=True)
     
     return cred
index 9cb905d..b596d8d 100644 (file)
@@ -237,7 +237,7 @@ class Auth:
         verify_cancreate_credential()
         """
 
-        rl = RightList()
+        rl = Rights()
         type = record['type']
 
 
index 1c41b08..ebecedb 100644 (file)
@@ -35,15 +35,12 @@ from tempfile import mkstemp
 from xml.dom.minidom import Document, parseString
 from dateutil.parser import parse
 
+from sfa.util.faults import *
 from sfa.util.sfalogging import sfa_logger
 from sfa.trust.certificate import Keypair
 from sfa.trust.credential_legacy import CredentialLegacy
-from sfa.trust.rights import *
-from sfa.trust.gid import *
-from sfa.util.faults import *
-
-
-
+from sfa.trust.rights import Right, Rights
+from sfa.trust.gid import GID
 
 # Two years, in seconds 
 DEFAULT_CREDENTIAL_LIFETIME = 60 * 60 * 24 * 365 * 2
@@ -342,17 +339,17 @@ class Credential(object):
     ##
     # set the privileges
     #
-    # @param privs either a comma-separated list of privileges of a RightList object
+    # @param privs either a comma-separated list of privileges of a Rights object
 
     def set_privileges(self, privs):
         if isinstance(privs, str):
-            self.privileges = RightList(string = privs)
+            self.privileges = Rights(string = privs)
         else:
             self.privileges = privs
         
 
     ##
-    # return the privileges as a RightList object
+    # return the privileges as a Rights object
 
     def get_privileges(self):
         if not self.privileges:
@@ -590,7 +587,7 @@ class Credential(object):
 
         # Process privileges
         privs = cred.getElementsByTagName("privileges")[0]
-        rlist = RightList()
+        rlist = Rights()
         for priv in privs.getElementsByTagName("privilege"):
             kind = getTextNode(priv, "name")
             deleg = str2bool(getTextNode(priv, "can_delegate"))
index dc02941..b868f2d 100644 (file)
 
 import xmlrpclib
 
-from sfa.trust.certificate import Certificate
-from sfa.trust.rights import *
-from sfa.trust.gid import *
 from sfa.util.faults import *
+from sfa.trust.certificate import Certificate
+from sfa.trust.rights import Right,Rights
+from sfa.trust.gid import GID
 
 ##
 # Credential is a tuple:
@@ -110,16 +110,16 @@ class CredentialLegacy(Certificate):
     ##
     # set the privileges
     #
-    # @param privs either a comma-separated list of privileges of a RightList object
+    # @param privs either a comma-separated list of privileges of a Rights object
 
     def set_privileges(self, privs):
         if isinstance(privs, str):
-            self.privileges = RightList(string = privs)
+            self.privileges = Rights(string = privs)
         else:
             self.privileges = privs
 
     ##
-    # return the privileges as a RightList object
+    # return the privileges as a Rights object
 
     def get_privileges(self):
         if not self.privileges:
@@ -176,7 +176,7 @@ class CredentialLegacy(Certificate):
 
         privStr = dict.get("privileges", None)
         if privStr:
-            self.privileges = RightList(string = privStr)
+            self.privileges = Rights(string = privStr)
         else:
             self.privileges = None
 
index 4678964..1f8afcf 100644 (file)
@@ -206,7 +206,7 @@ class Hierarchy:
 
     def get_auth_info(self, xrn):
         hrn, type = urn_to_hrn(xrn)
-        sfa_logger.debug("Hierarchy: getting authority: " + hrn)
+        sfa_logger.debug("Hierarchy: xrn=%s, getting authority for hrn=%s"%(xrn,hrn))
         if not self.auth_exists(hrn):
             raise MissingAuthority(hrn)
 
index 59324e8..bb4dffe 100644 (file)
@@ -4,7 +4,7 @@
 #
 # Right - represents a single right
 #
-# RightList - represents a list of rights
+# Rights - represents a list of rights
 #
 # A right may allow several different operations. For example, the "info" right
 # allows "listslices", "listcomponentresources", etc.
@@ -24,9 +24,11 @@ privilege_table = {"authority": ["register", "remove", "update", "resolve", "lis
                    "sa": ["getticket", "redeemslice", "redeemticket", "createslice", "createsliver", "deleteslice", "deletesliver", "updateslice",
                           "getsliceresources", "getticket", "loanresources", "stopslice", "startslice", "renewsliver",
                           "deleteslice", "deletesliver", "resetslice", "listslices", "listnodes", "getpolicy", "sliverstatus"],
-                   "embed": ["getticket", "redeemslice", "redeemticket", "createslice", "createsliver", "renewsliver", "deleteslice", "deletesliver", "updateslice", "sliverstatus", "getsliceresources", "shutdown"],
+                   "embed": ["getticket", "redeemslice", "redeemticket", "createslice", "createsliver", "renewsliver", "deleteslice", 
+                             "deletesliver", "updateslice", "sliverstatus", "getsliceresources", "shutdown"],
                    "bind": ["getticket", "loanresources", "redeemticket"],
-                   "control": ["updateslice", "createslice", "createsliver", "renewsliver", "sliverstatus", "stopslice", "startslice", "deleteslice", "deletesliver", "resetslice", "getsliceresources", "getgids"],
+                   "control": ["updateslice", "createslice", "createsliver", "renewsliver", "sliverstatus", "stopslice", "startslice", 
+                               "deleteslice", "deletesliver", "resetslice", "getsliceresources", "getgids"],
                    "info": ["listslices", "listnodes", "getpolicy"],
                    "ma": ["setbootstate", "getbootstate", "reboot", "getgids", "gettrustedcerts"],
                    "operator": ["gettrustedcerts", "getgids"],                   
@@ -35,17 +37,17 @@ privilege_table = {"authority": ["register", "remove", "update", "resolve", "lis
 
 
 ##
-# Determine tje rights that an object should have. The rights are entirely
+# Determine the rights that an object should have. The rights are entirely
 # dependent on the type of the object. For example, users automatically
 # get "refresh", "resolve", and "info".
 #
 # @param type the type of the object (user | sa | ma | slice | node)
 # @param name human readable name of the object (not used at this time)
 #
-# @return RightList object containing rights
+# @return Rights object containing rights
 
 def determine_rights(type, name):
-    rl = RightList()
+    rl = Rights()
 
     # rights seem to be somewhat redundant with the type of the credential.
     # For example, a "sa" credential implies the authority right, because
@@ -132,9 +134,9 @@ class Right:
         return True
 
 ##
-# A RightList object represents a list of privileges.
+# A Rights object represents a list of privileges.
 
-class RightList:
+class Rights:
     ##
     # Create a new rightlist object, containing no rights.
     #
@@ -252,10 +254,10 @@ class RightList:
     # @param type the type of the object (user | sa | ma | slice | node)
     # @param name human readable name of the object (not used at this time)
     #
-    # @return RightList object containing rights
+    # @return Rights object containing rights
 
     def determine_rights(self, type, name):
-        rl = RightList()
+        rl = Rights()
 
         # rights seem to be somewhat redundant with the type of the credential.
         # For example, a "sa" credential implies the authority right, because
index afba6f3..d1fbe1e 100644 (file)
@@ -2,6 +2,8 @@
 
 import xmlrpclib
 
+from sfa.util.sfalogging import sfa_logger, console_logger
+
 ##
 # ServerException, ExceptionUnmarshaller
 #
@@ -51,11 +53,14 @@ class XMLRPCServerProxy(xmlrpclib.ServerProxy):
         verbose = False
         if self.options and self.options.debug:
             verbose = True
+        if self.options and hasattr(self.options,'client'):
+            XMLRPCServerProxy.logger=console_logger
+        else:
+            XMLRPCServerProxy.logger=sfa_logger
         xmlrpclib.ServerProxy.__init__(self, url, transport, allow_none=allow_none, verbose=verbose)
 
     def __getattr__(self, attr):
-        if self.options and self.options.verbose:
-            print "Calling xml-rpc method:", attr
+        XMLRPCServerProxy.logger.debug("Calling xml-rpc method:%s"%attr)
         return xmlrpclib.ServerProxy.__getattr__(self, attr)
 
 
index 9990ffc..ac3d47a 100755 (executable)
@@ -1,12 +1,18 @@
-from testRights import *
-from testCert import *
-from testGid import *
-from testCred import *
+#!/usr/bin/python
+from testNamespace import *
+# xxx broken-test
+#from testRights import *
+# xxx broken-test
+#from testCert import *
+# xxx broken-test
+#from testGid import *
+# xxx broken-test
+#from testCred import *
 from testKeypair import *
 from testMisc import *
-from testHierarchy import *
+# xxx broken-test
+#from testHierarchy import *
 from testRecord import *
-from testTable import *
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/tests/testNamespace.py b/tests/testNamespace.py
new file mode 100755 (executable)
index 0000000..7fc5e3c
--- /dev/null
@@ -0,0 +1,38 @@
+#!/usr/bin/python
+import sys
+import unittest
+
+from sfa.util.namespace import *
+
+class TestNamespace(unittest.TestCase):
+
+    hrns=[
+        ('plc.princeton.tmack','user'),
+        ('ple.inria.baris','user'),
+        ('emulab\.net.slice.jktest','slice'),
+        ]
+    
+    urns=[
+        'urn:publicid:IDN+emulab:net+slice+jktest',
+        'urn:publicid:IDN+emulab.net+slice+jktest',
+
+        ]
+
+    def test_hrns(self):
+        for (h,t) in TestNamespace.hrns:
+            print 'testing hrn',h,t
+            urn=hrn_to_urn(h,t)
+            (h1,t1) = urn_to_hrn(urn)
+            self.assertEqual(h1,h)
+            self.assertEqual(t1,t)
+            if h1!=h or t1!=t:
+                print "hrn->urn->hrn : MISMATCH with in=(%s,%s) -- out=(%s,%s) -- urn=%s"%(h,t,h1,t1,urn)
+
+    def test_urns(self):
+        for urn in TestNamespace.urns:
+            print 'testing urn',urn
+            (h,t)=urn_to_hrn(urn)
+            urn1 = hrn_to_urn(h,t)
+            self.assertEqual(urn1,urn)
+            if urn1!=urn:
+                print "urn->hrn->urn : MISMATCH with in=(%s) -- out=(%s) -- hrn=(%s,%s)"%(urn,urn1,h,t)
index 081a9bf..0eff8e8 100755 (executable)
@@ -1,7 +1,7 @@
 import unittest
 import xmlrpclib
 from sfa.trust.gid import *
-from sfa.trust.config import *
+from sfa.util.config import *
 from sfa.util.record import *
 
 class TestRecord(unittest.TestCase):
index a67a25f..a65c9dd 100755 (executable)
@@ -30,56 +30,56 @@ class TestRight(unittest.TestCase):
       self.assert_(not pright.is_superset(cright))
       self.assert_(not cright.is_superset(pright))
 
-class TestRightList(unittest.TestCase):
+class TestRights(unittest.TestCase):
     def setUp(self):
         pass
 
     def testInit(self):
         # create a blank right list
-        rightList = RightList()
+        rightList = Rights()
 
         # create a right list with "embed" in it
-        rightList = RightList(string="embed")
+        rightList = Rights(string="embed")
 
     def testAsString(self):
-        rightList = RightList()
+        rightList = Rights()
         self.assertEqual(rightList.save_to_string(), "")
 
-        rightList = RightList(string="embed")
+        rightList = Rights(string="embed")
         self.assertEqual(rightList.save_to_string(), "embed")
 
-        rightList = RightList(string="embed,resolve")
+        rightList = Rights(string="embed,resolve")
         self.assertEqual(rightList.save_to_string(), "embed,resolve")
 
     def testCanPerform(self):
-        rightList = RightList(string="embed")
+        rightList = Rights(string="embed")
         self.assert_(rightList.can_perform("getticket"))
         self.assert_(not rightList.can_perform("resolve"))
 
-        rightList = RightList(string="embed,resolve")
+        rightList = Rights(string="embed,resolve")
         self.assert_(rightList.can_perform("getticket"))
         self.assert_(rightList.can_perform("resolve"))
 
     def testIsSuperset(self):
-        pRightList = RightList(string="sa")
-        cRightList = RightList(string="embed")
-        self.assert_(pRightList.is_superset(cRightList))
-        self.assert_(not cRightList.is_superset(pRightList))
-
-        pRightList = RightList(string="embed")
-        cRightList = RightList(string="embed")
-        self.assert_(pRightList.is_superset(cRightList))
-        self.assert_(cRightList.is_superset(pRightList))
-
-        pRightList = RightList(string="control")
-        cRightList = RightList(string="embed")
-        self.assert_(not pRightList.is_superset(cRightList))
-        self.assert_(not cRightList.is_superset(pRightList))
-
-        pRightList = RightList(string="control,sa")
-        cRightList = RightList(string="embed")
-        self.assert_(pRightList.is_superset(cRightList))
-        self.assert_(not cRightList.is_superset(pRightList))
+        pRights = Rights(string="sa")
+        cRights = Rights(string="embed")
+        self.assert_(pRights.is_superset(cRights))
+        self.assert_(not cRights.is_superset(pRights))
+
+        pRights = Rights(string="embed")
+        cRights = Rights(string="embed")
+        self.assert_(pRights.is_superset(cRights))
+        self.assert_(cRights.is_superset(pRights))
+
+        pRights = Rights(string="control")
+        cRights = Rights(string="embed")
+        self.assert_(not pRights.is_superset(cRights))
+        self.assert_(not cRights.is_superset(pRights))
+
+        pRights = Rights(string="control,sa")
+        cRights = Rights(string="embed")
+        self.assert_(pRights.is_superset(cRights))
+        self.assert_(not cRights.is_superset(pRights))
 
 
 if __name__ == "__main__":