Skip to content

Commit

Permalink
Display clouds integration tests
Browse files Browse the repository at this point in the history
The following changes introduce the idea of a display clouds integration
tests. Unfortunately it required to change how we handle machine
interactions. For formatting directives such as json or yaml, we never
want to be prompted for anything, we just either want an empty output in
the right format (json being {}) or the data.

Bringing in the changes is the first drive into doing so, the PR doesn't
enforce the changes through out, although it is a first step in doing
so.

Adding redirection of the stderr to /dev/null for machine directives is
pointless, so in the future checking for ctx.IsSerial() should be used.
If the value is true then omitting the information and the noise is
probably the wisest.
  • Loading branch information
SimonRichardson committed Jan 6, 2020
1 parent 40dfedb commit 6234651
Show file tree
Hide file tree
Showing 21 changed files with 68 additions and 20 deletions.
6 changes: 4 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Expand Up @@ -285,7 +285,7 @@

[[constraint]]
name = "github.com/juju/cmd"
revision = "74922f23f6436a661dacd8c5fdf9cb15641e7a2e"
revision = "3494531d4f0091d4d43a19b4ace7b87e13995c74"

[[constraint]]
name = "github.com/juju/collections"
Expand Down
2 changes: 1 addition & 1 deletion cmd/juju/application/show.go
Expand Up @@ -86,7 +86,7 @@ func (c *showApplicationCommand) Init(args []string) error {
// SetFlags implements Command.SetFlags.
func (c *showApplicationCommand) SetFlags(f *gnuflag.FlagSet) {
c.ModelCommandBase.SetFlags(f)
c.out.AddFlags(f, "yaml", cmd.DefaultFormatters)
c.out.AddFlags(f, "yaml", cmd.DefaultFormatters.Formatters())
}

// ApplicationsInfoAPI defines the API methods that show-application command uses.
Expand Down
7 changes: 7 additions & 0 deletions cmd/juju/cloud/list.go
Expand Up @@ -175,9 +175,16 @@ func (c *listCloudsCommand) getCloudList(ctxt *cmd.Context) (*cloudList, error)
}

