Skip to content

Commit

Permalink
Merge pull request #2028 from Nordix/mquhuy/fetch-ironic-nodes
Browse files Browse the repository at this point in the history
🌱  Fetch Ironic node list after each e2e test
  • Loading branch information
metal3-io-bot authored Nov 4, 2024
2 parents e57389b + ad35224 commit 2b1fb3d
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 12 deletions.
4 changes: 4 additions & 0 deletions hack/ci-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ rm /tmp/bmo-e2e.tar
# This IP is defined by the network we created above.
IP_ADDRESS="192.168.222.1"

# This IP is also defined by the network above, and is used consistently in all of
# our e2e overlays
export IRONIC_PROVISIONING_IP="192.168.222.199"

pushd "${REPO_ROOT}/test/createVM" || exit 1
go run main.go --yaml-source-file "${E2E_BMCS_CONF_FILE}"
popd
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/basic_ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ var _ = Describe("basic", Label("required", "basic"), func() {
})

AfterEach(func() {
DumpResources(ctx, clusterProxy, namespace.Name, path.Join(artifactFolder, specName))
DumpResources(ctx, e2eConfig, clusterProxy, namespace.Name, path.Join(artifactFolder, specName))
if !skipCleanup {
cleanup(ctx, clusterProxy, namespace, cancelWatches, e2eConfig.GetIntervals("default", "wait-namespace-deleted")...)
}
Expand Down
60 changes: 59 additions & 1 deletion test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ package e2e
import (
"bytes"
"context"
"crypto/tls"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net"
"net/http"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -499,12 +505,64 @@ func dumpCRDS(ctx context.Context, cli client.Client, artifactFolder string) {
}

// DumpResources dumps resources related to BMO e2e tests as YAML.
func DumpResources(ctx context.Context, clusterProxy framework.ClusterProxy, namespace string, artifactFolder string) {
func DumpResources(ctx context.Context, e2eConfig *Config, clusterProxy framework.ClusterProxy, namespace string, artifactFolder string) {
// CAPI resources.
framework.DumpAllResources(ctx, framework.DumpAllResourcesInput{
Lister: clusterProxy.GetClient(),
Namespace: namespace,
LogPath: filepath.Join(artifactFolder, "clusters", clusterProxy.GetName(), "resources"),
})
dumpCRDS(ctx, clusterProxy.GetClient(), filepath.Join(artifactFolder, "crd"))
if e2eConfig.GetBoolVariable("FETCH_IRONIC_NODES") {
dumpIronicNodes(ctx, e2eConfig, artifactFolder)
}
}

// dumpIronicNodes dumps the nodes in ironic's view into json file inside the provided artifactFolder.
func dumpIronicNodes(ctx context.Context, e2eConfig *Config, artifactFolder string) {
ironicProvisioningIP := e2eConfig.GetVariable("IRONIC_PROVISIONING_IP")
ironicProvisioningPort := e2eConfig.GetVariable("IRONIC_PROVISIONING_PORT")
ironicURL := fmt.Sprintf("https://%s/v1/nodes", net.JoinHostPort(ironicProvisioningIP, ironicProvisioningPort))
username := e2eConfig.GetVariable("IRONIC_USERNAME")
password := e2eConfig.GetVariable("IRONIC_PASSWORD")

// Create HTTP client with TLS settings
tlsConfig := &tls.Config{
InsecureSkipVerify: true, // #nosec G402 Skip verification as we are using self-signed certificates
}
client := &http.Client{
Transport: &http.Transport{TLSClientConfig: tlsConfig},
}

// Create the request
req, err := http.NewRequestWithContext(ctx, http.MethodGet, ironicURL, http.NoBody)
Expect(err).ToNot(HaveOccurred(), "Failed to create request")

// Set basic auth header
auth := base64.StdEncoding.EncodeToString([]byte(username + ":" + password))
req.Header.Add("Authorization", "Basic "+auth)

// Make the request
resp, err := client.Do(req)
Expect(err).ToNot(HaveOccurred(), "Failed to send request")
Expect(resp.StatusCode).To(Equal(http.StatusOK), fmt.Sprintf("Unexpected Status Code: %d", resp.StatusCode))

defer resp.Body.Close()
// Read and output the response
body, err := io.ReadAll(resp.Body)
Expect(err).ToNot(HaveOccurred(), "Failed to read response body")

var logOutput bytes.Buffer

// Format the JSON with indentation
err = json.Indent(&logOutput, body, "", " ")
Expect(err).ToNot(HaveOccurred(), "Error formatting JSON")

file, err := os.Create(path.Join(artifactFolder, "ironic-nodes.json"))
Expect(err).ToNot(HaveOccurred(), "Error creating file")
defer file.Close()

// Write indented JSON to file
_, err = file.Write(logOutput.Bytes())
Expect(err).ToNot(HaveOccurred(), "Error writing JSON to file")
}
1 change: 1 addition & 0 deletions test/e2e/config/fixture.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ variables:
IMAGE_CHECKSUM: "c8fc807773e5354afe61636071771906"
CERT_MANAGER_VERSION: "v1.13.1"
SSH_CHECK_PROVISIONED: "false"
FETCH_IRONIC_NODES: "false"

intervals:
inspection/wait-unmanaged: ["1m", "10ms"]
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/config/ironic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ variables:
SSH_USERNAME: "root"
SSH_PRIV_KEY: "./images/ssh_testkey"
SSH_PUB_KEY: "./images/ssh_testkey.pub"
FETCH_IRONIC_NODES: "true"
IRONIC_USERNAME: "changeme"
IRONIC_PASSWORD: "changeme"
IRONIC_PROVISIONING_IP: "localhost"
IRONIC_PROVISIONING_PORT: "6385"

intervals:
inspection/wait-unmanaged: ["1m", "5s"]
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/e2e_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,15 @@ func (c *Config) GetVariable(varName string) string {
Expect(ok).To(BeTrue(), fmt.Sprintf("Configuration variable '%s' not found", varName))
return value
}

// GetBoolVariable returns a variable from environment variables or from the e2e config file as boolean.
func (c *Config) GetBoolVariable(varName string) bool {
value := c.GetVariable(varName)
falseValues := []string{"", "false", "no"}
for _, falseVal := range falseValues {
if strings.EqualFold(value, falseVal) {
return false
}
}
return true
}
6 changes: 3 additions & 3 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {

os.Setenv("KUBECONFIG", clusterProxy.GetKubeconfigPath())

if e2eConfig.GetVariable("DEPLOY_CERT_MANAGER") != "false" {
if e2eConfig.GetBoolVariable("DEPLOY_CERT_MANAGER") {
// Install cert-manager
By("Installing cert-manager")
err := checkCertManagerAPI(clusterProxy)
Expand All @@ -122,7 +122,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {

bmoIronicNamespace := "baremetal-operator-system"

if e2eConfig.GetVariable("DEPLOY_IRONIC") != "false" {
if e2eConfig.GetBoolVariable("DEPLOY_IRONIC") {
// Install Ironic
By("Installing Ironic")
err := FlakeAttempt(2, func() error {
Expand All @@ -140,7 +140,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {
Expect(err).NotTo(HaveOccurred())
}

if e2eConfig.GetVariable("DEPLOY_BMO") != "false" {
if e2eConfig.GetBoolVariable("DEPLOY_BMO") {
// Install BMO
By("Installing BMO")
err := FlakeAttempt(2, func() error {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/external_inspection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ var _ = Describe("External Inspection", Label("required", "external-inspection")
})

AfterEach(func() {
DumpResources(ctx, clusterProxy, namespace.Name, path.Join(artifactFolder, specName))
DumpResources(ctx, e2eConfig, clusterProxy, namespace.Name, path.Join(artifactFolder, specName))
if !skipCleanup {
cleanup(ctx, clusterProxy, namespace, cancelWatches, e2eConfig.GetIntervals("default", "wait-namespace-deleted")...)
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/inspection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ var _ = Describe("Inspection", Label("required", "inspection"), func() {
})

AfterEach(func() {
DumpResources(ctx, clusterProxy, namespace.Name, path.Join(artifactFolder, specName))
DumpResources(ctx, e2eConfig, clusterProxy, namespace.Name, path.Join(artifactFolder, specName))
if !skipCleanup {
cleanup(ctx, clusterProxy, namespace, cancelWatches, e2eConfig.GetIntervals("default", "wait-namespace-deleted")...)
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/live_iso_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ var _ = Describe("Live-ISO", Label("required", "live-iso"), func() {
})

AfterEach(func() {
DumpResources(ctx, clusterProxy, namespace.Name, path.Join(artifactFolder, specName))
DumpResources(ctx, e2eConfig, clusterProxy, namespace.Name, path.Join(artifactFolder, specName))
if !skipCleanup {
cleanup(ctx, clusterProxy, namespace, cancelWatches, e2eConfig.GetIntervals("default", "wait-namespace-deleted")...)
}
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/provisioning_and_annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,10 @@ var _ = Describe("Provision, detach, recreate from status and deprovision", Labe
Bmh: bmh,
State: metal3api.StateAvailable,
}, e2eConfig.GetIntervals(specName, "wait-available")...)

})

AfterEach(func() {
DumpResources(ctx, clusterProxy, namespace.Name, path.Join(artifactFolder, specName))
DumpResources(ctx, e2eConfig, clusterProxy, namespace.Name, path.Join(artifactFolder, specName))
if !skipCleanup {
cleanup(ctx, clusterProxy, namespace, cancelWatches, e2eConfig.GetIntervals("default", "wait-namespace-deleted")...)
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/re_inspection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ var _ = Describe("Re-Inspection", Label("required", "re-inspection"), func() {
})

AfterEach(func() {
DumpResources(ctx, clusterProxy, namespace.Name, path.Join(artifactFolder, specName))
DumpResources(ctx, e2eConfig, clusterProxy, namespace.Name, path.Join(artifactFolder, specName))
if !skipCleanup {
cleanup(ctx, clusterProxy, namespace, cancelWatches, e2eConfig.GetIntervals("default", "wait-namespace-deleted")...)
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ var _ = Describe("Upgrade", Label("optional", "upgrade"), func() {
upgradeClusterProxy.Dispose(ctx)
})

if e2eConfig.GetVariable("UPGRADE_DEPLOY_CERT_MANAGER") != "false" {
if e2eConfig.GetBoolVariable("UPGRADE_DEPLOY_CERT_MANAGER") {
By("Installing cert-manager on the upgrade cluster")
cmVersion := e2eConfig.GetVariable("CERT_MANAGER_VERSION")
err := installCertManager(ctx, upgradeClusterProxy, cmVersion)
Expand Down

0 comments on commit 2b1fb3d

Please sign in to comment.