Skip to content

Commit

Permalink
Implement air-gapped E2E tests for plugin bundle download, upload and…
Browse files Browse the repository at this point in the history
… lifecycle (#245)

Implement airgapped e2e tests for plugin download, upload, and lifecycle
  • Loading branch information
anujc25 authored May 3, 2023
1 parent 925931c commit ee05e1d
Show file tree
Hide file tree
Showing 11 changed files with 470 additions and 6 deletions.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ test: fmt ## Run Tests
${GO} test `go list ./... | grep -v test/e2e | grep -v test/coexistence` -timeout 60m -race -coverprofile coverage.txt ${GOTEST_VERBOSE}

.PHONY: e2e-cli-core ## Execute all CLI Core E2E Tests
e2e-cli-core: start-test-central-repo e2e-cli-core-all ## Execute all CLI Core E2E Tests
e2e-cli-core: start-test-central-repo start-airgapped-local-registry e2e-cli-core-all ## Execute all CLI Core E2E Tests

.PHONY: setup-custom-cert-for-test-central-repo
setup-custom-cert-for-test-central-repo: ## Setup up the custom ca cert for test-central-repo in the config file
Expand Down Expand Up @@ -207,6 +207,15 @@ start-test-central-repo: stop-test-central-repo setup-custom-cert-for-test-centr
stop-test-central-repo: ## Stops and removes the local test central repository
@docker container stop central > /dev/null 2>&1 && echo "Stopped docker test central repo" || true

.PHONY: start-airgapped-local-registry
start-airgapped-local-registry: stop-airgapped-local-registry
@docker run --rm -d -p 6001:5000 --name temp-airgapped-local-registry mirror.gcr.io/library/registry:2 > /dev/null && \
echo "Started docker test airgapped repo at 'localhost:6001'."

.PHONY: stop-airgapped-local-registry
stop-airgapped-local-registry:
@docker stop temp-airgapped-local-registry > /dev/null 2>&1 && echo "Stopping docker test airgapped repo if running..." || true

.PHONY: fmt
fmt: $(GOIMPORTS) ## Run goimports
$(GOIMPORTS) -w -local github.com/vmware-tanzu ./
Expand Down
Binary file modified hack/central-repo/registry-content.bz2
Binary file not shown.
2 changes: 0 additions & 2 deletions hack/central-repo/upload-plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ cat $ROOT_DIR/create_tables.sql | sqlite3 -batch $database
for name in ${globalPlugins[0]}; do
addPlugin $name global true v0.0.1
addPlugin $name global true v9.9.9
addGroup vmware tkg v9.9.9 $name global v9.9.9
done

for name in ${k8sPlugins[0]}; do
Expand Down Expand Up @@ -317,7 +316,6 @@ cat $ROOT_DIR/create_tables.sql | sqlite3 -batch $database
for name in ${globalPlugins[*]}; do
addPlugin $name global true v0.0.1
addPlugin $name global true v9.9.9
addGroup vmware tkg v9.9.9 $name global v9.9.9
done

for name in ${k8sPlugins[*]}; do
Expand Down
20 changes: 19 additions & 1 deletion test/e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ E2E_TEST_OUTPUT ?= ${ROOT_DIR}/e2e-test-output.txt
E2E_TEST_TIMEOUT ?= 60m
GOTEST_VERBOSE ?= -v
ROOT_DIR := $(shell git rev-parse --show-toplevel)
GO := go

ifndef TANZU_API_TOKEN
TANZU_API_TOKEN = ""
Expand Down Expand Up @@ -34,10 +35,16 @@ ifndef TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_PLUGIN_DISCOVERY_IMAGE_SIGNATURE_PU
TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_PLUGIN_DISCOVERY_IMAGE_SIGNATURE_PUBLIC_KEY_PATH = ${ROOT_DIR}/hack/central-repo/cosign-key-pair/cosign.pub
endif

ifndef TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_IMAGE_FOR_AIRGAPPED
TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_IMAGE_FOR_AIRGAPPED = localhost:9876/tanzu-cli/plugins/airgapped:large
endif

ifndef TANZU_CLI_E2E_AIRGAPPED_REPO
TANZU_CLI_E2E_AIRGAPPED_REPO = localhost:6001/tanzu-cli/plugins/
endif

.PHONY: e2e-cli-core-all ## Execute all CLI Core E2E Tests
e2e-cli-core-all: e2e-cli-lifecycle e2e-cli-config e2e-cli-plugin-compatibility-test e2e-context-k8s-tests e2e-context-tmc-test e2e-cli-plugin-lifecycle-sync-test
e2e-cli-core-all: e2e-cli-lifecycle e2e-cli-config e2e-cli-plugin-compatibility-test e2e-context-k8s-tests e2e-context-tmc-test e2e-cli-plugin-lifecycle-sync-test e2e-airgapped-tests


.PHONY: e2e-cli-lifecycle ## Execute CLI life cycle specific e2e tests
Expand Down Expand Up @@ -89,3 +96,14 @@ e2e-context-tmc-test:
export TANZU_CLI_CEIP_OPT_IN_PROMPT_ANSWER="No" ; \
${GO} test ${ROOT_DIR}/test/e2e/context/tmc -timeout ${E2E_TEST_TIMEOUT} -race -coverprofile ${E2E_TEST_OUTPUT} ${GOTEST_VERBOSE} ; \
fi

.PHONY: e2e-airgapped-tests ## Execute CLI airgapped tests
e2e-airgapped-tests:
export TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_URL=$(TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_IMAGE_FOR_AIRGAPPED) ; \
export TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_PLUGIN_DISCOVERY_IMAGE_SIGNATURE_PUBLIC_KEY_PATH=$(TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_PLUGIN_DISCOVERY_IMAGE_SIGNATURE_PUBLIC_KEY_PATH) ; \
export TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_HOST=${TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_HOST} ; \
export TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_CA_CERT_PATH=${TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_CA_CERT_PATH} ; \
export TANZU_CLI_PLUGIN_DISCOVERY_IMAGE_SIGNATURE_VERIFICATION_SKIP_LIST=$(TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_IMAGE_FOR_AIRGAPPED) ; \
export TANZU_CLI_E2E_AIRGAPPED_REPO=$(TANZU_CLI_E2E_AIRGAPPED_REPO) ; \
export TANZU_CLI_CEIP_OPT_IN_PROMPT_ANSWER="Yes" ; \
${GO} test ${ROOT_DIR}/test/e2e/airgapped -timeout ${E2E_TEST_TIMEOUT} -race -coverprofile ${E2E_TEST_OUTPUT} ${GOTEST_VERBOSE} ;
97 changes: 97 additions & 0 deletions test/e2e/airgapped/airgapped_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright 2023 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// airgapped provides airgapped specific E2E test cases
package airgapped

import (
"fmt"
"os"
"path/filepath"
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/vmware-tanzu/tanzu-cli/pkg/carvelhelpers"
"github.com/vmware-tanzu/tanzu-cli/test/e2e/framework"
pluginlifecyclee2e "github.com/vmware-tanzu/tanzu-cli/test/e2e/plugin_lifecycle"
)

func TestAirgapped(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Airgapped E2E Test Suite")
}

var (
tf *framework.Framework
e2eTestLocalCentralRepoImage string
e2eAirgappedCentralRepo string
e2eAirgappedCentralRepoImage string
pluginsSearchList []*framework.PluginInfo
pluginGroups []*framework.PluginGroup
pluginGroupToPluginListMap map[string][]*framework.PluginInfo
pluginSourceName string
tempDir string
)

// BeforeSuite initializes and set up the environment to execute the airgapped tests
var _ = BeforeSuite(func() {
tf = framework.NewFramework()
// check E2E test central repo URL (TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_URL)
e2eTestLocalCentralRepoImage = os.Getenv(framework.TanzuCliE2ETestLocalCentralRepositoryURL)
Expect(e2eTestLocalCentralRepoImage).NotTo(BeEmpty(), fmt.Sprintf("environment variable %s should set with local central repository URL", framework.TanzuCliE2ETestLocalCentralRepositoryURL))

// check E2E airgapped central repo (TANZU_CLI_E2E_AIRGAPPED_REPO)
e2eAirgappedCentralRepo = os.Getenv(framework.TanzuCliE2ETestAirgappedRepo)
Expect(e2eAirgappedCentralRepo).NotTo(BeEmpty(), fmt.Sprintf("environment variable %s should set with airgapped central repository URL", framework.TanzuCliE2ETestAirgappedRepo))

e2eAirgappedCentralRepoImage = fmt.Sprintf("%s%s", e2eAirgappedCentralRepo, filepath.Base(e2eTestLocalCentralRepoImage))

os.Setenv(framework.TanzuCliPluginDiscoverySignatureVerificationSkipList, e2eAirgappedCentralRepoImage)

// setup the test central repo
_, err := tf.PluginCmd.UpdatePluginDiscoverySource(&framework.DiscoveryOptions{Name: "default", SourceType: framework.SourceType, URI: e2eTestLocalCentralRepoImage})
Expect(err).To(BeNil(), "should not get any error for plugin source update")

e2eTestLocalCentralRepoPluginHost := os.Getenv(framework.TanzuCliE2ETestLocalCentralRepositoryHost)
Expect(e2eTestLocalCentralRepoPluginHost).NotTo(BeEmpty(), fmt.Sprintf("environment variable %s should set with local central repository host", framework.TanzuCliE2ETestLocalCentralRepositoryHost))

e2eTestLocalCentralRepoCACertPath := os.Getenv(framework.TanzuCliE2ETestLocalCentralRepositoryCACertPath)
Expect(e2eTestLocalCentralRepoCACertPath).NotTo(BeEmpty(), fmt.Sprintf("environment variable %s should set with local central repository CA cert path", framework.TanzuCliE2ETestLocalCentralRepositoryCACertPath))

// set up the CA cert fort local central repository
_ = tf.Config.ConfigCertDelete(e2eTestLocalCentralRepoPluginHost)
_, err = tf.Config.ConfigCertAdd(&framework.CertAddOptions{Host: e2eTestLocalCentralRepoPluginHost, CACertificatePath: e2eTestLocalCentralRepoCACertPath, SkipCertVerify: "false", Insecure: "false"})
Expect(err).To(BeNil())

// set up the local central repository discovery image public key path
e2eTestLocalCentralRepoPluginDiscoveryImageSignaturePublicKeyPath := os.Getenv(framework.TanzuCliE2ETestLocalCentralRepositoryPluginDiscoveryImageSignaturePublicKeyPath)
Expect(e2eTestLocalCentralRepoPluginDiscoveryImageSignaturePublicKeyPath).NotTo(BeEmpty(), fmt.Sprintf("environment variable %s should set with local central repository discovery image signature public key path", framework.TanzuCliE2ETestLocalCentralRepositoryPluginDiscoveryImageSignaturePublicKeyPath))
os.Setenv("TANZU_CLI_PLUGIN_DISCOVERY_IMAGE_SIGNATURE_PUBLIC_KEY_PATH", e2eTestLocalCentralRepoPluginDiscoveryImageSignaturePublicKeyPath)

// search plugin groups and make sure there plugin groups available
pluginGroups = pluginlifecyclee2e.SearchAllPluginGroups(tf)

// Make sure airgapped plugin inventory image doesn't exists before starting the tests
_, _, err = carvelhelpers.GetImageDigest(e2eAirgappedCentralRepoImage)
Expect(err).NotTo(BeNil(), "looks like airgapped plugin inventory image already exists before starting the airgapped tests. This should not be the case as it leads to incorrect test results")

// check all required plugin groups are available in the central repository with plugin group search output before running airgapped tests
Expect(framework.IsAllPluginGroupsExists(pluginGroups, framework.PluginGroupsForLifeCycleTests)).Should(BeTrue(), "all required plugin groups for life cycle tests should exists in plugin group search output")

// search plugins and make sure there are plugins available
pluginsSearchList = pluginlifecyclee2e.SearchAllPlugins(tf)
Expect(len(pluginsSearchList)).Should(BeNumerically(">", 0))

// check all required plugins are available in the central repository with plugin search output before running airgapped tests
Expect(framework.CheckAllPluginsExists(pluginsSearchList, framework.PluginsForLifeCycleTests)).To(BeTrue())

// Configure temporary directory to save the plugin bundles for tests
tempDir, err = os.MkdirTemp("", "")
Expect(err).To(BeNil())
})

var _ = AfterSuite(func() {
_ = os.RemoveAll(tempDir)
})
Loading

0 comments on commit ee05e1d

Please sign in to comment.