Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 24, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Explicitly allow http connections via a new 'http' option to `--insecure-options` ([#1945](https://github.com/coreos/rkt/pull/1945)). Any data and credentials will be sent in the clear.
- When using `bash`, `rkt` commands can be auto-completed ([#1955](https://github.com/coreos/rkt/pull/1955)).
- The executables given on the command line via the `--exec` parameters don't need to be absolute paths anymore ([#1953](https://github.com/coreos/rkt/pull/1953)). This change reflects an update in the appc spec since [v0.7.2](https://github.com/appc/spec/releases/tag/v0.7.2). See rkt's [rkt run --exec](https://github.com/coreos/rkt/blob/master/Documentation/subcommands/run.md#overriding-executable-to-launch) documentation.
- Add a `--full` flag to rkt fetch so it returns full hash of the image. ([#1976](https://github.com/coreos/rkt/pull/1976))

#### Build improvements

Expand Down
8 changes: 6 additions & 2 deletions rkt/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
Short: "Fetch image(s) and store them in the local store",
Run: runWrapper(runFetch),
}
flagFullHash bool
)

func init() {
Expand All @@ -48,6 +49,7 @@ func init() {
cmdFetch.Flags().Var((*appAsc)(&rktApps), "signature", "local signature file to use in validating the preceding image")
cmdFetch.Flags().BoolVar(&flagStoreOnly, "store-only", false, "use only available images in the store (do not discover or download from remote URLs)")
cmdFetch.Flags().BoolVar(&flagNoStore, "no-store", false, "fetch images ignoring the local store")
cmdFetch.Flags().BoolVar(&flagFullHash, "full", false, "print the full image hash after fetching")
}

func runFetch(cmd *cobra.Command, args []string) (exit int) {
Expand Down Expand Up @@ -96,8 +98,10 @@ func runFetch(cmd *cobra.Command, args []string) (exit int) {
if err != nil {
return err
}
shortHash := types.ShortHash(hash)
stdout(shortHash)
if !flagFullHash {
hash = types.ShortHash(hash)
}
stdout(hash)
return nil
})
if err != nil {
Expand Down
26 changes: 24 additions & 2 deletions tests/rkt_fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,28 @@ func TestFetch(t *testing.T) {
}
}

func TestFetchFullHash(t *testing.T) {
imagePath := getInspectImagePath()

ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()

tests := []struct {
fetchArgs string
expectedHashLength int
}{
{"", len("sha512-") + 32},
{"--full", len("sha512-") + 64},
}

for _, tt := range tests {
hash := importImageAndFetchHash(t, ctx, tt.fetchArgs, imagePath)
if len(hash) != tt.expectedHashLength {
t.Fatalf("expected hash length of %d, got %d", tt.expectedHashLength, len(hash))
}
}
}

func testFetchDefault(t *testing.T, arg string, image string, imageArgs string, finalURL string) {
remoteFetchMsgTpl := `remote fetching from URL %q`
storeMsgTpl := `using image from local store for .* %s`
Expand Down Expand Up @@ -156,7 +178,7 @@ func testFetchStoreOnly(t *testing.T, args string, image string, imageArgs strin
// 1. Run cmd with the image not available in the store should get $cannotFetchMsg.
runRktAndCheckRegexOutput(t, cmd, cannotFetchMsg)

importImageAndFetchHash(t, ctx, image)
importImageAndFetchHash(t, ctx, "", image)

// 2. Run cmd with the image available in the store, should get $storeMsg.
runRktAndCheckRegexOutput(t, cmd, storeMsg)
Expand All @@ -169,7 +191,7 @@ func testFetchNoStore(t *testing.T, args string, image string, imageArgs string,
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()

importImageAndFetchHash(t, ctx, image)
importImageAndFetchHash(t, ctx, "", image)

cmd := fmt.Sprintf("%s --no-store %s %s %s", ctx.Cmd(), args, image, imageArgs)

Expand Down
2 changes: 1 addition & 1 deletion tests/rkt_image_cat_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestImageCatManifest(t *testing.T) {
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()

testImageHash := importImageAndFetchHash(t, ctx, testImage)
testImageHash := importImageAndFetchHash(t, ctx, "", testImage)

tests := []struct {
image string
Expand Down
4 changes: 2 additions & 2 deletions tests/rkt_image_dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestImageDependencies(t *testing.T) {
defer server.Close()

baseImage := getInspectImagePath()
_ = importImageAndFetchHash(t, ctx, baseImage)
_ = importImageAndFetchHash(t, ctx, "", baseImage)
emptyImage := getEmptyImagePath()
fileSet := make(map[string]string)

Expand Down Expand Up @@ -171,7 +171,7 @@ func TestImageDependencies(t *testing.T) {
img := imageList[i]
if img.prefetch {
t.Logf("Importing image %q: %q", img.imageName, img.fileName)
testImageShortHash := importImageAndFetchHash(t, ctx, img.fileName)
testImageShortHash := importImageAndFetchHash(t, ctx, "", img.fileName)
t.Logf("Imported image %q: %s", img.imageName, testImageShortHash)
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/rkt_image_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestImageExport(t *testing.T) {
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()

testImageID := importImageAndFetchHash(t, ctx, testImage)
testImageID := importImageAndFetchHash(t, ctx, "", testImage)

testImageHash, err := getHash(testImage)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion tests/rkt_image_extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestImageExtract(t *testing.T) {
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()

testImageShortHash := importImageAndFetchHash(t, ctx, testImage)
testImageShortHash := importImageAndFetchHash(t, ctx, "", testImage)

tests := []struct {
image string
Expand Down
4 changes: 2 additions & 2 deletions tests/rkt_image_render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func TestImageRender(t *testing.T) {
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()

_ = importImageAndFetchHash(t, ctx, baseImage)
testImageShortHash := importImageAndFetchHash(t, ctx, testImage)
_ = importImageAndFetchHash(t, ctx, "", baseImage)
testImageShortHash := importImageAndFetchHash(t, ctx, "", testImage)

tests := []struct {
image string
Expand Down
4 changes: 2 additions & 2 deletions tests/rkt_non_root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestNonRootFetchRmGCImage(t *testing.T) {

rootImg := patchTestACI("rkt-inspect-root-rm.aci", "--exec=/inspect --print-msg=foobar")
defer os.Remove(rootImg)
rootImgHash := importImageAndFetchHash(t, ctx, rootImg)
rootImgHash := importImageAndFetchHash(t, ctx, "", rootImg)

// Launch/gc a pod so we can test non-root image gc.
runCmd := fmt.Sprintf("%s --insecure-options=image run --mds-register=false %s", ctx.Cmd(), rootImg)
Expand All @@ -125,7 +125,7 @@ func TestNonRootFetchRmGCImage(t *testing.T) {
// Should be able to remove the image fetched by ourselves.
nonrootImg := patchTestACI("rkt-inspect-non-root-rm.aci", "--exec=/inspect")
defer os.Remove(nonrootImg)
nonrootImgHash := importImageAndFetchHashAsGid(t, ctx, nonrootImg, gid)
nonrootImgHash := importImageAndFetchHashAsGid(t, ctx, nonrootImg, "", gid)

imgRmCmd = fmt.Sprintf("%s image rm %s", ctx.Cmd(), nonrootImgHash)
t.Logf("Running %s", imgRmCmd)
Expand Down
2 changes: 1 addition & 1 deletion tests/rkt_os_arch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestMissingOrInvalidOSArchFetchRun(t *testing.T) {
defer osArchTestRemoveImages(tests)

for i, tt := range tests {
imgHash := importImageAndFetchHash(t, ctx, tt.image)
imgHash := importImageAndFetchHash(t, ctx, "", tt.image)
rktCmd := fmt.Sprintf("%s run --mds-register=false %s", ctx.Cmd(), imgHash)
t.Logf("Running test #%v: %v", i, rktCmd)
runRktAndCheckOutput(t, rktCmd, tt.expectedLine, tt.expectError)
Expand Down
14 changes: 7 additions & 7 deletions tests/rkt_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ func createTempDirOrPanic(dirName string) string {
return tmpDir
}

func importImageAndFetchHashAsGid(t *testing.T, ctx *testutils.RktRunCtx, img string, gid int) string {
func importImageAndFetchHashAsGid(t *testing.T, ctx *testutils.RktRunCtx, img string, fetchArgs string, gid int) string {
// Import the test image into store manually.
cmd := fmt.Sprintf("%s --insecure-options=image,tls fetch %s", ctx.Cmd(), img)
cmd := fmt.Sprintf("%s --insecure-options=image,tls fetch %s %s", ctx.Cmd(), fetchArgs, img)

// TODO(jonboulle): non-root user breaks trying to read root-written
// config directories. Should be a better way to approach this. Should
// config directories be readable by the rkt group too?
if gid != 0 {
cmd = fmt.Sprintf("%s --insecure-options=image,tls fetch %s", ctx.CmdNoConfig(), img)
cmd = fmt.Sprintf("%s --insecure-options=image,tls fetch %s %s", ctx.CmdNoConfig(), fetchArgs, img)
}
child, err := gexpect.Command(cmd)
if err != nil {
Expand All @@ -200,7 +200,7 @@ func importImageAndFetchHashAsGid(t *testing.T, ctx *testutils.RktRunCtx, img st
}

// Read out the image hash.
result, out, err := expectRegexWithOutput(child, "sha512-[0-9a-f]{32}")
result, out, err := expectRegexWithOutput(child, "sha512-[0-9a-f]{32,64}")
if err != nil || len(result) != 1 {
t.Fatalf("Error: %v\nOutput: %v", err, out)
}
Expand All @@ -210,15 +210,15 @@ func importImageAndFetchHashAsGid(t *testing.T, ctx *testutils.RktRunCtx, img st
return result[0]
}

func importImageAndFetchHash(t *testing.T, ctx *testutils.RktRunCtx, img string) string {
return importImageAndFetchHashAsGid(t, ctx, img, 0)
func importImageAndFetchHash(t *testing.T, ctx *testutils.RktRunCtx, fetchArgs string, img string) string {
return importImageAndFetchHashAsGid(t, ctx, fetchArgs, img, 0)
}

func patchImportAndFetchHash(image string, patches []string, t *testing.T, ctx *testutils.RktRunCtx) string {
imagePath := patchTestACI(image, patches...)
defer os.Remove(imagePath)

return importImageAndFetchHash(t, ctx, imagePath)
return importImageAndFetchHash(t, ctx, "", imagePath)
}

func patchImportAndRun(image string, patches []string, t *testing.T, ctx *testutils.RktRunCtx) {
Expand Down