diff options
-rw-r--r-- | .cirrus.yml | 2 | ||||
-rw-r--r-- | cmd/podman/remoteclientconfig/configfile.go | 2 | ||||
-rwxr-xr-x | contrib/cirrus/check_image.sh | 37 | ||||
-rw-r--r-- | contrib/cirrus/lib.sh | 24 | ||||
-rwxr-xr-x | contrib/cirrus/lib.sh.t | 37 | ||||
-rw-r--r-- | libpod.conf | 7 | ||||
-rw-r--r-- | libpod/runtime.go | 55 | ||||
-rw-r--r-- | pkg/adapter/client.go | 10 | ||||
-rw-r--r-- | test/e2e/common_test.go | 2 |
9 files changed, 140 insertions, 36 deletions
diff --git a/.cirrus.yml b/.cirrus.yml index a56697855..00cf1ea5c 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -410,7 +410,7 @@ verify_test_built_images_task: # "probably" work. A full round of testing will happen again after $*_CACHE_IMAGE_NAME # are updated in this or another PR (w/o '***CIRRUS: TEST IMAGES***'). environment_script: '$SCRIPT_BASE/setup_environment.sh |& ${TIMESTAMP}' - + check_image_script: '$SCRIPT_BASE/check_image.sh' integration_test_script: '$SCRIPT_BASE/integration_test.sh |& ${TIMESTAMP}' always: diff --git a/cmd/podman/remoteclientconfig/configfile.go b/cmd/podman/remoteclientconfig/configfile.go index aa3e82a31..06e82b186 100644 --- a/cmd/podman/remoteclientconfig/configfile.go +++ b/cmd/podman/remoteclientconfig/configfile.go @@ -22,7 +22,7 @@ func ReadRemoteConfig(reader io.Reader) (*RemoteConfig, error) { // We need to validate each remote connection has fields filled out for name, conn := range remoteConfig.Connections { if len(conn.Destination) < 1 { - return nil, errors.Errorf("connection %s has no destination defined", name) + return nil, errors.Errorf("connection %q has no destination defined", name) } } return &remoteConfig, err diff --git a/contrib/cirrus/check_image.sh b/contrib/cirrus/check_image.sh new file mode 100755 index 000000000..948039234 --- /dev/null +++ b/contrib/cirrus/check_image.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +set -eo pipefail + +source $(dirname $0)/lib.sh + +RET=0 +echo "Validating VM image" + +MIN_SLASH_GIGS=50 +read SLASH_DEVICE SLASH_FSTYPE SLASH_SIZE JUNK <<<$(findmnt --df --first-only --noheadings / | cut -d '.' -f 1) +SLASH_SIZE_GIGS=$(echo "$SLASH_SIZE" | sed -r -e 's/G|g//') +item_test "Minimum available disk space" $SLASH_SIZE_GIGS -gt $MIN_SLASH_GIGS || let "RET+=1" + +MIN_MEM_MB=2000 +read JUNK TOTAL USED MEM_FREE JUNK <<<$(free -tm | tail -1) +item_test 'Minimum available memory' $MEM_FREE -ge $MIN_MEM_MB || let "RET+=1" + +item_test "podman command NOT found on path" -z "$(type -P podman)" || let "RET+=1" + +MIN_ZIP_VER='3.0' +VER_RE='.+([[:digit:]]+\.[[:digit:]]+).+' +ACTUAL_VER=$(zip --version 2>&1 | egrep -m 1 "Zip$VER_RE" | sed -r -e "s/$VER_RE/\\1/") +item_test "minimum zip version" "$MIN_ZIP_VER" = $(echo -e "$MIN_ZIP_VER\n$ACTUAL_VER" | sort -V | head -1) || let "RET+=1" + +for REQ_UNIT in google-accounts-daemon.service \ + google-clock-skew-daemon.service \ + google-instance-setup.service \ + google-network-daemon.service \ + google-shutdown-scripts.service \ + google-startup-scripts.service +do + item_test "required $REQ_UNIT enabled" \ + "$(systemctl list-unit-files --no-legend $REQ_UNIT)" = "$REQ_UNIT enabled" || let "RET+=1" +done + +exit $RET diff --git a/contrib/cirrus/lib.sh b/contrib/cirrus/lib.sh index 30141db67..36751fbd7 100644 --- a/contrib/cirrus/lib.sh +++ b/contrib/cirrus/lib.sh @@ -114,6 +114,30 @@ req_env_var() { done } +item_test() { + ITEM="$1" + shift + TEST_ARGS="$@" + req_env_var ITEM TEST_ARGS + + if ERR=$(test "$@" 2>&1) + then + echo "ok $ITEM" + return 0 + else + RET=$? + echo -n "not ok $ITEM: $TEST_ARGS" + if [[ -z "$ERR" ]] + then + echo "" + else # test command itself failed + echo -n ":" # space follows :'s in $ERR + echo "$ERR" | cut -d : -f 4- # omit filename, line number, and command + fi + return $RET + fi +} + show_env_vars() { echo "Showing selection of environment variable definitions:" _ENV_VAR_NAMES=$(awk 'BEGIN{for(v in ENVIRON) print v}' | \ diff --git a/contrib/cirrus/lib.sh.t b/contrib/cirrus/lib.sh.t index 1f05b3bb5..70246ef41 100755 --- a/contrib/cirrus/lib.sh.t +++ b/contrib/cirrus/lib.sh.t @@ -12,7 +12,7 @@ function check_result { testnum=$(expr $testnum + 1) MSG=$(echo "$1" | tr -d '*>\012'|sed -e 's/^ \+//') if [ "$MSG" = "$2" ]; then - echo "ok $testnum $3 = $MSG" + echo "ok $testnum $(echo $3) = $(echo $MSG)" else echo "not ok $testnum $3" echo "# expected: $2" @@ -84,5 +84,40 @@ BAR=1 test_rev "FOO BAR" 0 '' ############################################################################### +# tests for test_okay() + +function test_item_test { + local exp_msg=$1 + local exp_ret=$2 + local item=$3 + shift 3 + local test_args="$@" + local msg + msg=$(item_test "$item" "$@") + local status=$? + + check_result "$msg" "$exp_msg" "test_item $item $test_args" + check_result "$status" "$exp_ret" "test_item $item $test_args (actual rc $status)" +} + +# negative tests +test_item_test "FATAL: item_test() requires \$ITEM to be non-empty" 9 "" "" +test_item_test "FATAL: item_test() requires \$TEST_ARGS to be non-empty" 9 "foo" "" +test_item_test "not ok foo: -gt 5 ~= bar: too many arguments" 2 "foo" "-gt" "5" "~=" "bar" +test_item_test "not ok bar: a -ge 10: a: integer expression expected" 2 "bar" "a" "-ge" "10" +test_item_test "not ok basic logic: 0 -ne 0" 1 "basic logic" "0" "-ne" "0" + +# positive tests +test_item_test "ok snafu" 0 "snafu" "foo" "!=" "bar" +test_item_test "ok foobar" 0 "foobar" "one two three" "=" "one two three" +test_item_test "ok oh boy" 0 "oh boy" "line 1 +line2" "!=" "line 1 + +line2" +test_item_test "ok okay enough" 0 "okay enough" "line 1 +line2" "=" "line 1 +line2" + +############################################################################### exit $rc diff --git a/libpod.conf b/libpod.conf index 32f7a56ae..2b5df0e66 100644 --- a/libpod.conf +++ b/libpod.conf @@ -7,15 +7,12 @@ image_default_transport = "docker://" # Paths to look for the Conmon container manager binary conmon_path = [ "/usr/libexec/podman/conmon", - "/usr/libexec/crio/conmon", + "/usr/local/libexec/podman/conmon", "/usr/local/lib/podman/conmon", - "/usr/local/libexec/crio/conmon", "/usr/bin/conmon", "/usr/sbin/conmon", "/usr/local/bin/conmon", - "/usr/local/sbin/conmon", - "/usr/lib/podman/bin/conmon", - "/usr/lib/crio/bin/conmon" + "/usr/local/sbin/conmon" ] # Environment variables to pass into conmon diff --git a/libpod/runtime.go b/libpod/runtime.go index d0dc9e693..c0f49c468 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -284,14 +284,11 @@ func defaultRuntimeConfig() (RuntimeConfig, error) { }, ConmonPath: []string{ "/usr/libexec/podman/conmon", - "/usr/libexec/crio/conmon", "/usr/local/lib/podman/conmon", - "/usr/local/libexec/crio/conmon", "/usr/bin/conmon", "/usr/sbin/conmon", "/usr/local/bin/conmon", "/usr/local/sbin/conmon", - "/usr/lib/crio/bin/conmon", }, ConmonEnvVars: []string{ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", @@ -375,7 +372,7 @@ func NewRuntimeFromConfig(ctx context.Context, userConfigPath string, options .. func homeDir() (string, error) { home := os.Getenv("HOME") if home == "" { - usr, err := user.Current() + usr, err := user.LookupId(fmt.Sprintf("%d", rootless.GetRootlessUID())) if err != nil { return "", errors.Wrapf(err, "unable to resolve HOME directory") } @@ -393,28 +390,33 @@ func getRootlessConfigPath() (string, error) { return filepath.Join(home, ".config/containers/libpod.conf"), nil } -func getConfigPath() string { +func getConfigPath() (string, error) { if rootless.IsRootless() { - rootlessConfigPath, err := getRootlessConfigPath() + path, err := getRootlessConfigPath() if err != nil { - if _, err := os.Stat(rootlessConfigPath); err == nil { - return rootlessConfigPath - } + return "", err + } + if _, err := os.Stat(path); err == nil { + return path, nil } + return "", err } if _, err := os.Stat(OverrideConfigPath); err == nil { // Use the override configuration path - return OverrideConfigPath + return OverrideConfigPath, nil } if _, err := os.Stat(ConfigPath); err == nil { - return ConfigPath + return ConfigPath, nil } - return "" + return "", nil } // DefaultRuntimeConfig reads default config path and returns the RuntimeConfig func DefaultRuntimeConfig() (*RuntimeConfig, error) { - configPath := getConfigPath() + configPath, err := getConfigPath() + if err != nil { + return nil, err + } contents, err := ioutil.ReadFile(configPath) if err != nil { @@ -462,8 +464,10 @@ func newRuntimeFromConfig(ctx context.Context, userConfigPath string, options .. runtime.config.StaticDir = filepath.Join(storageConf.GraphRoot, "libpod") runtime.config.VolumePath = filepath.Join(storageConf.GraphRoot, "volumes") - configPath := getConfigPath() - rootlessConfigPath := "" + configPath, err := getConfigPath() + if err != nil { + return nil, err + } if rootless.IsRootless() { home, err := homeDir() if err != nil { @@ -476,11 +480,6 @@ func newRuntimeFromConfig(ctx context.Context, userConfigPath string, options .. } } - rootlessConfigPath, err = getRootlessConfigPath() - if err != nil { - return nil, err - } - runtimeDir, err := util.GetRootlessRuntimeDir() if err != nil { return nil, err @@ -601,7 +600,13 @@ func newRuntimeFromConfig(ctx context.Context, userConfigPath string, options .. return nil, errors.Wrapf(err, "error configuring runtime") } } - if rootlessConfigPath != "" { + + if rootless.IsRootless() && configPath == "" { + configPath, err := getRootlessConfigPath() + if err != nil { + return nil, err + } + // storage.conf storageConfFile, err := storage.DefaultConfigFile(rootless.IsRootless()) if err != nil { @@ -614,16 +619,16 @@ func newRuntimeFromConfig(ctx context.Context, userConfigPath string, options .. } if configPath != "" { - os.MkdirAll(filepath.Dir(rootlessConfigPath), 0755) - file, err := os.OpenFile(rootlessConfigPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666) + os.MkdirAll(filepath.Dir(configPath), 0755) + file, err := os.OpenFile(configPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666) if err != nil && !os.IsExist(err) { - return nil, errors.Wrapf(err, "cannot open file %s", rootlessConfigPath) + return nil, errors.Wrapf(err, "cannot open file %s", configPath) } if err == nil { defer file.Close() enc := toml.NewEncoder(file) if err := enc.Encode(runtime.config); err != nil { - os.Remove(rootlessConfigPath) + os.Remove(configPath) } } } diff --git a/pkg/adapter/client.go b/pkg/adapter/client.go index 6feae5400..694d9f961 100644 --- a/pkg/adapter/client.go +++ b/pkg/adapter/client.go @@ -15,8 +15,10 @@ import ( var remoteEndpoint *Endpoint func (r RemoteRuntime) RemoteEndpoint() (remoteEndpoint *Endpoint, err error) { - remoteConfigConnections, _ := remoteclientconfig.ReadRemoteConfig(r.config) - + remoteConfigConnections, err := remoteclientconfig.ReadRemoteConfig(r.config) + if errors.Cause(err) != remoteclientconfig.ErrNoConfigationFile { + return nil, err + } // If the user defines an env variable for podman_varlink_bridge // we use that as passed. if bridge := os.Getenv("PODMAN_VARLINK_BRIDGE"); bridge != "" { @@ -47,6 +49,10 @@ func (r RemoteRuntime) RemoteEndpoint() (remoteEndpoint *Endpoint, err error) { if err != nil { return nil, err } + if len(rc.Username) < 1 { + logrus.Debugf("Connection has no username, using current user %q", r.cmd.RemoteUserName) + rc.Username = r.cmd.RemoteUserName + } remoteEndpoint, err = newBridgeConnection("", rc, r.cmd.LogLevel) // last resort is to make a socket connection with the default varlink address for root user } else { diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index 8b6eab892..c3a37236b 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -195,7 +195,7 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration { } } conmonBinary := filepath.Join("/usr/libexec/podman/conmon") - altConmonBinary := "/usr/libexec/crio/conmon" + altConmonBinary := "/usr/bin/conmon" if _, err := os.Stat(conmonBinary); os.IsNotExist(err) { conmonBinary = altConmonBinary } |