Skip to content

Commit c2b0cec

Browse files
author
Steve Martinelli
committed
Create message variables for exceptions
Instead of inline messages, let's create variables instead, as it's easier to find strings, and mark them for translation. Change-Id: Ibbcfdbc59d12a0cb4af50f73043d3ff7f3c76f99
1 parent eb6b302 commit c2b0cec

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

‎openstackclient/compute/v2/keypair.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ def take_action(self, parsed_args):
5757
with open(os.path.expanduser(parsed_args.public_key)) as p:
5858
public_key = p.read()
5959
except IOError as e:
60-
raise exceptions.CommandError(
61-
"Key file %s not found: %s" % (parsed_args.public_key, e))
60+
msg = "Key file %s not found: %s"
61+
raise exceptions.CommandError(msg
62+
% (parsed_args.public_key, e))
6263

6364
keypair = compute_client.keypairs.create(
6465
parsed_args.name,

‎openstackclient/compute/v2/server.py‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,19 +300,22 @@ def take_action(self, parsed_args):
300300
raise exceptions.CommandError("Can't open '%s': %s" % (src, e))
301301

302302
if parsed_args.min > parsed_args.max:
303-
raise exceptions.CommandError("min instances should be <= "
304-
"max instances")
303+
msg = "min instances should be <= max instances"
304+
raise exceptions.CommandError(msg)
305305
if parsed_args.min < 1:
306-
raise exceptions.CommandError("min instances should be > 0")
306+
msg = "min instances should be > 0"
307+
raise exceptions.CommandError(msg)
307308
if parsed_args.max < 1:
308-
raise exceptions.CommandError("max instances should be > 0")
309+
msg = "max instances should be > 0"
310+
raise exceptions.CommandError(msg)
309311

310312
userdata = None
311313
if parsed_args.user_data:
312314
try:
313315
userdata = open(parsed_args.user_data)
314316
except IOError as e:
315-
raise exceptions.CommandError("Can't open '%s': %s" %
317+
msg = "Can't open '%s': %s"
318+
raise exceptions.CommandError(msg %
316319
(parsed_args.user_data, e))
317320

318321
block_device_mapping = dict(v.split('=', 1)
@@ -1077,8 +1080,8 @@ def take_action(self, parsed_args):
10771080
if p1 == p2:
10781081
server.change_password(p1)
10791082
else:
1080-
raise exceptions.CommandError(
1081-
"Passwords do not match, password unchanged")
1083+
msg = "Passwords do not match, password unchanged"
1084+
raise exceptions.CommandError(msg)
10821085

10831086

10841087
class ShowServer(show.ShowOne):

‎openstackclient/network/v2/network.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ def take_action(self, parsed_args):
206206
if parsed_args.shared is not None:
207207
body['shared'] = parsed_args.shared
208208
if body == {}:
209-
raise exceptions.CommandError("Nothing specified to be set")
209+
msg = "Nothing specified to be set"
210+
raise exceptions.CommandError(msg)
210211
update_method = getattr(client, "update_network")
211212
update_method(_id, {'network': body})
212213
return

0 commit comments

Comments
 (0)