Skip to content

Commit

Permalink
Randomize cdi namespace in tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Wels <awels@redhat.com>
  • Loading branch information
awels committed May 14, 2019
1 parent f242869 commit f40c16b
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -163,7 +163,7 @@ format:
${DO} "./hack/build/format.sh"

manifests:
${DO} "CSV_VERSION=${CSV_VERSION} QUAY_NAMESPACE=${QUAY_NAMESPACE} QUAY_REPOSITORY=${QUAY_REPOSITORY} DOCKER_REPO=${DOCKER_REPO} DOCKER_TAG=${DOCKER_TAG} VERBOSITY=${VERBOSITY} PULL_POLICY=${PULL_POLICY} ./hack/build/build-manifests.sh"
${DO} "CSV_VERSION=${CSV_VERSION} QUAY_NAMESPACE=${QUAY_NAMESPACE} QUAY_REPOSITORY=${QUAY_REPOSITORY} DOCKER_REPO=${DOCKER_REPO} DOCKER_TAG=${DOCKER_TAG} VERBOSITY=${VERBOSITY} PULL_POLICY=${PULL_POLICY} NAMESPACE=${NAMESPACE} ./hack/build/build-manifests.sh"

goveralls:
${DO} "TRAVIS_JOB_ID=${TRAVIS_JOB_ID} TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST} TRAVIS_BRANCH=${TRAVIS_BRANCH} ./hack/build/goveralls.sh"
Expand Down
5 changes: 5 additions & 0 deletions automation/test.sh
Expand Up @@ -24,6 +24,11 @@

set -ex

export NAMESPACE="cdi-$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 5 | head -n 1)"
export CDI_NAMESPACE=$NAMESPACE

echo "namespace: ${NAMESPACE}, cdi-namespace: ${CDI_NAMESPACE}"

export WORKSPACE="${WORKSPACE:-$PWD}"
readonly ARTIFACTS_PATH="exported-artifacts"

Expand Down
4 changes: 2 additions & 2 deletions tests/cloner_test.go
Expand Up @@ -87,8 +87,8 @@ var _ = Describe("Block PV Cloner Test", func() {
err := f.ClearBlockPV()
Expect(err).NotTo(HaveOccurred())

pod, err := utils.FindPodByPrefix(f.K8sClient, "cdi", "cdi-block-device", "kubevirt.io=cdi-block-device")
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Unable to get pod %q", "cdi"+"/"+"cdi-block-device"))
pod, err := utils.FindPodByPrefix(f.K8sClient, f.CdiInstallNs, "cdi-block-device", "kubevirt.io=cdi-block-device")
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Unable to get pod %q", f.CdiInstallNs+"/"+"cdi-block-device"))
nodeName := pod.Spec.NodeName

By(fmt.Sprintf("Creating storageClass for Block PVs"))
Expand Down
26 changes: 15 additions & 11 deletions tests/datavolume_test.go
Expand Up @@ -37,6 +37,10 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",

f := framework.NewFrameworkOrDie("dv-func-test")

tinyCoreIsoURL := fmt.Sprintf(utils.TinyCoreIsoURL, f.CdiInstallNs)
httpsTinyCoreIsoURL := fmt.Sprintf(utils.HTTPSTinyCoreIsoURL, f.CdiInstallNs)
tinyCoreIsoRegistryURL := fmt.Sprintf(utils.TinyCoreIsoRegistryURL, f.CdiInstallNs)

AfterEach(func() {
if sourcePvc != nil {
By("[AfterEach] Clean up target PVC")
Expand All @@ -54,7 +58,7 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",
dataVolume = utils.NewDataVolumeWithHTTPImport(dataVolumeName, "1Gi", url)
case "import-https":
dataVolume = utils.NewDataVolumeWithHTTPImport(dataVolumeName, "1Gi", url)
cm, err := utils.CopyFileHostCertConfigMap(f.K8sClient, f.Namespace.Name)
cm, err := utils.CopyFileHostCertConfigMap(f.K8sClient, f.Namespace.Name, f.CdiInstallNs)
Expect(err).To(BeNil())
dataVolume.Spec.Source.HTTP.CertConfigMap = cm
case "blank":
Expand All @@ -70,7 +74,7 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",
dataVolume = utils.NewCloningDataVolume(dataVolumeName, "1Gi", sourcePvc)
case "import-registry":
dataVolume = utils.NewDataVolumeWithRegistryImport(dataVolumeName, "1Gi", url)
cm, err := utils.CopyRegistryCertConfigMap(f.K8sClient, f.Namespace.Name)
cm, err := utils.CopyRegistryCertConfigMap(f.K8sClient, f.Namespace.Name, f.CdiInstallNs)
Expect(err).To(BeNil())
dataVolume.Spec.Source.Registry.CertConfigMap = cm
}
Expand Down Expand Up @@ -110,14 +114,14 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",
Expect(err).ToNot(HaveOccurred())

},
table.Entry("[rfe_id:1115][crit:high][test_id:1357]succeed creating import dv with given valid url", "import-http", "", utils.TinyCoreIsoURL, "dv-phase-test-1", controller.ImportSucceeded, cdiv1.Succeeded),
table.Entry("[rfe_id:1115][crit:high][test_id:1357]succeed creating import dv with given valid url", "import-http", "", tinyCoreIsoURL, "dv-phase-test-1", controller.ImportSucceeded, cdiv1.Succeeded),
table.Entry("[rfe_id:1115][crit:high][posneg:negative][test_id:1358]fail creating import dv due to invalid DNS entry", "import-http", "", "http://i-made-this-up.kube-system/tinyCore.iso", "dv-phase-test-2", controller.ImportFailed, cdiv1.Failed),
table.Entry("[rfe_id:1115][crit:high][posneg:negative][test_id:1359]fail creating import dv due to file not found", "import-http", "", utils.TinyCoreIsoURL+"not.real.file", "dv-phase-test-3", controller.ImportFailed, cdiv1.Failed),
table.Entry("[rfe_id:1115][crit:high][posneg:negative][test_id:1359]fail creating import dv due to file not found", "import-http", "", tinyCoreIsoURL+"not.real.file", "dv-phase-test-3", controller.ImportFailed, cdiv1.Failed),
table.Entry("[rfe_id:1277][crit:high][test_id:1360]succeed creating clone dv", "clone", fillCommand, "", "dv-clone-test-1", controller.CloneSucceeded, cdiv1.Succeeded),
table.Entry("[rfe_id:1111][crit:high][test_id:1361]succeed creating blank image dv", "blank", "", "", "blank-image-dv", controller.ImportSucceeded, cdiv1.Succeeded),
table.Entry("[rfe_id:138][crit:high][test_id:1362]succeed creating upload dv", "upload", "", "", "upload-dv", controller.UploadReady, cdiv1.Succeeded),
table.Entry("[rfe_id:1115][crit:high][test_id:1478]succeed creating import dv with given valid registry url", "import-registry", "", utils.TinyCoreIsoRegistryURL, "dv-phase-test-4", controller.ImportSucceeded, cdiv1.Succeeded),
table.Entry("[rfe_id:1115][crit:high][test_id:1379]succeed creating import dv with given valid url (https)", "import-https", "", utils.HTTPSTinyCoreIsoURL, "dv-phase-test-1", controller.ImportSucceeded, cdiv1.Succeeded),
table.Entry("[rfe_id:1115][crit:high][test_id:1478]succeed creating import dv with given valid registry url", "import-registry", "", tinyCoreIsoRegistryURL, "dv-phase-test-4", controller.ImportSucceeded, cdiv1.Succeeded),
table.Entry("[rfe_id:1115][crit:high][test_id:1379]succeed creating import dv with given valid url (https)", "import-https", "", httpsTinyCoreIsoURL, "dv-phase-test-1", controller.ImportSucceeded, cdiv1.Succeeded),
)
})

Expand All @@ -132,8 +136,8 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",
storageClass, err = f.CreateStorageClassFromDefinition(utils.NewStorageClassForBlockPVDefinition("manual"))
Expect(err).ToNot(HaveOccurred())

pod, err = utils.FindPodByPrefix(f.K8sClient, "cdi", "cdi-block-device", "kubevirt.io=cdi-block-device")
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Unable to get pod %q", "cdi"+"/"+"cdi-block-device"))
pod, err = utils.FindPodByPrefix(f.K8sClient, f.CdiInstallNs, "cdi-block-device", "kubevirt.io=cdi-block-device")
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Unable to get pod %q", f.CdiInstallNs+"/"+"cdi-block-device"))

nodeName := pod.Spec.NodeName

Expand Down Expand Up @@ -196,7 +200,7 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",
Expect(err).ToNot(HaveOccurred())

},
table.Entry("succeed creating import dv with given valid url", "import-http", "", utils.TinyCoreIsoURL, "dv-phase-test-1", controller.ImportSucceeded, cdiv1.Succeeded),
table.Entry("succeed creating import dv with given valid url", "import-http", "", tinyCoreIsoURL, "dv-phase-test-1", controller.ImportSucceeded, cdiv1.Succeeded),
)
})

Expand Down Expand Up @@ -248,7 +252,7 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",
Describe("Create/Delete same datavolume in a loop", func() {
Context("retry loop", func() {
dataVolumeName := "dv1"
url := utils.TinyCoreIsoURL
url := fmt.Sprintf(utils.TinyCoreIsoURL, f.CdiInstallNs)
numTries := 5
for i := 1; i <= numTries; i++ {
It(fmt.Sprintf("should succeed on loop %d", i), func() {
Expand All @@ -272,7 +276,7 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",

Describe("Progress reporting on import datavolume", func() {
It("Should report progress while importing", func() {
dataVolume := utils.NewDataVolumeWithHTTPImport(dataVolumeName, "1Gi", utils.TinyCoreQcow2URLRateLimit)
dataVolume := utils.NewDataVolumeWithHTTPImport(dataVolumeName, "1Gi", fmt.Sprintf(utils.TinyCoreQcow2URLRateLimit, f.CdiInstallNs))
By(fmt.Sprintf("creating new datavolume %s", dataVolume.Name))
dataVolume, err := utils.CreateDataVolumeFromDefinition(f.CdiClient, f.Namespace.Name, dataVolume)
Expect(err).ToNot(HaveOccurred())
Expand Down
8 changes: 4 additions & 4 deletions tests/import_test.go
Expand Up @@ -145,7 +145,7 @@ var _ = Describe("[rfe_id:1118][crit:high][vendor:cnv-qe@redhat.com][level:compo
It("Import pod should have prometheus stats available while importing", func() {
c := f.K8sClient
ns := f.Namespace.Name
httpEp := fmt.Sprintf("http://%s:%d", utils.FileHostName+"."+utils.FileHostNs, utils.HTTPRateLimitPort)
httpEp := fmt.Sprintf("http://%s:%d", utils.FileHostName+"."+f.CdiInstallNs, utils.HTTPRateLimitPort)
pvcAnn := map[string]string{
controller.AnnEndpoint: httpEp + "/tinyCore.qcow2",
controller.AnnSecret: "",
Expand Down Expand Up @@ -234,8 +234,8 @@ var _ = Describe("Importer Test Suite-Block_device", func() {
err = f.ClearBlockPV()
Expect(err).NotTo(HaveOccurred())

pod, err = utils.FindPodByPrefix(f.K8sClient, "cdi", "cdi-block-device", "kubevirt.io=cdi-block-device")
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Unable to get pod %q", "cdi"+"/"+"cdi-block-device"))
pod, err = utils.FindPodByPrefix(f.K8sClient, f.CdiInstallNs, "cdi-block-device", "kubevirt.io=cdi-block-device")
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Unable to get pod %q", f.CdiInstallNs+"/"+"cdi-block-device"))

nodeName := pod.Spec.NodeName

Expand All @@ -261,7 +261,7 @@ var _ = Describe("Importer Test Suite-Block_device", func() {
})

It("Should create import pod for block pv", func() {
httpEp := fmt.Sprintf("http://%s:%d", utils.FileHostName+"."+utils.FileHostNs, utils.HTTPNoAuthPort)
httpEp := fmt.Sprintf("http://%s:%d", utils.FileHostName+"."+f.CdiInstallNs, utils.HTTPNoAuthPort)
pvcAnn := map[string]string{
controller.AnnEndpoint: httpEp + "/tinyCore.iso",
}
Expand Down
2 changes: 1 addition & 1 deletion tests/local_volume_test.go
Expand Up @@ -34,7 +34,7 @@ var _ = Describe("[rfe_id:1125][crit:high][vendor:cnv-qe@redhat.com][level:compo
Expect(err).ToNot(HaveOccurred())

By("Creating PVC with a selector field matches the PV's label")
httpEp := fmt.Sprintf("http://%s:%d", utils.FileHostName+"."+utils.FileHostNs, utils.HTTPNoAuthPort)
httpEp := fmt.Sprintf("http://%s:%d", utils.FileHostName+"."+f.CdiInstallNs, utils.HTTPNoAuthPort)
_, err = f.CreatePVCFromDefinition(utils.NewPVCDefinitionWithSelector("local-volume-pvc",
"1G",
map[string]string{"node": node},
Expand Down
16 changes: 8 additions & 8 deletions tests/transport_test.go
Expand Up @@ -38,8 +38,8 @@ var _ = Describe("Transport Tests", func() {

BeforeEach(func() {
ns = f.Namespace.Name
By(fmt.Sprintf("Waiting for all \"%s/%s\" deployment replicas to be Ready", utils.FileHostNs, utils.FileHostName))
utils.WaitForDeploymentReplicasReadyOrDie(c, utils.FileHostNs, utils.FileHostName)
By(fmt.Sprintf("Waiting for all \"%s/%s\" deployment replicas to be Ready", f.CdiInstallNs, utils.FileHostName))
utils.WaitForDeploymentReplicasReadyOrDie(c, f.CdiInstallNs, utils.FileHostName)
})

// it() is the body of the test and is executed once per Entry() by DescribeTable()
Expand Down Expand Up @@ -80,9 +80,9 @@ var _ = Describe("Transport Tests", func() {
}

if insecureRegistry {
err = utils.SetInsecureRegistry(c)
err = utils.SetInsecureRegistry(c, f.CdiInstallNs)
Expect(err).To(BeNil())
defer utils.ClearInsecureRegistry(c)
defer utils.ClearInsecureRegistry(c, f.CdiInstallNs)
}

By(fmt.Sprintf("Creating PVC with endpoint annotation %q", pvcAnn[controller.AnnEndpoint]))
Expand Down Expand Up @@ -122,10 +122,10 @@ var _ = Describe("Transport Tests", func() {
}
}

httpNoAuthEp := fmt.Sprintf("http://%s:%d", utils.FileHostName+"."+utils.FileHostNs, utils.HTTPNoAuthPort)
httpsNoAuthEp := fmt.Sprintf("https://%s:%d", utils.FileHostName+"."+utils.FileHostNs, utils.HTTPSNoAuthPort)
httpAuthEp := fmt.Sprintf("http://%s:%d", utils.FileHostName+"."+utils.FileHostNs, utils.HTTPAuthPort)
registryNoAuthEp := fmt.Sprintf("docker://%s", utils.RegistryHostName+"."+utils.RegistryHostNs)
httpNoAuthEp := fmt.Sprintf("http://%s:%d", utils.FileHostName+"."+f.CdiInstallNs, utils.HTTPNoAuthPort)
httpsNoAuthEp := fmt.Sprintf("https://%s:%d", utils.FileHostName+"."+f.CdiInstallNs, utils.HTTPSNoAuthPort)
httpAuthEp := fmt.Sprintf("http://%s:%d", utils.FileHostName+"."+f.CdiInstallNs, utils.HTTPAuthPort)
registryNoAuthEp := fmt.Sprintf("docker://%s", utils.RegistryHostName+"."+f.CdiInstallNs)
DescribeTable("Transport Test Table", it,
Entry("should connect to http endpoint without credentials", httpNoAuthEp, targetFile, "", "", controller.SourceHTTP, "", false, true),
Entry("should connect to http endpoint with credentials", httpAuthEp, targetFile, utils.AccessKeyValue, utils.SecretKeyValue, controller.SourceHTTP, "", false, true),
Expand Down
4 changes: 2 additions & 2 deletions tests/upload_test.go
Expand Up @@ -185,8 +185,8 @@ var _ = Describe("Block PV upload Test", func() {
err := f.ClearBlockPV()
Expect(err).NotTo(HaveOccurred())

pod, err := utils.FindPodByPrefix(f.K8sClient, "cdi", "cdi-block-device", "kubevirt.io=cdi-block-device")
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Unable to get pod %q", "cdi"+"/"+"cdi-block-device"))
pod, err := utils.FindPodByPrefix(f.K8sClient, f.CdiInstallNs, "cdi-block-device", "kubevirt.io=cdi-block-device")
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Unable to get pod %q", f.CdiInstallNs+"/"+"cdi-block-device"))

nodeName := pod.Spec.NodeName

Expand Down
4 changes: 0 additions & 4 deletions tests/utils/common.go
Expand Up @@ -4,12 +4,8 @@ package utils
const (
//RegistryHostName provides a deploymnet and service name for registry
RegistryHostName = "cdi-docker-registry-host"
// RegistryHostNs provides a deployment ans service namespace for tests
RegistryHostNs = "cdi"
// FileHostName provides a deployment and service name for tests
FileHostName = "cdi-file-host"
// FileHostNs provides a deployment ans service namespace for tests
FileHostNs = "cdi"
// FileHostS3Bucket provides an S3 bucket name for tests (e.g. http://<serviceIP:port>/FileHostS3Bucket/image)
FileHostS3Bucket = "images"
// AccessKeyValue provides a username to use for http and S3 (see hack/build/docker/cdi-func-test-file-host-http/htpasswd)
Expand Down
30 changes: 15 additions & 15 deletions tests/utils/configmaps.go
Expand Up @@ -12,20 +12,20 @@ import (
"kubevirt.io/containerized-data-importer/pkg/util"
)

const registryHostname = RegistryHostName + "." + RegistryHostNs
//const registryHostname = RegistryHostName + "." + RegistryHostNs

// CopyRegistryCertConfigMap copies the test registry configmap
func CopyRegistryCertConfigMap(client kubernetes.Interface, destNamespace string) (string, error) {
n, err := CopyConfigMap(client, RegistryHostNs, RegistryCertConfigMap, destNamespace, "")
// CopyRegistryCertConfigMap copies the test registry configmap, it assumes the Registry host is in the CDI namespace
func CopyRegistryCertConfigMap(client kubernetes.Interface, destNamespace, cdiNamespace string) (string, error) {
n, err := CopyConfigMap(client, cdiNamespace, RegistryCertConfigMap, destNamespace, "")
if err != nil {
return "", err
}
return n, nil
}

// CopyFileHostCertConfigMap copies the test file host configmap
func CopyFileHostCertConfigMap(client kubernetes.Interface, destNamespace string) (string, error) {
n, err := CopyConfigMap(client, FileHostNs, FileHostCertConfigMap, destNamespace, "")
// CopyFileHostCertConfigMap copies the test file host configmap, it assumes the File host is in the CDI namespace
func CopyFileHostCertConfigMap(client kubernetes.Interface, destNamespace, cdiNamespace string) (string, error) {
n, err := CopyConfigMap(client, cdiNamespace, FileHostCertConfigMap, destNamespace, "")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -64,8 +64,8 @@ func CopyConfigMap(client kubernetes.Interface, srcNamespace, srcName, destNames
}

// SetInsecureRegistry sets the configmap entry to mark the registry as okay to be insecure
func SetInsecureRegistry(client kubernetes.Interface) error {
cm, err := client.CoreV1().ConfigMaps(RegistryHostNs).Get(common.InsecureRegistryConfigMap, metav1.GetOptions{})
func SetInsecureRegistry(client kubernetes.Interface, cdiNamespace string) error {
cm, err := client.CoreV1().ConfigMaps(cdiNamespace).Get(common.InsecureRegistryConfigMap, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -74,9 +74,9 @@ func SetInsecureRegistry(client kubernetes.Interface) error {
cm.Data = map[string]string{}
}

cm.Data[registryHostname] = ""
cm.Data[RegistryHostName+"."+cdiNamespace] = ""

_, err = client.CoreV1().ConfigMaps(RegistryHostNs).Update(cm)
_, err = client.CoreV1().ConfigMaps(cdiNamespace).Update(cm)
if err != nil {
return err
}
Expand All @@ -85,15 +85,15 @@ func SetInsecureRegistry(client kubernetes.Interface) error {
}

// ClearInsecureRegistry undoes whatever SetInsecureRegistry does
func ClearInsecureRegistry(client kubernetes.Interface) error {
cm, err := client.CoreV1().ConfigMaps(RegistryHostNs).Get(common.InsecureRegistryConfigMap, metav1.GetOptions{})
func ClearInsecureRegistry(client kubernetes.Interface, cdiNamespace string) error {
cm, err := client.CoreV1().ConfigMaps(cdiNamespace).Get(common.InsecureRegistryConfigMap, metav1.GetOptions{})
if err != nil {
return err
}

delete(cm.Data, registryHostname)
delete(cm.Data, RegistryHostName+"."+cdiNamespace)

_, err = client.CoreV1().ConfigMaps(RegistryHostNs).Update(cm)
_, err = client.CoreV1().ConfigMaps(cdiNamespace).Update(cm)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions tests/utils/datavolume.go
Expand Up @@ -23,13 +23,13 @@ const (

const (
// TinyCoreIsoURL provides a test url for the tineyCore iso image
TinyCoreIsoURL = "http://cdi-file-host.cdi/tinyCore.iso"
TinyCoreIsoURL = "http://cdi-file-host.%s/tinyCore.iso"
//TinyCoreIsoRegistryURL provides a test url for the tinycore.qcow2 image wrapped in docker container
TinyCoreIsoRegistryURL = "docker://cdi-docker-registry-host.cdi/tinycoreqcow2"
TinyCoreIsoRegistryURL = "docker://cdi-docker-registry-host.%s/tinycoreqcow2"
// HTTPSTinyCoreIsoURL provides a test (https) url for the tineyCore iso image
HTTPSTinyCoreIsoURL = "https://cdi-file-host.cdi/tinyCore.iso"
HTTPSTinyCoreIsoURL = "https://cdi-file-host.%s/tinyCore.iso"
// TinyCoreQcow2URLRateLimit provides a test url for the tineyCore iso image
TinyCoreQcow2URLRateLimit = "http://cdi-file-host.cdi:82/tinyCore.qcow2"
TinyCoreQcow2URLRateLimit = "http://cdi-file-host.%s:82/tinyCore.qcow2"
)

// CreateDataVolumeFromDefinition is used by tests to create a testable Data Volume
Expand Down

0 comments on commit f40c16b

Please sign in to comment.