Skip to content

Commit

Permalink
Change mof_compiler and test_mof_compiler from
Browse files Browse the repository at this point in the history
using args[0] and args[1] in CIMError references
to use status_code and status_description.

Add to changes.rst
  • Loading branch information
KSchopmeyer authored and andy-maier committed Apr 24, 2018
1 parent 8b40400 commit d6c6035
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ Released: not yet

* Resolved several Pylint issues, including several fixes (Issue #1206).

* Cleanup mof_compiler use of args[0] and args[1] with CIMError. (Issue #1221)

**Known issues:**

* See `list of open issues`_.
Expand Down
43 changes: 24 additions & 19 deletions pywbem/mof_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def _create_ns(p, handle, ns):
if 'PG_InterOp' in inames:
cimom_type = 'pegasus'
except CIMError as ce:
if ce.args[0] != CIM_ERR_NOT_FOUND:
if ce.status_code != CIM_ERR_NOT_FOUND:
ce.file_line = (p.parser.file, p.lexer.lineno)
raise
if not cimom_type:
Expand Down Expand Up @@ -527,7 +527,7 @@ def _create_ns(p, handle, ns):
try:
handle.CreateInstance(inst)
except CIMError as ce:
if ce.args[0] != CIM_ERR_ALREADY_EXISTS:
if ce.status_code != CIM_ERR_ALREADY_EXISTS:
ce.file_line = (p.parser.file, p.lexer.lineno)
raise

Expand Down Expand Up @@ -564,7 +564,7 @@ def p_mp_createClass(p):
break
except CIMError as ce:
ce.file_line = (p.parser.file, p.lexer.lineno)
errcode = ce.args[0]
errcode = ce.status_code
if errcode == CIM_ERR_INVALID_NAMESPACE:
if fixedNS:
raise
Expand Down Expand Up @@ -643,7 +643,7 @@ def p_mp_createClass(p):
(cc.classname, ns, cln))
p.parser.mofcomp.compile_file(moffile, ns)
except CIMError as ce:
if ce.args[0] == CIM_ERR_NOT_FOUND:
if ce.status_code == CIM_ERR_NOT_FOUND:
raise err
else:
raise
Expand All @@ -654,15 +654,15 @@ def p_mp_createClass(p):

except CIMError as ce:
ce.file_line = (p.parser.file, p.lexer.lineno)
if ce.args[0] != CIM_ERR_ALREADY_EXISTS:
if ce.status_code != CIM_ERR_ALREADY_EXISTS:
raise
if p.parser.verbose:
p.parser.log('Class %s already exist. Modifying...' % cc.classname)
try:
p.parser.handle.ModifyClass(cc, ns)
except CIMError as ce:
p.parser.log('Error Modifying class %s: %s, %s' %
(cc.classname, ce.args[0], ce.args[1]))
(cc.classname, ce.status_code, ce.status_description))


