only sets default value for chef license when installing chef and the install command is not set

This commit is contained in:
Aaron Walker 2019-05-21 15:26:07 +02:00
parent dfc5e5cf94
commit 85b8a654b0
4 changed files with 60 additions and 4 deletions

View File

@ -196,8 +196,10 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
errs, fmt.Errorf("server_url must be set"))
}
if p.config.ChefLicense == "" {
p.config.ChefLicense = "accept-silent"
if p.config.SkipInstall == false && p.config.InstallCommand == p.guestOSTypeConfig.installCommand {
if p.config.ChefLicense == "" {
p.config.ChefLicense = "accept-silent"
}
}
if p.config.EncryptedDataBagSecretPath != "" {

View File

@ -164,6 +164,32 @@ func TestProvisionerPrepare_chefLicense(t *testing.T) {
if p.config.ChefLicense != "accept" {
t.Fatalf("unexpected: %#v", p.config.ChefLicense)
}
// Test set skipInstall true
config = testConfig()
config["skip_install"] = true
p = Provisioner{}
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
if p.config.ChefLicense != "" {
t.Fatalf("unexpected: %#v", "empty string")
}
// Test set installCommand true
config = testConfig()
config["install_command"] = "install chef"
p = Provisioner{}
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
if p.config.ChefLicense != "" {
t.Fatalf("unexpected: %#v", "empty string")
}
}
func TestProvisionerPrepare_encryptedDataBagSecretPath(t *testing.T) {

View File

@ -146,8 +146,10 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
p.config.StagingDir = p.guestOSTypeConfig.stagingDir
}
if p.config.ChefLicense == "" {
p.config.ChefLicense = "accept-silent"
if p.config.SkipInstall == false && p.config.InstallCommand == p.guestOSTypeConfig.installCommand {
if p.config.ChefLicense == "" {
p.config.ChefLicense = "accept-silent"
}
}
var errs *packer.MultiError

View File

@ -61,6 +61,32 @@ func TestProvisionerPrepare_chefLicense(t *testing.T) {
if p.config.ChefLicense != "accept" {
t.Fatalf("unexpected: %#v", p.config.ChefLicense)
}
// Test set skipInstall true
config = testConfig()
config["skip_install"] = true
p = Provisioner{}
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
if p.config.ChefLicense != "" {
t.Fatalf("unexpected: %#v", "empty string")
}
// Test set installCommand true
config = testConfig()
config["install_command"] = "install chef"
p = Provisioner{}
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
if p.config.ChefLicense != "" {
t.Fatalf("unexpected: %#v", "empty string")
}
}
func TestProvisionerPrepare_configTemplate(t *testing.T) {