Skip to content

Commit cd71c63

Browse files
committed
MCO-2055 migrate bootimages tests
1 parent a7cc42b commit cd71c63

File tree

7 files changed

+1100
-91
lines changed

7 files changed

+1100
-91
lines changed

test/extended-priv/controller.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,46 @@ func (mcc *Controller) GetNode() (*Node, error) {
146146

147147
return NewNode(mcc.oc, nodeName), nil
148148
}
149+
150+
// GetPreviousLogs returns the previous logs of the machine-config-controller pod
151+
func (mcc *Controller) GetPreviousLogs() (string, error) {
152+
cachedPodName, err := mcc.GetCachedPodName()
153+
if err != nil {
154+
return "", err
155+
}
156+
if cachedPodName == "" {
157+
err := fmt.Errorf("Cannot get controller pod name. Failed getting MCO controller logs")
158+
logger.Errorf("Error getting controller pod name. Error: %s", err)
159+
return "", err
160+
}
161+
162+
prevLogs, err := NewNamespacedResource(mcc.oc, "pod", MachineConfigNamespace, cachedPodName).Logs("-p")
163+
if err != nil {
164+
if strings.Contains(prevLogs, "previous terminated container") && strings.Contains(prevLogs, "not found") {
165+
logger.Infof("There was no previous pod for %s", cachedPodName)
166+
return "", nil
167+
}
168+
logger.Infof("Unexpected error while getting MCC previous logs: %s", err)
169+
return prevLogs, err
170+
}
171+
return prevLogs, nil
172+
}
173+
174+
// checkMCCPanic checks the machine-config-controller logs for panics
175+
func checkMCCPanic(oc *exutil.CLI) {
176+
var (
177+
mcc = NewController(oc.AsAdmin())
178+
)
179+
180+
exutil.By("Check MCC Logs for Panic is not produced")
181+
mccPrevLogs, err := mcc.GetPreviousLogs()
182+
o.Expect(err).NotTo(o.HaveOccurred(), "Error getting previous MCC logs")
183+
184+
o.Expect(mccPrevLogs).NotTo(o.Or(o.ContainSubstring("panic"), o.ContainSubstring("Panic")), "Panic is seen in MCC previous logs after deleting OCB resources:\n%s", mccPrevLogs)
185+
mccLogs, err := mcc.GetLogs()
186+
187+
o.Expect(err).NotTo(o.HaveOccurred(), "Error getting MCC logs")
188+
o.Expect(mccLogs).NotTo(o.Or(o.ContainSubstring("panic"), o.ContainSubstring("Panic")), "Panic is seen in MCC logs after deleting OCB resources:\n%s", mccLogs)
189+
190+
logger.Infof("OK!\n")
191+
}

test/extended-priv/gomega_matchers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ func HaveConditionField(conditionType, conditionField string, expected interface
9494
return &conditionMatcher{conditionType: conditionType, field: conditionField, expected: expected}
9595
}
9696

97+
// HaveDegradedMessage returns the gomega matcher to check if a resource is reporting the given degraded message
98+
func HaveDegradedMessage(expected interface{}) types.GomegaMatcher {
99+
return &conditionMatcher{conditionType: "Degraded", field: "message", expected: expected}
100+
}
101+
97102
// DegradedMatcher struct implementing gomaega matcher interface to check Degraded condition
98103
type DegradedMatcher struct {
99104
*conditionMatcher

test/extended-priv/machineset.go

Lines changed: 93 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/tidwall/gjson"
1515
"github.com/tidwall/sjson"
1616
"k8s.io/apimachinery/pkg/util/wait"
17+
e2e "k8s.io/kubernetes/test/e2e/framework"
1718
)
1819

1920
// MachineSet struct to handle MachineSet resources
@@ -36,6 +37,10 @@ func NewMachineSetList(oc *exutil.CLI, namespace string) *MachineSetList {
3637
return &MachineSetList{*NewNamespacedResourceList(oc, MachineSetFullName, namespace)}
3738
}
3839

