Skip to content

Commit 8e74735

Browse files
author
Roman Sysoev
committed
test(ci): add e2e github workflow
Signed-off-by: Roman Sysoev <[email protected]>
1 parent e599b02 commit 8e74735

File tree

8 files changed

+135
-46
lines changed

8 files changed

+135
-46
lines changed

.github/workflows/e2e_main.yaml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Copyright 2024 Flant JSC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: e2e
16+
17+
env:
18+
CI_COMMIT_REF_NAME: ${{ github.ref_name }}
19+
GO_VERSION: "1.22.7"
20+
GINKGO_VERSION: "2.20.0"
21+
22+
on:
23+
workflow_dispatch:
24+
schedule:
25+
- cron: "0 1 * * *"
26+
27+
defaults:
28+
run:
29+
shell: bash
30+
31+
jobs:
32+
show_dev_manifest:
33+
runs-on: ubuntu-latest
34+
name: Run e2e
35+
steps:
36+
- uses: actions/checkout@v4
37+
38+
- name: Set up Go ${{ env.GO_VERSION }}
39+
uses: actions/setup-go@v5
40+
with:
41+
go-version: "${{ env.GO_VERSION }}"
42+
43+
- name: Install Task
44+
uses: arduino/setup-task@v2
45+
46+
- name: Install ginkgo
47+
run: |
48+
echo "Install ginkgo"
49+
go install "github.com/onsi/ginkgo/v2/ginkgo@v${{ env.GINKGO_VERSION }}"
50+
51+
- name: Install Deckhouse-cli
52+
run: |
53+
echo "Install d8"
54+
curl -fsSL -o d8-install.sh https://raw.githubusercontent.com/deckhouse/deckhouse-cli/main/d8-install.sh
55+
bash d8-install.sh
56+
57+
- uses: azure/k8s-set-context@v4
58+
with:
59+
method: service-account
60+
k8s-url: https://api.e2e.virtlab.flant.com
61+
k8s-secret: ${{ secrets.E2E_VIRTUALIZATION_SA_SECRET }}
62+
63+
- name: Download dependencies
64+
working-directory: ./tests/e2e/
65+
run: |
66+
echo "Download dependencies"
67+
go mod download
68+
69+
- name: Run E2E
70+
working-directory: ./tests/e2e/
71+
run: |
72+
task run -v

tests/e2e/Taskfile.yaml

+15-32
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,28 @@ tasks:
1010
copy:
1111
cmds:
1212
- |
13-
rm -fr /tmp/testdata
14-
mkdir /tmp/testdata
15-
cp -a testdata/complex-test /tmp/testdata/complex-test
16-
cp -a testdata/connectivity /tmp/testdata/connectivity
17-
cp -a testdata/disk-resizing /tmp/testdata/disk-resizing
18-
cp -a testdata/sizing-policy /tmp/testdata/sizing-policy
19-
cp -a testdata/vm-configuration /tmp/testdata/vm-configuration
20-
cp -a testdata/vm-migration /tmp/testdata/vm-migration
21-
cp -a testdata/vm-disk-attachment /tmp/testdata/vm-disk-attachment
22-
cp -a testdata/sshkeys /tmp/testdata/sshkeys
13+
rm --force --recursive /tmp/testdata
14+
cp -a testdata /tmp/testdata
15+
2316
ginkgo:
2417
cmds:
2518
- |
2619
v=($(ginkgo version 2>/dev/null))
2720
if [ "${v[2]}" != "{{ .GINKGO_VERSION }}" ]; then
28-
go install github.com/onsi/ginkgo/v2/ginkgo@v"{{ .GINKGO_VERSION }}" ;
21+
go install "github.com/onsi/ginkgo/v2/ginkgo@v{{ .GINKGO_VERSION }}" ;
2922
fi
3023
run:
3124
desc: "Run e2e tests"
3225
deps:
33-
- ginkgo
26+
- copy
3427
cmds:
35-
- ginkgo --focus "Virtualization resources" -v
28+
- |
29+
ginkgo \
30+
--skip-file vm_test.go \
31+
--skip-file vm_label_annotation_test.go \
32+
--skip-file ipam_test.go \
33+
--skip-file disks_test.go \
34+
-v
3635
3736
run_local:
3837
desc: "Run locally e2e tests"
@@ -55,25 +54,9 @@ tasks:
5554
- ginkgo
5655
cmds:
5756
- |
58-
{{if .TEST }}
59-
ginkgo --focus "{{ .TEST }}" -v
57+
{{if .FOCUS }}
58+
ginkgo --focus "{{ .FOCUS }}" -v
6059
{{else}}
6160
echo "Specify test to run"
62-
echo 'Example: TEST="Label and Annotation" task run_one'
61+
echo 'Example: FOCUS="Label and Annotation" task run_one'
6362
{{end}}
64-
65-
fix:ssh_key_perm:
66-
desc: "Check and fix permissions for ssh keys"
67-
cmds:
68-
- |
69-
ID_ED=testdata/vm/sshkeys/id_ed
70-
case {{OS}} in
71-
darwin*) RIGHTS_SSH=$(stat -f %Lp $ID_ED) ;;
72-
linux*) RIGHTS_SSH=$(stat -c "%a" $ID_ED) ;;
73-
*) echo "unknown: {{OS}}"; exit 1 ;;
74-
esac
75-
76-
if [ $RIGHTS_SSH -ne 600 ]; then
77-
echo "Fix permissions for file $ID_ED"
78-
chmod 600 $ID_ED
79-
fi

