From 8bf001235786592de4c48892ce6aca8b7c38e0d5 Mon Sep 17 00:00:00 2001 From: Dale Smith Date: Fri, 19 Sep 2025 16:58:06 +1200 Subject: [PATCH] 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 Closes-Bug: #2121213 (cherry picked from commit a950ce711abf5d23b5e95a4db4341dc90f5202e1) --- magnum/api/validation.py | 8 ++++++-- magnum/tests/unit/api/controllers/v1/test_cluster.py | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/magnum/api/validation.py b/magnum/api/validation.py index c17c673cd6..dd87ba90d2 100644 --- a/magnum/api/validation.py +++ b/magnum/api/validation.py @@ -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) diff --git a/magnum/tests/unit/api/controllers/v1/test_cluster.py b/magnum/tests/unit/api/controllers/v1/test_cluster.py index 60f8f6c6ce..5e70ea9a12 100644 --- a/magnum/tests/unit/api/controllers/v1/test_cluster.py +++ b/magnum/tests/unit/api/controllers/v1/test_cluster.py @@ -706,10 +706,10 @@ def test_create_cluster_with_non_existent_cluster_template_name(self): 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)