From 5b3e809c147a59971260f35f41510c20acaed3b4 Mon Sep 17 00:00:00 2001 From: TommyLike Date: Sat, 25 Nov 2017 15:23:44 +0800 Subject: [PATCH] Fix 'KeyError' when 'with_count' is not specified Pop method will raise KeyError if the key does not exist. Fix this by ensuring 'with_count' exists before parsing the string value. Change-Id: Ibcba92f7cdb2506f3b2f31baa2fca6c696ff57a4 --- cinder/api/contrib/backups.py | 3 ++- cinder/api/v3/snapshots.py | 3 ++- cinder/api/v3/volumes.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cinder/api/contrib/backups.py b/cinder/api/contrib/backups.py index 84a3e2d3616..200d5a53b53 100644 --- a/cinder/api/contrib/backups.py +++ b/cinder/api/contrib/backups.py @@ -103,7 +103,8 @@ class BackupsController(wsgi.Controller): sort_keys, sort_dirs = common.get_sort_params(filters) show_count = False - if req_version.matches(mv.SUPPORT_COUNT_INFO): + if req_version.matches( + mv.SUPPORT_COUNT_INFO) and 'with_count' in filters: show_count = utils.get_bool_param('with_count', filters) filters.pop('with_count') self._convert_sort_name(req_version, sort_keys) diff --git a/cinder/api/v3/snapshots.py b/cinder/api/v3/snapshots.py index 276967d6c92..2595cf02540 100644 --- a/cinder/api/v3/snapshots.py +++ b/cinder/api/v3/snapshots.py @@ -80,7 +80,8 @@ class SnapshotsController(snapshots_v2.SnapshotsController): req_version = req.api_version_request show_count = False - if req_version.matches(mv.SUPPORT_COUNT_INFO): + if req_version.matches( + mv.SUPPORT_COUNT_INFO) and 'with_count' in search_opts: show_count = utils.get_bool_param('with_count', search_opts) search_opts.pop('with_count') diff --git a/cinder/api/v3/volumes.py b/cinder/api/v3/volumes.py index 4aa84801c9c..9b40144d00b 100644 --- a/cinder/api/v3/volumes.py +++ b/cinder/api/v3/volumes.py @@ -98,7 +98,8 @@ class VolumeController(volumes_v2.VolumeController): filters = params show_count = False - if req_version.matches(mv.SUPPORT_COUNT_INFO): + if req_version.matches( + mv.SUPPORT_COUNT_INFO) and 'with_count' in filters: show_count = utils.get_bool_param('with_count', filters) filters.pop('with_count')