Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request rkt#3860 from sch00lb0y/status
Browse files Browse the repository at this point in the history
status: added read from uuid-file
  • Loading branch information
iaguis committed Nov 28, 2017
2 parents d36f557 + c4aea40 commit dfa1722
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 8 deletions.
1 change: 1 addition & 0 deletions Documentation/subcommands/status.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Both options also accept a duration. To wait up to 10 seconds until the pod is f
| --- | --- | --- | --- |
| `--wait` | `false` | `true` or `false` or duration | Toggle waiting for the pod to finish. |
| `--wait-ready` | `false` | `true` or `false` or duration | Toggle waiting until the pod is ready. |
| `--uuid-file` | "" | UUID file | UUID of the pod. |

## Global options

Expand Down
22 changes: 18 additions & 4 deletions rkt/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

var (
cmdStatus = &cobra.Command{
Use: "status [--wait=bool|timeout] [--wait-ready=bool|timeout] UUID",
Use: "status [--wait=bool|timeout] [--wait-ready=bool|timeout] --uuid-file=FILE | UUID",
Short: "Check the status of a rkt pod",
Long: `Prints assorted information about the pod such as its state, pid and exit status.
Expand All @@ -55,10 +55,25 @@ func init() {

cmdStatus.Flags().Lookup("wait").NoOptDefVal = "true"
cmdStatus.Flags().Lookup("wait-ready").NoOptDefVal = "true"
cmdStatus.Flags().StringVar(&flagUUIDFile, "uuid-file", "", "read pod UUID from file instead of argument")
}

func runStatus(cmd *cobra.Command, args []string) (exit int) {
if len(args) != 1 {
var podUUID string

switch {
case len(args) == 0 && flagUUIDFile != "":
UUID, err := pkgPod.ReadUUIDFromFile(flagUUIDFile)
if err != nil {
stderr.PrintE("unable to resolve UUID from file", err)
return 1
}
podUUID = UUID

case len(args) == 1 && flagUUIDFile == "":
podUUID = args[0]

default:
cmd.Usage()
return 254
}
Expand All @@ -74,8 +89,7 @@ func runStatus(cmd *cobra.Command, args []string) (exit int) {
cmd.Usage()
return 254
}

p, err := pkgPod.PodFromUUIDString(getDataDir(), args[0])
p, err := pkgPod.PodFromUUIDString(getDataDir(), podUUID)
if err != nil {
stderr.PrintE("problem retrieving pod", err)
return 254
Expand Down
8 changes: 4 additions & 4 deletions tests/build-and-run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ function ciSkip {
exit 0
}

# Finds the branching point of two commits.
# For example, let B and D be two commits, and their ancestry graph as A -> B, A -> C -> D.
# Given commits B and D, it returns A.
# Finds the branching point of two commits.
# For example, let B and D be two commits, and their ancestry graph as A -> B, A -> C -> D.
# Given commits B and D, it returns A.
function getBranchingPoint {
diff --old-line-format='' --new-line-format='' \
<(git rev-list --first-parent "${1:-$1}") \
Expand All @@ -51,7 +51,7 @@ function semaphoreCIConfiguration {
if [ -f /opt/change-go-version.sh ]; then
. /opt/change-go-version.sh
change-go-version 1.7

# systemd v229 doesn't build on gcc-4.8, set the compiler to gcc-5
export CC=gcc-5
fi
Expand Down
48 changes: 48 additions & 0 deletions tests/rkt_status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2017 The rkt Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"fmt"
"io/ioutil"
"os"
"testing"

"github.com/rkt/rkt/tests/testutils"
)

func TestUuidFile(t *testing.T) {
const imgName = "rkt-uuid-file-status-test"
imagePath := patchTestACI(fmt.Sprintf("%s.aci", imgName), fmt.Sprintf("--name=%s", imgName))
defer os.Remove(imagePath)

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

cmd := fmt.Sprintf("%s --insecure-options=image prepare %s", ctx.Cmd(), imagePath)
podUuid := runRktAndGetUUID(t, cmd)
tmpDir := mustTempDir(imgName)
defer os.RemoveAll(tmpDir)
uuidFile, err := ioutil.TempFile(tmpDir, "uuid-file")
if err != nil {
panic(fmt.Sprintf("Cannot create uuid-file: %v", err))
}
uuidFilePath := uuidFile.Name()
if err := ioutil.WriteFile(uuidFilePath, []byte(podUuid), 0600); err != nil {
panic(fmt.Sprintf("Cannot write pod uuid to uuid-file %v", err))
}
statusCmd := fmt.Sprintf("%s status --uuid-file=%s", ctx.Cmd(), uuidFilePath)
runRktAndCheckRegexOutput(t, statusCmd, "state=prepared")
}

0 comments on commit dfa1722

Please sign in to comment.