From 8169c04259d14904a6f7425f06cf552946b6994e Mon Sep 17 00:00:00 2001 From: jmontesi Date: Thu, 21 Dec 2023 16:06:40 +0100 Subject: [PATCH 1/3] go.mod: bump test-network-function-claim to v1.0.33 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 17ec2c351..c86a8b22d 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/sirupsen/logrus v1.9.3 // indirect github.com/spf13/cobra v1.8.0 github.com/stretchr/testify v1.8.4 - github.com/test-network-function/test-network-function-claim v1.0.32 + github.com/test-network-function/test-network-function-claim v1.0.33 github.com/xeipuuv/gojsonschema v1.2.0 // indirect gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index c95c6f852..679c3db93 100644 --- a/go.sum +++ b/go.sum @@ -575,8 +575,8 @@ github.com/test-network-function/oct v0.0.4 h1:rU4kps/gbAHkR0rc5WzVtTOcJt/NBcse8 github.com/test-network-function/oct v0.0.4/go.mod h1:oOPuUMnX6YR+cl3usBJfwCllsv7Hphw9jVi7VtniAzo= github.com/test-network-function/privileged-daemonset v1.0.18 h1:BFGAz5A77VxJCfHx6YEI+QehEINfCHm7KB+35QebsWs= github.com/test-network-function/privileged-daemonset v1.0.18/go.mod h1:zIxnKlnvftN62+38OCu/H7bLDjW3fzkpTY+lhyfxlPM= -github.com/test-network-function/test-network-function-claim v1.0.32 h1:GeUwbHYaXL5Yx785NmbuSQbqby8LVPEWHeW3bFEpQ9g= -github.com/test-network-function/test-network-function-claim v1.0.32/go.mod h1:+0c6DMF/ycFmEH3EB5mJ9rSQ+3T/d48NuqmY2aXjrqQ= +github.com/test-network-function/test-network-function-claim v1.0.33 h1:thLfqtzpXMNlmA8ZGpee3BUN+OfhRiFoTuEHWsE3d7Y= +github.com/test-network-function/test-network-function-claim v1.0.33/go.mod h1:+0c6DMF/ycFmEH3EB5mJ9rSQ+3T/d48NuqmY2aXjrqQ= github.com/urfave/cli v1.22.12/go.mod h1:sSBEIC79qR6OvcmsD4U3KABeOTxDqQtdDnaFuUN30b8= github.com/vbatts/tar-split v0.11.3 h1:hLFqsOLQ1SsppQNTMpkpPXClLDfC2A3Zgy9OUU+RVck= github.com/vbatts/tar-split v0.11.3/go.mod h1:9QlHN18E+fEH7RdG+QAJJcuya3rqT7eXSTY7wGrAokY= From 88c60c5cd644b9bf8cfefc5bc34e6c156171b8ff Mon Sep 17 00:00:00 2001 From: jmontesi Date: Thu, 21 Dec 2023 16:56:57 +0100 Subject: [PATCH 2/3] Remove legacy tool claim add --- cmd/tnf/claim/add/add.go | 112 ---------------------------------- cmd/tnf/claim/add/add_test.go | 49 --------------- cmd/tnf/claim/claim.go | 2 - 3 files changed, 163 deletions(-) delete mode 100644 cmd/tnf/claim/add/add.go delete mode 100644 cmd/tnf/claim/add/add_test.go diff --git a/cmd/tnf/claim/add/add.go b/cmd/tnf/claim/add/add.go deleted file mode 100644 index 7cd3509cb..000000000 --- a/cmd/tnf/claim/add/add.go +++ /dev/null @@ -1,112 +0,0 @@ -package add - -import ( - "fmt" - "os" - "path/filepath" - - "encoding/json" - - "github.com/spf13/cobra" - "github.com/test-network-function/cnf-certification-test/internal/log" - "github.com/test-network-function/cnf-certification-test/pkg/junit" - "github.com/test-network-function/test-network-function-claim/pkg/claim" -) - -var ( - Reportdir string - Claim string - - claimAddFile = &cobra.Command{ - Use: "add", - Short: "Add results from xml junit files to an existing claim file.", - RunE: claimUpdate, - } -) - -const ( - claimFilePermissions = 0o644 -) - -func claimUpdate(_ *cobra.Command, _ []string) error { - claimFileTextPtr := &Claim - reportFilesTextPtr := &Reportdir - fileUpdated := false - dat, err := os.ReadFile(*claimFileTextPtr) - if err != nil { - log.Error("Error reading claim file :%v", err) - os.Exit(1) - } - claimRoot := readClaim(&dat) - junitMap := claimRoot.Claim.RawResults - items, err := os.ReadDir(*reportFilesTextPtr) - if err != nil { - log.Error("Error reading directory: %v", err) - os.Exit(1) - } - for _, item := range items { - fileName := item.Name() - extension := filepath.Ext(fileName) - reportKeyName := fileName[0 : len(fileName)-len(extension)] - if _, ok := junitMap[reportKeyName]; ok { - log.Info("Skipping: %s already exists in supplied `%s` claim file", reportKeyName, *claimFileTextPtr) - } else { - junitMap[reportKeyName], err = junit.ExportJUnitAsMap(fmt.Sprintf("%s/%s", *reportFilesTextPtr, item.Name())) - if err != nil { - log.Error("Error reading JUnit XML file into JSON: %v", err) - os.Exit(1) - } - fileUpdated = true - } - } - claimRoot.Claim.RawResults = junitMap - payload, err := json.MarshalIndent(claimRoot, "", " ") - if err != nil { - log.Error("Failed to generate the claim: %v", err) - os.Exit(1) - } - err = os.WriteFile(*claimFileTextPtr, payload, claimFilePermissions) - if err != nil { - log.Error("Error writing claim data:\n%s", string(payload)) - os.Exit(1) - } - if fileUpdated { - log.Info("Claim file `%s` updated\n", *claimFileTextPtr) - } else { - log.Info("No changes were applied to `%s`\n", *claimFileTextPtr) - } - return nil -} - -func readClaim(contents *[]byte) *claim.Root { - var claimRoot claim.Root - err := json.Unmarshal(*contents, &claimRoot) - if err != nil { - log.Error("Error reading claim constents file into type: %v", err) - os.Exit(1) - } - return &claimRoot -} - -func NewCommand() *cobra.Command { - claimAddFile.Flags().StringVarP( - &Reportdir, "reportdir", "r", "", - "dir of JUnit XML reports. (Required)", - ) - - err := claimAddFile.MarkFlagRequired("reportdir") - if err != nil { - return nil - } - - claimAddFile.Flags().StringVarP( - &Claim, "claim", "c", "", - "existing claim file. (Required)", - ) - err = claimAddFile.MarkFlagRequired("claim") - if err != nil { - return nil - } - - return claimAddFile -} diff --git a/cmd/tnf/claim/add/add_test.go b/cmd/tnf/claim/add/add_test.go deleted file mode 100644 index 4ef364631..000000000 --- a/cmd/tnf/claim/add/add_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package add - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "github.com/test-network-function/test-network-function-claim/pkg/claim" -) - -func TestReadClaim(t *testing.T) { - testCases := []struct { - testContents string - expectedClaimRoot *claim.Root - }{ - { // Test Case #1 - Happy path - testContents: `{"claim":{"versions":{"k8s":"1.23.1","tnf":"0.3.1", "claimFormat":"v0.0.1"},"configurations":{},"metadata":{"endTime":"1:33:00","startTime":"2:33:00"},"nodes":{},"results":{},"rawResults":{}}}`, - expectedClaimRoot: &claim.Root{ - Claim: &claim.Claim{ - Versions: &claim.Versions{ - K8s: "1.23.1", - Tnf: "0.3.1", - ClaimFormat: "v0.0.1", - }, - Metadata: &claim.Metadata{ - EndTime: "1:33:00", - StartTime: "2:33:00", - }, - Nodes: make(map[string]interface{}), - Results: make(map[string]interface{}), - RawResults: make(map[string]interface{}), - Configurations: make(map[string]interface{}), - }, - }, - }, - } - - for _, tc := range testCases { - byteContents := []byte(tc.testContents) - assert.Equal(t, tc.expectedClaimRoot, readClaim(&byteContents)) - } -} - -func TestNewCommand(t *testing.T) { - // No parameters to test - result := NewCommand() - assert.NotNil(t, result) - assert.Equal(t, "add", result.Use) - assert.Equal(t, "Add results from xml junit files to an existing claim file.", result.Short) -} diff --git a/cmd/tnf/claim/claim.go b/cmd/tnf/claim/claim.go index 530d84509..14c460ea6 100644 --- a/cmd/tnf/claim/claim.go +++ b/cmd/tnf/claim/claim.go @@ -2,7 +2,6 @@ package claim import ( "github.com/spf13/cobra" - "github.com/test-network-function/cnf-certification-test/cmd/tnf/claim/add" "github.com/test-network-function/cnf-certification-test/cmd/tnf/claim/compare" "github.com/test-network-function/cnf-certification-test/cmd/tnf/claim/show" ) @@ -15,7 +14,6 @@ var ( ) func NewCommand() *cobra.Command { - claimCommand.AddCommand(add.NewCommand()) claimCommand.AddCommand(compare.NewCommand()) claimCommand.AddCommand(show.NewCommand()) From 38e00ecf6a2da1fb8f7cbc0ee6af84ca1e4d3527 Mon Sep 17 00:00:00 2001 From: jmontesi Date: Thu, 21 Dec 2023 17:03:40 +0100 Subject: [PATCH 3/3] Temporarily disable the gradetool --- .github/workflows/pre-main.yaml | 88 ++++++++++++++++----------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/.github/workflows/pre-main.yaml b/.github/workflows/pre-main.yaml index 90d034d75..6347eceb7 100644 --- a/.github/workflows/pre-main.yaml +++ b/.github/workflows/pre-main.yaml @@ -249,28 +249,28 @@ jobs: - name: Remove tarball(s) to save disk space. run: rm -f cnf-certification-test/*.tar.gz - - name: Run gradetool on the claim.json. - run: | - docker run \ - --rm \ - --volume "${GITHUB_WORKSPACE}"/generated_policy.json:/policy.json \ - --volume "${GITHUB_WORKSPACE}"/cnf-certification-test/claim.json:/claim.json \ - ${REGISTRY}/${GRADETOOL_IMAGE_NAME}:${GRADETOOL_IMAGE_TAG} \ - --OutputPath results.txt \ - --policy /policy.json \ - --results /claim.json \ - >"${GITHUB_WORKSPACE}"/results.txt - docker system prune --volumes -f - - - name: Check that their are 0 failed tests in the gradetool results - run: | - if $(jq '.[] | .Fail | length' "${GITHUB_WORKSPACE}"/results.txt | grep -q 0); then - echo OK - else - echo "Gradetool has found failing tests in the following:" - jq '.[] | .Fail | .[].id' "${GITHUB_WORKSPACE}"/results.txt - exit 1 - fi + # - name: Run gradetool on the claim.json. + # run: | + # docker run \ + # --rm \ + # --volume "${GITHUB_WORKSPACE}"/generated_policy.json:/policy.json \ + # --volume "${GITHUB_WORKSPACE}"/cnf-certification-test/claim.json:/claim.json \ + # ${REGISTRY}/${GRADETOOL_IMAGE_NAME}:${GRADETOOL_IMAGE_TAG} \ + # --OutputPath results.txt \ + # --policy /policy.json \ + # --results /claim.json \ + # >"${GITHUB_WORKSPACE}"/results.txt + # docker system prune --volumes -f + + # - name: Check that their are 0 failed tests in the gradetool results + # run: | + # if $(jq '.[] | .Fail | length' "${GITHUB_WORKSPACE}"/results.txt | grep -q 0); then + # echo OK + # else + # echo "Gradetool has found failing tests in the following:" + # jq '.[] | .Fail | .[].id' "${GITHUB_WORKSPACE}"/results.txt + # exit 1 + # fi - name: 'Test: Run preflight specific test suite' run: TNF_LOG_LEVEL=${TNF_SMOKE_TESTS_LOG_LEVEL} ./run-cnf-suites.sh -l "preflight" @@ -404,28 +404,28 @@ jobs: - name: Remove tarball(s) to save disk space. run: rm -f ${{ env.TNF_OUTPUT_DIR }}/*.tar.gz - - name: Run gradetool on the claim.json. - run: | - docker run \ - --rm \ - --volume "${GITHUB_WORKSPACE}"/generated_policy.json:/policy.json \ - --volume "${TNF_OUTPUT_DIR}"/claim.json:/claim.json \ - ${REGISTRY}/${GRADETOOL_IMAGE_NAME}:${GRADETOOL_IMAGE_TAG} \ - --OutputPath results.txt \ - --policy /policy.json \ - --results /claim.json \ - >"${GITHUB_WORKSPACE}"/results.txt - docker system prune --volumes -f - - - name: Check that their are 0 failed tests in the gradetool results - run: | - if $(jq '.[] | .Fail | length' "${GITHUB_WORKSPACE}"/results.txt | grep -q 0); then - echo OK - else - echo "Gradetool has found failing tests in the following:" - jq '.[] | .Fail | .[].id' "${GITHUB_WORKSPACE}"/results.txt - exit 1 - fi + # - name: Run gradetool on the claim.json. + # run: | + # docker run \ + # --rm \ + # --volume "${GITHUB_WORKSPACE}"/generated_policy.json:/policy.json \ + # --volume "${TNF_OUTPUT_DIR}"/claim.json:/claim.json \ + # ${REGISTRY}/${GRADETOOL_IMAGE_NAME}:${GRADETOOL_IMAGE_TAG} \ + # --OutputPath results.txt \ + # --policy /policy.json \ + # --results /claim.json \ + # >"${GITHUB_WORKSPACE}"/results.txt + # docker system prune --volumes -f + + # - name: Check that their are 0 failed tests in the gradetool results + # run: | + # if $(jq '.[] | .Fail | length' "${GITHUB_WORKSPACE}"/results.txt | grep -q 0); then + # echo OK + # else + # echo "Gradetool has found failing tests in the following:" + # jq '.[] | .Fail | .[].id' "${GITHUB_WORKSPACE}"/results.txt + # exit 1 + # fi - name: 'Test: Run Preflight Specific Smoke Tests in a TNF container' run: TNF_LOG_LEVEL=${TNF_SMOKE_TESTS_LOG_LEVEL} ./run-tnf-container.sh ${{ env.TESTING_CMD_PARAMS }} -l "preflight"