From 3759e36784bffd09f9668137f826be743bfbcd37 Mon Sep 17 00:00:00 2001 From: Joe Topjian Date: Mon, 6 Mar 2017 04:19:30 -0700 Subject: [PATCH] provider/cobbler: Profile and System Fixes (#12452) * vendor: Updating cobblerclient for Cobbler * provider/cobbler: Fix Profile Repos This commit fixes a bug where adding repos would result in an error. This was due to the Cobbler API wanting a space-separated list of repos rather than an array. The Cobbler Service will split the string by space when used internally, but will always present the repos as a string. * provider/cobbler: System Interface Management Test This commit adds a test to verify that the Management parameter of System Interfaces works. --- .../cobbler/resource_cobbler_profile.go | 8 +++- .../cobbler/resource_cobbler_profile_test.go | 37 +++++++++++++++++++ .../cobbler/resource_cobbler_system_test.go | 3 ++ .../jtopjian/cobblerclient/profile.go | 2 +- .../jtopjian/cobblerclient/system.go | 2 +- vendor/vendor.json | 6 +-- 6 files changed, 51 insertions(+), 7 deletions(-) diff --git a/builtin/providers/cobbler/resource_cobbler_profile.go b/builtin/providers/cobbler/resource_cobbler_profile.go index de4cc6b7e..9f2998157 100644 --- a/builtin/providers/cobbler/resource_cobbler_profile.go +++ b/builtin/providers/cobbler/resource_cobbler_profile.go @@ -3,6 +3,7 @@ package cobbler import ( "fmt" "log" + "strings" "github.com/hashicorp/terraform/helper/schema" cobbler "github.com/jtopjian/cobblerclient" @@ -261,7 +262,6 @@ func resourceProfileRead(d *schema.ResourceData, meta interface{}) error { d.Set("proxy", profile.Proxy) d.Set("redhat_management_key", profile.RedHatManagementKey) d.Set("redhat_management_server", profile.RedHatManagementServer) - d.Set("repos", profile.Repos) d.Set("template_files", profile.TemplateFiles) d.Set("template_remote_kickstarts", profile.TemplateRemoteKickstarts) d.Set("virt_auto_boot", profile.VirtAutoBoot) @@ -273,6 +273,10 @@ func resourceProfileRead(d *schema.ResourceData, meta interface{}) error { d.Set("virt_ram", profile.VirtRam) d.Set("virt_type", profile.VirtType) + // Split repos into a list + repos := strings.Split(profile.Repos, " ") + d.Set("repos", repos) + return nil } @@ -351,7 +355,7 @@ func buildProfile(d *schema.ResourceData, meta interface{}) cobbler.Profile { Proxy: d.Get("proxy").(string), RedHatManagementKey: d.Get("redhat_management_key").(string), RedHatManagementServer: d.Get("redhat_management_server").(string), - Repos: repos, + Repos: strings.Join(repos, " "), Server: d.Get("server").(string), TemplateFiles: d.Get("template_files").(string), TemplateRemoteKickstarts: d.Get("template_remote_kickstarts").(int), diff --git a/builtin/providers/cobbler/resource_cobbler_profile_test.go b/builtin/providers/cobbler/resource_cobbler_profile_test.go index 1d72a9fb8..0aa088a0f 100644 --- a/builtin/providers/cobbler/resource_cobbler_profile_test.go +++ b/builtin/providers/cobbler/resource_cobbler_profile_test.go @@ -57,6 +57,26 @@ func TestAccCobblerProfile_change(t *testing.T) { }) } +func TestAccCobblerProfile_withRepo(t *testing.T) { + var distro cobbler.Distro + var profile cobbler.Profile + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccCobblerPreCheck(t) }, + Providers: testAccCobblerProviders, + CheckDestroy: testAccCobblerCheckProfileDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCobblerProfile_withRepo, + Check: resource.ComposeTestCheckFunc( + testAccCobblerCheckDistroExists(t, "cobbler_distro.foo", &distro), + testAccCobblerCheckProfileExists(t, "cobbler_profile.foo", &profile), + ), + }, + }, + }) +} + func testAccCobblerCheckProfileDestroy(s *terraform.State) error { config := testAccCobblerProvider.Meta().(*Config) @@ -147,3 +167,20 @@ var testAccCobblerProfile_change_2 = ` comment = "I am a profile again" distro = "${cobbler_distro.foo.name}" }` + +var testAccCobblerProfile_withRepo = ` + resource "cobbler_distro" "foo" { + name = "foo" + breed = "ubuntu" + os_version = "trusty" + arch = "x86_64" + kernel = "/var/www/cobbler/ks_mirror/Ubuntu-14.04/install/netboot/ubuntu-installer/amd64/linux" + initrd = "/var/www/cobbler/ks_mirror/Ubuntu-14.04/install/netboot/ubuntu-installer/amd64/initrd.gz" + } + + resource "cobbler_profile" "foo" { + name = "foo" + comment = "I am a profile again" + distro = "${cobbler_distro.foo.name}" + repos = ["Ubuntu-14.04-x86_64"] + }` diff --git a/builtin/providers/cobbler/resource_cobbler_system_test.go b/builtin/providers/cobbler/resource_cobbler_system_test.go index df668b59e..2977f4024 100644 --- a/builtin/providers/cobbler/resource_cobbler_system_test.go +++ b/builtin/providers/cobbler/resource_cobbler_system_test.go @@ -100,6 +100,8 @@ func TestAccCobblerSystem_removeInterface(t *testing.T) { testAccCobblerCheckDistroExists(t, "cobbler_distro.foo", &distro), testAccCobblerCheckProfileExists(t, "cobbler_profile.foo", &profile), testAccCobblerCheckSystemExists(t, "cobbler_system.foo", &system), + resource.TestCheckResourceAttr( + "cobbler_system.foo", "interface.586365610.management", "true"), ), }, resource.TestStep{ @@ -345,6 +347,7 @@ var testAccCobblerSystem_removeInterface_1 = ` static = true ip_address = "1.2.3.5" netmask = "255.255.255.0" + management = true } }` diff --git a/vendor/github.com/jtopjian/cobblerclient/profile.go b/vendor/github.com/jtopjian/cobblerclient/profile.go index 5aa971e52..18e42e0de 100644 --- a/vendor/github.com/jtopjian/cobblerclient/profile.go +++ b/vendor/github.com/jtopjian/cobblerclient/profile.go @@ -50,7 +50,7 @@ type Profile struct { Proxy string `mapstructure:"proxy"` RedHatManagementKey string `mapstructure:"redhat_management_key"` RedHatManagementServer string `mapstructure:"redhat_management_server"` - Repos []string `mapstructure:"repos"` + Repos string `mapstructure:"repos"` Server string `mapstructure:"server"` TemplateFiles string `mapstructure:"template_files"` TemplateRemoteKickstarts int `mapstructure:"template_remote_kickstarts"` diff --git a/vendor/github.com/jtopjian/cobblerclient/system.go b/vendor/github.com/jtopjian/cobblerclient/system.go index 1f93d8428..39f6bc2fe 100644 --- a/vendor/github.com/jtopjian/cobblerclient/system.go +++ b/vendor/github.com/jtopjian/cobblerclient/system.go @@ -98,7 +98,7 @@ type Interface struct { IPv6StaticRoutes []string `mapstructure:"ipv6_static_routes" structs:"ipv6_static_routes"` IPv6DefaultGateway string `mapstructure:"ipv6_default_gateway structs:"ipv6_default_gateway"` MACAddress string `mapstructure:"mac_address" structs:"mac_address"` - Management bool `mapstructure:"management" structs:"managment"` + Management bool `mapstructure:"management" structs:"management"` Netmask string `mapstructure:"netmask" structs:"netmask"` Static bool `mapstructure:"static" structs:"static"` StaticRoutes []string `mapstructure:"static_routes" structs:"static_routes"` diff --git a/vendor/vendor.json b/vendor/vendor.json index d3b3f93c5..2eacf031c 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -2160,11 +2160,11 @@ "revisionTime": "2016-06-16T18:50:15Z" }, { - "checksumSHA1": "N4M0qtTBHR2XBxTuPRL9ocdkQns=", + "checksumSHA1": "YhQcOsGx8r2S/jkJ0Qt4cZ5BLCU=", "comment": "v0.3.0-33-g53d1c0a", "path": "github.com/jtopjian/cobblerclient", - "revision": "53d1c0a0b003aabfa7ecfa848d856606cb481196", - "revisionTime": "2016-04-01T00:38:02Z" + "revision": "3b306e0a196ac0dc04751ad27130601a4533cce9", + "revisionTime": "2017-03-05T20:21:00Z" }, { "checksumSHA1": "sKheT5xw89Tbu2Q071FQO27CVmE=",