Skip to content

Commit

Permalink
PRODENG-2563 Initial integration test for Mcc (#449)
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Dimitrov <[email protected]>
  • Loading branch information
cranzy authored Mar 14, 2024
1 parent 30c368a commit 8d89387
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ lint:
unit-test:
$(GO) test -v ./pkg/...

.PHONY: integration-test
integration-test:
go test -v ./test/integration/... -timeout 20m

.PHONY: smoke-small
smoke-small:
go test -v ./test/smoke/... -run TestSmallCluster -timeout 20m
Expand Down
117 changes: 117 additions & 0 deletions test/integration/integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package integration_test

import (
"encoding/json"
"fmt"
"log"
"os"
"path"
"testing"

"github.com/Mirantis/mcc/pkg/config"
"github.com/Mirantis/mcc/pkg/constant"
"github.com/Mirantis/mcc/pkg/mke"
"github.com/Mirantis/mcc/test"
"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/mitchellh/go-homedir"
"github.com/stretchr/testify/assert"
)

var AWS = map[string]interface{}{
"region": "eu-central-1",
}

var MKE_CONNECT = map[string]interface{}{
"username": "admin",
"password": "",
"insecure": false,
}

var LAUNCHPAD = map[string]interface{}{
"drain": false,
"mcr_version": "23.0.8",
"mke_version": "3.7.3",
"msr_version": "",
"mke_connect": MKE_CONNECT,
}

// configure the network stack
var NETWORK = map[string]interface{}{
"cidr": "172.31.0.0/16",
"public_subnet_count": 3,
"private_subnet_count": 0, // if 0 then no private nodegroups allowed
}

func TestMKEClientConfig(t *testing.T) {
log.Println("TestMKEClientConfig")
nodegroups := map[string]interface{}{
"MngrUbuntu22": test.Platforms["Ubuntu22"].GetManager(),
"WrkRhel9": test.Platforms["Ubuntu22"].GetWorker(),
}

uTestId := test.GenerateRandomAlphaNumericString(5)

name := fmt.Sprintf("smoke-%s", uTestId)

rndPassword := test.GenerateRandomAlphaNumericString(12)

MKE_CONNECT["password"] = rndPassword

// Create a temporary directory to store Terraform files
tempSSHKeyPathDir := t.TempDir()

options := terraform.Options{
// The path to where the Terraform tf chart is located
TerraformDir: "../../examples/tf-aws/launchpad",
Vars: map[string]interface{}{
"name": name,
"aws": AWS,
"launchpad": LAUNCHPAD,
"network": NETWORK,
"ssh_pk_location": tempSSHKeyPathDir,
"nodegroups": nodegroups,
},
}

terraformOptions := terraform.WithDefaultRetryableErrors(t, &options)
// Run `terraform init` and `terraform apply`. Fail the test if there are any errors.
if _, err := terraform.InitAndApplyE(t, terraformOptions); err != nil {
t.Fatal(err)
}

// Destroy the Terraform resources at the end of the test
defer terraform.Destroy(t, terraformOptions)
mkeClusterConfig := terraform.Output(t, terraformOptions, "launchpad_yaml")

product, err := config.ProductFromYAML([]byte(mkeClusterConfig))
assert.NoError(t, err)

// Do Launchpad Apply as pre-requisite to the tests
err = product.Apply(true, true, 3, true)
assert.NoError(t, err)

err = product.ClientConfig()
assert.NoError(t, err)

home, err := homedir.Dir()
assert.NoError(t, err)

mkeConnectOut := terraform.OutputJson(t, terraformOptions, "mke_connect")

product.ClientConfig()
var m struct {
mke.Credentials
Host string
Insecure bool
}

err = json.Unmarshal([]byte(mkeConnectOut), &m)
assert.NoError(t, err)

bundlePath := path.Join(home, constant.StateBaseDir, "cluster", product.ClusterName(), "bundle", m.Username)
_, err = os.Stat(bundlePath)
assert.NoError(t, err)

err = os.RemoveAll(bundlePath)
assert.NoError(t, err)
}

0 comments on commit 8d89387

Please sign in to comment.