From c6abd511599afcf5d823f092e24b2a4fd2863048 Mon Sep 17 00:00:00 2001 From: Vladyslav Drok Date: Wed, 8 Feb 2017 11:45:35 +0200 Subject: [PATCH] Unbind tenant ports before rebuild Currently, during rebuild, tenant ports are bound to tenant network when we call add_provisioning_network. We need to unbind them first. Closes-Bug: #1657083 Change-Id: I475a089ee646872f7874c3d257c1dc571ea94f4d --- ironic/drivers/modules/agent.py | 3 +++ ironic/drivers/modules/iscsi_deploy.py | 3 +++ ironic/tests/unit/drivers/modules/test_agent.py | 9 +++++++-- ironic/tests/unit/drivers/modules/test_iscsi_deploy.py | 9 ++++++--- .../notes/fix-net-ifaces-rebuild-1cc03df5d37f38dd.yaml | 5 +++++ 5 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/fix-net-ifaces-rebuild-1cc03df5d37f38dd.yaml diff --git a/ironic/drivers/modules/agent.py b/ironic/drivers/modules/agent.py index 26f6fc9a21..1160066971 100644 --- a/ironic/drivers/modules/agent.py +++ b/ironic/drivers/modules/agent.py @@ -425,6 +425,9 @@ class AgentDeploy(AgentDeployMixin, base.DeployInterface): # Adding the node to provisioning network so that the dhcp # options get added for the provisioning port. manager_utils.node_power_action(task, states.POWER_OFF) + # NOTE(vdrok): in case of rebuild, we have tenant network already + # configured, unbind tenant ports if present + task.driver.network.unconfigure_tenant_networks(task) task.driver.network.add_provisioning_network(task) if node.provision_state == states.ACTIVE: task.driver.boot.prepare_instance(task) diff --git a/ironic/drivers/modules/iscsi_deploy.py b/ironic/drivers/modules/iscsi_deploy.py index 7b79d7cbc5..760f6820c8 100644 --- a/ironic/drivers/modules/iscsi_deploy.py +++ b/ironic/drivers/modules/iscsi_deploy.py @@ -497,6 +497,9 @@ class ISCSIDeploy(AgentDeployMixin, base.DeployInterface): # Adding the node to provisioning network so that the dhcp # options get added for the provisioning port. manager_utils.node_power_action(task, states.POWER_OFF) + # NOTE(vdrok): in case of rebuild, we have tenant network + # already configured, unbind tenant ports if present + task.driver.network.unconfigure_tenant_networks(task) task.driver.network.add_provisioning_network(task) deploy_opts = deploy_utils.build_agent_options(node) diff --git a/ironic/tests/unit/drivers/modules/test_agent.py b/ironic/tests/unit/drivers/modules/test_agent.py index 36afdd0031..b011ac9e91 100644 --- a/ironic/tests/unit/drivers/modules/test_agent.py +++ b/ironic/tests/unit/drivers/modules/test_agent.py @@ -286,8 +286,12 @@ class TestAgentDeploy(db_base.DbTestCase): @mock.patch.object(deploy_utils, 'build_instance_info_for_deploy') @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.' 'add_provisioning_network', autospec=True) - def test_prepare(self, add_provisioning_net_mock, build_instance_info_mock, - build_options_mock, pxe_prepare_ramdisk_mock): + @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.' + 'unconfigure_tenant_networks', spec_set=True, autospec=True) + def test_prepare( + self, unconfigure_tenant_net_mock, add_provisioning_net_mock, + build_instance_info_mock, build_options_mock, + pxe_prepare_ramdisk_mock): with task_manager.acquire( self.context, self.node['uuid'], shared=False) as task: task.node.provision_state = states.DEPLOYING @@ -301,6 +305,7 @@ class TestAgentDeploy(db_base.DbTestCase): pxe_prepare_ramdisk_mock.assert_called_once_with( task, {'a': 'b'}) add_provisioning_net_mock.assert_called_once_with(mock.ANY, task) + unconfigure_tenant_net_mock.assert_called_once_with(mock.ANY, task) self.node.refresh() self.assertEqual('bar', self.node.instance_info['foo']) diff --git a/ironic/tests/unit/drivers/modules/test_iscsi_deploy.py b/ironic/tests/unit/drivers/modules/test_iscsi_deploy.py index 75195360b1..a1f6a0e01f 100644 --- a/ironic/tests/unit/drivers/modules/test_iscsi_deploy.py +++ b/ironic/tests/unit/drivers/modules/test_iscsi_deploy.py @@ -594,9 +594,11 @@ class ISCSIDeployTestCase(db_base.DbTestCase): @mock.patch.object(pxe.PXEBoot, 'prepare_ramdisk', autospec=True) @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.' 'add_provisioning_network', spec_set=True, autospec=True) - def test_prepare_node_deploying(self, add_provisioning_net_mock, - mock_prepare_ramdisk, - mock_agent_options): + @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.' + 'unconfigure_tenant_networks', spec_set=True, autospec=True) + def test_prepare_node_deploying( + self, unconfigure_tenant_net_mock, add_provisioning_net_mock, + mock_prepare_ramdisk, mock_agent_options): mock_agent_options.return_value = {'c': 'd'} with task_manager.acquire(self.context, self.node.uuid) as task: task.node.provision_state = states.DEPLOYING @@ -607,6 +609,7 @@ class ISCSIDeployTestCase(db_base.DbTestCase): mock_prepare_ramdisk.assert_called_once_with( task.driver.boot, task, {'c': 'd'}) add_provisioning_net_mock.assert_called_once_with(mock.ANY, task) + unconfigure_tenant_net_mock.assert_called_once_with(mock.ANY, task) @mock.patch.object(manager_utils, 'node_power_action', autospec=True) @mock.patch.object(iscsi_deploy, 'check_image_size', autospec=True) diff --git a/releasenotes/notes/fix-net-ifaces-rebuild-1cc03df5d37f38dd.yaml b/releasenotes/notes/fix-net-ifaces-rebuild-1cc03df5d37f38dd.yaml new file mode 100644 index 0000000000..65ef3dd962 --- /dev/null +++ b/releasenotes/notes/fix-net-ifaces-rebuild-1cc03df5d37f38dd.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixes an issue with node rebuild, when tenant network ports were not + unbound prior to moving the node to provisioning network.