Skip to content

Commit

Permalink
🤖 Add upgrade tests from latest release
Browse files Browse the repository at this point in the history
  • Loading branch information
mudler authored May 29, 2022
1 parent 9051127 commit c14a500
Show file tree
Hide file tree
Showing 8 changed files with 526 additions and 94 deletions.
7 changes: 7 additions & 0 deletions .github/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

go get github.com/onsi/ginkgo/v2
go get github.com/onsi/gomega/...
go get github.com/onsi/ginkgo/v2/ginkgo/internal@v2.1.3
go install github.com/onsi/ginkgo/v2/ginkgo
ginkgo --label-filter "$1" --fail-fast -r ./tests/
169 changes: 143 additions & 26 deletions .github/workflows/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ jobs:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
run: |
docker push quay.io/c3os/c3os:${{ matrix.flavor }}-latest
- name: Push to testing
run: |
docker tag quay.io/c3os/c3os:${{ matrix.flavor }}-latest ttl.sh/c3os-${{ matrix.flavor }}-${{ github.sha }}:8h
docker push ttl.sh/c3os-${{ matrix.flavor }}-${{ github.sha }}:8h
# Test start
build-vm-images:
needs: build
needs:
- build
runs-on: macos-10.15
strategy:
fail-fast: false
Expand Down Expand Up @@ -115,8 +119,11 @@ jobs:
config.yaml
if-no-files-found: error

