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
10a9b549-5bdb-488c-9390-e5f69d937b89
BeDegraded
['"github.com/onsi/gomega/types"']
['conditionMatcher', 'DegradedMatcher']
github.com/openshift/openshift-tests-private/test/extended/mco/gomega_matchers.go
func BeDegraded() types.GomegaMatcher { return &DegradedMatcher{&conditionMatcher{conditionType: "Degraded", field: "status", expected: "True"}} }
mco
function
openshift/openshift-tests-private
5b37ca50-2cd6-481f-871c-a98415fbb3a5
FailureMessage
['"fmt"']
['AvailableMatcher']
github.com/openshift/openshift-tests-private/test/extended/mco/gomega_matchers.go
func (matcher *AvailableMatcher) FailureMessage(actual interface{}) (message string) { // The type was already validated in Match, we can safely ignore the error resource, _ := actual.(ResourceInterface) message = fmt.Sprintf("Resource %s is NOT Available but it should.\n%s condition: %s\n", resource, matcher.conditionType, matcher.currentCondition) message += matcher.expectedMatcher.FailureMessage(matcher.value) return message }
mco
function
openshift/openshift-tests-private
831c31ea-f68d-4ce3-8dff-3755bcce0bbc
NegatedFailureMessage
['"fmt"']
['AvailableMatcher']
github.com/openshift/openshift-tests-private/test/extended/mco/gomega_matchers.go
func (matcher *AvailableMatcher) NegatedFailureMessage(actual interface{}) (message string) { // The type was already validated in Match, we can safely ignore the error resource, _ := actual.(ResourceInterface) message = fmt.Sprintf("Resource %s is Available but it should not.\n%s condition: %s", resource, matcher.conditionType, matcher.currentCondition) message += matcher.expectedMatcher.NegatedFailureMessage(matcher.value) return message }
mco
function
openshift/openshift-tests-private
7cbdd7fd-70ae-4d4b-bfb5-6b9361c7cbd5
BeAvailable
['"github.com/onsi/gomega/types"']
['conditionMatcher', 'DegradedMatcher']
github.com/openshift/openshift-tests-private/test/extended/mco/gomega_matchers.go
func BeAvailable() types.GomegaMatcher { return &DegradedMatcher{&conditionMatcher{conditionType: "Available", field: "status", expected: "True"}} }
mco
file
openshift/openshift-tests-private
ba8b895c-819d-4615-b844-6bc14e16f5cc
inside_node_containers
import ( "fmt" "path/filepath" "strings" exutil "github.com/openshift/openshift-tests-private/test/extended/util" container "github.com/openshift/openshift-tests-private/test/extended/util/container" 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/inside_node_containers.go
package mco import ( "fmt" "path/filepath" "strings" exutil "github.com/openshift/openshift-tests-private/test/extended/util" container "github.com/openshift/openshift-tests-private/test/extended/util/container" logger "github.com/openshift/openshift-tests-private/test/extended/util/logext" e2e "k8s.io/kubernetes/test/e2e/framework" ) // OsImageBuilderInNode encapsulates the functionality to build custom osImages inside a cluster node type OsImageBuilderInNode struct { node Node baseImage, osImage, dockerFileCommands, // Full docker file but the "FROM basOsImage..." that will be calculated dockerConfig, httpProxy, httpsProxy, noProxy, tmpDir, remoteTmpDir, remoteKubeconfig, remoteDockerConfig, remoteDockerfile string UseInternalRegistry bool } func (b *OsImageBuilderInNode) prepareEnvironment() error { var err error if b.dockerConfig == "" { logger.Infof("No docker config file was provided to the osImage builder. Generating a new docker config file") exutil.By("Extract pull-secret") pullSecret := GetPullSecret(b.node.oc.AsAdmin()) tokenDir, err := pullSecret.Extract() if err != nil { return fmt.Errorf("Error extracting pull-secret. Error: %s", err) } logger.Infof("Pull secret has been extracted to: %s\n", tokenDir) b.dockerConfig = filepath.Join(tokenDir, ".dockerconfigjson") } logger.Infof("Using docker config file: %s\n", b.dockerConfig) b.remoteTmpDir = filepath.Join("/root", e2e.TestContext.OutputDir, fmt.Sprintf("mco-test-%s", exutil.GetRandomString())) _, err = b.node.DebugNodeWithChroot("mkdir", "-p", b.remoteTmpDir) if err != nil { return fmt.Errorf("Error creating tmp dir %s in node %s. Error: %s", b.remoteTmpDir, b.node.GetName(), err) } if b.remoteKubeconfig == "" { b.remoteKubeconfig = filepath.Join(b.remoteTmpDir, "kubeconfig") } if b.remoteDockerConfig == "" { b.remoteDockerConfig = filepath.Join(b.remoteTmpDir, ".dockerconfigjson") } if b.remoteDockerfile == "" { b.remoteDockerfile = filepath.Join(b.remoteTmpDir, "Dockerfile") } exutil.By("Prepare remote docker config file") logger.Infof("Copy cluster config.json file") _, cpErr := b.node.DebugNodeWithChroot("cp", "/var/lib/kubelet/config.json", b.remoteDockerConfig) if cpErr != nil { logger.Errorf("Error copying cluster config.json file to a temporary directory") return cpErr } b.baseImage, err = getImageFromReleaseInfo(b.node.oc.AsAdmin(), LayeringBaseImageReleaseInfo, b.dockerConfig) if err != nil { return fmt.Errorf("Error getting the base image to build new osImages. Error: %s", err) } uniqueTag, err := generateUniqueTag(b.node.oc.AsAdmin(), b.baseImage) if err != nil { return err } if b.UseInternalRegistry { // The images must be created inside the MCO namespace or MCO will not have permissions to pull them b.osImage = fmt.Sprintf("%s/%s/%s:%s", InternalRegistrySvcURL, MachineConfigNamespace, "layering", uniqueTag) if err := b.preparePushToInternalRegistry(); err != nil { return err } } else if b.osImage == "" { b.osImage = getLayeringTestImageRepository(uniqueTag) } logger.Infof("Building image: %s", b.osImage) if b.tmpDir == "" { b.tmpDir = e2e.TestContext.OutputDir } logger.Infof("Gathering proxy information") proxy := NewResource(b.node.oc, "proxy", "cluster") if proxy.Exists() { b.httpProxy = proxy.GetOrFail(`{.status.httpProxy}`) b.httpsProxy = proxy.GetOrFail(`{.status.httpsProxy}`) b.noProxy = proxy.GetOrFail(`{.status.noProxy}`) } logger.Infof("OK!\n") return nil } func (b *OsImageBuilderInNode) preparePushToInternalRegistry() error { logger.Infof("Create namespace to store the service account to access the internal registry") nsExistsErr := b.node.oc.Run("get").Args("namespace", layeringTestsTmpNamespace).Execute() if nsExistsErr != nil { err := b.node.oc.Run("create").Args("namespace", layeringTestsTmpNamespace).Execute() if err != nil { return fmt.Errorf("Error creating namespace %s to store the tmp SAs. Error: %s", layeringTestsTmpNamespace, err) } } else { logger.Infof("Namespace %s already exists. Skip namespace creation", layeringTestsTmpNamespace) } logger.Infof("Create service account with registry admin permissions to store the imagestream") saExistsErr := b.node.oc.Run("get").Args("-n", layeringTestsTmpNamespace, "serviceaccount", layeringRegistryAdminSAName).Execute() if saExistsErr != nil { cErr := b.node.oc.Run("create").Args("-n", layeringTestsTmpNamespace, "serviceaccount", layeringRegistryAdminSAName).Execute() if cErr != nil { return fmt.Errorf("Error creating ServiceAccount %s/%s: %s", layeringTestsTmpNamespace, layeringRegistryAdminSAName, cErr) } } else { logger.Infof("SA %s/%s already exists. Skip SA creation", layeringTestsTmpNamespace, layeringRegistryAdminSAName) } admErr := b.node.oc.Run("adm").Args("-n", layeringTestsTmpNamespace, "policy", "add-cluster-role-to-user", "registry-admin", "-z", layeringRegistryAdminSAName).Execute() if admErr != nil { return fmt.Errorf("Error creating ServiceAccount %s: %s", layeringRegistryAdminSAName, admErr) } logger.Infof("Get SA token") saToken, err := b.node.oc.Run("create").Args("-n", layeringTestsTmpNamespace, "token", layeringRegistryAdminSAName).Output() if err != nil { logger.Errorf("Error getting token for SA %s", layeringRegistryAdminSAName) return err } logger.Debugf("SA TOKEN: %s", saToken) logger.Infof("OK!\n") logger.Infof("Loging as registry admin to internal registry") loginOut, loginErr := b.node.DebugNodeWithChroot("podman", "login", InternalRegistrySvcURL, "-u", layeringRegistryAdminSAName, "-p", saToken, "--authfile", b.remoteDockerConfig) if loginErr != nil { return fmt.Errorf("Error trying to login to internal registry:\nOutput:%s\nError:%s", loginOut, loginErr) } logger.Infof("OK!\n") return nil } // CleanUp will clean up all the helper resources created by the builder func (b *OsImageBuilderInNode) CleanUp() error { logger.Infof("Cleanup image builder resources") if b.UseInternalRegistry { logger.Infof("Removing namespace %s", layeringTestsTmpNamespace) err := b.node.oc.Run("delete").Args("namespace", layeringTestsTmpNamespace, "--ignore-not-found").Execute() if err != nil { return fmt.Errorf("Error deleting namespace %s. Error: %s", layeringTestsTmpNamespace, err) } } else { logger.Infof("Not using internal registry, nothing to clean") } return nil } func (b *OsImageBuilderInNode) buildImage() error { exutil.By("Get base osImage locally") logger.Infof("Base image: %s\n", b.baseImage) exutil.By("Prepare remote dockerFile directory") dockerFile := "FROM " + b.baseImage + "\n" + b.dockerFileCommands + "\n" + ExpirationDockerfileLabel logger.Infof(" Using Dockerfile:\n%s", dockerFile) localBuildDir, err := prepareDockerfileDirectory(b.tmpDir, dockerFile) if err != nil { return fmt.Errorf("Error creating the build directory with the Dockerfile. Error: %s", err) } cpErr := b.node.CopyFromLocal(filepath.Join(localBuildDir, "Dockerfile"), b.remoteDockerfile) if cpErr != nil { return fmt.Errorf("Error creating the Dockerfile in the remote node. Error: %s", cpErr) } logger.Infof("OK!\n") exutil.By("Build osImage") podmanCLI := container.NewPodmanCLI() buildPath := filepath.Dir(b.remoteDockerfile) podmanCLI.ExecCommandPath = buildPath logger.Infof("Copy the /etc/pki/ca-trust/source/anchors/openshift-config-user-ca-bundle.crt file to the build dir, so that it can be used if needed") _, err = b.node.DebugNodeWithChroot("cp", "/etc/pki/ca-trust/source/anchors/openshift-config-user-ca-bundle.crt", buildPath) if err != nil { return err } buildCommand := "NO_PROXY=" + b.noProxy + " HTTPS_PROXY=" + b.httpsProxy + " HTTP_PROXY=" + b.httpProxy + " podman build " + buildPath + " --tag " + b.osImage + " --authfile " + b.remoteDockerConfig logger.Infof("Executing build command: %s", buildCommand) output, err := b.node.DebugNodeWithChroot("bash", "-c", buildCommand) if err != nil { msg := fmt.Sprintf("Podman failed building image %s:\n%s\n%s", b.osImage, output, err) logger.Errorf(msg) return fmt.Errorf(msg) } logger.Debugf(output) logger.Infof("OK!\n") return nil } func (b *OsImageBuilderInNode) pushImage() error { exutil.By("Push osImage") pushCommand := "NO_PROXY=" + b.noProxy + " HTTPS_PROXY=" + b.httpsProxy + " HTTP_PROXY=" + b.httpProxy + " podman push " + b.osImage + " --authfile " + b.remoteDockerConfig logger.Infof("Executing push command: %s", pushCommand) output, err := b.node.DebugNodeWithChroot("bash", "-c", pushCommand) if err != nil { msg := fmt.Sprintf("Podman failed pushing image %s:\n%s\n%s", b.osImage, output, err) logger.Errorf(msg) return fmt.Errorf(msg) } // If we don't have permissions to push the image, the `oc debug` command will not return an error // so we need to check manually that there is no unauthorized error if strings.Contains(output, "unauthorized: access to the requested resource is not authorized") { msg := fmt.Sprintf("Podman was not authorized to push the image %s:\n%s\n", b.osImage, output) logger.Errorf(msg) return fmt.Errorf(msg) } logger.Debugf(output) logger.Infof("OK!\n") return nil } func (b *OsImageBuilderInNode) removeImage() error { exutil.By("Remove osImage") rmOutput, err := b.node.DebugNodeWithChroot("podman", "rmi", "-i", b.osImage) if err != nil { msg := fmt.Sprintf("Podman failed removing image %s:\n%s\n%s", b.osImage, rmOutput, err) logger.Errorf(msg) return fmt.Errorf(msg) } logger.Debugf(rmOutput) logger.Infof("OK!\n") return nil } func (b *OsImageBuilderInNode) digestImage() (string, error) { exutil.By("Digest osImage") skopeoCommand := "NO_PROXY=" + b.noProxy + " HTTPS_PROXY=" + b.httpsProxy + " HTTP_PROXY=" + b.httpProxy + " skopeo inspect docker://" + b.osImage + " --authfile " + b.remoteDockerConfig logger.Infof("Executing skopeo command: %s", skopeoCommand) inspectInfo, _, err := b.node.DebugNodeWithChrootStd("bash", "-c", skopeoCommand) if err != nil { msg := fmt.Sprintf("Skopeo failed inspecting image %s:\n%s\n%s", b.osImage, inspectInfo, err) logger.Errorf(msg) return "", fmt.Errorf(msg) } logger.Debugf(inspectInfo) inspectJSON := JSON(inspectInfo) digestedImage := inspectJSON.Get("Name").ToString() + "@" + inspectJSON.Get("Digest").ToString() logger.Infof("Image %s was built and pushed properly", b.osImage) logger.Infof("Image %s was digested as %s", b.osImage, digestedImage) logger.Infof("OK!\n") return digestedImage, nil } // CreateAndDigestOsImage create the osImage and returns the image digested func (b *OsImageBuilderInNode) CreateAndDigestOsImage() (string, error) { if err := b.prepareEnvironment(); err != nil { return "", err } if err := b.buildImage(); err != nil { return "", err } if err := b.pushImage(); err != nil { return "", err } if err := b.removeImage(); err != nil { return "", err } return b.digestImage() }
package mco
function
openshift/openshift-tests-private
183fd6ad-3e0b-4460-a60c-2575570ab81b
prepareEnvironment
['"fmt"', '"path/filepath"']
['OsImageBuilderInNode']
github.com/openshift/openshift-tests-private/test/extended/mco/inside_node_containers.go
func (b *OsImageBuilderInNode) prepareEnvironment() error { var err error if b.dockerConfig == "" { logger.Infof("No docker config file was provided to the osImage builder. Generating a new docker config file") exutil.By("Extract pull-secret") pullSecret := GetPullSecret(b.node.oc.AsAdmin()) tokenDir, err := pullSecret.Extract() if err != nil { return fmt.Errorf("Error extracting pull-secret. Error: %s", err) } logger.Infof("Pull secret has been extracted to: %s\n", tokenDir) b.dockerConfig = filepath.Join(tokenDir, ".dockerconfigjson") } logger.Infof("Using docker config file: %s\n", b.dockerConfig) b.remoteTmpDir = filepath.Join("/root", e2e.TestContext.OutputDir, fmt.Sprintf("mco-test-%s", exutil.GetRandomString())) _, err = b.node.DebugNodeWithChroot("mkdir", "-p", b.remoteTmpDir) if err != nil { return fmt.Errorf("Error creating tmp dir %s in node %s. Error: %s", b.remoteTmpDir, b.node.GetName(), err) } if b.remoteKubeconfig == "" { b.remoteKubeconfig = filepath.Join(b.remoteTmpDir, "kubeconfig") } if b.remoteDockerConfig == "" { b.remoteDockerConfig = filepath.Join(b.remoteTmpDir, ".dockerconfigjson") } if b.remoteDockerfile == "" { b.remoteDockerfile = filepath.Join(b.remoteTmpDir, "Dockerfile") } exutil.By("Prepare remote docker config file") logger.Infof("Copy cluster config.json file") _, cpErr := b.node.DebugNodeWithChroot("cp", "/var/lib/kubelet/config.json", b.remoteDockerConfig) if cpErr != nil { logger.Errorf("Error copying cluster config.json file to a temporary directory") return cpErr } b.baseImage, err = getImageFromReleaseInfo(b.node.oc.AsAdmin(), LayeringBaseImageReleaseInfo, b.dockerConfig) if err != nil { return fmt.Errorf("Error getting the base image to build new osImages. Error: %s", err) } uniqueTag, err := generateUniqueTag(b.node.oc.AsAdmin(), b.baseImage) if err != nil { return err } if b.UseInternalRegistry { // The images must be created inside the MCO namespace or MCO will not have permissions to pull them b.osImage = fmt.Sprintf("%s/%s/%s:%s", InternalRegistrySvcURL, MachineConfigNamespace, "layering", uniqueTag) if err := b.preparePushToInternalRegistry(); err != nil { return err } } else if b.osImage == "" { b.osImage = getLayeringTestImageRepository(uniqueTag) } logger.Infof("Building image: %s", b.osImage) if b.tmpDir == "" { b.tmpDir = e2e.TestContext.OutputDir } logger.Infof("Gathering proxy information") proxy := NewResource(b.node.oc, "proxy", "cluster") if proxy.Exists() { b.httpProxy = proxy.GetOrFail(`{.status.httpProxy}`) b.httpsProxy = proxy.GetOrFail(`{.status.httpsProxy}`) b.noProxy = proxy.GetOrFail(`{.status.noProxy}`) } logger.Infof("OK!\n") return nil }
mco
function
openshift/openshift-tests-private
ef1d4c75-2a3d-476a-aae4-cc481f141075
preparePushToInternalRegistry
['"fmt"']
['OsImageBuilderInNode']
github.com/openshift/openshift-tests-private/test/extended/mco/inside_node_containers.go
func (b *OsImageBuilderInNode) preparePushToInternalRegistry() error { logger.Infof("Create namespace to store the service account to access the internal registry") nsExistsErr := b.node.oc.Run("get").Args("namespace", layeringTestsTmpNamespace).Execute() if nsExistsErr != nil { err := b.node.oc.Run("create").Args("namespace", layeringTestsTmpNamespace).Execute() if err != nil { return fmt.Errorf("Error creating namespace %s to store the tmp SAs. Error: %s", layeringTestsTmpNamespace, err) } } else { logger.Infof("Namespace %s already exists. Skip namespace creation", layeringTestsTmpNamespace) } logger.Infof("Create service account with registry admin permissions to store the imagestream") saExistsErr := b.node.oc.Run("get").Args("-n", layeringTestsTmpNamespace, "serviceaccount", layeringRegistryAdminSAName).Execute() if saExistsErr != nil { cErr := b.node.oc.Run("create").Args("-n", layeringTestsTmpNamespace, "serviceaccount", layeringRegistryAdminSAName).Execute() if cErr != nil { return fmt.Errorf("Error creating ServiceAccount %s/%s: %s", layeringTestsTmpNamespace, layeringRegistryAdminSAName, cErr) } } else { logger.Infof("SA %s/%s already exists. Skip SA creation", layeringTestsTmpNamespace, layeringRegistryAdminSAName) } admErr := b.node.oc.Run("adm").Args("-n", layeringTestsTmpNamespace, "policy", "add-cluster-role-to-user", "registry-admin", "-z", layeringRegistryAdminSAName).Execute() if admErr != nil { return fmt.Errorf("Error creating ServiceAccount %s: %s", layeringRegistryAdminSAName, admErr) } logger.Infof("Get SA token") saToken, err := b.node.oc.Run("create").Args("-n", layeringTestsTmpNamespace, "token", layeringRegistryAdminSAName).Output() if err != nil { logger.Errorf("Error getting token for SA %s", layeringRegistryAdminSAName) return err } logger.Debugf("SA TOKEN: %s", saToken) logger.Infof("OK!\n") logger.Infof("Loging as registry admin to internal registry") loginOut, loginErr := b.node.DebugNodeWithChroot("podman", "login", InternalRegistrySvcURL, "-u", layeringRegistryAdminSAName, "-p", saToken, "--authfile", b.remoteDockerConfig) if loginErr != nil { return fmt.Errorf("Error trying to login to internal registry:\nOutput:%s\nError:%s", loginOut, loginErr) } logger.Infof("OK!\n") return nil }
mco
function
openshift/openshift-tests-private
ded2c04c-fb5f-4926-abdb-ae7991557843
CleanUp
['"fmt"']
['OsImageBuilderInNode']
github.com/openshift/openshift-tests-private/test/extended/mco/inside_node_containers.go
func (b *OsImageBuilderInNode) CleanUp() error { logger.Infof("Cleanup image builder resources") if b.UseInternalRegistry { logger.Infof("Removing namespace %s", layeringTestsTmpNamespace) err := b.node.oc.Run("delete").Args("namespace", layeringTestsTmpNamespace, "--ignore-not-found").Execute() if err != nil { return fmt.Errorf("Error deleting namespace %s. Error: %s", layeringTestsTmpNamespace, err) } } else { logger.Infof("Not using internal registry, nothing to clean") } return nil }
mco
function
openshift/openshift-tests-private
45b910a4-308e-497b-b823-d38e48ceb1cf
buildImage
['"fmt"', '"path/filepath"', 'container "github.com/openshift/openshift-tests-private/test/extended/util/container"']
['OsImageBuilderInNode']
github.com/openshift/openshift-tests-private/test/extended/mco/inside_node_containers.go
func (b *OsImageBuilderInNode) buildImage() error { exutil.By("Get base osImage locally") logger.Infof("Base image: %s\n", b.baseImage) exutil.By("Prepare remote dockerFile directory") dockerFile := "FROM " + b.baseImage + "\n" + b.dockerFileCommands + "\n" + ExpirationDockerfileLabel logger.Infof(" Using Dockerfile:\n%s", dockerFile) localBuildDir, err := prepareDockerfileDirectory(b.tmpDir, dockerFile) if err != nil { return fmt.Errorf("Error creating the build directory with the Dockerfile. Error: %s", err) } cpErr := b.node.CopyFromLocal(filepath.Join(localBuildDir, "Dockerfile"), b.remoteDockerfile) if cpErr != nil { return fmt.Errorf("Error creating the Dockerfile in the remote node. Error: %s", cpErr) } logger.Infof("OK!\n") exutil.By("Build osImage") podmanCLI := container.NewPodmanCLI() buildPath := filepath.Dir(b.remoteDockerfile) podmanCLI.ExecCommandPath = buildPath logger.Infof("Copy the /etc/pki/ca-trust/source/anchors/openshift-config-user-ca-bundle.crt file to the build dir, so that it can be used if needed") _, err = b.node.DebugNodeWithChroot("cp", "/etc/pki/ca-trust/source/anchors/openshift-config-user-ca-bundle.crt", buildPath) if err != nil { return err } buildCommand := "NO_PROXY=" + b.noProxy + " HTTPS_PROXY=" + b.httpsProxy + " HTTP_PROXY=" + b.httpProxy + " podman build " + buildPath + " --tag " + b.osImage + " --authfile " + b.remoteDockerConfig logger.Infof("Executing build command: %s", buildCommand) output, err := b.node.DebugNodeWithChroot("bash", "-c", buildCommand) if err != nil { msg := fmt.Sprintf("Podman failed building image %s:\n%s\n%s", b.osImage, output, err) logger.Errorf(msg) return fmt.Errorf(msg) } logger.Debugf(output) logger.Infof("OK!\n") return nil }
mco
function
openshift/openshift-tests-private
609cea05-88dd-459e-9c48-bd09eeccf026
pushImage
['"fmt"', '"strings"']
['OsImageBuilderInNode']
github.com/openshift/openshift-tests-private/test/extended/mco/inside_node_containers.go
func (b *OsImageBuilderInNode) pushImage() error { exutil.By("Push osImage") pushCommand := "NO_PROXY=" + b.noProxy + " HTTPS_PROXY=" + b.httpsProxy + " HTTP_PROXY=" + b.httpProxy + " podman push " + b.osImage + " --authfile " + b.remoteDockerConfig logger.Infof("Executing push command: %s", pushCommand) output, err := b.node.DebugNodeWithChroot("bash", "-c", pushCommand) if err != nil { msg := fmt.Sprintf("Podman failed pushing image %s:\n%s\n%s", b.osImage, output, err) logger.Errorf(msg) return fmt.Errorf(msg) } // If we don't have permissions to push the image, the `oc debug` command will not return an error // so we need to check manually that there is no unauthorized error if strings.Contains(output, "unauthorized: access to the requested resource is not authorized") { msg := fmt.Sprintf("Podman was not authorized to push the image %s:\n%s\n", b.osImage, output) logger.Errorf(msg) return fmt.Errorf(msg) } logger.Debugf(output) logger.Infof("OK!\n") return nil }
mco
function
openshift/openshift-tests-private
4b9f1c00-f4c9-404c-b26d-682b64652a0b
removeImage
['"fmt"']
['OsImageBuilderInNode']
github.com/openshift/openshift-tests-private/test/extended/mco/inside_node_containers.go
func (b *OsImageBuilderInNode) removeImage() error { exutil.By("Remove osImage") rmOutput, err := b.node.DebugNodeWithChroot("podman", "rmi", "-i", b.osImage) if err != nil { msg := fmt.Sprintf("Podman failed removing image %s:\n%s\n%s", b.osImage, rmOutput, err) logger.Errorf(msg) return fmt.Errorf(msg) } logger.Debugf(rmOutput) logger.Infof("OK!\n") return nil }
mco
function
openshift/openshift-tests-private
26138c25-29c0-4ecc-a434-613a6ec0530f
digestImage
['"fmt"']
['OsImageBuilderInNode']
github.com/openshift/openshift-tests-private/test/extended/mco/inside_node_containers.go
func (b *OsImageBuilderInNode) digestImage() (string, error) { exutil.By("Digest osImage") skopeoCommand := "NO_PROXY=" + b.noProxy + " HTTPS_PROXY=" + b.httpsProxy + " HTTP_PROXY=" + b.httpProxy + " skopeo inspect docker://" + b.osImage + " --authfile " + b.remoteDockerConfig logger.Infof("Executing skopeo command: %s", skopeoCommand) inspectInfo, _, err := b.node.DebugNodeWithChrootStd("bash", "-c", skopeoCommand) if err != nil { msg := fmt.Sprintf("Skopeo failed inspecting image %s:\n%s\n%s", b.osImage, inspectInfo, err) logger.Errorf(msg) return "", fmt.Errorf(msg) } logger.Debugf(inspectInfo) inspectJSON := JSON(inspectInfo) digestedImage := inspectJSON.Get("Name").ToString() + "@" + inspectJSON.Get("Digest").ToString() logger.Infof("Image %s was built and pushed properly", b.osImage) logger.Infof("Image %s was digested as %s", b.osImage, digestedImage) logger.Infof("OK!\n") return digestedImage, nil }
mco
function
openshift/openshift-tests-private
aca4b8de-cec4-458d-8b51-a2ebd4ae3072
CreateAndDigestOsImage
['OsImageBuilderInNode']
github.com/openshift/openshift-tests-private/test/extended/mco/inside_node_containers.go
func (b *OsImageBuilderInNode) CreateAndDigestOsImage() (string, error) { if err := b.prepareEnvironment(); err != nil { return "", err } if err := b.buildImage(); err != nil { return "", err } if err := b.pushImage(); err != nil { return "", err } if err := b.removeImage(); err != nil { return "", err } return b.digestImage() }
mco
file
openshift/openshift-tests-private
14a46d4c-5278-459e-8c59-cb98f193858e
kubeletconfig
import ( "fmt" o "github.com/onsi/gomega" exutil "github.com/openshift/openshift-tests-private/test/extended/util" logger "github.com/openshift/openshift-tests-private/test/extended/util/logext" )
github.com/openshift/openshift-tests-private/test/extended/mco/kubeletconfig.go
package mco import ( "fmt" o "github.com/onsi/gomega" exutil "github.com/openshift/openshift-tests-private/test/extended/util" logger "github.com/openshift/openshift-tests-private/test/extended/util/logext" ) // KubeletConfig struct is used to handle KubeletConfig resources in OCP type KubeletConfig struct { Resource template string } // KubeletConfigList handles list of nodes type KubeletConfigList struct { ResourceList } // NewKubeletConfig create a NewKubeletConfig struct func NewKubeletConfig(oc *exutil.CLI, name, template string) *KubeletConfig { return &KubeletConfig{Resource: *NewResource(oc, "KubeletConfig", name), template: template} } // NewKubeletConfigList create a NewKubeletConfigList struct func NewKubeletConfigList(oc *exutil.CLI) *KubeletConfigList { return &KubeletConfigList{*NewResourceList(oc, "KubeletConfig")} } func (kc *KubeletConfig) create(parameters ...string) { allParams := []string{"--ignore-unknown-parameters=true", "-f", kc.template, "-p", "NAME=" + kc.name} allParams = append(allParams, parameters...) exutil.CreateClusterResourceFromTemplate(kc.oc, allParams...) } func (kc KubeletConfig) waitUntilSuccess(timeout string) { logger.Infof("wait for %s to report success", kc.name) o.Eventually(func() map[string]interface{} { successCond := JSON(kc.GetConditionByType("Success")) if successCond.Exists() { return successCond.ToMap() } logger.Infof("success condition not found, conditions are %s", kc.GetOrFail(`{.status.conditions}`)) return nil }, timeout, "2s").Should(o.SatisfyAll(o.HaveKeyWithValue("status", "True"), o.HaveKeyWithValue("message", "Success")), "KubeletConfig '%s' should report Success in status.conditions, but the current status is not success", kc.GetName()) } func (kc KubeletConfig) waitUntilFailure(expectedMsg, timeout string) { logger.Infof("wait for %s to report failure", kc.name) o.Eventually(func() map[string]interface{} { failureCond := JSON(kc.GetConditionByType("Failure")) if failureCond.Exists() { return failureCond.ToMap() } logger.Infof("Failure condition not found, conditions are %s", kc.GetOrFail(`{.status.conditions}`)) return nil }, timeout, "2s").Should(o.SatisfyAll(o.HaveKeyWithValue("status", "False"), o.HaveKeyWithValue("message", o.ContainSubstring(expectedMsg))), "KubeletConfig '%s' should report Failure in status.conditions and report failure message %s. But it doesnt.", kc.GetName(), expectedMsg) } // GetGeneratedMCName returns the name of the MC that was generated by this KubeletConfig resource func (kc KubeletConfig) GetGeneratedMCName() (string, error) { mcName, err := kc.Get(`{.metadata.finalizers[0]}`) if err != nil { return "", err } if mcName == "" { return "", fmt.Errorf("It was not possible to get the finalizer from %s %s: %s", kc.GetKind(), kc.GetName(), kc.PrettyString()) } return mcName, nil } // GetGeneratedMCNameOrFail returns the name of the MC that was generated by this KubeletConfig resource and fails the test case if it cannot be done func (kc KubeletConfig) GetGeneratedMCNameOrFail() string { mcName, err := kc.GetGeneratedMCName() o.Expect(err).NotTo(o.HaveOccurred(), "Error getting the generated MC for %s %s", kc.GetKind(), kc.GetName()) return mcName }
package mco
function
openshift/openshift-tests-private
2ebc1c8e-84c0-4a8e-bf8d-4f1812f7aea5
NewKubeletConfig
['KubeletConfig']
github.com/openshift/openshift-tests-private/test/extended/mco/kubeletconfig.go
func NewKubeletConfig(oc *exutil.CLI, name, template string) *KubeletConfig { return &KubeletConfig{Resource: *NewResource(oc, "KubeletConfig", name), template: template} }
mco
function
openshift/openshift-tests-private
5d3e8236-773c-421c-b4e1-3324c1b143f4
NewKubeletConfigList
['KubeletConfig', 'KubeletConfigList']
github.com/openshift/openshift-tests-private/test/extended/mco/kubeletconfig.go
func NewKubeletConfigList(oc *exutil.CLI) *KubeletConfigList { return &KubeletConfigList{*NewResourceList(oc, "KubeletConfig")} }
mco
function
openshift/openshift-tests-private
426a3453-e528-4945-ae34-c728dbb3823d
create
['KubeletConfig']
github.com/openshift/openshift-tests-private/test/extended/mco/kubeletconfig.go
func (kc *KubeletConfig) create(parameters ...string) { allParams := []string{"--ignore-unknown-parameters=true", "-f", kc.template, "-p", "NAME=" + kc.name} allParams = append(allParams, parameters...) exutil.CreateClusterResourceFromTemplate(kc.oc, allParams...) }
mco
function
openshift/openshift-tests-private
98ae76ba-5c34-4e20-972a-ee93df33f659
waitUntilSuccess
['KubeletConfig']
github.com/openshift/openshift-tests-private/test/extended/mco/kubeletconfig.go
func (kc KubeletConfig) waitUntilSuccess(timeout string) { logger.Infof("wait for %s to report success", kc.name) o.Eventually(func() map[string]interface{} { successCond := JSON(kc.GetConditionByType("Success")) if successCond.Exists() { return successCond.ToMap() } logger.Infof("success condition not found, conditions are %s", kc.GetOrFail(`{.status.conditions}`)) return nil }, timeout, "2s").Should(o.SatisfyAll(o.HaveKeyWithValue("status", "True"), o.HaveKeyWithValue("message", "Success")), "KubeletConfig '%s' should report Success in status.conditions, but the current status is not success", kc.GetName()) }
mco
function
openshift/openshift-tests-private
776d7b0f-3b62-43de-ba44-48eb742101d5
waitUntilFailure
['KubeletConfig']
github.com/openshift/openshift-tests-private/test/extended/mco/kubeletconfig.go
func (kc KubeletConfig) waitUntilFailure(expectedMsg, timeout string) { logger.Infof("wait for %s to report failure", kc.name) o.Eventually(func() map[string]interface{} { failureCond := JSON(kc.GetConditionByType("Failure")) if failureCond.Exists() { return failureCond.ToMap() } logger.Infof("Failure condition not found, conditions are %s", kc.GetOrFail(`{.status.conditions}`)) return nil }, timeout, "2s").Should(o.SatisfyAll(o.HaveKeyWithValue("status", "False"), o.HaveKeyWithValue("message", o.ContainSubstring(expectedMsg))), "KubeletConfig '%s' should report Failure in status.conditions and report failure message %s. But it doesnt.", kc.GetName(), expectedMsg) }
mco
function
openshift/openshift-tests-private
07115e73-2901-44b1-9b16-6fedf4d6a366
GetGeneratedMCName
['"fmt"']
['KubeletConfig']
github.com/openshift/openshift-tests-private/test/extended/mco/kubeletconfig.go
func (kc KubeletConfig) GetGeneratedMCName() (string, error) { mcName, err := kc.Get(`{.metadata.finalizers[0]}`) if err != nil { return "", err } if mcName == "" { return "", fmt.Errorf("It was not possible to get the finalizer from %s %s: %s", kc.GetKind(), kc.GetName(), kc.PrettyString()) } return mcName, nil }
mco
function
openshift/openshift-tests-private
ab6ba0bb-8330-4be5-af15-2d568fd1a0db
GetGeneratedMCNameOrFail
['KubeletConfig']
github.com/openshift/openshift-tests-private/test/extended/mco/kubeletconfig.go
func (kc KubeletConfig) GetGeneratedMCNameOrFail() string { mcName, err := kc.GetGeneratedMCName() o.Expect(err).NotTo(o.HaveOccurred(), "Error getting the generated MC for %s %s", kc.GetKind(), kc.GetName()) return mcName }
mco
file
openshift/openshift-tests-private
0d323c3d-6463-40ad-8ac5-1d417ac3063e
machine
import ( "fmt" o "github.com/onsi/gomega" exutil "github.com/openshift/openshift-tests-private/test/extended/util" logger "github.com/openshift/openshift-tests-private/test/extended/util/logext" )
github.com/openshift/openshift-tests-private/test/extended/mco/machine.go
package mco import ( "fmt" o "github.com/onsi/gomega" exutil "github.com/openshift/openshift-tests-private/test/extended/util" logger "github.com/openshift/openshift-tests-private/test/extended/util/logext" ) // Machine struct to handle Machine resources type Machine struct { Resource } // MachineList struct to handle lists of Machine resources type MachineList struct { ResourceList } // NewMachine constructs a new Machine struct func NewMachine(oc *exutil.CLI, namespace, name string) *Machine { return &Machine{*NewNamespacedResource(oc, MachineFullName, namespace, name)} } // GetNode returns the node created by this machine func (m Machine) GetNode() (*Node, error) { nodeList := NewNodeList(m.oc) nodeList.SetItemsFilter(`?(@.metadata.annotations.machine\.openshift\.io/machine=="openshift-machine-api/` + m.GetName() + `")`) nodes, nErr := nodeList.GetAll() if nErr != nil { return nil, nErr } numNodes := len(nodes) if numNodes > 1 { return nil, fmt.Errorf("More than one nodes linked to this Machine. Machine: %s. Num nodes:%d", m.GetName(), numNodes) } if numNodes == 0 { return nil, fmt.Errorf("No node linked to this Machine. Machine: %s", m.GetName()) } return &(nodes[0]), nil } // GetNodeOrFail, call GetNode, fail the test if any error occurred func (m Machine) GetNodeOrFail() *Node { node, err := m.GetNode() o.Expect(err).NotTo(o.HaveOccurred(), "Get node from machine %s failed", m.GetName()) return node } // GetPhase get phase of the machine func (m Machine) GetPhase() string { phase := m.GetOrFail(`{.status.phase}`) logger.Infof("machine %s phase is %s", m.GetName(), phase) return phase } // NewMachineList constructs a new MachineList struct to handle all existing Machines func NewMachineList(oc *exutil.CLI, namespace string) *MachineList { return &MachineList{*NewNamespacedResourceList(oc, MachineFullName, namespace)} } // GetAll returns a []Machine slice with all existing nodes func (ml MachineList) GetAll() ([]Machine, error) { allMResources, err := ml.ResourceList.GetAll() if err != nil { return nil, err } allMs := make([]Machine, 0, len(allMResources)) for _, mRes := range allMResources { allMs = append(allMs, *NewMachine(ml.oc, mRes.GetNamespace(), mRes.GetName())) } return allMs, nil }
package mco
function
openshift/openshift-tests-private
d75f52fb-01a2-4d45-ac43-5539c6039f13
NewMachine
['Machine']
github.com/openshift/openshift-tests-private/test/extended/mco/machine.go
func NewMachine(oc *exutil.CLI, namespace, name string) *Machine { return &Machine{*NewNamespacedResource(oc, MachineFullName, namespace, name)} }
mco
function
openshift/openshift-tests-private
e39b77b9-2978-4030-baea-cd61976d622c
GetNode
['"fmt"']
['Machine']
github.com/openshift/openshift-tests-private/test/extended/mco/machine.go
func (m Machine) GetNode() (*Node, error) { nodeList := NewNodeList(m.oc) nodeList.SetItemsFilter(`?(@.metadata.annotations.machine\.openshift\.io/machine=="openshift-machine-api/` + m.GetName() + `")`) nodes, nErr := nodeList.GetAll() if nErr != nil { return nil, nErr } numNodes := len(nodes) if numNodes > 1 { return nil, fmt.Errorf("More than one nodes linked to this Machine. Machine: %s. Num nodes:%d", m.GetName(), numNodes) } if numNodes == 0 { return nil, fmt.Errorf("No node linked to this Machine. Machine: %s", m.GetName()) } return &(nodes[0]), nil }
mco
function
openshift/openshift-tests-private
8fddce7d-8fe3-4f7a-831d-5b2b9cee38e5
GetNodeOrFail
['Machine']
github.com/openshift/openshift-tests-private/test/extended/mco/machine.go
func (m Machine) GetNodeOrFail() *Node { node, err := m.GetNode() o.Expect(err).NotTo(o.HaveOccurred(), "Get node from machine %s failed", m.GetName()) return node }
mco
function
openshift/openshift-tests-private
b06cf02e-dcd5-4633-acbd-6fe94c175d74
GetPhase
['Machine']
github.com/openshift/openshift-tests-private/test/extended/mco/machine.go
func (m Machine) GetPhase() string { phase := m.GetOrFail(`{.status.phase}`) logger.Infof("machine %s phase is %s", m.GetName(), phase) return phase }
mco
function
openshift/openshift-tests-private
cdb667d4-2033-4824-925e-233cab5bcda7
NewMachineList
['MachineList']
github.com/openshift/openshift-tests-private/test/extended/mco/machine.go
func NewMachineList(oc *exutil.CLI, namespace string) *MachineList { return &MachineList{*NewNamespacedResourceList(oc, MachineFullName, namespace)} }
mco
function
openshift/openshift-tests-private
13cfd3b7-8aa1-46da-85db-276e3d35a7f2
GetAll
['Machine', 'MachineList']
github.com/openshift/openshift-tests-private/test/extended/mco/machine.go
func (ml MachineList) GetAll() ([]Machine, error) { allMResources, err := ml.ResourceList.GetAll() if err != nil { return nil, err } allMs := make([]Machine, 0, len(allMResources)) for _, mRes := range allMResources { allMs = append(allMs, *NewMachine(ml.oc, mRes.GetNamespace(), mRes.GetName())) } return allMs, nil }
mco
file
openshift/openshift-tests-private
f5cbe8f6-e7ce-4a50-a4a2-30bc06212de7
machineconfignode
import ( exutil "github.com/openshift/openshift-tests-private/test/extended/util" )
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
package mco import ( exutil "github.com/openshift/openshift-tests-private/test/extended/util" ) // MachineConfigNode resource type declaration type MachineConfigNode struct { Resource } // MachineConfigNodeList resource type declaration type MachineConfigNodeList struct { ResourceList } // NewMachineConfigNode constructor to get MCN resource func NewMachineConfigNode(oc *exutil.CLI, node string) *MachineConfigNode { return &MachineConfigNode{Resource: *NewResource(oc, "machineconfignode", node)} } // NewMachineConfigNodeList constructor to get MCN list func NewMachineConfigNodeList(oc *exutil.CLI) *MachineConfigNodeList { return &MachineConfigNodeList{ResourceList: *NewResourceList(oc, "machineconfignodes")} } // GetAll get list of MachineConfigNode func (mcnl *MachineConfigNodeList) GetAll() ([]MachineConfigNode, error) { resources, err := mcnl.ResourceList.GetAll() if err != nil { return nil, err } allMCNs := make([]MachineConfigNode, 0, len(resources)) for _, mcn := range resources { allMCNs = append(allMCNs, *NewMachineConfigNode(mcnl.oc, mcn.GetName())) } return allMCNs, nil } // GetDesiredMachineConfigOfSpec get value of `.spec.configVersion.desired` func (mcn *MachineConfigNode) GetDesiredMachineConfigOfSpec() string { return mcn.GetOrFail(`{.spec.configVersion.desired}`) } // GetDesiredMachineConfigOfStatus get value of `.status.configVersion.desired` func (mcn *MachineConfigNode) GetDesiredMachineConfigOfStatus() string { return mcn.GetOrFail(`{.status.configVersion.desired}`) } // GetCurrentMachineConfigOfStatus get value of `.status.configVersion.current` func (mcn *MachineConfigNode) GetCurrentMachineConfigOfStatus() string { return mcn.GetOrFail(`{.status.configVersion.current}`) } // GetPool get value of `.spec.pool.name` func (mcn *MachineConfigNode) GetPool() string { return mcn.GetOrFail(`{.spec.pool.name}`) } // GetNode get value of `.spec.node.name` func (mcn *MachineConfigNode) GetNode() string { return mcn.GetOrFail(`{.spec.node.name}`) } // GetUpdated get condition status of `Updated` func (mcn *MachineConfigNode) GetUpdated() string { return mcn.GetConditionStatusByType("Updated") } // GetUpdatePrepared get condition status of `UpdatePrepared` func (mcn *MachineConfigNode) GetUpdatePrepared() string { return mcn.GetConditionStatusByType("UpdatePrepared") } // GetUpdateExecuted get condition status of `UpdateExecuted` func (mcn *MachineConfigNode) GetUpdateExecuted() string { return mcn.GetConditionStatusByType("UpdateExecuted") } // GetUpdatePostActionComplete get condition status of `UpdatePostActionComplete` func (mcn *MachineConfigNode) GetUpdatePostActionComplete() string { return mcn.GetConditionStatusByType("UpdatePostActionComplete") } // GetUpdateComplete get condition status of `UpdateComplete` func (mcn *MachineConfigNode) GetUpdateComplete() string { return mcn.GetConditionStatusByType("UpdateComplete") } // GetResumed get condition status of `Resumed` func (mcn *MachineConfigNode) GetResumed() string { return mcn.GetConditionStatusByType("Resumed") } // GetUpdateCompatible get condition status of `UpdateCompatible` func (mcn *MachineConfigNode) GetUpdateCompatible() string { return mcn.GetConditionStatusByType("UpdateCompatible") } // GetAppliedFilesAndOS get condition status of `AppliedFilesAndOS` func (mcn *MachineConfigNode) GetAppliedFilesAndOS() string { return mcn.GetConditionStatusByType("AppliedFilesAndOS") } // GetCordoned get condition status of `Cordoned` func (mcn *MachineConfigNode) GetCordoned() string { return mcn.GetConditionStatusByType("Cordoned") } // GetUncordoned get condition status of `Uncordoned` func (mcn *MachineConfigNode) GetUncordoned() string { return mcn.GetConditionStatusByType("Uncordoned") } // GetDrained get condition status of `Drained` func (mcn *MachineConfigNode) GetDrained() string { return mcn.GetConditionStatusByType("Drained") } // GetRebootedNode get condition status of `RebootedNode` func (mcn *MachineConfigNode) GetRebootedNode() string { return mcn.GetConditionStatusByType("RebootedNode") } // GetReloadedCRIO get condition status of `ReloadedCRIO` func (mcn *MachineConfigNode) GetReloadedCRIO() string { return mcn.GetConditionStatusByType("ReloadedCRIO") } func (mcn *MachineConfigNode) IsPinnedImageSetsDegraded() bool { return mcn.IsConditionStatusTrue("PinnedImageSetsDegraded") } func (mcn *MachineConfigNode) IsPinnedImageSetsProgressing() bool { return mcn.IsConditionStatusTrue("PinnedImageSetsProgressing") }
package mco
function
openshift/openshift-tests-private
a2581076-dedd-4482-803f-53d955bcfa07
NewMachineConfigNode
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func NewMachineConfigNode(oc *exutil.CLI, node string) *MachineConfigNode { return &MachineConfigNode{Resource: *NewResource(oc, "machineconfignode", node)} }
mco
function
openshift/openshift-tests-private
22b4e045-c248-49c6-a7ad-e849ea65ac51
NewMachineConfigNodeList
['MachineConfigNodeList']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func NewMachineConfigNodeList(oc *exutil.CLI) *MachineConfigNodeList { return &MachineConfigNodeList{ResourceList: *NewResourceList(oc, "machineconfignodes")} }
mco
function
openshift/openshift-tests-private
ed2a9699-008f-465b-9540-bfb971375d8d
GetAll
['MachineConfigNode', 'MachineConfigNodeList']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcnl *MachineConfigNodeList) GetAll() ([]MachineConfigNode, error) { resources, err := mcnl.ResourceList.GetAll() if err != nil { return nil, err } allMCNs := make([]MachineConfigNode, 0, len(resources)) for _, mcn := range resources { allMCNs = append(allMCNs, *NewMachineConfigNode(mcnl.oc, mcn.GetName())) } return allMCNs, nil }
mco
function
openshift/openshift-tests-private
fcf10d77-dab8-40ed-8c5b-b2f9309cc8b1
GetDesiredMachineConfigOfSpec
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetDesiredMachineConfigOfSpec() string { return mcn.GetOrFail(`{.spec.configVersion.desired}`) }
mco
function
openshift/openshift-tests-private
639b0450-8f91-4ee3-b943-73c46d9e34e4
GetDesiredMachineConfigOfStatus
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetDesiredMachineConfigOfStatus() string { return mcn.GetOrFail(`{.status.configVersion.desired}`) }
mco
function
openshift/openshift-tests-private
e5a47099-9a8b-48cb-9c22-920a6b304bc6
GetCurrentMachineConfigOfStatus
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetCurrentMachineConfigOfStatus() string { return mcn.GetOrFail(`{.status.configVersion.current}`) }
mco
function
openshift/openshift-tests-private
42d6753a-be12-4e8d-b7dc-390b71fca567
GetPool
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetPool() string { return mcn.GetOrFail(`{.spec.pool.name}`) }
mco
function
openshift/openshift-tests-private
d155c63f-28f4-41b5-a6be-ed2a2705f69c
GetNode
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetNode() string { return mcn.GetOrFail(`{.spec.node.name}`) }
mco
function
openshift/openshift-tests-private
646d80e3-854c-499a-a8e3-d8227db8ce1e
GetUpdated
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetUpdated() string { return mcn.GetConditionStatusByType("Updated") }
mco
function
openshift/openshift-tests-private
3d7fce3e-ad22-4cf9-9cf8-e7b2cb3ac7b2
GetUpdatePrepared
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetUpdatePrepared() string { return mcn.GetConditionStatusByType("UpdatePrepared") }
mco
function
openshift/openshift-tests-private
f8edd926-eecc-47bc-8b60-665af8b439e3
GetUpdateExecuted
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetUpdateExecuted() string { return mcn.GetConditionStatusByType("UpdateExecuted") }
mco
function
openshift/openshift-tests-private
f61f4bcb-205e-4aaa-9741-18dea8313115
GetUpdatePostActionComplete
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetUpdatePostActionComplete() string { return mcn.GetConditionStatusByType("UpdatePostActionComplete") }
mco
function
openshift/openshift-tests-private
e03c6bb3-0438-4f65-ab73-137982f96740
GetUpdateComplete
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetUpdateComplete() string { return mcn.GetConditionStatusByType("UpdateComplete") }
mco
function
openshift/openshift-tests-private
86da3047-c3e8-49e6-a17f-dba6fa8f2df4
GetResumed
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetResumed() string { return mcn.GetConditionStatusByType("Resumed") }
mco
function
openshift/openshift-tests-private
2f436065-76f3-4cae-909d-4c59d519de88
GetUpdateCompatible
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetUpdateCompatible() string { return mcn.GetConditionStatusByType("UpdateCompatible") }
mco
function
openshift/openshift-tests-private
a148a13d-ff8b-4bdc-b2e8-d25e385ce91f
GetAppliedFilesAndOS
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetAppliedFilesAndOS() string { return mcn.GetConditionStatusByType("AppliedFilesAndOS") }
mco
function
openshift/openshift-tests-private
f7711fff-50ec-49d9-a357-6748387c4ceb
GetCordoned
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetCordoned() string { return mcn.GetConditionStatusByType("Cordoned") }
mco
function
openshift/openshift-tests-private
49d82d34-d3cf-4fc3-ab95-226d33f3e4e4
GetUncordoned
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetUncordoned() string { return mcn.GetConditionStatusByType("Uncordoned") }
mco
function
openshift/openshift-tests-private
b724535a-313b-4893-9f7c-4a0943bb4e8c
GetDrained
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetDrained() string { return mcn.GetConditionStatusByType("Drained") }
mco
function
openshift/openshift-tests-private
7339391f-edb1-43a2-b97b-2c26bfa43fef
GetRebootedNode
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetRebootedNode() string { return mcn.GetConditionStatusByType("RebootedNode") }
mco
function
openshift/openshift-tests-private
2a5ebe3b-953e-4b6c-ab83-b59c05203b06
GetReloadedCRIO
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) GetReloadedCRIO() string { return mcn.GetConditionStatusByType("ReloadedCRIO") }
mco
function
openshift/openshift-tests-private
19000148-7a53-431f-aa56-10ff4313e52c
IsPinnedImageSetsDegraded
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) IsPinnedImageSetsDegraded() bool { return mcn.IsConditionStatusTrue("PinnedImageSetsDegraded") }
mco
function
openshift/openshift-tests-private
263bfd31-dce5-4e51-b67a-5f630af2bcb6
IsPinnedImageSetsProgressing
['MachineConfigNode']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfignode.go
func (mcn *MachineConfigNode) IsPinnedImageSetsProgressing() bool { return mcn.IsConditionStatusTrue("PinnedImageSetsProgressing") }
mco
file
openshift/openshift-tests-private
aa7eae0e-e1bf-4375-ab94-215c23efbcef
machineconfiguration
import ( exutil "github.com/openshift/openshift-tests-private/test/extended/util" logger "github.com/openshift/openshift-tests-private/test/extended/util/logext" )
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfiguration.go
package mco import ( exutil "github.com/openshift/openshift-tests-private/test/extended/util" logger "github.com/openshift/openshift-tests-private/test/extended/util/logext" ) // MachineConfiguration struct is used to handle MachineConfiguration resources in OCP type MachineConfiguration struct { Resource } // GetMachineConfiguration returns the "cluster" MachineConfiguration resource. It is the only MachineConfiguration resource that can be used func GetMachineConfiguration(oc *exutil.CLI) *MachineConfiguration { return &MachineConfiguration{Resource: *NewResource(oc, "machineconfiguration", "cluster")} } // RemoveManagedBootImagesConfig removes the ManagedBootImagesConfig from the MachineConfig resource. It returns a function that can be used to restore the original config and an error. func (mc MachineConfiguration) RemoveManagedBootImagesConfig() error { logger.Infof("Removing .spec.managedBootImages from %s", mc) managedBootImages, err := mc.Get(`{.spec.managedBootImages}`) if err != nil { return err } if managedBootImages == "" { logger.Infof(".spec.managedBootImages does not exist. No need to remove it") return nil } return mc.Patch("json", `[{ "op": "remove", "path": "/spec/managedBootImages"}]`) } // SetAllManagedBootImagesConfig configures MachineConfiguration so that all machinesets are updated if necessary func (mc MachineConfiguration) SetAllManagedBootImagesConfig() error { return mc.Patch("merge", `{"spec":{"managedBootImages":{"machineManagers":[{"resource": "machinesets","apiGroup": "machine.openshift.io","selection": {"mode": "All"}}]}}}`) } // SetPartialManagedBootImagesConfig configures MachineConfiguration so that only the machinesets with the given label are updated if necessary func (mc MachineConfiguration) SetPartialManagedBootImagesConfig(label, value string) error { return mc.Patch("merge", `{"spec":{"managedBootImages":{"machineManagers":[{"resource":"machinesets","apiGroup":"machine.openshift.io","selection":{"mode":"Partial","partial":{"machineResourceSelector":{"matchLabels":{"`+label+`":"`+value+`"}}}}}]}}}`) }
package mco
function
openshift/openshift-tests-private
556d204e-4506-4275-b72e-a836620f82d2
GetMachineConfiguration
['MachineConfiguration']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfiguration.go
func GetMachineConfiguration(oc *exutil.CLI) *MachineConfiguration { return &MachineConfiguration{Resource: *NewResource(oc, "machineconfiguration", "cluster")} }
mco
function
openshift/openshift-tests-private
c8710b96-70ac-4aba-b9ff-d777f440b28e
RemoveManagedBootImagesConfig
['MachineConfiguration']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfiguration.go
func (mc MachineConfiguration) RemoveManagedBootImagesConfig() error { logger.Infof("Removing .spec.managedBootImages from %s", mc) managedBootImages, err := mc.Get(`{.spec.managedBootImages}`) if err != nil { return err } if managedBootImages == "" { logger.Infof(".spec.managedBootImages does not exist. No need to remove it") return nil } return mc.Patch("json", `[{ "op": "remove", "path": "/spec/managedBootImages"}]`) }
mco
function
openshift/openshift-tests-private
4bb2f71a-adef-4342-9f07-144a53b48687
SetAllManagedBootImagesConfig
['MachineConfiguration']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfiguration.go
func (mc MachineConfiguration) SetAllManagedBootImagesConfig() error { return mc.Patch("merge", `{"spec":{"managedBootImages":{"machineManagers":[{"resource": "machinesets","apiGroup": "machine.openshift.io","selection": {"mode": "All"}}]}}}`) }
mco
function
openshift/openshift-tests-private
671905c4-bd5c-4053-83fe-0f7e71149605
SetPartialManagedBootImagesConfig
['MachineConfiguration']
github.com/openshift/openshift-tests-private/test/extended/mco/machineconfiguration.go
func (mc MachineConfiguration) SetPartialManagedBootImagesConfig(label, value string) error { return mc.Patch("merge", `{"spec":{"managedBootImages":{"machineManagers":[{"resource":"machinesets","apiGroup":"machine.openshift.io","selection":{"mode":"Partial","partial":{"machineResourceSelector":{"matchLabels":{"`+label+`":"`+value+`"}}}}}]}}}`) }
mco
file
openshift/openshift-tests-private
493571cb-8387-4f3a-92b6-b427345163be
nodedisruptionpolicy
import ( "encoding/json" "fmt" "reflect" exutil "github.com/openshift/openshift-tests-private/test/extended/util" )
github.com/openshift/openshift-tests-private/test/extended/mco/nodedisruptionpolicy.go
package mco import ( "encoding/json" "fmt" "reflect" exutil "github.com/openshift/openshift-tests-private/test/extended/util" ) // NodeDisruptionPolicy, represents content of machineconfigurations.operator.openshift.io/cluster type NodeDisruptionPolicy struct { Resource `json:"-"` Snapshot string `json:"-"` Files []*Policy `json:"files,omitempty"` Units []*Policy `json:"units,omitempty"` SSHKey *Policy `json:"sshkey,omitempty"` } // Policy, represents content of every policy type Policy struct { Name *string `json:"name,omitempty"` Path *string `json:"path"` Actions []Action `json:"actions"` } // Action, represents content of every action in policy type Action struct { Type string `json:"type"` Reload *Service `json:"reload,omitempty"` Restart *Service `json:"restart,omitempty"` } // Service represents service info in reload/restart type Service struct { Name string `json:"serviceName"` } // NewNodeDisruptionPolicy constructor of NodeDisruptionPolicy func NewNodeDisruptionPolicy(oc *exutil.CLI) *NodeDisruptionPolicy { ndp := NodeDisruptionPolicy{Resource: *NewResource(oc.AsAdmin(), "machineconfigurations.operator.openshift.io", "cluster")} ndp.Snapshot = ndp.GetOrFail("{.spec.nodeDisruptionPolicy}") return &ndp } // NewPolicyWithParams constructor of Policy func NewPolicyWithParams(path, name *string, actions ...Action) Policy { return Policy{Path: path, Name: name, Actions: actions} } // NewActionWithParams constrctor of Action func NewActionWithParams(actnType string, reload, restart *Service) Action { return Action{Type: actnType, Reload: reload, Restart: restart} } // NewService constructor of Service func NewService(name string) *Service { return &Service{Name: name} } // NewReloadAction create new reload action func NewReloadAction(serviceName string) Action { return NewActionWithParams("Reload", NewService(serviceName), nil) } // NewRestartAction create new restart action func NewRestartAction(serviceName string) Action { return NewActionWithParams("Restart", nil, NewService(serviceName)) } // NewCommonAction create new common action, only has type func NewCommonAction(actnType string) Action { return NewActionWithParams(actnType, nil, nil) } // Equals deep equal policies func (p Policy) Equals(policy Policy) bool { return reflect.DeepEqual(p, policy) } // IsUpdated check whether polcies in this object are synced to status func (ndp NodeDisruptionPolicy) IsUpdated() (bool, error) { latest := NewNodeDisruptionPolicy(ndp.oc) err := json.Unmarshal([]byte(ndp.GetOrFail("{.status.nodeDisruptionPolicyStatus.clusterPolicies}")), &latest) if err != nil { return false, err } updatedPolices := 0 for _, file := range ndp.Files { for _, latestFile := range latest.Files { if file.Equals(*latestFile) { updatedPolices++ } } } for _, unit := range ndp.Units { for _, latestUnit := range latest.Units { if unit.Equals(*latestUnit) { updatedPolices++ } } } if ndp.SSHKey != nil && ndp.SSHKey.Equals(*latest.SSHKey) { updatedPolices++ } currentPolicies := len(ndp.Files) + len(ndp.Units) if ndp.SSHKey != nil { currentPolicies++ } return updatedPolices == currentPolicies, nil } // Rollback rollback the spec to the original values, it should be called in defer block func (ndp NodeDisruptionPolicy) Rollback() { if ndp.Snapshot != "" { ndp.Patch("json", fmt.Sprintf(`[{"op": "replace", "path": "/spec/nodeDisruptionPolicy", "value": %s}]`, ndp.Snapshot)) } else { ndp.Patch("json", `[{"op": "remove", "path": "/spec/nodeDisruptionPolicy"}]`) } } // AddFilePolicy add file based policy func (ndp NodeDisruptionPolicy) AddFilePolicy(path string, actions ...Action) NodeDisruptionPolicy { policy := NewPolicyWithParams(&path, nil, actions...) ndp.Files = append(ndp.Files, &policy) return ndp } // AddUnitPolicy add unit based policy func (ndp NodeDisruptionPolicy) AddUnitPolicy(name string, actions ...Action) NodeDisruptionPolicy { policy := NewPolicyWithParams(nil, &name, actions...) ndp.Units = append(ndp.Units, &policy) return ndp } // SetSSHKeyPolicy set actions for sshkey based policy func (ndp NodeDisruptionPolicy) SetSSHKeyPolicy(actions ...Action) NodeDisruptionPolicy { policy := NewPolicyWithParams(nil, nil, actions...) ndp.SSHKey = &policy return ndp } // Apply apply changes to machineconfiguration/cluster func (ndp NodeDisruptionPolicy) Apply() error { bytes, err := json.Marshal(ndp) if err != nil { return err } err = ndp.Patch("merge", fmt.Sprintf(`{"spec":{"nodeDisruptionPolicy":%s}}`, string(bytes))) if err != nil { return err } return nil }
package mco
function
openshift/openshift-tests-private
082d4c03-9c38-4b1f-b763-c1a352b0b5e0
NewNodeDisruptionPolicy
['NodeDisruptionPolicy']
github.com/openshift/openshift-tests-private/test/extended/mco/nodedisruptionpolicy.go
func NewNodeDisruptionPolicy(oc *exutil.CLI) *NodeDisruptionPolicy { ndp := NodeDisruptionPolicy{Resource: *NewResource(oc.AsAdmin(), "machineconfigurations.operator.openshift.io", "cluster")} ndp.Snapshot = ndp.GetOrFail("{.spec.nodeDisruptionPolicy}") return &ndp }
mco
function
openshift/openshift-tests-private
a6e2023b-fcad-4c53-97aa-aa899c511b76
NewPolicyWithParams
['Policy', 'Action']
github.com/openshift/openshift-tests-private/test/extended/mco/nodedisruptionpolicy.go
func NewPolicyWithParams(path, name *string, actions ...Action) Policy { return Policy{Path: path, Name: name, Actions: actions} }
mco
function
openshift/openshift-tests-private
7b8b18f4-b7eb-473b-b3a4-fb28a8151439
NewActionWithParams
['Action', 'Service']
github.com/openshift/openshift-tests-private/test/extended/mco/nodedisruptionpolicy.go
func NewActionWithParams(actnType string, reload, restart *Service) Action { return Action{Type: actnType, Reload: reload, Restart: restart} }
mco
function
openshift/openshift-tests-private
fcda99a1-62c8-4258-a44c-dd5b527b2314
NewService
['Service']
github.com/openshift/openshift-tests-private/test/extended/mco/nodedisruptionpolicy.go
func NewService(name string) *Service { return &Service{Name: name} }
mco
function
openshift/openshift-tests-private
fb090af1-a53d-477f-8310-6bf83cf77566
NewReloadAction
['Action']
github.com/openshift/openshift-tests-private/test/extended/mco/nodedisruptionpolicy.go
func NewReloadAction(serviceName string) Action { return NewActionWithParams("Reload", NewService(serviceName), nil) }
mco
function
openshift/openshift-tests-private
90ecda77-0b5e-4842-838a-45d1b5309d14
NewRestartAction
['Action']
github.com/openshift/openshift-tests-private/test/extended/mco/nodedisruptionpolicy.go
func NewRestartAction(serviceName string) Action { return NewActionWithParams("Restart", nil, NewService(serviceName)) }
mco
function
openshift/openshift-tests-private
2ddae4eb-1141-4c54-89be-6801a97b461c
NewCommonAction
['Action']
github.com/openshift/openshift-tests-private/test/extended/mco/nodedisruptionpolicy.go
func NewCommonAction(actnType string) Action { return NewActionWithParams(actnType, nil, nil) }
mco
function
openshift/openshift-tests-private
bdf3afdd-0272-4fa5-a6de-485b5a7ec2e5
Equals
['"reflect"']
['Policy']
github.com/openshift/openshift-tests-private/test/extended/mco/nodedisruptionpolicy.go
func (p Policy) Equals(policy Policy) bool { return reflect.DeepEqual(p, policy) }
mco
function
openshift/openshift-tests-private
09ad0647-c5ba-47ca-bd0a-c8496baff891
IsUpdated
['"encoding/json"']
['NodeDisruptionPolicy']
github.com/openshift/openshift-tests-private/test/extended/mco/nodedisruptionpolicy.go
func (ndp NodeDisruptionPolicy) IsUpdated() (bool, error) { latest := NewNodeDisruptionPolicy(ndp.oc) err := json.Unmarshal([]byte(ndp.GetOrFail("{.status.nodeDisruptionPolicyStatus.clusterPolicies}")), &latest) if err != nil { return false, err } updatedPolices := 0 for _, file := range ndp.Files { for _, latestFile := range latest.Files { if file.Equals(*latestFile) { updatedPolices++ } } } for _, unit := range ndp.Units { for _, latestUnit := range latest.Units { if unit.Equals(*latestUnit) { updatedPolices++ } } } if ndp.SSHKey != nil && ndp.SSHKey.Equals(*latest.SSHKey) { updatedPolices++ } currentPolicies := len(ndp.Files) + len(ndp.Units) if ndp.SSHKey != nil { currentPolicies++ } return updatedPolices == currentPolicies, nil }
mco
function
openshift/openshift-tests-private
df1e49a4-fbab-437c-b458-caebdd487e0f
Rollback
['"encoding/json"', '"fmt"']
['NodeDisruptionPolicy']
github.com/openshift/openshift-tests-private/test/extended/mco/nodedisruptionpolicy.go
func (ndp NodeDisruptionPolicy) Rollback() { if ndp.Snapshot != "" { ndp.Patch("json", fmt.Sprintf(`[{"op": "replace", "path": "/spec/nodeDisruptionPolicy", "value": %s}]`, ndp.Snapshot)) } else { ndp.Patch("json", `[{"op": "remove", "path": "/spec/nodeDisruptionPolicy"}]`) } }
mco
function
openshift/openshift-tests-private
dd4c15fd-79a5-4447-a473-dfa1f64aec6b
AddFilePolicy
['NodeDisruptionPolicy', 'Action']
github.com/openshift/openshift-tests-private/test/extended/mco/nodedisruptionpolicy.go
func (ndp NodeDisruptionPolicy) AddFilePolicy(path string, actions ...Action) NodeDisruptionPolicy { policy := NewPolicyWithParams(&path, nil, actions...) ndp.Files = append(ndp.Files, &policy) return ndp }
mco
function
openshift/openshift-tests-private
10cc30c6-16d1-4bca-a898-899f3bc10bb7
AddUnitPolicy
['NodeDisruptionPolicy', 'Action']
github.com/openshift/openshift-tests-private/test/extended/mco/nodedisruptionpolicy.go
func (ndp NodeDisruptionPolicy) AddUnitPolicy(name string, actions ...Action) NodeDisruptionPolicy { policy := NewPolicyWithParams(nil, &name, actions...) ndp.Units = append(ndp.Units, &policy) return ndp }
mco
function
openshift/openshift-tests-private
330522af-07a4-4d67-b288-269191556e56
SetSSHKeyPolicy
['NodeDisruptionPolicy', 'Action']
github.com/openshift/openshift-tests-private/test/extended/mco/nodedisruptionpolicy.go
func (ndp NodeDisruptionPolicy) SetSSHKeyPolicy(actions ...Action) NodeDisruptionPolicy { policy := NewPolicyWithParams(nil, nil, actions...) ndp.SSHKey = &policy return ndp }
mco
function
openshift/openshift-tests-private
90327053-d043-4854-a55d-0272b579892a
Apply
['"encoding/json"', '"fmt"']
['NodeDisruptionPolicy']
github.com/openshift/openshift-tests-private/test/extended/mco/nodedisruptionpolicy.go
func (ndp NodeDisruptionPolicy) Apply() error { bytes, err := json.Marshal(ndp) if err != nil { return err } err = ndp.Patch("merge", fmt.Sprintf(`{"spec":{"nodeDisruptionPolicy":%s}}`, string(bytes))) if err != nil { return err } return nil }
mco
file
openshift/openshift-tests-private
42715428-da85-43da-85e2-58f5a9588c00
pinnedimageset
import ( "encoding/json" "time" o "github.com/onsi/gomega" exutil "github.com/openshift/openshift-tests-private/test/extended/util" logger "github.com/openshift/openshift-tests-private/test/extended/util/logext" )
github.com/openshift/openshift-tests-private/test/extended/mco/pinnedimageset.go
package mco import ( "encoding/json" "time" o "github.com/onsi/gomega" exutil "github.com/openshift/openshift-tests-private/test/extended/util" logger "github.com/openshift/openshift-tests-private/test/extended/util/logext" ) type Pinnedimage struct { Name string `json:"name"` } // PinnedImageSet resource type declaration type PinnedImageSet struct { Resource } // PinnedImageSetList handles list of PinnedImageSet type PinnedImageSetList struct { ResourceList } // NewPinnedImageSetList construct a new PinnedImageSet list struct to handle all existing PinnedImageSet func NewPinnedImageSetList(oc *exutil.CLI) *PinnedImageSetList { return &PinnedImageSetList{*NewResourceList(oc, "pinnedimageset")} } // NewPinnedImageSet constructor to get PinnedImageSet resource func NewPinnedImageSet(oc *exutil.CLI, name string) *PinnedImageSet { return &PinnedImageSet{Resource: *NewResource(oc, "pinnedimageset", name)} } // CreateGenericPinnedImageSet uses a generic template to create a PinnedImageSet resource func CreateGenericPinnedImageSet(oc *exutil.CLI, name, pool string, images []string) (*PinnedImageSet, error) { logger.Infof("Creating PinnedImageSet %s in pool %s with images %s", name, pool, images) newPIS := NewPinnedImageSet(oc, name) pinnedImages := []Pinnedimage{} for i := range images { pinnedImages = append(pinnedImages, Pinnedimage{Name: images[i]}) } JSONImages, err := json.Marshal(pinnedImages) if err != nil { return newPIS, err } err = NewMCOTemplate(oc, "generic-pinned-image-set.yaml").Create("-p", "NAME="+name, "POOL="+pool, "IMAGES="+string(JSONImages)) if err != nil { return newPIS, err } return newPIS, nil } // GetPools returns the pools where this PinnedImageSet will be applied func (pis PinnedImageSet) GetPools() ([]MachineConfigPool, error) { returnPools := []MachineConfigPool{} pools, err := NewMachineConfigPoolList(pis.GetOC()).GetAll() if err != nil { return nil, err } for _, item := range pools { pool := item ps, err := pool.GetPinnedImageSets() if err != nil { return nil, err } for _, p := range ps { if p.GetName() == pis.GetName() { returnPools = append(returnPools, pool) break } } } return returnPools, nil } func (pis PinnedImageSet) DeleteAndWait(waitingTime time.Duration) error { if !pis.Exists() { logger.Infof("%s does not exist! No need to delete it!", pis) return nil } pools, err := pis.GetPools() if err != nil { return err } err = pis.Delete() if err != nil { return err } for _, pool := range pools { err := pool.waitForPinComplete(waitingTime) if err != nil { return err } } return nil } // GetAll returns a []PinnedImageSet list with all existing pinnedimageset sorted by creation timestamp func (pisl *PinnedImageSetList) GetAll() ([]PinnedImageSet, error) { pisl.ResourceList.SortByTimestamp() allPISResources, err := pisl.ResourceList.GetAll() if err != nil { return nil, err } allPISs := make([]PinnedImageSet, 0, len(allPISResources)) for _, pisRes := range allPISResources { allPISs = append(allPISs, *NewPinnedImageSet(pisl.oc, pisRes.name)) } return allPISs, nil } // GetAllOrFail returns a []PinnedImageSet list with all existing pinnedimageset sorted by creation time, if any error happens it fails the test func (pisl *PinnedImageSetList) GetAllOrFail() []PinnedImageSet { piss, err := pisl.GetAll() o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error getting the list of existing PinnedImageSet in the cluster") return piss }
package mco
function
openshift/openshift-tests-private
9a16fb7e-2c8d-480c-ab62-d5a796669579
NewPinnedImageSetList
['PinnedImageSetList']
github.com/openshift/openshift-tests-private/test/extended/mco/pinnedimageset.go
func NewPinnedImageSetList(oc *exutil.CLI) *PinnedImageSetList { return &PinnedImageSetList{*NewResourceList(oc, "pinnedimageset")} }
mco
function
openshift/openshift-tests-private
595992fa-5867-445d-9f2c-a0b7eb611915
NewPinnedImageSet
['PinnedImageSet']
github.com/openshift/openshift-tests-private/test/extended/mco/pinnedimageset.go
func NewPinnedImageSet(oc *exutil.CLI, name string) *PinnedImageSet { return &PinnedImageSet{Resource: *NewResource(oc, "pinnedimageset", name)} }
mco
function
openshift/openshift-tests-private
c762526d-7542-4167-8fe6-5742f65d84bd
CreateGenericPinnedImageSet
['"encoding/json"']
['Pinnedimage', 'PinnedImageSet']
github.com/openshift/openshift-tests-private/test/extended/mco/pinnedimageset.go
func CreateGenericPinnedImageSet(oc *exutil.CLI, name, pool string, images []string) (*PinnedImageSet, error) { logger.Infof("Creating PinnedImageSet %s in pool %s with images %s", name, pool, images) newPIS := NewPinnedImageSet(oc, name) pinnedImages := []Pinnedimage{} for i := range images { pinnedImages = append(pinnedImages, Pinnedimage{Name: images[i]}) } JSONImages, err := json.Marshal(pinnedImages) if err != nil { return newPIS, err } err = NewMCOTemplate(oc, "generic-pinned-image-set.yaml").Create("-p", "NAME="+name, "POOL="+pool, "IMAGES="+string(JSONImages)) if err != nil { return newPIS, err } return newPIS, nil }
mco
function
openshift/openshift-tests-private
40a18331-b007-41c3-bbd7-091ed2c1d879
GetPools
['PinnedImageSet']
github.com/openshift/openshift-tests-private/test/extended/mco/pinnedimageset.go
func (pis PinnedImageSet) GetPools() ([]MachineConfigPool, error) { returnPools := []MachineConfigPool{} pools, err := NewMachineConfigPoolList(pis.GetOC()).GetAll() if err != nil { return nil, err } for _, item := range pools { pool := item ps, err := pool.GetPinnedImageSets() if err != nil { return nil, err } for _, p := range ps { if p.GetName() == pis.GetName() { returnPools = append(returnPools, pool) break } } } return returnPools, nil }
mco
function
openshift/openshift-tests-private
78993e7e-a4ca-44f1-b5ed-d726ca96e6d1
DeleteAndWait
['"time"']
['PinnedImageSet']
github.com/openshift/openshift-tests-private/test/extended/mco/pinnedimageset.go
func (pis PinnedImageSet) DeleteAndWait(waitingTime time.Duration) error { if !pis.Exists() { logger.Infof("%s does not exist! No need to delete it!", pis) return nil } pools, err := pis.GetPools() if err != nil { return err } err = pis.Delete() if err != nil { return err } for _, pool := range pools { err := pool.waitForPinComplete(waitingTime) if err != nil { return err } } return nil }
mco
function
openshift/openshift-tests-private
b8f2bd88-576b-4631-8f18-91a15581449e
GetAll
['PinnedImageSet', 'PinnedImageSetList']
github.com/openshift/openshift-tests-private/test/extended/mco/pinnedimageset.go
func (pisl *PinnedImageSetList) GetAll() ([]PinnedImageSet, error) { pisl.ResourceList.SortByTimestamp() allPISResources, err := pisl.ResourceList.GetAll() if err != nil { return nil, err } allPISs := make([]PinnedImageSet, 0, len(allPISResources)) for _, pisRes := range allPISResources { allPISs = append(allPISs, *NewPinnedImageSet(pisl.oc, pisRes.name)) } return allPISs, nil }
mco
function
openshift/openshift-tests-private
4d5ad6df-b128-42da-96ca-38714ff82e15
GetAllOrFail
['PinnedImageSet', 'PinnedImageSetList']
github.com/openshift/openshift-tests-private/test/extended/mco/pinnedimageset.go
func (pisl *PinnedImageSetList) GetAllOrFail() []PinnedImageSet { piss, err := pisl.GetAll() o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error getting the list of existing PinnedImageSet in the cluster") return piss }
mco
file
openshift/openshift-tests-private
d49035f6-abc5-43ba-975d-53ae25b64799
remote_images
import ( "fmt" logger "github.com/openshift/openshift-tests-private/test/extended/util/logext" "github.com/tidwall/gjson" )
github.com/openshift/openshift-tests-private/test/extended/mco/remote_images.go
package mco import ( "fmt" logger "github.com/openshift/openshift-tests-private/test/extended/util/logext" "github.com/tidwall/gjson" ) // RemoteImage handles images located remotely in a node type RemoteImage struct { Node Node ImageName string } // NewRemoteImage creates a new instance of RemoteFile func NewRemoteImage(node Node, imageName string) *RemoteImage { return &RemoteImage{Node: node, ImageName: imageName} } // String implements the stringer interface func (ri RemoteImage) String() string { return fmt.Sprintf("image %s in node %s", ri.ImageName, ri.Node.GetName()) } func (ri RemoteImage) IsPinned() (bool, error) { stdout, stderr, err := ri.Node.DebugNodeWithChrootStd("crictl", "images", "--pinned", "-o", "json", ri.ImageName) if err != nil { logger.Errorf("Error getting pinned imaformation for %s:\nstdout:%s\nstderr:%s", ri, stdout, stderr) return false, err } logger.Debugf("%s:%s", ri, stdout) pinned := gjson.Get(stdout, "images.0.pinned") if !pinned.Exists() { logger.Infof("%s:%s", ri, stdout) return false, fmt.Errorf("Could not get pinned information for %s", ri) } return pinned.Bool(), nil } // Rmi executes the rmi command to delete the image func (ri RemoteImage) Rmi(args ...string) error { logger.Infof("Removing image %s from node %s", ri.ImageName, ri.Node.GetName()) cmd := []string{"crictl", "rmi"} if len(args) > 0 { cmd = append(cmd, args...) } cmd = append(cmd, ri.ImageName) output, err := ri.Node.DebugNodeWithChroot(cmd...) logger.Infof(output) return err } // Pull pull the image in the node func (ri RemoteImage) Pull(args ...string) error { logger.Infof("Puilling image %s in node %s", ri.ImageName, ri.Node.GetName()) cmd := []string{"crictl", "pull"} if len(args) > 0 { cmd = append(cmd, args...) } cmd = append(cmd, ri.ImageName) output, err := ri.Node.DebugNodeWithChroot(cmd...) logger.Infof(output) return err } // Exists return true if the image is present in the node (it has been pulled) func (ri RemoteImage) Exists() bool { logger.Infof("Checking if %s exists", ri) stdout, stderr, err := ri.Node.DebugNodeWithChrootStd("crictl", "images", "--pinned", "-o", "json", ri.ImageName) if err != nil { logger.Errorf("Error getting pinned imaformation for %s:\nstdout:%s\nstderr:%s", ri, stdout, stderr) return false } logger.Debugf("%s:%s", ri, stdout) pinned := gjson.Get(stdout, "images.0") logger.Infof("%t", pinned.Exists()) return pinned.Exists() }
package mco
function
openshift/openshift-tests-private
6b962132-a6b3-49df-8110-b6a4d31aaea2
NewRemoteImage
['RemoteImage']
github.com/openshift/openshift-tests-private/test/extended/mco/remote_images.go
func NewRemoteImage(node Node, imageName string) *RemoteImage { return &RemoteImage{Node: node, ImageName: imageName} }
mco
function
openshift/openshift-tests-private
db7f6fdd-3573-4642-8a8a-2a2f0b9141de
String
['"fmt"']
['RemoteImage']
github.com/openshift/openshift-tests-private/test/extended/mco/remote_images.go
func (ri RemoteImage) String() string { return fmt.Sprintf("image %s in node %s", ri.ImageName, ri.Node.GetName()) }
mco
function
openshift/openshift-tests-private
0107fb5b-6cf2-41c4-8a68-173183725591
IsPinned
['"fmt"', '"github.com/tidwall/gjson"']
['RemoteImage']
github.com/openshift/openshift-tests-private/test/extended/mco/remote_images.go
func (ri RemoteImage) IsPinned() (bool, error) { stdout, stderr, err := ri.Node.DebugNodeWithChrootStd("crictl", "images", "--pinned", "-o", "json", ri.ImageName) if err != nil { logger.Errorf("Error getting pinned imaformation for %s:\nstdout:%s\nstderr:%s", ri, stdout, stderr) return false, err } logger.Debugf("%s:%s", ri, stdout) pinned := gjson.Get(stdout, "images.0.pinned") if !pinned.Exists() { logger.Infof("%s:%s", ri, stdout) return false, fmt.Errorf("Could not get pinned information for %s", ri) } return pinned.Bool(), nil }
mco
function
openshift/openshift-tests-private
74c5a761-ce42-467b-b99f-5c4b8499069a
Rmi
['RemoteImage']
github.com/openshift/openshift-tests-private/test/extended/mco/remote_images.go
func (ri RemoteImage) Rmi(args ...string) error { logger.Infof("Removing image %s from node %s", ri.ImageName, ri.Node.GetName()) cmd := []string{"crictl", "rmi"} if len(args) > 0 { cmd = append(cmd, args...) } cmd = append(cmd, ri.ImageName) output, err := ri.Node.DebugNodeWithChroot(cmd...) logger.Infof(output) return err }
mco
function
openshift/openshift-tests-private
84407576-c495-441b-b9e7-89046ba37a52
Pull
['RemoteImage']
github.com/openshift/openshift-tests-private/test/extended/mco/remote_images.go
func (ri RemoteImage) Pull(args ...string) error { logger.Infof("Puilling image %s in node %s", ri.ImageName, ri.Node.GetName()) cmd := []string{"crictl", "pull"} if len(args) > 0 { cmd = append(cmd, args...) } cmd = append(cmd, ri.ImageName) output, err := ri.Node.DebugNodeWithChroot(cmd...) logger.Infof(output) return err }
mco
function
openshift/openshift-tests-private
75a87a99-2564-425c-ae04-8b422bd02368
Exists
['"github.com/tidwall/gjson"']
['RemoteImage']
github.com/openshift/openshift-tests-private/test/extended/mco/remote_images.go
func (ri RemoteImage) Exists() bool { logger.Infof("Checking if %s exists", ri) stdout, stderr, err := ri.Node.DebugNodeWithChrootStd("crictl", "images", "--pinned", "-o", "json", ri.ImageName) if err != nil { logger.Errorf("Error getting pinned imaformation for %s:\nstdout:%s\nstderr:%s", ri, stdout, stderr) return false } logger.Debugf("%s:%s", ri, stdout) pinned := gjson.Get(stdout, "images.0") logger.Infof("%t", pinned.Exists()) return pinned.Exists() }
mco
test
openshift/openshift-tests-private
c84f2af7-e6e8-47d4-b7b6-cdea0a45748a
remotefile
import ( "fmt" "os" "path/filepath" "regexp" "strings" 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/remotefile.go
package mco import ( "fmt" "os" "path/filepath" "regexp" "strings" 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" ) const ( statFormat = `--print=Name: %n\nSize: %s\nKind: %F\nPermissions: %04a/%A\nUID: %u/%U\nGID: %g/%G\nLinks: %h\nSymLink: %N\nSelinux: %C\n` statParser = `Name: (?P<name>.+)\n` + `Size: (?P<size>\d+)\n` + `Kind: (?P<kind>.*)\n` + `Permissions: (?P<octalperm>\d+)\/(?P<rwxperm>\S+)\n` + `UID: (?P<uidnumber>\d+)\/(?P<uidname>\S+)\n` + `GID: (?P<gidnumber>\d+)\/(?P<gidname>\S+)\n` + `Links: (?P<links>\d+)\n` + `SymLink: (?P<symlink>.*)\n` + `Selinux: (?P<selinux>.*)` // When parsing an "oc debug" command output, remember that the "utils" function will always trim the latest spaces and newlines startCat = "{{[[!\n" endCat = "\n!]]}}" ) // RemoteFile handles files located remotely in a node type RemoteFile struct { node Node fullPath string statData map[string]string content string } // NewRemoteFile creates a new instance of RemoteFile func NewRemoteFile(node Node, fullPath string) *RemoteFile { return &RemoteFile{node: node, fullPath: fullPath} } // Fetch gets the file information from the node func (rf *RemoteFile) Fetch() error { err := rf.Stat() if err != nil { return err } if !rf.IsDirectory() { err = rf.fetchTextContent() } else { logger.Debugf("Remote file %s is a directory. Skipping fetch content", rf.GetName()) } return err } // Stat get file properties only func (rf *RemoteFile) Stat() error { stdout, stderr, err := rf.node.DebugNodeWithChrootStd("stat", statFormat, rf.fullPath) if err != nil { logger.Errorf("Could not fetch the remote file %s. Stderr: %s", rf.fullPath, stderr) return err } return rf.digest(stdout) } func (rf *RemoteFile) fetchTextContent() error { output, err := rf.node.DebugNodeWithChroot("sh", "-c", fmt.Sprintf("echo -n '%s'; cat %s; echo '%s'", startCat, rf.fullPath, endCat)) if err != nil { return err } // Split by first occurrence of startCat and last occurrence of endCat tmpcontent := strings.SplitN(output, startCat, 2)[1] // take into account that "cat" introduces a newline at the end lastIndex := strings.LastIndex(tmpcontent, endCat) rf.content = fmt.Sprintf(tmpcontent[:lastIndex]) logger.Debugf("remote file %s content is:\n%s", rf.fullPath, rf.content) return nil } // PushNewOwner modifies the remote file's owners, setting the provided new owner using `sudo chown newowner` func (rf *RemoteFile) PushNewOwner(newowner string) error { logger.Infof("Push owner %s to file %s in node %s", newowner, rf.fullPath, rf.node.GetName()) _, err := rf.node.DebugNodeWithChroot("sh", "-c", fmt.Sprintf("sudo chown %s %s", newowner, rf.fullPath)) if err != nil { logger.Errorf("Error: %s", err) return err } return nil } // PushNewPermissions modifies the remote file's permissions, setting the provided new permissions using `chmod newperm` func (rf *RemoteFile) PushNewPermissions(newperm string) error { logger.Infof("Push permissions %s to file %s in node %s", newperm, rf.fullPath, rf.node.GetName()) _, err := rf.node.DebugNodeWithChroot("sh", "-c", fmt.Sprintf("chmod %s %s", newperm, rf.fullPath)) if err != nil { logger.Errorf("Error: %s", err) return err } return nil } // PushNewTextContent modifies the remote file's content func (rf *RemoteFile) PushNewTextContent(newTextContent string) error { return rf.PushNewContent([]byte(newTextContent)) } // PushNewContent modifies the remote file's content func (rf *RemoteFile) PushNewContent(newContent []byte) error { exists, err := rf.ExistsSafe() if err != nil { return err } if !exists { return fmt.Errorf("Node %s. file %s. Refuse to modify the content of a file that does not exist", rf.node.GetName(), rf.fullPath) } tmpFile := filepath.Join(e2e.TestContext.OutputDir, fmt.Sprintf("fetch-%s", exutil.GetRandomString())) if err := os.WriteFile(tmpFile, newContent, 0o600); err != nil { logger.Errorf("Could not read the fetched content from tmp file %s. Error: %s", tmpFile, err) return err } if err := rf.node.CopyFromLocal(tmpFile, rf.fullPath); err != nil { logger.Errorf("Could not push the new content of the remote file %s. Error: %s", rf.fullPath, err) return err } return nil } // GetTextContent return the content of the text file. If the file contains binary data this method cannot be used to retrieve the file's content func (rf *RemoteFile) GetTextContent() string { return rf.content } // Diggest the output of the 'stat' command using the 'statFormat' format. And stores the parsed information inside the 'statData' map // To be able to understand the 'statFormat' format, it uses the 'statParser' regex. Both, 'statFormat' and 'statParser', must be coherent func (rf *RemoteFile) digest(statOutput string) error { logger.Debugf("stat output: %v", statOutput) rf.statData = make(map[string]string) logger.Debugf("parsing with string: %s", statParser) re := regexp.MustCompile(statParser) match := re.FindStringSubmatch(statOutput) logger.Debugf("matched stat info: %v", match) // check whether matched string found if len(match) == 0 { return fmt.Errorf("no file stat info matched") } for i, name := range re.SubexpNames() { if i < 0 { return fmt.Errorf("Data [%s] could not be parsed from 'stat' output: %s", name, statOutput) } if i != 0 && name != "" { rf.statData[name] = match[i] logger.Debugf("Parsing %s = %s", name, rf.statData[name]) } } return nil } // GetUIDName returns the UID of the file in name format func (rf *RemoteFile) GetUIDName() string { return rf.statData["uidname"] } // GetGIDName returns the GID of the file in name format func (rf *RemoteFile) GetGIDName() string { return rf.statData["gidname"] } // GetSelinux returns the file's selinux info func (rf *RemoteFile) GetSelinux() string { return rf.statData["selinux"] } // GetName returns the name of the file func (rf *RemoteFile) GetName() string { return rf.statData["name"] } // GetKind returns a human readable description of the file (regular file, regular empty file, directory, symbolyc link..) func (rf *RemoteFile) GetKind() string { return rf.statData["kind"] } // GetNpermissions deprecated. Use GetOctalPermissions instead func (rf *RemoteFile) GetNpermissions() string { return rf.statData["octalperm"] } // GetOctalPermissions returns permissions in numeric format (0664). Always 4 digits func (rf *RemoteFile) GetOctalPermissions() string { return rf.statData["octalperm"] } // GetUIDNumber the file's UID number func (rf *RemoteFile) GetUIDNumber() string { return rf.statData["uidnumber"] } // GetSymLink returns the symlink description of the file (i.e: "'/tmp/actualfile'" if no link, or "'/tmp/linkfile' -> '/tmp/actualfile'" if link. func (rf *RemoteFile) GetSymLink() string { return rf.statData["symlink"] } // GetSize returns the size of the file in bytes func (rf *RemoteFile) GetSize() string { return rf.statData["size"] } // GetRWXPermissions returns the file permissions in ugo rwx format func (rf *RemoteFile) GetRWXPermissions() string { return rf.statData["rwxperm"] } // GetGIDNumber returns the file's GID number func (rf *RemoteFile) GetGIDNumber() string { return rf.statData["gidnumber"] } // GetLinks returns the number of hard links func (rf *RemoteFile) GetLinks() string { return rf.statData["links"] } // IsDirectory returns true if it is a directory func (rf *RemoteFile) IsDirectory() bool { return rf.GetRWXPermissions()[0] == 'd' && strings.Contains(rf.GetKind(), "directory") } // GetTextContentAsList returns the content of the text file as a list of strings, one string per line func (rf RemoteFile) GetTextContentAsList() []string { return strings.Split(rf.GetTextContent(), "\n") } // GetFilteredTextContent returns the filetered remote file's text content as a list of strings, one string per line matching the regexp. func (rf RemoteFile) GetFilteredTextContent(regex string) ([]string, error) { content := rf.GetTextContentAsList() filteredContent := []string{} for _, line := range content { match, err := regexp.MatchString(regex, line) if err != nil { logger.Errorf("Error filtering content lines. Error: %s", err) return nil, err } if match { filteredContent = append(filteredContent, line) } } return filteredContent, nil } // GetFullPath returns the full path of the remote file func (rf RemoteFile) GetFullPath() string { return rf.fullPath } // ExistsSafe check if a file exists. Returns an error in case of not being able to know if the file exists or not func (rf RemoteFile) ExistsSafe() (bool, error) { output, err := rf.node.DebugNodeWithChroot("stat", rf.fullPath) logger.Infof("\n%s", output) if strings.Contains(output, "No such file or directory") { return false, nil } if err == nil { return true, nil } return false, err } // Exists is like ExistsSafe but if any error happens the file is considered to be non existent func (rf RemoteFile) Exists() bool { exists, err := rf.ExistsSafe() return exists && (err == nil) } // Rm removes the remote file from the node func (rf RemoteFile) Rm(args ...string) error { logger.Infof("Removing file %s from node %s", rf.fullPath, rf.node.GetName()) cmd := []string{"rm"} if len(args) > 0 { cmd = append(cmd, args...) } cmd = append(cmd, rf.fullPath) output, err := rf.node.DebugNodeWithChroot(cmd...) logger.Infof(output) return err } // Create this file in the node with the given content and permissions. It will be created with root/root user/grou since there are no methods to modify the user and the group. // In the future we can modify this method to accept the user and the group as parameters func (rf RemoteFile) Create(content []byte, perm os.FileMode) error { tmpFile := filepath.Join(e2e.TestContext.OutputDir, fmt.Sprintf("fetch-%s", exutil.GetRandomString())) if err := os.WriteFile(tmpFile, content, perm); err != nil { logger.Errorf("Could not read the content from tmp file %s. Error: %s", tmpFile, err) return err } if err := rf.node.CopyFromLocal(tmpFile, rf.fullPath); err != nil { logger.Errorf("Could not copy the file %s from local to path %s in node %s. Error: %s", tmpFile, rf.fullPath, rf.node.GetName(), err) return err } // Actually, the "oc adm copy-to-node" file will ignore the file permissions. Hence, we need to manually set the required permissions if err := rf.PushNewPermissions(fmt.Sprintf("%#o", perm)); err != nil { logger.Infof("Could not set the right permissions in remote file %s in node %s. Error: %s", rf.fullPath, rf.node.GetName(), err) } return nil } // PrintDebug prints a log message with the stats and the content of the remote file func (rf RemoteFile) PrintDebugInfo() error { logger.Infof("Remote file %s in node %s", rf.fullPath, rf.node.GetName()) stdout, _, err := rf.node.DebugNodeWithChrootStd("stat", statFormat, rf.fullPath) if err != nil { return err } logger.Infof("Stat: \n%s", stdout) stdout, _, err = rf.node.DebugNodeWithChrootStd("cat", rf.fullPath) if err != nil { return err } logger.Infof("Content: \n%s", stdout) return nil } // Read is the same function as Fetch but it returns itself as a value, so that it can be used in gomega assertions easily func (rf RemoteFile) Read() (RemoteFile, error) { return rf, rf.Fetch() } // String implements the stringer interface func (rf RemoteFile) String() string { return fmt.Sprintf("file %s in node %s", rf.fullPath, rf.node.GetName()) } // HasInfo returns true if the remote file has been already fetched/read func (rf RemoteFile) HasInfo() bool { return len(rf.statData) > 0 }
package mco
function
openshift/openshift-tests-private
5be23482-fa7a-4ecc-bf6e-1d56f12b16ce
NewRemoteFile
['RemoteFile']
github.com/openshift/openshift-tests-private/test/extended/mco/remotefile.go
func NewRemoteFile(node Node, fullPath string) *RemoteFile { return &RemoteFile{node: node, fullPath: fullPath} }
mco
function
openshift/openshift-tests-private
f59a1ec0-51de-498c-8935-e8fffbc85f87
Fetch
['RemoteFile']
github.com/openshift/openshift-tests-private/test/extended/mco/remotefile.go
func (rf *RemoteFile) Fetch() error { err := rf.Stat() if err != nil { return err } if !rf.IsDirectory() { err = rf.fetchTextContent() } else { logger.Debugf("Remote file %s is a directory. Skipping fetch content", rf.GetName()) } return err }
mco
function
openshift/openshift-tests-private
ac7a7a74-e67f-4fd3-ae32-e71998086a0b
Stat
['RemoteFile']
github.com/openshift/openshift-tests-private/test/extended/mco/remotefile.go
func (rf *RemoteFile) Stat() error { stdout, stderr, err := rf.node.DebugNodeWithChrootStd("stat", statFormat, rf.fullPath) if err != nil { logger.Errorf("Could not fetch the remote file %s. Stderr: %s", rf.fullPath, stderr) return err } return rf.digest(stdout) }
mco
function
openshift/openshift-tests-private
42377f67-c11f-4520-a22b-fe2a178dcc95
fetchTextContent
['"fmt"', '"strings"']
['RemoteFile']
github.com/openshift/openshift-tests-private/test/extended/mco/remotefile.go
func (rf *RemoteFile) fetchTextContent() error { output, err := rf.node.DebugNodeWithChroot("sh", "-c", fmt.Sprintf("echo -n '%s'; cat %s; echo '%s'", startCat, rf.fullPath, endCat)) if err != nil { return err } // Split by first occurrence of startCat and last occurrence of endCat tmpcontent := strings.SplitN(output, startCat, 2)[1] // take into account that "cat" introduces a newline at the end lastIndex := strings.LastIndex(tmpcontent, endCat) rf.content = fmt.Sprintf(tmpcontent[:lastIndex]) logger.Debugf("remote file %s content is:\n%s", rf.fullPath, rf.content) return nil }
mco
function
openshift/openshift-tests-private
a157013a-c62c-4968-bd09-73cb739aa5b3
PushNewOwner
['"fmt"']
['RemoteFile']
github.com/openshift/openshift-tests-private/test/extended/mco/remotefile.go
func (rf *RemoteFile) PushNewOwner(newowner string) error { logger.Infof("Push owner %s to file %s in node %s", newowner, rf.fullPath, rf.node.GetName()) _, err := rf.node.DebugNodeWithChroot("sh", "-c", fmt.Sprintf("sudo chown %s %s", newowner, rf.fullPath)) if err != nil { logger.Errorf("Error: %s", err) return err } return nil }
mco
function
openshift/openshift-tests-private
11402f3c-4bcd-47dc-8bf4-a941edd3ac7d
PushNewPermissions
['"fmt"']
['RemoteFile']
github.com/openshift/openshift-tests-private/test/extended/mco/remotefile.go
func (rf *RemoteFile) PushNewPermissions(newperm string) error { logger.Infof("Push permissions %s to file %s in node %s", newperm, rf.fullPath, rf.node.GetName()) _, err := rf.node.DebugNodeWithChroot("sh", "-c", fmt.Sprintf("chmod %s %s", newperm, rf.fullPath)) if err != nil { logger.Errorf("Error: %s", err) return err } return nil }
mco
function
openshift/openshift-tests-private
c8fa5be3-9b0c-4214-b251-d87d0502a38f
PushNewTextContent
['RemoteFile']
github.com/openshift/openshift-tests-private/test/extended/mco/remotefile.go
func (rf *RemoteFile) PushNewTextContent(newTextContent string) error { return rf.PushNewContent([]byte(newTextContent)) }
mco
function
openshift/openshift-tests-private
14bc6d47-c8e4-4a55-8017-34826dbfa272
PushNewContent
['"fmt"', '"os"', '"path/filepath"']
['RemoteFile']
github.com/openshift/openshift-tests-private/test/extended/mco/remotefile.go
func (rf *RemoteFile) PushNewContent(newContent []byte) error { exists, err := rf.ExistsSafe() if err != nil { return err } if !exists { return fmt.Errorf("Node %s. file %s. Refuse to modify the content of a file that does not exist", rf.node.GetName(), rf.fullPath) } tmpFile := filepath.Join(e2e.TestContext.OutputDir, fmt.Sprintf("fetch-%s", exutil.GetRandomString())) if err := os.WriteFile(tmpFile, newContent, 0o600); err != nil { logger.Errorf("Could not read the fetched content from tmp file %s. Error: %s", tmpFile, err) return err } if err := rf.node.CopyFromLocal(tmpFile, rf.fullPath); err != nil { logger.Errorf("Could not push the new content of the remote file %s. Error: %s", rf.fullPath, err) return err } return nil }
mco
function
openshift/openshift-tests-private
52f5b78c-e27e-4e57-b39a-08ae171b6688
GetTextContent
['RemoteFile']
github.com/openshift/openshift-tests-private/test/extended/mco/remotefile.go
func (rf *RemoteFile) GetTextContent() string { return rf.content }
mco
function
openshift/openshift-tests-private
b1533506-ec89-4081-b943-9f1f6365236b
digest
['"fmt"', '"regexp"']
['RemoteFile']
github.com/openshift/openshift-tests-private/test/extended/mco/remotefile.go
func (rf *RemoteFile) digest(statOutput string) error { logger.Debugf("stat output: %v", statOutput) rf.statData = make(map[string]string) logger.Debugf("parsing with string: %s", statParser) re := regexp.MustCompile(statParser) match := re.FindStringSubmatch(statOutput) logger.Debugf("matched stat info: %v", match) // check whether matched string found if len(match) == 0 { return fmt.Errorf("no file stat info matched") } for i, name := range re.SubexpNames() { if i < 0 { return fmt.Errorf("Data [%s] could not be parsed from 'stat' output: %s", name, statOutput) } if i != 0 && name != "" { rf.statData[name] = match[i] logger.Debugf("Parsing %s = %s", name, rf.statData[name]) } } return nil }
mco
function
openshift/openshift-tests-private
f5b32161-9c23-49f5-9937-8daf97750d20
GetUIDName
['RemoteFile']
github.com/openshift/openshift-tests-private/test/extended/mco/remotefile.go
func (rf *RemoteFile) GetUIDName() string { return rf.statData["uidname"] }
mco
function
openshift/openshift-tests-private
7b809daa-2647-4f48-bce6-2e22eb319cf7
GetGIDName
['RemoteFile']
github.com/openshift/openshift-tests-private/test/extended/mco/remotefile.go
func (rf *RemoteFile) GetGIDName() string { return rf.statData["gidname"] }
mco