Skip to content

Commit

Permalink
OCM-5648 | ci: Update ids:63164,63178,63179
Browse files Browse the repository at this point in the history
  • Loading branch information
radtriste committed Jul 15, 2024
1 parent 374b54d commit ea50cce
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 99 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ require (
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v2 v2.4.0
k8s.io/klog/v2 v2.110.1 // indirect
)

Expand Down
104 changes: 50 additions & 54 deletions tests/e2e/hcp_tuning_config_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package e2e

import (
"encoding/json"
"fmt"
"os"
"strings"

"gopkg.in/yaml.v2"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -41,90 +43,84 @@ var _ = Describe("Create Tuning Config", labels.Feature.TuningConfigs, func() {
labels.Critical, labels.Runtime.Day2,
func() {
tuningConfigService := rosaClient.TuningConfig
tuningConfigName_1 := common.GenerateRandomName("tuned01", 2)
tuningConfigName_2 := common.GenerateRandomName("tuned02", 2)

tuningConfigPayload_1 := `{
"profile": [
{
"data": "[main]\nsummary=Custom OpenShift profile\ninclude=openshift-node\n\n[sysctl]\nvm.dirty_ratio=\"25\"\n",
"name": "%s-profile"
}
],
"recommend": [
{
"priority": 10,
"profile": "%s-profile"
}
]
}`
tuningConfigPayload_2 := `{
"profile": [
{
"data": "[main]\nsummary=Custom OpenShift profile\ninclude=openshift-node\n\n[sysctl]\nvm.dirty_ratio=\"65\"\n",
"name": "%s-profile"
}
],
"recommend": [
{
"priority": 20,
"profile": "%s-profile"
}
]
}`
tc1Name := common.GenerateRandomName("tuned01", 2)
firstPriority := 10
firstVMDirtyRatio := 25
tc2Name := common.GenerateRandomName("tuned02", 2)
secondPriority := 20
secondVMDirtyRatio := 65

tc1Spec := rosacli.NewTuningConfigSpecRootStub(tc1Name, firstVMDirtyRatio, firstPriority)
tc2Spec := rosacli.NewTuningConfigSpecRootStub(tc2Name, firstVMDirtyRatio, firstPriority)

By("Create tuning configs to the cluster")
tc1JSON, err := json.Marshal(tc1Spec)
Expect(err).ToNot(HaveOccurred())
resp, err := tuningConfigService.CreateTuningConfig(
clusterID,
tuningConfigName_1,
fmt.Sprintf(tuningConfigPayload_1, tuningConfigName_1, tuningConfigName_1))
tc1Name,
string(tc1JSON))
Expect(err).ToNot(HaveOccurred())
textData := rosaClient.Parser.TextData.Input(resp).Parse().Tip()
Expect(textData).
To(ContainSubstring(
fmt.Sprintf("Tuning config '%s' has been created on cluster '%s'", tuningConfigName_1, clusterID)))
fmt.Sprintf("Tuning config '%s' has been created on cluster '%s'", tc1Name, clusterID)))

tc2YAML, err := yaml.Marshal(tc2Spec)
Expect(err).ToNot(HaveOccurred())
resp, err = tuningConfigService.CreateTuningConfig(
clusterID,
tuningConfigName_2,
fmt.Sprintf(tuningConfigPayload_1, tuningConfigName_2, tuningConfigName_2))
tc2Name,
string(tc2YAML))
Expect(err).ToNot(HaveOccurred())
textData = rosaClient.Parser.TextData.Input(resp).Parse().Tip()
Expect(textData).
To(ContainSubstring(
fmt.Sprintf("Tuning config '%s' has been created on cluster '%s'", tuningConfigName_2, clusterID)))
fmt.Sprintf("Tuning config '%s' has been created on cluster '%s'", tc2Name, clusterID)))

By("List all tuning configs")
tuningConfigList, err := tuningConfigService.ListTuningConfigsAndReflect(clusterID)
Expect(err).ToNot(HaveOccurred())
Expect(tuningConfigList.IsPresent(tuningConfigName_1)).
To(BeTrue(), "the tuningconfig %s is not in output", tuningConfigName_1)
Expect(tuningConfigList.IsPresent(tuningConfigName_2)).
To(BeTrue(), "the tuningconfig %s is not in output", tuningConfigName_2)
Expect(tuningConfigList.IsPresent(tc1Name)).
To(BeTrue(), "the tuningconfig %s is not in output", tc1Name)
Expect(tuningConfigList.IsPresent(tc2Name)).
To(BeTrue(), "the tuningconfig %s is not in output", tc2Name)

By("Update a tuning config of the cluster")
specPath, err := common.CreateTempFileWithContent(
fmt.Sprintf(tuningConfigPayload_2, tuningConfigName_2, tuningConfigName_2))
tc2Spec.Profile[0].Data = rosacli.NewTuningConfigSpecProfileData(secondVMDirtyRatio)
tc2Spec.Recommend[0].Priority = secondPriority
tc2JSON, err := json.Marshal(tc2Spec)
Expect(err).ToNot(HaveOccurred())
specPath, err := common.CreateTempFileWithContent(string(tc2JSON))
defer os.Remove(specPath)
Expect(err).ToNot(HaveOccurred())
_, err = tuningConfigService.EditTuningConfig(clusterID, tuningConfigName_2, "--spec-path", specPath)
_, err = tuningConfigService.EditTuningConfig(clusterID, tc2Name, "--spec-path", specPath)
Expect(err).ToNot(HaveOccurred())

