Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport: fix virt-v2v disk name generation #876

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,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
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 = ["cold_test.go"],
embed = [":cold_lib"],
)
29 changes: 29 additions & 0 deletions virt-v2v/cold/cold_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 @@ -142,11 +142,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
Loading