Add --uuid to chassis-create

Support specifiy the uuid of chassis when create chassis like node.

Change-Id: I82a352f3fe877b1f1100022f9b3c304b9ab7cd24
This commit is contained in:
Lin Tan 2015-12-03 13:32:41 +08:00
parent 5751b32932
commit dd94f2303a
4 changed files with 27 additions and 3 deletions

View File

@ -46,6 +46,9 @@ CREATE_CHASSIS = copy.deepcopy(CHASSIS)
del CREATE_CHASSIS['id']
del CREATE_CHASSIS['uuid']
CREATE_WITH_UUID = copy.deepcopy(CHASSIS)
del CREATE_WITH_UUID['id']
UPDATED_CHASSIS = copy.deepcopy(CHASSIS)
NEW_DESCR = 'new-description'
UPDATED_CHASSIS['description'] = NEW_DESCR
@ -326,6 +329,14 @@ class ChassisManagerTest(testtools.TestCase):
self.assertEqual(expect, self.api.calls)
self.assertTrue(chassis)
def test_create_with_uuid(self):
chassis = self.mgr.create(**CREATE_WITH_UUID)
expect = [
('POST', '/v1/chassis', {}, CREATE_WITH_UUID),
]
self.assertEqual(expect, self.api.calls)
self.assertTrue(chassis)
def test_delete(self):
chassis = self.mgr.delete(chassis_id=CHASSIS['uuid'])
expect = [

View File

@ -14,6 +14,8 @@
import mock
from oslo_utils import uuidutils
from ironicclient.common.apiclient import exceptions
from ironicclient.common import cliutils
from ironicclient.common import utils as commonutils
@ -316,6 +318,14 @@ class ChassisShellTest(utils.BaseTestCase):
c_shell.do_chassis_create(client_mock, args)
client_mock.chassis.create.assert_called_once_with()
def test_do_chassis_create_with_uuid(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
args.uuid = uuidutils.generate_uuid()
c_shell.do_chassis_create(client_mock, args)
client_mock.chassis.create.assert_called_once_with(uuid=args.uuid)
def test_do_chassis_create_valid_field(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()

View File

@ -28,7 +28,7 @@ class Chassis(base.Resource):
class ChassisManager(base.CreateManager):
resource_class = Chassis
_resource_name = 'chassis'
_creation_attributes = ['description', 'extra']
_creation_attributes = ['description', 'extra', 'uuid']
def list(self, marker=None, limit=None, sort_key=None,
sort_dir=None, detail=False, fields=None):

View File

@ -120,15 +120,18 @@ def do_chassis_list(cc, args):
action='append',
help="Record arbitrary key/value metadata. "
"Can be specified multiple times.")
@cliutils.arg(
'-u', '--uuid',
metavar='<uuid>',
help="UUID of the chassis.")
def do_chassis_create(cc, args):
"""Create a new chassis."""
field_list = ['description', 'extra']
field_list = ['description', 'extra', 'uuid']
fields = dict((k, v) for (k, v) in vars(args).items()
if k in field_list and not (v is None))
fields = utils.args_array_to_dict(fields, 'extra')
chassis = cc.chassis.create(**fields)
field_list.append('uuid')
data = dict([(f, getattr(chassis, f, '')) for f in field_list])
cliutils.print_dict(data, wrap=72)