incubator-tashi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strou...@apache.org
Subject svn commit: r1058368 - in /incubator/tashi/trunk/src/tashi: client/tashi-client.py clustermanager/clustermanagerservice.py clustermanager/data/sql.py
Date Thu, 13 Jan 2011 00:09:30 GMT
Author: stroucki
Date: Thu Jan 13 00:09:29 2011
New Revision: 1058368

URL: http://svn.apache.org/viewvc?rev=1058368&view=rev
Log:
Merge in fixes from last semester's project deployment of Tashi
tashi-client: don't print usage if an exception happened in the call.
clustermanagerservice: validate fields before using them
                       clean up invalid instance entries
sql: make sure to validate values before inserting into sql statements

Modified:
    incubator/tashi/trunk/src/tashi/client/tashi-client.py
    incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py
    incubator/tashi/trunk/src/tashi/clustermanager/data/sql.py

Modified: incubator/tashi/trunk/src/tashi/client/tashi-client.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/client/tashi-client.py?rev=1058368&r1=1058367&r2=1058368&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/client/tashi-client.py (original)
+++ incubator/tashi/trunk/src/tashi/client/tashi-client.py Thu Jan 13 00:09:29 2011
@@ -64,6 +64,8 @@ def checkIid(instance):
 		raise ValueError("Unknown instance %s" % (str(instance)))
 	for instance in instances:
 		if (instance.id == instanceId):
+			# XXXstroucki uid 0 to have superuser access
+			# how about admin groups?
 			if (instance.userId != userId and instance.userId != None and userId != 0):
 				raise ValueError("You don't own that VM")
 	return instanceId
@@ -526,7 +528,10 @@ def main():
 		exitCode = e.errno
 	except Exception, e:
 		print e
-		usage(function)
+		# XXXstroucki: exception may be unrelated to usage of function
+		# so don't print usage on exception as if there were a problem
+		# with the arguments
+		#usage(function)
 	sys.exit(exitCode)
 
 if __name__ == "__main__":

Modified: incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py?rev=1058368&r1=1058367&r2=1058368&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py (original)
+++ incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py Thu Jan 13 00:09:29
2011
@@ -107,6 +107,7 @@ class ClusterManagerService(object):
 					else:
 						sleepFor = min(self.lastContacted[k] + self.expireHostTime - now, sleepFor)
 				for hostId in self.decayedHosts.keys():
+					# XXXstroucki: what if the host undecays here?
 					if (self.decayedHosts[hostId] < (now-self.allowDecayed)):
 						host = self.data.getHost(hostId)
 						self.log.warning('Fetching state from host %s because it is decayed' % (host.name))
@@ -132,6 +133,7 @@ class ClusterManagerService(object):
 							self.log.warning('Fetching state on instance %d because it is decayed' % (instanceId))
 							try:
 								instance = self.data.getInstance(instanceId)
+								if instance.hostId is None: raise AssertionError
 							except TashiException, e:
 								if (e.errno == Errors.NoSuchInstanceId):
 									del self.decayedInstances[instanceId]
@@ -147,10 +149,14 @@ class ClusterManagerService(object):
 							self.decayedInstances[instanceId] = now
 						else:
 							sleepFor = min(self.decayedInstances[instanceId] + self.allowDecayed - now, sleepFor)
+					except (KeyError, TashiException):
+						self.log.warning("Don't know about instance %d anymore." % instanceId)
+						self.data.removeInstance(instance)
 					except Exception, e:
 						self.log.exception('Exception in monitorHosts trying to get instance information')
 			except Exception, e:
 				self.log.exception('Exception in monitorHosts')
+
 			time.sleep(sleepFor)
 	
 	def normalize(self, instance):
@@ -210,12 +216,19 @@ class ClusterManagerService(object):
 		else:
 			self.stateTransition(instance, None, InstanceState.Destroying)
 			self.data.releaseInstance(instance)
-			hostname = self.data.getHost(instance.hostId).name
-			try:
-				self.proxy[hostname].destroyVm(instance.vmId)
-			except Exception:
-				self.log.exception('destroyVm failed for host %s vmId %d' % (hostname, instance.vmId))
-				raise
+
+			if instance.hostId is None:
+				self.data.removeInstance(instance)
+			else:
+				hostname = self.data.getHost(instance.hostId).name
+				try:
+					if hostname is not None:
+						self.proxy[hostname].destroyVm(instance.vmId)
+				except Exception:
+					self.log.exception('destroyVm failed on host %s vmId %d' % (hostname, instance.vmId))
+					self.data.removeInstance(instance)
+
+
 		return
 	
 	def suspendVm(self, instanceId):
