-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci): manager systemd integration tests (#1724)
* chore(ci): manager integration tests * f * f * f * f
- Loading branch information
Showing
12 changed files
with
171 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,6 @@ preflightbundle* | |
|
||
hack/release.tgz | ||
hack/release | ||
|
||
# Test binary, built with `go test -c` | ||
*.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.