Skip to content

Commit

Permalink
MGMT-6411 Discovery image deleted on cluster removal
Browse files Browse the repository at this point in the history
When removing a cluster, its discovery-image should be deleted as well.

Signed-off-by: Moti Asayag <[email protected]>
  • Loading branch information
masayag committed May 18, 2021
1 parent 32486e6 commit 7918423
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
66 changes: 66 additions & 0 deletions subsystem/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions subsystem/subsystem_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 7918423

Please sign in to comment.