зеркало из https://github.com/Azure/ARO-RP.git
Admin API E2E fixups
This commit is contained in:
Родитель
b53c7d2e81
Коммит
61669a737c
|
@ -83,10 +83,40 @@ func adminRequest(ctx context.Context, method, path string, params url.Values, i
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCluster(ctx context.Context, resourceID string) *admin.OpenShiftCluster {
|
// adminGetCluster returns admin representation of an ARO cluster
|
||||||
|
func adminGetCluster(ctx context.Context, resourceID string) *admin.OpenShiftCluster {
|
||||||
var oc admin.OpenShiftCluster
|
var oc admin.OpenShiftCluster
|
||||||
resp, err := adminRequest(ctx, http.MethodGet, resourceID, nil, nil, &oc)
|
resp, err := adminRequest(ctx, http.MethodGet, resourceID, nil, nil, &oc)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(resp.StatusCode).To(Equal(http.StatusOK))
|
Expect(resp.StatusCode).To(Equal(http.StatusOK))
|
||||||
return &oc
|
return &oc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// adminListClusters returns a list of ARO clusters in admin representation.
|
||||||
|
// It handles pagination: function returns all the clusters from all pages.
|
||||||
|
func adminListClusters(ctx context.Context, path string) []*admin.OpenShiftCluster {
|
||||||
|
ocs := make([]*admin.OpenShiftCluster, 0)
|
||||||
|
params := url.Values{}
|
||||||
|
for {
|
||||||
|
var list admin.OpenShiftClusterList
|
||||||
|
resp, err := adminRequest(ctx, http.MethodGet, path, params, nil, &list)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(resp.StatusCode).To(Equal(http.StatusOK))
|
||||||
|
|
||||||
|
ocs = append(ocs, list.OpenShiftClusters...)
|
||||||
|
|
||||||
|
if list.NextLink == "" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
params = nextParams(list.NextLink)
|
||||||
|
}
|
||||||
|
return ocs
|
||||||
|
}
|
||||||
|
|
||||||
|
func nextParams(nextLink string) url.Values {
|
||||||
|
url, err := url.Parse(nextLink)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
return url.Query()
|
||||||
|
}
|
||||||
|
|
|
@ -13,12 +13,12 @@ import (
|
||||||
var _ = Describe("[Admin API] Get cluster action", func() {
|
var _ = Describe("[Admin API] Get cluster action", func() {
|
||||||
BeforeEach(skipIfNotInDevelopmentEnv)
|
BeforeEach(skipIfNotInDevelopmentEnv)
|
||||||
|
|
||||||
It("should be able to return single cluster with admin fields", func() {
|
It("must return single cluster with admin fields", func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
resourceID := resourceIDFromEnv()
|
resourceID := resourceIDFromEnv()
|
||||||
|
|
||||||
By("requesting the cluster document via RP admin API")
|
By("requesting the cluster document via RP admin API")
|
||||||
oc := getCluster(ctx, resourceID)
|
oc := adminGetCluster(ctx, resourceID)
|
||||||
|
|
||||||
By("checking that we received the expected cluster")
|
By("checking that we received the expected cluster")
|
||||||
Expect(oc.ID).To(Equal(resourceID))
|
Expect(oc.ID).To(Equal(resourceID))
|
||||||
|
|
|
@ -6,8 +6,6 @@ package e2e
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
@ -18,24 +16,14 @@ import (
|
||||||
var _ = Describe("[Admin API] List clusters action", func() {
|
var _ = Describe("[Admin API] List clusters action", func() {
|
||||||
BeforeEach(skipIfNotInDevelopmentEnv)
|
BeforeEach(skipIfNotInDevelopmentEnv)
|
||||||
|
|
||||||
It("should be able to return list of all clusters with admin fields", func() {
|
It("must return list of clusters with admin fields", func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
resourceID := resourceIDFromEnv()
|
resourceID := resourceIDFromEnv()
|
||||||
|
|
||||||
By("requesting the cluster document via RP admin API")
|
testAdminClustersList(ctx, "/admin/providers/Microsoft.RedHatOpenShift/openShiftClusters", resourceID)
|
||||||
ocs := adminClustersList(ctx, "/admin/providers/Microsoft.RedHatOpenShift/openShiftClusters")
|
|
||||||
|
|
||||||
By("checking that we received the expected cluster")
|
|
||||||
var oc *admin.OpenShiftCluster
|
|
||||||
for i := range ocs {
|
|
||||||
if ocs[i].ID == resourceID {
|
|
||||||
oc = ocs[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Expect(oc).ToNot(BeNil())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should be able to return list clusters with admin fields by subscription", func() {
|
It("must return list of clusters with admin fields by subscription", func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
resourceID := resourceIDFromEnv()
|
resourceID := resourceIDFromEnv()
|
||||||
|
|
||||||
|
@ -43,7 +31,7 @@ var _ = Describe("[Admin API] List clusters action", func() {
|
||||||
testAdminClustersList(ctx, path, resourceID)
|
testAdminClustersList(ctx, path, resourceID)
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should be able to return list clusters with admin fields by resource group", func() {
|
It("must return list of clusters with admin fields by resource group", func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
resourceID := resourceIDFromEnv()
|
resourceID := resourceIDFromEnv()
|
||||||
|
|
||||||
|
@ -52,32 +40,11 @@ var _ = Describe("[Admin API] List clusters action", func() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
func adminClustersList(ctx context.Context, path string) []*admin.OpenShiftCluster {
|
|
||||||
By("requesting the cluster document via RP admin API")
|
|
||||||
ocs := make([]*admin.OpenShiftCluster, 0)
|
|
||||||
params := url.Values{}
|
|
||||||
for {
|
|
||||||
var list admin.OpenShiftClusterList
|
|
||||||
resp, err := adminRequest(ctx, http.MethodGet, path, params, nil, &list)
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
Expect(resp.StatusCode).To(Equal(http.StatusOK))
|
|
||||||
|
|
||||||
ocs = append(ocs, list.OpenShiftClusters...)
|
|
||||||
|
|
||||||
if list.NextLink == "" {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
params = nextParams(list.NextLink)
|
|
||||||
}
|
|
||||||
return ocs
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAdminClustersList(ctx context.Context, path, wantResourceID string) {
|
func testAdminClustersList(ctx context.Context, path, wantResourceID string) {
|
||||||
By("requesting the cluster document via RP admin API")
|
By("listing the cluster documents via RP admin API")
|
||||||
ocs := adminClustersList(ctx, path)
|
ocs := adminListClusters(ctx, path)
|
||||||
|
|
||||||
By("checking that we received the expected cluster")
|
By("verifying that we received the expected cluster")
|
||||||
var oc *admin.OpenShiftCluster
|
var oc *admin.OpenShiftCluster
|
||||||
for i := range ocs {
|
for i := range ocs {
|
||||||
if ocs[i].ID == wantResourceID {
|
if ocs[i].ID == wantResourceID {
|
||||||
|
@ -85,16 +52,11 @@ func testAdminClustersList(ctx context.Context, path, wantResourceID string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expect(oc).ToNot(BeNil())
|
Expect(oc).ToNot(BeNil())
|
||||||
|
Expect(oc.ID).To(Equal(wantResourceID))
|
||||||
|
|
||||||
By("checking that fields available only in Admin API have values")
|
By("checking that fields available only in Admin API have values")
|
||||||
// Note: some fields will have empty values
|
// Note: some fields will have empty values
|
||||||
// on successfully provisioned cluster (oc.Properties.Install, for example)
|
// on successfully provisioned cluster (oc.Properties.Install, for example)
|
||||||
Expect(oc.Properties.StorageSuffix).ToNot(BeEmpty())
|
Expect(oc.Properties.StorageSuffix).ToNot(BeEmpty())
|
||||||
}
|
Expect(oc.Properties.InfraID).ToNot(BeEmpty())
|
||||||
|
|
||||||
func nextParams(nextLink string) url.Values {
|
|
||||||
url, err := url.Parse(nextLink)
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
|
|
||||||
return url.Query()
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
var _ = Describe("[Admin API] Cluster admin update action", func() {
|
var _ = Describe("[Admin API] Cluster admin update action", func() {
|
||||||
BeforeEach(skipIfNotInDevelopmentEnv)
|
BeforeEach(skipIfNotInDevelopmentEnv)
|
||||||
|
|
||||||
It("should be able to run cluster update operation on a cluster", func() {
|
It("must run cluster update operation on a cluster", func() {
|
||||||
var oc = &admin.OpenShiftCluster{}
|
var oc = &admin.OpenShiftCluster{}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
resourceID := resourceIDFromEnv()
|
resourceID := resourceIDFromEnv()
|
||||||
|
@ -36,7 +36,7 @@ var _ = Describe("[Admin API] Cluster admin update action", func() {
|
||||||
|
|
||||||
By("waiting for the update to complete")
|
By("waiting for the update to complete")
|
||||||
err = wait.PollImmediate(10*time.Second, 30*time.Minute, func() (bool, error) {
|
err = wait.PollImmediate(10*time.Second, 30*time.Minute, func() (bool, error) {
|
||||||
oc = getCluster(ctx, resourceID)
|
oc = adminGetCluster(ctx, resourceID)
|
||||||
return oc.Properties.ProvisioningState == admin.ProvisioningStateSucceeded, nil
|
return oc.Properties.ProvisioningState == admin.ProvisioningStateSucceeded, nil
|
||||||
})
|
})
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
|
@ -31,7 +31,7 @@ const (
|
||||||
var _ = Describe("[Admin API] VM redeploy action", func() {
|
var _ = Describe("[Admin API] VM redeploy action", func() {
|
||||||
BeforeEach(skipIfNotInDevelopmentEnv)
|
BeforeEach(skipIfNotInDevelopmentEnv)
|
||||||
|
|
||||||
It("should trigger a selected VM to redeploy", func() {
|
It("must trigger a selected VM to redeploy", func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
resourceID := resourceIDFromEnv()
|
resourceID := resourceIDFromEnv()
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ var _ = Describe("[Admin API] VM redeploy action", func() {
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(resp.StatusCode).To(Equal(http.StatusOK))
|
Expect(resp.StatusCode).To(Equal(http.StatusOK))
|
||||||
|
|
||||||
By("verifying node power state is eventually Running in Azure")
|
By("waiting for the redeployed VM to report Running power state in Azure")
|
||||||
// we can pollimmediate without fear of false positive because we have
|
// we can pollimmediate without fear of false positive because we have
|
||||||
// already waited on the redeploy future
|
// already waited on the redeploy future
|
||||||
err = wait.PollImmediate(1*time.Minute, 10*time.Minute, func() (bool, error) {
|
err = wait.PollImmediate(1*time.Minute, 10*time.Minute, func() (bool, error) {
|
||||||
|
@ -74,7 +74,7 @@ var _ = Describe("[Admin API] VM redeploy action", func() {
|
||||||
})
|
})
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
By("verifying redeployed node is eventually Ready in OpenShift")
|
By("waiting for the redeployed node to eventually become Ready in OpenShift")
|
||||||
// wait 1 minute - this will guarantee we pass the minimum (default) threshold of Node heartbeats (40 seconds)
|
// wait 1 minute - this will guarantee we pass the minimum (default) threshold of Node heartbeats (40 seconds)
|
||||||
err = wait.Poll(1*time.Minute, 10*time.Minute, func() (bool, error) {
|
err = wait.Poll(1*time.Minute, 10*time.Minute, func() (bool, error) {
|
||||||
node, err := clients.Kubernetes.CoreV1().Nodes().Get(ctx, *vm.Name, metav1.GetOptions{})
|
node, err := clients.Kubernetes.CoreV1().Nodes().Get(ctx, *vm.Name, metav1.GetOptions{})
|
||||||
|
|
|
@ -22,7 +22,7 @@ import (
|
||||||
var _ = Describe("[Admin API] List Azure resources action", func() {
|
var _ = Describe("[Admin API] List Azure resources action", func() {
|
||||||
BeforeEach(skipIfNotInDevelopmentEnv)
|
BeforeEach(skipIfNotInDevelopmentEnv)
|
||||||
|
|
||||||
It("should list Azure resources", func() {
|
It("must list Azure resources for a cluster", func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
resourceID := resourceIDFromEnv()
|
resourceID := resourceIDFromEnv()
|
||||||
|
|
||||||
|
@ -31,21 +31,27 @@ var _ = Describe("[Admin API] List Azure resources action", func() {
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
clusterResourceGroup := stringutils.LastTokenByte(*oc.OpenShiftClusterProperties.ClusterProfile.ResourceGroupID, '/')
|
clusterResourceGroup := stringutils.LastTokenByte(*oc.OpenShiftClusterProperties.ClusterProfile.ResourceGroupID, '/')
|
||||||
|
|
||||||
By("building a list of valid Azure resource IDs via the Azure API")
|
By("getting a list of resources from the cluster resource group via ARM")
|
||||||
expectedResources, err := clients.Resources.ListByResourceGroup(ctx, clusterResourceGroup, "", "", nil)
|
expectedResources, err := clients.Resources.ListByResourceGroup(ctx, clusterResourceGroup, "", "", nil)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
By("building a list of expected Azure resource IDs")
|
||||||
expectedResourceIDs := make([]string, 0, len(expectedResources)+1)
|
expectedResourceIDs := make([]string, 0, len(expectedResources)+1)
|
||||||
for _, r := range expectedResources {
|
for _, r := range expectedResources {
|
||||||
expectedResourceIDs = append(expectedResourceIDs, strings.ToLower(*r.ID))
|
expectedResourceIDs = append(expectedResourceIDs, strings.ToLower(*r.ID))
|
||||||
}
|
}
|
||||||
|
|
||||||
By("adding VNet to list of valid Azure resource IDs")
|
By("adding disk encryption sets to the the list of expected resource IDs")
|
||||||
|
diskEncryptionSet, err := clients.DiskEncryptionSets.Get(ctx, vnetResourceGroup, fmt.Sprintf("%s-disk-encryption-set", vnetResourceGroup))
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
expectedResourceIDs = append(expectedResourceIDs, strings.ToLower(*diskEncryptionSet.ID))
|
||||||
|
|
||||||
|
By("adding VNet to the list of expected resource IDs")
|
||||||
vnetID, _, err := subnet.Split(*oc.OpenShiftClusterProperties.MasterProfile.SubnetID)
|
vnetID, _, err := subnet.Split(*oc.OpenShiftClusterProperties.MasterProfile.SubnetID)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
expectedResourceIDs = append(expectedResourceIDs, strings.ToLower(vnetID))
|
expectedResourceIDs = append(expectedResourceIDs, strings.ToLower(vnetID))
|
||||||
|
|
||||||
By("adding RouteTables to list of valid Azure resource IDs")
|
By("adding RouteTables to the list of expected resource IDs")
|
||||||
r, err := azure.ParseResourceID(vnetID)
|
r, err := azure.ParseResourceID(vnetID)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
@ -59,10 +65,6 @@ var _ = Describe("[Admin API] List Azure resources action", func() {
|
||||||
vnet, err := clients.VirtualNetworks.Get(ctx, r.ResourceGroup, r.ResourceName, "")
|
vnet, err := clients.VirtualNetworks.Get(ctx, r.ResourceGroup, r.ResourceName, "")
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
diskEncryptionSet, err := clients.DiskEncryptionSets.Get(ctx, vnetResourceGroup, fmt.Sprintf("%s-disk-encryption-set", vnetResourceGroup))
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
expectedResourceIDs = append(expectedResourceIDs, strings.ToLower(*diskEncryptionSet.ID))
|
|
||||||
|
|
||||||
for _, subnet := range *vnet.Subnets {
|
for _, subnet := range *vnet.Subnets {
|
||||||
if _, ok := subnets[strings.ToLower(*subnet.ID)]; !ok {
|
if _, ok := subnets[strings.ToLower(*subnet.ID)]; !ok {
|
||||||
continue
|
continue
|
||||||
|
@ -74,7 +76,7 @@ var _ = Describe("[Admin API] List Azure resources action", func() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
By("getting the actual Azure resource IDs via admin actions API")
|
By("getting the actual Azure resource IDs via RP admin API")
|
||||||
var actualResources []mgmtfeatures.GenericResourceExpanded
|
var actualResources []mgmtfeatures.GenericResourceExpanded
|
||||||
resp, err := adminRequest(ctx, http.MethodGet, "/admin"+resourceID+"/resources", nil, nil, &actualResources)
|
resp, err := adminRequest(ctx, http.MethodGet, "/admin"+resourceID+"/resources", nil, nil, &actualResources)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
@ -87,7 +89,7 @@ var _ = Describe("[Admin API] List Azure resources action", func() {
|
||||||
actualResourceIDs = append(actualResourceIDs, id)
|
actualResourceIDs = append(actualResourceIDs, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
By("comparing lists of resources")
|
By("verifying the list of resources")
|
||||||
Expect(actualResourceIDs).To(ConsistOf(expectedResourceIDs))
|
Expect(actualResourceIDs).To(ConsistOf(expectedResourceIDs))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Загрузка…
Ссылка в новой задаче