[SCM] build.samba.org - branch master updated
Jelmer Vernooij
jelmer at samba.org
Fri Nov 5 10:44:34 MDT 2010
The branch, master has been updated
via 9dc4ebb add basic host database.
from 73e47d1 Refactor html out of buildfarm.data.
http://gitweb.samba.org/?p=build-farm.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 9dc4ebb877c34d2d8efe6576213f07ee7f24e805
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Fri Nov 5 17:44:03 2010 +0100
add basic host database.
-----------------------------------------------------------------------
Summary of changes:
buildfarm/data.py | 1 +
buildfarm/hostdb.py | 120 ++++++++++++++++++++++++++++++++++++++++
buildfarm/tests/test_hostdb.py | 47 ++++++++++++++++
3 files changed, 168 insertions(+), 0 deletions(-)
create mode 100644 buildfarm/hostdb.py
create mode 100644 buildfarm/tests/test_hostdb.py
Changeset truncated at 500 lines:
diff --git a/buildfarm/data.py b/buildfarm/data.py
index 665492f..b2c2aef 100644
--- a/buildfarm/data.py
+++ b/buildfarm/data.py
@@ -116,6 +116,7 @@ class Tree(object):
self.branch = branch
self.subdir = subdir
self.srcdir = srcdir
+ self.scm = scm
def __repr__(self):
return "<%s %r>" % (self.__class__.__name__, self.name)
diff --git a/buildfarm/hostdb.py b/buildfarm/hostdb.py
new file mode 100644
index 0000000..b2336b6
--- /dev/null
+++ b/buildfarm/hostdb.py
@@ -0,0 +1,120 @@
+#!/usr/bin/python
+
+# Samba.org buildfarm
+# Copyright (C) 2008 Andrew Bartlett <abartlet at samba.org>
+# Copyright (C) 2008-2010 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/>.
+#
+
+
+import sqlite3
+import time
+
+
+class Host(object):
+ """A host in the buildfarm."""
+
+ def __init__(self, name, owner=None, owner_email=None, password=None, platform=None):
+ self.name = name
+ if owner:
+ self.owner = (owner, owner_email)
+ else:
+ self.owner = None
+ self.password = password
+ self.platform = platform
+
+
+class HostDatabase(object):
+
+ def __init__(self, filename=None):
+ if filename is None:
+ self.db = sqlite3.connect(":memory:")
+ else:
+ self.db = sqlite3.connect(filename)
+ self.filename = filename
+ self.db.executescript("""
+ CREATE TABLE IF NOT EXISTS host ( name text, owner text, owner_email text, password text, ssh_access int, fqdn text, platform text, permission text, last_dead_mail int, join_time int );
+ CREATE UNIQUE INDEX IF NOT EXISTS unique_hostname ON host (name);
+ CREATE TABLE IF NOT EXISTS build ( id integer primary key autoincrement, tree text, revision text, host text, compiler text, checksum text, age int, status text, commit_revision text);
+ CREATE UNIQUE INDEX IF NOT EXISTS unique_checksum ON build (checksum);
+ CREATE TABLE IF NOT EXISTS test_run ( build int, test text, result text, output text);
+ """)
+ 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()))
+ self.db.commit()
+
+ def deletehost(self, name):
+ self.db.execute("DELETE FROM host WHERE name = ?", name)
+ self.db.commit()
+
+ def hosts(self):
+ cursor = self.db.execute("SELECT name, owner, owner_email, password, platform 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])
+
+ def dead_hosts(self, age):
+ dead_time = time.time() - age
+ cursor = self.db.execute("SELECT host.name AS host, host.owner AS owner, host.owner_email AS owner_email, MAX(age) AS last_update FROM host LEFT JOIN build ON ( host.name == build.host) WHERE ifnull(last_dead_mail, 0) < %d AND ifnull(join_time, 0) < %d GROUP BY host.name having ifnull(MAX(age),0) < %d" % (dead_time, dead_time, dead_time))
+ for row in cursor.fetchall():
+ yield row[0]
+
+ def host_ages(self):
+ cursor = self.db.execute("SELECT host.name AS host, host.owner AS owner, host.owner_email AS owner_email, MAX(age) AS last_update FROM host LEFT JOIN build ON ( host.name == build.host) GROUP BY host.name ORDER BY age")
+ for row in cursor.fetchall():
+ yield (row[0], row[1], row[2], row[3])
+
+ def sent_dead_mail(self, host):
+ self.db.execute("UPDATE host SET last_dead_mail = ? WHERE name = ?", time.time(), host)
+ self.db.commit()
+
+ def host(self, name):
+ for host in self.hosts():
+ if host.name == name:
+ return host
+
+ return None
+
+ def update_platform(self, name, new_platform):
+ self.db.execute("UPDATE host SET platform = ? WHERE name = ?", new_platform, name)
+ self.db.commit()
+
+ def update_owner(self, name, new_owner, new_owner_email):
+ self.db.execute("UPDATE host SET owner = ?, owner_email = ? WHERE name = ?",
+ new_owner, new_owner_email, name)
+ self.db.commit()
+
+ def create_rsync_secrets(self):
+ """Write out the rsyncd.secrets"""
+ yield "# rsyncd.secrets file\n"
+ yield "# automatically generated by textfiles.pl. DO NOT EDIT!\n\n"
+
+ for host in self.hosts():
+ if host.owner:
+ yield "# %s, owner: %s <%s>\n" % (host.name, host.owner[0], host.owner[1])
+ else:
+ yield "# %s, owner unknown\n" % (host.name,);
+ if host.password:
+ yield "# %s:%s\n\n" % (host.name, host.password)
+ else:
+ yield "# %s password is unknown\n\n" % host.name
+
+ def create_hosts_list(self):
+ """Write out the web/"""
+
+ for host in self.hosts():
+ yield "%s: %s\n" % (host.name, host.platform)
diff --git a/buildfarm/tests/test_hostdb.py b/buildfarm/tests/test_hostdb.py
new file mode 100644
index 0000000..c71d7ac
--- /dev/null
+++ b/buildfarm/tests/test_hostdb.py
@@ -0,0 +1,47 @@
+#!/usr/bin/python
+# Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2010
+#
+# 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, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+import unittest
+
+from buildfarm import hostdb
+
+
+class HostTests(unittest.TestCase):
+
+ def test_create_simple(self):
+ host = hostdb.Host(name="foo")
+ self.assertEquals(None, host.owner)
+ self.assertEquals("foo", host.name)
+
+ def test_create_with_owner(self):
+ host = hostdb.Host(name="foo", owner="Jelmer", owner_email="jelmer at samba.org")
+ self.assertEquals(("Jelmer", "jelmer at samba.org"), host.owner)
+ self.assertEquals("foo", host.name)
+
+
+
+class DatabaseTests(unittest.TestCase):
+
+ def setUp(self):
+ super(DatabaseTests, self).setUp()
+ self.db = hostdb.HostDatabase()
+
+ def test_createhost(self):
+ self.db.createhost("charis", "linux", "Jelmer", "jelmer at samba.org", "bla", "Pemrission?")
+ hosts = list(self.db.hosts())
+ self.assertEquals(1, len(hosts))
+ self.assertEquals("charis", hosts[0].name)
--
build.samba.org
More information about the samba-cvs
mailing list