Merge "Add --uuid to port-create"
This commit is contained in:
commit
bbc9fe1534
@ -38,6 +38,9 @@ CREATE_PORT = copy.deepcopy(PORT)
|
|||||||
del CREATE_PORT['id']
|
del CREATE_PORT['id']
|
||||||
del CREATE_PORT['uuid']
|
del CREATE_PORT['uuid']
|
||||||
|
|
||||||
|
CREATE_PORT_WITH_UUID = copy.deepcopy(PORT)
|
||||||
|
del CREATE_PORT_WITH_UUID['id']
|
||||||
|
|
||||||
UPDATED_PORT = copy.deepcopy(PORT)
|
UPDATED_PORT = copy.deepcopy(PORT)
|
||||||
NEW_ADDR = 'AA:AA:AA:AA:AA:AA'
|
NEW_ADDR = 'AA:AA:AA:AA:AA:AA'
|
||||||
UPDATED_PORT['address'] = NEW_ADDR
|
UPDATED_PORT['address'] = NEW_ADDR
|
||||||
@ -290,6 +293,14 @@ class PortManagerTest(testtools.TestCase):
|
|||||||
self.assertEqual(expect, self.api.calls)
|
self.assertEqual(expect, self.api.calls)
|
||||||
self.assertTrue(port)
|
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):
|
def test_delete(self):
|
||||||
port = self.mgr.delete(port_id=PORT['uuid'])
|
port = self.mgr.delete(port_id=PORT['uuid'])
|
||||||
expect = [
|
expect = [
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
|
from oslo_utils import uuidutils
|
||||||
|
|
||||||
from ironicclient.common.apiclient import exceptions
|
from ironicclient.common.apiclient import exceptions
|
||||||
from ironicclient.common import cliutils
|
from ironicclient.common import cliutils
|
||||||
from ironicclient.common import utils as commonutils
|
from ironicclient.common import utils as commonutils
|
||||||
@ -232,6 +234,14 @@ class PortShellTest(utils.BaseTestCase):
|
|||||||
p_shell.do_port_create(client_mock, args)
|
p_shell.do_port_create(client_mock, args)
|
||||||
client_mock.port.create.assert_called_once_with()
|
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):
|
def test_do_port_create_valid_fields_values(self):
|
||||||
client_mock = mock.MagicMock()
|
client_mock = mock.MagicMock()
|
||||||
args = mock.MagicMock()
|
args = mock.MagicMock()
|
||||||
|
@ -27,7 +27,7 @@ class Port(base.Resource):
|
|||||||
|
|
||||||
class PortManager(base.CreateManager):
|
class PortManager(base.CreateManager):
|
||||||
resource_class = Port
|
resource_class = Port
|
||||||
_creation_attributes = ['address', 'extra', 'node_uuid']
|
_creation_attributes = ['address', 'extra', 'node_uuid', 'uuid']
|
||||||
_resource_name = 'ports'
|
_resource_name = 'ports'
|
||||||
|
|
||||||
def list(self, address=None, limit=None, marker=None, sort_key=None,
|
def list(self, address=None, limit=None, marker=None, sort_key=None,
|
||||||
|
@ -148,15 +148,18 @@ def do_port_list(cc, args):
|
|||||||
action='append',
|
action='append',
|
||||||
help="Record arbitrary key/value metadata. "
|
help="Record arbitrary key/value metadata. "
|
||||||
"Can be specified multiple times.")
|
"Can be specified multiple times.")
|
||||||
|
@cliutils.arg(
|
||||||
|
'-u', '--uuid',
|
||||||
|
metavar='<uuid>',
|
||||||
|
help="UUID of the port.")
|
||||||
def do_port_create(cc, args):
|
def do_port_create(cc, args):
|
||||||
"""Create a new port."""
|
"""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()
|
fields = dict((k, v) for (k, v) in vars(args).items()
|
||||||
if k in field_list and not (v is None))
|
if k in field_list and not (v is None))
|
||||||
fields = utils.args_array_to_dict(fields, 'extra')
|
fields = utils.args_array_to_dict(fields, 'extra')
|
||||||
port = cc.port.create(**fields)
|
port = cc.port.create(**fields)
|
||||||
|
|
||||||
field_list.append('uuid')
|
|
||||||
data = dict([(f, getattr(port, f, '')) for f in field_list])
|
data = dict([(f, getattr(port, f, '')) for f in field_list])
|
||||||
cliutils.print_dict(data, wrap=72)
|
cliutils.print_dict(data, wrap=72)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user