From 5b773adada2e1baa76032f7a38e0d4d624eb67d6 Mon Sep 17 00:00:00 2001
From: huangtianhua <huangtianhua@huawei.com>
Date: Fri, 6 Dec 2013 11:41:44 +0800
Subject: [PATCH] Fix "device" as the optional para on volume-attach

Attach a volume to a server without device name, the client returned the
error msg: "error: too few arguments". But for server, we can attach a
volume to a server without the device name.

Change-Id: Ia2743c6e3956cae6591ecd414baf89b0dbcf532b
Closes-Bug: #1257137
---
 novaclient/tests/v1_1/test_shell.py | 7 +++++++
 novaclient/v1_1/shell.py            | 2 +-
 novaclient/v3/shell.py              | 2 +-
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/novaclient/tests/v1_1/test_shell.py b/novaclient/tests/v1_1/test_shell.py
index c02dc3dcf..4eb2c7d41 100644
--- a/novaclient/tests/v1_1/test_shell.py
+++ b/novaclient/tests/v1_1/test_shell.py
@@ -1790,6 +1790,13 @@ class ShellTest(utils.TestCase):
                                {'device': '/dev/vdb',
                                 'volumeId': 'Work'}})
 
+    def test_volume_attach_without_device(self):
+        self.run_command('volume-attach sample-server Work')
+        self.assert_called('POST', '/servers/1234/os-volume_attachments',
+                           {'volumeAttachment':
+                               {'device': None,
+                                'volumeId': 'Work'}})
+
     def test_volume_update(self):
         self.run_command('volume-update sample-server Work Work')
         self.assert_called('PUT', '/servers/1234/os-volume_attachments/Work',
diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py
index 890fd0daa..b3de5808d 100644
--- a/novaclient/v1_1/shell.py
+++ b/novaclient/v1_1/shell.py
@@ -1707,7 +1707,7 @@ def do_volume_delete(cs, args):
 @utils.arg('volume',
     metavar='<volume>',
     help='ID of the volume to attach.')
-@utils.arg('device', metavar='<device>',
+@utils.arg('device', metavar='<device>', default=None, nargs='?',
     help='Name of the device e.g. /dev/vdb. '
          'Use "auto" for autoassign (if supported)')
 def do_volume_attach(cs, args):
diff --git a/novaclient/v3/shell.py b/novaclient/v3/shell.py
index bc123b29e..39ad3d2ed 100644
--- a/novaclient/v3/shell.py
+++ b/novaclient/v3/shell.py
@@ -1557,7 +1557,7 @@ def do_volume_delete(cs, args):
 @utils.arg('volume',
     metavar='<volume>',
     help='ID of the volume to attach.')
-@utils.arg('device', metavar='<device>',
+@utils.arg('device', metavar='<device>', default=None, nargs='?',
     help='Name of the device e.g. /dev/vdb. '
          'Use "auto" for autoassign (if supported)')
 def do_volume_attach(cs, args):