Skip to content

Commit

Permalink
Fetch Ironic node list after each e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: Huy Mai <huy.mai@est.tech>
  • Loading branch information
mquhuy committed Nov 1, 2024
1 parent 8a6d953 commit 1b1b654
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 8 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
59 changes: 58 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,63 @@ 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.GetVariable("FETCH_IRONIC_NODES") != "false" {
dumpIronicNodes(ctx, e2eConfig, 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
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

0 comments on commit 1b1b654

Please sign in to comment.