Skip to content

Commit

Permalink
latest isn't an actual tag, so remove it: #161
Browse files Browse the repository at this point in the history
  • Loading branch information
NorseGaud committed Aug 28, 2023
1 parent 838b1c1 commit d39014e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
13 changes: 7 additions & 6 deletions builder/anka/step_clone_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multist
onError := func(err error) multistep.StepAction {
return ankaUtil.StepError(ui, state, err)
}
sourceVMTag := "latest"

doPull := config.AlwaysFetch

if config.SourceVMTag != "" {
sourceVMTag = config.SourceVMTag
sourceVMTag := fmt.Sprintf("%s tag", config.SourceVMTag)
if config.SourceVMTag == "" {
sourceVMTag = "latest tag"
}

s.client = state.Get("client").(client.Client)
Expand Down Expand Up @@ -73,7 +74,7 @@ func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multist
}

if doPull {
ui.Say(fmt.Sprintf("Pulling source VM %s with tag %s from Anka Registry", config.SourceVMName, sourceVMTag))
ui.Say(fmt.Sprintf("Pulling source VM %s with %s from Anka Registry", config.SourceVMName, sourceVMTag))

registryParams := client.RegistryParams{
Remote: config.Remote,
Expand All @@ -86,14 +87,14 @@ func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multist

registryPullParams := client.RegistryPullParams{
VMID: config.SourceVMName,
Tag: sourceVMTag,
Tag: config.SourceVMTag,
Local: false,
Shrink: false,
}

err := s.client.RegistryPull(registryParams, registryPullParams)
if err != nil {
return onError(fmt.Errorf("failed to pull vm %v with tag %v from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName, sourceVMTag))
return onError(fmt.Errorf("failed to pull vm %s with %s from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName, sourceVMTag))
}
}

Expand Down
20 changes: 10 additions & 10 deletions builder/anka/step_clone_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestCloneVMRun(t *testing.T) {
PackerBuilderType: "veertu-anka-vm-clone",
},
}
sourceVMTag := "latest"
sourceVMTag := ""
registryParams := client.RegistryParams{}
registryPullParams := client.RegistryPullParams{
VMID: config.SourceVMName,
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestCloneVMRun(t *testing.T) {
PackerBuilderType: "veertu-anka-vm-clone",
},
}
sourceVMTag := "latest"
sourceVMTag := ""
registryParams := client.RegistryParams{}
registryPullParams := client.RegistryPullParams{
VMID: config.SourceVMName,
Expand All @@ -211,10 +211,10 @@ func TestCloneVMRun(t *testing.T) {
ankaClient.EXPECT().Exists(config.SourceVMName).Return(false, nil).Times(1),
ankaClient.EXPECT().
RegistryPull(registryParams, registryPullParams).
Return(fmt.Errorf("failed to pull vm %v with tag %v from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName, sourceVMTag)).
Return(fmt.Errorf("failed to pull vm %v with latest tag from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName)).
Times(1),
ankaUtil.EXPECT().
StepError(ui, state, fmt.Errorf("failed to pull vm %v with tag %v from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName, sourceVMTag)).
StepError(ui, state, fmt.Errorf("failed to pull vm %v with latest tag from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName)).
Return(multistep.ActionHalt).
Times(1),
)
Expand All @@ -233,7 +233,7 @@ func TestCloneVMRun(t *testing.T) {
PackerBuilderType: "veertu-anka-vm-clone",
},
}
sourceVMTag := "latest"
sourceVMTag := ""
registryParams := client.RegistryParams{}
registryPullParams := client.RegistryPullParams{
VMID: config.SourceVMName,
Expand All @@ -255,12 +255,12 @@ func TestCloneVMRun(t *testing.T) {
)

mockui := packer.MockUi{}
mockui.Say(fmt.Sprintf("Pulling source VM %s with tag %s from Anka Registry", config.SourceVMName, sourceVMTag))
mockui.Say(fmt.Sprintf("Pulling source VM %s with latest tag from Anka Registry", config.SourceVMName))
mockui.Say(fmt.Sprintf("Cloning source VM %s into a new virtual machine: %s", sourceShowResponse.Name, step.vmName))

stepAction := step.Run(ctx, state)

assert.Equal(t, mockui.SayMessages[0].Message, "Pulling source VM source_foo with tag latest from Anka Registry")
assert.Equal(t, mockui.SayMessages[0].Message, "Pulling source VM source_foo with latest tag from Anka Registry")
assert.Equal(t, mockui.SayMessages[1].Message, "Cloning source VM source_foo into a new virtual machine: foo")
assert.Equal(t, multistep.ActionContinue, stepAction)
})
Expand All @@ -274,7 +274,7 @@ func TestCloneVMRun(t *testing.T) {
PackerBuilderType: "veertu-anka-vm-clone",
},
}
sourceVMTag := "latest"
sourceVMTag := ""
registryParams := client.RegistryParams{}
registryPullParams := client.RegistryPullParams{
VMID: config.SourceVMName,
Expand All @@ -291,10 +291,10 @@ func TestCloneVMRun(t *testing.T) {
gomock.InOrder(
ankaClient.EXPECT().
RegistryPull(registryParams, registryPullParams).
Return(fmt.Errorf("failed to pull vm %v with tag %v from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName, sourceVMTag)).
Return(fmt.Errorf("failed to pull vm %v with latest from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName)).
Times(1),
ankaUtil.EXPECT().
StepError(ui, state, fmt.Errorf("failed to pull vm %v with tag %v from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName, sourceVMTag)).
StepError(ui, state, fmt.Errorf("failed to pull vm %v with latest tag from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName)).
Return(multistep.ActionHalt).
Times(1),
)
Expand Down

0 comments on commit d39014e

Please sign in to comment.