Skip to content

Commit

Permalink
Convert bootstrapping test scripts in go (rancher#89)
Browse files Browse the repository at this point in the history
* ci: add verbose mode to ginkgo tests
This is helpful to have the trace of all steps of a test.

* ci: add missing `make deps` for some integration tests

* ci: convert bootstrapping scripts to use Go/Ginkgo

* ci: fix linter errors

Signed-off-by: Loic Devulder <[email protected]>
  • Loading branch information
ldevulder authored May 2, 2022
1 parent 4b350e0 commit 03a77f7
Show file tree
Hide file tree
Showing 17 changed files with 548 additions and 275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
REPO: quay.io/costoolkit/os2-ci
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
Expand Down Expand Up @@ -46,28 +46,29 @@ jobs:
env:
CLUSTER_NAME: cluster-k3s
CLUSTER_NS: fleet-default
K8S_VERSION: v1.21.9+k3s1
INSTALL_K3S_VERSION: v1.21.9+k3s1
INSTALL_K3S_SKIP_ENABLE: true
KUBECONFIG: /etc/rancher/k3s/k3s.yaml
options: --privileged
steps:
- name: Install dependencies
run: zypper -n in -l qemu-kvm libvirt virt-install curl helm git-core tar make
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: '~1.17'
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: artifacts
- name: Install Rancher
run: cd tests && make install-rancher
- name: Configure Rancher to provision RancherOS on a test server
run: cd tests && make configure-rancher-step-01
- name: Install RancherOS on the test server
run: cd tests && make install-ros-node
- name: Configure Rancher to add the test server in a test cluster
run: cd tests && make configure-rancher-step-02
- name: Add the test server in the test cluster
run: cd tests && make add-node-in-cluster
- name: E2E - Bootstrapping node with Rancher
run: |
# Clean Helm repo
REPO=$(helm repo list 2>/dev/null | awk '(NR>1) { print $1 }')
helm repo remove ${REPO}
cd tests && make e2e-bootstraping-node-with-rancher
- name: Upload logs
uses: actions/upload-artifact@v3
if: failure()
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
make deps
- name: Run tests
run: |
ginkgo -r ./pkg/...
ginkgo -r -v ./pkg/...
31 changes: 8 additions & 23 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ deps:
integration-tests: clean add up deps run

run:
ginkgo -r ./smoke
ginkgo -r -v ./smoke

.PHONY: install
install:
ginkgo --label-filter setup -r ./install
ginkgo --label-filter setup -r -v ./install

build/ci.iso:
./prepare_cloudinit

vbox-tests: build/ci.iso iso-to-vm
vbox-tests: build/ci.iso deps iso-to-vm
$(MAKE) run

build-box:
Expand All @@ -52,7 +52,7 @@ build-box:
build-box/sda.vdi: build-box
VBoxManage createmedium disk --filename build-box/sda.vdi --size 40000

iso-to-vm: build-box/sda.vdi
iso-to-vm: build-box/sda.vdi deps
VBoxManage createvm --name "test" --register
VBoxManage modifyvm "test" --memory 10240 --cpus 3
VBoxManage modifyvm "test" --nic1 nat --boot1 disk --boot2 dvd --natpf1 "guestssh,tcp,,2222,,22"
Expand All @@ -71,32 +71,17 @@ clean_vm_from_iso:
VBoxManage unregistervm "test" --delete &>/dev/null || true
VBoxManage closemedium disk sda.vdi --delete &>/dev/null || true

installer-tests: build-box/sda.vdi
installer-tests: build-box/sda.vdi deps
VBoxManage createvm --name "test" --register
VBoxManage modifyvm "test" --memory 10240 --cpus 3
VBoxManage modifyvm "test" --nic1 nat --boot1 disk --boot2 dvd --natpf1 "guestssh,tcp,,2222,,22"
VBoxManage storagectl "test" --name "sata controller" --add sata --portcount 2 --hostiocache off
VBoxManage storageattach "test" --storagectl "sata controller" --port 0 --device 0 --type hdd --medium build-box/sda.vdi
VBoxManage storageattach "test" --storagectl "sata controller" --port 1 --device 0 --type dvddrive --medium $(ISO)
VBoxManage startvm "test" --type headless
ginkgo --label-filter "!setup" -r ./install
ginkgo --label-filter "!setup" -r -v ./install
VBoxManage controlvm "test" poweroff &>/dev/null || true

# e2e CI tests
install-rancher:
./scripts/install-rancher

configure-rancher-step-01:
./scripts/configure-rancher-step-01

install-ros-node:
# Force the execution with a tty, needed to follow VM installation
script -e -c ./scripts/install-ros-node

configure-rancher-step-02:
./scripts/configure-rancher-step-02

add-node-in-cluster:
./scripts/add-node-in-cluster

e2e-bootstraping-node-with-rancher: install-rancher configure-rancher-step-01 install-ros-node configure-rancher-step-02 add-node-in-cluster
e2e-bootstraping-node-with-rancher: deps
ginkgo --label-filter bootstrapping -r -v ./e2e
11 changes: 11 additions & 0 deletions tests/assets/add_cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
kind: Cluster
apiVersion: provisioning.cattle.io/v1
metadata:
name: %CLUSTER_NAME%
# namespace: fleet-default
spec:
rkeConfig:
machineGlobalConfig:
cluster-cidr: "10.44.0.0/16"
service-cidr: "10.45.0.0/16"
kubernetesVersion: v1.21.9+k3s1
8 changes: 3 additions & 5 deletions tests/assets/machineregistration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ metadata:
name: machine-registration
# The namespace must match the namespace of the cluster
# assigned to the clusters.provisioning.cattle.io resource
namespace: fleet-default
# namespace: fleet-default
spec:
# Labels to be added to the created MachineInventory object
machineInventoryLabels: {}
# Annotations to be added to the created MachineInventory object
machineInventoryAnnotations: {}
# The cloud config that will be used to provision the node
cloudConfig:
hostname: ros-node-{{ trunc 4 .MachineID }}
install:
device: /dev/vda
rancheros:
install:
isoUrl: https://something.example.com
users:
- name: root
passwd: root
passwd: root
16 changes: 16 additions & 0 deletions tests/assets/net-default.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<network>
<name>default</name>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='virbr0' stp='on' delay='0'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'/>
<host mac='52:54:00:00:00:01' name='ros-node' ip='192.168.122.10'/>
%IPXE_SCRIPT%
</dhcp>
</ip>
</network>
Loading

0 comments on commit 03a77f7

Please sign in to comment.