From e8f251c00755001dc71fa97d4eaef6a4a32e13c8 Mon Sep 17 00:00:00 2001 From: Lin Tan Date: Thu, 3 Dec 2015 14:04:08 +0800 Subject: [PATCH] Add --uuid to port-create Support specify port uuid to port-create like node-create Change-Id: Ifc187238134d4661c47efe8dea11e99c48e71a3e --- ironicclient/tests/unit/v1/test_port.py | 11 +++++++++++ ironicclient/tests/unit/v1/test_port_shell.py | 10 ++++++++++ ironicclient/v1/port.py | 2 +- ironicclient/v1/port_shell.py | 7 +++++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/ironicclient/tests/unit/v1/test_port.py b/ironicclient/tests/unit/v1/test_port.py index dd2529b1c..1c7998a92 100644 --- a/ironicclient/tests/unit/v1/test_port.py +++ b/ironicclient/tests/unit/v1/test_port.py @@ -38,6 +38,9 @@ CREATE_PORT = copy.deepcopy(PORT) del CREATE_PORT['id'] del CREATE_PORT['uuid'] +CREATE_PORT_WITH_UUID = copy.deepcopy(PORT) +del CREATE_PORT_WITH_UUID['id'] + UPDATED_PORT = copy.deepcopy(PORT) NEW_ADDR = 'AA:AA:AA:AA:AA:AA' UPDATED_PORT['address'] = NEW_ADDR @@ -290,6 +293,14 @@ class PortManagerTest(testtools.TestCase): self.assertEqual(expect, self.api.calls) self.assertTrue(port) + def test_create_with_uuid(self): + port = self.mgr.create(**CREATE_PORT_WITH_UUID) + expect = [ + ('POST', '/v1/ports', {}, CREATE_PORT_WITH_UUID), + ] + self.assertEqual(expect, self.api.calls) + self.assertTrue(port) + def test_delete(self): port = self.mgr.delete(port_id=PORT['uuid']) expect = [ diff --git a/ironicclient/tests/unit/v1/test_port_shell.py b/ironicclient/tests/unit/v1/test_port_shell.py index e65b646aa..99eb8067a 100644 --- a/ironicclient/tests/unit/v1/test_port_shell.py +++ b/ironicclient/tests/unit/v1/test_port_shell.py @@ -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 @@ -232,6 +234,14 @@ class PortShellTest(utils.BaseTestCase): p_shell.do_port_create(client_mock, args) client_mock.port.create.assert_called_once_with() + def test_do_port_create_with_uuid(self): + client_mock = mock.MagicMock() + args = mock.MagicMock() + args.uuid = uuidutils.generate_uuid() + + p_shell.do_port_create(client_mock, args) + client_mock.port.create.assert_called_once_with(uuid=args.uuid) + def test_do_port_create_valid_fields_values(self): client_mock = mock.MagicMock() args = mock.MagicMock() diff --git a/ironicclient/v1/port.py b/ironicclient/v1/port.py index d3b0c0c20..d84512db8 100644 --- a/ironicclient/v1/port.py +++ b/ironicclient/v1/port.py @@ -27,7 +27,7 @@ class Port(base.Resource): class PortManager(base.CreateManager): resource_class = Port - _creation_attributes = ['address', 'extra', 'node_uuid'] + _creation_attributes = ['address', 'extra', 'node_uuid', 'uuid'] _resource_name = 'ports' def list(self, address=None, limit=None, marker=None, sort_key=None, diff --git a/ironicclient/v1/port_shell.py b/ironicclient/v1/port_shell.py index b6f4b2270..4dc810dce 100644 --- a/ironicclient/v1/port_shell.py +++ b/ironicclient/v1/port_shell.py @@ -148,15 +148,18 @@ def do_port_list(cc, args): action='append', help="Record arbitrary key/value metadata. " "Can be specified multiple times.") +@cliutils.arg( + '-u', '--uuid', + metavar='', + help="UUID of the port.") def do_port_create(cc, args): """Create a new port.""" - field_list = ['address', 'extra', 'node_uuid'] + field_list = ['address', 'extra', 'node_uuid', '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') port = cc.port.create(**fields) - field_list.append('uuid') data = dict([(f, getattr(port, f, '')) for f in field_list]) cliutils.print_dict(data, wrap=72)