Skip to content

Commit 6f63a4a

Browse files
committed
tests: add ostree.sync test
Add test for https://issues.redhat.com/browse/OCPBUGS-15917, to verify ostree works in the siutation with disconnected the network volume. As we do not have ceph for testing, according to the suggestion from Colin and Joseph: `use something like NFS, we should in theory see the same error if we disconnected the NFS volume and we could not sync the filesystem.`
1 parent 17c1cc8 commit 6f63a4a

File tree

1 file changed

+239
-0
lines changed

1 file changed

+239
-0
lines changed

mantle/kola/tests/ostree/sync.go

+239
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
// Copyright 2015 CoreOS, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package ostree
16+
17+
import (
18+
"fmt"
19+
"strings"
20+
"time"
21+
22+
"github.com/coreos/coreos-assembler/mantle/kola"
23+
"github.com/coreos/coreos-assembler/mantle/kola/cluster"
24+
"github.com/coreos/coreos-assembler/mantle/kola/register"
25+
"github.com/coreos/coreos-assembler/mantle/platform"
26+
"github.com/coreos/coreos-assembler/mantle/platform/conf"
27+
"github.com/coreos/coreos-assembler/mantle/platform/machine/qemu"
28+
"github.com/coreos/coreos-assembler/mantle/util"
29+
)
30+
31+
var nfs_server_butane = conf.Butane(`variant: fcos
32+
version: 1.5.0
33+
storage:
34+
directories:
35+
- path: /var/nfs/share1
36+
mode: 0777
37+
- path: /var/nfs/share2
38+
mode: 0777
39+
- path: /var/nfs/share3
40+
mode: 0777
41+
- path: /var/nfs/share4
42+
mode: 0777
43+
- path: /var/nfs/share5
44+
mode: 0777
45+
- path: /var/nfs/share6
46+
mode: 0777
47+
files:
48+
- path: "/etc/exports"
49+
overwrite: true
50+
contents:
51+
inline: |
52+
/var/nfs/share1 *(rw)
53+
/var/nfs/share2 *(rw)
54+
/var/nfs/share3 *(rw)
55+
/var/nfs/share4 *(rw)
56+
/var/nfs/share5 *(rw)
57+
/var/nfs/share6 *(rw)
58+
- path: "/var/lib/nfs/etab"
59+
systemd:
60+
units:
61+
- name: "nfs-server.service"
62+
enabled: true`)
63+
64+
func init() {
65+
register.RegisterTest(&register.Test{
66+
// See https://github.com/ostreedev/ostree/pull/2968
67+
Run: ostreeSyncTest,
68+
ClusterSize: 0,
69+
Name: "ostree.sync",
70+
Description: "Verify ostree sync works.",
71+
Distros: []string{"rhcos"},
72+
Platforms: []string{"gcp"},
73+
Tags: []string{"ostree", kola.SkipBaseChecksTag, kola.NeedsInternetTag},
74+
})
75+
}
76+
77+
// NFS server
78+
type NfsServer struct {
79+
Machine platform.Machine
80+
MachineAddress string
81+
}
82+
83+
func setupNFSMachine(c cluster.TestCluster) NfsServer {
84+
var m platform.Machine
85+
var err error
86+
var nfs_server string
87+
88+
options := platform.QemuMachineOptions{
89+
HostForwardPorts: []platform.HostForwardPort{
90+
{Service: "ssh", HostPort: 0, GuestPort: 22},
91+
{Service: "nfs", HostPort: 2049, GuestPort: 2049},
92+
},
93+
}
94+
options.MinMemory = 2048
95+
96+
// start the machine
97+
switch c := c.Cluster.(type) {
98+
// These cases have to be separated because when put together to the same case statement
99+
// the golang compiler no longer checks that the individual types in the case have the
100+
// NewMachineWithQemuOptions function, but rather whether platform.Cluster
101+
// does which fails
102+
case *qemu.Cluster:
103+
m, err = c.NewMachineWithQemuOptions(nfs_server_butane, options)
104+
nfs_server = "10.0.2.2"
105+
default:
106+
m, err = c.NewMachine(nfs_server_butane)
107+
nfs_server = m.PrivateIP()
108+
}
109+
if err != nil {
110+
c.Fatal(err)
111+
}
112+
113+
// Wait for nfs server to become active
114+
err = util.Retry(6, 10*time.Second, func() error {
115+
nfs_status := c.MustSSH(m, "systemctl is-active nfs-server.service")
116+
if string(nfs_status) != "active" {
117+
return fmt.Errorf("nfs-server.service is not ready: %s.", string(nfs_status))
118+
}
119+
return nil
120+
})
121+
if err != nil {
122+
c.Fatalf("Timeout(1m) while waiting for nfs-server.service to be ready: %v", err)
123+
}
124+
return NfsServer{
125+
Machine: m,
126+
MachineAddress: nfs_server,
127+
}
128+
}
129+
130+
// Refer to the steps:
131+
// https://issues.redhat.com/browse/ECOENGCL-91?focusedId=26272587&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-26272587
132+
func ostreeSyncTest(c cluster.TestCluster) {
133+
// Start nfs server machine
134+
nfs_server := setupNFSMachine(c)
135+
136+
// Start test machine
137+
butane := conf.Butane(`variant: fcos
138+
version: 1.5.0
139+
storage:
140+
directories:
141+
- path: /var/tmp/data1
142+
mode: 0777
143+
- path: /var/tmp/data2
144+
mode: 0777
145+
- path: /var/tmp/data3
146+
mode: 0777
147+
- path: /var/tmp/data4
148+
mode: 0777
149+
- path: /var/tmp/data5
150+
mode: 0777
151+
- path: /var/tmp/data6
152+
mode: 0777
153+
files:
154+
- path: /etc/systemd/system.conf
155+
append:
156+
- inline: DefaultTimeoutStopSec=2s
157+
`)
158+
opts := platform.MachineOptions{
159+
MinMemory: 2048,
160+
}
161+
var nfs_client platform.Machine
162+
var err error
163+
164+
switch c := c.Cluster.(type) {
165+
case *qemu.Cluster:
166+
nfs_client, err = c.NewMachineWithOptions(butane, opts)
167+
default:
168+
nfs_client, err = c.NewMachine(butane)
169+
}
170+
if err != nil {
171+
c.Fatalf("Unable to create test machine: %v", err)
172+
}
173+
174+
// Wait for test machine
175+
err = util.Retry(6, 10*time.Second, func() error {
176+
_, err := c.SSHf(nfs_client, `for i in $(seq 6); do
177+
sudo mount -t nfs %s:/var/nfs/share$i /var/tmp/data$i
178+
done`, nfs_server.MachineAddress)
179+
if err != nil {
180+
return err
181+
}
182+
183+
mounts := c.MustSSH(nfs_client, "sudo df -Th | grep nfs | wc -l")
184+
if string(mounts) != "6" {
185+
c.Fatalf("Can not mount all nfs")
186+
}
187+
c.Log("Got NFS mount.")
188+
return nil
189+
})
190+
if err != nil {
191+
c.Fatalf("Timeout(1m) to get nfs mount: %v", err)
192+
}
193+
194+
doSyncTest(c, nfs_client)
195+
}
196+
197+
func doSyncTest(c cluster.TestCluster, client platform.Machine) {
198+
c.RunCmdSync(client, "sudo touch /var/tmp/data3/test")
199+
// Continue write
200+
go func() {
201+
_ = c.MustSSH(client, `set -x; for i in $(seq 6); do
202+
(while sudo rm -f /var/tmp/data$i/test; do \
203+
for x in $(seq 6); do \
204+
sudo dd if=/dev/urandom of=/var/tmp/data$i/test bs=4096 count=2048 conv=notrunc oflag=append &> /dev/null; \
205+
sleep 0.5; \
206+
done; \
207+
done) &
208+
done`)
209+
}()
210+
211+
// Create a stage deploy using kargs while writing
212+
c.RunCmdSync(client, "sleep 2 && sudo rpm-ostree kargs --append=test=1")
213+
214+
netdevices := c.MustSSH(client, "ls /sys/class/net | grep -v lo")
215+
netdevice := string(netdevices)
216+
if netdevice == "" {
217+
c.Fatalf("failed to get net device")
218+
}
219+
c.Log("Set link down and rebooting.")
220+
// Skip the error check as it is expected
221+
cmd := fmt.Sprintf("sudo ip link set %s down && sleep 2 && sudo reboot", netdevice)
222+
_, _, _ = client.SSH(cmd)
223+
224+
time.Sleep(6 * time.Nanosecond)
225+
err := util.Retry(6, 10*time.Second, func() error {
226+
// Look for the kernel argument test=1
227+
kernelArguments, err := c.SSH(client, "cat /proc/cmdline")
228+
if err != nil {
229+
return err
230+
} else if !strings.Contains(string(kernelArguments), "test=1") {
231+
c.Fatalf("Not found test=1 in kernel argument after rebooted")
232+
}
233+
return nil
234+
})
235+
if err != nil {
236+
c.Fatalf("Unable to reboot machine: %v", err)
237+
}
238+
c.Log("Found test=1 in kernel argument after rebooted.")
239+
}

0 commit comments

Comments
 (0)