summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Peck <bpeck@redhat.com>2011-03-12 02:00:59 +1000
committerGerrit Code Review <gerrit@maeby.djc.id.au>2011-03-12 02:00:59 +1000
commita6e8659f0f05b43c7b9c892a48f7096febdf6031 (patch)
tree1944df31319e2fe68d08f2a8a75831d87508a9f4
parent1b36e7fd9b5d67829980ec6f282a89a334c79717 (diff)
parentddb3bef70e2222adc6a7704426b81e8ecb5086dc (diff)
Merge "script to populate reservation table" into develop
-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()