From fa5eb8a11992bf0f11642c748ba43c1bd6c8249c Mon Sep 17 00:00:00 2001 From: Mark Bolton Date: Fri, 19 Jul 2024 09:08:04 -0700 Subject: [PATCH 1/2] lxd: Update logic for project config patch Signed-off-by: Mark Bolton --- lxd/api_project.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lxd/api_project.go b/lxd/api_project.go index 5e75f1ca5d41..693ec8954844 100644 --- a/lxd/api_project.go +++ b/lxd/api_project.go @@ -599,14 +599,14 @@ func projectPatch(d *Daemon, r *http.Request) response.Response { req.Description = project.Description } - config, err := reqRaw.GetMap("config") - if err != nil { - req.Config = project.Config - } else { - for k, v := range project.Config { - _, ok := config[k] - if !ok { - config[k] = v + // Perform config patch + req.Config = util.CopyConfig(project.Config) + patches, err := reqRaw.GetMap("config") + if err == nil { + for k, v := range patches { + strVal, ok := v.(string) + if ok { + req.Config[k] = strVal } } } From b44b461d0be0c6c53b1beecad728fad9c233d729 Mon Sep 17 00:00:00 2001 From: Mark Bolton Date: Fri, 19 Jul 2024 12:48:14 -0700 Subject: [PATCH 2/2] test/suites: Add testing for project PATCH Signed-off-by: Mark Bolton --- test/suites/projects.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/suites/projects.sh b/test/suites/projects.sh index a1269b97c2ba..5af0bc750ac7 100644 --- a/test/suites/projects.sh +++ b/test/suites/projects.sh @@ -20,6 +20,10 @@ test_projects_crud() { lxc project show foo | grep -q 'features.images: "true"' lxc project get foo "features.profiles" | grep -q 'true' + # Set a limit + lxc project set foo limits.containers 10 + lxc project show foo | grep -q 'limits.containers: "10"' + # Trying to create a project with the same name fails ! lxc project create foo || false @@ -37,6 +41,13 @@ test_projects_crud() { lxc project show bar| sed 's/^description:.*/description: "Bar project"/' | lxc project edit bar lxc project show bar | grep -q "description: Bar project" + # Edit the project config via PATCH. Existing key/value pairs should remain or be updated. + lxc query -X PATCH -d '{\"config\" : {\"limits.memory\":\"5GiB\",\"features.images\":\"false\"}}' /1.0/projects/bar + lxc project show bar | grep -q 'limits.memory: 5GiB' + lxc project show bar | grep -q 'features.images: "false"' + lxc project show bar | grep -q 'features.profiles: "true"' + lxc project show bar | grep -q 'limits.containers: "10"' + # Create a second project lxc project create foo