Skip to content

Commit 523ab58

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Log hint when --enable present with --disable-reason"
2 parents 81e37a2 + 4d3f996 commit 523ab58

3 files changed

Lines changed: 74 additions & 13 deletions

File tree

doc/source/command-objects/compute-service.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ List service command
3636
.. _compute-service-list:
3737
.. option:: --host <host>
3838

39-
List services on specified host (name only)
39+
List services on specified host (name only)
4040

4141
.. option:: --service <service>
4242

@@ -71,7 +71,8 @@ Set service command
7171

7272
.. option:: --disable-reason <reason>
7373

74-
Reason for disabling the service (in quotes)
74+
Reason for disabling the service (in quotes). Note that when the service
75+
is enabled, this option is ignored.
7576

7677
.. describe:: <host>
7778

openstackclient/compute/v2/service.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from openstackclient.common import command
1919
from openstackclient.common import utils
20+
from openstackclient.i18n import _ # noqa
2021

2122

2223
class DeleteService(command.Command):
@@ -117,8 +118,8 @@ def get_parser(self, prog_name):
117118
"--disable-reason",
118119
default=None,
119120
metavar="<reason>",
120-
help="Reason for disabling the service (in quotas)"
121-
)
121+
help="Reason for disabling the service (in quotas). Note that "
122+
"when the service is enabled, this option is ignored.")
122123
return parser
123124

124125
def take_action(self, parsed_args):
@@ -133,4 +134,8 @@ def take_action(self, parsed_args):
133134
else:
134135
cs.disable(parsed_args.host, parsed_args.service)
135136
else:
137+
if parsed_args.disable_reason:
138+
msg = _("argument --disable-reason has been ignored")
139+
self.log.info(msg)
140+
136141
cs.enable(parsed_args.host, parsed_args.service)

openstackclient/tests/compute/v2/test_service.py

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#
1515

1616
import copy
17+
import mock
1718

1819
from openstackclient.compute.v2 import service
1920
from openstackclient.tests.compute.v2 import fakes as compute_fakes
@@ -138,14 +139,14 @@ def setUp(self):
138139

139140
def test_service_set_enable(self):
140141
arglist = [
142+
'--enable',
141143
compute_fakes.service_host,
142144
compute_fakes.service_binary,
143-
'--enable',
144145
]
145146
verifylist = [
147+
('enabled', True),
146148
('host', compute_fakes.service_host),
147149
('service', compute_fakes.service_binary),
148-
('enabled', True),
149150
]
150151
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
151152

@@ -159,14 +160,14 @@ def test_service_set_enable(self):
159160

160161
def test_service_set_disable(self):
161162
arglist = [
163+
'--disable',
162164
compute_fakes.service_host,
163165
compute_fakes.service_binary,
164-
'--disable',
165166
]
166167
verifylist = [
168+
('enabled', False),
167169
('host', compute_fakes.service_host),
168170
('service', compute_fakes.service_binary),
169-
('enabled', False),
170171
]
171172
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
172173

@@ -181,17 +182,16 @@ def test_service_set_disable(self):
181182
def test_service_set_disable_with_reason(self):
182183
reason = 'earthquake'
183184
arglist = [
185+
'--disable',
186+
'--disable-reason', reason,
184187
compute_fakes.service_host,
185188
compute_fakes.service_binary,
186-
'--disable',
187-
'--disable-reason',
188-
reason
189189
]
190190
verifylist = [
191+
('enabled', False),
192+
('disable_reason', reason),
191193
('host', compute_fakes.service_host),
192194
('service', compute_fakes.service_binary),
193-
('enabled', False),
194-
('disable_reason', reason)
195195
]
196196
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
197197

@@ -203,3 +203,58 @@ def test_service_set_disable_with_reason(self):
203203
reason
204204
)
205205
self.assertIsNone(result)
206+
207+
def test_service_set_only_with_disable_reason(self):
208+
reason = 'earthquake'
209+
arglist = [
210+
'--disable-reason', reason,
211+
compute_fakes.service_host,
212+
compute_fakes.service_binary,
213+
]
214+
verifylist = [
215+
('enabled', True),
216+
('disable_reason', reason),
217+
('host', compute_fakes.service_host),
218+
('service', compute_fakes.service_binary),
219+
]
220+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
221+
222+
with mock.patch.object(self.cmd.log, 'info') as mock_log:
223+
result = self.cmd.take_action(parsed_args)
224+
225+
msg = "argument --disable-reason has been ignored"
226+
mock_log.assert_called_once_with(msg)
227+
228+
self.service_mock.enable.assert_called_with(
229+
compute_fakes.service_host,
230+
compute_fakes.service_binary
231+
)
232+
self.assertIsNone(result)
233+
234+
def test_service_set_enable_with_disable_reason(self):
235+
reason = 'earthquake'
236+
arglist = [
237+
'--enable',
238+
'--disable-reason', reason,
239+
compute_fakes.service_host,
240+
compute_fakes.service_binary,
241+
]
242+
verifylist = [
243+
('enabled', True),
244+
('disable_reason', reason),
245+
('host', compute_fakes.service_host),
246+
('service', compute_fakes.service_binary),
247+
]
248+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
249+
250+
with mock.patch.object(self.cmd.log, 'info') as mock_log:
251+
result = self.cmd.take_action(parsed_args)
252+
253+
msg = "argument --disable-reason has been ignored"
254+
mock_log.assert_called_once_with(msg)
255+
256+
self.service_mock.enable.assert_called_with(
257+
compute_fakes.service_host,
258+
compute_fakes.service_binary
259+
)
260+
self.assertIsNone(result)

0 commit comments

Comments
 (0)