add default conductor group capability

When creating nodes, previously there was no way to set a
default conductor group to create nodes with, thus forcing
a two step process, a dedicated conductor without a conductor
group to serve reqeusts for it.

With this change, an operator can set specific conductor_group
settings by API, allowing increased delineation with reduced
risk of misconfiguration or mis-step.

Story: 2010267
Task: 46183
Change-Id: I21d58750504b2eecf3368d2e03eaca050065c3d7
This commit is contained in:
Julia Kreger 2022-09-02 15:43:08 -07:00
parent a346862e39
commit 9953b5a2e8
4 changed files with 34 additions and 1 deletions

View File

@ -2538,7 +2538,7 @@ class NodesController(rest.RestController):
# NOTE(jroll) this is special-cased to "" and not None,
# because it is used in hash ring calculations
if not node.get('conductor_group'):
node['conductor_group'] = ''
node['conductor_group'] = CONF.default_conductor_group
if node.get('name') is not None:
error_msg = _("Cannot create node with invalid name '%(name)s'")

View File

@ -81,6 +81,11 @@ api_opts = [
mutable=True,
help=_('Resource class to use for new nodes when no resource '
'class is provided in the creation request.')),
cfg.StrOpt('default_conductor_group',
mutable=True,
default="",
help=_('The conductor_group to use for new nodes when no '
'conductor_group was defined in the creation request.')),
]
driver_opts = [

View File

@ -4495,6 +4495,27 @@ class TestPost(test_api_base.BaseApiTest):
headers={api_base.Version.string: "1.21"})
self.assertEqual('class2', result['resource_class'])
def test_create_node_with_default_conductor_group(self):
self.config(default_conductor_group='magic')
ndict = test_api_utils.post_get_test_node()
self.post_json('/nodes', ndict)
# newer version is needed to see the resource_class field
result = self.get_json('/nodes/%s' % ndict['uuid'],
headers={api_base.Version.string: "1.46"})
self.assertEqual('magic', result['conductor_group'])
def test_create_node_explicit_default_conductor_group(self):
self.config(default_conductor_group='meow')
ndict = test_api_utils.post_get_test_node(conductor_group='mouse')
self.post_json('/nodes', ndict,
headers={api_base.Version.string: "1.46"})
result = self.get_json('/nodes/%s' % ndict['uuid'],
headers={api_base.Version.string: "1.46"})
self.assertEqual('mouse', result['conductor_group'])
def test_create_node_doesnt_contain_id(self):
# FIXME(comstud): I'd like to make this test not use the
# dbapi, however, no matter what I do when trying to mock

View File

@ -0,0 +1,7 @@
---
features:
- |
Adds the capability to define a ``default_conductor_group`` setting
which allows operators to assign a default conductor group to new nodes
created in Ironic if they do not otherwise have a ``conductor_group``
set upon creation. By default, this setting has no value.