tests/e2e/complex_test.go

+36-5
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,41 @@ import (
2323
. "github.com/onsi/ginkgo/v2"
2424
. "github.com/onsi/gomega"
2525

26+
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
2627
kc "github.com/deckhouse/virtualization/tests/e2e/kubectl"
2728
)
2829

30+
func AssignIPToVMIP(name string) error {
31+
assignErr := fmt.Sprintf("cannot patch VMIP %q with unnassigned IP address", name)
32+
unassignedIP, err := FindUnassignedIP(mc.Spec.Settings.VirtualMachineCIDRs)
33+
if err != nil {
34+
return fmt.Errorf("%s\n%s", assignErr, err)
35+
}
36+
patch := fmt.Sprintf("{\"spec\":{\"staticIP\":%q}}", unassignedIP)
37+
err = MergePatchResource(kc.ResourceVMIP, name, patch)
38+
if err != nil {
39+
return fmt.Errorf("%s\n%s", assignErr, err)
40+
}
41+
vmip := virtv2.VirtualMachineIPAddress{}
42+
err = GetObject(kc.ResourceVMIP, name, &vmip, kc.GetOptions{
43+
Namespace: conf.Namespace,
44+
})
45+
if err != nil {
46+
return fmt.Errorf("%s\n%s", assignErr, err)
47+
}
48+
jsonPath := fmt.Sprintf("'jsonpath={.status.phase}=%s'", PhaseAttached)
49+
waitOpts := kc.WaitOptions{
50+
Namespace: conf.Namespace,
51+
For: jsonPath,
52+
Timeout: 30,
53+
}
54+
res := kubectl.WaitResources(kc.ResourceVMIP, waitOpts, name)
55+
if res.Error() != nil {
56+
return fmt.Errorf("%s\n%s", assignErr, res.StdErr())
57+
}
58+
return nil
59+
}
60+
2961
var _ = Describe("Complex test", Ordered, ContinueOnFailure, func() {
3062
var (
3163
testCaseLabel = map[string]string{"testcase": "complex-test"}
@@ -74,11 +106,10 @@ var _ = Describe("Complex test", Ordered, ContinueOnFailure, func() {
74106

75107
Context("When virtual machines IP addresses are applied:", func() {
76108
It("patches custom VMIP with unassigned address", func() {
77-
unassignedIP, err := FindUnassignedIP(mc.Spec.Settings.VirtualMachineCIDRs)
78-
Expect(err).NotTo(HaveOccurred())
79-
vmipMetadataName := fmt.Sprintf("%s-%s", namePrefix, "vm-custom-ip")
80-
mergePatch := fmt.Sprintf("{\"spec\":{\"staticIP\":%q}}", unassignedIP)
81-
MergePatchResource(kc.ResourceVMIP, vmipMetadataName, mergePatch)
109+
vmipName := fmt.Sprintf("%s-%s", namePrefix, "vm-custom-ip")
110+
Eventually(func() error {
111+
return AssignIPToVMIP(vmipName)
112+
}).Should(Succeed())
82113
})
83114

84115
It("checks VMIPs phases", func() {

tests/e2e/d8/d8.go

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ func NewD8Virtualization(conf D8VirtualizationConf) (*d8VirtualizationCMD, error
6868
}
6969

7070
connEnvs, connArgs, err := clustertransport.KubeConnectionCmdSettings(clustertransport.ClusterTransport(conf))
71-
7271
if err != nil {
7372
return nil, fmt.Errorf("load connection config: %w", err)
7473
}

tests/e2e/kubectl/kubectl.go

-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ func NewKubectl(conf KubectlConf) (*KubectlCMD, error) {
133133
}
134134

135135
connEnvs, connArgs, err := clustertransport.KubeConnectionCmdSettings(clustertransport.ClusterTransport(conf))
136-
137136
if err != nil {
138137
return nil, fmt.Errorf("load connection config: %w", err)
139138
}

tests/e2e/sizing_policy_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ var _ = Describe("Sizing policy", Ordered, ContinueOnFailure, func() {
161161

162162
It("changes VMClassName in VM specification with existing VMClass", func() {
163163
mergePatch := fmt.Sprintf("{\"spec\":{\"virtualMachineClassName\":%q}}", vmClassDiscovery)
164-
MergePatchResource(kc.ResourceVM, vmNotValidSizingPolicyChanging, mergePatch)
164+
err := MergePatchResource(kc.ResourceVM, vmNotValidSizingPolicyChanging, mergePatch)
165+
Expect(err).NotTo(HaveOccurred(), err)
165166
})
166167

167168
It("checks VM phase and condition status after changing", func() {
@@ -184,7 +185,8 @@ var _ = Describe("Sizing policy", Ordered, ContinueOnFailure, func() {
184185

185186
It("changes VMClassName in VM specification with not existing VMClass which have correct prefix for creating", func() {
186187
mergePatch := fmt.Sprintf("{\"spec\":{\"virtualMachineClassName\":%q}}", vmClassDiscoveryCopy)
187-
MergePatchResource(kc.ResourceVM, vmNotValidSizingPolicyCreating, mergePatch)
188+
err := MergePatchResource(kc.ResourceVM, vmNotValidSizingPolicyCreating, mergePatch)
189+
Expect(err).NotTo(HaveOccurred(), err)
188190
})
189191

190192
It("creates new `VirtualMachineClass`", func() {

tests/e2e/util_test.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,16 @@ func PatchResource(resource kc.Resource, name string, patch *kc.JsonPatch) {
148148
res.StdErr())
149149
}
150150

151-
func MergePatchResource(resource kc.Resource, name, patch string) {
151+
func MergePatchResource(resource kc.Resource, name, patch string) error {
152152
GinkgoHelper()
153153
res := kubectl.PatchResource(resource, name, kc.PatchOptions{
154154
Namespace: conf.Namespace,
155155
MergePatch: patch,
156156
})
157-
Expect(res.Error()).NotTo(HaveOccurred(), "patch failed %s %s/%s.\n%s", resource, conf.Namespace, name,
158-
res.StdErr())
157+
if res.Error() != nil {
158+
return fmt.Errorf("patch failed %s %s/%s.\n%s", resource, conf.Namespace, name, res.StdErr())
159+
}
160+
return nil
159161
}
160162

161163
func CheckField(resource kc.Resource, name, output, compareValue string) {
@@ -234,7 +236,7 @@ func WaitPhase(resource kc.Resource, phase string, opts kc.GetOptions) {
234236
Timeout: 600,
235237
}
236238
waitResult := kubectl.WaitResources(resource, waitOpts, resources...)
237-
Expect(waitResult.WasSuccess()).To(Equal(true), waitResult.StdErr())
239+
Expect(waitResult.Error()).NotTo(HaveOccurred(), waitResult.StdErr())
238240
}
239241

240242
func GetDefaultStorageClass() (*storagev1.StorageClass, error) {

tests/e2e/vm_disk_resizing_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ func ResizeDisks(addedSize *resource.Quantity, config *cfg.Config, virtualDisks
6363
Expect(err).NotTo(HaveOccurred(), err)
6464
newValue := resource.NewQuantity(diskObject.Spec.PersistentVolumeClaim.Size.Value()+addedSize.Value(), resource.BinarySI)
6565
mergePatch := fmt.Sprintf("{\"spec\":{\"persistentVolumeClaim\":{\"size\":\"%s\"}}}", newValue.String())
66-
MergePatchResource(kc.ResourceVD, vd, mergePatch)
66+
err = MergePatchResource(kc.ResourceVD, vd, mergePatch)
67+
Expect(err).NotTo(HaveOccurred(), err)
6768
}
6869
}
6970

0 commit comments

Comments
 (0)