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 8c2b0b6
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 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
25 changes: 25 additions & 0 deletions test/createVM/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Support FROM override
ARG BUILD_IMAGE=docker.io/golang:1.22.8@sha256:b274ff14d8eb9309b61b1a45333bf0559a554ebcf6732fa2012dbed9b01ea56f
ARG BASE_IMAGE=gcr.io/distroless/static:nonroot@sha256:9ecc53c269509f63c69a266168e4a687c7eb8c0cfd753bd8bfcaa4f58a90876f

# Build the manager binary
FROM $BUILD_IMAGE AS builder

WORKDIR /workspace

# Bring in the go dependencies before anything else so we can take
# advantage of caching these layers in future builds.
COPY go.mod go.sum ./
RUN go mod download

COPY . .
RUN CGO_ENABLED=0 GO111MODULE=on go build -a -o createVM main.go

# Copy the controller-manager into a thin image
# BMO has a dependency preventing us to use the static one,
# using the base one instead
FROM $BASE_IMAGE
WORKDIR /
COPY --from=builder /workspace/createVM .
USER nonroot:nonroot
ENTRYPOINT ["/createVM"]
77 changes: 77 additions & 0 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ package e2e
import (
"bytes"
"context"
"crypto/tls"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -507,4 +512,76 @@ func DumpResources(ctx context.Context, clusterProxy framework.ClusterProxy, nam
LogPath: filepath.Join(artifactFolder, "clusters", clusterProxy.GetName(), "resources"),
})
dumpCRDS(ctx, clusterProxy.GetClient(), filepath.Join(artifactFolder, "crd"))
DumpIronicNodes(artifactFolder)
// if err != nil {

Check failure on line 516 in test/e2e/common.go

View workflow job for this annotation

GitHub Actions / golangci-lint / lint (test)

commentedOutCode: may want to remove commented-out code (gocritic)

Check failure on line 516 in test/e2e/common.go

View workflow job for this annotation

GitHub Actions / golangci-lint / lint (test)

commentedOutCode: may want to remove commented-out code (gocritic)
// Logf("ERROR: %v", err)
// }
}

func DumpIronicNodes(artifactFolder string) {
ironicProvisioningIp, exists := os.LookupEnv("IRONIC_PROVISIONING_IP")

Check failure on line 522 in test/e2e/common.go

View workflow job for this annotation

GitHub Actions / golangci-lint / lint (test)

var-naming: var ironicProvisioningIp should be ironicProvisioningIP (revive)

Check failure on line 522 in test/e2e/common.go

View workflow job for this annotation

GitHub Actions / golangci-lint / lint (test)

var-naming: var ironicProvisioningIp should be ironicProvisioningIP (revive)
if !exists {
fmt.Println("Running fixture tests, skip fetching ironic nodes.")
return
}
ironicURL := fmt.Sprintf("https://%s:6385/v1/nodes", ironicProvisioningIp)

Check failure on line 527 in test/e2e/common.go

View workflow job for this annotation

GitHub Actions / golangci-lint / lint (test)

host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf (nosprintfhostport)

Check failure on line 527 in test/e2e/common.go

View workflow job for this annotation

GitHub Actions / golangci-lint / lint (test)

host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf (nosprintfhostport)
username := os.Getenv("IRONIC_USERNAME")
password := os.Getenv("IRONIC_PASSWORD")

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

// Create the request
req, err := http.NewRequest("GET", ironicURL, nil)

Check failure on line 540 in test/e2e/common.go

View workflow job for this annotation

GitHub Actions / golangci-lint / lint (test)

httpNoBody: http.NoBody should be preferred to the nil request body (gocritic)

Check failure on line 540 in test/e2e/common.go

View workflow job for this annotation

GitHub Actions / golangci-lint / lint (test)

httpNoBody: http.NoBody should be preferred to the nil request body (gocritic)
if err != nil {
fmt.Println("Failed to create request:", err)
return
}

// 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)
if err != nil {
fmt.Println("Failed to send request:", err)
return
}
defer resp.Body.Close()

// Read and output the response
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Failed to read response body:", err)
return
}
fmt.Println("Response status:", resp.Status)
var logOutput bytes.Buffer

// Format the JSON with indentation
err = json.Indent(&logOutput, body, "", " ")
if err != nil {
fmt.Println("Error formatting JSON:", err)
return
}

file, err := os.Create(path.Join(artifactFolder, "ironic-nodes.json"))
if err != nil {
fmt.Println("Error creating file:", err)
return
}
defer file.Close()

// Write indented JSON to file
_, err = file.Write(logOutput.Bytes())
if err != nil {
fmt.Println("Error writing JSON to file:", err)
return
}
}

0 comments on commit 8c2b0b6

Please sign in to comment.