Skip to content

Commit

Permalink
[ATMOSPHERE-533] ci: update go unit tests (#1983)
Browse files Browse the repository at this point in the history
remove 1.22 from TestKubeconform test (node-feature-discovery uses grpc in probe which is available since 1.22)
add a workaround values in TestKubeconform for loki chart
skip CephFilesystemSubVolumeGroup kind for ceph chart
fix oslo_db test expected values
update TestImageExist test to support image tags without digest
fix pxc test codes
supplement placement chart value for database max_retries param

depends-on: #1977
depends-on: #1211
depends-on: #1987 #1211 #1977

Reviewed-by: Mohammed Naser <[email protected]>
Reviewed-by: Oleksandr K.
  • Loading branch information
okozachenko1203 authored Oct 30, 2024
1 parent fa5d244 commit 99651a6
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 30 deletions.
30 changes: 24 additions & 6 deletions charts/charts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

var (
KUBERNETES_VERSIONS = []string{
"1.22.0",
"1.23.0",
"1.24.0",
"1.25.0",
Expand Down Expand Up @@ -59,10 +58,11 @@ func TestKubeconform(t *testing.T) {
opts := validator.Opts{
KubernetesVersion: version,
SkipKinds: map[string]struct{}{
"CephBlockPool": {},
"CephCluster": {},
"CephFilesystem": {},
"CephObjectStore": {},
"CephBlockPool": {},
"CephCluster": {},
"CephFilesystem": {},
"CephObjectStore": {},
"CephFilesystemSubVolumeGroup": {},
"apiextensions.k8s.io/v1/CustomResourceDefinition": {},
},
Strict: true,
Expand All @@ -78,6 +78,9 @@ func TestKubeconform(t *testing.T) {
if !file.IsDir() {
continue
}
if file.Name() == "patches" {
continue
}

t.Run(file.Name(), func(t *testing.T) {
chart, err := loader.LoadDir(file.Name())
Expand All @@ -92,7 +95,22 @@ func TestKubeconform(t *testing.T) {

t.Parallel()

rel, err := client.Run(chart, map[string]interface{}{})
rel, err := client.Run(
chart,
// NOTE(okozachenko1203): loki helm chart default values doesn't work.
map[string]interface{}{
"loki": map[string]interface{}{
"storage": map[string]interface{}{
"bucketNames": map[string]string{
"chunks": "FIXME",
"ruler": "FIXME",
"admin": "FIXME",
},
},
"useTestSchema": true,
},
},
)
require.NoError(t, err)

manifests := io.NopCloser(strings.NewReader(rel.Manifest))
Expand Down
4 changes: 2 additions & 2 deletions internal/testutils/oslo_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestDatabaseConf(t *testing.T, config *openstack_helm.DatabaseConf) {
assert.Equal(t, 10, config.ConnectionRecycleTime)
assert.Equal(t, 1, config.MaxPoolSize)
assert.Equal(t, 600, config.ConnectionRecycleTime)
assert.Equal(t, 5, config.MaxPoolSize)
assert.Equal(t, -1, config.MaxRetries)
}
14 changes: 13 additions & 1 deletion roles/defaults/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package defaults
import (
"bytes"
_ "embed"
"strings"

"github.com/goccy/go-yaml"
)
Expand All @@ -12,14 +13,25 @@ var (
varsFile []byte
)

// Define a global variable for the release value.
var release = "main"

// Function to replace the {{ release }} placeholders
func replaceReleaseInYAML(yamlContent []byte, release string) []byte {
return []byte(strings.ReplaceAll(string(yamlContent), "{{ atmosphere_release }}", release))
}

func GetImages() (map[string]string, error) {
// Replace {{ release }} with the actual release value
modifiedVarsFile := replaceReleaseInYAML(varsFile, release)

path, err := yaml.PathString("$._atmosphere_images")
if err != nil {
return nil, err
}

var images map[string]string
if err := path.Read(bytes.NewReader(varsFile), &images); err != nil {
if err := path.Read(bytes.NewReader(modifiedVarsFile), &images); err != nil {
return nil, err
}

Expand Down
18 changes: 12 additions & 6 deletions roles/defaults/vars_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,22 @@ func TestImageExist(t *testing.T) {
// NOTE(mnaser): ParseReference does not allow both tag & digest,
// so we strip the tags from the image name.
nameWithTagSplit := strings.Split(image, "@")
require.Len(t, nameWithTagSplit, 2)
// NOTE(okozachenko1203): We'll enable this again when use image digest.
// require.Len(t, nameWithTagSplit, 2)
nameWithTag := nameWithTagSplit[0]
name := strings.Split(nameWithTag, ":")[0]
digest := strings.Split(image, "@")[1]
image := fmt.Sprintf("%s@%s", name, digest)
var imageRef string
if len(nameWithTagSplit) == 2 {
name := strings.Split(nameWithTag, ":")[0]
digest := strings.Split(image, "@")[1]
imageRef = fmt.Sprintf("%s@%s", name, digest)
} else {
imageRef = nameWithTag
}

t.Run(image, func(t *testing.T) {
t.Run(imageRef, func(t *testing.T) {
t.Parallel()

ref, err := docker.ParseReference(fmt.Sprintf("//%s", image))
ref, err := docker.ParseReference(fmt.Sprintf("//%s", imageRef))
require.NoError(t, err)

ctx := context.Background()
Expand Down
20 changes: 5 additions & 15 deletions roles/percona_xtradb_cluster/vars_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestPerconaXtraDBClusterSpec(t *testing.T) {
func TestPerconaXtraDBClusterPXCSpec(t *testing.T) {
assert.Equal(t, int32(3), vars.PerconaXtraDBClusterSpec.PXC.Size)
assert.Equal(t, true, *vars.PerconaXtraDBClusterSpec.PXC.AutoRecovery)
defaults.AssertAtmosphereImage(t, "docker.io/percona/percona-xtradb-cluster:8.0.32-24.2@sha256:1f978ab8912e1b5fc66570529cb7e7a4ec6a38adbfce1ece78159b0fcfa7d47a", vars.PerconaXtraDBClusterSpec.PXC.Image)
defaults.AssertAtmosphereImage(t, "docker.io/percona/percona-xtradb-cluster:8.0.36-28.1", vars.PerconaXtraDBClusterSpec.PXC.Image)

assert.Equal(t, map[string]string{
"openstack-control-plane": "enabled",
Expand Down Expand Up @@ -92,10 +92,10 @@ func TestPerconaXtraDBClusterPXCConfiguration(t *testing.T) {
func TestPerconaXtraDBClusterPXCSidecarSpec(t *testing.T) {
sidecar := vars.PerconaXtraDBClusterSpec.PXC.Sidecars[0]
assert.Equal(t, "exporter", sidecar.Name)
defaults.AssertAtmosphereImage(t, "quay.io/prometheus/mysqld-exporter:v0.14.0@sha256:eb6fe170738bf9181c51f5bc89f93adb26672ec49ffdcb22f55c24834003b45d", sidecar.Image)
defaults.AssertAtmosphereImage(t, "quay.io/prometheus/mysqld-exporter:v0.15.1", sidecar.Image)

assert.Equal(t, v1.EnvVar{
Name: "MONITOR_PASSWORD",
Name: "MYSQLD_EXPORTER_PASSWORD",
ValueFrom: &v1.EnvVarSource{
SecretKeyRef: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Expand All @@ -105,10 +105,6 @@ func TestPerconaXtraDBClusterPXCSidecarSpec(t *testing.T) {
},
},
}, sidecar.Env[0])
assert.Equal(t, v1.EnvVar{
Name: "DATA_SOURCE_NAME",
Value: "monitor:$(MONITOR_PASSWORD)@(localhost:3306)/",
}, sidecar.Env[1])

assert.Equal(t, v1.ContainerPort{
Name: "metrics",
Expand All @@ -120,11 +116,8 @@ func TestPerconaXtraDBClusterHAProxySpec(t *testing.T) {
assert.Equal(t, true, vars.PerconaXtraDBClusterSpec.HAProxy.Enabled)
assert.Equal(t, int32(3), vars.PerconaXtraDBClusterSpec.HAProxy.Size)

chart, err := loader.LoadDir("../../charts/pxc-operator")
require.NoError(t, err)

defaults.AssertAtmosphereImage(t,
fmt.Sprintf("docker.io/percona/percona-xtradb-cluster-operator:%s-haproxy@sha256:f04e4fea548bfc7cb0bfc73c75c7f2c64d299cf04125a07a8101a55f0f734fed", chart.AppVersion()),
fmt.Sprintf("docker.io/percona/percona-xtradb-cluster-operator:%s-haproxy", vars.PerconaXtraDBClusterSpec.CRVersion),
vars.PerconaXtraDBClusterSpec.HAProxy.Image,
)

Expand All @@ -134,9 +127,6 @@ func TestPerconaXtraDBClusterHAProxySpec(t *testing.T) {
}

func TestPerconaXtraDBClusterHAProxyConfiguration(t *testing.T) {
chart, err := loader.LoadDir("../../charts/pxc-operator")
require.NoError(t, err)

pxcConfig := parsePXCConfiguration(t, vars.PerconaXtraDBClusterSpec.PXC.Configuration)
maxConnections := pxcConfig.Section("mysqld").Key("max_connections").MustInt()

Expand All @@ -145,7 +135,7 @@ func TestPerconaXtraDBClusterHAProxyConfiguration(t *testing.T) {
// then compare it.

// Get the default HAproxy configuration
configFileUrl := fmt.Sprintf("https://raw.githubusercontent.com/percona/percona-docker/pxc-operator-%s/haproxy/dockerdir/etc/haproxy/haproxy-global.cfg", chart.AppVersion())
configFileUrl := fmt.Sprintf("https://raw.githubusercontent.com/percona/percona-docker/pxc-operator-%s/haproxy/dockerdir/etc/haproxy/haproxy-global.cfg", vars.PerconaXtraDBClusterSpec.CRVersion)
resp, err := http.Get(configFileUrl)
require.NoError(t, err)
defer resp.Body.Close()
Expand Down
1 change: 1 addition & 0 deletions roles/placement/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ _placement_helm_values:
connection_recycle_time: 600
max_overflow: 50
max_pool_size: 5
max_retries: -1
pool_timeout: 30
oslo_messaging_notifications:
driver: noop
Expand Down
13 changes: 13 additions & 0 deletions zuul.d/jobs.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
- job:
name: atmosphere-golang-go
parent: golang-go
abstract: true
vars:
go_version: 1.21.13

- job:
name: atmosphere-golang-go-test
parent: atmosphere-golang-go
vars:
go_command: test ./... -v

- job:
name: atmosphere-chart-vendor
parent: chart-vendor
Expand Down
2 changes: 2 additions & 0 deletions zuul.d/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
check:
jobs:
- atmosphere-chart-vendor
- atmosphere-golang-go-test
- atmosphere-linters
- atmosphere-tox-promtool-test
- atmosphere-tox-py3
Expand Down Expand Up @@ -87,6 +88,7 @@
gate:
jobs:
- atmosphere-chart-vendor
- atmosphere-golang-go-test
- atmosphere-linters
- atmosphere-tox-py3
- atmosphere-build-collection:
Expand Down

0 comments on commit 99651a6

Please sign in to comment.