Add a configuration option for the default resource class
If no resource class is provided in a creation request, the value of the new ``default_resource_class`` configuration option is used. While this feature is implemented on the API level, it's not a part of the API contract, so it's not covered by a microversion. It's particularly important, because it allows this change to apply even to requests using an old API version, thus making these versions usable after the mandatory switch to resource classes in nova. Change-Id: I58232d9c92d6ffca49d334e5fb7078bce19f1cb4 Closes-Bug: #1732190
This commit is contained in:
parent
27ce77142b
commit
265993316b
@ -1643,6 +1643,9 @@ class NodesController(rest.RestController):
|
||||
self._check_names_acceptable([node.name], error_msg)
|
||||
node.provision_state = api_utils.initial_node_provision_state()
|
||||
|
||||
if not node.resource_class:
|
||||
node.resource_class = CONF.default_resource_class
|
||||
|
||||
new_node = objects.Node(context, **node.as_dict())
|
||||
notify.emit_start_notification(context, new_node, 'create',
|
||||
chassis_uuid=node.chassis_uuid)
|
||||
|
@ -69,6 +69,9 @@ api_opts = [
|
||||
default=False,
|
||||
help=_('Enable pecan debug mode. WARNING: this is insecure '
|
||||
'and should not be used in a production environment.')),
|
||||
cfg.StrOpt('default_resource_class',
|
||||
help=_('Resource class to use for new nodes when no resource '
|
||||
'class is provided in the creation request.')),
|
||||
]
|
||||
|
||||
driver_opts = [
|
||||
|
@ -2267,6 +2267,37 @@ class TestPost(test_api_base.BaseApiTest):
|
||||
self.assertEqual(ndict['uuid'], result['uuid'])
|
||||
self.assertEqual(states.ENROLL, result['provision_state'])
|
||||
|
||||
def test_create_node_no_default_resource_class(self):
|
||||
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.21"})
|
||||
self.assertIsNone(result['resource_class'])
|
||||
|
||||
def test_create_node_with_default_resource_class(self):
|
||||
self.config(default_resource_class='class1')
|
||||
|
||||
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.21"})
|
||||
self.assertEqual('class1', result['resource_class'])
|
||||
|
||||
def test_create_node_explicit_resource_class(self):
|
||||
self.config(default_resource_class='class1')
|
||||
|
||||
ndict = test_api_utils.post_get_test_node(resource_class='class2')
|
||||
self.post_json('/nodes', ndict,
|
||||
headers={api_base.Version.string: "1.21"})
|
||||
|
||||
result = self.get_json('/nodes/%s' % ndict['uuid'],
|
||||
headers={api_base.Version.string: "1.21"})
|
||||
self.assertEqual('class2', result['resource_class'])
|
||||
|
||||
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
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Adds new configuration option ``[DEFAULT]default_resource_class`` that
|
||||
specifies the resource class to use for new nodes when no resource class
|
||||
is provided in the node creation request.
|
Loading…
Reference in New Issue
Block a user