Skip to content

Commit

Permalink
Merge 716f2e6 into 11a2133
Browse files Browse the repository at this point in the history
  • Loading branch information
KSchopmeyer committed Jun 26, 2020
2 parents 11a2133 + 716f2e6 commit 8101400
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
7 changes: 7 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ Released: not yet
* Adjusted to changes in the pywbem mock support for method providers, in the
sample method provider simple_mock_invokemethod_pywbem_V1.py. (See issue #646)

* Fix issue with MOF compile in mocker to account for changes to
pywbem.FakedWBEMConnection in pywbem 1.0.0. Because the pywbem
mocker stopped displaying compile error messages, we modified the
code to display the exceptions for pywbem 1.0 and use the original
display for pre 1.0 pywbem version. (See issue #637)


**Enhancements:**

* Enabled installation using 'setup.py install' from unpacked source distribution
Expand Down
23 changes: 17 additions & 6 deletions pywbemtools/pywbemcli/_pywbemcli_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import traceback
import click

from pywbem import WBEMConnection, MOFParseError
from pywbem import WBEMConnection, Error, MOFParseError
import pywbem_mock

from pywbem import __version__ as PYWBEM_VERSION

from .config import DEFAULT_MAXPULLCNT

# __all__ = ['PYWBEMCLIConnection', 'PYWBEMCLIFakedConnection']
Expand Down Expand Up @@ -316,14 +318,23 @@ def build_repository(conn, server, file_path_list, verbose):
try:
# Displays any MOFParseError already
conn.compile_mof_file(file_path)
except MOFParseError:
except Error as er:
# Abort the entire pywbemcli command because the
# MOF compilation might have caused inconsistencies in the
# mock repository.
click.echo(
"Mock MOF file '{}' failed compiling (see above)".
format(file_path),
err=True)

if not PYWBEM_VERSION.startswith("0"):
# display just the exception.
msg = "MOF compile failed:\n{0}".format(er)
else:
# display file name. Error text displayed already.
if isinstance(er, MOFParseError):
msg = "MOF compile failed: File: '{0}'" \
"(see above)".format(file_path)
else: # not parse error, display exception
msg = "MOF compile failed: File: {0} " \
"Error: {1}".format(file_path, er)
click.echo(msg, err=True)
raise click.Abort()
else:
assert ext == '.py' # already checked
Expand Down
6 changes: 3 additions & 3 deletions pywbemtools/pywbemcli/pywbemcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from prompt_toolkit.history import FileHistory
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory

import pywbem
from pywbem import LOGGER_SIMPLE_NAMES, \
LOG_DESTINATIONS, DEFAULT_LOG_DESTINATION, LOG_DETAIL_LEVELS, \
DEFAULT_LOG_DETAIL_LEVEL
Expand All @@ -43,10 +42,10 @@
DEFAULT_CONNECTION_TIMEOUT, MAX_TIMEOUT, USE_AUTOSUGGEST
from ._connection_repository import ConnectionRepository
from ._click_extensions import PywbemcliTopGroup
from pywbem import __version__ as PYWBEM_VERSION

__all__ = ['cli']

PYWBEM_VERSION = "pywbem, version {}".format(pywbem.__version__)

# Defaults for some options
DEFAULT_VERIFY = True # The default is to verify
Expand Down Expand Up @@ -246,7 +245,8 @@
'Default: EnvVar {ev}, or false.'.
format(ev=PywbemServer.pdb_envvar))
@click.version_option(
message='%(prog)s, version %(version)s\n' + PYWBEM_VERSION,
message='%(prog)s, version %(version)s\npywbem, version {}'.format(
PYWBEM_VERSION),
help='Show the version of this command and the pywbem package.')
@add_options(help_option)
@click.pass_context
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_general_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ class Command group for CIM classes.
{'general': ['-m', BAD_MOF_FILE_PATH],
'cmdgrp': 'class',
'args': ['enumerate']},
{'stderr': ['Mock MOF file', BAD_MOF_FILE_PATH, 'failed compiling',
{'stderr': ['MOF compile failed:',
BAD_MOF_FILE_PATH,
"^^^^^^^^^^" if PYWBEM_1 else "(see above)",
'Aborted!'],
'rc': 1,
'test': 'innows'},
Expand Down

0 comments on commit 8101400

Please sign in to comment.