Skip to content

Commit

Permalink
Add end to end tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ondra Machacek <[email protected]>
  • Loading branch information
machacekondra committed Oct 26, 2024
1 parent b842aee commit 0c7b9c9
Show file tree
Hide file tree
Showing 13 changed files with 623 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rhcos-live.x86_64.iso
**/*iso
10 changes: 10 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5

- name: Setup libvirt
run: |
sudo apt update
sudo apt install libvirt-dev
- name: Prepare
run: |
make generate
Expand All @@ -36,6 +41,11 @@ jobs:
- name: Check out code
uses: actions/checkout@v4

- name: Setup libvirt
run: |
sudo apt update
sudo apt install libvirt-dev
- name: Run golangci-lint
uses: golangci/[email protected]
with:
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/kind.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Run e2e test

on:
workflow_dispatch:
push:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout the code
uses: actions/checkout@v2

- name: Install kubectl
uses: azure/setup-kubectl@v4

- name: Create k8s Kind Cluster
uses: helm/kind-action@v1
with:
cluster_name: kind

- name: Setup libvirt
run: |
sudo apt update
sudo apt install sshpass libvirt-dev libvirt-daemon libvirt-daemon-system
sudo systemctl restart libvirtd
- name: Deploy dependencies
run: |
kubectl create deployment registry --image=docker.io/registry
kubectl create deployment vcsim --image=docker.io/vmware/vcsim
kubectl wait --for=condition=Ready pods --all --timeout=240s
kubectl port-forward --address 0.0.0.0 deploy/registry 5000:5000 &
kubectl port-forward --address 0.0.0.0 deploy/vcsim 8989:8989 &
- name: Build agent container
run: |
export REGISTRY_IP=$(ip addr show eth0 | grep -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+')
export MIGRATION_PLANNER_AGENT_IMAGE="${REGISTRY_IP}:5000/agent"
cat << EOF | sudo tee -a /etc/containers/registries.conf.d/myregistry.conf
[[registry]]
location = "${REGISTRY_IP}:5000"
insecure = true
EOF
make migration-planner-agent-container
podman push $MIGRATION_PLANNER_AGENT_IMAGE
- name: Deploy
run: |
export REGISTRY_IP=$(ip addr show eth0 | grep -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+')
export MIGRATION_PLANNER_AGENT_IMAGE="${REGISTRY_IP}:5000/agent"
make deploy-on-kind
kubectl wait --for=condition=Ready pods --all --timeout=240s
kubectl port-forward --address 0.0.0.0 service/migration-planner-agent 7443:7443 &
kubectl port-forward --address 0.0.0.0 service/migration-planner 3443:3443 &
- name: Run test
run: |
sudo make integration-test PLANNER_IP=$(ip addr show eth0 | grep -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+')
24 changes: 19 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ MIGRATION_PLANNER_AGENT_IMAGE ?= quay.io/kubev2v/migration-planner-agent
MIGRATION_PLANNER_API_IMAGE ?= quay.io/kubev2v/migration-planner-api
MIGRATION_PLANNER_UI_IMAGE ?= quay.io/kubev2v/migration-planner-ui
DOWNLOAD_RHCOS ?= true
KUBECTL ?= kubectl
IFACE ?= eth0
PODMAN ?= podman

SOURCE_GIT_TAG ?=$(shell git describe --always --long --tags --abbrev=7 --match 'v[0-9]*' || echo 'v0.0.0-unknown-$(SOURCE_GIT_COMMIT)')
SOURCE_GIT_TREE_STATE ?=$(shell ( ( [ ! -d ".git/" ] || git diff --quiet ) && echo 'clean' ) || echo 'dirty')
Expand Down Expand Up @@ -69,6 +72,9 @@ ifeq ($(DOWNLOAD_RHCOS), true)
curl --silent -C - -O https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/latest/rhcos-live.x86_64.iso
endif

integration-test: ginkgo
$(GINKGO) -focus=$(FOCUS) run test/e2e

build: bin image
go build -buildvcs=false $(GO_BUILD_FLAGS) -o $(GOBIN) ./cmd/...

Expand All @@ -78,10 +84,10 @@ build-api: bin

# rebuild container only on source changes
bin/.migration-planner-agent-container: bin Containerfile.agent go.mod go.sum $(GO_FILES)
podman build -f Containerfile.agent -t $(MIGRATION_PLANNER_AGENT_IMAGE):latest
$(PODMAN) build . -f Containerfile.agent -t $(MIGRATION_PLANNER_AGENT_IMAGE):latest

bin/.migration-planner-api-container: bin Containerfile.api go.mod go.sum $(GO_FILES)
podman build -f Containerfile.api -t $(MIGRATION_PLANNER_API_IMAGE):latest
$(PODMAN) build . -f Containerfile.api -t $(MIGRATION_PLANNER_API_IMAGE):latest

migration-planner-api-container: bin/.migration-planner-api-container
migration-planner-agent-container: bin/.migration-planner-agent-container
Expand All @@ -91,11 +97,19 @@ build-containers: migration-planner-api-container migration-planner-agent-contai
.PHONY: build-containers

push-containers: build-containers
podman push $(MIGRATION_PLANNER_API_IMAGE):latest
podman push $(MIGRATION_PLANNER_AGENT_IMAGE):latest
$(PODMAN) push $(MIGRATION_PLANNER_API_IMAGE):latest
$(PODMAN) push $(MIGRATION_PLANNER_AGENT_IMAGE):latest

deploy-on-kind:
sed 's|@MIGRATION_PLANNER_AGENT_IMAGE@|$(MIGRATION_PLANNER_AGENT_IMAGE)|g; s|@MIGRATION_PLANNER_API_IMAGE@|$(MIGRATION_PLANNER_API_IMAGE)|g' deploy/k8s/migration-planner.yaml.template > deploy/k8s/migration-planner.yaml
$(KUBECTL) apply -f 'deploy/k8s/*-service.yaml'
$(KUBECTL) apply -f 'deploy/k8s/*-secret.yaml'
@config_server=$$(ip addr show ${IFACE}| grep -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+'); \
$(KUBECTL) create secret generic migration-planner-secret --from-literal=config_server=http://$$config_server:7443 || true
$(KUBECTL) apply -f deploy/k8s/

deploy-on-openshift:
sed 's|@MIGRATION_PLANNER_API_IMAGE@|$(MIGRATION_PLANNER_API_IMAGE)|g' deploy/k8s/migration-planner.yaml.template > deploy/k8s/migration-planner.yaml
sed 's|@MIGRATION_PLANNER_AGENT_IMAGE@|$(MIGRATION_PLANNER_AGENT_IMAGE)|g; s|@MIGRATION_PLANNER_API_IMAGE@|$(MIGRATION_PLANNER_API_IMAGE)|g' deploy/k8s/migration-planner.yaml.template > deploy/k8s/migration-planner.yaml
sed 's|@MIGRATION_PLANNER_UI_IMAGE@|$(MIGRATION_PLANNER_UI_IMAGE)|g' deploy/k8s/migration-planner-ui.yaml.template > deploy/k8s/migration-planner-ui.yaml
oc apply -f 'deploy/k8s/*-service.yaml'
oc apply -f 'deploy/k8s/*-secret.yaml'
Expand Down
2 changes: 2 additions & 0 deletions deploy/k8s/migration-planner.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ spec:
secretKeyRef:
name: migration-planner-secret
key: config_server
- name: MIGRATION_PLANNER_AGENT_IMAGE
value: @MIGRATION_PLANNER_AGENT_IMAGE@
volumeMounts:
- name: migration-planner-config
mountPath: "/.migration-planner/config.yaml"
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ require (
github.com/go-chi/render v1.0.3
github.com/google/uuid v1.6.0
github.com/konveyor/forklift-controller v0.0.0-20221102112227-e73b65a01cda
github.com/libvirt/libvirt-go v7.4.0+incompatible
github.com/lthibault/jitterbug v2.0.0+incompatible
github.com/oapi-codegen/nethttp-middleware v1.0.2
github.com/oapi-codegen/runtime v1.1.1
github.com/onsi/ginkgo v1.16.5
github.com/onsi/ginkgo/v2 v2.15.0
github.com/onsi/gomega v1.32.0
github.com/openshift/assisted-image-service v0.0.0-20240827125623-ad5c4b36a817
Expand Down Expand Up @@ -50,6 +52,7 @@ require (
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/cors v1.3.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
Expand Down Expand Up @@ -94,6 +97,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nxadm/tail v1.4.11 // indirect
github.com/openshift/api v0.0.0-20230613151523-ba04973d3ed1 // indirect
github.com/openshift/custom-resource-status v1.1.2 // indirect
github.com/pborman/uuid v1.2.1 // indirect
Expand Down Expand Up @@ -125,6 +129,7 @@ require (
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/djherbis/times.v1 v1.3.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.28.3 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ github.com/kubev2v/forklift v0.0.0-20240729073638-8978e272380e/go.mod h1:1jmlC7L
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/libvirt/libvirt-go v7.4.0+incompatible h1:crnSLkwPqCdXtg6jib/FxBG/hweAc/3Wxth1AehCXL4=
github.com/libvirt/libvirt-go v7.4.0+incompatible/go.mod h1:34zsnB4iGeOv7Byj6qotuW8Ya4v4Tr43ttjz/F0wjLE=
github.com/lthibault/jitterbug v2.0.0+incompatible h1:qouq51IKzlMx25+15jbxhC/d79YyTj0q6XFoptNqaUw=
github.com/lthibault/jitterbug v2.0.0+incompatible/go.mod h1:2l7akWd27PScEs6YkjyUVj/8hKgNhbbQ3KiJgJtlf6o=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand Down Expand Up @@ -461,6 +463,7 @@ golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Running integration tests
The integration tests are executed against deployed `planner-api`. The planner api can be deployed
as container or running as binary.

## Requiremets

```
dnf install -y libvirt-devel
sudo usermod -a -G libvirt $USER
```

Running planner api, either as container or binary:
```
bin/planner-api
```

## Executing tests
```
PLANNER_IP=1.2.3.4 make integration-tests
```
34 changes: 34 additions & 0 deletions test/e2e/data/vm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<domain type='kvm'>
<name>coreos-vm</name>
<memory unit='MiB'>4096</memory>
<vcpu placement='static'>2</vcpu>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://fedoraproject.org/coreos/stable"/>
</libosinfo:libosinfo>
</metadata>
<os>
<type arch='x86_64' machine='pc-q35-6.2'>hvm</type>
<boot dev='cdrom'/>
</os>
<cpu mode='host-passthrough' check='none' migratable='on'/>
<features>
<acpi/>
<apic/>
</features>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/tmp/agent.iso'/>
<target dev='sda' bus='sata'/>
<readonly/>
</disk>
<interface type='network'>
<source network='default'/>
<model type='virtio'/>
</interface>
<graphics type='vnc' port='-1'/>
<console type='pty'/>
</devices>
</domain>
Loading

0 comments on commit 0c7b9c9

Please sign in to comment.