Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #778 from darkowlzz/no-storage-ps-fail
Browse files Browse the repository at this point in the history
Signed-off-by: leigh capili <leigh@null.net>
  • Loading branch information
stealthybox authored Feb 8, 2021
2 parents 9a9ed89 + 6f16174 commit 05698d4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/ignite/run/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package run
import (
"bytes"
"fmt"
"strings"
"text/template"

api "github.com/weaveworks/ignite/pkg/apis/ignite"
Expand All @@ -27,6 +28,11 @@ type PsOptions struct {
func (pf *PsFlags) NewPsOptions() (po *PsOptions, err error) {
po = &PsOptions{PsFlags: pf}
po.allVMs, err = providers.Client.VMs().FindAll(filter.NewVMFilterAll("", po.All))
// If the storage is uninitialized, avoid failure and continue with empty
// VM list.
if err != nil && strings.Contains(err.Error(), "no such file or directory") {
err = nil
}
return
}

Expand Down
26 changes: 26 additions & 0 deletions cmd/ignite/run/ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ import (
"time"

api "github.com/weaveworks/ignite/pkg/apis/ignite"
"github.com/weaveworks/ignite/pkg/apis/ignite/scheme"
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
"github.com/weaveworks/ignite/pkg/client"
"github.com/weaveworks/ignite/pkg/providers"
"github.com/weaveworks/libgitops/pkg/runtime"
"github.com/weaveworks/libgitops/pkg/storage"
"github.com/weaveworks/libgitops/pkg/storage/cache"
"gotest.tools/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/weaveworks/ignite/pkg/util"
Expand Down Expand Up @@ -167,3 +173,23 @@ func TestPs(t *testing.T) {
}

}

// TestNewPsOptionsStorageNotExists tests that no error is returned if the
// storage directory doesn't exist and NewPsOptions() succeeds with empty VM
// list.
func TestNewPsOptionsStorageNotExists(t *testing.T) {
// Path to a directory that doesn't exist.
dir := "/tmp/ignite-fake-storage-path"
storage := cache.NewCache(
storage.NewGenericStorage(
storage.NewGenericRawStorage(dir), scheme.Serializer))

// Create ignite client with the storage.
providers.Client = client.NewClient(storage)

// Create a new PsOptions and check result.
pf := &PsFlags{}
po, err := pf.NewPsOptions()
assert.NilError(t, err)
assert.Equal(t, 0, len(po.allVMs))
}

0 comments on commit 05698d4

Please # to comment.