diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 15a5a5df0..9a7915bc2 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -16,7 +16,7 @@ runs: - name: Set up Go 1.21 uses: actions/setup-go@v4 with: - go-version: 1.21.3 + go-version: 1.21.4 - name: Disable default go problem matcher run: echo "::remove-matcher owner=go::" diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index a1b09044a..83a70f93c 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -45,7 +45,7 @@ jobs: - name: Set up Go 1.21 uses: actions/setup-go@v4 with: - go-version: 1.21.3 + go-version: 1.21.4 - name: Install ginkgo run: make install-tools diff --git a/.github/workflows/merge.yaml b/.github/workflows/merge.yaml index 5649900a0..64855646f 100644 --- a/.github/workflows/merge.yaml +++ b/.github/workflows/merge.yaml @@ -24,7 +24,7 @@ jobs: - name: Set up Go 1.21 uses: actions/setup-go@v4 with: - go-version: 1.21.3 + go-version: 1.21.4 - name: Check out code into the Go module directory uses: actions/checkout@v4 diff --git a/.github/workflows/pre-main.yaml b/.github/workflows/pre-main.yaml index 0cf1831a0..0cd044974 100644 --- a/.github/workflows/pre-main.yaml +++ b/.github/workflows/pre-main.yaml @@ -41,7 +41,7 @@ jobs: - name: Set up Go 1.21 uses: actions/setup-go@v4 with: - go-version: 1.21.3 + go-version: 1.21.4 - name: Disable default go problem matcher run: echo "::remove-matcher owner=go::" @@ -113,7 +113,7 @@ jobs: - name: Set up Go 1.21 uses: actions/setup-go@v4 with: - go-version: 1.21.3 + go-version: 1.21.4 - name: Disable default go problem matcher run: echo "::remove-matcher owner=go::" @@ -179,7 +179,7 @@ jobs: - name: Set up Go 1.21 uses: actions/setup-go@v4 with: - go-version: 1.21.3 + go-version: 1.21.4 - name: Disable default go problem matcher run: echo "::remove-matcher owner=go::" @@ -334,7 +334,7 @@ jobs: - name: Set up Go 1.21 uses: actions/setup-go@v4 with: - go-version: 1.21.3 + go-version: 1.21.4 @@ -386,12 +386,12 @@ jobs: run: TNF_LOG_LEVEL=${TNF_SMOKE_TESTS_LOG_LEVEL} ./run-tnf-container.sh ${{ env.TESTING_CMD_PARAMS }} - name: 'Test: Run Smoke Tests in a TNF container' - run: TNF_LOG_LEVEL=${TNF_SMOKE_TESTS_LOG_LEVEL} TNF_ENABLE_DATA_COLLECTION=true ./run-tnf-container.sh ${{ env.TESTING_CMD_PARAMS }} -l "${SMOKE_TESTS_GINKGO_LABELS_FILTER}" + run: TNF_LOG_LEVEL=${TNF_SMOKE_TESTS_LOG_LEVEL} TNF_ENABLE_DATA_COLLECTION=false ./run-tnf-container.sh ${{ env.TESTING_CMD_PARAMS }} -l "${SMOKE_TESTS_GINKGO_LABELS_FILTER}" - - name: Run sanity check on collector - uses: ./collector/.github/actions/run-sanity-check - with: - working_directory: collector + # - name: Run sanity check on collector + # uses: ./collector/.github/actions/run-sanity-check + # with: + # working_directory: collector - name: Upload container test results as an artifact uses: actions/upload-artifact@v3 diff --git a/.github/workflows/preflight.yml b/.github/workflows/preflight.yml index 2af36f708..8b55e41c2 100644 --- a/.github/workflows/preflight.yml +++ b/.github/workflows/preflight.yml @@ -20,7 +20,7 @@ jobs: - name: Set up Go 1.21 uses: actions/setup-go@v4 with: - go-version: 1.21.3 + go-version: 1.21.4 - name: Disable default go problem matcher run: echo "::remove-matcher owner=go::" diff --git a/.github/workflows/qe-hosted.yml b/.github/workflows/qe-hosted.yml index 88d72d115..833d8e910 100644 --- a/.github/workflows/qe-hosted.yml +++ b/.github/workflows/qe-hosted.yml @@ -49,7 +49,7 @@ jobs: - name: Set up Go 1.21 uses: actions/setup-go@v4 with: - go-version: 1.21.3 + go-version: 1.21.4 - name: Disable default go problem matcher run: echo "::remove-matcher owner=go::" diff --git a/.github/workflows/qe-ocp-intrusive.yaml b/.github/workflows/qe-ocp-413-intrusive.yaml similarity index 89% rename from .github/workflows/qe-ocp-intrusive.yaml rename to .github/workflows/qe-ocp-413-intrusive.yaml index 7709dcf34..bee1a95c6 100644 --- a/.github/workflows/qe-ocp-intrusive.yaml +++ b/.github/workflows/qe-ocp-413-intrusive.yaml @@ -1,4 +1,4 @@ -name: QE OCP Intrusive Testing +name: QE OCP 4.13 Intrusive Testing on: # pull_request: @@ -11,7 +11,7 @@ env: QE_REPO: test-network-function/cnfcert-tests-verification jobs: - qe-ocp-intrusive-testing: + qe-ocp-413-intrusive-testing: runs-on: qe-ocp strategy: fail-fast: false @@ -25,6 +25,8 @@ jobs: TEST_TNF_IMAGE_NAME: quay.io/testnetworkfunction/cnf-certification-test TEST_TNF_IMAGE_TAG: localtest DOCKER_CONFIG_DIR: '/home/labuser/.docker' + TNF_CONFIG_DIR: '/home/labuser/tnf_config' + TNF_REPORT_DIR: '/home/labuser/tnf_report' steps: - name: Check out code @@ -74,5 +76,5 @@ jobs: GITHUB_REPO: https://github.com/test-network-function/cnf-certification-test run: | curl -X POST --data "{ - \"text\": \"🚨⚠️ Failed to run intrusive OCP QE tests from commit \<$GITHUB_REPO/commit/$COMMIT_SHA|$COMMIT_SHA\>, job ID \<$GITHUB_REPO/actions/runs/$JOB_RUN_ID/attempts/$JOB_RUN_ATTEMPT|$JOB_RUN_ID\> \" + \"text\": \"🚨⚠️ Failed to run intrusive OCP 4.13 QE tests from commit \<$GITHUB_REPO/commit/$COMMIT_SHA|$COMMIT_SHA\>, job ID \<$GITHUB_REPO/actions/runs/$JOB_RUN_ID/attempts/$JOB_RUN_ATTEMPT|$JOB_RUN_ID\> \" }" -H 'Content-type: application/json; charset=UTF-8' ${{ secrets.QE_NIGHTLY_WEBHOOK }} diff --git a/.github/workflows/qe-ocp.yaml b/.github/workflows/qe-ocp-413.yaml similarity index 89% rename from .github/workflows/qe-ocp.yaml rename to .github/workflows/qe-ocp-413.yaml index 702224833..152b186b9 100644 --- a/.github/workflows/qe-ocp.yaml +++ b/.github/workflows/qe-ocp-413.yaml @@ -1,4 +1,4 @@ -name: QE OCP Testing +name: QE OCP 4.13 Testing on: # pull_request: @@ -11,7 +11,7 @@ env: QE_REPO: test-network-function/cnfcert-tests-verification jobs: - qe-ocp-testing: + qe-ocp-413-testing: runs-on: qe-ocp strategy: fail-fast: false @@ -24,6 +24,8 @@ jobs: TEST_TNF_IMAGE_NAME: quay.io/testnetworkfunction/cnf-certification-test TEST_TNF_IMAGE_TAG: localtest DOCKER_CONFIG_DIR: '/home/labuser/.docker' + TNF_CONFIG_DIR: '/home/labuser/tnf_config' + TNF_REPORT_DIR: '/home/labuser/tnf_report' steps: - name: Check out code @@ -73,5 +75,5 @@ jobs: GITHUB_REPO: https://github.com/test-network-function/cnf-certification-test run: | curl -X POST --data "{ - \"text\": \"🚨⚠️ Failed to run non-intrusive OCP QE tests from commit \<$GITHUB_REPO/commit/$COMMIT_SHA|$COMMIT_SHA\>, job ID \<$GITHUB_REPO/actions/runs/$JOB_RUN_ID/attempts/$JOB_RUN_ATTEMPT|$JOB_RUN_ID\> \" + \"text\": \"🚨⚠️ Failed to run non-intrusive OCP 4.13 QE tests from commit \<$GITHUB_REPO/commit/$COMMIT_SHA|$COMMIT_SHA\>, job ID \<$GITHUB_REPO/actions/runs/$JOB_RUN_ID/attempts/$JOB_RUN_ATTEMPT|$JOB_RUN_ID\> \" }" -H 'Content-type: application/json; charset=UTF-8' ${{ secrets.QE_NIGHTLY_WEBHOOK }} diff --git a/.github/workflows/qe-ocp-414-intrusive.yaml b/.github/workflows/qe-ocp-414-intrusive.yaml new file mode 100644 index 000000000..22e340a9a --- /dev/null +++ b/.github/workflows/qe-ocp-414-intrusive.yaml @@ -0,0 +1,80 @@ +name: QE OCP 4.14 Intrusive Testing + +on: + # pull_request: + # branches: [ main ] + workflow_dispatch: + # Schedule a daily cron at midnight UTC + schedule: + - cron: '0 0 * * *' +env: + QE_REPO: test-network-function/cnfcert-tests-verification + +jobs: + qe-ocp-414-intrusive-testing: + runs-on: qe-ocp-414 + strategy: + fail-fast: false + matrix: + # Add more suites if more intrusive tests are added to the QE repo + suite: [lifecycle] + env: + SHELL: /bin/bash + KUBECONFIG: '/home/labuser2/.kube/config' + PFLT_DOCKERCONFIG: '/home/labuser2/.docker/config' + TEST_TNF_IMAGE_NAME: quay.io/testnetworkfunction/cnf-certification-test + TEST_TNF_IMAGE_TAG: localtest + DOCKER_CONFIG_DIR: '/home/labuser2/.docker' + TNF_CONFIG_DIR: '/home/labuser2/tnf_config' + TNF_REPORT_DIR: '/home/labuser2/tnf_report' + + steps: + - name: Check out code + uses: actions/checkout@v4 + with: + ref: ${{ github.sha }} + + - name: Run initial setup + uses: ./.github/actions/setup + + - name: Preemptively prune docker resources + run: docker system prune -f --volumes + + - name: Build the test image + run: make build-image-local # quay.io/testnetworkfunction/cnf-certification-test:localtest + + - name: Show pods + run: oc get pods -A + + - name: Clone the QE repository + uses: actions/checkout@v4 + with: + repository: ${{ env.QE_REPO }} + path: cnfcert-tests-verification + + - name: Preemptively potential QE namespaces + run: ./scripts/delete-namespaces.sh + working-directory: cnfcert-tests-verification + + - name: Preemptively delete report and config folders + shell: bash + run: | + sudo rm -rf /tmp/tnf_config/ + sudo rm -rf /tmp/tnf_report/ + + # Setup is complete. Time to run the QE tests. + - name: Run the tests + run: FEATURES=${{matrix.suite}} TNF_REPO_PATH=${GITHUB_WORKSPACE} TNF_IMAGE=${{env.TEST_TNF_IMAGE_NAME}} TNF_IMAGE_TAG=${{env.TEST_TNF_IMAGE_TAG}} DISABLE_INTRUSIVE_TESTS=false ENABLE_PARALLEL=false ENABLE_FLAKY_RETRY=true make test-features + working-directory: cnfcert-tests-verification + + - name: (if on main and upstream) Send chat msg to dev team if failed to run QE tests + if: ${{ failure() && github.ref == 'refs/heads/main' && github.repository_owner == 'test-network-function' }} + env: + COMMIT_SHA: ${{ github.sha }} + JOB_RUN_ID: ${{ github.run_id }} + JOB_RUN_ATTEMPT: ${{ github.run_attempt }} + GITHUB_REPO: https://github.com/test-network-function/cnf-certification-test + run: | + curl -X POST --data "{ + \"text\": \"🚨⚠️ Failed to run intrusive OCP 4.14 QE tests from commit \<$GITHUB_REPO/commit/$COMMIT_SHA|$COMMIT_SHA\>, job ID \<$GITHUB_REPO/actions/runs/$JOB_RUN_ID/attempts/$JOB_RUN_ATTEMPT|$JOB_RUN_ID\> \" + }" -H 'Content-type: application/json; charset=UTF-8' ${{ secrets.QE_NIGHTLY_WEBHOOK }} diff --git a/.github/workflows/qe-ocp-414.yaml b/.github/workflows/qe-ocp-414.yaml new file mode 100644 index 000000000..eed2acbba --- /dev/null +++ b/.github/workflows/qe-ocp-414.yaml @@ -0,0 +1,79 @@ +name: QE OCP 4.14 Testing + +on: + # pull_request: + # branches: [ main ] + workflow_dispatch: + # Schedule a daily cron at midnight UTC + schedule: + - cron: '0 0 * * *' +env: + QE_REPO: test-network-function/cnfcert-tests-verification + +jobs: + qe-ocp-414-testing: + runs-on: qe-ocp-414 + strategy: + fail-fast: false + matrix: + suite: [accesscontrol, affiliatedcertification, manageability, networking, lifecycle, performance, platformalteration, observability, operator] + env: + SHELL: /bin/bash + KUBECONFIG: '/home/labuser2/.kube/config' + PFLT_DOCKERCONFIG: '/home/labuser2/.docker/config' + TEST_TNF_IMAGE_NAME: quay.io/testnetworkfunction/cnf-certification-test + TEST_TNF_IMAGE_TAG: localtest + DOCKER_CONFIG_DIR: '/home/labuser2/.docker' + TNF_CONFIG_DIR: '/home/labuser2/tnf_config' + TNF_REPORT_DIR: '/home/labuser2/tnf_report' + + steps: + - name: Check out code + uses: actions/checkout@v4 + with: + ref: ${{ github.sha }} + + - name: Run initial setup + uses: ./.github/actions/setup + + - name: Preemptively prune docker resources + run: docker system prune -f --volumes + + - name: Build the test image + run: make build-image-local # quay.io/testnetworkfunction/cnf-certification-test:localtest + + - name: Show pods + run: oc get pods -A + + - name: Clone the QE repository + uses: actions/checkout@v4 + with: + repository: ${{ env.QE_REPO }} + path: cnfcert-tests-verification + + - name: Preemptively potential QE namespaces + run: ./scripts/delete-namespaces.sh + working-directory: cnfcert-tests-verification + + - name: Preemptively delete report and config folders + shell: bash + run: | + sudo rm -rf /tmp/tnf_config/ + sudo rm -rf /tmp/tnf_report/ + + # Setup is complete. Time to run the QE tests. + - name: Run the tests + run: FEATURES=${{matrix.suite}} TNF_REPO_PATH=${GITHUB_WORKSPACE} TNF_IMAGE=${{env.TEST_TNF_IMAGE_NAME}} TNF_IMAGE_TAG=${{env.TEST_TNF_IMAGE_TAG}} DISABLE_INTRUSIVE_TESTS=true ENABLE_PARALLEL=true ENABLE_FLAKY_RETRY=true make test-features + working-directory: cnfcert-tests-verification + + - name: (if on main and upstream) Send chat msg to dev team if failed to run QE tests + if: ${{ failure() && github.ref == 'refs/heads/main' && github.repository_owner == 'test-network-function' }} + env: + COMMIT_SHA: ${{ github.sha }} + JOB_RUN_ID: ${{ github.run_id }} + JOB_RUN_ATTEMPT: ${{ github.run_attempt }} + GITHUB_REPO: https://github.com/test-network-function/cnf-certification-test + run: | + curl -X POST --data "{ + \"text\": \"🚨⚠️ Failed to run non-intrusive OCP 4.14 QE tests from commit \<$GITHUB_REPO/commit/$COMMIT_SHA|$COMMIT_SHA\>, job ID \<$GITHUB_REPO/actions/runs/$JOB_RUN_ID/attempts/$JOB_RUN_ATTEMPT|$JOB_RUN_ID\> \" + }" -H 'Content-type: application/json; charset=UTF-8' ${{ secrets.QE_NIGHTLY_WEBHOOK }} diff --git a/.github/workflows/update-rhcos-mapping.yml b/.github/workflows/update-rhcos-mapping.yml index eff535f19..08e62c1d6 100644 --- a/.github/workflows/update-rhcos-mapping.yml +++ b/.github/workflows/update-rhcos-mapping.yml @@ -23,7 +23,7 @@ jobs: - name: Set up Go 1.21 uses: actions/setup-go@v4 with: - go-version: 1.21.3 + go-version: 1.21.4 # This prevents any failures due to the updated rhcos_versions_map file from # making it into the PR phase. diff --git a/Dockerfile b/Dockerfile index 620e3fa0e..63c9ef3a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ RUN \ # Install Go binary and set the PATH ENV \ GO_DL_URL=https://golang.org/dl \ - GO_BIN_TAR=go1.21.3.linux-amd64.tar.gz \ + GO_BIN_TAR=go1.21.4.linux-amd64.tar.gz \ GOPATH=/root/go ENV GO_BIN_URL_x86_64=${GO_DL_URL}/${GO_BIN_TAR} RUN \ diff --git a/cnf-certification-test/performance/suite.go b/cnf-certification-test/performance/suite.go index fad47e3d1..ce5bf652f 100644 --- a/cnf-certification-test/performance/suite.go +++ b/cnf-certification-test/performance/suite.go @@ -18,6 +18,7 @@ package performance import ( "fmt" + "slices" "strconv" "strings" @@ -325,13 +326,11 @@ func filterProbeProcesses(allProcesses []*crclient.Process, cut *provider.Contai } // remove all exec probes and their children from the process list for _, p := range allProcesses { - for _, parentProbePid := range execProbeProcesses { - if p.Pid == parentProbePid || p.PPid == parentProbePid { - // skip exec probe processes (child or parent) - continue - } - notExecProbeProcesses = append(notExecProbeProcesses, p) + if slices.Contains(execProbeProcesses, p.Pid) || slices.Contains(execProbeProcesses, p.PPid) { + // this process is part of an exec probe (child or parent), continue + continue } + notExecProbeProcesses = append(notExecProbeProcesses, p) } return notExecProbeProcesses, compliantObjects } diff --git a/cnf-certification-test/platform/operatingsystem/files/rhcos_version_map b/cnf-certification-test/platform/operatingsystem/files/rhcos_version_map index 386a8c385..d1ca1d661 100644 --- a/cnf-certification-test/platform/operatingsystem/files/rhcos_version_map +++ b/cnf-certification-test/platform/operatingsystem/files/rhcos_version_map @@ -188,6 +188,7 @@ 4.12.40 / 412.86.202310170023-0 4.12.41 / 412.86.202310210217-0 4.12.42 / 412.86.202310302215-0 +4.12.43 / 412.86.202311051457-0 4.12.5 / 412.86.202302170236-0 4.12.6 / 412.86.202302282003-0 4.12.7 / 412.86.202303011010-0 diff --git a/cnf-certification-test/suite_test.go b/cnf-certification-test/suite_test.go index 21ed4ade1..2946edeac 100644 --- a/cnf-certification-test/suite_test.go +++ b/cnf-certification-test/suite_test.go @@ -17,16 +17,24 @@ package suite import ( + "bytes" _ "embed" + "encoding/json" "flag" + "fmt" + "io" + rlog "log" + "net/http" "os" "path/filepath" + "strings" "testing" "time" "github.com/onsi/ginkgo/v2" log "github.com/sirupsen/logrus" "github.com/test-network-function/cnf-certification-test/cnf-certification-test/results" + "github.com/test-network-function/cnf-certification-test/pkg/claim" "github.com/test-network-function/cnf-certification-test/pkg/claimhelper" "github.com/test-network-function/cnf-certification-test/pkg/collector" "github.com/test-network-function/cnf-certification-test/pkg/loghelper" @@ -44,6 +52,7 @@ import ( _ "github.com/test-network-function/cnf-certification-test/cnf-certification-test/performance" _ "github.com/test-network-function/cnf-certification-test/cnf-certification-test/platform" _ "github.com/test-network-function/cnf-certification-test/cnf-certification-test/preflight" + "github.com/test-network-function/cnf-certification-test/cnf-certification-test/webserver" "github.com/test-network-function/cnf-certification-test/internal/clientsholder" "github.com/test-network-function/cnf-certification-test/internal/version" "github.com/test-network-function/cnf-certification-test/pkg/configuration" @@ -55,13 +64,16 @@ const ( defaultClaimPath = ".." defaultCliArgValue = "" junitFlagKey = "junit" + serverModeFlag = "serverMode" TNFReportKey = "cnf-certification-test" extraInfoKey = "testsExtraInfo" + defaultServerMode = false ) var ( - claimPath *string - junitPath *string + claimPath *string + junitPath *string + serverMode *bool ) func init() { @@ -69,6 +81,7 @@ func init() { "the path where the claimfile will be output") junitPath = flag.String(junitFlagKey, defaultCliArgValue, "the path for the junit format report") + serverMode = flag.Bool("serverMode", defaultServerMode, "run test with webserver") } // setLogLevel sets the log level for logrus based on the "TNF_LOG_LEVEL" environment variable @@ -99,8 +112,7 @@ func getK8sClientsConfigFileNames() []string { return fileNames } -// TestTest invokes the CNF Certification Test Suite. -func TestTest(t *testing.T) { +func PreRun(t *testing.T) (claimData *claim.Claim, claimRoot *claim.Root) { // When running unit tests, skip the suite if os.Getenv("UNIT_TEST") != "" { t.Skip("Skipping test suite when running unit tests") @@ -119,20 +131,13 @@ func TestTest(t *testing.T) { log.Infof("TNF Version : %v", version.GetGitVersion()) log.Infof("Ginkgo Version : %v", ginkgo.GINKGO_VERSION) log.Infof("Labels filter : %v", ginkgoConfig.LabelFilter) - - // Diagnostic functions will run when no labels are provided. - var diagnosticMode bool - if ginkgoConfig.LabelFilter == "" { - log.Infof("TNF will run in diagnostic mode so no test case will be launched.") - diagnosticMode = true - } - + log.Infof("run test with webserver : %v", *serverMode) // Set clientsholder singleton with the filenames from the env vars. _ = clientsholder.GetClientsHolder(getK8sClientsConfigFileNames()...) // Initialize the claim with the start time, tnf version, etc. - claimRoot := claimhelper.CreateClaimRoot() - claimData := claimRoot.Claim + claimRoot = claimhelper.CreateClaimRoot() + claimData = claimRoot.Claim claimData.Configurations = make(map[string]interface{}) claimData.Nodes = make(map[string]interface{}) claimhelper.IncorporateVersions(claimData) @@ -142,21 +147,42 @@ func TestTest(t *testing.T) { log.Errorf("Configuration node missing because of: %s", err) t.FailNow() } - claimData.Nodes = claimhelper.GenerateNodes() claimhelper.UnmarshalConfigurations(configurations, claimData.Configurations) + return claimData, claimRoot +} + +// TestTest invokes the CNF Certification Test Suite. +func TestTest(t *testing.T) { + ginkgoConfig, _ := ginkgo.GinkgoConfiguration() + if !*serverMode { + claimData, claimRoot := PreRun(t) + var diagnosticMode bool + // Diagnostic functions will run when no labels are provided. + + if ginkgoConfig.LabelFilter == "" { + log.Infof("TNF will run in diagnostic mode so no test case will be launched.") + diagnosticMode = true + } - // initialize abort flag - testhelper.AbortTrigger = "" + // initialize abort flag + testhelper.AbortTrigger = "" - // Run tests specs only if not in diagnostic mode, otherwise all TSs would run. - var env provider.TestEnvironment - if !diagnosticMode { - env.SetNeedsRefresh() - env = provider.GetTestEnvironment() - ginkgo.RunSpecs(t, CnfCertificationTestSuiteName) + // Run tests specs only if not in diagnostic mode, otherwise all TSs would run. + var env provider.TestEnvironment + if !diagnosticMode { + env.SetNeedsRefresh() + env = provider.GetTestEnvironment() + ginkgo.RunSpecs(t, CnfCertificationTestSuiteName) + } + ContinueRun(diagnosticMode, &env, claimData, claimRoot) + } else { + go StartServer() + select {} } +} +func ContinueRun(diagnosticMode bool, env *provider.TestEnvironment, claimData *claim.Claim, claimRoot *claim.Root) { endTime := time.Now() claimData.Metadata.EndTime = endTime.UTC().Format(claimhelper.DateTimeFormatDirective) @@ -183,7 +209,7 @@ func TestTest(t *testing.T) { // Send claim file to the collector if specified by env var if configuration.GetTestParameters().EnableDataCollection { - err = collector.SendClaimFileToCollector(env.CollectorAppEndPoint, claimOutputFile, env.ExecutedBy, env.PartnerName, env.CollectorAppPassword) + err := collector.SendClaimFileToCollector(env.CollectorAppEndPoint, claimOutputFile, env.ExecutedBy, env.PartnerName, env.CollectorAppPassword) if err != nil { log.Errorf("Failed to send post request to the collector: %v", err) } @@ -224,3 +250,103 @@ func TestTest(t *testing.T) { } } } + +func StartServer() { + server := &http.Server{ + Addr: ":8084", // Server address + ReadTimeout: 10 * time.Second, // Maximum duration for reading the entire request + WriteTimeout: 10 * time.Second, // Maximum duration for writing the entire response + IdleTimeout: 120 * time.Second, // Maximum idle duration before closing the connection + } + webserver.HandlereqFunc() + + http.HandleFunc("/runFunction", RunHandler) + + fmt.Println("Server is running on :8084...") + if err := server.ListenAndServe(); err != nil { + panic(err) + } +} + +// Define an HTTP handler that triggers Ginkgo tests +func RunHandler(w http.ResponseWriter, r *http.Request) { + webserver.Buf = bytes.NewBufferString("") + log.SetOutput(webserver.Buf) + rlog.SetOutput(webserver.Buf) + + jsonData := r.FormValue("jsonData") // "jsonData" is the name of the JSON input field + log.Info(jsonData) + var data webserver.RequestedData + if err := json.Unmarshal([]byte(jsonData), &data); err != nil { + fmt.Println("Error:", err) + } + var flattenedOptions []string + flattenedOptions = webserver.FlattenData(data.SelectedOptions, flattenedOptions) + + // Get the file from the request + file, handler, err := r.FormFile("kubeConfigPath") // "fileInput" is the name of the file input field + if err != nil { + http.Error(w, "Unable to retrieve file from form", http.StatusBadRequest) + return + } + defer file.Close() + + // Create a new file on the server to store the uploaded content + uploadedFile, err := os.Create(handler.Filename) + if err != nil { + http.Error(w, "Unable to create file for writing", http.StatusInternalServerError) + return + } + defer uploadedFile.Close() + + // Copy the uploaded file's content to the new file + _, err = io.Copy(uploadedFile, file) + if err != nil { + http.Error(w, "Unable to copy file", http.StatusInternalServerError) + return + } + + // Copy the uploaded file to the server file + + os.Setenv("KUBECONFIG", handler.Filename) + log.Infof("KUBECONFIG : %v", handler.Filename) + + log.Infof("Labels filter : %v", flattenedOptions) + t := testing.T{} + claimData, claimRoot := PreRun(&t) + var env provider.TestEnvironment + env.SetNeedsRefresh() + env = provider.GetTestEnvironment() + + // fetch the current config + suiteConfig, reporterConfig := ginkgo.GinkgoConfiguration() + // adjust it + suiteConfig.SkipStrings = []string{"NEVER-RUN"} + reporterConfig.FullTrace = true + reporterConfig.JUnitReport = "cnf-certification-tests_junit.xml" + // pass it in to RunSpecs + suiteConfig.LabelFilter = strings.Join(flattenedOptions, "") + ginkgo.RunSpecs(&t, CnfCertificationTestSuiteName, suiteConfig, reporterConfig) + + ContinueRun(false, &env, claimData, claimRoot) + // Return the result as JSON + response := struct { + Message string `json:"Message"` + }{ + Message: fmt.Sprintf("Sucsses to run %s", strings.Join(flattenedOptions, "")), + } + // Serialize the response data to JSON + jsonResponse, err := json.Marshal(response) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + // Set the Content-Type header to specify that the response is JSON + w.Header().Set("Content-Type", "application/json") + // Write the JSON response to the client + _, err = w.Write(jsonResponse) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} diff --git a/cnf-certification-test/webserver/index.html b/cnf-certification-test/webserver/index.html new file mode 100644 index 000000000..07611612a --- /dev/null +++ b/cnf-certification-test/webserver/index.html @@ -0,0 +1,238 @@ + + +
+ + +