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
=== modified file 'utah/provisioning/inventory/sqlite.py'
--- utah/provisioning/inventory/sqlite.py 2012-11-08 17:23:31 +0000
+++ utah/provisioning/inventory/sqlite.py 2012-11-15 21:39:20 +0000
@@ -2,6 +2,7 @@
22
3import sqlite33import sqlite3
4import os4import os
5import psutil
5from utah.provisioning.inventory.exceptions import \6from utah.provisioning.inventory.exceptions import \
6 UTAHProvisioningInventoryException7 UTAHProvisioningInventoryException
7from utah.provisioning.inventory.inventory import Inventory8from utah.provisioning.inventory.inventory import Inventory
@@ -113,35 +114,50 @@
113 else:114 else:
114 for machineinfo in result:115 for machineinfo in result:
115 cargs = dict(machineinfo)116 cargs = dict(machineinfo)
116 machineid = cargs.pop('machineid')117 if cargs['state'] == 'available':
117 name = cargs.pop('name')118 return self._take(cargs, *args, **kw)
118 state = cargs.pop('state')119 for machineinfo in result:
119 if state == 'available':120 cargs = dict(machineinfo)
120 update = self.connection.execute(121 pid = cargs['pid']
121 "UPDATE machines SET state='provisioned' "122 try:
122 "WHERE machineid=? AND state='available'",123 if not (psutil.pid_exists(pid) and ('utah' in
123 [machineid]).rowcount124 ' '.join(psutil.Process(pid).cmdline)
124 if update == 1:125 or 'run_test_cobbler.py' in
125 machine = machinetype(*args, cargs=cargs,126 ' '.join(psutil.Process(pid).cmdline))):
126 inventory=self, name=name, **kw)127 return self._take(cargs, *args, **kw)
127 self.machines.append(machine)128 except ValueError:
128 return machine129 continue
129 elif update == 0:130
130 raise UTAHProvisioningInventoryException(
131 'Machine was requested by another process '
132 'before we could request it')
133 elif update > 1:
134 raise UTAHProvisioningInventoryException(
135 'Multiple machines exist '
136 'matching those criteria; '
137 'database ' + self.db + ' may be corrupt')
138 else:
139 raise UTAHProvisioningInventoryException(
140 'Negative rowcount returned '
141 'when attempting to request machine')
142 raise UTAHProvisioningInventoryException(131 raise UTAHProvisioningInventoryException(
143 'All machines meeting criteria are currently unavailable')132 'All machines meeting criteria are currently unavailable')
144133
134 def _take(self, cargs, *args, **kw):
135 machineid = cargs.pop('machineid')
136 name = cargs.pop('name')
137 state = cargs.pop('state')
138 pid = cargs.pop('pid')
139 update = self.connection.execute(
140 "UPDATE machines SET pid=?, state='provisioned' WHERE machineid=? AND state=?",
141 [os.getpid(), machineid, state]).rowcount
142 if update == 1:
143 machine = CobblerMachine(*args, cargs=cargs,
144 inventory=self, name=name, **kw)
145 self.machines.append(machine)
146 return machine
147 elif update == 0:
148 raise UTAHProvisioningInventoryException(
149 'Machine was requested by another process '
150 'before we could request it')
151 elif update > 1:
152 raise UTAHProvisioningInventoryException(
153 'Multiple machines exist '
154 'matching those criteria; '
155 'database ' + self.db + ' may be corrupt')
156 else:
157 raise UTAHProvisioningInventoryException(
158 'Negative rowcount returned '
159 'when attempting to request machine')
160
145 def release(self, machine=None, name=None):161 def release(self, machine=None, name=None):
146 if machine is not None:162 if machine is not None:
147 name = machine.name163 name = machine.name
@@ -173,6 +189,7 @@
173 # CREATE TABLE machines (machineid INTEGER PRIMARY KEY,189 # CREATE TABLE machines (machineid INTEGER PRIMARY KEY,
174 # name TEXT NOT NULL UNIQUE,190 # name TEXT NOT NULL UNIQUE,
175 # state TEXT default 'available',191 # state TEXT default 'available',
192 # pid TEXT,
176 # [mac-address] TEXT NOT NULL UNIQUE,193 # [mac-address] TEXT NOT NULL UNIQUE,
177 # [power-address] TEXT DEFAULT '10.97.0.13',194 # [power-address] TEXT DEFAULT '10.97.0.13',
178 # [power-id] TEXT,195 # [power-id] TEXT,

Subscribers

People subscribed via source and target branches