fc119315f1
Cinder v2 API allows creating a volume with a quoted (single or double quotes or even unbalanced number of quotes) display name. But when we try to get info for such volume, we end up getting an error message saying that no volume with such a name or ID exists. This error is due to the inadvertent stripping of quotes from the filter in the api layer. The api call eventually comes to check_volume_filters() in cinder/volume/api.py. The invocation of ast.literal_eval() inside this method strips the quotes for certain quoted strings leading to this incorrect filtering. ast.literal_eval() is used to convert string representations into python objects which are then used to frame the SQL queries in the db layer. For example, the string "[1,2]" for a filter (not the display name filter) gets converted to a list object and results in an "IN" operation being emitted in the SQL query as opposed to an exact match. When display_name does not contain any quotes or contains an unbalanced number of quotes, then ast.literal_eval() throws (just like the Python interpreter would throw for an unquoted string literal or one with unbalanced number of quotes). We handle this by ignoring the exception and using the raw input value as the filter and moving on. For string containing balanced number of quotes, such as, '"foo"', ast.literal_eval() succeeds and returns the input with the surrounding quotes stripped (just like how the python interpreter strips quotes from a string literal to initialize a string var's value in memory). To always use the raw user input string as the filter value, we can either not pass string inputs to ast.literal_eval() or encode the string using encode("string-escape") so that we get the original string back after passing through ast.literal_eval(). We choose the former as the latter buys us nothing. Change-Id: I48e0aea801ccb011cb974eea3d685bb9f35c61b2 Closes-Bug: #1503485
6 lines
130 B
YAML
6 lines
130 B
YAML
---
|
|
fixes:
|
|
- Filtering volumes by their display name now
|
|
correctly handles display names with single and
|
|
double quotes.
|