From: Kun Huang Date: Thu, 11 Jul 2013 04:04:52 +0000 (+0800) Subject: remove improper assert usage X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=718a5293bc9ac36f5cbccb35296322fd7446f36d;p=openstack-build%2Fcinder-build.git remove improper assert usage There're many talks about it. An assert should be used for `never happen` cases, not common paramaters validating. With grep, we could many all assert statement used in none-test codes: cinder/volume/drivers/san/solaris.py:110: cinder/volume/drivers/san/solaris.py:116: cinder/volume/drivers/san/solaris.py:161: cinder/volume/drivers/san/solaris.py:162: cinder/volume/drivers/san/solaris.py:163: cinder/volume/drivers/san/solaris.py:164: cinder/volume/drivers/san/solaris.py:170: checking cmd output which should never changed, so leave it cinder/db/sqlalchemy/migration.py:113: ensure file existence from impossible cases, so leave it cinder/utils.py: used for functional flow, so use ValueError instead fixes bug #1199354 Change-Id: I2b1701269bdf7c8737548e57bd940921a6256372 --- diff --git a/cinder/utils.py b/cinder/utils.py index 276e80d29..49b3c2564 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -590,21 +590,20 @@ def xhtml_escape(value): def utf8(value): """Try to turn a string into utf-8 if possible. - Code is directly from the utf8 function in - http://github.com/facebook/tornado/blob/master/tornado/escape.py - """ if isinstance(value, unicode): return value.encode('utf-8') - assert isinstance(value, str) - return value + elif isinstance(value, str): + return value + else: + raise ValueError("%s is not a string" % value) def get_from_path(items, path): """Returns a list of items matching the specified path. Takes an XPath-like expression e.g. prop1/prop2/prop3, and for each item - in items, looks up items[prop1][prop2][prop3]. Like XPath, if any of the + in items, looks up items[prop1][prop2][prop3]. Like XPath, if any of the intermediate results are lists it will treat each list item individually. A 'None' in items or any child expressions will be ignored, this function will not throw because of None (anywhere) in items. The returned list