diff --git a/Makefile b/Makefile index 5d87f944d56..742f543786a 100644 --- a/Makefile +++ b/Makefile @@ -421,6 +421,7 @@ $(REPORTS): -mkdir -p $(REPORTS) test-onprem: + WORK_DIR=$(shell podman inspect $(shell podman ps | grep /assisted-service | cut -f1 -d" ") | jq -r '.[].GraphDriver.Data.UpperDir')/data \ INVENTORY=127.0.0.1:8090 \ DB_HOST=127.0.0.1 \ DB_PORT=5432 \ diff --git a/subsystem/cluster_test.go b/subsystem/cluster_test.go index 2c4c9819cde..4ef92c67845 100644 --- a/subsystem/cluster_test.go +++ b/subsystem/cluster_test.go @@ -36,6 +36,7 @@ import ( "github.com/openshift/assisted-service/models" "github.com/openshift/assisted-service/pkg/auth" "github.com/openshift/assisted-service/pkg/conversions" + "github.com/openshift/assisted-service/pkg/s3wrapper" ) // #nosec @@ -3234,6 +3235,71 @@ var _ = Describe("Update cluster with OLM operators", func() { }) }) +var _ = FDescribe("Verify ISO is deleted on cluster de-registration", func() { + var ( + ctx context.Context = context.Background() + clusterID strfmt.UUID + ) + + BeforeEach(func() { + var err error + clusterID, err = registerCluster(ctx, userBMClient, "test-deregister-cluster", pullSecret) + Expect(err).NotTo(HaveOccurred()) + }) + + AfterEach(func() { + clearDB() + }) + + Context("Deregister cluster deletes cluster resources test", func() { + if Options.Storage != "filesystem" || Options.DeployTarget != "onprem" { + return + } + + It("Deregister cluster deletes discovery image from Filesystem test", func() { + By("Generate discovery image for cluster") + imageType := models.ImageTypeMinimalIso + _, err := userBMClient.Installer.GenerateClusterISO(ctx, &installer.GenerateClusterISOParams{ + ClusterID: clusterID, + ImageCreateParams: &models.ImageCreateParams{ + ImageType: imageType, + }, + }) + + Expect(err).NotTo(HaveOccurred()) + verifyEventExistence(clusterID, fmt.Sprintf("Image type is \"%s\"", imageType)) + + By("verify discovery-image existence") + file, err := ioutil.TempFile("", "tmp") + if err != nil { + log.Fatal(err) + } + defer os.Remove(file.Name()) + _, err = userBMClient.Installer.DownloadClusterISO(ctx, &installer.DownloadClusterISOParams{ClusterID: clusterID}, file) + Expect(err).NotTo(HaveOccurred()) + fsClient := s3wrapper.NewFSClient(Options.WorkDir, log, nil, nil, nil, 0) + discoveryImage := fmt.Sprintf("%s.iso", fmt.Sprintf(s3wrapper.DiscoveryImageTemplate, clusterID)) + exists, err := fsClient.DoesObjectExist(ctx, discoveryImage) + Expect(err).NotTo(HaveOccurred()) + Expect(exists).To(BeTrue()) + + By("deregister cluster") + _, err = userBMClient.Installer.DeregisterCluster(ctx, &installer.DeregisterClusterParams{ + ClusterID: clusterID, + }) + Expect(err).NotTo(HaveOccurred()) + + By("verify discovery-image cannot be downloaded") + _, err = userBMClient.Installer.DownloadClusterISO(ctx, &installer.DownloadClusterISOParams{ClusterID: clusterID}, file) + Expect(err).To(HaveOccurred()) + exists, err = fsClient.DoesObjectExist(ctx, discoveryImage) + Expect(err).NotTo(HaveOccurred()) + Expect(exists).To(BeFalse()) + + }) + }) +}) + func registerHostsAndSetRoles(clusterID strfmt.UUID, numHosts int) []*models.Host { ctx := context.Background() hosts := make([]*models.Host, 0) diff --git a/subsystem/subsystem_suite_test.go b/subsystem/subsystem_suite_test.go index 25da17ef54a..d03448d651b 100644 --- a/subsystem/subsystem_suite_test.go +++ b/subsystem/subsystem_suite_test.go @@ -50,6 +50,7 @@ var Options struct { OCMHost string `envconfig:"OCM_HOST"` DeployTarget string `envconfig:"DEPLOY_TARGET" default:"k8s"` Storage string `envconfig:"STORAGE" default:""` + WorkDir string `envconfig:"WORK_DIR" default:"/data/"` Namespace string `envconfig:"NAMESPACE" default:"assisted-installer"` EnableKubeAPI bool `envconfig:"ENABLE_KUBE_API" default:"false"` WithAMSSubscriptions bool `envconfig:"WITH_AMS_SUBSCRIPTIONS" default:"false"`