Skip to content

Commit

Permalink
tests: Drop ostree.basic
Browse files Browse the repository at this point in the history
This test was trying to cross-check `ostree admin status` and
`rpm-ostree status` which is well-intentioned but parsing
the former with regexps is just not sustainable and actively broke
with trying to switch to a container deployment in
openshift/os#657

I don't think this check is really worth maintaining; if we somehow
broke `ostree admin status` a whole lot of other upstream tests
would start failing.
  • Loading branch information
cgwalters authored and jmarrero committed Aug 21, 2023
1 parent 3d0c115 commit c82bcb6
Showing 1 changed file with 0 additions and 137 deletions.
137 changes: 0 additions & 137 deletions mantle/kola/tests/ostree/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,16 @@
package ostree

import (
"fmt"
"regexp"
"strings"
"time"

"github.com/coreos/coreos-assembler/mantle/kola"
"github.com/coreos/coreos-assembler/mantle/kola/cluster"
"github.com/coreos/coreos-assembler/mantle/kola/register"
"github.com/coreos/coreos-assembler/mantle/kola/tests/util"
"github.com/coreos/coreos-assembler/mantle/platform"
)

// the "basic" test is only supported on 'rhcos' for now because of how
// the refs are defined. if 'fcos' goes in the same direction, we can
// expand support there.
func init() {
register.RegisterTest(&register.Test{
Run: ostreeBasicTest,
ClusterSize: 1,
Name: "ostree.basic",
Description: "Verify the ostree basic functions work.",
Distros: []string{"rhcos"},
FailFast: true,
Tags: []string{"ostree"},
})

register.RegisterTest(&register.Test{
Run: ostreeRemoteTest,
ClusterSize: 1,
Expand All @@ -51,12 +35,6 @@ func init() {
})
}

type ostreeAdminStatus struct {
Checksum string
Origin string
Version string
}

// getOstreeRemotes returns the current number of ostree remotes on a machine
func getOstreeRemotes(c cluster.TestCluster, m platform.Machine) (int, []string) {
remoteListOut := string(c.MustSSH(m, "ostree remote list"))
Expand All @@ -71,121 +49,6 @@ func getOstreeRemotes(c cluster.TestCluster, m platform.Machine) (int, []string)
return numRemotes, remoteListRaw
}

// getOstreeAdminStatus stuffs the important output of `ostree admin status`
// into an `ostreeAdminStatus` struct
func getOstreeAdminStatus(c cluster.TestCluster, m platform.Machine) (ostreeAdminStatus, error) {
oaStatus := ostreeAdminStatus{}

oasOutput, err := c.SSH(m, "ostree admin status")
if err != nil {
return oaStatus, fmt.Errorf(`Could not get "ostree admin status": %v`, err)
}

oasSplit := strings.Split(string(oasOutput), "\n")
if len(oasSplit) < 3 {
return oaStatus, fmt.Errorf(`Unexpected output from "ostree admin status": %v`, string(oasOutput))
}

// we use a bunch of regexps to find the content in each line of output
// from "ostree admin status". the `match` for each line sticks the
// captured group as the last element of the array; that is used as the
// value for each field of the struct
reCsum, _ := regexp.Compile(`^\* [\w\-]+ ([0-9a-f]+)\.\d`)
csumMatch := reCsum.FindStringSubmatch(oasSplit[0])
if csumMatch == nil {
return oaStatus, fmt.Errorf(`Could not parse first line from "ostree admin status": %q`, oasSplit[0])
}
oaStatus.Checksum = csumMatch[len(csumMatch)-1]

reVersion, _ := regexp.Compile(`^Version: (.*)`)
versionMatch := reVersion.FindStringSubmatch(strings.TrimSpace(oasSplit[1]))
if versionMatch == nil {
return oaStatus, fmt.Errorf(`Could not parse second line from "ostree admin status": %q`, oasSplit[1])
}
oaStatus.Version = versionMatch[len(versionMatch)-1]

reOrigin, _ := regexp.Compile(`^origin refspec: (.*)`)
originMatch := reOrigin.FindStringSubmatch(strings.TrimSpace(oasSplit[2]))
if originMatch == nil {
return oaStatus, fmt.Errorf(`Could not parse third line from "ostree admin status": %q`, oasSplit[2])
}
oaStatus.Origin = originMatch[len(originMatch)-1]

return oaStatus, nil
}

// ostreeBasicTest performs sanity checks on the output from `ostree admin status`,
// `ostree rev-parse`, and `ostree show` by comparing to the output from `rpm-ostree status`
func ostreeBasicTest(c cluster.TestCluster) {
m := c.Machines()[0]

ros, err := util.GetRpmOstreeStatusJSON(c, m)
if err != nil {
c.Fatal(err)
}

oas, err := getOstreeAdminStatus(c, m)
if err != nil {
c.Fatal(err)
}

if len(ros.Deployments) < 1 {
c.Fatalf(`Did not find any deployments?!`)
}

// verify the output from `ostree admin status`
c.RunLogged("admin status", func(c cluster.TestCluster) {
if oas.Checksum != ros.Deployments[0].Checksum {
c.Fatalf(`Checksums do not match; expected %q, got %q`, ros.Deployments[0].Checksum, oas.Checksum)
}
if oas.Version != ros.Deployments[0].Version {
c.Fatalf(`Versions do not match; expected %q, got %q`, ros.Deployments[0].Version, oas.Version)
}
if oas.Origin != ros.Deployments[0].Origin {
c.Fatalf(`Origins do not match; expected %q, got %q`, ros.Deployments[0].Origin, oas.Origin)
}
})

// verify the output from `ostree rev-parse`
// this is kind of moot since the origin for RHCOS is just
// the checksum now
c.RunLogged("rev-parse", func(c cluster.TestCluster) {
// check the output of `ostree rev-parse`
c.AssertCmdOutputContains(m, ("ostree rev-parse " + oas.Origin), oas.Checksum)
})

// verify the output of 'ostree show'
c.RunLogged("show", func(c cluster.TestCluster) {
oShowOut := c.MustSSH(m, ("ostree show " + oas.Checksum))
oShowOutSplit := strings.Split(string(oShowOut), "\n")
// we need at least the first 4 lines (commit, ContentChecksum, Date, Version)
// to proceed safely
if len(oShowOutSplit) < 4 {
c.Fatalf(`Unexpected output from "ostree show": %q`, string(oShowOut))
}

// convert the 'timestamp' from `rpm-ostree status` into a date that
// we can compare to the date in `ostree admin status`
// also, wtf is up with formatting date/time in golang?!
timeFormat := "2006-01-02 15:04:05 +0000"
tsUnix := time.Unix(ros.Deployments[0].Timestamp, 0).UTC()
tsFormatted := tsUnix.Format(timeFormat)
oShowDate := strings.TrimPrefix(oShowOutSplit[2], "Date: ")

if oShowDate != tsFormatted {
c.Fatalf(`Dates do not match; expected %q, got %q`, tsFormatted, oShowDate)
}

oVersionSplit := strings.Fields(oShowOutSplit[3])
if len(oVersionSplit) < 2 {
c.Fatalf(`Unexpected content in "Version" field of "ostree show" output: %q`, oShowOutSplit[3])
}
if oVersionSplit[1] != ros.Deployments[0].Version {
c.Fatalf(`Versions do not match; expected %q, got %q`, ros.Deployments[0].Version, oVersionSplit[1])
}
})
}

// ostreeRemoteTest verifies the `ostree remote` functionality;
// specifically: `add`, `delete`, `list`, `refs`, `show-url`, `summary`
func ostreeRemoteTest(c cluster.TestCluster) {
Expand Down

0 comments on commit c82bcb6

Please sign in to comment.