summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Callaghan <dcallagh@redhat.com>2011-03-10 16:26:57 +1000
committerDan Callaghan <dcallagh@redhat.com>2011-03-11 12:38:20 +1000
commitddb3bef70e2222adc6a7704426b81e8ecb5086dc (patch)
treeaa2591d601651083aba2bf20eb98bc4834dce21e
parentfb1850981b65a33f42301102c25d41b786ab6cf9 (diff)
script to populate reservation table
-rw-r--r--SchemaUpgrades/upgrade_0.6.7.txt36
-rw-r--r--SchemaUpgrades/upgrade_0.6.7_check_reservations.py25
2 files changed, 61 insertions, 0 deletions
diff --git a/SchemaUpgrades/upgrade_0.6.7.txt b/SchemaUpgrades/upgrade_0.6.7.txt
index 454eed1..73f39d5 100644
--- a/SchemaUpgrades/upgrade_0.6.7.txt
+++ b/SchemaUpgrades/upgrade_0.6.7.txt
@@ -4,3 +4,39 @@ Update all existing FQDNs to lowercase
Run the following SQL statement (expected run time <5sec):
UPDATE system SET fqdn = LOWER(fqdn);
+
+
+Populate the reservation table
+------------------------------
+
+After running beaker-init to create the reservation table, populate it with
+historical data using this SQL statement (expected run time approx. 15 mins):
+
+ INSERT INTO reservation (system_id, user_id, start_time, finish_time, type)
+ SELECT
+ system_id,
+ user_id,
+ created AS start_time,
+ (SELECT MIN(created)
+ FROM activity
+ INNER JOIN system_activity ON activity.id = system_activity.id
+ WHERE system_id = outer_system_activity.system_id
+ AND ((created >= outer_activity.created AND action = 'Returned')
+ OR (created > outer_activity.created AND action = 'Reserved'))
+ ) AS finish_time,
+ CASE service
+ WHEN 'Scheduler' THEN 'recipe'
+ ELSE 'manual'
+ END AS type
+ FROM activity outer_activity
+ INNER JOIN system_activity outer_system_activity ON outer_activity.id = outer_system_activity.id
+ WHERE action = 'Reserved'
+ GROUP BY start_time;
+
+As apache user, run the sanity checking script provided in this directory, to
+verify that the reservation table has been populated correctly (expected run
+time approx. 2 mins):
+
+ su -s /bin/sh -c 'python /usr/share/doc/beaker-server-0.6.7/upgrade_0.6.7_check_reservations.py' apache
+
+If the script produces any errors, seek advice from a Beaker developer.
diff --git a/SchemaUpgrades/upgrade_0.6.7_check_reservations.py b/SchemaUpgrades/upgrade_0.6.7_check_reservations.py
new file mode 100644
index 0000000..3d733d3
--- /dev/null
+++ b/SchemaUpgrades/upgrade_0.6.7_check_reservations.py
@@ -0,0 +1,25 @@
+#!/usr/bin/python
+
+import datetime
+from turbogears.database import session
+from bkr.server.util import load_config
+from bkr.server.model import System
+
+def check_reservations(system):
+ if not system.reservations: return
+ prev = system.reservations[0]
+ if prev.finish_time:
+ assert prev.start_time <= prev.finish_time, \
+ '%r is backwards' % prev
+ for r in system.reservations[1:]:
+ assert r.finish_time <= prev.start_time, \
+ '%r does not finish before %r' % (r, prev)
+ assert r.start_time <= r.finish_time, '%r is backwards' % r
+ prev = r
+
+if __name__ == '__main__':
+ load_config()
+ for system_id in [s.id for s in System.query()]:
+ system = System.query().get(system_id)
+ check_reservations(system)
+ session.clear()