summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEoghan Glynn <eglynn@redhat.com>2013-10-02 09:30:27 +0000
committerEoghan Glynn <eglynn@redhat.com>2013-10-02 17:15:43 +0100
commit7c8a676b43e9f82276041afbae15d739dc2c1ab4 (patch)
treee834f040133726daccdd511d774b42bebbb928e4
parentb961738765976e77711d909eec1ecc402fa8a484 (diff)
downloadpython-ceilometerclient-7c8a676b43e9f82276041afbae15d739dc2c1ab4.tar.gz
Fix shell.do_alarm_get_state to get as opposed to set
Otherwise the CLI fails when attempting to set a state arg that doesn't exist. (Simple copy'n'paste error in the original code). Change-Id: Iab117177805449ddec9d03656a95a0cbbbbd58bb
-rw-r--r--ceilometerclient/tests/v2/test_shell.py39
-rw-r--r--ceilometerclient/v2/shell.py6
-rw-r--r--test-requirements.txt1
3 files changed, 42 insertions, 4 deletions
diff --git a/ceilometerclient/tests/v2/test_shell.py b/ceilometerclient/tests/v2/test_shell.py
new file mode 100644
index 0000000..c758619
--- /dev/null
+++ b/ceilometerclient/tests/v2/test_shell.py
@@ -0,0 +1,39 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import mock
+
+from ceilometerclient.tests import utils
+from ceilometerclient.v2 import shell as ceilometer_shell
+
+
+class ShellAlarmStateCommandsTest(utils.BaseTestCase):
+
+ ALARM_ID = 'foobar'
+
+ def setUp(self):
+ super(ShellAlarmStateCommandsTest, self).setUp()
+ self.cc = mock.Mock()
+ self.cc.alarms = mock.Mock()
+ self.args = mock.Mock()
+ self.args.alarm_id = self.ALARM_ID
+
+ def test_alarm_state_get(self):
+ ceilometer_shell.do_alarm_get_state(self.cc, self.args)
+ self.cc.alarms.get_state.assert_called_once_with(self.ALARM_ID)
+ self.assertFalse(self.cc.alarms.set_state.called)
+
+ def test_alarm_state_set(self):
+ self.args.state = 'ok'
+ ceilometer_shell.do_alarm_set_state(self.cc, self.args)
+ self.cc.alarms.set_state.assert_called_once_with(self.ALARM_ID, 'ok')
+ self.assertFalse(self.cc.alarms.get_state.called)
diff --git a/ceilometerclient/v2/shell.py b/ceilometerclient/v2/shell.py
index bcd5657..76aea34 100644
--- a/ceilometerclient/v2/shell.py
+++ b/ceilometerclient/v2/shell.py
@@ -423,10 +423,9 @@ def do_alarm_delete(cc, args={}):
def do_alarm_set_state(cc, args={}):
'''Set the state of an alarm.'''
try:
- cc.alarms.set_state(args.alarm_id, args.state)
+ state = cc.alarms.set_state(args.alarm_id, args.state)
except exc.HTTPNotFound:
raise exc.CommandError('Alarm not found: %s' % args.alarm_id)
- state = cc.alarms.get_state(args.alarm_id)
utils.print_dict({'state': state}, wrap=72)
@@ -435,10 +434,9 @@ def do_alarm_set_state(cc, args={}):
def do_alarm_get_state(cc, args={}):
'''Get the state of an alarm.'''
try:
- cc.alarms.set_state(args.alarm_id, args.state)
+ state = cc.alarms.get_state(args.alarm_id)
except exc.HTTPNotFound:
raise exc.CommandError('Alarm not found: %s' % args.alarm_id)
- state = cc.alarms.get_state(args.alarm_id)
utils.print_dict({'state': state}, wrap=72)
diff --git a/test-requirements.txt b/test-requirements.txt
index a3e4bfc..26843ce 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -6,6 +6,7 @@ hacking>=0.5.6,<0.8
coverage>=3.6
discover
fixtures>=0.3.14
+mock>=1.0
mox>=0.5.3
python-subunit
sphinx>=1.1.2