Merge lp:~joetalbott/utah/cobbler-pidlock-updated into lp:utah

Proposed by Joe Talbott
Status: Merged
Approved by: Max Brustkern
Approved revision: 713
Merged at revision: 751
Proposed branch: lp:~joetalbott/utah/cobbler-pidlock-updated
Merge into: lp:utah
Diff against target: 96 lines (+43/-26)
1 file modified
utah/provisioning/inventory/sqlite.py (+43/-26)
To merge this branch: bzr merge lp:~joetalbott/utah/cobbler-pidlock-updated
Reviewer Review Type Date Requested Status
Max Brustkern (community) Approve
Joe Talbott (community) Needs Resubmitting
Review via email: mp+134568@code.launchpad.net

Description of the change

This branch is an update to Max's cobbler-pidlock branch that stores the 'pid' in the DB and uses that to check if a provisioned machine is still in use.

To post a comment you must log in.
712. By Joe Talbott

Merge with dev.

* Added information parser for dashboard
* Updated ISO static validation to use new features of ISO class and
  work independent of script directory and image directory and image
  name
* Added support for desktop image kernel detection from bootloader
  configuration files
* Added support for automatic ISO downloading and made CustomVM the
  default provisioning method
* Updated config handling: directories now supported, as well as most
  command line options
* Dashboard integration merge
* Merged initial arm support
* Pushing version to 0.5 to create a new stable version before UDS
* phoenix - Fix comment for fetch_method.
* phoenix - Adjust default ts_control to be more informative
* Add 'run_as' to phoenix created tc_control files
* Update documentation for phoenix
* Add reboot documentation
* Allow phoenix to append new testcases to tslist.run
* Update phoenix.py output
* phoenix - Move command to the end of the tc_control file to match
  the training docs
* Update VCS revision methods for adding revision info to results

Revision history for this message
Joe Talbott (joetalbott) wrote :

Merged with dev and fixed state setting per Max on IRC.

review: Needs Resubmitting
713. By Joe Talbott

Remove unneeded code.

Revision history for this message
Max Brustkern (nuclearbob) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utah/provisioning/inventory/sqlite.py'
2--- utah/provisioning/inventory/sqlite.py 2012-11-08 17:23:31 +0000
3+++ utah/provisioning/inventory/sqlite.py 2012-11-15 21:39:20 +0000
4@@ -2,6 +2,7 @@
5
6 import sqlite3
7 import os
8+import psutil
9 from utah.provisioning.inventory.exceptions import \
10 UTAHProvisioningInventoryException
11 from utah.provisioning.inventory.inventory import Inventory
12@@ -113,35 +114,50 @@
13 else:
14 for machineinfo in result:
15 cargs = dict(machineinfo)
16- machineid = cargs.pop('machineid')
17- name = cargs.pop('name')
18- state = cargs.pop('state')
19- if state == 'available':
20- update = self.connection.execute(
21- "UPDATE machines SET state='provisioned' "
22- "WHERE machineid=? AND state='available'",
23- [machineid]).rowcount
24- if update == 1:
25- machine = machinetype(*args, cargs=cargs,
26- inventory=self, name=name, **kw)
27- self.machines.append(machine)
28- return machine
29- elif update == 0:
30- raise UTAHProvisioningInventoryException(
31- 'Machine was requested by another process '
32- 'before we could request it')
33- elif update > 1:
34- raise UTAHProvisioningInventoryException(
35- 'Multiple machines exist '
36- 'matching those criteria; '
37- 'database ' + self.db + ' may be corrupt')
38- else:
39- raise UTAHProvisioningInventoryException(
40- 'Negative rowcount returned '
41- 'when attempting to request machine')
42+ if cargs['state'] == 'available':
43+ return self._take(cargs, *args, **kw)
44+ for machineinfo in result:
45+ cargs = dict(machineinfo)
46+ pid = cargs['pid']
47+ try:
48+ if not (psutil.pid_exists(pid) and ('utah' in
49+ ' '.join(psutil.Process(pid).cmdline)
50+ or 'run_test_cobbler.py' in
51+ ' '.join(psutil.Process(pid).cmdline))):
52+ return self._take(cargs, *args, **kw)
53+ except ValueError:
54+ continue
55+
56 raise UTAHProvisioningInventoryException(
57 'All machines meeting criteria are currently unavailable')
58
59+ def _take(self, cargs, *args, **kw):
60+ machineid = cargs.pop('machineid')
61+ name = cargs.pop('name')
62+ state = cargs.pop('state')
63+ pid = cargs.pop('pid')
64+ update = self.connection.execute(
65+ "UPDATE machines SET pid=?, state='provisioned' WHERE machineid=? AND state=?",
66+ [os.getpid(), machineid, state]).rowcount
67+ if update == 1:
68+ machine = CobblerMachine(*args, cargs=cargs,
69+ inventory=self, name=name, **kw)
70+ self.machines.append(machine)
71+ return machine
72+ elif update == 0:
73+ raise UTAHProvisioningInventoryException(
74+ 'Machine was requested by another process '
75+ 'before we could request it')
76+ elif update > 1:
77+ raise UTAHProvisioningInventoryException(
78+ 'Multiple machines exist '
79+ 'matching those criteria; '
80+ 'database ' + self.db + ' may be corrupt')
81+ else:
82+ raise UTAHProvisioningInventoryException(
83+ 'Negative rowcount returned '
84+ 'when attempting to request machine')
85+
86 def release(self, machine=None, name=None):
87 if machine is not None:
88 name = machine.name
89@@ -173,6 +189,7 @@
90 # CREATE TABLE machines (machineid INTEGER PRIMARY KEY,
91 # name TEXT NOT NULL UNIQUE,
92 # state TEXT default 'available',
93+ # pid TEXT,
94 # [mac-address] TEXT NOT NULL UNIQUE,
95 # [power-address] TEXT DEFAULT '10.97.0.13',
96 # [power-id] TEXT,

Subscribers

People subscribed via source and target branches