Skip to content
This repository has been archived by the owner on Sep 18, 2020. It is now read-only.

tests: expand coreos-install test options #250

Merged
merged 3 commits into from
Sep 13, 2017

Conversation

arithx
Copy link
Contributor

@arithx arithx commented Sep 12, 2017

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

    • Size of the disk the image is being installed onto. Defaults to 10Gb
  • Board

  • LocalImage

  • Version

  • BaseURL

  • Channel

  • UseLocalServer


The following tests have switched to pulling from the local HTTP server:

  • TestCoreosInstall/Ignition_Test
  • TestCoreosInstall/CloudConfig_Test
  • TestCoreosInstall/Disk_Size_too_small_-_Remote

The following tests are added in this PR:

  • TestCoreosInstall/Disk_Size_too_small_-_Local
  • TestCoreosInstall/Disk_Size_too_small_-_Remote
  • TestCoreosInstall/Alpha_1520.0
  • TestCoreosInstall/Channel_Only
  • TestCoreosInstall/arm64-usr_alpha_1367.5.0
  • TestCoreosInstall/Version_Only

diskFile, loopDevice := test.CreateDevice(t)
defer test.CleanupDisk(t, diskFile, loopDevice)

opts := []string{
Copy link
Contributor

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.

if err == nil {
t.Fatalf("install passed when it shouldn't have")
}
}
Copy link
Contributor

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.

opts = append(opts, "-f", test.LocalImagePath)
}

err := util.Run(t, test.BinaryPath, opts...)
Copy link
Contributor

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?


_, err = io.Copy(tmpFile, resp.Body)
if err != nil {
defer os.Remove(tmpFile.Name())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer not needed here.

newPath := fmt.Sprintf("%s.bin.bz2", oldPath)
err = os.Rename(oldPath, newPath)
if err != nil {
return ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete file.


resp, err := http.Get("https://stable.release.core-os.net/amd64-usr/current/coreos_production_image.bin.bz2")
if err != nil {
return ""
Copy link
Contributor

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.

@@ -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
Copy link
Contributor

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).

@@ -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, " "))
Copy link
Contributor

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.

@arithx
Copy link
Contributor Author

arithx commented Sep 13, 2017

Update pushed

Copy link
Contributor

@bgilbert bgilbert left a 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.

Name: "Disk Size too small - Remote",
Func: installShouldFail,
DiskSize: 2 * 1024 * 1024 * 1024,
BaseURL: util.StringToPtr("https://stable.release.core-os.net/amd64-usr"),
Copy link
Contributor

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.

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 {
Copy link
Contributor

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?

opts = append(opts, "-b", "https://127.0.0.1:8080/")
}

if test.UseLocalFile && test.LocalImagePath != "" {
Copy link
Contributor

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.

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update message

func DownloadFile(tmpDir, name string) error {
file, err := os.Create(filepath.Join(tmpDir, name))
if err != nil {
return fmt.Errorf("failed to create file")
Copy link
Contributor

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.

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"}
Copy link
Contributor

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...)

@arithx
Copy link
Contributor Author

arithx commented Sep 13, 2017

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.

@arithx arithx force-pushed the expanded_options branch 2 times, most recently from b9c984d to 0713486 Compare September 13, 2017 06:13
@arithx
Copy link
Contributor Author

arithx commented Sep 13, 2017

Addressed comments and split the files back out into proper commits (and updated the commit messages).

@arithx arithx force-pushed the expanded_options branch 2 times, most recently from 0838675 to 7f22f47 Compare September 13, 2017 18:02
if err != nil {
panic(err)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return err.

Func: installShouldFail,
DiskSize: 2 * 1024 * 1024 * 1024,
OutputRegexp: diskSize,
})
Copy link
Contributor

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.
@arithx
Copy link
Contributor Author

arithx commented Sep 13, 2017

Updated & pushed, good to merge from my end

@bgilbert bgilbert merged commit 6470951 into coreos:master Sep 13, 2017
@arithx arithx deleted the expanded_options branch September 13, 2017 20:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants