[SCM] build.samba.org - branch master updated

Jelmer Vernooij jelmer at samba.org
Sat Nov 6 13:58:48 MDT 2010


The branch, master has been updated
       via  6ee58c0 Remove old admin script.
       via  42776b1 Add python version of admin.py.
       via  39ccbc1 Use iterators, proper booleans.
      from  7adca02 Add convenience class for build status.

http://gitweb.samba.org/?p=build-farm.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 6ee58c01e768e7f3844e166d0d5eb40238998eee
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat Nov 6 20:59:25 2010 +0100

    Remove old admin script.

commit 42776b1066ef4b7613aaf670bbfee9da7ee72159
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat Nov 6 20:15:58 2010 +0100

    Add python version of admin.py.

commit 39ccbc102dea09aefe866600a5b62b350070ecb1
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat Nov 6 19:43:32 2010 +0100

    Use iterators, proper booleans.

-----------------------------------------------------------------------

Summary of changes:
 admin.pl                       |  217 ----------------------------------------
 admin.py                       |  190 +++++++++++++++++++++++++++++++++++
 buildfarm/hostdb.py            |   61 +++++++++---
 buildfarm/tests/test_hostdb.py |   60 +++++++++++-
 web/build.py                   |   28 +++---
 5 files changed, 310 insertions(+), 246 deletions(-)
 delete mode 100755 admin.pl
 create mode 100755 admin.py


Changeset truncated at 500 lines:

