Skip to content

Commit

Permalink
[MTV-595] [2.6.5] Add customize disk image step to virt-v2v pod (#995)
Browse files Browse the repository at this point in the history
Backport of 
#985 - sen mac <=> ip mappings
for linux
#983 - customize script for
linux
#997 - refactor bash script
#998 - run customize script on
any linux

Ref: https://issues.redhat.com/browse/MTV-595

Issue:
When migrating a simple RHEL8 VM from VMware 7 to OCPv 4.13 the name of
the network interfaces changes and the static IP configuration for the
VM no longer works

---------

Signed-off-by: yaacov <[email protected]>
  • Loading branch information
yaacov authored Aug 28, 2024
1 parent 6974365 commit b580f1b
Show file tree
Hide file tree
Showing 15 changed files with 811 additions and 146 deletions.
1 change: 1 addition & 0 deletions pkg/controller/plan/adapter/vsphere/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ go_test(
"//pkg/controller/plan/util",
"//pkg/controller/provider/model/vsphere",
"//pkg/controller/provider/web",
"//pkg/controller/provider/web/base",
"//pkg/controller/provider/web/vsphere",
"//pkg/lib/logging",
"//vendor/github.com/onsi/ginkgo/v2:ginkgo",
Expand Down
14 changes: 9 additions & 5 deletions pkg/controller/plan/adapter/vsphere/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,14 @@ func (r *Builder) PodEnvironment(vmRef ref.Ref, sourceSecret *core.Secret) (env
}

func (r *Builder) mapMacStaticIps(vm *model.VM) (ipMap string, err error) {
if !isWindows(vm) {
return "", nil
}
// on windows machines we check if the interface origin is manual
// on linux we collect all networks.
isWindowsFlag := isWindows(vm)

configurations := []string{}
gatewaySet := false
for _, guestNetwork := range vm.GuestNetworks {
if guestNetwork.Origin == string(types.NetIpConfigInfoIpAddressOriginManual) {
if !isWindowsFlag || guestNetwork.Origin == string(types.NetIpConfigInfoIpAddressOriginManual) {
gateway := ""
if !gatewaySet {
isIpv4 := net.IP.To4(net.ParseIP(guestNetwork.IP)) != nil
Expand All @@ -269,7 +270,10 @@ func (r *Builder) mapMacStaticIps(vm *model.VM) (ipMap string, err error) {
}
}
dnsString := strings.Join(guestNetwork.DNS, ",")
configurations = append(configurations, fmt.Sprintf("%s:ip:%s,%s,%d,%s", guestNetwork.MAC, guestNetwork.IP, gateway, guestNetwork.PrefixLength, dnsString))
configurationString := fmt.Sprintf("%s:ip:%s,%s,%d,%s", guestNetwork.MAC, guestNetwork.IP, gateway, guestNetwork.PrefixLength, dnsString)

// if DNS is "", we get configurationString with trailing comma, use TrimSuffix to remove it.
configurations = append(configurations, strings.TrimSuffix(configurationString, ","))
}
}
return strings.Join(configurations, "_"), nil
Expand Down
18 changes: 16 additions & 2 deletions pkg/controller/plan/adapter/vsphere/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ var _ = Describe("vSphere builder", func() {
},
}, "00:50:56:83:25:47:ip:172.29.3.193,172.29.3.1,16,8.8.8.8_00:50:56:83:25:47:ip:fe80::5da:b7a5:e0a2:a097,,64,fec0:0:0:ffff::1,fec0:0:0:ffff::2,fec0:0:0:ffff::3"),
Entry("non-static ip", &model.VM{GuestID: "windows9Guest", GuestNetworks: []vsphere.GuestNetwork{{MAC: "00:50:56:83:25:47", IP: "172.29.3.193", Origin: string(types.NetIpConfigInfoIpAddressOriginDhcp)}}}, ""),
Entry("non windows vm", &model.VM{GuestID: "other", GuestNetworks: []vsphere.GuestNetwork{{MAC: "00:50:56:83:25:47", IP: "172.29.3.193", Origin: ManualOrigin}}}, ""),
Entry("no OS vm", &model.VM{GuestNetworks: []vsphere.GuestNetwork{{MAC: "00:50:56:83:25:47", IP: "172.29.3.193", Origin: ManualOrigin}}}, ""),
Entry("non windows vm", &model.VM{GuestID: "other", GuestNetworks: []vsphere.GuestNetwork{{MAC: "00:50:56:83:25:47", IP: "172.29.3.193", Origin: ManualOrigin}}}, "00:50:56:83:25:47:ip:172.29.3.193,,0"),
Entry("no OS vm", &model.VM{GuestNetworks: []vsphere.GuestNetwork{{MAC: "00:50:56:83:25:47", IP: "172.29.3.193", Origin: ManualOrigin}}}, "00:50:56:83:25:47:ip:172.29.3.193,,0"),
Entry("multiple nics static ips", &model.VM{
GuestID: "windows9Guest",
GuestNetworks: []vsphere.GuestNetwork{
Expand Down Expand Up @@ -116,6 +116,20 @@ var _ = Describe("vSphere builder", func() {
},
},
}, "00:50:56:83:25:47:ip:172.29.3.193,172.29.3.1,16,8.8.8.8_00:50:56:83:25:47:ip:fe80::5da:b7a5:e0a2:a097,,64,fec0:0:0:ffff::1,fec0:0:0:ffff::2,fec0:0:0:ffff::3_00:50:56:83:25:48:ip:172.29.3.192,,24,4.4.4.4_00:50:56:83:25:48:ip:fe80::5da:b7a5:e0a2:a090,,32,fec0:0:0:ffff::4,fec0:0:0:ffff::5,fec0:0:0:ffff::6"),
Entry("single static ip without DNS", &model.VM{
GuestID: "windows9Guest",
GuestNetworks: []vsphere.GuestNetwork{
{
MAC: "00:50:56:83:25:47",
IP: "172.29.3.193",
Origin: ManualOrigin,
PrefixLength: 16,
}},
GuestIpStacks: []vsphere.GuestIpStack{
{
Gateway: "172.29.3.1",
}},
}, "00:50:56:83:25:47:ip:172.29.3.193,172.29.3.1,16"),
)
})

Expand Down
3 changes: 0 additions & 3 deletions pkg/controller/plan/adapter/vsphere/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ func (r *Validator) StaticIPs(vmRef ref.Ref) (ok bool, err error) {
err = liberr.Wrap(err, "vm", vmRef)
return
}
if !isWindows(&vm.VM) {
return true, nil
}

for _, nic := range vm.NICs {
found := false
Expand Down
9 changes: 7 additions & 2 deletions pkg/controller/plan/adapter/vsphere/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/ref"
"github.com/konveyor/forklift-controller/pkg/controller/provider/model/vsphere"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web/base"
model "github.com/konveyor/forklift-controller/pkg/controller/provider/web/vsphere"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -36,6 +37,9 @@ func (m *mockInventory) Find(resource interface{}, ref ref.Ref) error {
if ref.Name == "not_windows_guest" {
res.VM.GuestID = "rhel8_64Guest"
}
if ref.Name == "missing_from_invetory" {
return base.NotFoundError{}
}
}
return nil
}
Expand Down Expand Up @@ -88,7 +92,6 @@ var _ = Describe("vsphere validation tests", func() {
}
ok, err := validator.StaticIPs(ref.Ref{Name: vmName})
if shouldError {
Expect(err).NotTo(HaveOccurred())
Expect(ok).To(BeFalse())
} else {
Expect(err).NotTo(HaveOccurred())
Expand All @@ -101,7 +104,9 @@ var _ = Describe("vsphere validation tests", func() {
Entry("when the vm doesn't have static ips, and the plan set without static ip", "test", false, false),
Entry("when the vm have static ips, and the plan set with static ip", "full_guest_network", true, false),
Entry("when the vm have static ips, and the plan set without static ip", "test", false, false),
Entry("when the vm doesn't have static ips, and the plan set without static ip, vm is non-windows", "not_windows_guest", true, false),
Entry("when the vm doesn't have static ips, and the plan set without static ip, vm is non-windows", "not_windows_guest", false, false),
Entry("when the vm doesn't have static ips, and the plan set with static ip, vm is non-windows", "not_windows_guest", true, true),
Entry("when the vm doesn't exist", "missing_from_invetory", true, true),
)
})
})
Expand Down
68 changes: 38 additions & 30 deletions virt-v2v/cold/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ go_library(
name = "cold_lib",
srcs = [
"customize-image.go",
"customize-rhel.go",
"embed-tool.go",
"entrypoint.go",
"xml-reader.go",
Expand All @@ -102,6 +103,10 @@ go_library(
"scripts/windows/9999-restore_config.ps1",
"scripts/windows/9999-restore_config_init.bat",
"scripts/windows/firstboot.bat",
"scripts/rhel/firstboot/README.md",
"scripts/rhel/run/README.md",
"scripts/rhel/run/network_config_util.sh",
"scripts/rhel/run/network_config_util_test",
],
importpath = "github.com/konveyor/forklift-controller/virt-v2v/cold",
visibility = ["//visibility:private"],
Expand Down Expand Up @@ -134,7 +139,10 @@ container_image(

go_test(
name = "cold_test",
srcs = ["cold_test.go"],
srcs = [
"cold_test.go",
"customize-rhel_test.go",
],
data = glob(["testdata/**"]),
embed = [":cold_lib"],
)
Expand All @@ -151,7 +159,7 @@ rpmtree(
"@bash-0__5.1.8-9.el9.x86_64//rpm",
"@bzip2-0__1.0.8-8.el9.x86_64//rpm",
"@bzip2-libs-0__1.0.8-8.el9.x86_64//rpm",
"@ca-certificates-0__2024.2.69_v8.0.303-91.3.el9.x86_64//rpm",
"@ca-certificates-0__2024.2.69_v8.0.303-91.4.el9.x86_64//rpm",
"@capstone-0__4.0.2-10.el9.x86_64//rpm",
"@centos-gpg-keys-0__9.0-11.el9.x86_64//rpm",
"@centos-stream-release-0__9.0-11.el9.x86_64//rpm",
Expand All @@ -161,23 +169,23 @@ rpmtree(
"@cpio-0__2.13-16.el9.x86_64//rpm",
"@cracklib-0__2.9.6-27.el9.x86_64//rpm",
"@cracklib-dicts-0__2.9.6-27.el9.x86_64//rpm",
"@crypto-policies-0__20240815-1.gite217f03.el9.x86_64//rpm",
"@crypto-policies-0__20240822-1.gitbaf3e06.el9.x86_64//rpm",
"@cryptsetup-libs-0__2.7.2-1.el9.x86_64//rpm",
"@curl-minimal-0__7.76.1-30.el9.x86_64//rpm",
"@curl-minimal-0__7.76.1-31.el9.x86_64//rpm",
"@cyrus-sasl-gssapi-0__2.1.27-21.el9.x86_64//rpm",
"@cyrus-sasl-lib-0__2.1.27-21.el9.x86_64//rpm",
"@daxctl-libs-0__71.1-8.el9.x86_64//rpm",
"@daxctl-libs-0__78-2.el9.x86_64//rpm",
"@dbus-1__1.12.20-8.el9.x86_64//rpm",
"@dbus-broker-0__28-7.el9.x86_64//rpm",
"@dbus-common-1__1.12.20-8.el9.x86_64//rpm",
"@device-mapper-9__1.02.198-2.el9.x86_64//rpm",
"@device-mapper-libs-9__1.02.198-2.el9.x86_64//rpm",
"@diffutils-0__3.7-12.el9.x86_64//rpm",
"@dmidecode-1__3.6-1.el9.x86_64//rpm",
"@dracut-0__057-67.git20240812.el9.x86_64//rpm",
"@dracut-0__057-70.git20240819.el9.x86_64//rpm",
"@dwz-0__0.14-3.el9.x86_64//rpm",
"@e2fsprogs-libs-0__1.46.5-5.el9.x86_64//rpm",
"@edk2-ovmf-0__20240524-2.el9.x86_64//rpm",
"@edk2-ovmf-0__20240524-3.el9.x86_64//rpm",
"@efi-srpm-macros-0__6-2.el9.x86_64//rpm",
"@elfutils-libelf-0__0.191-4.el9.x86_64//rpm",
"@expat-0__2.5.0-2.el9.x86_64//rpm",
Expand Down Expand Up @@ -210,11 +218,11 @@ rpmtree(
"@groff-base-0__1.22.4-10.el9.x86_64//rpm",
"@gsettings-desktop-schemas-0__40.0-6.el9.x86_64//rpm",
"@gssproxy-0__0.8.4-7.el9.x86_64//rpm",
"@guestfs-tools-0__1.51.6-3.el9.x86_64//rpm",
"@guestfs-tools-0__1.51.6-5.el9.x86_64//rpm",
"@gzip-0__1.12-1.el9.x86_64//rpm",
"@hexedit-0__1.6-1.el9.x86_64//rpm",
"@hivex-libs-0__1.3.21-3.el9.x86_64//rpm",
"@hwdata-0__0.348-9.14.el9.x86_64//rpm",
"@hwdata-0__0.348-9.15.el9.x86_64//rpm",
"@inih-0__49-6.el9.x86_64//rpm",
"@iproute-0__6.2.0-5.el9.x86_64//rpm",
"@iproute-tc-0__6.2.0-5.el9.x86_64//rpm",
Expand All @@ -226,8 +234,8 @@ rpmtree(
"@kbd-0__2.4.0-10.el9.x86_64//rpm",
"@kbd-legacy-0__2.4.0-10.el9.x86_64//rpm",
"@kbd-misc-0__2.4.0-10.el9.x86_64//rpm",
"@kernel-core-0__5.14.0-495.el9.x86_64//rpm",
"@kernel-modules-core-0__5.14.0-495.el9.x86_64//rpm",
"@kernel-core-0__5.14.0-500.el9.x86_64//rpm",
"@kernel-modules-core-0__5.14.0-500.el9.x86_64//rpm",
"@kernel-srpm-macros-0__1.0-13.el9.x86_64//rpm",
"@keyutils-0__1.6.3-1.el9.x86_64//rpm",
"@keyutils-libs-0__1.6.3-1.el9.x86_64//rpm",
Expand All @@ -242,7 +250,7 @@ rpmtree(
"@libassuan-0__2.5.5-3.el9.x86_64//rpm",
"@libattr-0__2.5.1-3.el9.x86_64//rpm",
"@libbasicobjects-0__0.1.1-53.el9.x86_64//rpm",
"@libblkid-0__2.37.4-18.el9.x86_64//rpm",
"@libblkid-0__2.37.4-20.el9.x86_64//rpm",
"@libbpf-2__1.4.0-1.el9.x86_64//rpm",
"@libbrotli-0__1.0.9-6.el9.x86_64//rpm",
"@libcap-0__2.48-9.el9.x86_64//rpm",
Expand All @@ -251,13 +259,13 @@ rpmtree(
"@libcollection-0__0.7.0-53.el9.x86_64//rpm",
"@libcom_err-0__1.46.5-5.el9.x86_64//rpm",
"@libconfig-0__1.7.2-9.el9.x86_64//rpm",
"@libcurl-minimal-0__7.76.1-30.el9.x86_64//rpm",
"@libcurl-minimal-0__7.76.1-31.el9.x86_64//rpm",
"@libdb-0__5.3.28-54.el9.x86_64//rpm",
"@libeconf-0__0.4.1-4.el9.x86_64//rpm",
"@libedit-0__3.1-38.20210216cvs.el9.x86_64//rpm",
"@libev-0__4.33-5.el9.x86_64//rpm",
"@libevent-0__2.1.12-6.el9.x86_64//rpm",
"@libfdisk-0__2.37.4-18.el9.x86_64//rpm",
"@libfdisk-0__2.37.4-20.el9.x86_64//rpm",
"@libfdt-0__1.6.0-7.el9.x86_64//rpm",
"@libffi-0__3.4.2-8.el9.x86_64//rpm",
"@libfido2-0__1.13.0-2.el9.x86_64//rpm",
Expand All @@ -275,7 +283,7 @@ rpmtree(
"@libkcapi-hmaccalc-0__1.4.0-2.el9.x86_64//rpm",
"@libksba-0__1.5.1-7.el9.x86_64//rpm",
"@libmnl-0__1.0.4-15.el9.x86_64//rpm",
"@libmount-0__2.37.4-18.el9.x86_64//rpm",
"@libmount-0__2.37.4-20.el9.x86_64//rpm",
"@libnbd-0__1.20.2-2.el9.x86_64//rpm",
"@libnetfilter_conntrack-0__1.0.9-1.el9.x86_64//rpm",
"@libnfnetlink-0__1.0.1-21.el9.x86_64//rpm",
Expand All @@ -300,7 +308,7 @@ rpmtree(
"@libsepol-0__3.6-1.el9.x86_64//rpm",
"@libsigsegv-0__2.13-4.el9.x86_64//rpm",
"@libslirp-0__4.4.0-8.el9.x86_64//rpm",
"@libsmartcols-0__2.37.4-18.el9.x86_64//rpm",
"@libsmartcols-0__2.37.4-20.el9.x86_64//rpm",
"@libsoup-0__2.72.0-8.el9.x86_64//rpm",
"@libssh-0__0.10.4-13.el9.x86_64//rpm",
"@libssh-config-0__0.10.4-13.el9.x86_64//rpm",
Expand All @@ -312,7 +320,7 @@ rpmtree(
"@liburing-0__2.5-1.el9.x86_64//rpm",
"@libusbx-0__1.0.26-1.el9.x86_64//rpm",
"@libutempter-0__1.2.1-6.el9.x86_64//rpm",
"@libuuid-0__2.37.4-18.el9.x86_64//rpm",
"@libuuid-0__2.37.4-20.el9.x86_64//rpm",
"@libverto-0__0.3.2-3.el9.x86_64//rpm",
"@libverto-libev-0__0.3.2-3.el9.x86_64//rpm",
"@libvirt-client-0__10.5.0-5.el9.x86_64//rpm",
Expand Down Expand Up @@ -349,7 +357,7 @@ rpmtree(
"@ncurses-0__6.2-10.20210508.el9.x86_64//rpm",
"@ncurses-base-0__6.2-10.20210508.el9.x86_64//rpm",
"@ncurses-libs-0__6.2-10.20210508.el9.x86_64//rpm",
"@ndctl-libs-0__71.1-8.el9.x86_64//rpm",
"@ndctl-libs-0__78-2.el9.x86_64//rpm",
"@nettle-0__3.9.1-1.el9.x86_64//rpm",
"@nfs-utils-1__2.5.4-27.el9.x86_64//rpm",
"@npth-0__1.6-8.el9.x86_64//rpm",
Expand All @@ -360,8 +368,8 @@ rpmtree(
"@openldap-0__2.6.6-3.el9.x86_64//rpm",
"@openssh-0__8.7p1-43.el9.x86_64//rpm",
"@openssh-clients-0__8.7p1-43.el9.x86_64//rpm",
"@openssl-1__3.2.2-2.el9.x86_64//rpm",
"@openssl-libs-1__3.2.2-2.el9.x86_64//rpm",
"@openssl-1__3.2.2-4.el9.x86_64//rpm",
"@openssl-libs-1__3.2.2-4.el9.x86_64//rpm",
"@osinfo-db-0__20240701-2.el9.x86_64//rpm",
"@osinfo-db-tools-0__1.10.0-1.el9.x86_64//rpm",
"@p11-kit-0__0.25.3-2.el9.x86_64//rpm",
Expand Down Expand Up @@ -466,22 +474,22 @@ rpmtree(
"@swtpm-0__0.8.0-2.el9.x86_64//rpm",
"@swtpm-libs-0__0.8.0-2.el9.x86_64//rpm",
"@swtpm-tools-0__0.8.0-2.el9.x86_64//rpm",
"@systemd-0__252-38.el9.x86_64//rpm",
"@systemd-container-0__252-38.el9.x86_64//rpm",
"@systemd-libs-0__252-38.el9.x86_64//rpm",
"@systemd-pam-0__252-38.el9.x86_64//rpm",
"@systemd-rpm-macros-0__252-38.el9.x86_64//rpm",
"@systemd-udev-0__252-38.el9.x86_64//rpm",
"@systemd-0__252-45.el9.x86_64//rpm",
"@systemd-container-0__252-45.el9.x86_64//rpm",
"@systemd-libs-0__252-45.el9.x86_64//rpm",
"@systemd-pam-0__252-45.el9.x86_64//rpm",
"@systemd-rpm-macros-0__252-45.el9.x86_64//rpm",
"@systemd-udev-0__252-45.el9.x86_64//rpm",
"@tar-2__1.34-7.el9.x86_64//rpm",
"@tpm2-tss-0__3.2.3-1.el9.x86_64//rpm",
"@tzdata-0__2024a-2.el9.x86_64//rpm",
"@unbound-libs-0__1.16.2-8.el9.x86_64//rpm",
"@unzip-0__6.0-56.el9.x86_64//rpm",
"@unzip-0__6.0-57.el9.x86_64//rpm",
"@userspace-rcu-0__0.12.1-6.el9.x86_64//rpm",
"@util-linux-0__2.37.4-18.el9.x86_64//rpm",
"@util-linux-core-0__2.37.4-18.el9.x86_64//rpm",
"@util-linux-0__2.37.4-20.el9.x86_64//rpm",
"@util-linux-core-0__2.37.4-20.el9.x86_64//rpm",
"@vim-minimal-2__8.2.2637-21.el9.x86_64//rpm",
"@virt-v2v-1__2.5.6-3.el9.x86_64//rpm",
"@virt-v2v-1__2.5.6-4.el9.x86_64//rpm",
"@virtio-win-0__1.9.15-4.el9.x86_64//rpm",
"@which-0__2.21-29.el9.x86_64//rpm",
"@xfsprogs-0__6.4.0-4.el9.x86_64//rpm",
Expand Down
Loading

0 comments on commit b580f1b

Please sign in to comment.