diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-03-20 13:49:49 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-03-20 13:49:49 +0000 |
commit | a910e42fda9a8c7f25e67174a5c6abda51cce0ee (patch) | |
tree | 2a7cccdaeb07ad0c11d9dc0564e4d0a340a57299 | |
parent | 98ac5b6ac667a1a83314becf1479a57223496afb (diff) | |
parent | f72dc0c38951c898fc139cee6446ef0f125fde10 (diff) | |
download | python-ceilometerclient-a910e42fda9a8c7f25e67174a5c6abda51cce0ee.tar.gz |
Merge "support specify user-id when create sample and alarm"
-rw-r--r-- | ceilometerclient/tests/unit/v2/test_shell.py | 36 | ||||
-rw-r--r-- | ceilometerclient/v2/shell.py | 9 |
2 files changed, 31 insertions, 14 deletions
diff --git a/ceilometerclient/tests/unit/v2/test_shell.py b/ceilometerclient/tests/unit/v2/test_shell.py index a4b9f33..84a884b 100644 --- a/ceilometerclient/tests/unit/v2/test_shell.py +++ b/ceilometerclient/tests/unit/v2/test_shell.py @@ -1124,45 +1124,51 @@ class ShellEventListCommandTest(utils.BaseTestCase): class ShellShadowedArgsTest(test_shell.ShellTestBase): - def _test_project_id_alarm(self, command, args, method): + def _test_shadowed_args_alarm(self, command, args, method): self.make_env(test_shell.FAKE_V2_ENV) cli_args = [ '--os-project-id', '0ba30185ddf44834914a0b859d244c56', + '--os-user-id', '85f59b3b17484ccb974c50596023bf8c', '--debug', command, '--project-id', 'the-project-id-i-want-to-set', + '--user-id', 'the-user-id-i-want-to-set', '--name', 'project-id-test'] + args with mock.patch.object(alarms.AlarmManager, method) as mocked: base_shell.main(cli_args) args, kwargs = mocked.call_args self.assertEqual('the-project-id-i-want-to-set', kwargs.get('project_id')) + self.assertEqual('the-user-id-i-want-to-set', + kwargs.get('user_id')) - def test_project_id_threshold_alarm(self): + def test_shadowed_args_threshold_alarm(self): cli_args = ['--meter-name', 'cpu', '--threshold', '90'] - self._test_project_id_alarm('alarm-create', cli_args, 'create') - self._test_project_id_alarm('alarm-threshold-create', - cli_args, 'create') + self._test_shadowed_args_alarm('alarm-create', cli_args, 'create') + self._test_shadowed_args_alarm('alarm-threshold-create', + cli_args, 'create') cli_args += ['--alarm_id', '437b7ed0-3733-4054-a877-e9a297b8be85'] - self._test_project_id_alarm('alarm-update', cli_args, 'update') - self._test_project_id_alarm('alarm-threshold-update', - cli_args, 'update') + self._test_shadowed_args_alarm('alarm-update', cli_args, 'update') + self._test_shadowed_args_alarm('alarm-threshold-update', + cli_args, 'update') - def test_project_id_combination_alarm(self): + def test_shadowed_args_combination_alarm(self): cli_args = ['--alarm_ids', 'fb16a05a-669d-414e-8bbe-93aa381df6a8', '--alarm_ids', 'b189bcca-0a7b-49a9-a244-a927ac291881'] - self._test_project_id_alarm('alarm-combination-create', - cli_args, 'create') + self._test_shadowed_args_alarm('alarm-combination-create', + cli_args, 'create') cli_args += ['--alarm_id', '437b7ed0-3733-4054-a877-e9a297b8be85'] - self._test_project_id_alarm('alarm-combination-update', - cli_args, 'update') + self._test_shadowed_args_alarm('alarm-combination-update', + cli_args, 'update') @mock.patch.object(samples.OldSampleManager, 'create') - def test_project_id_sample_create(self, mocked): + def test_shadowed_args_sample_create(self, mocked): self.make_env(test_shell.FAKE_V2_ENV) cli_args = [ '--os-project-id', '0ba30185ddf44834914a0b859d244c56', + '--os-user-id', '85f59b3b17484ccb974c50596023bf8c', '--debug', 'sample-create', '--project-id', 'the-project-id-i-want-to-set', + '--user-id', 'the-user-id-i-want-to-set', '--resource-id', 'b666633d-9bb6-4e05-89c0-ee5a8752fb0b', '--meter-name', 'cpu', '--meter-type', 'cumulative', @@ -1173,3 +1179,5 @@ class ShellShadowedArgsTest(test_shell.ShellTestBase): args, kwargs = mocked.call_args self.assertEqual('the-project-id-i-want-to-set', kwargs.get('project_id')) + self.assertEqual('the-user-id-i-want-to-set', + kwargs.get('user_id')) diff --git a/ceilometerclient/v2/shell.py b/ceilometerclient/v2/shell.py index 48f2fe8..2ebef78 100644 --- a/ceilometerclient/v2/shell.py +++ b/ceilometerclient/v2/shell.py @@ -197,6 +197,7 @@ def _restore_shadowed_arg(shadowed, observed): help='Tenant to associate with sample ' '(only settable by admin users).') @utils.arg('--user-id', metavar='<SAMPLE_USER_ID>', + dest='sample_user_id', help='User to associate with sample ' '(only settable by admin users).') @utils.arg('-r', '--resource-id', metavar='<RESOURCE_ID>', required=True, @@ -215,6 +216,7 @@ def _restore_shadowed_arg(shadowed, observed): @utils.arg('--timestamp', metavar='<TIMESTAMP>', help='The sample timestamp.') @_restore_shadowed_arg('project_id', 'sample_project_id') +@_restore_shadowed_arg('user_id', 'sample_user_id') def do_sample_create(cc, args={}): """Create a sample.""" arg_to_field_mapping = { @@ -417,6 +419,7 @@ def common_alarm_arguments(create=False): help='Tenant to associate with alarm ' '(only settable by admin users).') @utils.arg('--user-id', metavar='<ALARM_USER_ID>', + dest='alarm_user_id', help='User to associate with alarm ' '(only settable by admin users).') @utils.arg('--description', metavar='<DESCRIPTION>', @@ -552,6 +555,7 @@ def common_alarm_gnocchi_resources_arguments(create=False): help=('True if actions should be repeatedly notified ' 'while alarm remains in target state.')) @_restore_shadowed_arg('project_id', 'alarm_project_id') +@_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_create(cc, args={}): """Create a new alarm (Deprecated). Use alarm-threshold-create instead.""" fields = dict(filter(lambda x: not (x[1] is None), vars(args).items())) @@ -618,6 +622,7 @@ def do_alarm_gnocchi_metrics_threshold_create(cc, args={}): help=('True if actions should be repeatedly notified ' 'while alarm remains in target state.')) @_restore_shadowed_arg('project_id', 'alarm_project_id') +@_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_threshold_create(cc, args={}): """Create a new alarm based on computed statistics.""" fields = dict(filter(lambda x: not (x[1] is None), vars(args).items())) @@ -645,6 +650,7 @@ def do_alarm_threshold_create(cc, args={}): help=('True if actions should be repeatedly notified ' 'while alarm remains in target state.')) @_restore_shadowed_arg('project_id', 'alarm_project_id') +@_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_combination_create(cc, args={}): """Create a new alarm based on state of other alarms.""" fields = dict(filter(lambda x: not (x[1] is None), vars(args).items())) @@ -687,6 +693,7 @@ def do_alarm_combination_create(cc, args={}): help=('True if actions should be repeatedly notified ' 'while alarm remains in target state.')) @_restore_shadowed_arg('project_id', 'alarm_project_id') +@_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_update(cc, args={}): """Update an existing alarm (Deprecated).""" fields = dict(filter(lambda x: not (x[1] is None), vars(args).items())) @@ -739,6 +746,7 @@ def do_alarm_update(cc, args={}): help=('True if actions should be repeatedly notified ' 'while alarm remains in target state.')) @_restore_shadowed_arg('project_id', 'alarm_project_id') +@_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_threshold_update(cc, args={}): """Update an existing alarm based on computed statistics.""" fields = dict(filter(lambda x: not (x[1] is None), vars(args).items())) @@ -830,6 +838,7 @@ def do_alarm_gnocchi_metrics_threshold_update(cc, args={}): help=('True if actions should be repeatedly notified ' 'while alarm remains in target state.')) @_restore_shadowed_arg('project_id', 'alarm_project_id') +@_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_combination_update(cc, args={}): """Update an existing alarm based on state of other alarms.""" fields = dict(filter(lambda x: not (x[1] is None), vars(args).items())) |