remove inappropriate assert() usage
Bug #1199354 reported by
Alexander Gorodnev
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Cinder |
Fix Released
|
Low
|
Kun Huang | ||
Glance |
Fix Released
|
Low
|
Unassigned | ||
OpenStack Compute (nova) |
Fix Released
|
Low
|
Kun Huang | ||
neutron |
Won't Fix
|
Undecided
|
Hua Zhang |
Bug Description
There are few places in nova where asserts are used in inappropriate manner. The example is below.
for option in ['memory_mb', 'vcpus']:
try:
assert int(str(
except (ValueError, AssertionError, TypeError):
msg = _("'%s' argument must be a positive integer") % option
raise exception.
Changed in nova: | |
assignee: | nobody → Alexander Gorodnev (a-gorodnev) |
affects: | nova → cinder |
Changed in nova: | |
assignee: | nobody → Haomai Wang (haomai) |
Changed in glance: | |
assignee: | nobody → Haomai Wang (haomai) |
assignee: | Haomai Wang (haomai) → nobody |
Changed in glance: | |
assignee: | nobody → Alexander Gorodnev (a-gorodnev) |
Changed in cinder: | |
status: | New → Confirmed |
importance: | Undecided → Low |
Changed in cinder: | |
assignee: | Alexander Gorodnev (a-gorodnev) → Kun Huang (academicgareth) |
status: | Confirmed → In Progress |
Changed in neutron: | |
assignee: | nobody → Hua Zhang (zhhuabj) |
Changed in glance: | |
status: | New → In Progress |
Changed in cinder: | |
milestone: | none → havana-2 |
status: | Fix Committed → Fix Released |
Changed in nova: | |
importance: | Undecided → Low |
Changed in neutron: | |
status: | In Progress → Won't Fix |
Changed in nova: | |
assignee: | Haomai Wang (haomai) → Kun Huang (academicgareth) |
Changed in nova: | |
milestone: | none → havana-3 |
status: | Fix Committed → Fix Released |
Changed in cinder: | |
milestone: | havana-2 → 2013.2 |
Changed in nova: | |
milestone: | havana-3 → 2013.2 |
Changed in glance: | |
assignee: | Alexander Gorodnev (a-gorodnev) → nobody |
status: | In Progress → New |
tags: | added: propose-close |
Changed in glance: | |
assignee: | nobody → Cindy Pallares (cindy-pallaresq) |
Changed in glance: | |
assignee: | Cindy Pallares (cindy-pallaresq) → nobody |
Changed in glance: | |
milestone: | none → kilo-3 |
status: | Fix Committed → Fix Released |
Changed in glance: | |
milestone: | kilo-3 → 2015.1.0 |
To post a comment you must log in.
Asserts should really only be used in tests. However, if there is a place in the code where you know a given state should not be possible but perhaps could happen (for example memory corruption) and you want to trap it in a known place instead of letting it float through the system in less detectable places assert can be used. It should be considered a debugging tool and not a way to validate parameters.
Below are some places this exists in glance. Each should be validated for proper assertion use.
https:/ /github. com/openstack/ glance/ blob/master/ glance/ api/v2/ images. py#L110 /github. com/openstack/ glance/ blob/master/ glance/ api/middleware/ cache.py# L84 /github. com/openstack/ glance/ blob/master/ glance/ api/middleware/ cache.py# L88 /github. com/openstack/ glance/ blob/master/ glance/ common/ rpc.py# L97 /github. com/openstack/ glance/ blob/master/ glance/ db/__init_ _.py#L58 /github. com/openstack/ glance/ blob/master/ glance/ db/sqlalchemy/ migrate_ repo/versions/ 015_quote_ swift_credentia ls.py#L94 /github. com/openstack/ glance/ blob/master/ glance/ db/sqlalchemy/ migrate_ repo/versions/ 017_quote_ encrypted_ swift_credentia ls.py#L157 /github. com/openstack/ glance/ blob/master/ glance/ db/sqlalchemy/ api.py# L154 /github. com/openstack/ glance/ blob/master/ glance/ db/sqlalchemy/ api.py# L212 /github. com/openstack/ glance/ blob/master/ glance/ db/sqlalchemy/ api.py# L456 /github. com/openstack/ glance/ blob/master/ glance/ db/sqlalchemy/ migration. py#L134
https:/
https:/
https:/
https:/
https:/
https:/
https:/
https:/
https:/
https:/