Cluster Create: template name now permitted again

This validation decorator used a driver convenience function
to find the cluster template that required a uuid.
With this change, we use the same code as others in the
class and no longer have to modify get_driver_for_cluster
to be more permissive.

Change-Id: I9e7a462b3d78bb5f520c3edd70dc452f6812f924
Signed-off-by: Dale Smith <dale@catalystcloud.nz>
Closes-Bug: #2121213
(cherry picked from commit a950ce711a)
This commit is contained in:
Dale Smith
2025-09-19 16:58:06 +12:00
parent aa954f9adb
commit 8bf0012357
2 changed files with 9 additions and 5 deletions

View File

@@ -94,8 +94,12 @@ def enforce_cluster_master_size_supported():
@decorator.decorator
def wrapper(func, *args, **kwargs):
cluster = args[1]
cluster_driver = driver.Driver.get_driver_for_cluster(
pecan.request.context, cluster)
cluster_template = objects.ClusterTemplate.get(
pecan.request.context, cluster.cluster_template_id)
cluster_type = (cluster_template.server_type,
cluster_template.cluster_distro,
cluster_template.coe)
cluster_driver = driver.Driver.get_driver(*cluster_type)
# Call into the driver to validate initial master size
cluster_driver.validate_master_size(cluster.master_count)
return func(*args, **kwargs)

View File

@@ -706,10 +706,10 @@ class TestPost(api_base.FunctionalTest):
self.assertEqual(400, response.status_int)
self.assertTrue(response.json['errors'])
def test_create_cluster_with_cluster_template_name(self):
def test_create_cluster_with_cluster_template_name_as_id(self):
modelname = self.cluster_template.name
bdict = apiutils.cluster_post_data(name=modelname)
response = self.post_json('/clusters', bdict, expect_errors=True)
bdict = apiutils.cluster_post_data(cluster_template_id=modelname)
response = self.post_json('/clusters', bdict)
self.assertEqual('application/json', response.content_type)
self.assertEqual(202, response.status_int)