diff --git a/admin.pl b/admin.pl
deleted file mode 100755
index 906d2b3..0000000
--- a/admin.pl
+++ /dev/null
@@ -1,217 +0,0 @@
-#!/usr/bin/perl
-# Samba.org buildfarm
-# Copyright (C) 2008 Andrew Bartlett <abartlet at samba.org>
-# Copyright (C) 2008 Jelmer Vernooij <jelmer at samba.org>
-#   
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#   
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#   
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-
-use FindBin qw($RealBin);
-
-use hostdb;
-use Mail::Send;
-use warnings;
-use strict;
-use Data::Dumper;
-use util;
-
-my $hostname;
-
-my $db = new hostdb("$RealBin/hostdb.sqlite") or die("Unable to connect to host database: $!");
-my $dry_run = 0;
-
-print "Samba Build farm management tool\n";
-print "================================\n";
-
-my $op;
-
-if ($#ARGV > -1) {
-	$op = shift(@ARGV);
-} else {
-	print "Initialize host database:       init\n";
-	print "Add Machine to build farm:      add\n";
-	print "Remove Machine from build farm: remove\n";
-	print "Modify build farm account:      modify\n";
-	print "Print build farm host info:     info\n";
-	print "Print build farm host list:     list\n";
-	print "Select Operation: [add] ";
-
-	$op = lc(<STDIN>);
-	chomp($op);
-
-	if ($op eq "") {
-		$op = "add";
-	}
-}
-
-if ($op eq "remove") {
-	print "Please enter hostname to delete: ";
-	$hostname = <>;
-	chomp($hostname);
-	$db->deletehost($hostname) or die("Unable to delete host $hostname");
-} elsif ($op eq "modify") {
-	print "Please enter hostname to modify: ";
-	$hostname = <>;
-	chomp($hostname);
-	my $host = $db->host($hostname);
-	print "Owner: $host->{owner} <$host->{owner_email}>\n";
-	print "Platform: $host->{platform}\n";
-	print "\n";
-	print "Modify owner or platform: [platform] ";
-	my $mod_op = <>;
-	chomp($mod_op);
-	if ($mod_op eq "") {
-		$mod_op = "platform";
-	}
-	if ($mod_op eq "platform") {
-		print "Enter new platform: ";
-		my $platform = <>;
-		chomp($platform);
-		$db->update_platform($hostname, $platform) or die "Unable to update platform";
-	} elsif ($mod_op eq "owner") {
-		print "Enter new owner's name: ";
-		my $owner = <>;
-		chomp($owner);
-		print "Enter new owner's e-mail address: ";
-		my $owner_email = <>;
-		chomp($owner_email);
-		$db->update_owner($hostname, $owner, $owner_email) or die "Unable to update owner";
-		
-	}	
-} elsif ($op eq "add") {
-	print "Machine hostname: ";
-	my $hostname = <>;
-	chomp($hostname);
-	print "Machine platform (eg Fedora 9 x86_64): ";
-	my $platform = <>;
-	chomp($platform);
-	print "Machine Owner Name: ";
-	my $owner = <>;
-	chomp($owner);
-	print "Machine Owner E-mail: ";
-	my $owner_email = <>;
-	chomp($owner_email);
-	print "Enter password: [generate random] ";
-	my $password = <>;
-	chomp($password);
-	if ($password eq "") {
-		$password = `pwgen 16 1`;
-		chomp($password);
-		print "Password will be: $password\n";
-	}
-	print "Enter permission e-mail, finish with a .\n";
-	my $permission;
-	while (<>) {
-		last if $_ eq ".\n";
-		$permission = $_;
-	}
-	
-	$db->createhost($hostname, $platform, $owner, $owner_email, $password, $permission) or die("Unable to create host $hostname");
-
-	my ($fh, $msg);
-	
-	# send the password in an e-mail to that address
-	my $subject = "Your new build farm host $hostname";
-	if ($dry_run) {
-		print "To: $owner <$owner_email>\n";
-		print "Subject: $subject\n";
-		open(MAIL,"|cat");
-	} else {
-		$msg = new Mail::Send(Subject=>$subject, To=>"\"$owner\" \<$owner_email\>", Bcc=>"build\@samba.org");
-		$msg->set("From", "\"Samba Build Farm\" \<build\@samba.org\>");
-		$fh = $msg->open; 
-	}
-
-	my $body = << "__EOF__";	
-Welcome to the Samba.org build farm.  
-
-Your host $hostname has been added to the Samba Build farm.  
-
-We have recorded that it is running $platform.  
-
-If you have not already done so, please read:
-http://build.samba.org/instructions.html
-
-The password for your rsync .password file is $password
-
-An e-mail asking you to subscribe to the build-farmers mailing
-list will arrive shortly.  Please ensure you maintain your 
-subscription to this list while you have hosts in the build farm.
-
-Thank you for your contribution to ensuring portability and quality
-of Samba.org projects.
-
-
-__EOF__
-	if ($dry_run) {
-		print MAIL $body;
-
-		close(MAIL);
-	} else {
-		print $fh "$body";
-		$fh->close;
-
-		$msg = new Mail::Send(Subject=>'Subscribe to build-farmers mailing list', To=>'build-farmers-join at lists.samba.org');
-		$msg->set("From", "\"$owner\" \<$owner_email\>");
-		$fh = $msg->open; 
-		print $fh "Please subscribe $owner to the build-farmers mailing list\n\n";
-		print $fh "Thanks, your friendly Samba build farm administrator <build\@samba.org>";
-		$fh->close;
-	}
-	
-
-	
-} elsif ($op eq "init") {
-	$db->provision();
-	print "Host database initialized successfully.\n";
-} elsif ($op eq "info") {
-	print "Hostname: ";
-	$hostname = <>;
-	chomp($hostname);
-	my $host = $db->host($hostname);
-	die ("No such host $host") unless ($host);
-	print "Host: $host->{name}";
-	if ($host->{fqdn}) { print " ($host->{fqdn})"; }
-	print "\n";
-	print "Platform: $host->{platform}\n";
-	print "Owner: $host->{owner} <$host->{owner_email}>\n";
-	
-	# Don't run the update of the text files
-	exit(0);
-} elsif ($op eq "list") {
-    my $hosts = $db->host_ages();
-    foreach (@$hosts) {
-	my $h = $_;
-	my $age = util::dhm_time(time() - $h->{last_update});
-	printf "%-12s $h->{host}\n", $age;
-    }
-#    print Dumper($hosts);
-} else {
-	die("Unknown command $op");
-}
-
-open(RSYNC_SECRETS, ">$RealBin/../rsyncd.secrets.new") or die("Unable to open rsyncd.secrets file: $!");
-print RSYNC_SECRETS $db->create_rsync_secrets();
-close(RSYNC_SECRETS);
-
-rename("$RealBin/../rsyncd.secrets.new", "../rsyncd.secrets");
-
-open(HOSTS, ">$RealBin/web/hosts.list.new") or die("Unable to open hosts file: $!");
-print HOSTS $db->create_hosts_list();
-close(HOSTS);
-
-rename("$RealBin/web/hosts.list.new", "$RealBin/web/hosts.list");
-
-1;
-
diff --git a/admin.py b/admin.py
new file mode 100755
index 0000000..731876c
--- /dev/null
+++ b/admin.py
@@ -0,0 +1,190 @@
+#!/usr/bin/python
+# Samba.org buildfarm
+# Copyright (C) 2008 Andrew Bartlett <abartlet at samba.org>
+# Copyright (C) 2008 Jelmer Vernooij <jelmer at samba.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+from buildfarm import hostdb
+import commands
+import os
+import smtplib
+import sys
+import time
+from email.MIMEText import MIMEText
+
+db = hostdb.HostDatabase(os.path.join(os.path.dirname(__file__), "hostdb.sqlite"))
+
+dry_run = False
+
+print "Samba Build farm management tool"
+print "================================"
+
+if len(sys.argv) > 1:
+    op = sys.argv[1]
+else:
+    print "Add Machine to build farm:      add"
+    print "Remove Machine from build farm: remove"
+    print "Modify build farm account:      modify"
+    print "Print build farm host info:     info"
+    print "Print build farm host list:     list"
+
+    op = raw_input("Select Operation: [add] ").lower()
+
+    if op == "":
+        op = "add"
+
+if op == "remove":
+    hostname = raw_input("Please enter hostname to delete: ")
+    try:
+        db.deletehost(hostname)
+    except hostdb.NoSuchHost, e:
+        print "No such host '%s'" % e.name
+        sys.exit(1)
+elif op == "modify":
+    hostname = raw_input("Please enter hostname to modify: ")
+    host = db.host(hostname)
+    print "Owner: %s <%s>" % host.owner
+    print "Platform: %s" % host.platform
+    print ""
+    mod_op = raw_input("Modify owner or platform: [platform] ")
+    if mod_op == "":
+        mod_op = "platform"
+    if mod_op == "platform":
+        platform = raw_input("Enter new platform: ")
+        try:
+            db.update_platform(hostname, platform)
+        except hostdb.NoSuchHost, e:
+            print "No such host: %s" % e.name
+            sys.exit(1)
+    elif mod_op == "owner":
+        owner = raw_input("Enter new owner's name: ")
+        owner_email = raw_input("Enter new owner's e-mail address: ")
+        try:
+            db.update_owner(hostname, owner, owner_email)
+        except hostdb.NoSuchHost, e:
+            print "No such host: %s" % e.name
+            sys.exit(1)
+    else:
+        print "Unknown subcommand %s" % mod_op
+        sys.exit(1)
+elif op == "add":
+    hostname = raw_input("Machine hostname: ")
+    platform = raw_input("Machine platform (eg Fedora 9 x86_64): ")
+    owner = raw_input("Machine Owner Name: ")
+    owner_email = raw_input("Machine Owner E-mail: ")
+    password = raw_input("Enter password: [generate random] ")
+    if password == "":
+        password = commands.getoutput("pwgen 16 1").strip()
+        print "Password will be: %s" % password
+    permission = []
+    print "Enter permission e-mail, finish with a ."
+    line = raw_input("")
+    while line != ".":
+        permission += line
+        line = raw_input("")
+
+    try:
+        db.createhost(hostname, platform, owner, owner_email, password, "".join(permission))
+    except hostdb.HostAlreadyExists, e:
+        print "A host with the name %s already exists." % e.name
+        sys.exit(1)
+
+    body = """
+Welcome to the Samba.org build farm.  
+
+Your host %(hostname)s has been added to the Samba Build farm.  
+
+We have recorded that it is running %(platform)s.  
+
+If you have not already done so, please read:
+http://build.samba.org/instructions.html
+
+The password for your rsync .password file is %(password)s
+
+An e-mail asking you to subscribe to the build-farmers mailing
+list will arrive shortly.  Please ensure you maintain your 
+subscription to this list while you have hosts in the build farm.
+
+Thank you for your contribution to ensuring portability and quality
+of Samba.org projects.
+
+
+""" % { "hostname": hostname, "platform": platform, "password": password }
+
+    msg_notification = MIMEText(body)
+
+    # send the password in an e-mail to that address
+    msg_notification["Subject"] = "Your new build farm host %s" % hostname
+    msg_notification["To"] = "\"%s\" <%s>" % (owner, owner_email)
+    msg_notification["Bcc"] = "build at samba.org"
+    msg_notification["From"] = "\"Samba Build Farm\" <build at samba.org>"
+
+    msg_subscribe = MIMEText("""Please subscribe %s to the build-farmers mailing list
+
+Thanks, your friendly Samba build farm administrator <build at samba.org>""" % owner)
+    msg_subscribe["From"] = "\"%s\" <%s>" % (owner, owner_email)
+    msg_subscribe["Subject"] = 'Subscribe to build-farmers mailing list'
+    msg_subscribe["To"] = 'build-farmers-join at lists.samba.org'
+
+    if dry_run:
+        print msg_notification
+    else:
+        s = smtplib.SMTP()
+        s.connect()
+        for msg in (msg_notification, msg_subscribe):
+            recipients = [msg["To"]]
+            if msg["Bcc"]:
+                recipients.append(msg["Bcc"])
+            s.sendmail(msg["From"], recipients, msg.as_string())
+        s.quit()
+
+elif op == "info":
+    hostname = raw_input("Hostname: ")
+    host = db.host(hostname)
+    if host.fqdn:
+        opt_fqdn = " (%s)" % host.fqdn
+    else:
+        opt_fqdn = ""
+    print "Host: %s%s" % (host.name, opt_fqdn)
+    print "Platform: %s" % host.platform
+    print "Owner: %s <%s>" % host.owner
+
+    # Don't run the update of the text files
+    sys.exit(0)
+elif op == "list":
+    for host in db.host_ages():
+        if host.last_update:
+            age = time.time() - host.last_update
+        else:
+            age = ""
+        print "%-12s %s" % (age, host.name)
+else:
+    print "Unknown command %s" % op
+    sys.exit(1)
+
+temp_rsyncd_secrets = os.path.join(os.path.dirname(__file__), "../rsyncd.secrets.new")
+f = open(temp_rsyncd_secrets, "w")
+f.writelines(db.create_rsync_secrets())
+f.close()
+
+os.rename(temp_rsyncd_secrets, "../rsyncd.secrets")
+
+temp_hosts_list_file = os.path.join(os.path.dirname(__file__), "web", "hosts.list.new")
+f = open(temp_hosts_list_file, "w")
+f.writelines(db.create_hosts_list())
+f.close()
+
+os.rename(temp_hosts_list_file, os.path.join(os.path.dirname(__file__), "web/hosts.list"))
diff --git a/buildfarm/hostdb.py b/buildfarm/hostdb.py
index b2336b6..51dafba 100644
--- a/buildfarm/hostdb.py
+++ b/buildfarm/hostdb.py
@@ -23,10 +23,27 @@ import sqlite3
 import time
 
 
