Logging ironic port creation

Adds info level logging for ironic port creation.

Change-Id: Ib7c24a4b6415a5ddcad997b2aa2092ec9f353858
This commit is contained in:
Anton Arefiev 2017-04-20 16:16:10 +03:00
parent 68cbd1286f
commit 703b780bc1
2 changed files with 23 additions and 1 deletions
ironic_inspector

@ -385,6 +385,11 @@ class NodeInfo(object):
try:
port = ironic.port.create(
node_uuid=self.uuid, address=mac, **kwargs)
LOG.info('Port %(uuid)s was created successfully, MAC: %(mac)s,'
'attributes: %(attrs)s',
{'uuid': port.uuid, 'mac': port.address,
'attrs': kwargs},
node_info=self)
except exceptions.Conflict:
LOG.warning('Port %s already exists, skipping',
mac, node_info=self)

@ -746,9 +746,26 @@ class TestUpdate(test_base.NodeTest):
self.assertFalse(mock_warn.called)
self.assertFalse(self.ironic.port.list.called)
@mock.patch.object(node_cache.LOG, 'info', autospec=True)
def test__create_port(self, mock_info):
uuid = uuidutils.generate_uuid()
address = 'mac1'
self.ironic.port.create.return_value = mock.Mock(uuid=uuid,
address=address)
self.node_info._create_port(address, client_id='42')
self.ironic.port.create.assert_called_once_with(
node_uuid=self.uuid, address='mac1', client_id='42')
mock_info.assert_called_once_with(
mock.ANY, {'uuid': uuid, 'mac': address,
'attrs': {'client_id': '42'}},
node_info=self.node_info)
@mock.patch.object(node_cache.LOG, 'warning', autospec=True)
def test_create_ports_with_conflicts(self, mock_warn):
self.ironic.port.create.return_value = mock.sentinel.port
self.ironic.port.create.return_value = mock.Mock(
uuid='fake', address='mac')
ports = [
'mac',