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

Add e2e test for ova provider #630

Merged
merged 5 commits into from
Dec 5, 2023
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
6 changes: 5 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ jobs:
- os: ubuntu-latest
source_provider: openstack

- os: ubuntu-latest
source_provider: ova


runs-on: ${{ matrix.os }}
env:
USE_BAZEL_VERSION: 5.4.0
Expand All @@ -50,7 +54,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: kubev2v/forkliftci
ref: v8.0
ref: v11.0

- name: Build and setup everything with bazel
id: forkliftci
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ OPERATOR_INDEX_IMAGE ?= $(REGISTRY)/$(REGISTRY_ORG)/forklift-operator-index:$(RE
POPULATOR_CONTROLLER_IMAGE ?= $(REGISTRY)/$(REGISTRY_ORG)/populator-controller:$(REGISTRY_TAG)
OVIRT_POPULATOR_IMAGE ?= $(REGISTRY)/$(REGISTRY_ORG)/ovirt-populator:$(REGISTRY_TAG)
OPENSTACK_POPULATOR_IMAGE ?= $(REGISTRY)/$(REGISTRY_ORG)/openstack-populator:$(REGISTRY_TAG)
OVA_PROVIDER_SERVER_IMAGE ?= $(REGISTRY)/$(REGISTRY_ORG)/ova-provider-server:$(REGISTRY_TAG)
OVA_PROVIDER_SERVER_IMAGE ?= $(REGISTRY)/$(REGISTRY_ORG)/forklift-ova-provider-server:$(REGISTRY_TAG)

### External images
MUST_GATHER_IMAGE ?= quay.io/kubev2v/forklift-must-gather:latest
Expand Down Expand Up @@ -106,6 +106,10 @@ e2e-sanity-openstack-extended:
sudo bash -c 'echo "127.0.0.1 packstack.konveyor-forklift" >>/etc/hosts'
go test ./tests/suit -v -ginkgo.focus ".*Migration Extended tests for OpenStack.*" -ginkgo.parallel.total 1

e2e-sanity-ova:
# ova suit
go test ./tests/suit -v -ginkgo.focus ".*OVA.*"


# Build forklift-controller binary
forklift-controller: generate fmt vet
Expand Down
1 change: 1 addition & 0 deletions tests/suit/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ go_test(
"forklift_test.go",
"openstack_extended_test.go",
"openstack_test.go",
"ova_test.go",
"ovirt_test.go",
"tests_suite_test.go",
"vsphere_test.go",
Expand Down
1 change: 1 addition & 0 deletions tests/suit/framework/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
"exec_util.go",
"framework.go",
"openstack.go",
"ova.go",
"ovirt.go",
],
importpath = "github.com/konveyor/forklift-controller/tests/suit/framework",
Expand Down
16 changes: 10 additions & 6 deletions tests/suit/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,12 @@ type Clients struct {

// CrClient is a controller runtime client
CrClient crclient.Client
// RestConfig provides a pointer to our REST client config.
RestConfig *rest.Config
// DynamicClient performs generic operations on arbitrary k8s API objects.
DynamicClient dynamic.Interface
// OvirtClient provides a pointer to ovirt client.
OvirtClient OvirtClient
// OpenStackClient provides a pointer to Openstack client.
DynamicClient dynamic.Interface
RestConfig *rest.Config
OvirtClient OvirtClient
OpenStackClient OpenStackClient
OvaClient OvaClient
}

// K8s returns Kubernetes Clientset
Expand Down Expand Up @@ -292,6 +290,12 @@ func (c *Clients) GetOpenStackClient() (*OpenStackClient, error) {
return &oc, nil
}

// GetOvaClient instantiates and returns an OvaClient
bkhizgiy marked this conversation as resolved.
Show resolved Hide resolved
func (c *Clients) GetOvaClient() (*OvaClient, error) {
oc := OvaClient{}
return &oc, nil
}

// GetRESTConfigForServiceAccount returns a RESTConfig for SA
func (f *Framework) GetRESTConfigForServiceAccount(namespace, name string) (*rest.Config, error) {
token, err := f.GetTokenForServiceAccount(namespace, name)
Expand Down
75 changes: 75 additions & 0 deletions tests/suit/framework/ova.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package framework

import (
"context"
"errors"
"os"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)

// LoadSourceDetails - Load Source VM details from ova
func (r *OvaClient) LoadSourceDetails() (vm *OvaVM, err error) {
if sc := os.Getenv("STORAGE_CLASS"); sc != "" {
r.storageClass = sc
} else {
r.storageClass = "nfs-csi"
}

r.vmData.testVMId = "c5686650854d1e69b4123f4bf2e70fe1ed2a"
r.vmData.testNetworkID = "ae1badc8c693926f492a01e2f357d6af321b"
r.vmData.testStorageName = "Dummy storage for source provider ova-provider"
return &r.vmData, nil
}

func (r *OvaClient) GetNfsServerForOva(k8sClient *kubernetes.Clientset) (string, error) {
storageClass, err := k8sClient.StorageV1().StorageClasses().Get(context.TODO(), r.storageClass, metav1.GetOptions{})
if err != nil {
return "", err
}
var server, share string
for parm, val := range storageClass.Parameters {
bkhizgiy marked this conversation as resolved.
Show resolved Hide resolved
if parm == "server" {
server = val
}
if parm == "share" {
share = val
}
}
nfsShare := server + ":" + share
if nfsShare == "" {
return "", errors.New("failed to fatch NFS settings")
}

r.nfsPath = nfsShare
return r.nfsPath, nil
}

// GetNetworkId - return the network interface for the VM
func (r *OvaVM) GetNetworkId() string {
return r.testNetworkID
}

// GetVolumeId - return storage domain IDs
func (r *OvaVM) GetStorageName() string {
return r.testStorageName
}

// GetTestVMId - return the test VM ID
func (r *OvaVM) GetVmId() string {
return r.testVMId
}

type OvaClient struct {
vmData OvaVM
CustomEnv bool
nfsPath string
storageClass string
}

type OvaVM struct {
testVMId string
testNetworkID string
testStorageName string
}
84 changes: 84 additions & 0 deletions tests/suit/ova_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package suit_test

import (
"time"

forkliftv1 "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"github.com/konveyor/forklift-controller/tests/suit/framework"
"github.com/konveyor/forklift-controller/tests/suit/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

const (
ovaProviderName = "ova-provider"
ovaStorageClass = "nfs-csi"
ahadas marked this conversation as resolved.
Show resolved Hide resolved
)

var _ = Describe("[level:component]Migration tests for OVA provider", func() {
f := framework.NewFramework("migration-func-test")

It("[test] should create provider with NetworkMap", func() {
namespace := f.Namespace.Name

By("Load Source VM Details from OVA")
vmData, err := f.Clients.OvaClient.LoadSourceDetails()
Expect(err).ToNot(HaveOccurred())

By("Get NFS share for OVA provider")
nfs, err := f.Clients.OvaClient.GetNfsServerForOva(f.K8sClient)
Expect(err).ToNot(HaveOccurred())
By("Create Secret from Definition")
secret, err := utils.CreateSecretFromDefinition(f.K8sClient, utils.NewSecretDefinition(
map[string]string{
"createdForProviderType": "ova",
}, nil,
map[string][]byte{
"url": []byte(nfs),
}, namespace, "provider-test-secret"))
Expect(err).ToNot(HaveOccurred())

targetNS, err := f.CreateNamespace("ova-migration-test", map[string]string{})
Expect(err).ToNot(HaveOccurred())
By("Create target Openshift provider")
targetPr := utils.NewProvider(utils.TargetProviderName, forkliftv1.OpenShift, namespace, map[string]string{}, map[string]string{}, "", nil)
err = utils.CreateProviderFromDefinition(f.CrClient, targetPr)
Expect(err).ToNot(HaveOccurred())
_, err = utils.WaitForProviderReadyWithTimeout(f.CrClient, namespace, utils.TargetProviderName, 30*time.Second)
Expect(err).ToNot(HaveOccurred())
By("Create OVA provider")
pr := utils.NewProvider(ovaProviderName, forkliftv1.Ova, namespace, map[string]string{}, map[string]string{}, nfs, secret)
err = utils.CreateProviderFromDefinition(f.CrClient, pr)
Expect(err).ToNot(HaveOccurred())
provider, err := utils.WaitForProviderReadyWithTimeout(f.CrClient, namespace, ovaProviderName, 5*time.Minute)
Expect(err).ToNot(HaveOccurred())
By("Create Network Map")
networkMapDef := utils.NewNetworkMap(namespace, *provider, networkMapName, vmData.GetNetworkId())
err = utils.CreateNetworkMapFromDefinition(f.CrClient, networkMapDef)
Expect(err).ToNot(HaveOccurred())
err = utils.WaitForNetworkMapReadyWithTimeout(f.CrClient, namespace, networkMapName, 30*time.Second)
Expect(err).ToNot(HaveOccurred())
By("Create Storage Map")
storageMapDef := utils.NewStorageMap(namespace, *provider, test_storage_map_name, []string{vmData.GetStorageName()}, ovaStorageClass)
err = utils.CreateStorageMapFromDefinition(f.CrClient, storageMapDef)
Expect(err).ToNot(HaveOccurred())
err = utils.WaitForStorageMapReadyWithTimeout(f.CrClient, namespace, test_storage_map_name, 10*time.Second)
Expect(err).ToNot(HaveOccurred())

By("Creating plan")
planDef := utils.NewPlanWithVmId(*provider, namespace, test_plan_name, test_storage_map_name, networkMapName, targetNS.Name, []string{vmData.GetVmId()})

err = utils.CreatePlanFromDefinition(f.CrClient, planDef)
Expect(err).ToNot(HaveOccurred())
err, _ = utils.WaitForPlanReadyWithTimeout(f.CrClient, namespace, test_plan_name, 15*time.Second)
Expect(err).ToNot(HaveOccurred())

By("Creating migration")
migrationDef := utils.NewMigration(provider.Namespace, test_migration_name, test_plan_name)
err = utils.CreateMigrationFromDefinition(f.CrClient, migrationDef)
Expect(err).ToNot(HaveOccurred())
err = utils.WaitForMigrationSucceededWithTimeout(f.CrClient, provider.Namespace, test_migration_name, 900*time.Second)
Expect(err).ToNot(HaveOccurred())

})
})
10 changes: 9 additions & 1 deletion tests/suit/utils/storagemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"time"

api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
forkliftv1 "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/provider"
"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/ref"
Expand All @@ -31,11 +32,18 @@ func NewStorageMap(namespace string, providerIdentifier forkliftv1.Provider, sto

for _, sd := range storageIDs {
pair := forkliftv1.StoragePair{
Source: ref.Ref{ID: sd},
Destination: forkliftv1.DestinationStorage{
StorageClass: storageClass,
},
}

switch providerIdentifier.Type() {
case api.Ova:
pair.Source = ref.Ref{Name: sd}
default:
pair.Source = ref.Ref{ID: sd}
}
bkhizgiy marked this conversation as resolved.
Show resolved Hide resolved

sdPairs = append(sdPairs, pair)
}

Expand Down
Loading