+class HostAlreadyExists(Exception):
+    """The specified host already exists."""
+
+    def __init__(self, name):
+        super(HostAlreadyExists, self).__init__()
+        self.name = name
+
+
+class NoSuchHost(Exception):
+    """The specified host did not exist."""
+
+    def __init__(self, name):
+        super(NoSuchHost, self).__init__()
+        self.name = name
+
+
 class Host(object):
     """A host in the buildfarm."""
 
-    def __init__(self, name, owner=None, owner_email=None, password=None, platform=None):
+    def __init__(self, name, owner=None, owner_email=None, password=None, platform=None,
+                 ssh_access=False, last_update=None, fqdn=None):
         self.name = name
         if owner:
             self.owner = (owner, owner_email)
@@ -34,9 +51,16 @@ class Host(object):
             self.owner = None
         self.password = password
         self.platform = platform
+        self.ssh_access = ssh_access
+        self.last_update = last_update
+        self.fqdn = fqdn
+
+    def __cmp__(self, other):
+        return cmp(self.name, other.name)
 
 
 class HostDatabase(object):
+    """Host database."""
 
     def __init__(self, filename=None):
         if filename is None:
@@ -53,30 +77,35 @@ class HostDatabase(object):
             """)
         self.db.commit()
 
-    def createhost(self, name, platform, owner, owner_email, password, permission):
-        self.db.execute("INSERT INTO host (name, platform, owner, owner_email, password, permission, join_time) VALUES (?,?,?,?,?,?,?)",
-                (name, platform, owner, owner_email, password, permission, time.time()))
+    def createhost(self, name, platform=None, owner=None, owner_email=None, password=None, permission=None):
+        try:
+            self.db.execute("INSERT INTO host (name, platform, owner, owner_email, password, permission, join_time) VALUES (?,?,?,?,?,?,?)",
+                    (name, platform, owner, owner_email, password, permission, time.time()))
+        except sqlite3.IntegrityError:
+            raise HostAlreadyExists(name)
         self.db.commit()
 
     def deletehost(self, name):
-        self.db.execute("DELETE FROM host WHERE name = ?", name)
+        cursor = self.db.execute("DELETE FROM host WHERE name = ?", (name,))
+        if cursor.rowcount == 0:
+            raise NoSuchHost(name)
         self.db.commit()
 
     def hosts(self):
-        cursor = self.db.execute("SELECT name, owner, owner_email, password, platform FROM host ORDER BY name")
+        cursor = self.db.execute("SELECT name, owner, owner_email, password, platform, ssh_access, fqdn FROM host ORDER BY name")
         for row in cursor.fetchall():
-            yield Host(name=row[0], owner=row[1], owner_email=row[2], password=row[3], platform=row[4])
+            yield Host(name=row[0], owner=row[1], owner_email=row[2], password=row[3], platform=row[4], ssh_access=bool(row[5]), fqdn=row[6])
 
     def dead_hosts(self, age):
         dead_time = time.time() - age


-- 
build.samba.org


More information about the samba-cvs mailing list