containerized-data-importer/tests/badserver_test.go
Maya Rashish 5fede6938b
Make it possible to import images needing conversion from servers that don't support range requests (#1326)
* Combine tests in bad_webserver.go into a table

No functional change intended.

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Use a QCOW2 image for testing badserver.

This has the benefit of going through qemu-img for conversion,
which can introduce more bugs.

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Don't pass URLs to qemu-img if Accept-Ranges header isn't bytes.

Adapt unit tests so they don't also test this feature.
Add a handler to bad-webserver to do a very plain HTTP response
using a downloaded file from cdi-file-host. This one doesn't
come with builtin support for range requests.

Use this handler to test that CDI can still import images needing
conversion.

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Invert polarity and test for "none".

It's highly unlikely that a value other than bytes becomes a
valid choice, but let's not rule that out.

Signed-off-by: Maya Rashish <mrashish@redhat.com>
2020-08-12 18:11:55 +02:00

44 lines
1.7 KiB
Go

package tests
import (
"fmt"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
"kubevirt.io/containerized-data-importer/tests/framework"
"kubevirt.io/containerized-data-importer/tests/utils"
cdiv1 "kubevirt.io/containerized-data-importer/pkg/apis/core/v1beta1"
)
var _ = Describe("Problematic server responses", func() {
f := framework.NewFramework("badserver-func-test")
const dvWaitTimeout = 500 * time.Second
var dataVolume *cdiv1.DataVolume
DescribeTable("Importing from cdi bad web server", func(pathname string) {
cdiBadServer := fmt.Sprintf("http://cdi-bad-webserver.%s:9090", f.CdiInstallNs)
dataVolume = utils.NewDataVolumeWithHTTPImport("badserver-dv", "1Gi", cdiBadServer+pathname)
By("creating DataVolume")
dataVolume, err := utils.CreateDataVolumeFromDefinition(f.CdiClient, f.Namespace.Name, dataVolume)
Expect(err).ToNot(HaveOccurred())
f.ForceBindPvcIfDvIsWaitForFirstConsumer(dataVolume)
err = utils.WaitForDataVolumePhase(f.CdiClient, f.Namespace.Name, cdiv1.Succeeded, dataVolume.Name)
Expect(err).ToNot(HaveOccurred())
},
Entry("[rfe_id:4109][test_id:4110][crit:low][vendor:cnv-qe@redhat.com][level:component] Should succeed even if HEAD forbidden", "/forbidden-HEAD/cirros-qcow2.img"),
Entry("[rfe_id:4191][test_id:4193][crit:low][vendor:cnv-qe@redhat.com][level:component] Should succeed even on a flaky server", "/flaky/cirros-qcow2.img"),
Entry("Should succeed even if Accept-Ranges doesn't exist", "/no-accept-ranges/cirros-qcow2.img"),
)
AfterEach(func() {
By("deleting DataVolume")
err := utils.DeleteDataVolume(f.CdiClient, f.Namespace.Name, dataVolumeName)
Expect(err).ToNot(HaveOccurred())
})
})