Skip to content

Commit

Permalink
Fixes issue #556 Brief and full form for connection list
Browse files Browse the repository at this point in the history
Modify connection list table to have a brief table form
that shows only name, server, and mock_server columns and
an option --full for a display of all of the fields (except
password and ca-certs).

Remove the option that hides empty columns of the table so
that all columns in the defined list show even if there is no
data in the column.

Added tests for this.

Modified the docs/pywbemcli/commands.rst to show this option
and show the tables with and without the option.

This change  modified cmdshelp.rst to add the option.
  • Loading branch information
KSchopmeyer committed Apr 4, 2020
1 parent 5dbf8b7 commit 99e8831
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 54 deletions.
9 changes: 9 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ Released: not yet
[COMMAND-OPTIONS] and showing the positioning of both arguments and
command arguments. (See issue #446)

* Add option `--full` to `connection list` to create both a brief table
output that only has 3 columns (name, server, mock-server) as default but
when the option is set all of the columns currently in the report. We did
this because it appears that the most frequent use of this command is to just
get the name of the various servers defined within an 80 column display.
This also now shows empty columns where the original report hid any columns
that were empty. (See issue #556)


**Cleanup:**

* Test: Enabled Python warning suppression for PendingDeprecationWarning
Expand Down
3 changes: 3 additions & 0 deletions docs/pywbemcli/cmdshelp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,9 @@ Help text for ``pywbemcli connection list`` (see :ref:`connection list command`)
See also the 'connection select' command.

Command Options:
-f, --full If set, display the full table. Otherwise display a brief view(name, server, mock_server columns). This
table does not show the ca_certs field.

-h, --help Show this message and exit.


Expand Down
64 changes: 50 additions & 14 deletions docs/pywbemcli/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ See :ref:`pywbemcli connection export --help` for the exact help output of the c
.. _`Connection list command`:

Connection list command
^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^

The ``connection list`` command lists the connection definitions in the
:term:`connections file` and also the current connection if it has not been
Expand All @@ -1331,19 +1331,55 @@ The default connection, if defined, is marked with `#` in the Name column.
pywbemcli> --server http://localhost --user me --password mypw --no-verify connection save me
pywbemcli> --server http://blahblah connection list
WBEM server connections: (#: default, *: current)
+--------------+------------------+-------------+-------------+-----------+----------+----------------------------------------+
| name | server | namespace | user | timeout | verify | mock-server |
|--------------+------------------+-------------+-------------+-----------+----------+----------------------------------------|
| *blahblah | http://blah | root/cimv2 | | 45 | False | |
| mock1 | | root/cimv2 | | | False | tests/unit/simple_mock_model.mof |
| mockalltypes | | root/cimv2 | | 30 | False | tests/unit/all_types.mof |
| mockassoc | | root/cimv2 | | 30 | False | tests/unit/simple_assoc_mock_model.mof |
| mockext | | root/cimv2 | | 30 | False | tests/unit/simple_mock_model_ext.mof |
| op | http://localhost | root/cimv2 | xxxxxxxxxxx | | False | |
| test3 | | root/cimv2 | | | False | tests/unit/simple_mock_model.mof |
| | | | | | | tests/unit/mock_confirm_y.py |
+--------------+------------------+-------------+-------------+-----------+----------+----------------------------------------+
WBEM server connections(brief): (#: default, *: current)
+--------------+------------------+----------------------------------------+
| name | server | mock-server |
|--------------+------------------+----------------------------------------|
| *blahblah | http://blah | |
| mock1 | | tests/unit/simple_mock_model.mof |
| mockalltypes | | tests/unit/all_types.mof |
| mockassoc | | tests/unit/simple_assoc_mock_model.mof |
| mockext | | tests/unit/simple_mock_model_ext.mof |
| op | http://localhost | |
| test3 | | tests/unit/simple_mock_model.mof |
| | | tests/unit/mock_confirm_y.py |
+--------------+------------------+----------------------------------------+
A more complete display of the server parameters is available with the
`--full` option as follows:

.. code-block:: text
pywbemcli> connection list --full
WBEM server connections(full): (#: default, *: current)
+--------------+----------------------+------------------------+-------------+-----------+------------+----------+------------+-----------+--------------------------------------------------+
| name | server | namespace | user | timeout | use_pull | verify | certfile | keyfile | mock-server |
+==============+======================+========================+=============+===========+============+==========+============+===========+==================================================+
| #mockassoc | | root/cimv2 | | 30 | | True | | | tests/unit/simple_assoc_mock_model.mof |
+--------------+----------------------+------------------------+-------------+-----------+------------+----------+------------+-----------+--------------------------------------------------+
| alltypes | | root/cimv2 | | 30 | | True | | | tests/unit/all_types.mof |
+--------------+----------------------+------------------------+-------------+-----------+------------+----------+------------+-----------+--------------------------------------------------+
| complexassoc | | root/cimv2 | | 30 | | True | | | tests/unit/complex_assoc_model.mof |
+--------------+----------------------+------------------------+-------------+-----------+------------+----------+------------+-----------+--------------------------------------------------+
| mock1 | | root/cimv2 | | 30 | | True | | | tests/unit/simple_mock_model.mof |
+--------------+----------------------+------------------------+-------------+-----------+------------+----------+------------+-----------+--------------------------------------------------+
| mock1ext | | root/cimv2 | | 30 | | True | | | tests/unit/simple_mock_model_ext.mof |
+--------------+----------------------+------------------------+-------------+-----------+------------+----------+------------+-----------+--------------------------------------------------+
| mock1interop | | interop | | 30 | | True | | | tests/unit/simple_mock_model.mof |
+--------------+----------------------+------------------------+-------------+-----------+------------+----------+------------+-----------+--------------------------------------------------+
| ophttp | http://localhost | root/cimv2 | | 30 | | True | | | |
+--------------+----------------------+------------------------+-------------+-----------+------------+----------+------------+-----------+--------------------------------------------------+
| ophttps | https://localhost | root/cimv2 | blahblah | 30 | | False | | | |
+--------------+----------------------+------------------------+-------------+-----------+------------+----------+------------+-----------+--------------------------------------------------+
| opt | https://blah | root/cimv2 | | 45 | | False | c1.pem | k1.pem | |
+--------------+----------------------+------------------------+-------------+-----------+------------+----------+------------+-----------+--------------------------------------------------+
| test1 | | root/cimv2 | | 30 | | True | | | tests/unit/simple_assoc_mock_model.mof |
+--------------+----------------------+------------------------+-------------+-----------+------------+----------+------------+-----------+--------------------------------------------------+
`Connection list` does not display the password or the ca-certs fields. See
:ref:`Connection show command` to display these fields.

See :ref:`pywbemcli connection list --help` for the exact help output of the command.

Expand Down
54 changes: 34 additions & 20 deletions pywbemtools/pywbemcli/_cmd_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
from pywbem import Error

from .pywbemcli import cli
from ._common import CMD_OPTS_TXT, CMD_OPTS_TXT, GENERAL_OPTS_TXT, \
from ._common import CMD_OPTS_TXT, GENERAL_OPTS_TXT, \
SUBCMD_HELP_TXT, pick_one_from_list, format_table, \
hide_empty_columns, raise_pywbem_error_exception, validate_output_format
raise_pywbem_error_exception, validate_output_format
from ._pywbem_server import PywbemServer
from ._connection_repository import ConnectionRepository
from ._context_obj import ContextObj
Expand Down Expand Up @@ -233,8 +233,13 @@ def connection_save(context, name):

@connection_group.command('list', cls=PywbemcliCommand,
options_metavar=CMD_OPTS_TXT)
@click.option('-f', '--full', is_flag=True,
default=False,
help='If set, display the full table. Otherwise display '
' a brief view(name, server, mock_server columns). '
'This table does not show the ca_certs field.')
@click.pass_obj
def connection_list(context):
def connection_list(context, **options):
"""
List the WBEM connection definitions.
Expand All @@ -248,7 +253,7 @@ def connection_list(context):
See also the 'connection select' command.
"""
context.execute_cmd(lambda: cmd_connection_list(context))
context.execute_cmd(lambda: cmd_connection_list(context, options))


################################################################
Expand Down Expand Up @@ -567,14 +572,24 @@ def cmd_connection_save(context, name):
connections.add(save_connection.name, save_connection)


def cmd_connection_list(context):
def cmd_connection_list(context, options):
"""
Dump all of the current servers in the persistent repository line
by line. This method displays the information as a table independent
of the value of the cmd line output_format general option.
"""
connections = ConnectionRepository()
def build_row(options, name, svr):
"""
Append one row to the list
"""
if options['full']:
return [name, svr.server, svr.default_namespace, svr.user,
svr.timeout, svr.use_pull, svr.verify, svr.certfile,
svr.keyfile, "\n".join(svr.mock_server)]
else:
return[name, svr.server, "\n".join(svr.mock_server)]

connections = ConnectionRepository()
output_format = validate_output_format(context.output_format, 'TABLE')

# build the table structure
Expand All @@ -585,34 +600,33 @@ def cmd_connection_list(context):
cc = cur_sym if is_current_connection(svr, context) else ''
dc = dflt_sym if is_default_connection(svr) else ''
name = '{}{}{}'.format(cc, dc, name)
row = [name, svr.server, svr.default_namespace, svr.user,
svr.timeout, svr.use_pull, svr.verify, svr.certfile,
svr.keyfile, "\n".join(svr.mock_server)]
rows.append(row)

rows.append(build_row(options, name, svr))

# add current connection if not in persistent connections
current_connection = context.pywbem_server or None

if current_connection:
cname = current_connection.name
if cname not in connections:
cname = '{}{}'.format('*', cname)
svr = current_connection
rows.append([cname, svr.server, svr.default_namespace, svr.user,
svr.timeout, svr.use_pull, svr.verify, svr.certfile,
svr.keyfile, "\n".join(svr.mock_server)])
rows.append(build_row(options, cname, svr))

# NOTE: Does not show ca_certs because that creates a very big table
# in particular if you use the default.
headers = ['name', 'server', 'namespace', 'user',
'timeout', 'use_pull', 'verify', 'certfile', 'keyfile',
'mock-server']

headers, rows = hide_empty_columns(headers, rows)
if options['full']:
headers = ['name', 'server', 'namespace', 'user',
'timeout', 'use_pull', 'verify', 'certfile', 'keyfile',
'mock-server']
else:
headers = ['name', 'server', 'mock-server']

context.spinner_stop()
table_type = 'full' if options['full'] else 'brief'
click.echo(format_table(
sorted(rows),
headers,
title='WBEM server connections: ({}: default, {}: current)'.format(
dflt_sym, cur_sym),
title='WBEM server connections({}): ({}: default, {}: current)'.format(
table_type, dflt_sym, cur_sym),
table_format=output_format))
78 changes: 58 additions & 20 deletions tests/unit/test_connection_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
CONNECTION_LIST_HELP_LINES = [
'Usage: pywbemcli [GENERAL-OPTIONS] connection list [COMMAND-OPTIONS]',
'List the WBEM connection definitions.',
'-f, --full If set, display the full table. Otherwise display a brief',
CMD_OPTION_HELP_HELP_LINE,
]

Expand Down Expand Up @@ -224,7 +225,7 @@
{'general': ['-o', 'simple'],
'args': ['list']},
{'stdout': [
"WBEM server connections:", ""],
"WBEM server connections(brief):", ""],
'test': 'innows'},
None, OK],

Expand Down Expand Up @@ -327,13 +328,16 @@
['Verify connection command list with 2 servers defined',
{'general': ['--output-format', 'plain'],
'args': ['list']},
{'stdout': ['WBEM server connections:',
'name server namespace user timeout verify',
"test1 http://blah root/cimv2 30 True",
"test2 http://blahblah root/cimv2 fred 18 False"],
{'stdout': ['WBEM server connections(brief): (#: default, *: current)',
'name server mock-server',
'test1 http://blah',
'test2 http://blahblah'],
'test': 'innows'},
None, OK],




['Verify connection command select test2',
['select', 'test2', '--default'],
{'stdout': ['test2', 'default'],
Expand Down Expand Up @@ -363,11 +367,45 @@
'next pywbemcli call',
{'general': ['--output-format', 'plain'],
'args': ['list']},
{'stdout': ['WBEM server connections:',
'(#: default, *: current)',
'name server namespace user timeout verify',
'test1 http://blah root/cimv2 30 True',
'*#test2 http://blahblah root/cimv2 fred 18 False', ],
{'stdout': ['WBEM server connections(brief): (#: default, *: current)',
'name server mock-server',
'*#test2 http://blahblah',
'test1 http://blah'],
'test': 'innows'},
None, OK],

['Verify connection command list with 2 servers defined, not sel after '
'next pywbemcli call',
{'general': ['--output-format', 'plain'],
'args': ['list']},
{'stdout': ['WBEM server connections(brief): (#: default, *: current)',
'name server mock-server',
'test1 http://blah',
'test2 http://blahblah'],
'test': 'innows'},
None, OK],

['Verify connection command list with 2 servers defined, not sel after '
'next pywbemcli call --full',
{'general': ['--output-format', 'plain'],
'args': ['list', '--full']},
{'stdout': ['WBEM server connections(full): (#: default, *: current)',
'name server namespace user timeout use_pull verify '
'certfile keyfile mock-server',
'*#test2 http://blahblah root/cimv2 fred 18 False',
'test1 http://blah root/cimv2 30 True'],
'test': 'innows'},
None, OK],

['Verify connection command list with 2 servers defined, not sel after '
'next pywbemcli call -f',
{'general': ['--output-format', 'plain'],
'args': ['list', '-f']},
{'stdout': ['WBEM server connections(full): (#: default, *: current)',
'name server namespace user timeout use_pull verify '
'certfile keyfile mock-server',
'*#test2 http://blahblah root/cimv2 fred 18 False',
'test1 http://blah root/cimv2 30 True'],
'test': 'innows'},
None, OK],

Expand Down Expand Up @@ -395,7 +433,7 @@
{'general': ['-o', 'simple'],
'args': ['list']},
{'stdout': [
"WBEM server connections:", ""],
"WBEM server connections(brief):", ""],
'test': 'innows',
'file': {'before': 'none', 'after': 'none'}},
None, OK],
Expand Down Expand Up @@ -741,8 +779,8 @@
['Verify connection list with current server from general options, plain',
{'args': ['list'],
'general': ['--server', 'http://blah', '--output-format', 'plain']},
{'stdout': ['WBEM server connections: (#: default, *: current)',
'*not-saved http://blah root/cimv2 30 True'],
{'stdout': ['WBEM server connections(brief): (#: default, *: current)',
'*not-saved http://blah'],
'test': 'innows',
'file': {'before': 'none', 'after': 'none'}},
None, OK],
Expand All @@ -767,13 +805,13 @@
{'args': ['list'],
'general': ['--output-format', 'table', '--server', 'http://blah']},
{'stdout': """
WBEM server connections: (#: default, *: current)
+------------+-------------+-------------+-----------+----------+
| name | server | namespace | timeout | verify |
|------------+-------------+-------------+-----------+----------|
| *not-saved | http://blah | root/cimv2 | 30 | True |
| svrtest | http://blah | root/cimv2 | 30 | True |
+------------+-------------+-------------+-----------+----------+
WBEM server connections(brief): (#: default, *: current)
+------------+-------------+---------------+
| name | server | mock-server |
|------------+-------------+---------------|
| *not-saved | http://blah | |
| svrtest | http://blah | |
+------------+-------------+---------------+
""",
'test': 'innows',
'file': {'before': 'exists', 'after': 'exists'}},
Expand Down

0 comments on commit 99e8831

Please sign in to comment.