Merge lp:~anso/nova/validate-device-attach-disk into lp:~hudson-openstack/nova/trunk

Proposed by Jesse Andrews
Status: Merged
Approved by: Jesse Andrews
Approved revision: 377
Merged at revision: 382
Proposed branch: lp:~anso/nova/validate-device-attach-disk
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 21 lines (+4/-0)
1 file modified
nova/api/ec2/cloud.py (+4/-0)
To merge this branch: bzr merge lp:~anso/nova/validate-device-attach-disk
Reviewer Review Type Date Requested Status
Vish Ishaya (community) Approve
Jay Pipes (community) Approve
Review via email: mp+39238@code.launchpad.net

Description of the change

validates device parameter for attach-volume

To post a comment you must log in.
Revision history for this message
Jay Pipes (jaypipes) wrote :

Good, but how about a tiny bit more descriptive in the error message?

Instead of:

17 + raise exception.ApiError("Invalid device. Example /dev/vdb")

how about:

17 + raise exception.ApiError("Invalid device specified: %s. Example device: /dev/vdb" % device)

377. By Jesse Andrews

update error message

Revision history for this message
Jay Pipes (jaypipes) wrote :

rock on :)

review: Approve
Revision history for this message
Vish Ishaya (vishvananda) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/api/ec2/cloud.py'
2--- nova/api/ec2/cloud.py 2010-10-21 22:26:06 +0000
3+++ nova/api/ec2/cloud.py 2010-10-25 17:46:00 +0000
4@@ -25,6 +25,7 @@
5 import base64
6 import datetime
7 import logging
8+import re
9 import os
10 import time
11
12@@ -519,6 +520,9 @@
13
14 def attach_volume(self, context, volume_id, instance_id, device, **kwargs):
15 volume_ref = db.volume_get_by_ec2_id(context, volume_id)
16+ if not re.match("^/dev/[a-z]d[a-z]+$", device):
17+ raise exception.ApiError("Invalid device specified: %s. "
18+ "Example device: /dev/vdb" % device)
19 # TODO(vish): abstract status checking?
20 if volume_ref['status'] != "available":
21 raise exception.ApiError("Volume status must be available")