diff options
-rw-r--r-- | cinderclient/shell.py | 17 | ||||
-rw-r--r-- | cinderclient/tests/unit/v3/test_shell.py | 18 | ||||
-rw-r--r-- | releasenotes/notes/collect-timing-ce6d521d40d422fb.yaml | 6 |
3 files changed, 41 insertions, 0 deletions
diff --git a/cinderclient/shell.py b/cinderclient/shell.py index dc9190a..ad7876c 100644 --- a/cinderclient/shell.py +++ b/cinderclient/shell.py @@ -705,6 +705,12 @@ class OpenStackCinderShell(object): if not auth_session: auth_session = self._get_keystone_session() + # collect_timing is a keystone session option + if (not isinstance(auth_session, session.Session) + and getattr(args, 'collect_timing', False) is True): + raise exc.AuthorizationFailure("Provided auth plugin doesn't " + "support collect_timing option") + insecure = self.options.insecure client_args = dict( @@ -805,6 +811,17 @@ class OpenStackCinderShell(object): print("To display trace use next command:\n" "osprofiler trace show --html %s " % trace_id) + if getattr(args, 'collect_timing', False) is True: + self._print_timings(auth_session) + + def _print_timings(self, session): + timings = session.get_timings() + utils.print_list( + timings, + fields=('method', 'url', 'seconds'), + sortby_index=None, + formatters={'seconds': lambda r: r.elapsed.total_seconds()}) + def _discover_client(self, current_client, os_api_version, diff --git a/cinderclient/tests/unit/v3/test_shell.py b/cinderclient/tests/unit/v3/test_shell.py index 58caddc..ee71620 100644 --- a/cinderclient/tests/unit/v3/test_shell.py +++ b/cinderclient/tests/unit/v3/test_shell.py @@ -970,6 +970,15 @@ class ShellTest(utils.TestCase): } } + SNAP_BODY_3_66_W_METADATA = { + 'snapshot': { + 'volume_id': '123456', + 'name': None, + 'description': None, + 'metadata': {'a': 'b'} + } + } + @ddt.data(True, 'true', 'on', '1') @mock.patch('cinderclient.utils.find_resource') def test_snapshot_create_3_66_with_force_true(self, f_val, mock_find_vol): @@ -1037,6 +1046,15 @@ class ShellTest(utils.TestCase): self.assert_called_anytime('POST', '/snapshots', body=pre_3_66_request_body) + @mock.patch('cinderclient.utils.find_resource') + def test_snapshot_create_w_metadata(self, mock_find_vol): + mock_find_vol.return_value = volumes.Volume( + self, {'id': '123456'}, loaded=True) + self.run_command('--os-volume-api-version 3.66 ' + 'snapshot-create 123456 --metadata a=b') + self.assert_called_anytime('POST', '/snapshots', + body=self.SNAP_BODY_3_66_W_METADATA) + def test_snapshot_manageable_list(self): self.run_command('--os-volume-api-version 3.8 ' 'snapshot-manageable-list fakehost') diff --git a/releasenotes/notes/collect-timing-ce6d521d40d422fb.yaml b/releasenotes/notes/collect-timing-ce6d521d40d422fb.yaml new file mode 100644 index 0000000..aa22517 --- /dev/null +++ b/releasenotes/notes/collect-timing-ce6d521d40d422fb.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + `Bug #1960337 <https://bugs.launchpad.net/cinder/+bug/1960337>`_: Added + support for ``collect-timing`` parameter to see the timings of REST API + requests from the client when using Keystone authentication. |