Skip to content

Commit

Permalink
fix virt-v2v disk name generation
Browse files Browse the repository at this point in the history
Signed-off-by: Bella Khizgiyaev <bkhizgiy@redhat.com>
  • Loading branch information
bkhizgiy authored and ahadas committed May 1, 2024
1 parent b679a00 commit a79f099
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ all: test forklift-controller

# Run tests
test: generate fmt vet manifests validation-test
go test -coverprofile=cover.out ./pkg/... ./cmd/...
go test -coverprofile=cover.out ./pkg/... ./cmd/... ./virt-v2v/cold/...

# Experimental e2e target
e2e-sanity: e2e-sanity-ovirt e2e-sanity-vsphere
Expand Down Expand Up @@ -114,6 +114,7 @@ e2e-sanity-ova:
forklift-controller: generate fmt vet
go build -o bin/forklift-controller github.com/konveyor/forklift-controller/cmd/forklift-controller


# Build manager binary with compiler optimizations disabled
debug: generate fmt vet
go build -o bin/forklift-controller -gcflags=all="-N -l" github.com/konveyor/forklift-controller/cmd/forklift-controller
Expand Down
8 changes: 7 additions & 1 deletion virt-v2v/cold/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
load(
"@io_bazel_rules_docker//container:container.bzl",
"container_image",
Expand Down Expand Up @@ -478,3 +478,9 @@ rpmtree(
],
visibility = ["//visibility:public"],
)

go_test(
name = "cold_test",
srcs = ["colde_test.go"],
embed = [":cold_lib"],
)
29 changes: 29 additions & 0 deletions virt-v2v/cold/colde_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"testing"
)

func TestGenName(t *testing.T) {
cases := []struct {
diskNum int
expected string
}{
{1, "a"},
{26, "z"},
{27, "aa"},
{28, "ab"},
{52, "az"},
{53, "ba"},
{55, "bc"},
{702, "zz"},
{754, "abz"},
}

for _, c := range cases {
got := genName(c.diskNum)
if got != c.expected {
t.Errorf("genName(%d) = %s; want %s", c.diskNum, got, c.expected)
}
}
}
10 changes: 7 additions & 3 deletions virt-v2v/cold/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,15 @@ func genName(diskNum int) string {
return ""
}

letters := []int32("abcdefghijklmnopqrstuvwxyz")
letters := "abcdefghijklmnopqrstuvwxyz"
index := (diskNum - 1) % len(letters)
cycels := (diskNum - 1) % len(letters)
cycles := (diskNum - 1) / len(letters)

return genName(cycels) + string(letters[index])
if cycles == 0 {
return string(letters[index])
} else {
return genName(cycles) + string(letters[index])
}
}

func LinkDisks(diskKind string, num int) (err error) {
Expand Down

0 comments on commit a79f099

Please sign in to comment.