/
githubmirror
/
origin
Обзор
Документация
Войти
/
githubmirror
/
origin
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
test/extended/image_ecosystem/s2i_python.go
141 строка
6 KB
Maciej Szulik
Adopt to v2 by migrating from CurrentGinkgoTestDescription() to CurrentSpecReport()
07 ноя 2022, 15:21
Не верифицирован
07 ноя 2022, 15:21
184bbf0
Код
Авторство
О чём код?
package image_ecosystem import ( "context" "fmt" "strings" "time" g "github.com/onsi/ginkgo/v2" o "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/util/wait" e2e "k8s.io/kubernetes/test/e2e/framework" exutil "github.com/openshift/origin/test/extended/util" ) var _ = g.Describe("[sig-devex][Feature:ImageEcosystem][python][Slow] hot deploy for openshift python image", func() { defer g.GinkgoRecover() var ( oc = exutil.NewCLI("s2i-python") djangoTemplate = "django-psql-example" modifyCommand = []string{"sed", "-ie", `s/'count': PageView.objects.count()/'count': 1337/`, "welcome/views.py"} pageCountFn = func(count int) string { return fmt.Sprintf("Page views: %d", count) } dcName = "django-psql-example" rcNameOne = fmt.Sprintf("%s-1", dcName) rcNameTwo = fmt.Sprintf("%s-2", dcName) dcLabelOne = exutil.ParseLabelsOrDie(fmt.Sprintf("deployment=%s", rcNameOne)) dcLabelTwo = exutil.ParseLabelsOrDie(fmt.Sprintf("deployment=%s", rcNameTwo)) ) g.Context("", func() { g.JustBeforeEach(func() { exutil.PreTestDump() }) g.AfterEach(func() { if g.CurrentSpecReport().Failed() { exutil.DumpPodStates(oc) exutil.DumpPodLogsStartingWith("", oc) } }) g.Describe("Django example", func() { g.It(fmt.Sprintf("should work with hot deploy [apigroup:image.openshift.io][apigroup:operator.openshift.io][apigroup:config.openshift.io][apigroup:build.openshift.io]"), func() { // skipping this test for now until we figure out why is not // passing on CI bz: 2023238 g.Skip("Skipping until bz_2023238 is fixed.") err := exutil.WaitForOpenShiftNamespaceImageStreams(oc) o.Expect(err).NotTo(o.HaveOccurred()) g.By(fmt.Sprintf("calling oc new-app %s", djangoTemplate)) // gunicorn workers read the application source lazily. For // this test to succeed reliably, we must have one worker only // (WEB_CONCURRENCY=1). Having primed the worker via // assertPageCountIs, we can then expect it not to read in the // modified application source when hot deploy is disabled. err = oc.Run("new-app").Args(djangoTemplate, "-e", "WEB_CONCURRENCY=1").Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("waiting for build to finish") err = exutil.WaitForABuild(oc.BuildClient().BuildV1().Builds(oc.Namespace()), rcNameOne, nil, nil, nil) if err != nil { exutil.DumpBuildLogs(dcName, oc) } o.Expect(err).NotTo(o.HaveOccurred()) err = exutil.WaitForDeploymentConfig(oc.KubeClient(), oc.AppsClient().AppsV1(), oc.Namespace(), dcName, 1, true, oc) o.Expect(err).NotTo(o.HaveOccurred()) g.By("waiting for endpoint") err = exutil.WaitForEndpoint(oc.KubeFramework().ClientSet, oc.Namespace(), dcName) o.Expect(err).NotTo(o.HaveOccurred()) oldEndpoint, err := oc.KubeFramework().ClientSet.CoreV1().Endpoints(oc.Namespace()).Get(context.Background(), dcName, metav1.GetOptions{}) o.Expect(err).NotTo(o.HaveOccurred()) assertPageCountIs := func(i int, dcLabel labels.Selector) { _, err := exutil.WaitForPods(oc.KubeClient().CoreV1().Pods(oc.Namespace()), dcLabel, exutil.CheckPodIsRunning, 1, 4*time.Minute) o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred()) result, err := CheckPageContains(oc, dcName, "", pageCountFn(i)) if err != nil || !result { exutil.DumpApplicationPodLogs(dcName, oc) } o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred()) o.ExpectWithOffset(1, result).To(o.BeTrue()) } g.By("checking page count") assertPageCountIs(1, dcLabelOne) assertPageCountIs(2, dcLabelOne) g.By("modifying the source code with disabled hot deploy") err = RunInPodContainer(oc, dcLabelOne, modifyCommand) o.Expect(err).NotTo(o.HaveOccurred()) assertPageCountIs(3, dcLabelOne) pods, err := oc.KubeClient().CoreV1().Pods(oc.Namespace()).List(context.Background(), metav1.ListOptions{LabelSelector: dcLabelOne.String()}) o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(len(pods.Items)).To(o.Equal(1)) g.By("turning on hot-deploy") err = oc.Run("set", "env").Args("dc", dcName, "APP_CONFIG=conf/reload.py").Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = exutil.WaitForDeploymentConfig(oc.KubeClient(), oc.AppsClient().AppsV1(), oc.Namespace(), dcName, 2, true, oc) o.Expect(err).NotTo(o.HaveOccurred()) g.By("waiting for a new endpoint") err = exutil.WaitForEndpoint(oc.KubeFramework().ClientSet, oc.Namespace(), dcName) o.Expect(err).NotTo(o.HaveOccurred()) // Ran into an issue where we'd try to hit the endpoint before it was updated, resulting in // request timeouts against the previous pod's ip. So make sure the endpoint is pointing to the // new pod before hitting it. err = wait.Poll(1*time.Second, 1*time.Minute, func() (bool, error) { newEndpoint, err := oc.KubeFramework().ClientSet.CoreV1().Endpoints(oc.Namespace()).Get(context.Background(), dcName, metav1.GetOptions{}) if err != nil { return false, err } if !strings.Contains(newEndpoint.Subsets[0].Addresses[0].TargetRef.Name, rcNameTwo) { e2e.Logf("waiting on endpoint address ref %s to contain %s", newEndpoint.Subsets[0].Addresses[0].TargetRef.Name, rcNameTwo) return false, nil } e2e.Logf("old endpoint was %#v, new endpoint is %#v", oldEndpoint, newEndpoint) return true, nil }) o.Expect(err).NotTo(o.HaveOccurred()) g.By("modifying the source code with enabled hot deploy") // now using a persistent template, the count does not reset assertPageCountIs(4, dcLabelTwo) err = RunInPodContainer(oc, dcLabelTwo, modifyCommand) o.Expect(err).NotTo(o.HaveOccurred()) assertPageCountIs(1337, dcLabelTwo) }) }) }) })