summaryrefslogtreecommitdiff
path: root/ironic/tests/unit/drivers/test_base.py
diff options
context:
space:
mode:
authorSam Betts <sam@code-smash.net>2016-11-30 18:29:04 +0000
committerVasyl Saienko <vsaienko@mirantis.com>2016-12-23 11:58:02 +0000
commit9088891ce72081684761e5cf54d3b3eabab0ca37 (patch)
tree65a82babad4dadef412730fea4bde28687bbec2f /ironic/tests/unit/drivers/test_base.py
parent12feff85d6826d198a424a1c25efcc3d3c591299 (diff)
downloadironic-9088891ce72081684761e5cf54d3b3eabab0ca37.tar.gz
Add Virtual Network Interface Driver APIs
This patch adds the driver API interfaces for the virtual network interface API in order to abstract the task of assigning logical network interfaces to physical network interfaces. Since the OpenStack Newton release, Ironic provides an interface for pluggable network implementations. Different network implementations may want to handle how logical to physical network interface assignment happens. To do this the new API calls into new functions on the network implementation loaded for the specified node. This is part 1 of 3, and adds four new functions vif_attach, vif_detach, vif_list, port_changed, portgroup_changed, get_current_vif to the base network interface class, which should be overridden by network interface implementations. DHCP provider update_mac_address method was deprecated, network interface port_changed() and portgroup_changed() should be used instead. Co-Authored-By: Vasyl Saienko (vsaienko@mirantis.com) Change-Id: I0b84cfd85557d18254697f2e539c583ea0f8e88c Partial-Bug: #1582188 Closes-Bug: #1158684
Diffstat (limited to 'ironic/tests/unit/drivers/test_base.py')
-rw-r--r--ironic/tests/unit/drivers/test_base.py90
1 files changed, 90 insertions, 0 deletions
diff --git a/ironic/tests/unit/drivers/test_base.py b/ironic/tests/unit/drivers/test_base.py
index cc9d4b0c9..50c462768 100644
--- a/ironic/tests/unit/drivers/test_base.py
+++ b/ironic/tests/unit/drivers/test_base.py
@@ -21,6 +21,7 @@ from ironic.common import exception
from ironic.common import raid
from ironic.drivers import base as driver_base
from ironic.drivers.modules import fake
+from ironic.drivers.modules.network import common as net_common
from ironic.tests import base
@@ -408,3 +409,92 @@ class TestDeployInterface(base.TestCase):
driver='driver')),
'url')
self.assertTrue(mock_log.called)
+
+
+class TestNetwork(driver_base.NetworkInterface):
+
+ def add_provisioning_network(self, task):
+ pass
+
+ def remove_provisioning_network(self, task):
+ pass
+
+ def add_cleaning_network(self, task):
+ pass
+
+ def remove_cleaning_network(self, task):
+ pass
+
+ def configure_tenant_networks(self, task):
+ pass
+
+ def unconfigure_tenant_networks(self, task):
+ pass
+
+
+class NetworkInterfaceTestCase(base.TestCase):
+
+ @mock.patch.object(driver_base.LOG, 'warning', autospec=True)
+ @mock.patch.object(net_common.VIFPortIDMixin, 'vif_list')
+ def test_vif_list(self, mock_vif, mock_warn):
+ mock_task = mock.MagicMock()
+ network = TestNetwork()
+ network.vif_list(mock_task)
+ mock_vif.assert_called_once_with(mock_task)
+ mock_warn.assert_called_once_with(mock.ANY, 'TestNetwork')
+ # Test if the log is only called once even if we recreate a new
+ # NetworkInterface and call it again.
+ # NOTE(sambetts): This must be done inside this test instead of a
+ # separate test because otherwise we end up race conditions between the
+ # test cases regarding the class variables that are set.
+ network = TestNetwork()
+ network.vif_list(mock_task)
+ mock_warn.assert_called_once_with(mock.ANY, 'TestNetwork')
+
+ @mock.patch.object(driver_base.LOG, 'warning', autospec=True)
+ @mock.patch.object(net_common.VIFPortIDMixin, 'vif_attach')
+ def test_vif_attach(self, mock_attach, mock_warn):
+ mock_task = mock.MagicMock()
+ network = TestNetwork()
+ network.vif_attach(mock_task, {'id': 'fake'})
+ mock_attach.assert_called_once_with(mock_task, {'id': 'fake'})
+ self.assertTrue(mock_warn.called)
+
+ @mock.patch.object(driver_base.LOG, 'warning', autospec=True)
+ @mock.patch.object(net_common.VIFPortIDMixin, 'vif_detach')
+ def test_vif_detach(self, mock_detach, mock_warn):
+ mock_task = mock.MagicMock()
+ network = TestNetwork()
+ network.vif_detach(mock_task, 'fake-vif-id')
+ mock_detach.assert_called_once_with(mock_task, 'fake-vif-id')
+ self.assertTrue(mock_warn.called)
+
+ @mock.patch.object(driver_base.LOG, 'warning', autospec=True)
+ @mock.patch.object(net_common.VIFPortIDMixin, 'port_changed')
+ def test_port_changed(self, mock_pc, mock_warn):
+ port = mock.MagicMock()
+ mock_task = mock.MagicMock()
+ network = TestNetwork()
+ network.port_changed(mock_task, port)
+ mock_pc.assert_called_once_with(mock_task, port)
+ self.assertTrue(mock_warn.called)
+
+ @mock.patch.object(driver_base.LOG, 'warning', autospec=True)
+ @mock.patch.object(net_common.VIFPortIDMixin, 'portgroup_changed')
+ def test_portgroup_changed(self, mock_pgc, mock_warn):
+ port = mock.MagicMock()
+ mock_task = mock.MagicMock()
+ network = TestNetwork()
+ network.portgroup_changed(mock_task, port)
+ mock_pgc.assert_called_once_with(mock_task, port)
+ self.assertTrue(mock_warn.called)
+
+ @mock.patch.object(driver_base.LOG, 'warning', autospec=True)
+ @mock.patch.object(net_common.VIFPortIDMixin, 'get_current_vif')
+ def test_get_current_vif(self, mock_gcv, mock_warn):
+ port = mock.MagicMock()
+ mock_task = mock.MagicMock()
+ network = TestNetwork()
+ network.get_current_vif(mock_task, port)
+ mock_gcv.assert_called_once_with(mock_task, port)
+ self.assertTrue(mock_warn.called)