40+
func (ms MachineSet) String() string {
41+
return ms.GetName()
42+
}
43+
3944
// ScaleTo scales the MachineSet to the exact given value
4045
func (ms MachineSet) ScaleTo(scale int) error {
4146
return ms.Patch("merge", fmt.Sprintf(`{"spec": {"replicas": %d}}`, scale))
@@ -250,24 +255,86 @@ func (ms MachineSet) GetArchitectureOrFail() architecture.Architecture {
250255
return arch
251256
}
252257

258+
// SetArchitecture sets the architecture annotation for this MachineSet
259+
func (ms MachineSet) SetArchitecture(arch string) error {
260+
return ms.Patch("json",
261+
fmt.Sprintf(`[{"op": "add", "path": "/metadata/annotations/capacity.cluster-autoscaler.kubernetes.io~1labels", "value": "kubernetes.io/arch=%s"}]`,
262+
arch))
263+
}
264+
265+
// GetUserDataSecretName returns the name of the user-data secret
266+
func (ms MachineSet) GetUserDataSecretName() (string, error) {
267+
return ms.Get(`{.spec.template.spec.providerSpec.value.userDataSecret.name}`)
268+
}
269+
270+
// GetUserDataSecret returns the secret used for user-data
271+
func (ms MachineSet) GetUserDataSecret() (*Secret, error) {
272+
secretName, err := ms.GetUserDataSecretName()
273+
if err != nil {
274+
return nil, err
275+
}
276+
return NewSecret(ms.GetOC(), MachineAPINamespace, secretName), nil
277+
}
278+
253279
// SetUserDataSecret configures the machineset to use the provided user-data secret in the machine-config-api namespace
254280
func (ms MachineSet) SetUserDataSecret(userDataSecretName string) error {
255281
return ms.Patch("json", `[{ "op": "replace", "path": "/spec/template/spec/providerSpec/value/userDataSecret/name", "value": "`+userDataSecretName+`" }]`)
256282
}
257283

258-
// GetAll returns a []*MachineSet list with all existing MachineSets
284+
// GetCoreOsBootImage returns the configured coreOsBootImage in this machineset
285+
func (ms MachineSet) GetCoreOsBootImage() (string, error) {
286+
// the coreOs boot image is stored differently in the machineset spec depending on the platform
287+
// currently we only support testing the coresOs boot image in GCP platform.
288+
coreOsBootImagePath := ""
289+
switch p := exutil.CheckPlatform(ms.oc); p {
290+
case AWSPlatform:
291+
coreOsBootImagePath = `{.spec.template.spec.providerSpec.value.ami.id}`
292+
case GCPPlatform:
293+
// For GCP, dynamically find the boot disk index
294+
bootDiskIndex, err := GCPGetMachineSetBootDiskIndex(ms)
295+
if err != nil {
296+
return "", err
297+
}
298+
coreOsBootImagePath = fmt.Sprintf(`{.spec.template.spec.providerSpec.value.disks[%d].image}`, bootDiskIndex)
299+
case VspherePlatform:
300+
coreOsBootImagePath = `{.spec.template.spec.providerSpec.value.template}`
301+
case AzurePlatform:
302+
coreOsBootImagePath = `{.spec.template.spec.providerSpec.value.image}`
303+
default:
304+
e2e.Failf("Machineset.GetCoreOsBootImage method is only supported for GCP and AWS infrastructure")
305+
}
306+
307+
return ms.Get(coreOsBootImagePath)
308+
}
309+
310+
// GetCoreOsBootImageOrFail returns the configured coreOsBootImage in this machineset and fails the test case if any error happened
311+
func (ms MachineSet) GetCoreOsBootImageOrFail() string {
312+
img, err := ms.GetCoreOsBootImage()
313+
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error getting the coreos boot image value in %s", ms)
314+
return img
315+
}
316+
317+
// GetAll returns a []*MachineSet list with all existing machinesets
259318
func (msl *MachineSetList) GetAll() ([]*MachineSet, error) {
260-
allMachineSetResources, err := msl.ResourceList.GetAll()
319+
allMSResources, err := msl.ResourceList.GetAll()
261320
if err != nil {
262321
return nil, err
263322
}
264-
allMachineSets := make([]*MachineSet, 0, len(allMachineSetResources))
323+
allMS := make([]*MachineSet, 0, len(allMSResources))
265324

266-
for _, msRes := range allMachineSetResources {
267-
allMachineSets = append(allMachineSets, NewMachineSet(msl.oc, msRes.GetNamespace(), msRes.GetName()))
325+
for _, msRes := range allMSResources {
326+
allMS = append(allMS, NewMachineSet(msl.oc, msRes.GetNamespace(), msRes.GetName()))
268327
}
269328

270-
return allMachineSets, nil
329+
return allMS, nil
330+
}
331+
332+
// GetAllOrFail returns a []*Machineset list with all existing machinesets and fail the test if it is not possible
333+
func (msl *MachineSetList) GetAllOrFail() []*MachineSet {
334+
allMs, err := msl.GetAll()
335+
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error getting the list of existing MachineSets")
336+
337+
return allMs
271338
}
272339

273340
// WaitForRunningMachines waits for the specified number of running machines to be created from this MachineSet
@@ -511,3 +578,23 @@ func GCPGetMachineSetBootDiskIndex(ms MachineSet) (int, error) {
511578

512579
return -1, fmt.Errorf("No boot disk found in disks array (no disk with boot: true)")
513580
}
581+
582+
// AllNodesUpdated returns true if all nodes in this machineset are updated
583+
func (ms MachineSet) AllNodesUpdated() (bool, error) {
584+
nodes, err := ms.GetNodes()
585+
if err != nil {
586+
return false, err
587+
}
588+
589+
for _, node := range nodes {
590+
updated, err := node.IsUpdated()
591+
if err != nil {
592+
return false, err
593+
}
594+
if !updated {
595+
return false, nil
596+
}
597+
}
598+
599+
return true, nil
600+
}

0 commit comments

Comments
 (0)