Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .supernova
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This is an example config for use with tests
[dfw]
SUPERNOVA_DASHBOARD_URL=https://dfw.dashboard.rackspacecloud.com/
SUPERNOVA_GROUP=raxusa
OS_AUTH_URL=https://identity.api.rackspacecloud.com/v2.0/
OS_AUTH_SYSTEM=rackspace
Expand Down
21 changes: 20 additions & 1 deletion supernova/executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
to run
"""
import sys
import webbrowser


import click
Expand Down Expand Up @@ -93,6 +94,8 @@ def print_env_short_list(ctx, param, value):
help="Display the least amount of output possible")
@click.option('--echo', '-e', default=None, is_flag=True,
help="Print the specified environment and exit")
@click.option('--dashboard', '-D', default=None, is_flag=True,
help="Open dashboard in browser for specified environment")
@click.argument('environment', nargs=1)
@click.argument('command', nargs=-1)
@click.version_option()
Expand All @@ -104,7 +107,7 @@ def print_env_short_list(ctx, param, value):
help="List all configured environments in shorter format")
@click.pass_context
def run_supernova(ctx, executable, debug, quiet, environment, command, conf,
echo):
echo, dashboard):
"""
You can use supernova with many OpenStack clients and avoid the pain of
managing multiple sets of environment variables. Getting started is easy
Expand Down Expand Up @@ -154,6 +157,7 @@ def run_supernova(ctx, executable, debug, quiet, environment, command, conf,
'executable': executable,
'quiet': quiet,
'echo': echo,
'dashboard': dashboard,
}

# If the user specified a single environment, we need to verify that the
Expand All @@ -176,6 +180,21 @@ def run_supernova(ctx, executable, debug, quiet, environment, command, conf,
click.echo('{0}={1}'.format(k, env[k]))
ctx.exit(0)

if supernova_args['dashboard']:
if len(envs) > 1:
msg = ("\nCan't open dashboard for a group of environments.\n"
"Specify a single environment when using --dashboard.")
click.echo(msg)
ctx.exit(1)
url = nova_creds[envs[0]].get('SUPERNOVA_DASHBOARD_URL')
if url is None:
msg = ("\nNo SUPERNOVA_DASHBOARD_URL specified "
"for environment: %s" % envs[0])
click.echo(msg)
ctx.exit(1)
webbrowser.open(url)
ctx.exit(0)

if len(command) == 0:
msg = ("\nMissing arguments to pass to executable Run supernova "
"--help for examples.\n".format(envs[0]))
Expand Down
25 changes: 25 additions & 0 deletions tests/test_executable.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import webbrowser

from click.testing import CliRunner


Expand Down Expand Up @@ -111,6 +113,29 @@ def test_broken_configuration_file(self):
assert result.exit_code != 0
assert "There's an error in your configuration file" in result.output

def test_dashboard(self, monkeypatch):
def mockreturn(url):
return False
monkeypatch.setattr(webbrowser, "open", mockreturn)
runner = CliRunner()
result = runner.invoke(executable.run_supernova,
['--dashboard', 'dfw'])
assert result.exit_code == 0

def test_dashboard_group(self):
runner = CliRunner()
result = runner.invoke(executable.run_supernova,
['--dashboard', 'raxusa'])
assert result.exit_code == 1
assert 'group of environments' in result.output

def test_dashboard_no_url(self):
runner = CliRunner()
result = runner.invoke(executable.run_supernova,
['--dashboard', 'hkg'])
assert result.exit_code == 1
assert 'No SUPERNOVA_DASHBOARD_URL' in result.output

def test_echo(self):
runner = CliRunner()
result = runner.invoke(executable.run_supernova, ['--echo', 'hkg'])
Expand Down