Skip to content

Commit dcf2b97

Browse files
committed
mantle: move kolet binary location to /usr/local/bin
I'm writing a test that verifies files on the filesystem in CoreOS machinges match the SELinux policy. Placing kolet in `/var/home/core/kolet` with a `bin_t` context is a violation of this. Let's use /usr/local/bin/. This has the side effect of the file having the right `bin_t` context as soon as it is created. (cherry picked from commit b076a72)
1 parent f97dd2e commit dcf2b97

File tree

7 files changed

+37
-20
lines changed

7 files changed

+37
-20
lines changed

docs/kola/external-tests.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,18 @@ method is deprecated and will be removed at some point)
112112

113113
## HTTP Server
114114

115-
The `kolet` binary is copied into the `core` user's home directory
116-
(`/var/home/core`) on the CoreOS system running the tests. Notably, it contains
117-
the built-in command `kolet httpd` for starting an HTTP file server to serve the
118-
contents of the file system.
119-
By default, it starts the server listening on port `80` and serves the contents of
115+
The `kolet` binary is copied into the `/usr/local/bin/` directory on the CoreOS
116+
system running the tests. Notably, it contains the built-in command `kolet httpd`
117+
for starting an HTTP file server to serve the contents of the file system. By
118+
default, it starts the server listening on port `80` and serves the contents of
120119
the file system at `./`; you can use the `--port` and `--path` flags to override
121120
the defaults.
122121

