Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display clouds integration test #11072

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 = "8e43f3faa5c9b0463c9b1fffd89dcdbf1f7ed620"

[[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
11 changes: 11 additions & 0 deletions cmd/juju/cloud/list.go
Expand Up @@ -175,9 +175,20 @@ func (c *listCloudsCommand) getCloudList(ctxt *cmd.Context) (*cloudList, error)
}

func (c *listCloudsCommand) Run(ctxt *cmd.Context) error {
// TODO (stickupkid): IsSerial states that its machine is serialisable, we
// shouldn't prompt in those situations. This is a general clean up of how
// we handle formatting directives the user has requested.
// The aim is to provide a more holistic approach at the CLI, rather than
// magic string checking.
// In an ideal world we would move this into MaybePrompt, but the changes
// may have unintended consequences without proper understanding.
// See: https://discourse.jujucharms.com/t/cli-serialisable-output-formats/2490
// 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
9 changes: 9 additions & 0 deletions tests/suites/cli/clouds/public-clouds.yaml
@@ -0,0 +1,9 @@
clouds:
SimonRichardson marked this conversation as resolved.
Show resolved Hide resolved
ec2-test:
type: ec2
auth-types: [userpass]
regions:
us-east-1:
endpoint: https://ec2.us-east-1.amazonaws.com
us-east-2:
endpoint: https://ec2.us-east-2.amazonaws.com
60 changes: 60 additions & 0 deletions tests/suites/cli/display_clouds.sh
@@ -0,0 +1,60 @@
run_show_clouds() {
echo

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 | jq ".[] | select(.defined != \"built-in\")")
if [ -n "${OUT}" ]; then
echo "expected empty, got ${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\")")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an echo of command run, or what's being attempted, for easier debugging and review of test results.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running: ./main.sh -V cli test_desplay_clouds (notice capital V) will tell you exactly what's running... It's easier to see what's going on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay that worked, but not exactly human reading friendly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can do something about that and only trace out certain things, let me think about this.

if [ -n "${OUT}" ]; then
echo "expected empty, got ${OUT}"
exit 1
fi

EXPECTED=$(cat <<'EOF'
{
"defined": "public",
"type": "ec2",
"auth-types": [
"userpass"
],
"regions": {
"us-east-1": {
"endpoint": "https://ec2.us-east-1.amazonaws.com"
},
"us-east-2": {
"endpoint": "https://ec2.us-east-2.amazonaws.com"
}
}
}
EOF
)

OUT=$(XDG_DATA_HOME="${TEST_DIR}" juju clouds --all --format=json 2>/dev/null | jq ".[] | select(.defined != \"built-in\")")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an echo of command run, or what's being attempted, for easier debugging and review of test results.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running: ./main.sh -V cli test_desplay_clouds (notice capital V) will tell you exactly what's running... It's easier to see what's going on.

if [ "${OUT}" != "${EXPECTED}" ]; then
echo "expected ${EXPECTED}, got ${OUT}"
exit 1
fi
}

test_display_clouds() {
if [ "$(skip 'test_display_clouds')" ]; then
echo "==> TEST SKIPPED: display clouds"
return
fi

(
set_verbosity

cd .. || exit

run "run_show_clouds"
)
}
File renamed without changes.
7 changes: 4 additions & 3 deletions tests/suites/cli/task.sh
Expand Up @@ -9,11 +9,12 @@ test_cli() {
echo "==> Checking for dependencies"
check_dependencies juju

file="${TEST_DIR}/test-local-charms.txt"
file="${TEST_DIR}/test-cli.txt"

bootstrap "test-local-charms" "${file}"
bootstrap "test-cli" "${file}"

test_display_clouds
test_local_charms

destroy_controller "test-local-charms"
destroy_controller "test-cli"
}
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