def p_mp_createInstance(p):
Expand All @@ -673,14 +673,14 @@ def p_mp_createInstance(p):
try:
p.parser.handle.CreateInstance(inst)
except CIMError as ce:
if ce.args[0] == CIM_ERR_ALREADY_EXISTS:
if ce.status_code == CIM_ERR_ALREADY_EXISTS:
if p.parser.verbose:
p.parser.log('Instance of class %s already exist. '
'Modifying...' % inst.classname)
try:
p.parser.handle.ModifyInstance(inst)
except CIMError as ce:
if ce.args[0] == CIM_ERR_NOT_SUPPORTED:
if ce.status_code == CIM_ERR_NOT_SUPPORTED:
if p.parser.verbose:
p.parser.log('ModifyInstance not supported. '
'Deleting instance of %s: %s' %
Expand All @@ -704,14 +704,14 @@ def p_mp_setQualifier(p):
try:
p.parser.handle.SetQualifier(qualdecl)
except CIMError as ce:
if ce.args[0] == CIM_ERR_INVALID_NAMESPACE:
if ce.status_code == CIM_ERR_INVALID_NAMESPACE:
if p.parser.verbose:
p.parser.log('Creating namespace ' + ns)
_create_ns(p, p.parser.handle, ns)
if p.parser.verbose:
p.parser.log('Setting qualifier %s' % qualdecl.name)
p.parser.handle.SetQualifier(qualdecl)
elif ce.args[0] == CIM_ERR_NOT_SUPPORTED:
elif ce.status_code == CIM_ERR_NOT_SUPPORTED:
if p.parser.verbose:
p.parser.log('Qualifier %s already exists. Deleting...' %
qualdecl.name)
Expand Down Expand Up @@ -963,7 +963,7 @@ def p_qualifier(p):
try:
quals = p.parser.handle.EnumerateQualifiers()
except CIMError as ce:
if ce.args[0] != CIM_ERR_INVALID_NAMESPACE:
if ce.status_code != CIM_ERR_INVALID_NAMESPACE:
ce.file_line = (p.parser.file, p.lexer.lineno)
raise
_create_ns(p, p.parser.handle, ns)
Expand Down Expand Up @@ -1621,7 +1621,7 @@ def p_instanceDeclaration(p):
p.parser.classnames[ns].append(cc.classname.lower())
except CIMError as ce:
ce.file_line = (p.parser.file, p.lexer.lineno)
if ce.args[0] == CIM_ERR_NOT_FOUND:
if ce.status_code == CIM_ERR_NOT_FOUND:
file_ = p.parser.mofcomp.find_mof(cname)
if p.parser.verbose:
p.parser.log('Class %s does not exist' % cname)
Expand Down Expand Up @@ -2176,7 +2176,7 @@ def CreateClass(self, *args, **kwargs):
_ = self.GetClass(cc.superclass, LocalOnly=True, # noqa: F841
IncludeQualifiers=False)
except CIMError as ce:
if ce.args[0] == CIM_ERR_NOT_FOUND:
if ce.status_code == CIM_ERR_NOT_FOUND:
ce.args = (CIM_ERR_INVALID_SUPERCLASS, cc.superclass)
raise
else:
Expand All @@ -2202,7 +2202,7 @@ def CreateClass(self, *args, **kwargs):
self.GetClass(obj.reference_class, LocalOnly=True,
IncludeQualifiers=True)
except CIMError as ce:
if ce.args[0] == CIM_ERR_NOT_FOUND:
if ce.status_code == CIM_ERR_NOT_FOUND:
raise CIMError(CIM_ERR_INVALID_PARAMETER,
'Class %r referenced by element '
'%r of class %r in namespace '
Expand All @@ -2218,7 +2218,7 @@ def CreateClass(self, *args, **kwargs):
self.GetClass(eiqualifier.value, LocalOnly=True,
IncludeQualifiers=False)
except CIMError as ce:
if ce.args[0] == CIM_ERR_NOT_FOUND:
if ce.status_code == CIM_ERR_NOT_FOUND:
raise CIMError(
CIM_ERR_INVALID_PARAMETER,
'Class %r specified by EmbeddInstance '
Expand Down Expand Up @@ -2313,7 +2313,8 @@ def rollback(self, verbose=False):
self.conn.DeleteInstance(inst.path)
except CIMError as ce:
print('Error deleting instance %s' % inst.path)
print(' %s %s' % (ce.args[0], ce.args[1]))
print(' %s %s' % (ce.status_code,
ce.status_description))
for ns, cnames in self.class_names.items():
self.default_namespace = ns
cnames.reverse()
Expand All @@ -2324,7 +2325,8 @@ def rollback(self, verbose=False):
self.conn.DeleteClass(cname)
except CIMError as ce:
print('Error deleting class %s:%s' % (ns, cname))
print(' %s %s' % (ce.args[0], ce.args[1]))
print(' %s %s' % (ce.status_code,
ce.status_description))
# TODO #990: Also roll back changes to qualifier declarations


Expand Down Expand Up @@ -2480,8 +2482,11 @@ def compile_string(self, mof, ns, filename=None):
else:
self.parser.log('Fatal Error:')

self.parser.log('%s%s' % (_statuscode2string(ce.args[0]),
ce.args[1] and ': ' + ce.args[1] or ''))
description = ':%s' % ce.status_description if \
ce.status_description else ""
self.parser.log('%s%s' % (_statuscode2string(ce.status_code),
description))

raise

def compile_file(self, filename, ns):
Expand Down
11 changes: 6 additions & 5 deletions testsuite/test_mof_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def test_all(self):
NAME_SPACE)
self.fail('Expected exception')
except CIMError as ce:
self.assertEqual(ce.args[0], CIM_ERR_FAILED)
self.assertEqual(ce.status_code, CIM_ERR_FAILED)
self.assertEqual(ce.file_line[0],
os.path.join(TEST_DMTF_CIMSCHEMA_MOF_DIR,
'System',
Expand All @@ -340,7 +340,7 @@ def test_all(self):
NAME_SPACE)
self.fail('Expected exception')
except CIMError as ce:
self.assertEqual(ce.args[0], CIM_ERR_INVALID_SUPERCLASS)
self.assertEqual(ce.status_code, CIM_ERR_INVALID_SUPERCLASS)
self.assertEqual(ce.file_line[0],
os.path.join(
TEST_DMTF_CIMSCHEMA_MOF_DIR,
Expand Down Expand Up @@ -604,7 +604,7 @@ def test_invalid_property(self):
self.mofcomp.compile_string(third_instance, NAME_SPACE)
self.fail('Must fail compile with invalid property name')
except CIMError as ce:
self.assertEqual(ce.args[0], CIM_ERR_INVALID_PARAMETER)
self.assertEqual(ce.status_code, CIM_ERR_INVALID_PARAMETER)

def test_dup_property(self):
"""Test compile of instance with duplicated property fails"""
Expand All @@ -628,7 +628,8 @@ def test_dup_property(self):
self.mofcomp.compile_string(third_instance, NAME_SPACE)
self.fail('Must fail compile with duplicate property name')
except CIMError as ce:
self.assertEqual(ce.args[0], CIM_ERR_INVALID_PARAMETER)
self.assertEqual(ce.status_code,
CIM_ERR_INVALID_PARAMETER)

def test_mismatch_property(self):
"""Test compile of instance with duplicated property fails"""
Expand All @@ -652,7 +653,7 @@ def test_mismatch_property(self):
self.mofcomp.compile_string(third_instance, NAME_SPACE)
self.fail('Must fail compile with mismatch property name')
except CIMError as ce:
self.assertEqual(ce.args[0], CIM_ERR_INVALID_PARAMETER)
self.assertEqual(ce.status_code, CIM_ERR_INVALID_PARAMETER)

# TODO add test for array value in inst, not scalar

Expand Down

0 comments on commit d6c6035

Please sign in to comment.