no longer rely on plcsh. Config will either import PLC.Shell or use xmlrpc, so use...
[tests.git] / qaapi / qa / tests / sync_person_key.py
index aa26046..d836964 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env /usr/share/plc_api/plcsh
+#!/usr/bin/python
 import os, sys
 from Test import Test
 from qa import utils
@@ -11,6 +11,7 @@ class sync_person_key(Test):
     """
 
     def make_keys(self, path, name):
+       
         if not os.path.isdir(path):
             os.mkdir(path)
         key_path = path + os.sep + name
@@ -18,6 +19,8 @@ class sync_person_key(Test):
         (stdout, stderr) = utils.popen(command)
 
     def call(self, email):
+       api = self.config.api
+       auth = self.config.auth
        email_parts = email.split("@")
        keys_filename = email_parts[0]
        keys_path = self.config.KEYS_PATH 
@@ -25,7 +28,7 @@ class sync_person_key(Test):
        public_key_path = private_key_path + ".pub"
        
        # Validate person
-       persons = GetPersons([email], ['person_id', 'key_ids'])
+       persons = api.GetPersons(auth, [email], ['person_id', 'key_ids'])
        if not persons:
            raise Exception, "No such person %(email)s"
        person = persons[0]
@@ -43,19 +46,19 @@ class sync_person_key(Test):
        public_key_file = open(public_key_path, 'r')
        public_key = public_key_file.readline()
                
-       keys = GetKeys(person['key_ids'])
+       keys = api.GetKeys(auth, person['key_ids'])
        if not keys:
            # Add current key to db
            key_fields = {'key_type': 'ssh',
                          'key': public_key}
-           AddPersonKey(person['person_id'], key_fields)
+           api.AddPersonKey(auth, person['person_id'], key_fields)
            if self.config.verbose:
                utils.header("Added public key in %(public_key_path)s to db" % locals() )
        else:
            # keys need to be checked and possibly updated
            key = keys[0]
            if key['key'] != public_key:
-               UpdateKey(key['key_id'], public_key)
+               api.UpdateKey(auth, key['key_id'], public_key)
                if self.config.verbose:
                    utils.header("Updated plc with new public key in %(public_key_path)s " % locals())
            else:
@@ -65,3 +68,4 @@ class sync_person_key(Test):
 if __name__ == '__main__':
     args = tuple(sys.argv[1:])
     sync_person_key()(*args)           
+