-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PRODENG-2563 Initial integration test for Mcc (#449)
Signed-off-by: Dimitar Dimitrov <[email protected]>
- Loading branch information
Showing
2 changed files
with
121 additions
and
0 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 |
---|---|---|
@@ -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) | ||
} |