element_type
stringclasses
4 values
project_name
stringclasses
1 value
uuid
stringlengths
36
36
name
stringlengths
0
346
imports
stringlengths
0
2.67k
structs
stringclasses
761 values
interfaces
stringclasses
22 values
file_location
stringclasses
545 values
code
stringlengths
26
8.07M
global_vars
stringclasses
7 values
package
stringclasses
124 values
tags
stringclasses
1 value
function
openshift/openshift-tests-private
7512ba8f-9d61-4142-8112-f8be7dfb8736
GetMachineConfigReason
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) GetMachineConfigReason() string { return n.GetOrFail(`{.metadata.annotations.machineconfiguration\.openshift\.io/reason}`) }
mco
function
openshift/openshift-tests-private
b5d8dd5d-8865-42eb-a9e5-ab8c8fe8128f
GetDesiredConfig
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) GetDesiredConfig() string { return n.GetOrFail(`{.metadata.annotations.machineconfiguration\.openshift\.io/desiredConfig}`) }
mco
function
openshift/openshift-tests-private
dbe17737-5fef-43a9-8aac-c3dee331d3d7
PatchDesiredConfig
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) PatchDesiredConfig(desiredConfig string) error { return n.Patch("merge", `{"metadata":{"annotations":{"machineconfiguration.openshift.io/desiredConfig":"`+desiredConfig+`"}}}`) }
mco
function
openshift/openshift-tests-private
2442ce3f-47b2-4d44-bab8-b7a0a439aebc
PatchDesiredConfigAndDesiredImage
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) PatchDesiredConfigAndDesiredImage(desiredConfig, desiredImage string) error { return n.Patch("merge", `{"metadata":{"annotations":{"machineconfiguration.openshift.io/desiredConfig":"`+desiredConfig+`", "machineconfiguration.openshift.io/desiredImage":"`+desiredImage+`"}}}`) }
mco
function
openshift/openshift-tests-private
54f14e8f-0d9e-4f9f-bb15-e6e15a655fe0
GetDesiredDrain
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) GetDesiredDrain() string { return n.GetOrFail(`{.metadata.annotations.machineconfiguration\.openshift\.io/desiredDrain}`) }
mco
function
openshift/openshift-tests-private
7d72eaaa-162e-440f-ba86-38ff3a76a3bf
GetLastAppliedDrain
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) GetLastAppliedDrain() string { return n.GetOrFail(`{.metadata.annotations.machineconfiguration\.openshift\.io/lastAppliedDrain}`) }
mco
function
openshift/openshift-tests-private
9d6eff39-847f-4558-a4d2-55e72d732ad9
HasBeenDrained
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) HasBeenDrained() bool { return n.GetLastAppliedDrain() == n.GetDesiredDrain() }
mco
function
openshift/openshift-tests-private
ee1ea271-8824-454e-85b2-a3a8718bca10
IsUpdated
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) IsUpdated() bool { return (n.GetCurrentMachineConfig() == n.GetDesiredMachineConfig()) && (n.GetMachineConfigState() == "Done") }
mco
function
openshift/openshift-tests-private
bd99400e-bab5-48d4-92e3-6e3deed598d8
IsTainted
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) IsTainted() bool { taint, err := n.Get("{.spec.taints}") return err == nil && taint != "" }
mco
function
openshift/openshift-tests-private
ee6357d4-b9ef-452d-a300-00978b888be6
IsSchedulable
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) IsSchedulable() (bool, error) { unschedulable, err := n.Get(`{.spec.unschedulable}`) if err != nil { return false, err } return !IsTrue(unschedulable), nil }
mco
function
openshift/openshift-tests-private
25895f02-ca28-4ea4-8ead-978c76e65a38
IsSchedulableOrFail
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) IsSchedulableOrFail() bool { schedulable, err := n.IsSchedulable() o.Expect(err).NotTo(o.HaveOccurred(), "Error while getting the taints in node %s", n.GetName()) return schedulable }
mco
function
openshift/openshift-tests-private
0a2f3ef0-78bb-490c-9815-c3e51d08a50b
HasTaintEffect
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) HasTaintEffect(taintEffect string) (bool, error) { taint, err := n.Get(`{.spec.taints[?(@.effect=="` + taintEffect + `")]}`) if err != nil { return false, err } return taint != "", nil }
mco
function
openshift/openshift-tests-private
eb09d1ee-5dc1-413c-97d9-a8b4776e017e
HasTaintEffectOrFail
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) HasTaintEffectOrFail(taintEffect string) bool { hasTaintEffect, err := n.HasTaintEffect(taintEffect) o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error while getting the taints effects in node %s", n.GetName()) return hasTaintEffect }
mco
function
openshift/openshift-tests-private
314a3a17-da66-411d-99bd-37512057846a
IsEdge
['"strings"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) IsEdge() (bool, error) { _, err := n.GetLabel(`node-role.kubernetes.io/edge`) if err != nil { if strings.Contains(err.Error(), "not found") { return false, nil } return false, err } return true, nil }
mco
function
openshift/openshift-tests-private
35404d36-24e9-46e2-a664-9615ed06a792
IsEdgeOrFail
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) IsEdgeOrFail() bool { isEdge, err := n.IsEdge() o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error finding out if node %s is an edge node", n) return isEdge }
mco
function
openshift/openshift-tests-private
d617c4dd-c8e1-4a84-9ee4-abf3b304fa42
IsUpdating
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) IsUpdating() bool { return n.GetMachineConfigState() == "Working" }
mco
function
openshift/openshift-tests-private
11104f76-1ddc-46c1-805e-ead6065d9c4b
IsReady
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) IsReady() bool { return n.IsConditionStatusTrue("Ready") }
mco
function
openshift/openshift-tests-private
1603444c-9f0d-45a5-bcd4-2bfe427f8eb1
GetMCDaemonLogs
['"time"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) GetMCDaemonLogs(filter string) (string, error) { var ( mcdLogs = "" err error ) err = Retry(5, 5*time.Second, func() error { mcdLogs, err = exutil.GetSpecificPodLogs(n.oc, MachineConfigNamespace, "machine-config-daemon", n.GetMachineConfigDaemon(), filter) return err }) return mcdLogs, err }
mco
function
openshift/openshift-tests-private
1d1998fc-8955-478c-8c02-09a13390180a
PollMCDaemonLogs
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) PollMCDaemonLogs(filter string) func() string { return func() string { logs, err := n.GetMCDaemonLogs(filter) if err != nil { return "" } return logs } }
mco
function
openshift/openshift-tests-private
6175a1b1-e544-424a-82e5-f7799eb1db4f
CaptureMCDaemonLogsUntilRestartWithTimeout
['"fmt"', '"time"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) CaptureMCDaemonLogsUntilRestartWithTimeout(timeout string) (string, error) { var ( logs = "" err error machineConfigDaemon = n.GetMachineConfigDaemon() ) duration, err := time.ParseDuration(timeout) if err != nil { return "", err } c := make(chan string, 1) go func() { err = Retry(5, 5*time.Second, func() error { var err error logs, err = n.oc.WithoutNamespace().Run("logs").Args("-n", MachineConfigNamespace, machineConfigDaemon, "-c", "machine-config-daemon", "-f").Output() if err != nil { logger.Errorf("Retrying because: Error getting %s logs. Error: %s\nOutput: %s", machineConfigDaemon, err, logs) } return err }) if err != nil { logger.Errorf("Error getting %s logs. Error: %s", machineConfigDaemon, err) } c <- logs }() select { case logs := <-c: return logs, nil case <-time.After(duration): errMsg := fmt.Sprintf(`Node "%s". Timeout while waiting for the daemon pod "%s" -n "%s" to be restarted`, n.GetName(), machineConfigDaemon, MachineConfigNamespace) logger.Infof(errMsg) return "", fmt.Errorf(errMsg) } }
mco
function
openshift/openshift-tests-private
952b687d-a25e-4954-b8d2-e5d8d1effa68
GetDateOrFail
['"time"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) GetDateOrFail() time.Time { date, err := n.GetDate() o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Could not get the current date in %s", n) return date }
mco
function
openshift/openshift-tests-private
85e4c0a5-c5f9-463e-bdb4-a1b692ce2215
GetDate
['"time"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) GetDate() (time.Time, error) { date, _, err := n.DebugNodeWithChrootStd(`date`, `+%Y-%m-%dT%H:%M:%SZ`) logger.Infof("node %s. DATE: %s", n.GetName(), date) if err != nil { logger.Errorf("Error trying to get date in node %s: %s", n.GetName(), err) return time.Time{}, err } layout := "2006-01-02T15:04:05Z" returnTime, perr := time.Parse(layout, date) if perr != nil { logger.Errorf("Error trying to parsing date %s in node %s: %s", date, n.GetName(), perr) return time.Time{}, perr } return returnTime, nil }
mco
function
openshift/openshift-tests-private
88519fb2-8ad7-45e3-811e-ef5b0acec7b3
GetUptime
['"time"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) GetUptime() (time.Time, error) { uptime, _, err := n.DebugNodeWithChrootStd(`uptime`, `-s`) logger.Infof("node %s. UPTIME: %s", n.GetName(), uptime) if err != nil { logger.Errorf("Error trying to get uptime in node %s: %s", n.GetName(), err) return time.Time{}, err } layout := "2006-01-02 15:04:05" returnTime, perr := time.Parse(layout, uptime) if perr != nil { logger.Errorf("Error trying to parsing uptime %s in node %s: %s", uptime, n.GetName(), perr) return time.Time{}, perr } return returnTime, nil }
mco
function
openshift/openshift-tests-private
d06d16d6-4e4a-4f59-8fd9-56ebb6b7ac09
GetEventsByReasonSince
['"time"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) GetEventsByReasonSince(since time.Time, reason string) ([]Event, error) { eventList := NewEventList(n.oc, MachineConfigNamespace) eventList.ByFieldSelector(`reason=` + reason + `,involvedObject.name=` + n.GetName()) return eventList.GetAllSince(since) }
mco
function
openshift/openshift-tests-private
cf764c74-d288-4c03-ae2f-3d1dd025f549
GetAllEventsSince
['"time"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) GetAllEventsSince(since time.Time) ([]Event, error) { eventList := NewEventList(n.oc, MachineConfigNamespace) eventList.ByFieldSelector(`involvedObject.name=` + n.GetName()) return eventList.GetAllSince(since) }
mco
function
openshift/openshift-tests-private
0013a53e-f5d9-4b19-9a6a-840c57d8056e
GetAllEventsSinceEvent
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) GetAllEventsSinceEvent(since *Event) ([]Event, error) { eventList := NewEventList(n.oc, MachineConfigNamespace) eventList.ByFieldSelector(`involvedObject.name=` + n.GetName()) return eventList.GetAllEventsSinceEvent(since) }
mco
function
openshift/openshift-tests-private
98c4cfeb-5a41-4859-ac60-667316c5ab2a
GetLatestEvent
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) GetLatestEvent() (*Event, error) { eventList := NewEventList(n.oc, MachineConfigNamespace) eventList.ByFieldSelector(`involvedObject.name=` + n.GetName()) return eventList.GetLatest() }
mco
function
openshift/openshift-tests-private
3177d70d-9462-468a-a05c-26b419c17a74
GetEvents
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) GetEvents() ([]Event, error) { return n.GetAllEventsSince(n.eventCheckpoint) }
mco
function
openshift/openshift-tests-private
f7747638-4745-4266-bb73-0087b6d6ed2c
IgnoreEventsBeforeNow
['"time"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) IgnoreEventsBeforeNow() error { var err error latestEvent, lerr := n.GetLatestEvent() if lerr != nil { return lerr } logger.Infof("Latest event in node %s was: %s", n.GetName(), latestEvent) if latestEvent == nil { logger.Infof("Since no event was found for node %s, we will not ignore any event", n.GetName()) n.eventCheckpoint = time.Time{} return nil } logger.Infof("Ignoring all previous events!") n.eventCheckpoint, err = latestEvent.GetLastTimestamp() return err }
mco
function
openshift/openshift-tests-private
8b9dce4b-8f81-4cb7-b9d5-e56d942db2b0
GetDateWithDelta
['"time"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) GetDateWithDelta(delta string) (time.Time, error) { date, err := n.GetDate() if err != nil { return time.Time{}, err } timeDuration, terr := time.ParseDuration(delta) if terr != nil { logger.Errorf("Error getting delta time %s", terr) return time.Time{}, terr } return date.Add(timeDuration), nil }
mco
function
openshift/openshift-tests-private
6cb4f0e1-2045-472f-9956-f2136c076925
IsFIPSEnabled
['"strings"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) IsFIPSEnabled() (bool, error) { output, err := n.DebugNodeWithChroot("fips-mode-setup", "--check") if err != nil { logger.Errorf("Error checking fips mode %s", err) } return strings.Contains(output, "FIPS mode is enabled"), err }
mco
function
openshift/openshift-tests-private
6d5e00c2-43a5-4ed1-bc0b-755d828fbbf8
IsKernelArgEnabled
['"strings"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) IsKernelArgEnabled(karg string) (bool, error) { unameOut, unameErr := n.DebugNodeWithChroot("bash", "-c", "uname -a") if unameErr != nil { logger.Errorf("Error checking kernel arg via uname -a: %v", unameErr) return false, unameErr } cliOut, cliErr := n.DebugNodeWithChroot("cat", "/proc/cmdline") if cliErr != nil { logger.Errorf("Err checking kernel arg via /proc/cmdline: %v", cliErr) return false, cliErr } return (strings.Contains(unameOut, karg) || strings.Contains(cliOut, karg)), nil }
mco
function
openshift/openshift-tests-private
4c585930-ab36-4974-9e7b-41b4befaaa70
IsRealTimeKernel
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) IsRealTimeKernel() (bool, error) { // we can use the IsKernelArgEnabled to check the realtime kernel return n.IsKernelArgEnabled("PREEMPT_RT") }
mco
function
openshift/openshift-tests-private
22c34ee5-d9ae-46b4-b20e-d43530a58f96
Is64kPagesKernel
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) Is64kPagesKernel() (bool, error) { // we can use the IsKernelArgEnabled to check the 64k-pages kernel return n.IsKernelArgEnabled("+64k") }
mco
function
openshift/openshift-tests-private
ebea3ac3-0d00-4847-b1a8-c59b3e19b6d2
InstallRpm
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) InstallRpm(rpmName string) (string, error) { logger.Infof("Installing rpm '%s' in node %s", rpmName, n.GetName()) out, err := n.DebugNodeWithChroot("rpm-ostree", "install", rpmName) return out, err }
mco
function
openshift/openshift-tests-private
c1842db9-9ec1-419a-8560-8e999f49f095
UninstallRpm
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) UninstallRpm(rpmName string) (string, error) { logger.Infof("Uninstalling rpm '%s' in node %s", rpmName, n.GetName()) out, err := n.DebugNodeWithChroot("rpm-ostree", "uninstall", rpmName) return out, err }
mco
function
openshift/openshift-tests-private
47ebf4af-a86d-4781-9c8c-fbb585ffc168
Reboot
['"fmt"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) Reboot() error { afterSeconds := 1 logger.Infof("REBOOTING NODE %s after %d seconds!!", n.GetName(), afterSeconds) // In SNO we cannot trigger the reboot directly using a debug command (like: "sleep 10 && reboot"), because the debug pod will return a failure // because we lose connectivity with the cluster when we reboot the only node in the cluster // The solution is to schedule a reboot 1 second after the Reboot method is called, and wait 5 seconds to make sure that the reboot happened out, err := n.DebugNodeWithChroot("sh", "-c", fmt.Sprintf("systemd-run --on-active=%d --timer-property=AccuracySec=10ms reboot", afterSeconds)) if err != nil { logger.Errorf("Error rebooting node %s:\n%s", n, out) } time.Sleep(time.Duration(afterSeconds) * time.Second) // we don't return the control of the program until we make sure that the timer for the reboot has expired return err }
mco
function
openshift/openshift-tests-private
c2669854-e5e1-407a-a4af-2c88f434da0f
IsRpmOsTreeIdle
['"strings"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) IsRpmOsTreeIdle() (bool, error) { status, err := n.GetRpmOstreeStatus(false) if strings.Contains(status, "State: idle") { return true, err } return false, err }
mco
function
openshift/openshift-tests-private
2d7f5eaa-e600-42cc-b25d-5d9643f2c762
WaitUntilRpmOsTreeIsIdle
['"context"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) WaitUntilRpmOsTreeIsIdle() error { logger.Infof("Waiting for rpm-ostree state to be idle in node %s", n.GetName()) immediate := false waitErr := wait.PollUntilContextTimeout(context.TODO(), 10*time.Second, 10*time.Minute, immediate, func(_ context.Context) (bool, error) { isIddle, err := n.IsRpmOsTreeIdle() if err == nil { if isIddle { return true, nil } return false, nil } logger.Infof("Error waiting for rpm-ostree status to report idle state: %s.\nTry next round", err) return false, nil }) if waitErr != nil { logger.Errorf("Timeout while waiting for rpm-ostree status to report idle state in node %s. Error: %s", n.GetName(), waitErr) } return waitErr }
mco
function
openshift/openshift-tests-private
2cff27d8-49aa-4d4d-a3e9-40972c3aea7e
CancelRpmOsTreeTransactions
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) CancelRpmOsTreeTransactions() (string, error) { return n.DebugNodeWithChroot("rpm-ostree", "cancel") }
mco
function
openshift/openshift-tests-private
853b05aa-9fbc-4b5d-85f0-bc8d8b6355a6
CopyFromLocal
['"context"', '"fmt"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) CopyFromLocal(from, to string) error { immediate := true waitErr := wait.PollUntilContextTimeout(context.TODO(), 1*time.Minute, 5*time.Minute, immediate, func(_ context.Context) (bool, error) { kubeletReady := n.IsReady() if kubeletReady { return true, nil } logger.Warnf("Kubelet is not ready in %s. To copy the file to the node we need to wait for kubelet to be ready. Waiting...", n) return false, nil }) if waitErr != nil { logger.Errorf("Cannot copy file %s to %s in node %s because Kubelet is not ready in this node", from, to, n) return waitErr } return n.oc.Run("adm").Args("copy-to-node", "node/"+n.GetName(), fmt.Sprintf("--copy=%s=%s", from, to)).Execute() }
mco
function
openshift/openshift-tests-private
87f6d63f-76ed-4cf0-9b55-22a9ea8ef379
CopyToLocal
['"path"', '"path/filepath"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) CopyToLocal(from, to string) error { logger.Infof("Node: %s. Copying file %s to local path %s", n.GetName(), from, to) mcDaemonName := n.GetMachineConfigDaemon() fromDaemon := filepath.Join("/rootfs", from) return n.oc.Run("cp").Args("-n", MachineConfigNamespace, mcDaemonName+":"+fromDaemon, to, "-c", MachineConfigDaemon).Execute() }
mco
function
openshift/openshift-tests-private
cfcc6072-5cde-4838-90b0-40cc6246b33b
RemoveFile
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) RemoveFile(filePathToRemove string) error { logger.Infof("Removing file %s from node %s", filePathToRemove, n.GetName()) output, err := n.DebugNodeWithChroot("rm", "-f", filePathToRemove) logger.Infof(output) return err }
mco
function
openshift/openshift-tests-private
7818b0d2-7212-4e0f-a935-8faa2a6b4719
RpmIsInstalled
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) RpmIsInstalled(rpmNames ...string) bool { rpmOutput, err := n.DebugNodeWithChroot(append([]string{"rpm", "-q"}, rpmNames...)...) logger.Infof(rpmOutput) return err == nil }
mco
function
openshift/openshift-tests-private
a5f49df6-d7a2-4473-9a7c-92421fe657a0
ExecuteDebugExpectBatch
['"fmt"', '"time"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) ExecuteDebugExpectBatch(timeout time.Duration, batch []expect.Batcher) ([]expect.BatchRes, error) { setErr := quietSetNamespacePrivileged(n.oc, n.oc.Namespace()) if setErr != nil { return nil, setErr } debugCommand := fmt.Sprintf("oc --kubeconfig=%s -n %s debug node/%s", exutil.KubeConfigPath(), n.oc.Namespace(), n.GetName()) logger.Infof("Expect spawning command: %s", debugCommand) e, _, err := expect.Spawn(debugCommand, -1, expect.Verbose(true)) defer func() { _ = e.Close() }() if err != nil { logger.Errorf("Error spawning process %s. Error: %s", debugCommand, err) return nil, err } bresps, err := e.ExpectBatch(batch, timeout) if err != nil { logger.Errorf("Error executing batch: %s", err) } recErr := quietRecoverNamespaceRestricted(n.oc, n.oc.Namespace()) if recErr != nil { return nil, err } return bresps, err }
mco
function
openshift/openshift-tests-private
007fb7f7-7cfb-4560-9bea-3d2f04c735dd
UserAdd
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) UserAdd(userName string) error { logger.Infof("Create user %s in node %s", userName, n.GetName()) _, err := n.DebugNodeWithChroot("useradd", userName) return err }
mco
function
openshift/openshift-tests-private
d0f29ce7-9d6c-4e5c-8498-00c2766ddba3
UserDel
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) UserDel(userName string) error { logger.Infof("Delete user %s in node %s", userName, n.GetName()) _, err := n.DebugNodeWithChroot("userdel", "-f", userName) return err }
mco
function
openshift/openshift-tests-private
596a8c5f-a750-4367-855b-80cb25d198f9
UserExists
['"fmt"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) UserExists(userName string) bool { _, err := n.DebugNodeWithChroot("grep", "-E", fmt.Sprintf("^%s:", userName), "/etc/shadow") return err == nil }
mco
function
openshift/openshift-tests-private
4f600107-73e7-4a81-8b38-1150b861b646
GetRHELVersion
['"fmt"', '"regexp"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) GetRHELVersion() (string, error) { vContent, err := n.DebugNodeWithChroot("cat", "/etc/os-release") if err != nil { return "", err } r := regexp.MustCompile(`RHEL_VERSION="?(?P<rhel_version>.*)"?`) match := r.FindStringSubmatch(vContent) if len(match) == 0 { msg := fmt.Sprintf("No RHEL_VERSION available in /etc/os-release file: %s", vContent) logger.Infof(msg) return "", fmt.Errorf(msg) } rhelvIndex := r.SubexpIndex("rhel_version") rhelVersion := match[rhelvIndex] logger.Infof("Node %s RHEL_VERSION %s", n.GetName(), rhelVersion) return rhelVersion, nil }
mco
function
openshift/openshift-tests-private
79bcc436-5878-4a45-a6cd-692915f4214f
GetPrimaryPool
['"fmt"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) GetPrimaryPool() (*MachineConfigPool, error) { allMCPs, err := NewMachineConfigPoolList(n.oc).GetAll() if err != nil { return nil, err } var primaryPool *MachineConfigPool for _, item := range allMCPs { pool := item allNodes, err := pool.getSelectedNodes("") if err != nil { return nil, err } for _, node := range allNodes { if node.GetName() != n.GetName() { continue } // We use short circuit evaluation to set the primary pool: // - If the pool is master, it will be the primary pool; // - If the primary pool is nil (not set yet), we set the primary pool (either worker or custom); // - If the primary pool is not nil, we overwrite it only if the primary pool is a worker. if pool.IsMaster() || primaryPool == nil || primaryPool.IsWorker() { primaryPool = &pool } else if pool.IsCustom() && primaryPool != nil && primaryPool.IsCustom() { // Error condition: the node belongs to 2 custom pools return nil, fmt.Errorf("Forbidden configuration. The node %s belongs to 2 custom pools: %s and %s", node.GetName(), primaryPool.GetName(), pool.GetName()) } } } return primaryPool, nil }
mco
function
openshift/openshift-tests-private
42e3bb07-e8f4-43aa-a6d9-4d7c9f8fc9b9
GetPrimaryPoolOrFail
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) GetPrimaryPoolOrFail() *MachineConfigPool { pool, err := n.GetPrimaryPool() o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error getting the pool that owns node %", n.GetName()) return pool }
mco
function
openshift/openshift-tests-private
7edaeaa1-de71-46e6-9493-e32674604a75
GetPools
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) GetPools() ([]MachineConfigPool, error) { allPools, err := NewMachineConfigPoolList(n.oc).GetAll() if err != nil { return nil, err } nodePools := []MachineConfigPool{} for _, mcp := range allPools { // Get all nodes labeled for this pool allNodes, err := mcp.getSelectedNodes("") if err != nil { return nil, err } for _, node := range allNodes { if n.GetName() == node.GetName() { nodePools = append(nodePools, mcp) } } } return nodePools, nil }
mco
function
openshift/openshift-tests-private
4d1d175a-5629-4feb-8441-bbab59197ce7
IsListedByPoolOrFail
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) IsListedByPoolOrFail(mcp *MachineConfigPool) bool { isInPool, err := n.IsListedByPool(mcp) o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Cannot get the list of pools for node %s", n.GetName()) return isInPool }
mco
function
openshift/openshift-tests-private
a6271672-95c6-44f4-ad9a-9151ead505df
IsListedByPool
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) IsListedByPool(mcp *MachineConfigPool) (bool, error) { pools, err := n.GetPools() if err != nil { return false, err } for _, pool := range pools { if pool.GetName() == mcp.GetName() { return true, nil } } return false, nil }
mco
function
openshift/openshift-tests-private
e65434a7-99bc-4e1d-a158-05cbc053bc25
RemoveIPTablesRulesByRegexp
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) RemoveIPTablesRulesByRegexp(regx string) ([]string, error) { return n.removeIPTablesRulesByRegexp(false, regx) }
mco
function
openshift/openshift-tests-private
0345205c-76d4-4fcc-87c1-525db396ff97
RemoveIP6TablesRulesByRegexp
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) RemoveIP6TablesRulesByRegexp(regx string) ([]string, error) { return n.removeIPTablesRulesByRegexp(true, regx) }
mco
function
openshift/openshift-tests-private
9e7aca70-4742-464a-ad4e-f9ba8a371a0e
removeIPTablesRulesByRegexp
['"regexp"', '"strings"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) removeIPTablesRulesByRegexp(ipv6 bool, regx string) ([]string, error) { removedRules := []string{} command := "iptables" if ipv6 == true { command = "ip6tables" } allRulesString, stderr, err := n.DebugNodeWithChrootStd(command, "-S") if err != nil { logger.Errorf("Error running `%s -S`. Stderr: %s", command, stderr) return nil, err } allRules := strings.Split(allRulesString, "\n") for _, rule := range allRules { if !regexp.MustCompile(regx).MatchString(rule) { continue } logger.Infof("%s. Removing %s rule: %s", n.GetName(), command, rule) removeCommand := strings.Replace(rule, "-A", "-D", 1) output, err := n.DebugNodeWithChroot(append([]string{command}, splitCommandString(removeCommand)...)...) // OCPQE-20258 if the rule is removed already, retry will be failed as well. add this logic to catach this error // if the error message indicates the rule does not exist, i.e. it's already removed, we consider the retry is succeed alreadyRemoved := strings.Contains(output, "does a matching rule exist in that chain") if alreadyRemoved { logger.Warnf("iptable rule %s is already removed", rule) } if err != nil && !alreadyRemoved { logger.Errorf("Output: %s", output) return removedRules, err } removedRules = append(removedRules, rule) } return removedRules, err }
mco
function
openshift/openshift-tests-private
0c7a4d55-3548-410e-a43d-ae70195a659f
execIPTables
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) execIPTables(ipv6 bool, rules []string) error { command := "iptables" if ipv6 == true { command = "ip6tables" } for _, rule := range rules { logger.Infof("%s. Adding %s rule: %s", n.GetName(), command, rule) output, err := n.DebugNodeWithChroot(append([]string{command}, splitCommandString(rule)...)...) if err != nil { logger.Errorf("Output: %s", output) return err } } return nil }
mco
function
openshift/openshift-tests-private
726eaad1-8e8e-4aca-9558-4f5a591f37c9
ExecIPTables
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) ExecIPTables(rules []string) error { return n.execIPTables(false, rules) }
mco
function
openshift/openshift-tests-private
7887da0c-3f27-4b60-9222-2a5b44f3ac17
ExecIP6Tables
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) ExecIP6Tables(rules []string) error { return n.execIPTables(true, rules) }
mco
function
openshift/openshift-tests-private
339403d6-5f18-4e20-b156-94326b696130
GetArchitecture
['"github.com/openshift/openshift-tests-private/test/extended/util/architecture"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) GetArchitecture() (architecture.Architecture, error) { arch, err := n.Get(`{.status.nodeInfo.architecture}`) if err != nil { return architecture.UNKNOWN, err } return architecture.FromString(arch), nil }
mco
function
openshift/openshift-tests-private
c03b7b30-c557-46a9-b646-99ce9f82e074
GetArchitectureOrFail
['"github.com/openshift/openshift-tests-private/test/extended/util/architecture"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) GetArchitectureOrFail() architecture.Architecture { arch, err := n.GetArchitecture() o.Expect(err).NotTo(o.HaveOccurred(), "Error getting the architecture of node %s", n.GetName()) return arch }
mco
function
openshift/openshift-tests-private
dd19ae72-c132-47fa-9496-06d99d608cdc
GetJournalLogs
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) GetJournalLogs(args ...string) (string, error) { cmd := []string{"journalctl", "-o", "with-unit"} return n.DebugNodeWithChroot(append(cmd, args...)...) }
mco
function
openshift/openshift-tests-private
e3351c07-62e9-4867-b101-2e756df397e9
GetMachineConfigNode
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) GetMachineConfigNode() *MachineConfigNode { return NewMachineConfigNode(n.oc.AsAdmin(), n.GetName()) }
mco
function
openshift/openshift-tests-private
edb88fbf-bfad-4b97-a381-6824debe2098
GetFileSystemSpaceUsage
['"fmt"', '"path"', '"regexp"', '"strconv"', '"strings"']
['Node', 'SpaceUsage']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n *Node) GetFileSystemSpaceUsage(path string) (*SpaceUsage, error) { var ( parserRegex = `(?P<Used>\d+)\D+(?P<Avail>\d+)` ) stdout, stderr, err := n.DebugNodeWithChrootStd("df", "-B1", "--output=used,avail", path) if err != nil { logger.Errorf("Error getting the disk usage in node %s:\nstdout:%s\nstderr:%s", n.GetName(), stdout, stderr) return nil, err } lines := strings.Split(stdout, "\n") if len(lines) != 2 { return nil, fmt.Errorf("Expected 2 lines, and got:\n%s", stdout) } logger.Debugf("parsing: %s", lines[1]) re := regexp.MustCompile(parserRegex) match := re.FindStringSubmatch(strings.TrimSpace(lines[1])) logger.Infof("matched disk space stat info: %v", match) // check whether matched string found if len(match) == 0 { return nil, fmt.Errorf("no disk space info matched") } usedIndex := re.SubexpIndex("Used") if usedIndex < 0 { return nil, fmt.Errorf("Could not parse Used bytes from\n%s", stdout) } used, err := strconv.ParseInt(match[usedIndex], 10, 64) if err != nil { return nil, fmt.Errorf("Could convert parsed Used data [%s] into float64 from\n%s", match[usedIndex], stdout) } availIndex := re.SubexpIndex("Avail") if usedIndex < 0 { return nil, fmt.Errorf("Could not parse Avail bytes from\n%s", stdout) } avail, err := strconv.ParseInt(match[availIndex], 10, 64) if err != nil { return nil, fmt.Errorf("Could convert parsed Avail data [%s] into float64 from\n%s", match[availIndex], stdout) } return &SpaceUsage{Used: used, Avail: avail}, nil }
mco
function
openshift/openshift-tests-private
2a0520a8-8013-4cd4-a41f-7518823a84ec
GetMachine
['"fmt"', '"strings"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) GetMachine() (*Machine, error) { machineLabel, err := n.GetAnnotation("machine.openshift.io/machine") if err != nil { return nil, err } machineLabelSplit := strings.Split(machineLabel, "/") if len(machineLabelSplit) != 2 { return nil, fmt.Errorf("Malformed machine label %s in node %s", machineLabel, n.GetName()) } machineName := machineLabelSplit[1] return NewMachine(n.GetOC(), "openshift-machine-api", machineName), nil }
mco
function
openshift/openshift-tests-private
77b4094a-2c80-442f-a380-4079137a6f33
CanUseDnfDownload
['"strings"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) CanUseDnfDownload() (bool, error) { out, err := n.DebugNodeWithChroot("dnf", "download", "--help") if err != nil { if strings.Contains(out, "No such command:") || strings.Contains(out, "No such file or directory") { return false, nil } return false, err } return true, nil }
mco
function
openshift/openshift-tests-private
2798ecfa-5679-44ce-995e-f1cee01d22d9
DnfDownload
['"fmt"', '"path"', '"regexp"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) DnfDownload(pkg, dir string) (string, error) { out, err := n.DebugNodeWithChroot("dnf", "download", pkg, "--destdir", dir) logger.Infof("Download output: %s", out) if err != nil { return "", err } expr := `(?P<package>(?m)^` + pkg + `.*rpm)` r := regexp.MustCompile(expr) match := r.FindStringSubmatch(out) if len(match) == 0 { msg := fmt.Sprintf("Wrong download output. Cannot extract the name of the downloaded package using expresion %s:\n%s", expr, out) logger.Errorf(msg) return "", fmt.Errorf(msg) } pkgNameIndex := r.SubexpIndex("package") pkgName := match[pkgNameIndex] fullPkgName := path.Join(dir, pkgName) logger.Infof("Downloaded package: %s", fullPkgName) return fullPkgName, nil }
mco
function
openshift/openshift-tests-private
f8a49b3d-ea38-4195-90a2-2e3cf6c4bbcb
OSReset
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (n Node) OSReset() error { logger.Infof("Resetting the OS in node %s", n) _, err := n.DebugNodeWithChroot("rpm-ostree", "reset") return err }
mco
function
openshift/openshift-tests-private
ba0cdd9e-1300-4580-8f3f-e703e6efed8d
GetAll
['Node', 'NodeList']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (nl *NodeList) GetAll() ([]Node, error) { allNodeResources, err := nl.ResourceList.GetAll() if err != nil { return nil, err } allNodes := make([]Node, 0, len(allNodeResources)) for _, nodeRes := range allNodeResources { allNodes = append(allNodes, *NewNode(nl.oc, nodeRes.name)) } return allNodes, nil }
mco
function
openshift/openshift-tests-private
1f1633c3-28e8-4ad4-b1d2-c15434c69295
GetAllLinux
['Node', 'NodeList']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (nl NodeList) GetAllLinux() ([]Node, error) { nl.ByLabel("kubernetes.io/os=linux") return nl.GetAll() }
mco
function
openshift/openshift-tests-private
06d7a542-a1cd-4bde-bccd-9294a3062ff8
GetAllMasterNodes
['Node', 'NodeList']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (nl NodeList) GetAllMasterNodes() ([]Node, error) { nl.ByLabel("node-role.kubernetes.io/master=") return nl.GetAll() }
mco
function
openshift/openshift-tests-private
3ca1d972-2425-4c23-89a0-40c4ffc359d6
GetAllWorkerNodes
['Node', 'NodeList']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (nl NodeList) GetAllWorkerNodes() ([]Node, error) { nl.ByLabel("node-role.kubernetes.io/worker=") return nl.GetAll() }
mco
function
openshift/openshift-tests-private
a0512b7e-1cb5-407b-9aa7-25535489abe4
GetAllMasterNodesOrFail
['Node', 'NodeList']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (nl NodeList) GetAllMasterNodesOrFail() []Node { masters, err := nl.GetAllMasterNodes() o.Expect(err).NotTo(o.HaveOccurred()) return masters }
mco
function
openshift/openshift-tests-private
2be48d75-c019-40fc-909a-ec1e68d6274b
GetAllWorkerNodesOrFail
['Node', 'NodeList']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (nl NodeList) GetAllWorkerNodesOrFail() []Node { workers, err := nl.GetAllWorkerNodes() o.Expect(err).NotTo(o.HaveOccurred()) return workers }
mco
function
openshift/openshift-tests-private
bdb7cb4a-96cb-4f0d-9fa7-4de216e7bcf6
GetAllLinuxWorkerNodes
['Node', 'NodeList']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (nl NodeList) GetAllLinuxWorkerNodes() ([]Node, error) { nl.ByLabel("node-role.kubernetes.io/worker=,kubernetes.io/os=linux") return nl.GetAll() }
mco
function
openshift/openshift-tests-private
b77e3ebe-2b5c-4afe-a35e-49efb2fdf6a7
GetAllLinuxWorkerNodesOrFail
['Node', 'NodeList']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (nl NodeList) GetAllLinuxWorkerNodesOrFail() []Node { workers, err := nl.GetAllLinuxWorkerNodes() o.Expect(err).NotTo(o.HaveOccurred()) return workers }
mco
function
openshift/openshift-tests-private
841c57c8-710d-4c18-b206-de4ca40331d4
GetAllRhelWokerNodesOrFail
['Node', 'NodeList']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (nl NodeList) GetAllRhelWokerNodesOrFail() []Node { nl.ByLabel("node-role.kubernetes.io/worker=,node.openshift.io/os_id=rhel") workers, err := nl.GetAll() o.Expect(err).NotTo(o.HaveOccurred()) return workers }
mco
function
openshift/openshift-tests-private
2501de00-9966-4c63-814d-61e5c7471cbe
GetAllCoreOsWokerNodesOrFail
['Node', 'NodeList']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (nl NodeList) GetAllCoreOsWokerNodesOrFail() []Node { nl.ByLabel("node-role.kubernetes.io/worker=,node.openshift.io/os_id=rhcos") workers, err := nl.GetAll() o.Expect(err).NotTo(o.HaveOccurred()) return workers }
mco
function
openshift/openshift-tests-private
c3932c07-b72d-435e-a565-d47b4cc97204
GetAllCoreOsNodesOrFail
['Node', 'NodeList']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (nl NodeList) GetAllCoreOsNodesOrFail() []Node { nl.ByLabel("node.openshift.io/os_id=rhcos") allRhcos, err := nl.GetAll() o.Expect(err).NotTo(o.HaveOccurred()) return allRhcos }
mco
function
openshift/openshift-tests-private
36198be0-ec26-4fa8-ba5a-97fd667ae613
GetTaintedNodes
['Node', 'NodeList']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (nl *NodeList) GetTaintedNodes() []Node { allNodes, err := nl.GetAll() o.Expect(err).NotTo(o.HaveOccurred()) taintedNodes := []Node{} for _, node := range allNodes { if node.IsTainted() { taintedNodes = append(taintedNodes, node) } } return taintedNodes }
mco
function
openshift/openshift-tests-private
21610438-33db-4874-bd32-7858514ac3e8
GetAllDegraded
['Node', 'NodeList']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (nl NodeList) GetAllDegraded() ([]Node, error) { filter := `?(@.metadata.annotations.machineconfiguration\.openshift\.io/state=="Degraded")` nl.SetItemsFilter(filter) return nl.GetAll() }
mco
function
openshift/openshift-tests-private
ff4fd184-677f-4512-ad26-09a8da44684b
McStateSnapshot
['NodeList']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func (nl NodeList) McStateSnapshot() string { return nl.GetOrFail(`{.items[*].metadata.annotations.machineconfiguration\.openshift\.io/state}`) }
mco
function
openshift/openshift-tests-private
418de71d-60ea-4642-8d16-ed3449d78544
quietSetNamespacePrivileged
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func quietSetNamespacePrivileged(oc *exutil.CLI, namespace string) error { oc.NotShowInfo() defer oc.SetShowInfo() logger.Debugf("Setting namespace %s as privileged", namespace) return exutil.SetNamespacePrivileged(oc, namespace) }
mco
function
openshift/openshift-tests-private
12dd1c04-493c-4269-80e4-ee0895c797e2
quietRecoverNamespaceRestricted
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func quietRecoverNamespaceRestricted(oc *exutil.CLI, namespace string) error { oc.NotShowInfo() defer oc.SetShowInfo() logger.Debugf("Recovering namespace %s from privileged", namespace) return exutil.RecoverNamespaceRestricted(oc, namespace) }
mco
function
openshift/openshift-tests-private
180fd0e0-5bbb-4865-bc50-f46a5c1e9abf
BreakRebootInNode
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func BreakRebootInNode(node *Node) error { logger.Infof("Breaking reboot process in node %s", node.GetName()) _, err := node.DebugNodeWithChroot("sh", "-c", "mount -o remount,rw /usr; mv /usr/bin/systemd-run /usr/bin/systemd-run2") return err }
mco
function
openshift/openshift-tests-private
f9db6e6b-faf5-4378-a957-2f6e156d067b
FixRebootInNode
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func FixRebootInNode(node *Node) error { logger.Infof("Fixing reboot process in node %s", node.GetName()) _, err := node.DebugNodeWithChroot("sh", "-c", "mount -o remount,rw /usr; mv /usr/bin/systemd-run2 /usr/bin/systemd-run") return err }
mco
function
openshift/openshift-tests-private
50d2fb1b-382a-4723-946f-135eaf2008b8
BreakRebaseInNode
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func BreakRebaseInNode(node *Node) error { logger.Infof("Breaking rpm-ostree rebase process in node %s", node.GetName()) brokenRpmOstree := generateTemplateAbsolutePath("rpm-ostree-force-pivot-error.sh") node.CopyFromLocal(brokenRpmOstree, "/tmp/rpm-ostree.broken") // It is very important the "-Z" option when we replace the original rpm-ostree file, because it will set the default selinux options for the file. // If we don't use this "-Z" option and the file has the wrong selinux type the test will fail because "rpm-ostree kargs" command cannot succeed _, err := node.DebugNodeWithChroot("sh", "-c", "mount -o remount,rw /usr; mv /usr/bin/rpm-ostree /usr/bin/rpm-ostree2 && mv -Z /tmp/rpm-ostree.broken /usr/bin/rpm-ostree && chmod +x /usr/bin/rpm-ostree") return err }
mco
function
openshift/openshift-tests-private
544ed1ec-9bee-4a4f-8a38-4be065441f00
FixRebaseInNode
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func FixRebaseInNode(node *Node) error { logger.Infof("Fixing rpm-ostree rebase process in node %s", node.GetName()) _, err := node.DebugNodeWithChroot("sh", "-c", "mount -o remount,rw /usr; mv /usr/bin/rpm-ostree2 /usr/bin/rpm-ostree") return err }
mco
function
openshift/openshift-tests-private
6d888e96-4740-421c-b02a-af0d08adeb83
FilterSchedulableNodesOrFail
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func FilterSchedulableNodesOrFail(nodes []Node) []Node { returnNodes := []Node{} for _, item := range nodes { node := item if node.IsSchedulableOrFail() { returnNodes = append(returnNodes, node) } } return returnNodes }
mco
function
openshift/openshift-tests-private
1ab0a717-df6e-49fe-b58e-66bf64afc79f
GetOperatorNode
['"fmt"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func GetOperatorNode(oc *exutil.CLI) (*Node, error) { podsList := NewNamespacedResourceList(oc.AsAdmin(), "pods", MachineConfigNamespace) podsList.ByLabel("k8s-app=machine-config-operator") mcoPods, err := podsList.GetAll() if err != nil { return nil, err } if len(mcoPods) != 1 { return nil, fmt.Errorf("There should be 1 and only 1 MCO operator pod. Found operator pods: %s", mcoPods) } nodeName, err := mcoPods[0].Get(`{.spec.nodeName}`) if err != nil { return nil, err } return NewNode(oc, nodeName), nil }
mco
function
openshift/openshift-tests-private
d301a3f4-1993-48b7-86c5-9db30bcf8f1c
ConfigureStreamCentosRepo
['"path"']
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func ConfigureStreamCentosRepo(n Node, stream string) error { var ( centosStreamTemplate = generateTemplateAbsolutePath("centos_stream.repo") centosStreamRepoFile = "/etc/yum.repos.d/mco-test-centos.repo" dnfVarDir = "/etc/dnf/vars/" streamVarRemoteFile = NewRemoteFile(n, path.Join(dnfVarDir, "stream")) proxy = NewResource(n.GetOC().AsAdmin(), "proxy", "cluster") ) logger.Infof("Creating necessary repo files") err := n.CopyFromLocal(centosStreamTemplate, centosStreamRepoFile) if err != nil { return err } _, err = n.DebugNodeWithChroot("mkdir", "-p", dnfVarDir) if err != nil { logger.Errorf("Error creating the dnf var directory %s: %s", dnfVarDir, err) return err } err = streamVarRemoteFile.Create([]byte(stream), 0o600) if err != nil { logger.Errorf("Error writing the content <%s> in the dnf var file %s: %s", stream, streamVarRemoteFile, err) return err } logger.Infof("Configuring proxy settings") httpProxy, err := proxy.Get(`{.status.httpProxy}`) if err != nil { logger.Errorf("Error getting the httpProxy value") return err } _, err = n.DebugNodeWithChroot("sed", "-i", "s#proxy=#proxy="+httpProxy+"#g", centosStreamRepoFile) if err != nil { logger.Errorf("Error configuring proxy in the centos repo file") return err } return err }
mco
function
openshift/openshift-tests-private
c2949caa-ea41-4c83-a18d-b91204eff800
RemoveConfiguredStreamCentosRepo
['Node']
github.com/openshift/openshift-tests-private/test/extended/mco/node.go
func RemoveConfiguredStreamCentosRepo(n Node) error { logger.Infof("Remoing the stream centos repo configuration") _, err := n.DebugNodeWithChroot("rm", "/etc/yum.repos.d/mco-test-centos.repo", "/etc/dnf/vars/stream") return err }
mco
test
openshift/openshift-tests-private
15a04b83-3af9-4861-99ee-4faf25c0f5d2
resource
import ( "encoding/json" "fmt" "os" "reflect" "strings" "time" o "github.com/onsi/gomega" "github.com/onsi/gomega/types" exutil "github.com/openshift/openshift-tests-private/test/extended/util" logger "github.com/openshift/openshift-tests-private/test/extended/util/logext" e2e "k8s.io/kubernetes/test/e2e/framework" )
github.com/openshift/openshift-tests-private/test/extended/mco/resource.go
package mco import ( "encoding/json" "fmt" "os" "reflect" "strings" "time" o "github.com/onsi/gomega" "github.com/onsi/gomega/types" exutil "github.com/openshift/openshift-tests-private/test/extended/util" logger "github.com/openshift/openshift-tests-private/test/extended/util/logext" e2e "k8s.io/kubernetes/test/e2e/framework" ) type ocGetter struct { oc *exutil.CLI kind string namespace string name string } // Template helps to create resources using openshift templates type Template struct { oc *exutil.CLI templateFile string } // ResourceInterface defines all methods available in a resource type ResourceInterface interface { GetKind() string GetName() string GetNamespace() string Get(jsonPath string, extraParams ...string) (string, error) GetSafe(jsonPath string, defaultValue string, extraParams ...string) string GetOrFail(jsonPath string, extraParams ...string) string Poll(jsonPath string) func() string Delete(extraParams ...string) error DeleteOrFail(extraParams ...string) Exists() bool Patch(patchType string, patch string, extraParams ...string) error GetAnnotationOrFail(annotation string) string GetConditionByType(ctype string) string IsConditionStatusTrue(ctype string) bool AddLabel(label, value string) error GetLabel(label string) (string, error) Describe() (string, error) ExportToFile(fileName string) error PrettyString() string GetOC() *exutil.CLI GetCleanJSON() (string, error) } // Resource will provide the functionality to hanlde general openshift resources type Resource struct { ocGetter } // GetOC retunrs the oc CLI used to execute commands in the resource func (r ocGetter) GetOC() *exutil.CLI { return r.oc } // getCommonParams returns the params that are necessary for all commands involving this object // It returns these 3 params (or 2 if the object is not namespaced): {kind} {resourcename} ({-n} {namespace} only if namespaced) func (r *ocGetter) getCommonParams() []string { params := []string{r.kind} if r.name != "" { params = append(params, r.name) } if r.namespace != "" { params = append([]string{"-n", r.namespace}, params...) } return params } // GetName returns the 'name' field func (r ocGetter) GetName() string { return r.name } // GetKind returns the 'kind' field func (r ocGetter) GetKind() string { return r.kind } // GetNamespace returns the 'namespace' field func (r ocGetter) GetNamespace() string { return r.namespace } // PrintDebugCommand prints the output of a "oc get $kind -n $namespace $name" command func (r ocGetter) PrintDebugCommand() error { params := r.getCommonParams() err := r.oc.WithoutNamespace().Run("get").Args(params...).Execute() return err } // GetCleanJSON return -o json output representation of the resource instead of -o jsonpath='{}'. It filters several fileds like managedFields. It is cleaner. func (r ocGetter) GetCleanJSON() (string, error) { params := r.getCommonParams() params = append(params, []string{"-o", "json"}...) result, err := r.oc.WithoutNamespace().Run("get").Args(params...).Output() return result, err } // Get uses the CLI to retrieve the return value for this jsonpath func (r *ocGetter) Get(jsonPath string, extraParams ...string) (string, error) { params := r.getCommonParams() params = append(params, extraParams...) params = append(params, []string{"-o", fmt.Sprintf("jsonpath=%s", jsonPath)}...) logger.Debugf("resource params %v:", params) result, err := r.oc.WithoutNamespace().Run("get").Args(params...).Output() return result, err } // GetSafe uses the CLI to retrieve the return value for this jsonpath, if the resource does not exist, it returns the defaut value func (r *ocGetter) GetSafe(jsonPath, defaultValue string, extraParams ...string) string { ret, err := r.Get(jsonPath, extraParams...) if err != nil { return defaultValue } return ret } // GetOrFail uses the CLI to retrieve the return value for this jsonpath, if the resource does not exist, it fails the test func (r *ocGetter) GetOrFail(jsonPath string, extraParams ...string) string { ret, err := r.Get(jsonPath, extraParams...) if err != nil { e2e.Failf("Could not get value %s in %s. Error: %v", jsonPath, r, err) } return ret } // PollValue returns a function suitable to be used with the gomega Eventually/Consistently checks func (r *ocGetter) Poll(jsonPath string) func() string { return func() string { ret, _ := r.Get(jsonPath) return ret } } // String implements the Stringer interface func (r ocGetter) String() string { return fmt.Sprintf("<Kind: %s, Name: %s, Namespace: %s>", r.kind, r.name, r.namespace) } // NewResource constructs a Resource struct for a not-namespaced resource func NewResource(oc *exutil.CLI, kind, name string) *Resource { return &Resource{ocGetter: ocGetter{oc, kind, "", name}} } // NewNamespacedResource constructs a Resource struct for a namespaced resource func NewNamespacedResource(oc *exutil.CLI, kind, namespace, name string) *Resource { return &Resource{ocGetter: ocGetter{oc, kind, namespace, name}} } // Delete removes the resource from openshift cluster func (r *Resource) Delete(extraParams ...string) error { params := r.getCommonParams() params = append(params, extraParams...) _, err := r.oc.WithoutNamespace().Run("delete").Args(params...).Output() if err != nil { logger.Errorf("%v", err) } return err } // DeleteOrFail deletes the resource, and if any error happens it fails the testcase func (r *Resource) DeleteOrFail(extraParams ...string) { err := r.Delete(extraParams...) o.Expect(err).NotTo(o.HaveOccurred()) } // GetSpecOrFail returns the resource's spec as a JSON string func (r Resource) GetSpecOrFail() string { return r.GetOrFail(`{.spec}`) } // SetSpec replace the current resource's spec with the provided JSON string spec func (r Resource) SetSpec(spec string) error { return r.Patch("json", `[{ "op": "add", "path": "/spec", "value": `+spec+`}]`) } // Exists returns true if the resource exists and false if not func (r *Resource) Exists() bool { _, err := r.Get("{.}") return err == nil } // HasOwnerOrFail returns true if the resource is owned by any other resource func (r Resource) HasOwner() (bool, error) { firstOwner, err := r.Get(`{.metadata.ownerReferences[0]}`) return firstOwner != "", err } // Logs exeucte the logs subcommand with using this resource func (r Resource) Logs(args ...string) (string, error) { var ( params = []string{} stdout, stderr string err error ) if r.namespace != "" { params = append([]string{"-n", r.namespace}, params...) } params = append(params, args...) params = append(params, r.kind+"/"+r.name) err = Retry(5, 10*time.Second, func() error { stdout, stderr, err = r.oc.WithoutNamespace().Run("logs").Args(params...).Outputs() return err }) if err != nil { logger.Errorf("Error getting %s logs.\nStdout:%s\nStderr:%s\nErr:%s", r, stdout, stderr, err) return stdout + stderr, err } return stdout, err } // Patch patches the resource using the given patch type // The following patches are exactly the same patch but using different types, 'merge' and 'json' // --type merge -p '{"spec": {"selector": {"app": "frommergepatch"}}}' // --type json -p '[{ "op": "replace", "path": "/spec/selector/app", "value": "fromjsonpatch"}]' func (r *Resource) Patch(patchType, patch string, extraParams ...string) error { params := r.getCommonParams() params = append(params, []string{"--type", patchType, "-p", patch}...) params = append(params, extraParams...) _, err := r.oc.WithoutNamespace().Run("patch").Args(params...).Output() if err != nil { logger.Errorf("%v", err) } return err } // GetAnnotation returns the value of the given annotation func (r *Resource) GetAnnotation(annotation string) (string, error) { scapedAnnotation := strings.ReplaceAll(annotation, `.`, `\.`) return r.Get(fmt.Sprintf(`{.metadata.annotations.%s}`, scapedAnnotation)) } // GetAnnotationOrFail returns the value of the given annotation and fails the test case if there is any error func (r *Resource) GetAnnotationOrFail(annotation string) string { annotation, err := r.GetAnnotation(annotation) o.Expect(err).NotTo(o.HaveOccurred(), "Error getting annotation %s from %s", annotation, r) return annotation } // GetConditionByType returns the status.condition matching the given type func (r *Resource) GetConditionByType(ctype string) string { return r.GetOrFail(`{.status.conditions[?(@.type=="` + ctype + `")]}`) } func (r *Resource) GetConditionStatusByType(ctype string) string { return r.GetOrFail(`{.status.conditions[?(@.type=="` + ctype + `")].status}`) } func (r *Resource) IsConditionStatusTrue(ctype string) bool { return strings.EqualFold(r.GetConditionStatusByType(ctype), TrueString) } // GetLabel returns the label's value if the value exists. It returns an error if the label does not exist func (r *Resource) GetLabel(label string) (string, error) { labels := map[string]string{} labelsJSON, err := r.Get(`{.metadata.labels}`) if err != nil { return "", err } if labelsJSON == "" { return "", fmt.Errorf("Labels not defined. Could not get .metadata.labels attribute") } if err := json.Unmarshal([]byte(labelsJSON), &labels); err != nil { return "", err } value, ok := labels[label] if !ok { return "", fmt.Errorf("%s. Label not found in -n %s %s", label, r.GetNamespace(), r.GetName()) } return value, nil } // AddLabel adds a label to the resource func (r *Resource) AddLabel(label, value string) error { params := r.getCommonParams() params = append(params, []string{label + "=" + value}...) return r.oc.WithoutNamespace().Run("label").Args(params...).Execute() } // RemoveLabel removes a label to the resource func (r *Resource) RemoveLabel(label string) error { params := r.getCommonParams() params = append(params, []string{label + "-"}...) return r.oc.WithoutNamespace().Run("label").Args(params...).Execute() } func (r *Resource) Describe() (string, error) { params := []string{r.kind, r.name} if r.namespace != "" { params = append([]string{"-n", r.namespace}, params...) } return r.oc.WithoutNamespace().Run("describe").Args(params...).Output() } // ExportToFile writes the resource json information in a given file. func (r *Resource) ExportToFile(fileName string) error { // We want to write the json info as "pretty", so that it is human readable. // But we don't want to use "PrettyString" because we want full control on the errors definition, dErr := r.Get(`{}`) if dErr != nil { return dErr } var data interface{} if err := json.Unmarshal([]byte(definition), &data); err != nil { return err } formattedDefinition, err := json.MarshalIndent(data, "", " ") if err != nil { return err } value := string(formattedDefinition) err = os.WriteFile(fileName, []byte(value), 0o644) if err != nil { logger.Infof("Resource %s has been saved in file %s", r, fileName) } return err } // PrettyString returns an indented json string with the definition of the resource func (r *Resource) PrettyString() string { definition, dErr := r.Get(`{}`) if dErr != nil { return dErr.Error() } var data interface{} if err := json.Unmarshal([]byte(definition), &data); err != nil { return err.Error() } formattedDefinition, err := json.MarshalIndent(data, "", " ") if err != nil { return err.Error() } return string(formattedDefinition) } // NewMCOTemplate creates a new template using the MCO fixture directory as the base path of the template file func NewMCOTemplate(oc *exutil.CLI, fileName string) *Template { return &Template{oc: oc, templateFile: generateTemplateAbsolutePath(fileName)} } // SetTemplate sets the template file that will be used to create this resource func (t *Template) SetTemplate(template string) { t.templateFile = template } // Create the resources defined in the template file // The template will be created using oc with no namespace (-n NAMESPACE) argument. So if we want to // create a namespaced resource we need to add the NAMESPACE parameter to the template and // provide the "-p NAMESPACE" argument to this function. func (t *Template) Create(parameters ...string) error { if t.templateFile == "" { return fmt.Errorf("There is no template configured") } allParams := []string{"--ignore-unknown-parameters=true", "-f", t.templateFile} allParams = append(allParams, parameters...) return exutil.CreateClusterResourceFromTemplateWithError(t.oc, allParams...) } // ResourceList provides the functionality to handle lists of openshift resources type ResourceList struct { ocGetter extraParams []string itemsFilter string } // NewResourceList constructs a ResourceList struct for not-namespaced resources func NewResourceList(oc *exutil.CLI, kind string) *ResourceList { return &ResourceList{ocGetter{oc.AsAdmin(), kind, "", ""}, []string{}, ""} } // NewNamespacedResourceList constructs a ResourceList struct for namespaced resources func NewNamespacedResourceList(oc *exutil.CLI, kind, namespace string) *ResourceList { return &ResourceList{ocGetter{oc.AsAdmin(), kind, namespace, ""}, []string{}, ""} } // CleanParams removes the extraparams added by methods like "ByLabel" or "SorBy..." func (l *ResourceList) CleanParams() { l.extraParams = []string{} } // SortByTimestamp will configure the list to be sorted by creation timestamp func (l *ResourceList) SortByTimestamp() { l.SortBy("metadata.creationTimestamp") } // SortByZone will configure the list to be sorted by HA topology zone func (l *ResourceList) SortByZone() { l.SortBy(`.metadata.labels.topology\.kubernetes\.io/zone`) } // SortBy will configure the list to be sorted by the given field func (l *ResourceList) SortBy(field string) { l.extraParams = append(l.extraParams, fmt.Sprintf(`--sort-by=%s`, field)) } // ByLabel will use the given label to filter the list func (l *ResourceList) ByLabel(label string) { l.extraParams = append(l.extraParams, fmt.Sprintf("--selector=%s", label)) } // ByFieldSelector will use the given field selector to fileter the list func (l *ResourceList) ByFieldSelector(fieldSelector string) { l.extraParams = append(l.extraParams, fmt.Sprintf("--field-selector=%s", fieldSelector)) } // SetItemsFilter sets the filter used by jsonpath expression when getting all resources "{.items["+ itemsFilter + "].metadata.name}" // an example of a valid filter is: `?(@.metadata.annotations.machine\.openshift\.io/machine=="openshift-machine-api/mymachinesetname-rc2-g5wx5-worker-us-east-2a-t9hw2")` func (l *ResourceList) SetItemsFilter(filter string) { l.itemsFilter = filter } // GetAll returns a list of Resource structs with the resources found in this list func (l ResourceList) GetAll() ([]Resource, error) { if l.itemsFilter == "" { l.itemsFilter = "*" } // silently look for the elements in order not to create a dirty log // TODO: Improve this. There is no method to get the current showInfo value, so we can't restore it l.oc.NotShowInfo() defer l.oc.SetShowInfo() allItemsNames, err := l.Get("{.items["+l.itemsFilter+"].metadata.name}", l.extraParams...) if err != nil { return nil, err } allNames := strings.Split(strings.Trim(allItemsNames, " "), " ") allResources := []Resource{} for _, name := range allNames { if name != "" { newResource := Resource{ocGetter: ocGetter{l.oc, l.kind, l.namespace, name}} allResources = append(allResources, newResource) } } return allResources, nil } // Exister interface for any object having a "Exists() (bool)" method. So that they can use the "Exist" gomega matcher type Exister interface { Exists() bool } // Exist returns a gomega matcher that checks if a resource exists or not func Exist() types.GomegaMatcher { return &existMatcher{} } type existMatcher struct { } func (matcher *existMatcher) Match(actual interface{}) (success bool, err error) { resource, ok := actual.(Exister) if !ok { return false, fmt.Errorf("Exist matcher expects a resource implementing the Exister interface") } return resource.Exists(), nil } func (matcher *existMatcher) FailureMessage(actual interface{}) (message string) { return fmt.Sprintf("Expected %s \n\t%s\nto exist", reflect.TypeOf(actual), actual) } func (matcher *existMatcher) NegatedFailureMessage(actual interface{}) (message string) { return fmt.Sprintf("Expected %s \n\t%s\nnot to exist", reflect.TypeOf(actual), actual) }
package mco
function
openshift/openshift-tests-private
98f6c1bd-81dc-47d6-87fc-c5b45edfe390
GetOC
['ocGetter']
github.com/openshift/openshift-tests-private/test/extended/mco/resource.go
func (r ocGetter) GetOC() *exutil.CLI { return r.oc }
mco
function
openshift/openshift-tests-private
bed603c6-526b-468a-9ad1-d0e629620a82
getCommonParams
['ocGetter']
github.com/openshift/openshift-tests-private/test/extended/mco/resource.go
func (r *ocGetter) getCommonParams() []string { params := []string{r.kind} if r.name != "" { params = append(params, r.name) } if r.namespace != "" { params = append([]string{"-n", r.namespace}, params...) } return params }
mco
function
openshift/openshift-tests-private
e9c954e6-9dc7-44ef-9311-43bee95b0950
GetName
['ocGetter']
github.com/openshift/openshift-tests-private/test/extended/mco/resource.go
func (r ocGetter) GetName() string { return r.name }
mco
function
openshift/openshift-tests-private
3b00bfc0-59b0-4d0a-bcb5-6e60ff5f588b
GetKind
['ocGetter']
github.com/openshift/openshift-tests-private/test/extended/mco/resource.go
func (r ocGetter) GetKind() string { return r.kind }
mco
function
openshift/openshift-tests-private
a72d9caa-0cb4-4f2e-8819-e823f856f3bf
GetNamespace
['ocGetter']
github.com/openshift/openshift-tests-private/test/extended/mco/resource.go
func (r ocGetter) GetNamespace() string { return r.namespace }
mco
function
openshift/openshift-tests-private
bb43c6ab-992e-4a8b-a84d-3f0a20670a3c
PrintDebugCommand
['ocGetter']
github.com/openshift/openshift-tests-private/test/extended/mco/resource.go
func (r ocGetter) PrintDebugCommand() error { params := r.getCommonParams() err := r.oc.WithoutNamespace().Run("get").Args(params...).Execute() return err }
mco