single-test:
needs: prepare-test
upgrade-single-node-k8s-test:
needs:
- prepare-test
- upgrade-test
- upgrade-latest-with-cli-test
runs-on: macos-10.15
strategy:
fail-fast: true
Expand Down Expand Up @@ -149,21 +156,24 @@ jobs:
ls -liah
export ISO=$PWD/$(ls *.iso)
export GOPATH="/Users/runner/go"
PATH=$PATH:$GOPATH/bin
go get github.com/onsi/ginkgo/v2
go get github.com/onsi/gomega/...
go get github.com/onsi/ginkgo/v2/ginkgo/internal@v2.1.3
go install github.com/onsi/ginkgo/v2/ginkgo
CLOUD_INIT=$PWD/config.yaml CREATE_VM=true FLAVOR=${{ matrix.flavor }} ginkgo --label-filter upgrade --fail-fast -r ./tests/
export PATH=$PATH:$GOPATH/bin
export CLOUD_INIT=$PWD/config.yaml
export CREATE_VM=true
export FLAVOR=${{ matrix.flavor }}
./.github/run_test.sh "upgrade-k8s"
- uses: actions/upload-artifact@v2
if: failure()
with:
name: ${{ matrix.flavor }}-vbox.logs.zip
path: tests/**/logs/*
if-no-files-found: warn

test:
needs: prepare-test
decentralized-k8s-test-opensuse:
needs:
- prepare-test
- upgrade-single-node-k8s-test
- upgrade-test
- upgrade-latest-with-cli-test
runs-on: macos-10.15
strategy:
fail-fast: true
Expand Down Expand Up @@ -196,12 +206,11 @@ jobs:
ls -liah
export ISO=$PWD/$(ls *.iso)
export GOPATH="/Users/runner/go"
PATH=$PATH:$GOPATH/bin
go get github.com/onsi/ginkgo/v2
go get github.com/onsi/gomega/...
go get github.com/onsi/ginkgo/v2/ginkgo/internal@v2.1.3
go install github.com/onsi/ginkgo/v2/ginkgo
CLOUD_INIT=$PWD/config.yaml CREATE_VM=true FLAVOR=${{ matrix.flavor }} ginkgo --label-filter smoke --fail-fast -r ./tests/
export PATH=$PATH:$GOPATH/bin
export CLOUD_INIT=$PWD/config.yaml
export CREATE_VM=true
export FLAVOR=${{ matrix.flavor }}
./.github/run_test.sh "decentralized-k8s"
- uses: actions/upload-artifact@v2
if: failure()
with:
Expand Down Expand Up @@ -239,10 +248,12 @@ jobs:
config.yaml
if-no-files-found: error

test-alpine:
decentralized-k8s-test-alpine:
needs:
- prepare-alpine-test
- test
- decentralized-k8s-test-opensuse
- upgrade-test
- upgrade-latest-with-cli-test
runs-on: macos-10.15
strategy:
fail-fast: true
Expand Down Expand Up @@ -275,20 +286,126 @@ jobs:
ls -liah
export ISO=$PWD/$(ls *.iso)
export GOPATH="/Users/runner/go"
PATH=$PATH:$GOPATH/bin
go get github.com/onsi/ginkgo/v2
go get github.com/onsi/gomega/...
go get github.com/onsi/ginkgo/v2/ginkgo/internal@v2.1.3
go install github.com/onsi/ginkgo/v2/ginkgo
CLOUD_INIT=$PWD/config.yaml CREATE_VM=true FLAVOR=${{ matrix.flavor }} ginkgo --label-filter smoke --fail-fast -r ./tests/
export PATH=$PATH:$GOPATH/bin
export CLOUD_INIT=$PWD/config.yaml
export CREATE_VM=true
export FLAVOR=${{ matrix.flavor }}
./.github/run_test.sh "decentralized-k8s"
- uses: actions/upload-artifact@v2
if: failure()
with:
name: ${{ matrix.flavor }}-vbox.logs.zip
path: tests/**/logs/*
if-no-files-found: warn

latest-release:
runs-on: ubuntu-latest
steps:
- uses: robinraju/release-downloader@v1.3
with:
# A flag to set the download target as latest release
# The default value is 'false'
latest: true
repository: "c3os-io/c3os"
fileName: "*"
out-file-path: "last-release"
- uses: actions/upload-artifact@v2
with:
name: latest-release.zip
path: last-release
if-no-files-found: error

upgrade-latest-with-cli-test:
needs:
- build
- latest-release
runs-on: macos-10.15
strategy:
fail-fast: false
matrix:
include:
- flavor: "alpine"
node: "A" # Arbitrary field
- flavor: "opensuse"
node: "B"
# - flavor: "alpine"
# node: "C"
steps:
- uses: actions/checkout@v2
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: latest-release.zip
- name: Install deps
run: |
brew install cdrtools jq
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: '^1.16'
- run: |
ls -liah
export ISO=$PWD/$(ls c3os-${{ matrix.flavor }}-*.iso)
export GOPATH="/Users/runner/go"
export CONTAINER_IMAGE=ttl.sh/c3os-${{ matrix.flavor }}-${{ github.sha }}:8h
export PATH=$PATH:$GOPATH/bin
export CLOUD_INIT=$PWD/tests/assets/config.yaml
export CREATE_VM=true
export FLAVOR=${{ matrix.flavor }}
./.github/run_test.sh "upgrade-latest-with-cli"
- uses: actions/upload-artifact@v2
if: failure()
with:
name: ${{ matrix.flavor }}-upgrade-test.logs.zip
path: tests/**/logs/*
if-no-files-found: warn



upgrade-test:
needs:
- build
- latest-release
runs-on: macos-10.15
strategy:
fail-fast: false
matrix:
include:
- flavor: "alpine"
node: "A" # Arbitrary field
- flavor: "opensuse"
node: "B"
# - flavor: "alpine"
# node: "C"
steps:
- uses: actions/checkout@v2
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: latest-release.zip
- name: Install deps
run: |
brew install cdrtools jq
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: '^1.16'
- run: |
ls -liah
export ISO=$PWD/$(ls c3os-${{ matrix.flavor }}-*.iso)
export GOPATH="/Users/runner/go"
export CONTAINER_IMAGE=ttl.sh/c3os-${{ matrix.flavor }}-${{ github.sha }}:8h
export PATH=$PATH:$GOPATH/bin
export CLOUD_INIT=$PWD/tests/assets/config.yaml
export CREATE_VM=true
export FLAVOR=${{ matrix.flavor }}
./.github/run_test.sh "upgrade-latest-with-kubernetes"
- uses: actions/upload-artifact@v2
if: failure()
with:
name: ${{ matrix.flavor }}-upgrade-test.logs.zip
path: tests/**/logs/*
if-no-files-found: warn
# test-tumbleweed:
# needs:
# - prepare-test
Expand Down
41 changes: 3 additions & 38 deletions tests/smoke_test.go → tests/decentralized_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,14 @@ import (
"github.com/onsi/gomega/types"
)

var _ = Describe("c3os smoke", Label("smoke"), func() {
var _ = Describe("c3os decentralized k8s test", Label("decentralized-k8s"), func() {
BeforeEach(func() {
machine.EventuallyConnects()
})

AfterEach(func() {
if CurrentGinkgoTestDescription().Failed {
machine.SSHCommand("sudo k3s kubectl get pods -A -o json > /run/pods.json")
machine.SSHCommand("sudo k3s kubectl get events -A -o json > /run/events.json")
machine.SSHCommand("sudo df -h > /run/disk")
machine.SSHCommand("sudo mount > /run/mounts")
machine.SSHCommand("sudo blkid > /run/blkid")

machine.GatherAllLogs(
[]string{
"edgevpn@c3os",
"c3os-agent",
"cos-setup-boot",
"cos-setup-network",
"c3os",
"k3s",
},
[]string{
"/var/log/edgevpn.log",
"/var/log/c3os-agent.log",
"/run/pods.json",
"/run/disk",
"/run/mounts",
"/run/blkid",
"/run/events.json",
})
gatherLogs()
}
})

Expand Down Expand Up @@ -125,7 +102,7 @@ var _ = Describe("c3os smoke", Label("smoke"), func() {

It("has default image sizes", func() {
for _, p := range []string{"active.img", "passive.img"} {
out, _ := machine.SSHCommand(`sudo stat -c "%s" /run/initramfs/cos-state/cOS/` + p )
out, _ := machine.SSHCommand(`sudo stat -c "%s" /run/initramfs/cos-state/cOS/` + p)
Expect(out).Should(ContainSubstring("2097152000"))
}
})
Expand Down Expand Up @@ -166,9 +143,6 @@ var _ = Describe("c3os smoke", Label("smoke"), func() {
})

It("propagate kubeconfig", func() {
if os.Getenv("FLAVOR") == "alpine" {
Skip("Skip on alpine")
}
Eventually(func() string {
out, _ := machine.SSHCommand("c3os get-kubeconfig")
return out
Expand All @@ -182,9 +156,6 @@ var _ = Describe("c3os smoke", Label("smoke"), func() {
})

It("has roles", func() {
if os.Getenv("FLAVOR") == "alpine" {
Skip("Skip on alpine")
}
uuid, _ := machine.SSHCommand("c3os uuid")
Expect(uuid).ToNot(Equal(""))
Eventually(func() string {
Expand All @@ -200,9 +171,6 @@ var _ = Describe("c3os smoke", Label("smoke"), func() {
})

It("has machines with different IPs", func() {
if os.Getenv("FLAVOR") == "alpine" {
Skip("Skip on alpine")
}
Eventually(func() string {
out, _ := machine.SSHCommand(`curl http://localhost:8080/api/machines`)
return out
Expand Down Expand Up @@ -232,9 +200,6 @@ var _ = Describe("c3os smoke", Label("smoke"), func() {
})

It("upgrades to a specific version", func() {
if os.Getenv("FLAVOR") == "alpine" {
Skip("not working on alpine yet")
}
version, _ := machine.SSHCommand("source /etc/os-release; echo $VERSION")

out, _ := machine.SSHCommand("sudo c3os upgrade v1.21.4-32")
Expand Down
53 changes: 52 additions & 1 deletion tests/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package machine
import (
"context"
"fmt"
"net"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -164,7 +165,7 @@ func connectToHost() (*ssh.Client, *ssh.Session, error) {

sshConfig.HostKeyCallback = ssh.InsecureIgnoreHostKey()

client, err := ssh.Dial("tcp", host(), sshConfig)
client, err := SSHDialTimeout("tcp", host(), sshConfig, 30*time.Second)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -283,3 +284,53 @@ func GatherLog(logPath string) {
fmt.Printf("File %s copied!\n", baseName)

}

type Conn struct {
net.Conn
ReadTimeout time.Duration
WriteTimeout time.Duration
}

func (c *Conn) Read(b []byte) (int, error) {
err := c.Conn.SetReadDeadline(time.Now().Add(c.ReadTimeout))
if err != nil {
return 0, err
}
return c.Conn.Read(b)
}

func (c *Conn) Write(b []byte) (int, error) {
err := c.Conn.SetWriteDeadline(time.Now().Add(c.WriteTimeout))
if err != nil {
return 0, err
}
return c.Conn.Write(b)
}

func SSHDialTimeout(network, addr string, config *ssh.ClientConfig, timeout time.Duration) (*ssh.Client, error) {
conn, err := net.DialTimeout(network, addr, timeout)
if err != nil {
return nil, err
}

timeoutConn := &Conn{conn, timeout, timeout}
c, chans, reqs, err := ssh.NewClientConn(timeoutConn, addr, config)
if err != nil {
return nil, err
}
client := ssh.NewClient(c, chans, reqs)

// this sends keepalive packets every 2 seconds
// there's no useful response from these, so we can just abort if there's an error
go func() {
t := time.NewTicker(2 * time.Second)
defer t.Stop()
for range t.C {
_, _, err := client.Conn.SendRequest("keepalive@golang.org", true, nil)
if err != nil {
return
}
}
}()
return client, nil
}
Loading

0 comments on commit c14a500

Please sign in to comment.