From 9f9ede951b57f7ff4de3117c2951a254c2942c97 Mon Sep 17 00:00:00 2001 From: Inessa Vasilevskaya Date: Mon, 20 Jan 2025 19:09:45 +0100 Subject: [PATCH] Fix tests --- builder/powervs/builder.hcl2spec.go | 2 +- builder/powervs/common/run_config.go | 14 +++++++------- builder/powervs/step_create_instance.go | 6 +++--- builder/powervs/step_create_network.go | 9 ++++----- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/builder/powervs/builder.hcl2spec.go b/builder/powervs/builder.hcl2spec.go index 9401886..4f5fb93 100644 --- a/builder/powervs/builder.hcl2spec.go +++ b/builder/powervs/builder.hcl2spec.go @@ -28,7 +28,7 @@ type FlatConfig struct { InstanceName *string `mapstructure:"instance_name" required:"true" cty:"instance_name" hcl:"instance_name"` KeyPairName *string `mapstructure:"key_pair_name" required:"true" cty:"key_pair_name" hcl:"key_pair_name"` SubnetIDs []string `mapstructure:"subnet_ids" required:"false" cty:"subnet_ids" hcl:"subnet_ids"` - UserData *string `mapstructure:"user_data" required:"false" cty:"user_data" hcl:"user_data"` + UserData *string `mapstructure:"user_data" required:"false" cty:"user_data" hcl:"user_data"` DHCPNetwork *bool `mapstructure:"dhcp_network" required:"false" cty:"dhcp_network" hcl:"dhcp_network"` Source *common.FlatSource `mapstructure:"source" required:"true" cty:"source" hcl:"source"` Capture *common.FlatCapture `mapstructure:"capture" required:"true" cty:"capture" hcl:"capture"` diff --git a/builder/powervs/common/run_config.go b/builder/powervs/common/run_config.go index b6883de..a268077 100644 --- a/builder/powervs/common/run_config.go +++ b/builder/powervs/common/run_config.go @@ -37,13 +37,13 @@ type CaptureCOS struct { } type RunConfig struct { - InstanceName string `mapstructure:"instance_name" required:"true"` - KeyPairName string `mapstructure:"key_pair_name" required:"true"` - SubnetIDs []string `mapstructure:"subnet_ids" required:"false"` - UserData string `mapstructure:"user_data" required:"false"` - DHCPNetwork bool `mapstructure:"dhcp_network" required:"false"` - Source Source `mapstructure:"source" required:"true"` - Capture Capture `mapstructure:"capture" required:"true"` + InstanceName string `mapstructure:"instance_name" required:"true"` + KeyPairName string `mapstructure:"key_pair_name" required:"true"` + SubnetIDs []string `mapstructure:"subnet_ids" required:"false"` + UserData string `mapstructure:"user_data" required:"false"` + DHCPNetwork bool `mapstructure:"dhcp_network" required:"false"` + Source Source `mapstructure:"source" required:"true"` + Capture Capture `mapstructure:"capture" required:"true"` // Communicator settings Comm communicator.Config `mapstructure:",squash"` diff --git a/builder/powervs/step_create_instance.go b/builder/powervs/step_create_instance.go index aec208f..3aeef7f 100644 --- a/builder/powervs/step_create_instance.go +++ b/builder/powervs/step_create_instance.go @@ -1,8 +1,8 @@ package powervs import ( - b64 "encoding/base64" "context" + b64 "encoding/base64" "fmt" "time" @@ -37,12 +37,12 @@ func (s *StepCreateInstance) Run(_ context.Context, state multistep.StateBag) mu // Several subnets have been specified -> pass them all for vm creation networks = []*models.PVMInstanceAddNetwork{} - for _, subnet := range state.Get("networks").([]string){ + for _, subnet := range state.Get("networks").([]string) { subnetAdd := &models.PVMInstanceAddNetwork{ NetworkID: &subnet, } networks = append(networks, subnetAdd) - } + } } else { networks = append(networks, &models.PVMInstanceAddNetwork{NetworkID: net.NetworkID}) } diff --git a/builder/powervs/step_create_network.go b/builder/powervs/step_create_network.go index e6578b1..8c4ca84 100644 --- a/builder/powervs/step_create_network.go +++ b/builder/powervs/step_create_network.go @@ -20,12 +20,11 @@ const ( ) type StepCreateNetwork struct { - SubnetIDs []string - DHCPNetwork bool - doCleanup bool + SubnetIDs []string + DHCPNetwork bool + doCleanup bool } - func (s *StepCreateNetwork) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { ui := state.Get("ui").(packersdk.Ui) @@ -50,7 +49,7 @@ func (s *StepCreateNetwork) Run(_ context.Context, state multistep.StateBag) mul // do not delete user specified subnets, hence skipping the cleanup s.doCleanup = false return multistep.ActionContinue - } + } // If CreateDHCPNetwork is set, Create DHCP network. if s.DHCPNetwork {