340
352
@mock.patch('ironic.dhcp.neutron.NeutronDHCPApi._get_port_ip_address')
341
353
def test_get_ip_addresses(self, get_ip_mock):
342
354
ip_address = '10.10.0.1'
343
address = "aa:aa:aa:aa:aa:aa"
344
355
expected = [ip_address]
345
port = object_utils.create_test_port(self.context,
346
node_id=self.node.id,
349
357
get_ip_mock.return_value = ip_address
351
359
with task_manager.acquire(self.context, self.node.uuid) as task:
352
360
api = dhcp_factory.DHCPFactory().provider
353
361
result = api.get_ip_addresses(task)
354
get_ip_mock.assert_called_once_with(task, port.uuid, mock.ANY)
362
get_ip_mock.assert_called_once_with(task, self.ports[0].uuid,
355
364
self.assertEqual(expected, result)
366
@mock.patch.object(client.Client, 'create_port')
367
def test_create_cleaning_ports(self, create_mock):
368
# Ensure we can create cleaning ports for in band cleaning
369
create_mock.return_value = {'port': self.neutron_port}
370
expected = {self.ports[0].uuid: self.neutron_port['id']}
371
api = dhcp_factory.DHCPFactory().provider
373
with task_manager.acquire(self.context, self.node.uuid) as task:
374
ports = api.create_cleaning_ports(task)
375
self.assertEqual(expected, ports)
376
create_mock.assert_called_once_with({'port': {
377
'network_id': '00000000-0000-0000-0000-000000000000',
378
'admin_state_up': True, 'mac_address': self.ports[0].address}})
380
@mock.patch('ironic.conductor.manager.cleaning_error_handler')
381
@mock.patch.object(client.Client, 'create_port')
382
def test_create_cleaning_ports_fail(self, create_mock, error_mock):
383
# Check that if creating a port fails, the node goes to cleanfail
384
create_mock.side_effect = neutron_client_exc.ConnectionFailed
385
api = dhcp_factory.DHCPFactory().provider
387
with task_manager.acquire(self.context, self.node.uuid) as task:
388
api.create_cleaning_ports(task)
389
error_mock.assert_called_once_with(task, mock.ANY)
390
create_mock.assert_called_once_with({'port': {
391
'network_id': '00000000-0000-0000-0000-000000000000',
392
'admin_state_up': True, 'mac_address': self.ports[0].address}})
394
@mock.patch('ironic.conductor.manager.cleaning_error_handler')
395
@mock.patch.object(client.Client, 'create_port')
396
def test_create_cleaning_ports_bad_config(self, create_mock, error_mock):
397
self.config(cleaning_network_uuid=None, group='neutron')
398
api = dhcp_factory.DHCPFactory().provider
400
with task_manager.acquire(self.context, self.node.uuid) as task:
401
self.assertRaises(exception.InvalidParameterValue,
402
api.create_cleaning_ports, task)
404
@mock.patch.object(client.Client, 'delete_port')
405
@mock.patch.object(client.Client, 'list_ports')
406
def test_delete_cleaning_ports(self, list_mock, delete_mock):
407
# Ensure that we can delete cleaning ports, and that ports with
408
# different macs don't get deleted
409
other_port = {'id': '132f871f-eaec-4fed-9475-0d54465e0f01',
410
'mac_address': 'aa:bb:cc:dd:ee:ff'}
411
list_mock.return_value = {'ports': [self.neutron_port, other_port]}
412
api = dhcp_factory.DHCPFactory().provider
414
with task_manager.acquire(self.context, self.node.uuid) as task:
415
api.delete_cleaning_ports(task)
416
list_mock.assert_called_once_with(
417
network_id='00000000-0000-0000-0000-000000000000')
418
delete_mock.assert_called_once_with(self.neutron_port['id'])
420
@mock.patch('ironic.conductor.manager.cleaning_error_handler')
421
@mock.patch.object(client.Client, 'list_ports')
422
def test_delete_cleaning_ports_list_fail(self, list_mock, error_mock):
423
# Check that if listing ports fails, the node goes to cleanfail
424
list_mock.side_effect = neutron_client_exc.ConnectionFailed
425
api = dhcp_factory.DHCPFactory().provider
427
with task_manager.acquire(self.context, self.node.uuid) as task:
428
api.delete_cleaning_ports(task)
429
list_mock.assert_called_once_with(
430
network_id='00000000-0000-0000-0000-000000000000')
431
error_mock.assert_called_once_with(task, mock.ANY)
433
@mock.patch('ironic.conductor.manager.cleaning_error_handler')
434
@mock.patch.object(client.Client, 'delete_port')
435
@mock.patch.object(client.Client, 'list_ports')
436
def test_delete_cleaning_ports_delete_fail(self, list_mock, delete_mock,
438
# Check that if deleting ports fails, the node goes to cleanfail
439
list_mock.return_value = {'ports': [self.neutron_port]}
440
delete_mock.side_effect = neutron_client_exc.ConnectionFailed
441
api = dhcp_factory.DHCPFactory().provider
443
with task_manager.acquire(self.context, self.node.uuid) as task:
444
api.delete_cleaning_ports(task)
445
list_mock.assert_called_once_with(
446
network_id='00000000-0000-0000-0000-000000000000')
447
delete_mock.assert_called_once_with(self.neutron_port['id'])
448
error_mock.assert_called_once_with(task, mock.ANY)