Change in vdsm[master]: Improve the validation of netmask and gateway
by wudxw@linux.vnet.ibm.com
Mark Wu has uploaded a new change for review.
Change subject: Improve the validation of netmask and gateway
......................................................................
Improve the validation of netmask and gateway
Change-Id: I3c0a39f3f681a9e587f9118246e42a29e18d604b
Signed-off-by: Mark Wu <wudxw(a)linux.vnet.ibm.com>
---
M tests/configNetworkTests.py
M vdsm/configNetwork.py
2 files changed, 34 insertions(+), 6 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/13/7713/1
diff --git a/tests/configNetworkTests.py b/tests/configNetworkTests.py
index cc88184..58d1ebe 100644
--- a/tests/configNetworkTests.py
+++ b/tests/configNetworkTests.py
@@ -126,10 +126,10 @@
self.assertEqual(configNetwork.validateIpAddress(address), None)
def testIsNetmaskValid(self):
- masks = ('10.18.1.254', '10.50.25.177', '250.0.0.1',
- '20.20.25.25')
- badMasks = ('192.168.1.256', '10.50.25.1777', '256.0.0.1',
- '20.20.25.25.25')
+ masks = ('254.0.0.0', '255.255.255.0', '255.255.255.128',
+ '255.255.255.224')
+ badMasks = ('192.168.1.0', '10.50.25.17', '255.0.255.0',
+ '253.0.0.0')
for mask in badMasks:
with self.assertRaises(configNetwork.ConfigNetworkError) \
@@ -141,6 +141,22 @@
for mask in masks:
self.assertEqual(configNetwork.validateNetmask(mask), None)
+ def testIsGatewayValid(self):
+ gateways = (('192.168.122.1', '192.168.122.234', '255.255.255.0'),
+ ('192.168.122.4', '192.168.122.29', '255.255.255.224'))
+ badGateways = (('192.168.122.1', '192.168.123.4', '255.255.255.0'),
+ ('192.168.122.1', '192.168.122.39', '255.255.255.224'))
+
+ for gateway in badGateways:
+ with self.assertRaises(configNetwork.ConfigNetworkError) \
+ as cneContext:
+ configNetwork.validateGateway(*gateway)
+ self.assertEqual(cneContext.exception.errCode,
+ configNetwork.ne.ERR_BAD_ADDR)
+
+ for gateway in gateways:
+ self.assertEqual(configNetwork.validateGateway(*gateway), None)
+
@memoized
def _bondingModuleOptions(self):
p = subprocess.Popen(['/sbin/modinfo', 'bonding'],
diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index b8fbd9f..cfa8c40 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -656,6 +656,9 @@
return False
return True
+def _dottedQuadToNum(ipaddr):
+ return int(''.join('%02x' % int(i) for i in ipaddr.split('.')), 16)
+
def validateIpAddress(ipAddr):
if not _validateIpAddress(ipAddr):
raise ConfigNetworkError(ne.ERR_BAD_ADDR, "Bad IP address: %r"%ipAddr)
@@ -663,10 +666,19 @@
def validateNetmask(netmask):
if not _validateIpAddress(netmask):
raise ConfigNetworkError(ne.ERR_BAD_ADDR, "Bad netmask: %r"%netmask)
+ num = _dottedQuadToNum(netmask)
+ if (num & (num - 1)) != (num << 1) & 0xffffffff:
+ raise ConfigNetworkError(ne.ERR_BAD_ADDR, "Bad netmask: %r"%netmask)
-def validateGateway(gateway):
+def validateGateway(gateway, ipaddr, netmask):
if not _validateIpAddress(gateway):
raise ConfigNetworkError(ne.ERR_BAD_ADDR, "Bad gateway: %r"%gateway)
+ else:
+ (gw, ip, mask) = [_dottedQuadToNum(addr) for addr
+ in (gateway, ipaddr, netmask)]
+ if ip & mask != gw & mask:
+ raise ConfigNetworkError(ne.ERR_BAD_ADDR,
+ "Bad gateway: %r"%gateway)
def validateBondingName(bonding):
if not re.match('^bond[0-9]+$', bonding):
@@ -763,7 +775,7 @@
validateIpAddress(ipaddr)
validateNetmask(netmask)
if gateway:
- validateGateway(gateway)
+ validateGateway(gateway, ipaddr, netmask)
else:
if netmask or gateway:
raise ConfigNetworkError(ne.ERR_BAD_ADDR,
--
To view, visit http://gerrit.ovirt.org/7713
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3c0a39f3f681a9e587f9118246e42a29e18d604b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Mark Wu <wudxw(a)linux.vnet.ibm.com>
11 years, 3 months
Change in vdsm[master]: make compression type configurable, support gzip and xz
by shaohef@linux.vnet.ibm.com
ShaoHe Feng has uploaded a new change for review.
Change subject: make compression type configurable, support gzip and xz
......................................................................
make compression type configurable, support gzip and xz
autoconf check for presense of xz, and if not found fallback on gzip
Change-Id: I4d88e9d40aefc87564c9c7e23f0d28aaad867aca
Signed-off-by: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
---
M Makefile.am
M autobuild.sh
M configure.ac
M vdsm.spec.in
4 files changed, 32 insertions(+), 2 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/74/4174/1
--
To view, visit http://gerrit.ovirt.org/4174
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4d88e9d40aefc87564c9c7e23f0d28aaad867aca
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
11 years, 3 months
Change in vdsm[master]: [WIP] Add copyVolumes command to the SPM
by Federico Simoncelli
Federico Simoncelli has uploaded a new change for review.
Change subject: [WIP] Add copyVolumes command to the SPM
......................................................................
[WIP] Add copyVolumes command to the SPM
Early implementation (the API might change).
Change-Id: Ia19dd9b779a06ff88efed2eef52c1d152cdc797c
---
M vdsm/API.py
M vdsm/BindingXMLRPC.py
M vdsm/storage/hsm.py
M vdsm/storage/image.py
M vdsm/storage/sp.py
5 files changed, 92 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/85/2885/1
--
To view, visit http://gerrit.ovirt.org/2885
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia19dd9b779a06ff88efed2eef52c1d152cdc797c
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Federico Simoncelli <fsimonce(a)redhat.com>
11 years, 3 months
Change in vdsm[master]: Don't rotate core dump logs on Fedora
by Federico Simoncelli
Federico Simoncelli has uploaded a new change for review.
Change subject: Don't rotate core dump logs on Fedora
......................................................................
Don't rotate core dump logs on Fedora
Core dumps are a system-level configuration and VDSM shouldn't try to
override what the sysadmin decides.
Change-Id: I0a2e86614475fd13de3888b956b5512a24016281
---
M configure.ac
M vdsm.spec.in
M vdsm/Makefile.am
A vdsm/cdumps-logrotate.conf
A vdsm/vdsm-logrotate.conf
D vdsm/vdsm-logrotate.conf.in
6 files changed, 27 insertions(+), 22 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/91/991/1
--
To view, visit http://gerrit.ovirt.org/991
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0a2e86614475fd13de3888b956b5512a24016281
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Federico Simoncelli <fsimonce(a)redhat.com>
11 years, 3 months
Change in vdsm[master]: DomainMonitor should use use real domains (no proxy)
by Federico Simoncelli
Federico Simoncelli has uploaded a new change for review.
Change subject: DomainMonitor should use use real domains (no proxy)
......................................................................
DomainMonitor should use use real domains (no proxy)
In this patch:
* produce the domain when refreshing
* remove the remaining getRealDomain (DomainProxy) calls
* fix manuallyRemoveDomain for non-existent domains
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
Change-Id: Ibbf67fc050658e3418aa666e8fcef1e1244571e9
---
M vdsm/storage/domainMonitor.py
M vdsm/storage/sdc.py
M vdsm/storage/sp.py
3 files changed, 32 insertions(+), 26 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/94/7294/1
diff --git a/vdsm/storage/domainMonitor.py b/vdsm/storage/domainMonitor.py
index 80b6ed3..0272cb1 100644
--- a/vdsm/storage/domainMonitor.py
+++ b/vdsm/storage/domainMonitor.py
@@ -75,13 +75,14 @@
def monitoredDomains(self):
return self._domains.keys()
- def startMonitoring(self, domain, hostId):
- if domain.sdUUID in self._domains:
+ def startMonitoring(self, sdUUID, hostId):
+ if sdUUID in self._domains:
return
- self._domains[domain.sdUUID] = DomainMonitorThread(
- domain, hostId, self._interval)
- self._domains[domain.sdUUID].start()
+ domainThread = DomainMonitorThread(sdUUID, hostId, self._interval)
+ domainThread.start()
+ # The domain should be added only after it succesfully started
+ self._domains[sdUUID] = domainThread
def stopMonitoring(self, sdUUID):
# The domain monitor issues events that might become raceful if
@@ -107,22 +108,25 @@
class DomainMonitorThread(object):
log = logging.getLogger('Storage.DomainMonitorThread')
- def __init__(self, domain, hostId, interval):
+ def __init__(self, sdUUID, hostId, interval):
self.thread = Thread(target=self._monitorLoop)
self.thread.setDaemon(True)
self.stopEvent = Event()
- self.domain = domain
+ self.domain = None
+ self.sdUUID = sdUUID
self.hostId = hostId
self.interval = interval
self.status = DomainMonitorStatus()
self.nextStatus = DomainMonitorStatus()
- self.isIsoDomain = domain.isISO()
+ self.isIsoDomain = None
self.lastRefresh = time()
self.refreshTime = \
config.getint("irs", "repo_stats_cache_refresh_timeout")
def start(self):
+ self.domain = sdCache.produce(self.sdUUID)
+ self.isIsoDomain = self.domain.isISO()
self.thread.start()
def stop(self, wait=True):
@@ -134,17 +138,17 @@
return self.status.copy()
def _monitorLoop(self):
- self.log.debug("Starting domain monitor for %s", self.domain.sdUUID)
+ self.log.debug("Starting domain monitor for %s", self.sdUUID)
while not self.stopEvent.is_set():
try:
self._monitorDomain()
except:
self.log.error("The domain monitor for %s failed unexpectedly",
- self.domain.sdUUID, exc_info=True)
+ self.sdUUID, exc_info=True)
self.stopEvent.wait(self.interval)
- self.log.debug("Stopping domain monitor for %s", self.domain.sdUUID)
+ self.log.debug("Stopping domain monitor for %s", self.sdUUID)
# If this is an ISO domain we didn't acquire the host id and releasing
# it is superfluous.
@@ -153,16 +157,17 @@
self.domain.releaseHostId(self.hostId, unused=True)
except:
self.log.debug("Unable to release the host id %s for domain "
- "%s", self.hostId, self.domain.sdUUID, exc_info=True)
+ "%s", self.hostId, self.sdUUID, exc_info=True)
def _monitorDomain(self):
self.nextStatus.clear()
- # Refreshing the domain object in order to pick up changes as,
- # for example, the domain upgrade.
if time() - self.lastRefresh > self.refreshTime:
- self.log.debug("Refreshing domain %s", self.domain.sdUUID)
- sdCache.manuallyRemoveDomain(self.domain.sdUUID)
+ # Refreshing the domain object in order to pick up changes as,
+ # for example, the domain upgrade.
+ self.log.debug("Refreshing domain %s", self.sdUUID)
+ sdCache.manuallyRemoveDomain(self.sdUUID)
+ self.domain = sdCache.produce(self.sdUUID)
self.lastRefresh = time()
try:
@@ -188,20 +193,19 @@
except Exception, e:
self.log.error("Error while collecting domain %s monitoring "
- "information", self.domain.sdUUID, exc_info=True)
+ "information", self.sdUUID, exc_info=True)
self.nextStatus.error = e
self.nextStatus.lastCheck = time()
self.nextStatus.valid = (self.nextStatus.error is None)
if self.status.valid != self.nextStatus.valid:
- self.log.debug("Domain %s changed its status to %s",
- self.domain.sdUUID,
+ self.log.debug("Domain %s changed its status to %s", self.sdUUID,
"Valid" if self.nextStatus.valid else "Invalid")
try:
self.onDomainConnectivityStateChange.emit(
- self.domain.sdUUID, self.nextStatus.valid)
+ self.sdUUID, self.nextStatus.valid)
except:
self.log.warn("Could not emit domain state change event",
exc_info=True)
@@ -213,7 +217,7 @@
self.domain.acquireHostId(self.hostId, async=True)
except:
self.log.debug("Unable to issue the acquire host id %s "
- "request for domain %s", self.hostId, self.domain.sdUUID,
+ "request for domain %s", self.hostId, self.sdUUID,
exc_info=True)
self.status.update(self.nextStatus)
diff --git a/vdsm/storage/sdc.py b/vdsm/storage/sdc.py
index 9a7d09d..eee8d73 100644
--- a/vdsm/storage/sdc.py
+++ b/vdsm/storage/sdc.py
@@ -137,7 +137,10 @@
def manuallyRemoveDomain(self, sdUUID):
with self._syncroot:
- del self.__cache[sdUUID]
+ try:
+ del self.__cache[sdUUID]
+ except KeyError:
+ pass
storage_repository = config.get('irs', 'repository')
diff --git a/vdsm/storage/sp.py b/vdsm/storage/sp.py
index ed2b893..da403d9 100644
--- a/vdsm/storage/sp.py
+++ b/vdsm/storage/sp.py
@@ -1022,8 +1022,8 @@
if targetFormat is None:
targetFormat = self.getFormat()
- self._formatConverter.convert(repoPath, self.id, domain.getRealDomain(),
- isMsd, targetFormat)
+ self._formatConverter.convert(repoPath, self.id, domain, isMsd,
+ targetFormat)
sdCache.manuallyRemoveDomain(sdUUID)
@unsecured
@@ -1557,8 +1557,7 @@
for sdUUID in activeDomains:
if sdUUID not in monitoredDomains:
try:
- self.domainMonitor \
- .startMonitoring(sdCache.produce(sdUUID), self.id)
+ self.domainMonitor.startMonitoring(sdUUID, self.id)
self.log.debug("Storage Pool `%s` started monitoring "
"domain `%s`", self.spUUID, sdUUID)
except se.StorageException:
--
To view, visit http://gerrit.ovirt.org/7294
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibbf67fc050658e3418aa666e8fcef1e1244571e9
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Federico Simoncelli <fsimonce(a)redhat.com>
11 years, 3 months
Change in vdsm[master]: Revert "BZ#842631 Use domain proxies instead of actual domai...
by Federico Simoncelli
Federico Simoncelli has uploaded a new change for review.
Change subject: Revert "BZ#842631 Use domain proxies instead of actual domain references"
......................................................................
Revert "BZ#842631 Use domain proxies instead of actual domain references"
This reverts commit 942c2dc8d317b6180529ed7df4eee98fbf1b9836.
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
Change-Id: Id4b1e0600948ab24e144df94f8d02a101a87627a
---
M vdsm/storage/sdc.py
1 file changed, 11 insertions(+), 40 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/93/7293/1
diff --git a/vdsm/storage/sdc.py b/vdsm/storage/sdc.py
index 2e8a6ff..9a7d09d 100644
--- a/vdsm/storage/sdc.py
+++ b/vdsm/storage/sdc.py
@@ -36,21 +36,6 @@
DEFAULT_REFRESH_INTERVAL = 300
-class DomainProxy(object):
- """Keeps domain references valid even when underlying domain object changes
- (due to format conversion for example"""
- def __init__(self, cache, sdUUID):
- self._sdUUID = sdUUID
- self._cache = cache
-
- def __getattr__(self, attrName):
- dom = self.getRealDomain()
- return getattr(dom, attrName)
-
- def getRealDomain(self):
- return self._cache._realProduce(self._sdUUID)
-
-
class StorageDomainCache:
"""
Storage Domain List keeps track of all the storage domains accessible by
@@ -59,9 +44,9 @@
log = logging.getLogger('Storage.StorageDomainCache')
def __init__(self, storage_repo):
- self._syncroot = threading.RLock()
- self.__proxyCache = {}
- self.__domainCache = {}
+ self._syncroot = threading.Lock()
+ self.__cache = {}
+ self.__weakCache = {}
self.storage_repo = storage_repo
self.storageStale = True
@@ -79,14 +64,14 @@
if self.storageStale == True:
return None
try:
- return self.__proxyCache[sdUUID]()
+ return self.__weakCache[sdUUID]()
except KeyError:
return None
def _cleanStaleWeakrefs(self):
- for sdUUID, ref in self.__proxyCache.items():
+ for sdUUID, ref in self.__weakCache.items():
if ref() is None:
- del self.__proxyCache[sdUUID]
+ del self.__weakCache[sdUUID]
def produce(self, sdUUID):
dom = self._getDomainFromCache(sdUUID)
@@ -103,25 +88,11 @@
self._cleanStaleWeakrefs()
- dom = DomainProxy(self, sdUUID)
- # This is needed to preserve the semantic where if the domain was
- # absent from the cache and the domain cannot be found the
- # operation would fail
- dom.getRealDomain()
- self.__proxyCache[sdUUID] = weakref.ref(dom)
- return dom
-
- def _realProduce(self, sdUUID):
- with self._syncroot:
- try:
- return self.__domainCache[sdUUID]
- except KeyError:
- pass
-
# _findDomain will raise StorageDomainDoesNotExist if sdUUID is not
# found in storage.
dom = self._findDomain(sdUUID)
- self.__domainCache[sdUUID] = dom
+ self.__cache[sdUUID] = dom
+ self.__weakCache[sdUUID] = weakref.ref(dom)
return dom
def _findDomain(self, sdUUID):
@@ -158,15 +129,15 @@
def refresh(self):
self.invalidateStorage()
- self.__domainCache.clear()
+ self.__cache.clear()
def manuallyAddDomain(self, dom):
with self._syncroot:
- self.__domainCache[dom.sdUUID] = dom
+ self.__cache[dom.sdUUID] = dom
def manuallyRemoveDomain(self, sdUUID):
with self._syncroot:
- del self.__domainCache[sdUUID]
+ del self.__cache[sdUUID]
storage_repository = config.get('irs', 'repository')
--
To view, visit http://gerrit.ovirt.org/7293
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id4b1e0600948ab24e144df94f8d02a101a87627a
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Federico Simoncelli <fsimonce(a)redhat.com>
11 years, 3 months
Change in vdsm[master]: Rename volumeCopy API to volumeCollapse
by Federico Simoncelli
Federico Simoncelli has uploaded a new change for review.
Change subject: Rename volumeCopy API to volumeCollapse
......................................................................
Rename volumeCopy API to volumeCollapse
copyImage (the internal call used by the former volumeCopy) creates
a new template/volume collapsing the whole chain (base->volUUID).
This is not just a nomenclature problem since we need to implement
the real volumeCopy.
Change-Id: Ide39bb54d2a97b3ba8d4712750ff10a67c5764f2
---
M vdsm/API.py
M vdsm/BindingXMLRPC.py
2 files changed, 11 insertions(+), 11 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/68/2968/1
--
To view, visit http://gerrit.ovirt.org/2968
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ide39bb54d2a97b3ba8d4712750ff10a67c5764f2
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Federico Simoncelli <fsimonce(a)redhat.com>
11 years, 3 months
Change in vdsm[master]: Extend the range of Vm's niceness to allow increasing cpu sh...
by wudxw@linux.vnet.ibm.com
Mark Wu has uploaded a new change for review.
Change subject: Extend the range of Vm's niceness to allow increasing cpu shares
......................................................................
Extend the range of Vm's niceness to allow increasing cpu shares
The current range of Vm's niceness is [0, 19], and the default value 0
represnts the biggest cpu shares. So if we want to assign more cpu shares
to one vm, we have to give a higher niceness to other vms.This patch extends
the range to [-19, 19], which makes the default value 0 be the middle of it.
It's more flexible for client to set Vm's niceness.
Change-Id: I5ae55daa5655dbd10c200dfd81ba80d8e71abfb5
Signed-off-by: Mark Wu <wudxw(a)linux.vnet.ibm.com>
---
M vdsm/libvirtvm.py
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/89/6289/1
--
To view, visit http://gerrit.ovirt.org/6289
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5ae55daa5655dbd10c200dfd81ba80d8e71abfb5
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Mark Wu <wudxw(a)linux.vnet.ibm.com>
11 years, 3 months
Change in vdsm[master]: Replace calling setSchedulerParameters() with filling its XM...
by wudxw@linux.vnet.ibm.com
Mark Wu has uploaded a new change for review.
Change subject: Replace calling setSchedulerParameters() with filling its XML description.
......................................................................
Replace calling setSchedulerParameters() with filling its XML description.
This patch changes to fill cgroup cpu.share into its XML description to set
Vm's niceness instead of calling setSchedulerParameters(). It can save us a
libvirt call on VM statup.
Change-Id: I211e191022f5a18fa7d97d5a8fb42e10729ddd06
Signed-off-by: Mark Wu <wudxw(a)linux.vnet.ibm.com>
---
M vdsm/libvirtvm.py
1 file changed, 10 insertions(+), 10 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/90/6290/1
--
To view, visit http://gerrit.ovirt.org/6290
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I211e191022f5a18fa7d97d5a8fb42e10729ddd06
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Mark Wu <wudxw(a)linux.vnet.ibm.com>
11 years, 3 months
Change in vdsm[master]: Allow tobool() convert int into bool.
by wudxw@linux.vnet.ibm.com
Mark Wu has uploaded a new change for review.
Change subject: Allow tobool() convert int into bool.
......................................................................
Allow tobool() convert int into bool.
The original code return False for any number. This patch makes
it return the result of bool(number). That means for any nonzero nubmer
it returns True, and returns False for 0.
This patch also adds a test case for tobool().
Change-Id: I6ae878b1171fe6827441751d6f02167e12e8bc03
Signed-off-by: Mark Wu <wudxw(a)linux.vnet.ibm.com>
---
M tests/Makefile.am
A tests/utilsTests.py
M vdsm/utils.py
3 files changed, 39 insertions(+), 6 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/80/8480/1
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a5e4c64..eb21f25 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -42,12 +42,13 @@
parted_utils_tests.py \
permutationTests.py \
persistentDictTests.py \
- restTests.py \
- restData.py \
- tcTests.py \
- vdsClientTests.py \
remoteFileHandlerTests.py \
- resourceManagerTests.py
+ resourceManagerTests.py \
+ restData.py \
+ restTests.py \
+ tcTests.py \
+ utilsTests.py \
+ vdsClientTests.py
dist_noinst_DATA = \
run_tests_local.sh
diff --git a/tests/utilsTests.py b/tests/utilsTests.py
new file mode 100644
index 0000000..01d8de0
--- /dev/null
+++ b/tests/utilsTests.py
@@ -0,0 +1,32 @@
+#
+# Copyright IBM Corp. 2012
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+from vdsm import utils
+from testrunner import VdsmTestCase as TestCaseBase
+
+
+class TestUtils(TestCaseBase):
+
+ def test_tobool(self):
+ self.assertEqual(utils.tobool('true'), True)
+ self.assertEqual(utils.tobool('false'), False)
+ self.assertEqual(utils.tobool('foo'), False)
+ self.assertEqual(utils.tobool(None), False)
+ self.assertEqual(utils.tobool(0), False)
+ self.assertEqual(utils.tobool(1), True)
diff --git a/vdsm/utils.py b/vdsm/utils.py
index 0dbb342..96aa928 100644
--- a/vdsm/utils.py
+++ b/vdsm/utils.py
@@ -657,7 +657,7 @@
return False
if type(s) == bool:
return s
- if s.lower() == 'true':
+ if type(s) == str and s.lower() == 'true':
return True
return bool(int(s))
except:
--
To view, visit http://gerrit.ovirt.org/8480
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6ae878b1171fe6827441751d6f02167e12e8bc03
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Mark Wu <wudxw(a)linux.vnet.ibm.com>
11 years, 3 months