123122
For example, if you're using a bash script as your test, you can start an HTTP
124123
server to serve the contents at `/var/home/core` like this:
125124
```
126125
echo testdata > /var/home/core/testdata.txt
127-
systemd-run /var/home/core/kolet httpd --path /var/home/core/
126+
systemd-run /usr/local/bin/kolet httpd --path /var/home/core/
128127
# It may take some time for the server to start.
129128
sleep 1
130129
curl localhost/testdata.txt
@@ -155,13 +154,13 @@ systemd:
155154
[Unit]
156155
Before=kola-runext.service
157156
[Path]
158-
PathExists=/var/home/core/kolet
157+
PathExists=/usr/local/bin/kolet
159158
[Install]
160159
WantedBy=kola-runext.service
161160
- name: kolet-httpd.service
162161
contents: |
163162
[Service]
164-
ExecStart=/var/home/core/kolet httpd --path /var/www -v
163+
ExecStart=/usr/local/bin/kolet httpd --path /var/www -v
165164
[Install]
166165
WantedBy=kola-runext.service
167166
storage:

mantle/cmd/kolet/kolet.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ const (
9797
autopkgTestRebootPath = "/tmp/autopkgtest-reboot"
9898
autopkgtestRebootScript = `#!/bin/bash
9999
set -xeuo pipefail
100-
~core/kolet reboot-request "$1"
100+
/usr/local/bin/kolet reboot-request "$1"
101101
reboot
102102
`
103103
autopkgTestRebootPreparePath = "/tmp/autopkgtest-reboot-prepare"
104104

105105
autopkgtestRebootPrepareScript = `#!/bin/bash
106106
set -euo pipefail
107-
exec ~core/kolet reboot-request "$1"
107+
exec /usr/local/bin/kolet reboot-request "$1"
108108
`
109109

110110
// File used to communicate between the script and the kolet runner internally

mantle/kola/cluster/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (t *TestCluster) RunLogged(name string, f func(c TestCluster)) bool {
7474

7575
// RunNative runs a registered NativeFunc on a remote machine
7676
func (t *TestCluster) RunNative(funcName string, m platform.Machine) bool {
77-
command := fmt.Sprintf("./kolet run %q %q", t.H.Name(), funcName)
77+
command := fmt.Sprintf("/usr/local/bin/kolet run %q %q", t.H.Name(), funcName)
7878
return t.Run(funcName, func(c TestCluster) {
7979
client, err := m.SSHClient()
8080
if err != nil {

mantle/kola/harness.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,10 +1118,10 @@ func runExternalTest(c cluster.TestCluster, mach platform.Machine, testNum int)
11181118
// This is a non-exclusive test
11191119
unit := fmt.Sprintf("%s-%d.service", KoletExtTestUnit, testNum)
11201120
// Reboot requests are disabled for non-exclusive tests
1121-
cmd = fmt.Sprintf("sudo ./kolet run-test-unit --deny-reboots %s", shellquote.Join(unit))
1121+
cmd = fmt.Sprintf("sudo /usr/local/bin/kolet run-test-unit --deny-reboots %s", shellquote.Join(unit))
11221122
} else {
11231123
unit := fmt.Sprintf("%s.service", KoletExtTestUnit)
1124-
cmd = fmt.Sprintf("sudo ./kolet run-test-unit %s", shellquote.Join(unit))
1124+
cmd = fmt.Sprintf("sudo /usr/local/bin/kolet run-test-unit %s", shellquote.Join(unit))
11251125
}
11261126
stdout, err = c.SSH(mach, cmd)
11271127

@@ -1893,9 +1893,14 @@ func runTest(h *harness.H, t *register.Test, pltfrm string, flight platform.Flig
18931893
t.Run(tcluster)
18941894
}
18951895

1896-
// ScpKolet searches for a kolet binary and copies it to the machine.
1896+
// ScpKolet searches for a kolet binary and copies it to the machines.
1897+
// Write initially to a .partial file in the same directory and then
1898+
// rename since systemd.path units may be watching and we don't want
1899+
// them to start while the file is still transferring.
18971900
func ScpKolet(machines []platform.Machine) error {
18981901
mArch := Options.CosaBuildArch
1902+
remotepath := "/usr/local/bin/kolet"
1903+
remotepathpartial := remotepath + ".partial"
18991904
exePath, err := os.Executable()
19001905
if err != nil {
19011906
return errors.Wrapf(err, "finding path of executable")
@@ -1908,8 +1913,21 @@ func ScpKolet(machines []platform.Machine) error {
19081913
} {
19091914
kolet := filepath.Join(d, "kolet")
19101915
if _, err := os.Stat(kolet); err == nil {
1911-
if err := cluster.DropLabeledFile(machines, kolet, "bin_t"); err != nil {
1912-
return errors.Wrapf(err, "dropping kolet binary")
1916+
in, err := os.Open(kolet)
1917+
if err != nil {
1918+
return err
1919+
}
1920+
defer in.Close()
1921+
for _, m := range machines {
1922+
if _, err := in.Seek(0, 0); err != nil {
1923+
return errors.Wrapf(err, "seeking kolet binary")
1924+
}
1925+
if err := platform.InstallFile(in, m, remotepathpartial); err != nil {
1926+
return errors.Wrapf(err, "dropping kolet binary")
1927+
}
1928+
if out, stderr, err := m.SSH(fmt.Sprintf("sudo mv %s %s", remotepathpartial, remotepath)); err != nil {
1929+
return errors.Wrapf(err, "running sudo mv %s %s: %s: %s", remotepathpartial, remotepath, out, stderr)
1930+
}
19131931
}
19141932
return nil
19151933
}

mantle/kola/tests/ignition/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func init() {
8181
func resourceLocal(c cluster.TestCluster) {
8282
server := c.Machines()[0]
8383

84-
c.RunCmdSyncf(server, "sudo systemd-run --quiet ./kolet run %s Serve", c.H.Name())
84+
c.RunCmdSyncf(server, "sudo systemd-run --quiet /usr/local/bin/kolet run %s Serve", c.H.Name())
8585

8686
ip := server.PrivateIP()
8787
if c.Platform() == packet.Platform {

mantle/kola/tests/ignition/security.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ EOF
9595
publicKey := c.MustSSH(server, "sudo cat /var/tls/server.crt")
9696

9797
var conf *conf.UserData = localSecurityClient
98-
c.RunCmdSyncf(server, "sudo systemd-run --quiet ./kolet run %s TLSServe", c.H.Name())
98+
c.RunCmdSyncf(server, "sudo systemd-run --quiet /usr/local/bin/kolet run %s TLSServe", c.H.Name())
9999

100100
client, err := c.NewMachine(conf.Subst("$IP", ip).Subst("$KEY", dataurl.EncodeBytes(publicKey)))
101101
if err != nil {

mantle/kola/tests/upgrade/basic.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ func init() {
8080
{
8181
"name": "kolet-httpd.path",
8282
"enabled": true,
83-
"contents": "[Path]\nPathExists=/var/home/core/kolet\n[Install]\nWantedBy=multi-user.target"
83+
"contents": "[Path]\nPathExists=/usr/local/bin/kolet\n[Install]\nWantedBy=multi-user.target"
8484
},
8585
{
8686
"name": "kolet-httpd.service",
87-
"contents": "[Service]\nExecStart=/var/home/core/kolet run fcos.upgrade.basic httpd -v\n[Install]\nWantedBy=multi-user.target"
87+
"contents": "[Service]\nExecStart=/usr/local/bin/kolet run fcos.upgrade.basic httpd -v\n[Install]\nWantedBy=multi-user.target"
8888
}
8989
]
9090
},

0 commit comments

Comments
 (0)