By("Describe the updated tuning config")
output, err := tuningConfigService.DescribeTuningConfigAndReflect(clusterID, tuningConfigName_2)
output, err := tuningConfigService.DescribeTuningConfigAndReflect(clusterID, tc2Name)
Expect(err).ToNot(HaveOccurred())
Expect(output.Name).To(Equal(tc2Name))
var spec rosacli.TuningConfigSpecRoot
err = json.Unmarshal([]byte(output.Spec), &spec)
Expect(err).ToNot(HaveOccurred())
tuningConfigPayload_2 = strings.ReplaceAll(tuningConfigPayload_2, "\t", " ")
Expect(output.Spec).To(Equal(fmt.Sprintf(tuningConfigPayload_2, tuningConfigName_2, tuningConfigName_2)))
Expect(output.Name).To(Equal(tuningConfigName_2))
Expect(len(spec.Profile)).To(Equal(len(tc2Spec.Profile)))
Expect(spec.Profile[0].Data).To(Equal(tc2Spec.Profile[0].Data))
Expect(spec.Profile[0].Name).To(Equal(tc2Spec.Profile[0].Name))
Expect(len(spec.Recommend)).To(Equal(len(tc2Spec.Recommend)))
Expect(spec.Recommend[0].Priority).To(Equal(tc2Spec.Recommend[0].Priority))
Expect(spec.Recommend[0].Profile).To(Equal(tc2Spec.Recommend[0].Profile))

By("Delete the tuning config")
_, err = tuningConfigService.DeleteTuningConfig(clusterID, tuningConfigName_2)
_, err = tuningConfigService.DeleteTuningConfig(clusterID, tc2Name)
Expect(err).ToNot(HaveOccurred())

By("List the tuning configs and check deleted tuning config should not be present]")
tuningConfigList, err = tuningConfigService.ListTuningConfigsAndReflect(clusterID)
Expect(err).ToNot(HaveOccurred())
Expect(tuningConfigList.IsPresent(tuningConfigName_1)).
To(BeTrue(), "the tuningconfig %s is not in output", tuningConfigName_1)
Expect(tuningConfigList.IsPresent(tuningConfigName_2)).
To(BeFalse(), "the tuningconfig %s is in the output", tuningConfigName_2)
Expect(tuningConfigList.IsPresent(tc1Name)).
To(BeTrue(), "the tuningconfig %s is not in output", tc1Name)
Expect(tuningConfigList.IsPresent(tc2Name)).
To(BeFalse(), "the tuningconfig %s is in the output", tc2Name)
})
})
69 changes: 25 additions & 44 deletions tests/e2e/test_rosacli_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2e
import (
"bytes"
"context"
"encoding/json"
"fmt"
"strconv"
"strings"
Expand Down Expand Up @@ -317,42 +318,36 @@ var _ = Describe("Edit nodepool",
tuningConfigService := rosaClient.TuningConfig
nodePoolName := common.GenerateRandomName("np-63178", 2)
tuningConfig1Name := common.GenerateRandomName("tuned01", 2)
tc1Spec := rosacli.NewTuningConfigSpecRootStub(tuningConfig1Name, 25, 10)
tuningConfig2Name := common.GenerateRandomName("tuned02", 2)
tc2Spec := rosacli.NewTuningConfigSpecRootStub(tuningConfig2Name, 25, 10)
tuningConfig3Name := common.GenerateRandomName("tuned03", 2)
tc3Spec := rosacli.NewTuningConfigSpecRootStub(tuningConfig2Name, 25, 10)
allTuningConfigNames := []string{tuningConfig1Name, tuningConfig2Name, tuningConfig3Name}

tuningConfigPayload := `
{
"profile": [
{
"data": "[main]\nsummary=Custom OpenShift profile\ninclude=openshift-node\n\n[sysctl]\nvm.dirty_ratio=\"25\"\n",
"name": "%s-profile"
}
],
"recommend": [
{
"priority": 10,
"profile": "%s-profile"
}
]
}
`

By("Prepare tuning configs")
_, err := tuningConfigService.CreateTuningConfig(
tc1JSON, err := json.Marshal(tc1Spec)
Expect(err).ToNot(HaveOccurred())
_, err = tuningConfigService.CreateTuningConfig(
clusterID,
tuningConfig1Name,
fmt.Sprintf(tuningConfigPayload, tuningConfig1Name, tuningConfig1Name))
string(tc1JSON))
Expect(err).ToNot(HaveOccurred())

tc2JSON, err := json.Marshal(tc2Spec)
Expect(err).ToNot(HaveOccurred())
_, err = tuningConfigService.CreateTuningConfig(
clusterID,
tuningConfig2Name,
fmt.Sprintf(tuningConfigPayload, tuningConfig2Name, tuningConfig2Name))
string(tc2JSON))
Expect(err).ToNot(HaveOccurred())

tc3JSON, err := json.Marshal(tc3Spec)
Expect(err).ToNot(HaveOccurred())
_, err = tuningConfigService.CreateTuningConfig(
clusterID,
tuningConfig3Name,
fmt.Sprintf(tuningConfigPayload, tuningConfig3Name, tuningConfig3Name))
string(tc3JSON))
Expect(err).ToNot(HaveOccurred())

By("Create nodepool with tuning configs")
Expand Down Expand Up @@ -393,31 +388,17 @@ var _ = Describe("Edit nodepool",
func() {
tuningConfigService := rosaClient.TuningConfig
nodePoolName := common.GenerateRandomName("np-63179", 2)
tuningConfigName_1 := common.GenerateRandomName("tuned01", 2)
tuningConfigName := common.GenerateRandomName("tuned01", 2)
tcSpec := rosacli.NewTuningConfigSpecRootStub(tuningConfigName, 25, 10)
nonExistingTuningConfigName := common.GenerateRandomName("fake_tuning_config", 2)

tuningConfigPayload := `
{
"profile": [
{
"data": "[main]\nsummary=Custom OpenShift profile\ninclude=openshift-node\n\n[sysctl]\nvm.dirty_ratio=\"25\"\n",
"name": "%s-profile"
}
],
"recommend": [
{
"priority": 10,
"profile": "%s-profile"
}
]
}
`

By("Prepare tuning configs")
_, err := tuningConfigService.CreateTuningConfig(
tcJSON, err := json.Marshal(tcSpec)
Expect(err).ToNot(HaveOccurred())
_, err = tuningConfigService.CreateTuningConfig(
clusterID,
tuningConfigName_1,
fmt.Sprintf(tuningConfigPayload, tuningConfigName_1, tuningConfigName_1))
tuningConfigName,
string(tcJSON))
Expect(err).ToNot(HaveOccurred())

By("Create nodepool with the non-existing tuning configs")
Expand All @@ -442,7 +423,7 @@ var _ = Describe("Edit nodepool",
clusterID,
nodePoolName,
"--replicas", "3",
"--tuning-configs", fmt.Sprintf("%s,%s", tuningConfigName_1, tuningConfigName_1),
"--tuning-configs", fmt.Sprintf("%s,%s", tuningConfigName, tuningConfigName),
)
textData = rosaClient.Parser.TextData.Input(output).Parse().Tip()
Expect(err).To(HaveOccurred())
Expand All @@ -451,7 +432,7 @@ var _ = Describe("Edit nodepool",
fmt.Sprintf("Failed to add machine pool to hosted cluster '%s': "+
"Tuning config with name '%s' is duplicated",
clusterID,
tuningConfigName_1)))
tuningConfigName)))

By("Create a nodepool")
_, err = machinePoolService.CreateMachinePool(clusterID, nodePoolName,
Expand Down
40 changes: 40 additions & 0 deletions tests/utils/exec/rosacli/tuning_config_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rosacli

import (
"bytes"
"fmt"
"os"
"strings"

Expand Down Expand Up @@ -58,8 +59,47 @@ type TuningConfigDescription struct {
Spec string `yaml:"Spec,omitempty"`
}

type TuningConfigSpecRoot struct {
Profile []TuningConfigSpecProfile `json:"profile,omitempty" yaml:"profile,omitempty"`
Recommend []TuningConfigSpecRecommend `json:"recommend,omitempty" yaml:"recommend,omitempty"`
}

type TuningConfigSpecProfile struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Data string `yaml:"data,omitempty" json:"data,omitempty"`
}

type TuningConfigSpecRecommend struct {
Priority int `yaml:"priority,omitempty" json:"priority,omitempty"`
Profile string `yaml:"profile,omitempty" json:"profile,omitempty"`
}

func NewTuningConfigSpecRootStub(tcName string, vmDirtyRatio int, priority int) TuningConfigSpecRoot {
return TuningConfigSpecRoot{
Profile: []TuningConfigSpecProfile{
{
Data: NewTuningConfigSpecProfileData(vmDirtyRatio),
Name: tcName + "-profile",
},
},
Recommend: []TuningConfigSpecRecommend{
{
Priority: priority,
Profile: tcName + "-profile",
},
},
}
}

func NewTuningConfigSpecProfileData(vmDirtyRatio int) string {
return fmt.Sprintf("[main]\nsummary=Custom OpenShift profile\ninclude=openshift-node\n\n"+
"[sysctl]\nvm.dirty_ratio=\"%d\"\n",
vmDirtyRatio)
}

func (tcs *tuningConfigService) CreateTuningConfig(
clusterID string, tcName string, specContent string, flags ...string) (output bytes.Buffer, err error) {
Logger.Debugf("Create tc %s with content %s", tcName, specContent)
specPath, err := common.CreateTempFileWithContent(specContent)
defer os.Remove(specPath)
if err != nil {
Expand Down

0 comments on commit ea50cce

Please sign in to comment.