Skip to content

Commit

Permalink
OCM-5581 | feat: Add support for ListInstanceTypes method
Browse files Browse the repository at this point in the history
This PR adds ListInstanceTypes function to list
all available instance-types (rosa list instance-types)
and it also verifies the presence of newly enabled instance-types
  • Loading branch information
AkashKanni committed May 8, 2024
1 parent ce68f1a commit 18b89dd
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
22 changes: 21 additions & 1 deletion tests/e2e/test_rosacli_machine_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/openshift/rosa/tests/utils/common"
"github.com/openshift/rosa/tests/utils/config"
"github.com/openshift/rosa/tests/utils/exec/rosacli"
"github.com/openshift/rosa/tests/utils/log"
)

var _ = Describe("Create machinepool",
Expand All @@ -22,6 +23,7 @@ var _ = Describe("Create machinepool",
clusterID string
rosaClient *rosacli.Client
machinePoolService rosacli.MachinePoolService
ocmResourceService rosacli.OCMResourceService
)

BeforeEach(func() {
Expand All @@ -32,7 +34,7 @@ var _ = Describe("Create machinepool",
By("Init the client")
rosaClient = rosacli.NewClient()
machinePoolService = rosaClient.MachinePool

ocmResourceService = rosaClient.OCMResource
})

AfterEach(func() {
Expand Down Expand Up @@ -102,6 +104,24 @@ var _ = Describe("Create machinepool",

})

It("List newly added instance-types - [id:73308]",
labels.Medium,
func() {
By("List the available instance-types and verify the presence of newly added instance-types")
newlyAddedTypes := []string{"c7a.xlarge", "c7a.48xlarge", "c7a.metal-48xl", "r7a.xlarge", "r7a.48xlarge", "r7a.metal-48xl", "hpc6a.48xlarge", "hpc6id.32xlarge", "hpc7a.96xlarge", "c7i.48xlarge", "c7i.metal-24xl", "c7i.metal-48xl", "r7i.xlarge", "r7i.48xlarge"}
availableMachineTypes, _, err := ocmResourceService.ListInstanceTypes()

if err != nil {
log.Logger.Errorf("Failed to fetch instance types: %v", err)
} else {
var availableMachineTypesIDs []string
for _, it := range availableMachineTypes.InstanceTypesList {
availableMachineTypesIDs = append(availableMachineTypesIDs, it.ID)
}
Expect(availableMachineTypesIDs).To(ContainElements(newlyAddedTypes))
}
})

It("can create spot machinepool - [id:43251]",
labels.High,
func() {
Expand Down
40 changes: 40 additions & 0 deletions tests/utils/exec/rosacli/ocm_resource_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type OCMResourceService interface {
ReflectOCMRoleList(result bytes.Buffer) (orl OCMRoleList, err error)

ListOIDCConfig() (OIDCConfigList, bytes.Buffer, error)
ListInstanceTypes() (InstanceTypesList, bytes.Buffer, error)
DeleteOIDCConfig(flags ...string) (bytes.Buffer, error)
CreateOIDCConfig(flags ...string) (bytes.Buffer, error)
ReflectOIDCConfigList(result bytes.Buffer) (oidclist OIDCConfigList, err error)
Expand All @@ -79,6 +80,17 @@ func NewOCMResourceService(client *Client) OCMResourceService {
}
}

// Struct for the 'rosa list instance-types' output
type InstanceTypes struct {
ID string `json:"ID,omitempty"`
CATEGORY string `json:"CATEGORY,omitempty"`
CPU_CORES string `json:"CPU_CORES,omitempty"`
MEMORY string `json:"MEMORY,omitempty"`
}
type InstanceTypesList struct {
InstanceTypesList []InstanceTypes `json:"InstanceTypesList,omitempty"`
}

// Struct for the 'rosa list region' output
type CloudRegion struct {
ID string `json:"ID,omitempty"`
Expand Down Expand Up @@ -159,6 +171,34 @@ type OIDCConfigList struct {
OIDCConfigList []OIDCConfig `json:"OIDCConfigList,omitempty"`
}

// Pasrse the result of 'rosa list instance-types' to InstanceTypes struct
func (ors *ocmResourceService) ReflectInstanceTypesList(result bytes.Buffer) (url InstanceTypesList, err error) {
url = InstanceTypesList{}
theMap := ors.client.Parser.TableData.Input(result).Parse().Output()
for _, instanceTypeItem := range theMap {
ur := &InstanceTypes{}
err = MapStructure(instanceTypeItem, ur)
if err != nil {
return
}
url.InstanceTypesList = append(url.InstanceTypesList, *ur)
}
return
}

// ListInstanceTypes implements OCMResourceService.
func (ors *ocmResourceService) ListInstanceTypes() (InstanceTypesList, bytes.Buffer, error) {
ors.client.Runner.cmdArgs = []string{}
listInstanceTypes := ors.client.Runner.
Cmd("list", "instance-types")
output, err := listInstanceTypes.Run()
if err != nil {
return InstanceTypesList{}, output, err
}
instanceList, err := ors.ReflectInstanceTypesList(output)
return instanceList, output, err
}

// List region
func (ors *ocmResourceService) ListRegion(flags ...string) ([]*CloudRegion, bytes.Buffer, error) {
listRegion := ors.client.Runner
Expand Down

0 comments on commit 18b89dd

Please sign in to comment.