ensure unique ironic node ID with UCS driver

The UCS driver info handling is split off the common
PrefixedDriverInfo implementation for the purpose of
generating unique node IDs in a driver-specific and
clean way.

This change un-deprecates `pm_service_profile` option
support.

Conflicts: tripleo_common/utils/nodes.py

Closes-Bug: #1739024
Change-Id: Ibabe216d3e2b1ea33adc1feaae7095e76cfad19d
(cherry picked from commit ea50e58eb6)
This commit is contained in:
Ilya Etingof 2017-12-18 14:40:17 +01:00
parent 7a136d8fb2
commit 65bb298f9f
3 changed files with 80 additions and 5 deletions

View File

@ -0,0 +1,11 @@
---
deprecations:
- |
Un-deprecated `pm_service_profile` option support at the UCS ironic
driver.
fixes:
- |
Previously, ironic nodes that only differ in `pm_service_profile`
or `ucs_service_profile` would override one another ultimately leaving
just one of them in ironic configuration. This fix un-deprecates
`pm_service_profile` option support at the UCS ironic driver.

View File

@ -197,6 +197,44 @@ class iBootDriverInfoTest(base.TestCase):
self.driver_info.unique_id_from_node(node))
class UcsDriverInfoTest(base.TestCase):
driver_info = nodes.UcsDriverInfo()
def test_convert_key(self):
keys = {
'pm_addr': 'ucs_address',
'pm_user': 'ucs_username',
'pm_password': 'ucs_password',
'pm_service_profile': 'ucs_service_profile'
}
for key, expected in keys.items():
self.assertEqual(expected, self.driver_info.convert_key(key))
self.assertIsNone(self.driver_info.convert_key('unknown'))
def test_unique_id_from_fields(self):
fields = {
'pm_addr': '127.0.0.1',
'pm_user': 'user',
'pm_password': '123456',
"pm_service_profile": 'org-root/org-CPC/ls-CPC-test'
}
self.assertEqual('127.0.0.1:org-root/org-CPC/ls-CPC-test',
self.driver_info.unique_id_from_fields(fields))
def test_unique_id_from_node(self):
node = mock.Mock(
driver_info={
'ucs_address': '127.0.0.1',
'ucs_username': 'user',
'ucs_password': '123456',
"ucs_service_profile": 'org-root/org-CPC/ls-CPC-test'
}
)
self.assertEqual('127.0.0.1:org-root/org-CPC/ls-CPC-test',
self.driver_info.unique_id_from_node(node))
class FindNodeHandlerTest(base.TestCase):
def test_found(self):
test = [('fake', 'fake'),

View File

@ -234,17 +234,43 @@ class iBootDriverInfo(PrefixedDriverInfo):
return result
class UcsDriverInfo(DriverInfo):
def __init__(self):
mapping = {
'pm_addr': 'ucs_address',
'pm_user': 'ucs_username',
'pm_password': 'ucs_password',
'pm_service_profile': 'ucs_service_profile'
}
mandatory_fields = list(mapping)
super(UcsDriverInfo, self).__init__(
'ucs', mapping,
mandatory_fields=mandatory_fields
)
def unique_id_from_fields(self, fields):
try:
return '%s:%s' % (fields['pm_addr'], fields['pm_service_profile'])
except KeyError:
return
def unique_id_from_node(self, node):
try:
return '%s:%s' % (node.driver_info['ucs_address'],
node.driver_info['ucs_service_profile'])
except KeyError:
return
DRIVER_INFO = {
# production drivers
'(ipmi|.*_ipmitool)': PrefixedDriverInfo('ipmi', has_port=True,
default_port=623),
'.*_drac': PrefixedDriverInfo('drac', has_port=True),
'.*_ilo': PrefixedDriverInfo('ilo'),
'.*_ucs': PrefixedDriverInfo(
'ucs',
deprecated_mapping={
'pm_service_profile': 'ucs_service_profile'
}),
'.*_ucs': UcsDriverInfo(),
'.*_irmc': PrefixedDriverInfo(
'irmc', has_port=True,
deprecated_mapping={