Skip to content

Commit

Permalink
Fix Issue with UUID template name in KVM
Browse files Browse the repository at this point in the history
When creating a KVM server resource using an UUID template ID as template name, the getTemplate helper could not match this to the ID in ServerDetails.InitialTemplate.

* Add if-statement to check InitialTemplate.ID
* Update glesys_server Tests

Fixes #78
  • Loading branch information
norrland committed Nov 1, 2022
1 parent e436b39 commit 2dd5e52
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions glesys/resource_glesys_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ func getTemplate(original string, srv *glesys.ServerDetails) string {
return original
}
}
if original == srv.InitialTemplate.ID {
return original
}
return srv.Template
}

Expand Down
20 changes: 15 additions & 5 deletions glesys/resource_glesys_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
func Test_getTemplate(t *testing.T) {
srv := &glesys.ServerDetails{}
for _, tt := range []struct {
name string
tfTemplate string
readTemplate string
readTags []string
want string
name string
tfTemplate string
readTemplate string
readTemplateID string
readTags []string
want string
}{
{
name: "KVM_instance",
Expand All @@ -22,6 +23,14 @@ func Test_getTemplate(t *testing.T) {
readTags: []string{"ubuntu", "ubuntu-lts", "ubuntu-20-04"},
want: "ubuntu-20-04",
},
{
name: "KVM_instance_UUID_Template",
tfTemplate: "fc5d38f7-4c9d-4920-a3a0-3252f71fe2c5",
readTemplate: "Ubuntu 20.04 LTS (Focal Fossa)",
readTemplateID: "fc5d38f7-4c9d-4920-a3a0-3252f71fe2c5",
readTags: []string{"ubuntu", "ubuntu-lts", "ubuntu-20-04"},
want: "fc5d38f7-4c9d-4920-a3a0-3252f71fe2c5",
},
{
name: "VMware_instance",
tfTemplate: "Ubuntu 20.04 LTS 64-bit",
Expand All @@ -34,6 +43,7 @@ func Test_getTemplate(t *testing.T) {
srv.Template = tt.readTemplate
srv.InitialTemplate.Name = tt.readTemplate
srv.InitialTemplate.CurrentTags = tt.readTags
srv.InitialTemplate.ID = tt.readTemplateID
if got := getTemplate(tt.tfTemplate, srv); got != tt.want {
t.Errorf("got: %v, want %v", got, tt.want)
}
Expand Down

0 comments on commit 2dd5e52

Please sign in to comment.