Skip to content

Commit

Permalink
chore(ci): manager systemd integration tests (#1724)
Browse files Browse the repository at this point in the history
* chore(ci): manager integration tests

* f

* f

* f

* f
  • Loading branch information
emosbaugh authored Jan 21, 2025
1 parent ccc7fcd commit 3250267
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 10 deletions.
27 changes: 26 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ jobs:
int-tests:
name: Integration tests
runs-on: ubuntu-latest
needs:
- int-tests-kind
- int-tests-manager
steps:
- name: Succeed if all tests passed
run: echo "Integration tests succeeded"

int-tests-kind:
name: Integration tests (kind)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -77,7 +87,22 @@ jobs:
sudo mv ./kind /usr/local/bin/kind
- name: Run tests
run: |
make -C tests/integration test
make -C tests/integration test-kind
int-tests-manager:
name: Integration tests (manager)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache-dependency-path: "**/*.sum"
- name: Run tests
run: |
make -C tests/integration test-manager
dryrun-tests:
name: Dryrun tests
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ preflightbundle*

hack/release.tgz
hack/release

# Test binary, built with `go test -c`
*.test
16 changes: 8 additions & 8 deletions tests/integration/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ PARALLEL ?= 2
RUN ?=

.PHONY: test
test: test-openebs
test: test-kind test-manager

.PHONY: test-openebs
test-openebs:
DEBUG=$(DEBUG) go test -v -tags exclude_graphdriver_btrfs \
-timeout=5m \
-parallel=$(PARALLEL) \
-run='$(value RUN)' \
./openebs/...
.PHONY: test-kind
test-kind:
$(MAKE) -C ./kind test

.PHONY: test-manager
test-manager:
$(MAKE) -C ./manager clean build test
16 changes: 16 additions & 0 deletions tests/integration/kind/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SHELL := /bin/bash

DEBUG ?=
PARALLEL ?= 2
RUN ?=

.PHONY: test
test: test-openebs

.PHONY: test-openebs
test-openebs:
DEBUG=$(DEBUG) go test -v -tags exclude_graphdriver_btrfs \
-timeout=5m \
-parallel=$(PARALLEL) \
-run='$(value RUN)' \
./openebs/...
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/replicatedhq/embedded-cluster/tests/integration/openebs/static"
"github.com/replicatedhq/embedded-cluster/tests/integration/kind/openebs/static"
"github.com/replicatedhq/embedded-cluster/tests/integration/util"
)

Expand Down
File renamed without changes.
41 changes: 41 additions & 0 deletions tests/integration/manager/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
SHELL := /bin/bash

DEBUG ?=
RUN ?=

CONTAINER_NAME = integration-test-manager

.PHONY: test
test: DISTRO = debian-bookworm
test:
@-docker rm -f $(CONTAINER_NAME) 2>/dev/null ; true
@docker run -d \
--name $(CONTAINER_NAME) \
--privileged \
--restart=unless-stopped \
-v $(shell pwd)/manager.test:/wrk/manager.test \
-v $(shell pwd)/../../../pkg/goods/bins/manager:/wrk/bin/manager \
-e DATA_DIR=/wrk \
replicated/ec-distro:$(DISTRO)
@sleep 5 # wait for container to be ready
docker exec \
-e DEBUG=$(DEBUG) \
$(CONTAINER_NAME) \
/wrk/manager.test \
-test.v \
-test.timeout=5m \
-test.run='$(value RUN)'

.PHONY: clean
clean:
rm -f manager.test
-docker rm -f $(CONTAINER_NAME) 2>/dev/null ; true

.PHONY: build
build: manager.test ../../../pkg/goods/bins/manager

manager.test:
GOOS=linux go test -c .

../../../pkg/goods/bins/manager:
$(MAKE) -C ../../../ pkg/goods/bins/manager
76 changes: 76 additions & 0 deletions tests/integration/manager/install_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package manager

import (
"context"
"os"
"os/exec"
"testing"
"time"

"github.com/replicatedhq/embedded-cluster/pkg/manager"
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestManagerInstall(t *testing.T) {
ctx := context.Background()

runtimeconfig.SetDataDir(getDataDir(t))

manager.SetServiceName("ec")
err := manager.Install(ctx, t.Logf)
require.NoError(t, err, "failed to install manager")

// Verify service files exists
serviceFileExists := checkFileExists(t, "/etc/systemd/system/ec-manager.service")
assert.True(t, serviceFileExists, "ec-manager.service file should exist")
dropInDirExists := checkFileExists(t, "/etc/systemd/system/ec-manager.service.d")
assert.True(t, dropInDirExists, "ec-manager.service.d drop-in directory should exist")

// Wait for service to start and become ready
// TODO: this should be added to the manager package
time.Sleep(5 * time.Second)

// Verify service is enabled and running
status := getServiceStatus(t, "ec-manager.service")
assert.Contains(t, status, "enabled", "service should be enabled")
assert.Contains(t, status, "active (running)", "service should be running")

err = manager.Uninstall(ctx, t.Logf)
require.NoError(t, err, "failed to uninstall manager")

// Verify service files do not exist
serviceFileExists = checkFileNotExists(t, "/etc/systemd/system/ec-manager.service")
assert.True(t, serviceFileExists, "ec-manager.service file should not exist")
dropInDirExists = checkFileNotExists(t, "/etc/systemd/system/ec-manager.service.d")
assert.True(t, dropInDirExists, "ec-manager.service.d drop-in directory should not exist")

// Verify service is disabled and not running
status = getServiceStatus(t, "ec-manager.service")
assert.Contains(t, status, "could not be found", "service should be removed")
}

func getDataDir(t *testing.T) string {
dataDir := os.Getenv("DATA_DIR")
if dataDir == "" {
t.Fatal("DATA_DIR must be set")
}
return dataDir
}

func checkFileExists(t *testing.T, path string) bool {
err := exec.Command("test", "-e", path).Run()
return err == nil
}

func checkFileNotExists(t *testing.T, path string) bool {
err := exec.Command("test", "-e", path).Run()
return err != nil
}

func getServiceStatus(t *testing.T, service string) string {
cmd := exec.Command("systemctl", "status", service)
output, _ := cmd.CombinedOutput()
return string(output)
}
Binary file added tests/integration/manager/manager.test
Binary file not shown.

0 comments on commit 3250267

Please sign in to comment.