Revert "osbuild-worker-executor: job-id in control.json as hostname"
This reverts commit fc1d1c3b8f.
This commit is contained in:
parent
ae4467ab0d
commit
4853bf3ec0
4 changed files with 0 additions and 56 deletions
|
|
@ -12,14 +12,6 @@ var (
|
||||||
HandleIncludedSources = handleIncludedSources
|
HandleIncludedSources = handleIncludedSources
|
||||||
)
|
)
|
||||||
|
|
||||||
func MockUnixSethostname(new func([]byte) error) (restore func()) {
|
|
||||||
saved := unixSethostname
|
|
||||||
unixSethostname = new
|
|
||||||
return func() {
|
|
||||||
unixSethostname = saved
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func MockOsbuildBinary(t *testing.T, new string) (restore func()) {
|
func MockOsbuildBinary(t *testing.T, new string) (restore func()) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
@ -109,7 +108,6 @@ func runOsbuild(logger *logrus.Logger, buildDir string, control *controlJSON, ou
|
||||||
type controlJSON struct {
|
type controlJSON struct {
|
||||||
Environments []string `json:"environments"`
|
Environments []string `json:"environments"`
|
||||||
Exports []string `json:"exports"`
|
Exports []string `json:"exports"`
|
||||||
JobID string `json:"job-id"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustRead(atar *tar.Reader, name string) error {
|
func mustRead(atar *tar.Reader, name string) error {
|
||||||
|
|
@ -237,15 +235,6 @@ func handleIncludedSources(atar *tar.Reader, buildDir string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var unixSethostname = unix.Sethostname
|
|
||||||
|
|
||||||
func setHostname(name string) error {
|
|
||||||
if name == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return unixSethostname([]byte(name))
|
|
||||||
}
|
|
||||||
|
|
||||||
// test for real via:
|
// test for real via:
|
||||||
// curl -o - --data-binary "@./test.tar" -H "Content-Type: application/x-tar" -X POST http://localhost:8001/api/v1/build
|
// curl -o - --data-binary "@./test.tar" -H "Content-Type: application/x-tar" -X POST http://localhost:8001/api/v1/build
|
||||||
func handleBuild(logger *logrus.Logger, config *Config) http.Handler {
|
func handleBuild(logger *logrus.Logger, config *Config) http.Handler {
|
||||||
|
|
@ -273,11 +262,6 @@ func handleBuild(logger *logrus.Logger, config *Config) http.Handler {
|
||||||
http.Error(w, "cannot decode control.json", http.StatusBadRequest)
|
http.Error(w, "cannot decode control.json", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := setHostname(control.JobID); err != nil {
|
|
||||||
logger.Error(err)
|
|
||||||
http.Error(w, "cannot set hostname", http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
buildDir, err := createBuildDir(config)
|
buildDir, err := createBuildDir(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -324,30 +324,3 @@ func TestBuildErrorHandlingTar(t *testing.T) {
|
||||||
assert.Contains(t, string(body), "cannot tar output directory:")
|
assert.Contains(t, string(body), "cannot tar output directory:")
|
||||||
assert.Contains(t, loggerHook.LastEntry().Message, "cannot tar output directory:")
|
assert.Contains(t, loggerHook.LastEntry().Message, "cannot tar output directory:")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuildSethostname(t *testing.T) {
|
|
||||||
baseURL, baseBuildDir, _ := runTestServer(t)
|
|
||||||
endpoint := baseURL + "api/v1/build"
|
|
||||||
|
|
||||||
restore := main.MockOsbuildBinary(t, fmt.Sprintf(`#!/bin/sh -e
|
|
||||||
# simulate output
|
|
||||||
mkdir -p %[1]s/build/output/image
|
|
||||||
echo "fake-build-result" > %[1]s/build/output/image/disk.img
|
|
||||||
`, baseBuildDir))
|
|
||||||
t.Cleanup(restore)
|
|
||||||
|
|
||||||
var hostnameCalls []string
|
|
||||||
restore = main.MockUnixSethostname(func(hn []byte) error {
|
|
||||||
hostnameCalls = append(hostnameCalls, string(hn))
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
t.Cleanup(restore)
|
|
||||||
|
|
||||||
buf := makeTestPost(t, `{"exports": ["tree"], "job-id": "1234-56"}`, `{"fake": "manifest"}`)
|
|
||||||
rsp, err := http.Post(endpoint, "application/x-tar", buf)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
defer func() { _, _ = io.ReadAll(rsp.Body) }()
|
|
||||||
defer rsp.Body.Close()
|
|
||||||
|
|
||||||
assert.Equal(t, []string{"1234-56"}, hostnameCalls)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -72,11 +72,6 @@ func runTestServer(t *testing.T) (baseURL, buildBaseDir string, loggerHook *logr
|
||||||
buildBaseDir = t.TempDir()
|
buildBaseDir = t.TempDir()
|
||||||
baseURL = fmt.Sprintf("http://%s:%d/", host, port)
|
baseURL = fmt.Sprintf("http://%s:%d/", host, port)
|
||||||
|
|
||||||
restore := main.MockUnixSethostname(func([]byte) error {
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
t.Cleanup(restore)
|
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
t.Cleanup(cancel)
|
t.Cleanup(cancel)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue