body = {'volume': 'string'}
self._create_volume_bad_request(body=body)
- @mock.patch('cinder.volume.api.API.get_all')
- def test_get_volumes_filter_with_string(self, get_all):
+ def _test_get_volumes_by_name(self, get_all, display_name):
req = mock.MagicMock()
context = mock.Mock()
req.environ = {'cinder.context': context}
- req.params = {'display_name': 'Volume-573108026'}
+ req.params = {'display_name': display_name}
self.controller._view_builder.detail_list = mock.Mock()
self.controller._get_volumes(req, True)
get_all.assert_called_once_with(
context, None, CONF.osapi_max_limit,
sort_keys=['created_at'], sort_dirs=['desc'],
- filters={'display_name': 'Volume-573108026'},
+ filters={'display_name': display_name},
viewable_admin_meta=True, offset=0)
+ @mock.patch('cinder.volume.api.API.get_all')
+ def test_get_volumes_filter_with_string(self, get_all):
+ """Test to get a volume with an alpha-numeric display name."""
+ self._test_get_volumes_by_name(get_all, 'Volume-573108026')
+
+ @mock.patch('cinder.volume.api.API.get_all')
+ def test_get_volumes_filter_with_double_quoted_string(self, get_all):
+ """Test to get a volume with a double-quoted display name."""
+ self._test_get_volumes_by_name(get_all, '"Volume-573108026"')
+
+ @mock.patch('cinder.volume.api.API.get_all')
+ def test_get_volumes_filter_with_single_quoted_string(self, get_all):
+ """Test to get a volume with a single-quoted display name."""
+ self._test_get_volumes_by_name(get_all, "'Volume-573108026'")
+
+ @mock.patch('cinder.volume.api.API.get_all')
+ def test_get_volumes_filter_with_quote_in_between_string(self, get_all):
+ """Test to get a volume with a quote in between the display name."""
+ self._test_get_volumes_by_name(get_all, 'Volu"me-573108026')
+
+ @mock.patch('cinder.volume.api.API.get_all')
+ def test_get_volumes_filter_with_mixed_quoted_string(self, get_all):
+ """Test to get a volume with a mix of single and double quotes. """
+ # The display name starts with a single quote and ends with a
+ # double quote
+ self._test_get_volumes_by_name(get_all, '\'Volume-573108026"')
+
@mock.patch('cinder.volume.api.API.get_all')
def test_get_volumes_filter_with_true(self, get_all):
req = mock.MagicMock()
filters[k] = True
else:
filters[k] = bool(v)
+ elif k == 'display_name':
+ # Use the raw value of display name as is for the filter
+ # without passing it through ast.literal_eval(). If the
+ # display name is a properly quoted string (e.g. '"foo"')
+ # then literal_eval() strips the quotes (i.e. 'foo'), so
+ # the filter becomes different from the user input.
+ continue
else:
filters[k] = ast.literal_eval(v)
except (ValueError, SyntaxError):