15
15
package ostree
16
16
17
17
import (
18
- "fmt"
19
18
"regexp"
20
19
"strings"
21
- "time"
22
20
23
21
"github.com/coreos/coreos-assembler/mantle/kola"
24
22
"github.com/coreos/coreos-assembler/mantle/kola/cluster"
25
23
"github.com/coreos/coreos-assembler/mantle/kola/register"
26
- "github.com/coreos/coreos-assembler/mantle/kola/tests/util"
27
24
"github.com/coreos/coreos-assembler/mantle/platform"
28
25
)
29
26
30
- // the "basic" test is only supported on 'rhcos' for now because of how
31
- // the refs are defined. if 'fcos' goes in the same direction, we can
32
- // expand support there.
33
27
func init () {
34
- register .RegisterTest (& register.Test {
35
- Run : ostreeBasicTest ,
36
- ClusterSize : 1 ,
37
- Name : "ostree.basic" ,
38
- Description : "Verify the ostree basic functions work." ,
39
- Distros : []string {"rhcos" },
40
- FailFast : true ,
41
- Tags : []string {"ostree" },
42
- })
43
-
44
28
register .RegisterTest (& register.Test {
45
29
Run : ostreeRemoteTest ,
46
30
ClusterSize : 1 ,
@@ -51,12 +35,6 @@ func init() {
51
35
})
52
36
}
53
37
54
- type ostreeAdminStatus struct {
55
- Checksum string
56
- Origin string
57
- Version string
58
- }
59
-
60
38
// getOstreeRemotes returns the current number of ostree remotes on a machine
61
39
func getOstreeRemotes (c cluster.TestCluster , m platform.Machine ) (int , []string ) {
62
40
remoteListOut := string (c .MustSSH (m , "ostree remote list" ))
@@ -71,121 +49,6 @@ func getOstreeRemotes(c cluster.TestCluster, m platform.Machine) (int, []string)
71
49
return numRemotes , remoteListRaw
72
50
}
73
51
74
- // getOstreeAdminStatus stuffs the important output of `ostree admin status`
75
- // into an `ostreeAdminStatus` struct
76
- func getOstreeAdminStatus (c cluster.TestCluster , m platform.Machine ) (ostreeAdminStatus , error ) {
77
- oaStatus := ostreeAdminStatus {}
78
-
79
- oasOutput , err := c .SSH (m , "ostree admin status" )
80
- if err != nil {
81
- return oaStatus , fmt .Errorf (`Could not get "ostree admin status": %v` , err )
82
- }
83
-
84
- oasSplit := strings .Split (string (oasOutput ), "\n " )
85
- if len (oasSplit ) < 3 {
86
- return oaStatus , fmt .Errorf (`Unexpected output from "ostree admin status": %v` , string (oasOutput ))
87
- }
88
-
89
- // we use a bunch of regexps to find the content in each line of output
90
- // from "ostree admin status". the `match` for each line sticks the
91
- // captured group as the last element of the array; that is used as the
92
- // value for each field of the struct
93
- reCsum , _ := regexp .Compile (`^\* [\w\-]+ ([0-9a-f]+)\.\d` )
94
- csumMatch := reCsum .FindStringSubmatch (oasSplit [0 ])
95
- if csumMatch == nil {
96
- return oaStatus , fmt .Errorf (`Could not parse first line from "ostree admin status": %q` , oasSplit [0 ])
97
- }
98
- oaStatus .Checksum = csumMatch [len (csumMatch )- 1 ]
99
-
100
- reVersion , _ := regexp .Compile (`^Version: (.*)` )
101
- versionMatch := reVersion .FindStringSubmatch (strings .TrimSpace (oasSplit [1 ]))
102
- if versionMatch == nil {
103
- return oaStatus , fmt .Errorf (`Could not parse second line from "ostree admin status": %q` , oasSplit [1 ])
104
- }
105
- oaStatus .Version = versionMatch [len (versionMatch )- 1 ]
106
-
107
- reOrigin , _ := regexp .Compile (`^origin refspec: (.*)` )
108
- originMatch := reOrigin .FindStringSubmatch (strings .TrimSpace (oasSplit [2 ]))
109
- if originMatch == nil {
110
- return oaStatus , fmt .Errorf (`Could not parse third line from "ostree admin status": %q` , oasSplit [2 ])
111
- }
112
- oaStatus .Origin = originMatch [len (originMatch )- 1 ]
113
-
114
- return oaStatus , nil
115
- }
116
-
117
- // ostreeBasicTest performs sanity checks on the output from `ostree admin status`,
118
- // `ostree rev-parse`, and `ostree show` by comparing to the output from `rpm-ostree status`
119
- func ostreeBasicTest (c cluster.TestCluster ) {
120
- m := c .Machines ()[0 ]
121
-
122
- ros , err := util .GetRpmOstreeStatusJSON (c , m )
123
- if err != nil {
124
- c .Fatal (err )
125
- }
126
-
127
- oas , err := getOstreeAdminStatus (c , m )
128
- if err != nil {
129
- c .Fatal (err )
130
- }
131
-
132
- if len (ros .Deployments ) < 1 {
133
- c .Fatalf (`Did not find any deployments?!` )
134
- }
135
-
136
- // verify the output from `ostree admin status`
137
- c .RunLogged ("admin status" , func (c cluster.TestCluster ) {
138
- if oas .Checksum != ros .Deployments [0 ].Checksum {
139
- c .Fatalf (`Checksums do not match; expected %q, got %q` , ros .Deployments [0 ].Checksum , oas .Checksum )
140
- }
141
- if oas .Version != ros .Deployments [0 ].Version {
142
- c .Fatalf (`Versions do not match; expected %q, got %q` , ros .Deployments [0 ].Version , oas .Version )
143
- }
144
- if oas .Origin != ros .Deployments [0 ].Origin {
145
- c .Fatalf (`Origins do not match; expected %q, got %q` , ros .Deployments [0 ].Origin , oas .Origin )
146
- }
147
- })
148
-
149
- // verify the output from `ostree rev-parse`
150
- // this is kind of moot since the origin for RHCOS is just
151
- // the checksum now
152
- c .RunLogged ("rev-parse" , func (c cluster.TestCluster ) {
153
- // check the output of `ostree rev-parse`
154
- c .AssertCmdOutputContains (m , ("ostree rev-parse " + oas .Origin ), oas .Checksum )
155
- })
156
-
157
- // verify the output of 'ostree show'
158
- c .RunLogged ("show" , func (c cluster.TestCluster ) {
159
- oShowOut := c .MustSSH (m , ("ostree show " + oas .Checksum ))
160
- oShowOutSplit := strings .Split (string (oShowOut ), "\n " )
161
- // we need at least the first 4 lines (commit, ContentChecksum, Date, Version)
162
- // to proceed safely
163
- if len (oShowOutSplit ) < 4 {
164
- c .Fatalf (`Unexpected output from "ostree show": %q` , string (oShowOut ))
165
- }
166
-
167
- // convert the 'timestamp' from `rpm-ostree status` into a date that
168
- // we can compare to the date in `ostree admin status`
169
- // also, wtf is up with formatting date/time in golang?!
170
- timeFormat := "2006-01-02 15:04:05 +0000"
171
- tsUnix := time .Unix (ros .Deployments [0 ].Timestamp , 0 ).UTC ()
172
- tsFormatted := tsUnix .Format (timeFormat )
173
- oShowDate := strings .TrimPrefix (oShowOutSplit [2 ], "Date: " )
174
-
175
- if oShowDate != tsFormatted {
176
- c .Fatalf (`Dates do not match; expected %q, got %q` , tsFormatted , oShowDate )
177
- }
178
-
179
- oVersionSplit := strings .Fields (oShowOutSplit [3 ])
180
- if len (oVersionSplit ) < 2 {
181
- c .Fatalf (`Unexpected content in "Version" field of "ostree show" output: %q` , oShowOutSplit [3 ])
182
- }
183
- if oVersionSplit [1 ] != ros .Deployments [0 ].Version {
184
- c .Fatalf (`Versions do not match; expected %q, got %q` , ros .Deployments [0 ].Version , oVersionSplit [1 ])
185
- }
186
- })
187
- }
188
-
189
52
// ostreeRemoteTest verifies the `ostree remote` functionality;
190
53
// specifically: `add`, `delete`, `list`, `refs`, `show-url`, `summary`
191
54
func ostreeRemoteTest (c cluster.TestCluster ) {
0 commit comments