@@ -355,7 +368,7 @@ class ClusterManagerService(object):
 				oldHost.up = True
 				oldHost.decayed = False
 
-# compare whether CM / NM versions are acceptable
+# compare whether CM / NM versions are compatible
 				if (host.version != version and not self.allowMismatchedVersions):
 					oldHost.state = HostState.VersionMismatch
 				if (host.version == version and oldHost.state == HostState.VersionMismatch):
@@ -397,6 +410,7 @@ class ClusterManagerService(object):
 		finally:
 			self.updateDecay(self.decayedHosts, oldHost)
 			self.data.releaseHost(oldHost)
+
 		return host.id
 	
 	def vmUpdate(self, instanceId, instance, oldState):

Modified: incubator/tashi/trunk/src/tashi/clustermanager/data/sql.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/clustermanager/data/sql.py?rev=1058368&r1=1058367&r2=1058368&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/clustermanager/data/sql.py (original)
+++ incubator/tashi/trunk/src/tashi/clustermanager/data/sql.py Thu Jan 13 00:09:29 2011
@@ -28,20 +28,22 @@ class SQL(DataInterface):
 		DataInterface.__init__(self, config)
 		self.uri = self.config.get("SQL", "uri")
 		self.log = logging.getLogger(__name__)
+
 		if (self.uri.startswith("sqlite://")):
 			import sqlite
-			self.dbengine = "sqlite"
+			self.dbEngine = "sqlite"
 			self.conn = sqlite.connect(self.uri[9:], autocommit=1)
 		elif (self.uri.startswith("mysql://")):
 			import MySQLdb
-			self.dbengine = "mysql"
+			self.dbEngine = "mysql"
 			uri = self.uri[8:]
 			(user, _, hostdb) = stringPartition(uri, '@')
 			(host, _, db) = stringPartition(hostdb, '/')
 			self.password = self.config.get('SQL', 'password')
 			self.conn = MySQLdb.connect(host=host, user=user, passwd=self.password, db=db)
 		else:
-			raise ValueException, 'Unknown SQL uri: %s' % (self.uri)
+			raise ValueException, 'Unknown SQL database engine by URI: %s' % (self.uri)
+
 		self.instanceOrder = ['id', 'vmId', 'hostId', 'decayed', 'state', 'userId', 'name', 'cores',
'memory', 'disks', 'nics', 'hints']
 		self.hostOrder = ['id', 'name', 'up', 'decayed', 'state', 'memory', 'cores', 'version']
 		self.instanceLock = threading.Lock()
@@ -115,9 +117,9 @@ class SQL(DataInterface):
 		h = Host()
 		for e in range(0, len(self.hostOrder)):
 			h.__dict__[self.hostOrder[e]] = l[e]
-		h.state = int(h.state)
 		h.up = boolean(h.up)
 		h.decayed = boolean(h.decayed)
+		h.state = int(h.state)
 		return h
 	
 	def registerInstance(self, instance):
@@ -205,8 +207,13 @@ class SQL(DataInterface):
 			hosts[host.id] = host
 		return hosts
 	
-	def getHost(self, id):
-		cur = self.executeStatement("SELECT * FROM hosts WHERE id = %d" % (int(id)))
+	def getHost(self, in_id):
+		try:
+			id = int(in_id)
+		except:
+			self.log.exception("Argument to getHost was not integer: %s" % in_id)
+
+		cur = self.executeStatement("SELECT * FROM hosts WHERE id = %d" % id)
 		r = cur.fetchone()
 		if (r == None):
 			raise TashiException(d={'errno':Errors.NoSuchHostId,'msg':"No such hostId - %s" % (id)})
@@ -222,8 +229,15 @@ class SQL(DataInterface):
 			instances[instance.id] = instance
 		return instances
 	
-	def getInstance(self, id):
+	def getInstance(self, in_id):
+		try:
+			id = int(in_id)
+		except:
+			self.log.exception("Argument to getInstance was not integer: %s" % in_id)
+
 		cur = self.executeStatement("SELECT * FROM instances WHERE id = %d" % (id))
+		# XXXstroucki should only return one row.
+		# what about migration? should it be enforced?
 		r = cur.fetchone()
 		if (not r):
 			raise TashiException(d={'errno':Errors.NoSuchInstanceId, 'msg':"No such instanceId - %d"
% (id)})



Mime
View raw message