-
Notifications
You must be signed in to change notification settings - Fork 207
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
OCM-8152 | test: automated id:38816 List cluster ROSA cli will work #2076
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package e2e | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/openshift/rosa/tests/ci/labels" | ||
"github.com/openshift/rosa/tests/utils/config" | ||
"github.com/openshift/rosa/tests/utils/exec/rosacli" | ||
"github.com/openshift/rosa/tests/utils/log" | ||
) | ||
|
||
var _ = Describe("List resources", | ||
labels.Day2, | ||
labels.FeatureMachinepool, | ||
labels.NonHCPCluster, | ||
func() { | ||
defer GinkgoRecover() | ||
var ( | ||
clusterID string | ||
rosaClient *rosacli.Client | ||
) | ||
|
||
BeforeEach(func() { | ||
By("Get the cluster") | ||
clusterID = config.GetClusterID() | ||
Expect(clusterID).ToNot(Equal(""), "ClusterID is required. Please export CLUSTER_ID") | ||
|
||
By("Init the client") | ||
rosaClient = rosacli.NewClient() | ||
}) | ||
|
||
AfterEach(func() { | ||
By("Clean remaining resources") | ||
rosaClient.CleanResources(clusterID) | ||
|
||
}) | ||
|
||
It("List cluster via ROSA cli will work well - [id:38816]", | ||
labels.Medium, | ||
func() { | ||
var ( | ||
clusterData []string | ||
ClusterService = rosaClient.Cluster | ||
) | ||
|
||
By("List all clusters") | ||
clusterList, _, err := ClusterService.ListCluster() | ||
Expect(err).To(BeNil()) | ||
if err != nil { | ||
log.Logger.Errorf("Failed to fetch clusters: %v", err) | ||
return | ||
} | ||
|
||
for _, it := range clusterList.ListCluster { | ||
clusterData = append(clusterData, it.ID) | ||
} | ||
Expect(err).To(BeNil()) | ||
Expect(clusterData).Should(ContainElement(clusterID)) | ||
|
||
clusterData = []string{} | ||
By("List clusters with '--all' flag") | ||
clusterList, _, err = ClusterService.ListCluster("--all") | ||
Expect(err).To(BeNil()) | ||
if err != nil { | ||
log.Logger.Errorf("Failed to fetch clusters: %v", err) | ||
return | ||
} | ||
for _, it := range clusterList.ListCluster { | ||
clusterData = append(clusterData, it.ID) | ||
} | ||
Expect(err).To(BeNil()) | ||
Expect(clusterData).Should(ContainElement(clusterID)) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ type ClusterService interface { | |
DescribeCluster(clusterID string) (bytes.Buffer, error) | ||
ReflectClusterDescription(result bytes.Buffer) (*ClusterDescription, error) | ||
DescribeClusterAndReflect(clusterID string) (*ClusterDescription, error) | ||
List() (bytes.Buffer, error) | ||
ListCluster(flags ...string) (ListCluster, bytes.Buffer, error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not add yet another return type. It is better to have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @radtriste There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AkashKanni I was meaning to have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you update following this ? |
||
Create(clusterName string, flags ...string) (bytes.Buffer, error, string) | ||
DeleteCluster(clusterID string, flags ...string) (bytes.Buffer, error) | ||
CreateDryRun(clusterName string, flags ...string) (bytes.Buffer, error) | ||
|
@@ -49,6 +49,17 @@ func NewClusterService(client *Client) ClusterService { | |
} | ||
} | ||
|
||
// Struct for the 'rosa list cluster' output | ||
type Clusters struct { | ||
ID string `json:"ID,omitempty"` | ||
NAME string `json:"NAME,omitempty"` | ||
STATE string `json:"STATE,omitempty"` | ||
TOPOLOGY string `json:"TOPOLOGY,omitempty"` | ||
} | ||
type ListCluster struct { | ||
ListCluster []Clusters `json:"ListCluster,omitempty"` | ||
} | ||
|
||
// Struct for the 'rosa describe cluster' output | ||
type ClusterDescription struct { | ||
Name string `yaml:"Name,omitempty"` | ||
|
@@ -95,6 +106,34 @@ type ClusterDescription struct { | |
ExternalAuthentication string `yaml:"External Authentication,omitempty"` | ||
} | ||
|
||
// Pasrse the result of 'rosa list clusters' to Clusters struct | ||
func (c *clusterService) ReflectClusterList(result bytes.Buffer) (url ListCluster, err error) { | ||
url = ListCluster{} | ||
theMap := c.client.Parser.TableData.Input(result).Parse().Output() | ||
for _, ClusterItem := range theMap { | ||
ur := &Clusters{} | ||
err = MapStructure(ClusterItem, ur) | ||
if err != nil { | ||
return | ||
} | ||
url.ListCluster = append(url.ListCluster, *ur) | ||
} | ||
return | ||
} | ||
|
||
// ListClusters implements OCMResourceService. | ||
func (c *clusterService) ListCluster(flags ...string) (ListCluster, bytes.Buffer, error) { | ||
c.client.Runner.cmdArgs = []string{} | ||
listClusters := c.client.Runner. | ||
Cmd("list", "clusters").CmdFlags(flags...) | ||
output, err := listClusters.Run() | ||
if err != nil { | ||
return ListCluster{}, output, err | ||
} | ||
clusterList, err := c.ReflectClusterList(output) | ||
return clusterList, output, err | ||
} | ||
|
||
func (c *clusterService) DescribeCluster(clusterID string) (bytes.Buffer, error) { | ||
describe := c.client.Runner. | ||
Cmd("describe", "cluster"). | ||
|
@@ -139,8 +178,8 @@ func (c *clusterService) ReflectClusterDescription(result bytes.Buffer) (res *Cl | |
return res, err | ||
} | ||
|
||
func (c *clusterService) List() (bytes.Buffer, error) { | ||
list := c.client.Runner.Cmd("list", "cluster") | ||
func (c *clusterService) List(flags ...string) (bytes.Buffer, error) { | ||
list := c.client.Runner.Cmd("list", "cluster").CmdFlags(flags...) | ||
return list.Run() | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this label ? This should work also for HCP or ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AkashKanni Please answer to this ?