Skip to content

Commit

Permalink
Fixes issue # 123 - Consistent return display for no value responses
Browse files Browse the repository at this point in the history
Modifies code so that the commands that do not return any data now
consistently display nothing if not in verbose mode and display some
message about the action or lack of data when --verbose is set.

This modifies the following commands:

- class delete
- instance delete
- instance modify
- class/instance enumerate/associators/references - This is done in the
- common display_cim_objects function when nothing is returned and
  --summary not set.

Adds tests for these changes

Fixes per comments
  • Loading branch information
KSchopmeyer authored and andy-maier committed Dec 20, 2019
1 parent 34b533f commit 660558f
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 14 deletions.
6 changes: 6 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ Released: not yet
any ongoing activities, by setting the env var PYWBEM_SPINNER to 'false',
'0', or the empty string. This is useful when debugging. See issue #465.

* Modified the response handling on commands that may return nothing with
successful response to display a message if the general option --verbose
is defined and display nothing if --verbose not set. This includes
class/instance delete, instance modify and the commands that display
cim objects. (See issue #123)

**Cleanup:**

* Test: Enabled Python warning suppression for PendingDeprecationWarning
Expand Down
21 changes: 10 additions & 11 deletions docs/pywbemcli/generaloptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ Other miscellaneous general options
"""""""""""""""""""""""""""""""""""

The :ref:`--verbose general option` displays extra information about the pywbemcli
internal processing, the :ref:`--version general option` displays pywbemcli version
internal processing.

The :ref:`--version general option` displays pywbemcli version
information and the :ref:`--help general option` provides top level help


Expand Down Expand Up @@ -553,8 +555,9 @@ For details, see :ref:`Output formats`.
--log general option
""""""""""""""""""""

The argument value of the ``--log``/``-l`` general option defines the destination and
parameters of logging of the requests and responses to the WBEM server.
The argument value of the ``--log``/``-l`` general option defines the
destination and parameters of logging of the requests and responses to the WBEM
server.

For details, see :ref:`Pywbemcli defined logging`.

Expand All @@ -567,14 +570,10 @@ For details, see :ref:`Pywbemcli defined logging`.
The ``--verbose``/``-v`` general option is a boolean option that enables the
display of extra information about the processing.


.. _`--version general option`:

--version general option
""""""""""""""""""""""""

The ``--version``/``-V`` general option displays the version of this command
and of the pywbem package it uses, and then exits.
In particular it outputs text for a number of commands that
normally return nothing upon successful execution(ex. instance delete,
instance enumerate that returns no CIM objects) to indicate the successful
command completion.


.. _`--help general option`:
Expand Down
3 changes: 2 additions & 1 deletion pywbemtools/pywbemcli/_cmd_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ def cmd_class_delete(context, classname, options):

try:
context.conn.DeleteClass(classname)
click.echo('{} delete successful'.format(classname))
if context.verbose:
click.echo('Deleted class {}.'.format(classname))
except Error as er:
raise_pywbem_error_exception(er)
4 changes: 3 additions & 1 deletion pywbemtools/pywbemcli/_cmd_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ def cmd_instance_delete(context, instancename, options):
context.conn.DeleteInstance(instancepath)

if context.verbose:
click.echo('Deleted {}'.format(instancepath))
click.echo('Deleted instance {}'.format(instancepath))

except Error as er:
raise_pywbem_error_exception(er)
Expand Down Expand Up @@ -868,6 +868,8 @@ def cmd_instance_modify(context, instancename, options):
try:
context.conn.ModifyInstance(modified_inst,
PropertyList=property_list)
if context.verbose:
click.echo('Modified instance {}'.format(instancepath))
except Error as er:
raise click.ClickException("Server Error modifying instance. "
'Exception: {}: {}'.format
Expand Down
4 changes: 4 additions & 0 deletions pywbemtools/pywbemcli/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,10 @@ def display_cim_objects(context, cim_objects, output_format=None, summary=False,
display_cim_objects_summary(context, cim_objects)
return

if not cim_objects and context.verbose:
click.echo("No objects returned")
return

if sort:
cim_objects = sort_cimobjects(cim_objects)

Expand Down
16 changes: 15 additions & 1 deletion tests/unit/test_class_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,12 @@ class TST_MemberOfFamilyCollection {
'test': 'innows'},
QUALIFIER_FILTER_MODEL, OK],

['Verify instance command enumerate CIM_Foo_sub2, w --verbose rtns msg.',
{'args': ['enumerate', 'CIM_Foo_sub2'],
'general': ['--verbose']},
{'stdout': 'No objects returned',
'test': 'linesnows'},
SIMPLE_MOCK_FILE, OK],

#
# Enumerate errors
Expand Down Expand Up @@ -1010,10 +1016,18 @@ class TST_MemberOfFamilyCollection {
# Class delete successful
['Verify class command delete successful with no subclasses, --force',
['delete', 'CIM_Foo_sub_sub', '--force'],
{'stdout': 'CIM_Foo_sub_sub delete successful',
{'stdout': '',
'test': 'in'},
[SIMPLE_MOCK_FILE], OK],

# Class delete successful
['Verify class command delete successful with no subclasses, --verbose',
{'args': ['delete', 'CIM_Foo_sub_sub', '--force'],
'general': ['--verbose']},
{'stdout': ['Deleted class', 'CIM_Foo_sub_sub'],
'test': 'innows'},
[SIMPLE_MOCK_FILE], OK],

['Verify class command delete fail instances exist',
['delete', 'CIM_Foo_sub_sub'],
{'stderr': 'Delete rejected; instances exist',
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/test_instance_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,20 @@
'test': 'linesnows'},
SIMPLE_MOCK_FILE, OK],

['Verify instance command enumerate CIM_Foo_sub2, rtns nothing,',
{'args': ['enumerate', 'CIM_Foo_sub2'],
'general': []},
{'stdout': "",
'test': 'linesnows'},
SIMPLE_MOCK_FILE, RUN],

['Verify instance command enumerate CIM_Foo_sub2, w --verbose rtns msg.',
{'args': ['enumerate', 'CIM_Foo_sub2'],
'general': ['--verbose']},
{'stdout': 'No objects returned',
'test': 'linesnows'},
SIMPLE_MOCK_FILE, RUN],

['Verify instance command enumerate CIM_Foo with --use-pull yes and '
'--pull-max-cnt=2',
{'args': ['enumerate', 'CIM_Foo', '--include-qualifiers'],
Expand Down Expand Up @@ -1240,6 +1254,15 @@
'test': 'linesnows'},
ALLTYPES_MOCK_FILE, OK],

['Verify instance modify, --verbose',
{'args': ['modify', 'PyWBEM_AllTypes.InstanceID="test_instance"',
'-p', 'scalBool=False'],
'general': ['--verbose']},
{'stdout': ['Modified'],
'rc': 0,
'test': 'innows'},
ALLTYPES_MOCK_FILE, OK],

['Verify instance command modify with --key, single good change',
['modify', 'PyWBEM_AllTypes', '--key', 'InstanceID=test_instance',
'-p', 'scalBool=False'],
Expand Down Expand Up @@ -1428,6 +1451,14 @@
'test': 'lines'},
SIMPLE_MOCK_FILE, OK],

['Verify instance command delete with --key, valid delete, --verbose',
{'args': ['delete', 'CIM_Foo', '--key', 'InstanceID=CIM_Foo1'],
'general': ['--verbose']},
{'stdout': ['Deleted'],
'rc': 0,
'test': 'innows'},
SIMPLE_MOCK_FILE, OK],

['Verify instance command delete, valid delete, explicit ns',
['delete', 'CIM_Foo.InstanceID="CIM_Foo1"', '-n', 'root/cimv2'],
{'stdout': '',
Expand Down

0 comments on commit 660558f

Please sign in to comment.