summaryrefslogtreecommitdiff
path: root/ironic/tests/unit/dhcp
diff options
context:
space:
mode:
authorvsaienko <vsaienko@mirantis.com>2016-03-16 11:31:38 +0200
committervsaienko <vsaienko@mirantis.com>2016-04-21 18:17:01 +0300
commit5cf9f083feb8d6f239b53f6c03f549b8cfb2c8dd (patch)
treefdb1eac6b005d92e435f40f7c17bf0fbc221f131 /ironic/tests/unit/dhcp
parent3d80e41e8d457443a6a5000f2a8afd1ccddd261a (diff)
downloadironic-5cf9f083feb8d6f239b53f6c03f549b8cfb2c8dd.tar.gz
Allow to set Neutron port setup delay from config
Unfortunately there still no mechanism to synchronize events with Neutron. Sometimes server can get to PXE faster than Neutron configures port for netboot. It may occur with VMs, and hardware servers with fast boot enabled. This patch introduce new config variable 'port_setup_delay' that allows to wait for Neutron operations. Change-Id: Iaeb78649a92b89e2c6eb0f545aed95a766d14430
Diffstat (limited to 'ironic/tests/unit/dhcp')
-rw-r--r--ironic/tests/unit/dhcp/test_neutron.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/ironic/tests/unit/dhcp/test_neutron.py b/ironic/tests/unit/dhcp/test_neutron.py
index 1b0283469..2647639e7 100644
--- a/ironic/tests/unit/dhcp/test_neutron.py
+++ b/ironic/tests/unit/dhcp/test_neutron.py
@@ -26,6 +26,7 @@ from ironic.common import exception
from ironic.common import pxe_utils
from ironic.conductor import task_manager
from ironic.dhcp import neutron
+from ironic.drivers.modules import ssh
from ironic.tests.unit.conductor import mgr_utils
from ironic.tests.unit.db import base as db_base
from ironic.tests.unit.objects import utils as object_utils
@@ -250,6 +251,87 @@ class TestNeutron(db_base.DbTestCase):
mock_gnvi.assert_called_once_with(task)
self.assertEqual(2, mock_updo.call_count)
+ @mock.patch('time.sleep', autospec=True)
+ @mock.patch.object(neutron.NeutronDHCPApi, 'update_port_dhcp_opts',
+ autospec=True)
+ @mock.patch('ironic.common.network.get_node_vif_ids', autospec=True)
+ def test_update_dhcp_set_sleep_and_ssh(self, mock_gnvi, mock_updo,
+ mock_ts):
+ mock_gnvi.return_value = {'ports': {'port-uuid': 'vif-uuid'},
+ 'portgroups': {}}
+ self.config(port_setup_delay=30, group='neutron')
+ with task_manager.acquire(self.context,
+ self.node.uuid) as task:
+ task.driver.power = ssh.SSHPower()
+ opts = pxe_utils.dhcp_options_for_instance(task)
+ api = dhcp_factory.DHCPFactory()
+ api.update_dhcp(task, opts)
+ mock_ts.assert_called_with(30)
+ mock_updo.assert_called_once_with(mock.ANY, 'vif-uuid', opts,
+ token=self.context.auth_token)
+
+ @mock.patch.object(neutron, 'LOG', autospec=True)
+ @mock.patch('time.sleep', autospec=True)
+ @mock.patch.object(neutron.NeutronDHCPApi, 'update_port_dhcp_opts',
+ autospec=True)
+ @mock.patch('ironic.common.network.get_node_vif_ids', autospec=True)
+ def test_update_dhcp_unset_sleep_and_ssh(self, mock_gnvi, mock_updo,
+ mock_ts, mock_log):
+ mock_gnvi.return_value = {'ports': {'port-uuid': 'vif-uuid'},
+ 'portgroups': {}}
+ with task_manager.acquire(self.context,
+ self.node.uuid) as task:
+ opts = pxe_utils.dhcp_options_for_instance(task)
+ task.driver.power = ssh.SSHPower()
+ api = dhcp_factory.DHCPFactory()
+ api.update_dhcp(task, opts)
+ self.assertTrue(mock_log.warning.called)
+ self.assertIn('Setting the port delay to 15 for SSH',
+ mock_log.warning.call_args[0][0])
+ mock_ts.assert_called_with(15)
+ mock_updo.assert_called_once_with(mock.ANY, 'vif-uuid', opts,
+ token=self.context.auth_token)
+
+ @mock.patch.object(neutron, 'LOG', autospec=True)
+ @mock.patch('time.sleep', autospec=True)
+ @mock.patch.object(neutron.NeutronDHCPApi, 'update_port_dhcp_opts',
+ autospec=True)
+ @mock.patch('ironic.common.network.get_node_vif_ids', autospec=True)
+ def test_update_dhcp_set_sleep_and_fake(self, mock_gnvi, mock_updo,
+ mock_ts, mock_log):
+ mock_gnvi.return_value = {'ports': {'port-uuid': 'vif-uuid'},
+ 'portgroups': {}}
+ self.config(port_setup_delay=30, group='neutron')
+ with task_manager.acquire(self.context,
+ self.node.uuid) as task:
+ opts = pxe_utils.dhcp_options_for_instance(task)
+ api = dhcp_factory.DHCPFactory()
+ api.update_dhcp(task, opts)
+ mock_log.debug.assert_called_once_with(
+ "Waiting %d seconds for Neutron.", 30)
+ mock_log.warning.assert_not_called()
+ mock_ts.assert_called_with(30)
+ mock_updo.assert_called_once_with(mock.ANY, 'vif-uuid', opts,
+ token=self.context.auth_token)
+
+ @mock.patch.object(neutron, 'LOG', autospec=True)
+ @mock.patch.object(neutron.NeutronDHCPApi, 'update_port_dhcp_opts',
+ autospec=True)
+ @mock.patch('ironic.common.network.get_node_vif_ids', autospec=True)
+ def test_update_dhcp_unset_sleep_and_fake(self, mock_gnvi, mock_updo,
+ mock_log):
+ mock_gnvi.return_value = {'ports': {'port-uuid': 'vif-uuid'},
+ 'portgroups': {}}
+ with task_manager.acquire(self.context,
+ self.node.uuid) as task:
+ opts = pxe_utils.dhcp_options_for_instance(task)
+ api = dhcp_factory.DHCPFactory()
+ api.update_dhcp(task, opts)
+ mock_log.debug.assert_not_called()
+ mock_log.warning.assert_not_called()
+ mock_updo.assert_called_once_with(mock.ANY, 'vif-uuid', opts,
+ token=self.context.auth_token)
+
def test__get_fixed_ip_address(self):
port_id = 'fake-port-id'
expected = "192.168.1.3"