[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

extras-buildsys/utils package-builder.py,1.1,1.2



Author: dcbw

Update of /cvs/fedora/extras-buildsys/utils
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv23432/utils

Modified Files:
	package-builder.py 
Log Message:
2005-06-14  Dan Williams <dcbw redhat com>

    * client/buildclient.py
        - Write mock output to a log on failure

    * server/buildmaster.py -> server/BuildMaster.py

    * server/BuildJob.py
      server/UserInterface.py
      server/buildserver.py
        - Fix for buildmaster.py -> BuildMaster.py

    * server/BuildJob.py
      server/BuildMaster.py
        - BuildMaster object now has a 'createrepo' method, which BuildJobs
            call when they need to update the repo.  BuildMaster.createrepo() is
            locked so that we never run two createrepos at the same time

    * server/CONFIG.py
        - Clarify some options

    * server/UserInterface.py
        - Remove list_waiting_jobs and list_building_jobs, we now have a more
            flexible "list_jobs" interface that will be extended to allow more
            search parameters
        - In update_clients(), return new clients that we've found

    * server/client_manager.py
        - Print out clients we find when we start up
        - In update_clients(), return new clients that we've found

    * utils/package-builder.py
        - Implement most of remaining functionality:
            - hook up enqueue and enqueue_srpm commands
            - Add a list_own_jobs command
            - grab user's email address from certificate or ~/.package-builder
        - Allow non-SSL connections to build server




Index: package-builder.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/utils/package-builder.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- package-builder.py	14 Jun 2005 01:16:31 -0000	1.1
+++ package-builder.py	15 Jun 2005 04:10:08 -0000	1.2
@@ -18,6 +18,9 @@
 import SSLXMLRPCServerProxy
 import ConfigParser
 import M2Crypto
+import M2Crypto.m2xmlrpclib
+import M2Crypto.X509
+import socket
 
 
 config = ConfigParser.ConfigParser()
@@ -28,65 +31,191 @@
 config.set('Certs', 'server-ca-cert', '~/.fedora-server-ca.cert')
 
 config.add_section('Server')
+config.set('Server', 'use_ssl', 'True')
 config.set('Server', 'address', 'https://127.0.0.1:8887')
 
-config.read([os.path.expanduser('~/.package-builder.cfg')])
+config.add_section('User')
+config.set('User', 'email', 'foo it com')
 
-# Write out config file if it doesn't exist
-if not os.path.exists(os.path.expanduser('~/.package-builder.cfg')):
-    f = open(os.path.expanduser('~/.package-builder.cfg'), "w+")
-    config.write(f)
-    f.close()
 
+config_file_path = os.path.expanduser('~/.package-builder.cfg')
+config.read([config_file_path])
 
-def getSSLXMLRPCServerProxy():
-    """
-    Create an SSL XMLRPC Server Proxy object that uses certificates for verification
-    """
 
-    certs = {}
-    certs['cert'] = os.path.expanduser(config.get('Certs', 'user-cert'))
-    client_key = config.get('Certs', 'user-key')
-    # If client-key is empty, key assumed to be in user-cert
-    certs['key'] = None
-    if len(client_key) > 0:
-        certs['key'] = os.path.expanduser(client_key)
-    certs['ca_cert'] = os.path.expanduser(config.get('Certs', 'user-ca-cert'))
-    certs['peer_ca_cert'] = os.path.expanduser(config.get('Certs', 'server-ca-cert'))
-    return SSLXMLRPCServerProxy.SSLXMLRPCServerProxy(certs, config.get('Server', 'address'))
+class ServerException:
+    def __init__(self, message):
+        self.message = message
+
+class CommandException:
+    def __init__(self, message):
+        self.message = message
+
+
+def enqueue(server, email, args):
+    """ Enqueue a package on the server by CVS tag """
+
+    if len(args) != 3:
+        raise CommandException("Invalid command.  The 'enqueue' command only takes 3 arguments.")
+    package = args[0]
+    tag = args[1]
+    target = args[2]
+    use_ssl = config.get('Server', 'use_ssl')
+    if use_ssl.lower() == 'true':
+        (e, msg, uid) = server.enqueue(package, tag, target)
+    else:
+        (e, msg, uid) = server.enqueue(email, package, tag, target)
+    print "Package %s enqueued with UID %d" % (package, uid)
 
 
-def enqueue(server, args):
-    pass
+def enqueue_srpm(server, email, args):
+    """ Enqueue a package on the server by SRPM """
 
+    if len(args) != 3:
+        raise CommandException("Invalid command.  The 'enqueue_srpm' command only takes 3 arguments.")
+    package = args[0]
+    srpm = args[1]
+    target = args[2]
+    use_ssl = config.get('Server', 'use_ssl')
+    if use_ssl.lower() == 'true':
+        (e, msg, uid) = server.enqueue(package, srpm, target)
+    else:
+        (e, msg, uid) = server.enqueue(email, package, srpm, target)
+    print "Package %s enqueued with UID %d" % (package, uid)
+
+
+def list_own_jobs(server, email):
+    """
+    Get a list of the jobs the current user owns.
+    """
 
-def list_waiting_jobs(server):
     try:
-        print server.list_waiting_jobs()
-    except M2Crypto.SSL.SSLError, e:
+        args = { 'email' : email }
+        jobs = server.list_jobs(args)
+    except (M2Crypto.SSL.SSLError, socket.error), e:
         print "Error connecting to build server: '%s'" % e
+        return
+
+    for job in jobs:
+        print job
+
 
+def update_clients(server, email):
+    """
+    Tell the build server to requery its build client list and re-add dropped
+    clients that are now alive.
+    """
 
-def update_clients(server):
     try:
-        print server.update_clients()
-    except M2Crypto.SSL.SSLError, e:
+        (e, msg, client_list) = server.update_clients()
+        if len(client_list) > 0:
+            print "\nNew Build Clients:"
+            print "-" * 70
+            for client in client_list:
+                string = "  " + client['address']
+                string = string + " " * (40 - len(client['address']))
+                for arch in client['arches']:
+                    string = string + arch + " "
+                string = string + "    " + client['status']
+                print string
+            print ""
+        else:
+            print "No new clients found."
+    except (M2Crypto.SSL.SSLError, socket.error), e:
         print "Error connecting to build server: '%s'" % e
 
 
+def getXMLRPCServerProxy(use_ssl):
+    """
+    Return an XMLRPC server proxy object, either one that uses SSL with certificates
+    for verification, or one that doesn't do any authentication/encryption at all.
+    """
+
+    server = None
+    addr = config.get('Server', 'address')
+    use_ssl = use_ssl.lower()
+    if use_ssl == 'true':
+        if addr.startswith("http:"):
+            raise ServerException("Error: '%s' is not an SSL server, but the use_ssl config option set to True.  See %s" % (addr, config_file_path))
+        else:
+            certs = {}
+            certs['cert'] = os.path.expanduser(config.get('Certs', 'user-cert'))
+            client_key = config.get('Certs', 'user-key')
+            # If client-key is empty, key assumed to be in user-cert
+            certs['key'] = None
+            if len(client_key) > 0:
+                certs['key'] = os.path.expanduser(client_key)
+            certs['ca_cert'] = os.path.expanduser(config.get('Certs', 'user-ca-cert'))
+            certs['peer_ca_cert'] = os.path.expanduser(config.get('Certs', 'server-ca-cert'))
+            server = SSLXMLRPCServerProxy.SSLXMLRPCServerProxy(certs, config.get('Server', 'address'))
+    elif use_ssl == 'false':
+        if addr.startswith("https:"):
+            raise ServerException("Error: '%s' is an SSL server, but the use_ssl config option set to False.  See %s" % (addr, config_file_path))
+        else:
+            server = M2Crypto.m2xmlrpclib.ServerProxy(addr)
+    else:
+        raise ServerException("Unrecognized value for config '%s' option use_ssl.  See %s" % (use_ssl, config_file_path))
+
+    return server
+
+
+def getEmailAddress():
+    """ Get email address either from certificate of config file """
+    config_email = config.get('User', 'email')
+
+    use_ssl = config.get('Server', 'use_ssl')
+    if use_ssl.lower() == 'true':
+        certfile = config.get('Certs', 'user-cert')
+        certfile = os.path.expanduser(certfile)
+        if not os.access(certfile, os.R_OK):
+            print "%s does not exist or is not readable." % certfile
+            sys.exit(1)
+        cert = M2Crypto.X509.load_cert(certfile)
+        cert_email = cert.get_subject().emailAddress
+        if cert_email != config_email:
+            print "Error: certificate's email address does not match the email address in the config file."
+            sys.exit(1)
+
+    return config_email
+
+
+
 if __name__ == '__main__':
     if len(sys.argv) < 2:
         print "Usage:\npackage-builder.py <command>\n\n"
+        print "      <command> is one of:"
+        print "      enqueue <package> <cvs_tag> <target>"
+        print "      enqueue_srpm <package> <cvs_tag> <target>"
+        print "      list_own_jobs"
+        print "      update_clients"
         sys.exit(1)
 
+    # Write out config file if it doesn't exist
+    if not os.path.exists(config_file_path):
+        f = open(config_file_path, "w+")
+        config.write(f)
+        f.close()
+
     cmd = sys.argv[1]
+    email = getEmailAddress()
 
-    server = getSSLXMLRPCServerProxy()
+    try:
+        server = getXMLRPCServerProxy(config.get('Server', 'use_ssl'))
+    except ServerException, e:
+        print e.message
+        sys.exit(1)
 
     if cmd == 'enqueue':
-        enqueue(server, sys.argv[2:])
-    elif cmd == 'list_waiting_jobs':
-        list_waiting_jobs(server)
+        try:
+            enqueue(server, email, sys.argv[2:])
+        except CommandException, e:
+            print e.message
+    elif cmd == 'enqueue_srpm':
+        try:
+            enqueue_srpm(server, email, sys.argv[2:])
+        except CommandException, e:
+            print e.message
+    elif cmd == 'list_own_jobs':
+        list_own_jobs(server, email)
     elif cmd == 'update_clients':
-        update_clients(server)
+        update_clients(server, email)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]