Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MGMT-15295: Fix bug in list manifests #5366

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions internal/manifests/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ func (m *Manifests) ListClusterManifestsInternal(ctx context.Context, params ope
}
if isUserManifest {
manifests = append(manifests, &models.Manifest{FileName: filename, Folder: folder})
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regarding line 154 - if the cluster doesn't exist please replace the "Object not found" message and use something like https://github.com/openshift/assisted-service/blob/master/internal/bminventory/inventory.go#L1535

return nil, common.NewApiError(http.StatusInternalServerError, errors.Errorf("Cannot list file %s in cluster %s", file, params.ClusterID.String()))
}
}
return manifests, nil
Expand Down
41 changes: 33 additions & 8 deletions internal/manifests/manifests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,14 +855,6 @@ spec:
})

Describe("IsUserManifest", func() {
var (
manifestsAPI *manifests.Manifests
db *gorm.DB
ctx = context.Background()
ctrl *gomock.Controller
mockS3Client *s3wrapper.MockAPI
)

BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT())
mockS3Client = s3wrapper.NewMockAPI(ctrl)
Expand Down Expand Up @@ -894,6 +886,39 @@ spec:
Expect(manifestsAPI.IsUserManifest(ctx, clusterId, "openshift", "system-generated-manifest.yaml")).To(BeFalse())
})
})

Describe("ListClusterManifestsInternal", func() {
It("Should be able to list only user manifests if user and non user manifests are present", func() {
clusterId := registerCluster().ID
manifests := []string{
filepath.Join(clusterId.String(), constants.ManifestFolder, "openshift", "system-generated-manifest.yaml"),
filepath.Join(clusterId.String(), constants.ManifestFolder, "openshift", "user-generated-manifest.yaml"),
}
objectName := filepath.Join(clusterId.String(), constants.ManifestFolder)
mockS3Client.EXPECT().ListObjectsByPrefix(ctx, objectName).Return(manifests, nil).Times(1)
mockS3Client.EXPECT().DoesObjectExist(
ctx,
filepath.Join(
clusterId.String(),
constants.ManifestMetadataFolder,
"openshift",
"system-generated-manifest.yaml", "user-supplied")).Return(false, nil).Times(1)
mockS3Client.EXPECT().DoesObjectExist(
ctx,
filepath.Join(
clusterId.String(),
constants.ManifestMetadataFolder,
"openshift",
"user-generated-manifest.yaml", "user-supplied")).Return(true, nil).Times(1)
listedManifests, err := manifestsAPI.ListClusterManifestsInternal(ctx, operations.V2ListClusterManifestsParams{
ClusterID: *clusterId,
})
Expect(err).NotTo(HaveOccurred())
Expect(len(listedManifests)).To(Equal(1))
Expect(listedManifests[0].Folder).To(Equal("openshift"))
Expect(listedManifests[0].FileName).To(Equal("user-generated-manifest.yaml"))
})
})
})

type VoidReadCloser struct {
Expand Down