Skip to content

Commit 02b7fe7

Browse files
authored
RD-6537 agents list: add --all-states (#1457)
* RD-6537 agents list: add `--all-states` By default, `cfy agents list` only shows started agents; with this, it still does that, but CLI-side rather than restclient-side; and now it's also possible to list agents in other states. Additionally, also show that state. * update tests - make all the mocks now expect the implicit state - check --all-states too * flake & format
1 parent d756136 commit 02b7fe7

4 files changed

Lines changed: 60 additions & 19 deletions

File tree

cloudify_cli/cli/cfy.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import click
1818

19+
from cloudify.models_states import AgentState
1920
from cloudify_rest_client.constants import VisibilityState
2021
from cloudify_rest_client.exceptions import NotModifiedError
2122
from cloudify_rest_client.exceptions import CloudifyClientError
@@ -1949,18 +1950,36 @@ def agent_filters(self, f):
19491950
19501951
Applies deployment id, node id and node instance id filters.
19511952
"""
1952-
node_instance_id = click.option('--node-instance-id', multiple=True,
1953-
help=helptexts.AGENT_NODE_INSTANCE_ID,
1954-
callback=self.parse_comma_separated)
1955-
node_id = click.option('--node-id', multiple=True,
1956-
help=helptexts.AGENT_NODE_ID,
1957-
callback=self.parse_comma_separated)
1958-
install_method = click.option('--install-method', multiple=True,
1959-
help=helptexts.AGENT_INSTALL_METHOD,
1960-
callback=self.parse_comma_separated)
1961-
deployment_id = click.option('--deployment-id', multiple=True,
1962-
help=helptexts.AGENT_DEPLOYMENT_ID,
1963-
callback=self.parse_comma_separated)
1953+
node_instance_id = click.option(
1954+
'--node-instance-id',
1955+
multiple=True,
1956+
help=helptexts.AGENT_NODE_INSTANCE_ID,
1957+
callback=self.parse_comma_separated,
1958+
)
1959+
node_id = click.option(
1960+
'--node-id',
1961+
multiple=True,
1962+
help=helptexts.AGENT_NODE_ID,
1963+
callback=self.parse_comma_separated,
1964+
)
1965+
install_method = click.option(
1966+
'--install-method',
1967+
multiple=True,
1968+
help=helptexts.AGENT_INSTALL_METHOD,
1969+
callback=self.parse_comma_separated,
1970+
)
1971+
deployment_id = click.option(
1972+
'--deployment-id',
1973+
multiple=True,
1974+
help=helptexts.AGENT_DEPLOYMENT_ID,
1975+
callback=self.parse_comma_separated,
1976+
)
1977+
all_states = click.option(
1978+
'--all-states',
1979+
default=False,
1980+
is_flag=True,
1981+
help=helptexts.AGENT_ALL_STATES,
1982+
)
19641983

19651984
# we add separate --node-instance-id, --node-id and --deployment-id
19661985
# arguments, but only expose a agents_filter = {'node_id': ..} dict
@@ -1976,12 +1995,14 @@ def _inner(*args, **kwargs):
19761995
('install_method', AGENT_FILTER_INSTALL_METHODS)]:
19771996
filters[filter_name] = kwargs.pop(arg_name, None)
19781997

1998+
if not kwargs.pop('all_states', False):
1999+
filters['state'] = [AgentState.STARTED]
19792000
kwargs['agent_filters'] = filters
19802001
return f(*args, **kwargs)
19812002
return _inner
19822003

19832004
for arg in [install_method, node_instance_id, node_id,
1984-
deployment_id, _filters_deco]:
2005+
deployment_id, all_states, _filters_deco]:
19852006
f = arg(f)
19862007
return f
19872008

cloudify_cli/cli/helptexts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@
433433
AGENT_INSTALL_METHOD = 'Only show agents installed with this install_method' \
434434
+ _MULTIPLE_TIMES_FRAGMENT
435435
AGENT_DEPLOYMENT_ID = DEPLOYMENT_ID + _MULTIPLE_TIMES_FRAGMENT
436+
AGENT_ALL_STATES = 'Show agents in all states, not only started ones'
436437

437438
AGENTS_WAIT = "Wait for agents operations to end, and show execution logs"
438439
INSTALL_AGENT_TIMEOUT = "Agent installation timeout"

cloudify_cli/commands/agents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535

3636

3737
_NODE_INSTANCE_STATE_STARTED = 'started'
38-
AGENT_COLUMNS = ['id', 'ip', 'deployment', 'node', 'system', 'version',
39-
'install_method', 'tenant_name']
38+
AGENT_COLUMNS = ['id', 'ip', 'deployment', 'state', 'node', 'system',
39+
'version', 'install_method', 'tenant_name']
4040

4141
MAX_TRACKER_THREADS = 20
4242

cloudify_cli/tests/commands/test_options.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from mock import MagicMock
22

3+
from cloudify.models_states import AgentState
34
from cloudify_cli.logger import get_global_json_output
45

56
from .mocks import MockListResponse
@@ -33,7 +34,9 @@ def test_agent_filters_all_tenants(self):
3334
install_methods=[],
3435
node_ids=['a'],
3536
node_instance_ids=[],
36-
_all_tenants=True)
37+
_all_tenants=True,
38+
state=[AgentState.STARTED],
39+
)
3740

3841
def test_agent_filters_multiple(self):
3942
self.invoke('agents list --node-id a --node-id b')
@@ -42,7 +45,9 @@ def test_agent_filters_multiple(self):
4245
install_methods=[],
4346
node_ids=['a', 'b'],
4447
node_instance_ids=[],
45-
_all_tenants=False)
48+
_all_tenants=False,
49+
state=[AgentState.STARTED],
50+
)
4651

4752
def test_agent_filters_commaseparated(self):
4853
self.invoke('agents list --node-id a,b')
@@ -51,7 +56,9 @@ def test_agent_filters_commaseparated(self):
5156
install_methods=[],
5257
node_ids=['a', 'b'],
5358
node_instance_ids=[],
54-
_all_tenants=False)
59+
_all_tenants=False,
60+
state=[AgentState.STARTED],
61+
)
5562

5663
def test_agent_filters_commaseparated_multiple(self):
5764
self.invoke('agents list --node-id a,b --node-id c')
@@ -60,4 +67,16 @@ def test_agent_filters_commaseparated_multiple(self):
6067
install_methods=[],
6168
node_ids=['a', 'b', 'c'],
6269
node_instance_ids=[],
63-
_all_tenants=False)
70+
_all_tenants=False,
71+
state=[AgentState.STARTED],
72+
)
73+
74+
def test_agents_filters_all_states(self):
75+
self.invoke('agents list --all-states')
76+
self.client.agents.list.assert_called_with(
77+
deployment_id=[],
78+
install_methods=[],
79+
node_ids=[],
80+
node_instance_ids=[],
81+
_all_tenants=False,
82+
)

0 commit comments

Comments
 (0)