func (c *listCloudsCommand) Run(ctxt *cmd.Context) error {
// TODO: is serial states that it's machine serialisable. We shouldn't
// prompt in those situations. In an ideal world we would move this into
// MaybePrompt, but the changes may have unintended consequences without
// proper understanding.
// Should fix this for Juju 3.0
c.ReadOnly = ctxt.IsSerial()
if err := c.MaybePrompt(ctxt, "list clouds from"); err != nil {
return errors.Trace(err)
}

details, err := c.getCloudList(ctxt)
if err != nil {
return errors.Trace(err)
Expand Down
Empty file.
7 changes: 7 additions & 0 deletions tests/suites/cli/clouds/public-clouds.yaml
@@ -0,0 +1,7 @@
clouds:
vmaas:
type: maas
auth-types: [oauth1]
endpoint: http://192.168.1.21/MAAS
regions:
default: {}
36 changes: 34 additions & 2 deletions tests/suites/cli/display_clouds.sh
@@ -1,11 +1,43 @@
run_show_clouds() {
echo

touch "${TEST_DIR}/public-clouds.yaml"
mkdir -p "${TEST_DIR}/juju"
echo "" >> "${TEST_DIR}/juju/public-clouds.yaml"
echo "" >> "${TEST_DIR}/juju/credentials.yaml"

OUT=$(XDG_DATA_HOME="${TEST_DIR}" juju clouds --local --format=json 2>/dev/null)
OUT=$(XDG_DATA_HOME="${TEST_DIR}" juju clouds --local --format=json 2>/dev/null | jq ".[] | select(.defined != \"built-in\")")
if [ -n "${OUT}" ]; then
echo "expected empty ${OUT}"
exit 1
fi

cp ./tests/suites/cli/clouds/public-clouds.yaml "${TEST_DIR}"/juju/public-clouds.yaml
OUT=$(XDG_DATA_HOME="${TEST_DIR}" juju clouds --local --format=json 2>/dev/null | jq ".[] | select(.defined != \"built-in\")")
if [ -n "${OUT}" ]; then
echo "expected empty ${OUT}"
exit 1
fi

EXPECTED=$(cat <<'EOF'
{
"defined": "public",
"type": "maas",
"description": "Metal As A Service",
"auth-types": [
"oauth1"
],
"endpoint": "http://192.168.1.21/MAAS",
"regions": {
"default": {}
}
}
EOF
)

OUT=$(XDG_DATA_HOME="${TEST_DIR}" juju clouds --all --format=json 2>/dev/null | jq ".[] | select(.defined != \"built-in\")")
if [ "${OUT}" != "${EXPECTED}" ]; then
echo "expected ${EXPECTED}, got ${OUT}"
exit 1
fi
}

Expand Down
2 changes: 1 addition & 1 deletion worker/uniter/runner/jujuc/action-get.go
Expand Up @@ -47,7 +47,7 @@ map as needed.
// SetFlags handles known option flags; in this case, [--output={json|yaml}]
// and --help.
func (c *ActionGetCommand) SetFlags(f *gnuflag.FlagSet) {
c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
c.out.AddFlags(f, "smart", cmd.DefaultFormatters.Formatters())
}

// Init makes sure there are no additional unknown arguments to action-get.
Expand Down
2 changes: 1 addition & 1 deletion worker/uniter/runner/jujuc/config-get.go
Expand Up @@ -40,7 +40,7 @@ reported as null. <key> and --all are mutually exclusive.
}

func (c *ConfigGetCommand) SetFlags(f *gnuflag.FlagSet) {
c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
c.out.AddFlags(f, "smart", cmd.DefaultFormatters.Formatters())
f.BoolVar(&c.All, "a", false, "print all keys")
f.BoolVar(&c.All, "all", false, "")
}
Expand Down
2 changes: 1 addition & 1 deletion worker/uniter/runner/jujuc/credential-get.go
Expand Up @@ -38,7 +38,7 @@ credential-get returns the cloud specification used by the unit's model.

// SetFlags is part of the cmd.Command interface.
func (c *CredentialGetCommand) SetFlags(f *gnuflag.FlagSet) {
c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
c.out.AddFlags(f, "smart", cmd.DefaultFormatters.Formatters())
}

// Init is part of the cmd.Command interface.
Expand Down
2 changes: 1 addition & 1 deletion worker/uniter/runner/jujuc/is-leader.go
Expand Up @@ -39,7 +39,7 @@ there is no such guarantee.

// SetFlags is part of the cmd.Command interface.
func (c *isLeaderCommand) SetFlags(f *gnuflag.FlagSet) {
c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
c.out.AddFlags(f, "smart", cmd.DefaultFormatters.Formatters())
}

// Run is part of the cmd.Command interface.
Expand Down
2 changes: 1 addition & 1 deletion worker/uniter/runner/jujuc/leader-get.go
Expand Up @@ -42,7 +42,7 @@ is given, or if the key is "-", all keys and values will be printed.

// SetFlags is part of the cmd.Command interface.
func (c *leaderGetCommand) SetFlags(f *gnuflag.FlagSet) {
c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
c.out.AddFlags(f, "smart", cmd.DefaultFormatters.Formatters())
}

// Init is part of the cmd.Command interface.
Expand Down
2 changes: 1 addition & 1 deletion worker/uniter/runner/jujuc/network-get.go
Expand Up @@ -75,7 +75,7 @@ If more than one flag is specified, a map of values is returned.

// SetFlags is part of the cmd.Command interface.
func (c *NetworkGetCommand) SetFlags(f *gnuflag.FlagSet) {
c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
c.out.AddFlags(f, "smart", cmd.DefaultFormatters.Formatters())
f.BoolVar(&c.primaryAddress, "primary-address", false, "(deprecated) get the primary address for the binding")
f.BoolVar(&c.bindAddress, "bind-address", false, "get the address for the binding on which the unit should listen")
f.BoolVar(&c.ingressAddress, "ingress-address", false, "get the ingress address for the binding")
Expand Down
2 changes: 1 addition & 1 deletion worker/uniter/runner/jujuc/opened-ports.go
Expand Up @@ -32,7 +32,7 @@ func (c *OpenedPortsCommand) Info() *cmd.Info {
}

func (c *OpenedPortsCommand) SetFlags(f *gnuflag.FlagSet) {
c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
c.out.AddFlags(f, "smart", cmd.DefaultFormatters.Formatters())
}

func (c *OpenedPortsCommand) Init(args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion worker/uniter/runner/jujuc/relation-get.go
Expand Up @@ -71,7 +71,7 @@ leader.

// SetFlags is part of the cmd.Command interface.
func (c *RelationGetCommand) SetFlags(f *gnuflag.FlagSet) {
c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
c.out.AddFlags(f, "smart", cmd.DefaultFormatters.Formatters())
f.Var(c.relationIdProxy, "r", "Specify a relation by id")
f.Var(c.relationIdProxy, "relation", "")

Expand Down
2 changes: 1 addition & 1 deletion worker/uniter/runner/jujuc/relation-ids.go
Expand Up @@ -52,7 +52,7 @@ func (c *RelationIdsCommand) Info() *cmd.Info {
}

func (c *RelationIdsCommand) SetFlags(f *gnuflag.FlagSet) {
c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
c.out.AddFlags(f, "smart", cmd.DefaultFormatters.Formatters())
}

func (c *RelationIdsCommand) Init(args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion worker/uniter/runner/jujuc/relation-list.go
Expand Up @@ -48,7 +48,7 @@ func (c *RelationListCommand) Info() *cmd.Info {
}

func (c *RelationListCommand) SetFlags(f *gnuflag.FlagSet) {
c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
c.out.AddFlags(f, "smart", cmd.DefaultFormatters.Formatters())
f.Var(c.relationIdProxy, "r", "specify a relation by id")
f.Var(c.relationIdProxy, "relation", "")
}
Expand Down
2 changes: 1 addition & 1 deletion worker/uniter/runner/jujuc/status-get.go
Expand Up @@ -39,7 +39,7 @@ If the --include-data flag is passed, the associated data are printed also.
}

func (c *StatusGetCommand) SetFlags(f *gnuflag.FlagSet) {
c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
c.out.AddFlags(f, "smart", cmd.DefaultFormatters.Formatters())
f.BoolVar(&c.includeData, "include-data", false, "print all status data")
f.BoolVar(&c.applicationWide, "application", false, "print status for all units of this application if this unit is the leader")
}
Expand Down
2 changes: 1 addition & 1 deletion worker/uniter/runner/jujuc/storage-get.go
Expand Up @@ -45,7 +45,7 @@ When no <key> is supplied, all keys values are printed.
}

func (c *StorageGetCommand) SetFlags(f *gnuflag.FlagSet) {
c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
c.out.AddFlags(f, "smart", cmd.DefaultFormatters.Formatters())
f.Var(c.storageTagProxy, "s", "specify a storage instance by id")
}

Expand Down
2 changes: 1 addition & 1 deletion worker/uniter/runner/jujuc/storage-list.go
Expand Up @@ -44,7 +44,7 @@ instances for that named storage will be returned.
}

func (c *StorageListCommand) SetFlags(f *gnuflag.FlagSet) {
c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
c.out.AddFlags(f, "smart", cmd.DefaultFormatters.Formatters())
}

func (c *StorageListCommand) Init(args []string) (err error) {
Expand Down
2 changes: 1 addition & 1 deletion worker/uniter/runner/jujuc/unit-get.go
Expand Up @@ -35,7 +35,7 @@ func (c *UnitGetCommand) Info() *cmd.Info {
}

func (c *UnitGetCommand) SetFlags(f *gnuflag.FlagSet) {
c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
c.out.AddFlags(f, "smart", cmd.DefaultFormatters.Formatters())
}

func (c *UnitGetCommand) Init(args []string) error {
Expand Down

0 comments on commit 6234651

Please sign in to comment.