Correct update_dhcp_opts methods

Due to recent changes in the neutron dhcp driver, an additional
argument was added to the update_dhcp_opts method.  The additional
argument was not added to the base.py example and the none driver.

As a result of this, the case of using Ironic with the none driver
set was broken.

In the process of adding a new test to detect such issues, additional
issues were detected resulting in the parameters for
update_dhcp_opts, update_dhcp_port_opts and update_port_address
being updated in the base class and the none driver.

Change-Id: Ia0ee0c2567309a230c2f1c044d50d9156afbf6a1
Closes-Bug: 1434852
This commit is contained in:
Julia Kreger
2015-03-25 10:32:27 -04:00
parent 565338fc5b
commit 29d6375a72
3 changed files with 50 additions and 6 deletions
+11 -3
View File
@@ -27,7 +27,7 @@ class BaseDHCP(object):
"""Base class for DHCP provider APIs."""
@abc.abstractmethod
def update_port_dhcp_opts(self, port_id, dhcp_options):
def update_port_dhcp_opts(self, port_id, dhcp_options, token=None):
"""Update one or more DHCP options on the specified port.
:param port_id: designate which port these attributes
@@ -42,21 +42,24 @@ class BaseDHCP(object):
'opt_value': '123.123.123.456'},
{'opt_name': 'tftp-server',
'opt_value': '123.123.123.123'}]
:param token: An optional authenticaiton token.
:raises: FailedToUpdateDHCPOptOnPort
"""
@abc.abstractmethod
def update_port_address(self, port_id, address):
def update_port_address(self, port_id, address, token=None):
"""Update a port's MAC address.
:param port_id: port id.
:param address: new MAC address.
:param token: An optional authenticaiton token.
:raises: FailedToUpdateMacOnPort
"""
@abc.abstractmethod
def update_dhcp_opts(self, task, options):
def update_dhcp_opts(self, task, options, vifs=None):
"""Send or update the DHCP BOOT options for this node.
:param task: A TaskManager instance.
@@ -70,6 +73,11 @@ class BaseDHCP(object):
'opt_value': '123.123.123.456'},
{'opt_name': 'tftp-server',
'opt_value': '123.123.123.123'}]
:param vifs: a dict of Neutron port dicts to update DHCP options on.
The keys should be Ironic port UUIDs, and the values should be
Neutron port UUIDs
If the value is None, will get the list of ports from the Ironic
port objects.
:raises: FailedToUpdateDHCPOptOnPort
"""
+4 -3
View File
@@ -18,13 +18,14 @@ from ironic.dhcp import base
class NoneDHCPApi(base.BaseDHCP):
"""No-op DHCP API."""
def update_port_dhcp_opts(self, port_id, dhcp_options):
def update_port_dhcp_opts(self, port_id, dhcp_options, token=None):
pass
def update_dhcp_opts(self, task, options):
def update_dhcp_opts(self, task, options, vifs=None):
pass
def update_port_address(self, port_id, address):
def update_port_address(self, port_id, address, token=None):
pass
def get_ip_addresses(self, task):
+35
View File
@@ -13,10 +13,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import inspect
import mock
from ironic.common import dhcp_factory
from ironic.common import exception
from ironic.dhcp import base as base_class
from ironic.dhcp import neutron
from ironic.dhcp import none
from ironic.tests import base
@@ -68,3 +71,35 @@ class TestDHCPFactory(base.TestCase):
group='dhcp')
self.assertRaises(exception.DHCPNotFound, dhcp_factory.DHCPFactory)
class CompareBasetoModules(base.TestCase):
def test_drivers_match_dhcp_base(self):
def _get_public_apis(inst):
methods = {}
for (name, value) in inspect.getmembers(inst, inspect.ismethod):
if name.startswith("_"):
continue
methods[name] = value
return methods
def _compare_classes(baseclass, driverclass):
basemethods = _get_public_apis(baseclass)
implmethods = _get_public_apis(driverclass)
for name in basemethods:
baseargs = inspect.getargspec(basemethods[name])
implargs = inspect.getargspec(implmethods[name])
self.assertEqual(
baseargs,
implargs,
"%s args of %s don't match base %s" % (
name,
driverclass,
baseclass)
)
_compare_classes(base_class.BaseDHCP, none.NoneDHCPApi)
_compare_classes(base_class.BaseDHCP, neutron.NeutronDHCPApi)