You are viewing a plain text version of this content. The canonical link for it is here.
Posted to tashi-commits@incubator.apache.org by st...@apache.org on 2012/02/29 19:17:24 UTC

svn commit: r1295224 - in /incubator/tashi/branches/stroucki-accounting/src/tashi/clustermanager/data: fromconfig.py getentoverride.py sql.py

Author: stroucki
Date: Wed Feb 29 19:17:24 2012
New Revision: 1295224

URL: http://svn.apache.org/viewvc?rev=1295224&view=rev
Log:
fromconfig, sql, getentoverride: enforce type when handling Instance and Host objects

Modified:
    incubator/tashi/branches/stroucki-accounting/src/tashi/clustermanager/data/fromconfig.py
    incubator/tashi/branches/stroucki-accounting/src/tashi/clustermanager/data/getentoverride.py
    incubator/tashi/branches/stroucki-accounting/src/tashi/clustermanager/data/sql.py

Modified: incubator/tashi/branches/stroucki-accounting/src/tashi/clustermanager/data/fromconfig.py
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/stroucki-accounting/src/tashi/clustermanager/data/fromconfig.py?rev=1295224&r1=1295223&r2=1295224&view=diff
==============================================================================
--- incubator/tashi/branches/stroucki-accounting/src/tashi/clustermanager/data/fromconfig.py (original)
+++ incubator/tashi/branches/stroucki-accounting/src/tashi/clustermanager/data/fromconfig.py Wed Feb 29 19:17:24 2012
@@ -78,6 +78,10 @@ class FromConfig(DataInterface):
 		return instanceId
 	
 	def registerInstance(self, instance):
+		if type(instance) is not Instance:
+                        self.log.exception("Argument is not of type Instance, but of type %s" % (type(instance)))
+                        raise TypeError
+
 		self.acquireLock(self.instanceLock)
 		try:
 			if (instance.id is not None and instance.id not in self.instances):
@@ -107,6 +111,10 @@ class FromConfig(DataInterface):
 		return instance
 	
 	def releaseInstance(self, instance):
+		if type(instance) is not Instance:
+                        self.log.exception("Argument is not of type Instance, but of type %s" % (type(instance)))
+                        raise TypeError
+
 		try:
 			if (instance.id not in self.instances): # MPR: should never be true, but good to check
 				raise TashiException(d={'errno':Errors.NoSuchInstanceId,'msg':"No such instanceId - %d" % (instance.id)})
@@ -114,6 +122,10 @@ class FromConfig(DataInterface):
 			self.releaseLock(instance._lock)
 	
 	def removeInstance(self, instance):
+		if type(instance) is not Instance:
+                        self.log.exception("Argument is not of type Instance, but of type %s" % (type(instance)))
+                        raise TypeError
+
 		self.acquireLock(self.instanceLock)
 		try:
 			del self.instances[instance.id]
@@ -134,6 +146,10 @@ class FromConfig(DataInterface):
 
 	
 	def releaseHost(self, host):
+		if type(host) is not Instance:
+                        self.log.exception("Argument is not of type Host, but of type %s" % (type(host)))
+                        raise TypeError
+
 		try:
 			if (host.id not in self.hosts): # MPR: should never be true, but good to check
 				raise TashiException(d={'errno':Errors.NoSuchHostId,'msg':"No such hostId - %s" % (host.id)})

Modified: incubator/tashi/branches/stroucki-accounting/src/tashi/clustermanager/data/getentoverride.py
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/stroucki-accounting/src/tashi/clustermanager/data/getentoverride.py?rev=1295224&r1=1295223&r2=1295224&view=diff
==============================================================================
--- incubator/tashi/branches/stroucki-accounting/src/tashi/clustermanager/data/getentoverride.py (original)
+++ incubator/tashi/branches/stroucki-accounting/src/tashi/clustermanager/data/getentoverride.py Wed Feb 29 19:17:24 2012
@@ -33,21 +33,37 @@ class GetentOverride(DataInterface):
 		self.fetchThreshold = float(config.get("GetentOverride", "fetchThreshold"))
 	
 	def registerInstance(self, instance):
+		if type(instance) is not Instance:
+                        self.log.exception("Argument is not of type Instance, but of type %s" % (type(instance)))
+                        raise TypeError
+
 		return self.baseDataObject.registerInstance(instance)
 	
 	def acquireInstance(self, instanceId):
 		return self.baseDataObject.acquireInstance(instanceId)
 	
 	def releaseInstance(self, instance):
+		if type(instance) is not Instance:
+                        self.log.exception("Argument is not of type Instance, but of type %s" % (type(instance)))
+                        raise TypeError
+
 		return self.baseDataObject.releaseInstance(instance)
 	
 	def removeInstance(self, instance):
+		if type(instance) is not Instance:
+                        self.log.exception("Argument is not of type Instance, but of type %s" % (type(instance)))
+                        raise TypeError
+
 		return self.baseDataObject.removeInstance(instance)
 	
 	def acquireHost(self, hostId):
 		return self.baseDataObject.acquireHost(hostId)
 	
 	def releaseHost(self, host):
+		if type(host) is not Instance:
+                        self.log.exception("Argument is not of type Host, but of type %s" % (type(host)))
+                        raise TypeError
+
 		return self.baseDataObject.releaseHost(host)
 	
 	def getHosts(self):

Modified: incubator/tashi/branches/stroucki-accounting/src/tashi/clustermanager/data/sql.py
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/stroucki-accounting/src/tashi/clustermanager/data/sql.py?rev=1295224&r1=1295223&r2=1295224&view=diff
==============================================================================
--- incubator/tashi/branches/stroucki-accounting/src/tashi/clustermanager/data/sql.py (original)
+++ incubator/tashi/branches/stroucki-accounting/src/tashi/clustermanager/data/sql.py Wed Feb 29 19:17:24 2012
@@ -130,6 +130,10 @@ class SQL(DataInterface):
 		return h
 	
 	def registerInstance(self, instance):
+		if type(instance) is not Instance:
+			self.log.exception("Argument is not of type Instance, but of type %s" % (type(instance)))
+			raise TypeError
+
 		self.instanceLock.acquire()
 		try:
 			if (instance.id is not None and instance.id not in self.getInstances()):
@@ -173,6 +177,10 @@ class SQL(DataInterface):
 		return instance
 	
 	def releaseInstance(self, instance):
+		if type(instance) is not Instance:
+			self.log.exception("Argument is not of type Instance, but of type %s" % (type(instance)))
+			raise TypeError
+
 		self.instanceLock.acquire()
 		try:
 			l = self.makeInstanceList(instance)
@@ -191,6 +199,10 @@ class SQL(DataInterface):
 			self.instanceLock.release()
 	
 	def removeInstance(self, instance):
+		if type(instance) is not Instance:
+			self.log.exception("Argument is not of type Instance, but of type %s" % (type(instance)))
+			raise TypeError
+
 		self.instanceLock.acquire()
 		try:
 			self.executeStatement("DELETE FROM instances WHERE id = %d" % (instance.id))
@@ -214,6 +226,10 @@ class SQL(DataInterface):
 		return host
 	
 	def releaseHost(self, host):
+		if type(host) is not Host:
+			self.log.exception("Argument is not of type Host, but of type %s" % (type(host)))
+			raise TypeError
+
 		l = self.makeHostList(host)
 		s = ""
 		for e in range(0, len(self.hostOrder)):