-
Notifications
You must be signed in to change notification settings - Fork 98
tests: expand coreos-install test options #250
Conversation
0fb1b3b
to
e82a902
Compare
tests/negative/disk_size.go
Outdated
diskFile, loopDevice := test.CreateDevice(t) | ||
defer test.CleanupDisk(t, diskFile, loopDevice) | ||
|
||
opts := []string{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be better to abstract out the command-line building used by the positive tests, rather than reimplementing here.
tests/negative/disk_size.go
Outdated
if err == nil { | ||
t.Fatalf("install passed when it shouldn't have") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should check that the partition table is wiped afterward.
tests/negative/disk_size.go
Outdated
opts = append(opts, "-f", test.LocalImagePath) | ||
} | ||
|
||
err := util.Run(t, test.BinaryPath, opts...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a test-specific regex to check for a reasonable error message?
tests/util/util.go
Outdated
|
||
_, err = io.Copy(tmpFile, resp.Body) | ||
if err != nil { | ||
defer os.Remove(tmpFile.Name()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defer
not needed here.
tests/util/util.go
Outdated
newPath := fmt.Sprintf("%s.bin.bz2", oldPath) | ||
err = os.Rename(oldPath, newPath) | ||
if err != nil { | ||
return "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete file.
tests/util/util.go
Outdated
|
||
resp, err := http.Get("https://stable.release.core-os.net/amd64-usr/current/coreos_production_image.bin.bz2") | ||
if err != nil { | ||
return "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete tmpFile, or else run Get
before creating the file.
tests/register/register.go
Outdated
@@ -110,6 +115,27 @@ func (test Test) UnmountPartitions(t *testing.T, loopDevice string) { | |||
func (test Test) RunCoreOSInstall(t *testing.T, loopDevice string, opts ...string) { | |||
opts = append(opts, "-d", loopDevice) | |||
|
|||
// use local image if it's available and we aren't testing any version picks directly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will mean that we're testing -f
most of the time, which is the opposite of what users will do, and won't exercise the fetching and signature checking code as much as we could. I'd rather have explicit tests for -f
, and default to overriding -b
instead (and serving HTTP locally).
tests/register/register.go
Outdated
@@ -120,6 +146,8 @@ func (test Test) RunCoreOSInstall(t *testing.T, loopDevice string, opts ...strin | |||
opts = append(opts, "-c", cloudinitPath) | |||
} | |||
|
|||
t.Logf("Running coreos-install via the following command: %s %s", test.BinaryPath, strings.Join(opts, " ")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please trim this message down. The command line is the important part, and the extra words will make it harder to skim the logs.
e82a902
to
44eef55
Compare
Update pushed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just some minor issues.
The review changes were all bunched into the last commit. If it's too hard to separate them out at this point, I'd be okay with squashing all three commits together, since this is still early code.
tests/negative/disk_size.go
Outdated
Name: "Disk Size too small - Remote", | ||
Func: installShouldFail, | ||
DiskSize: 2 * 1024 * 1024 * 1024, | ||
BaseURL: util.StringToPtr("https://stable.release.core-os.net/amd64-usr"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the override? It seems as though the local file, served via HTTP, should be sufficient.
tests/register/register.go
Outdated
opts = append(opts, "-d", loopDevice) | ||
|
||
// use local http server if we aren't testing specific flags | ||
if test.Version == nil && test.BaseURL == nil && test.Channel == nil && test.Board == nil && !test.UseLocalFile { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes it impossible to use a completely default command line (with only -d
specified). It seems as though we should have one test, at least, that does that. Maybe add e.g. a NoLocalServer
flag?
tests/register/register.go
Outdated
opts = append(opts, "-b", "https://127.0.0.1:8080/") | ||
} | ||
|
||
if test.UseLocalFile && test.LocalImagePath != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the test has asked to force a local file, but we don't have a path for one, we should fail rather than silently alter the command line.
tests/register/register.go
Outdated
@@ -183,11 +238,31 @@ func (test Test) ValidateCloudConfig(t *testing.T, rootDir, config string) { | |||
} | |||
|
|||
func (test Test) ValidateOSRelease(t *testing.T, rootDir string) { | |||
if _, err := os.Stat(filepath.Join(rootDir, "usr", "lib", "os-release")); os.IsNotExist(err) { | |||
data, err := ioutil.ReadFile(filepath.Join(rootDir, "usr", "lib", "os-release")) | |||
if os.IsNotExist(err) { | |||
t.Fatalf("/usr/lib/os-release was not found") | |||
} else if err != nil { | |||
t.Fatalf("running stat on /usr/lib/os-release: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update message
tests/util/util.go
Outdated
func DownloadFile(tmpDir, name string) error { | ||
file, err := os.Create(filepath.Join(tmpDir, name)) | ||
if err != nil { | ||
return fmt.Errorf("failed to create file") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include err
in all these calls.
tests/util/util.go
Outdated
http.HandleFunc(fmt.Sprintf("/%s/coreos_production_image.bin.bz2", version), server.Image) | ||
http.HandleFunc(fmt.Sprintf("/%s/coreos_production_image.bin.bz2.sig", version), server.Signature) | ||
|
||
s := &http.Server{Addr: ":8080"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll probably want to listen on localhost only. Also, in general, hardcoded ports should be avoided for this sort of thing, since they prevent two copies of the test suite from running at once. You can have the OS pick an unused port and pass it through to the tests.
(I just realized the Ignition tests also hardcode the server port...)
When I make the next round of changes I'll pull them back out into the proper commits and update the commit messages to reflect their new state. |
b9c984d
to
0713486
Compare
Addressed comments and split the files back out into proper commits (and updated the commit messages). |
0838675
to
7f22f47
Compare
tests/util/util.go
Outdated
if err != nil { | ||
panic(err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return err.
tests/negative/disk_size.go
Outdated
Func: installShouldFail, | ||
DiskSize: 2 * 1024 * 1024 * 1024, | ||
OutputRegexp: diskSize, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can fetch from local server.
Downloads the current stable release image and drops it into a temp dir in /var/tmp or the TMPDIR env var for the overall test run. Runs a webserver which serves the version.txt, image, and image signature. Adds the following variables to the Test object: - LocalImagePath - LocalAddress - Version - BaseURL - Channel - Board - UseLocalFile - UseLocalServer
Adds an initial set of tests targeting the Version, Channel, & Board functionality.
7f22f47
to
de333b5
Compare
Updated & pushed, good to merge from my end |
Also adds support for local image file caching. The
UseLocalServer
flag can be used to pull from the local HTTP server.Adds flags to the Test object for the following options:
Disk Size
Board
LocalImage
Version
BaseURL
Channel
UseLocalServer
The following tests have switched to pulling from the local HTTP server:
The following tests are added in this PR: