Skip to content

Commit

Permalink
cli: new install-client and install-cluster commands
Browse files Browse the repository at this point in the history
* Adds two new convenient helper commands to install (and upgrade) latest REANA
  client and cluster scripts.

Signed-off-by: Tibor Simko <tibor.simko@cern.ch>
  • Loading branch information
tiborsimko committed Jul 31, 2018
1 parent 845ea45 commit af98986
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 20 deletions.
113 changes: 100 additions & 13 deletions reana/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
]


REPO_LIST_CLIENT = [
'reana-commons',
'reana-client',
]


REPO_LIST_CLUSTER = [
'reana-commons',
'reana-job-controller',
Expand All @@ -76,6 +82,12 @@
]


REPO_LIST_CLUSTER_CLI = [
'reana-commons',
'reana-cluster',
]


@click.group()
def cli(): # noqa: D301
"""Run REANA development and integration commands.
Expand Down Expand Up @@ -124,6 +136,22 @@ def cli(): # noqa: D301
$ reana-cluster -f reana-cluster-latest.yaml init
$ # we now have REANA cluster running "master" versions of components
How to install latest ``master`` REANA client CLI script:
.. code-block:: console
\b
$ workon reana
$ reana install-client
How to install latest ``master`` REANA cluster CLI script:
.. code-block:: console
\b
$ workon reana
$ reana install-cluster
How to test one component pull request:
.. code-block:: console
Expand Down Expand Up @@ -256,7 +284,9 @@ def select_components(components):
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components;
* (5) special value 'ALL' that will expand to include
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:type components: list
Expand All @@ -271,6 +301,9 @@ def select_components(components):
if component == 'ALL':
for repo in REPO_LIST_ALL:
output.add(repo)
elif component == 'CLIENT':
for repo in REPO_LIST_CLIENT:
output.add(repo)
elif component == 'CLUSTER':
for repo in REPO_LIST_CLUSTER:
output.add(repo)
Expand Down Expand Up @@ -367,7 +400,9 @@ def git_fork(component, browser): # noqa: D301
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'ALL' that will expand to include
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:param browser: The web browser to use. [default=firefox]
:type component: str
Expand Down Expand Up @@ -408,7 +443,9 @@ def git_clone(user, component): # noqa: D301
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'ALL' that will expand to include
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:param user: The GitHub user name. [default=$REANA_GITHUB_USER]
:type component: str
Expand Down Expand Up @@ -449,7 +486,9 @@ def git_status(component): # noqa: D301
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'ALL' that will expand to include
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:type component: str
"""
Expand Down Expand Up @@ -482,7 +521,9 @@ def git_clean(component): # noqa: D301
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'ALL' that will expand to include
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:type component: str
"""
Expand Down Expand Up @@ -548,7 +589,9 @@ def git_fetch(component): # noqa: D301
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'ALL' that will expand to include
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:type component: str
"""
Expand All @@ -573,7 +616,9 @@ def git_upgrade(component): # noqa: D301
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'ALL' that will expand to include
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:type component: str
"""
Expand Down Expand Up @@ -602,7 +647,9 @@ def git_diff(component): # noqa: D301
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'ALL' that will expand to include
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:type component: str
"""
Expand All @@ -627,7 +674,9 @@ def git_push(full, component): # noqa: D301
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'ALL' that will expand to include
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:type component: str
"""
Expand Down Expand Up @@ -658,7 +707,9 @@ def docker_build(user, tag, component, no_cache): # noqa: D301
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'ALL' that will expand to include
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:param user: DockerHub organisation or user name. [default=reanahub]
:param tag: Docker tag to use. [default=latest]
Expand Down Expand Up @@ -717,7 +768,9 @@ def docker_rmi(user, tag, component): # noqa: D301
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'ALL' that will expand to include
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:param user: DockerHub organisation or user name. [default=reanahub]
:param tag: Docker tag to use. [default=latest]
Expand Down Expand Up @@ -756,7 +809,9 @@ def docker_push(user, tag, component): # noqa: D301
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'ALL' that will expand to include
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:param user: DockerHub organisation or user name. [default=reanahub]
:param tag: Docker tag to use. [default=latest]
Expand Down Expand Up @@ -795,7 +850,9 @@ def docker_pull(user, tag, component): # noqa: D301
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'ALL' that will expand to include
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:param user: DockerHub organisation or user name. [default=reanahub]
:param tag: Docker tag to use. [default=latest]
Expand All @@ -812,3 +869,33 @@ def docker_pull(user, tag, component): # noqa: D301
msg = 'Ignoring this component that does not contain' \
' a Dockerfile.'
display_message(msg, component)


@cli.command(name='install-client')
def install_client(): # noqa: D301
"""Install latest REANA client Python package and its dependencies.
\b
:param upgrade: Should we upgrade? [default=True]
:type fetch: bool
"""
for component in REPO_LIST_CLIENT:
for cmd in [
'pip install . --upgrade',
]:
run_command(cmd, component)


@cli.command(name='install-cluster')
def install_cluster(): # noqa: D301
"""Install latest REANA cluster Python package and its dependencies.
\b
:param upgrade: Should we upgrade if already installed? [default=True]
:type fetch: bool
"""
for component in REPO_LIST_CLUSTER_CLI:
for cmd in [
'pip install . --upgrade',
]:
run_command(cmd, component)
17 changes: 10 additions & 7 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def test_is_component_dockerised():

def test_select_components():
"""Tests for select_components()."""
from reana.cli import select_components, REPO_LIST_ALL, REPO_LIST_CLUSTER
from reana.cli import select_components, \
REPO_LIST_ALL, REPO_LIST_CLIENT, REPO_LIST_CLUSTER
for (input_value, output_expected) in (
# regular operation:
(['reana-job-controller', ],
Expand All @@ -57,17 +58,19 @@ def test_select_components():
['reana-job-controller', 'reana, ']),
# special value: '.'
(['.', ], [os.path.basename(os.getcwd()), ]),
# special value: 'cluster'
(['cluster', ], REPO_LIST_CLUSTER),
# special value: 'CLUSTER'
(['CLUSTER', ], REPO_LIST_CLUSTER),
# special value: 'CLIENT'
(['CLIENT', ], REPO_LIST_CLIENT),
# special value: 'ALL'
(['all', ], REPO_LIST_ALL),
(['ALL', ], REPO_LIST_ALL),
# bad values:
(['nonsense', ], []),
(['nonsense', 'reana', ], ['reana', ]),
# output uniqueness:
(['all', 'reana', ], REPO_LIST_ALL),
(['cluster', 'reana', ], REPO_LIST_CLUSTER),
(['all', 'cluster', 'reana'], REPO_LIST_ALL),
(['ALL', 'reana', ], REPO_LIST_ALL),
(['CLUSTER', 'reana', ], REPO_LIST_CLUSTER),
(['ALL', 'CLUSTER', 'reana'], REPO_LIST_ALL),
):
output_obtained = select_components(input_value)
assert output_obtained.sort() == output_expected.sort()
Expand Down

0 comments on commit af98986

Please sign in to comment.