Skip to content

Commit

Permalink
Fixes issue #1158 mofcomp remove of test.mof fails
Browse files Browse the repository at this point in the history
The first error encountered was that in the rollback logic the instance
paths are not set into instances when they are created locally. This is
because the normal compile with the pyebem mof compiler does not force
this.  We cannot do this by forcing the Alias on every instance created
in the mof to be able to remove it so the solution is to create a new
MOFWBEMConnection adaption that set the path into the mof as it is
created as part of the remove.

Added a test to test_mof_compiler.py to assure that we are propagating
key property qualifiers correctly because that appears to be another
issue in the remove.
  • Loading branch information
KSchopmeyer committed Nov 10, 2019
1 parent 2b0bb14 commit 5e02a1d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 10 deletions.
4 changes: 2 additions & 2 deletions mof_compiler
Expand Up @@ -35,7 +35,7 @@ from getpass import getpass

from pywbem._cliutils import SmartFormatter
from pywbem import WBEMConnection, Error
from pywbem.mof_compiler import MOFWBEMConnection, MOFCompiler
from pywbem.mof_compiler import MOFWBEMConnectionRollback, MOFCompiler
from pywbem.cim_http import get_default_ca_cert_paths
from pywbem import __version__

Expand Down Expand Up @@ -245,7 +245,7 @@ Example:

if args.remove or args.dry_run:

conn_mof = MOFWBEMConnection(conn=conn)
conn_mof = MOFWBEMConnectionRollback(conn=conn)

# Make it simple for this script to use these attributes:
conn_mof.default_namespace = conn.default_namespace
Expand Down
44 changes: 44 additions & 0 deletions pywbem/mof_compiler.py
Expand Up @@ -2256,6 +2256,50 @@ def rollback(self, verbose=False):
# Issue #990: Also roll back changes to qualifier declarations


class MOFWBEMConnectionRollback(MOFWBEMConnection):
"""
A CIM repository connection to an in-memory repository on top of an
underlying repository, adapts MOFWBEMConnection by modifying
CreateInstance to set CIMInstanceName on each created instance from
the properties in the instance. This is required for rollback
because the rollback uses the instance path to tell the server
delete each instance.
This class implements the
:class:`~pywbem.BaseRepositoryConnection` interface.
Raises:
: The methods of this class may raise any exceptions described for
class :class:`~pywbem.WBEMConnection`.
"""
def CreateInstance(self, *args, **kwargs):
"""
Extend CreateInstance to set instancePath on the instance so that
there is a path to be used in rollback.
For a description of the parameters, see
:meth:`pywbem.WBEMConnection.CreateInstance`.
"""

inst = args[0] if args else kwargs['NewInstance']

# If the path or keybindings do not exist, create the path from
# the class and instance and set it into NewInstance
if not inst.path or not inst.path.keybindings:

cls = self.GetClass(inst.classname,
LocalOnly=False,
IncludeQualifiers=True)
inst.path = CIMInstanceName.from_instance(cls, inst)
try:
self.instances[self.default_namespace].append(inst)
except KeyError: # default_namespace does not exist. Create it
self.instances[self.default_namespace] = [inst]

return inst.path


def _print_logger(msg):
"""Print the `msg` parameter to stdout."""
print(msg)
Expand Down
13 changes: 5 additions & 8 deletions tests/unittest/pywbem/test.mof
Expand Up @@ -37,17 +37,17 @@ instance of PyWBEM_PersonCollection as $Collection {
InstanceID = "PersonCollection";
};

instance of PyWBEM_MemberOfPersonCollection {
instance of PyWBEM_MemberOfPersonCollection as $MemOf1 {
Collection = $Collection;
Member = $Alice;
};

instance of PyWBEM_MemberOfPersonCollection {
instance of PyWBEM_MemberOfPersonCollection as $MemOf2 {
Collection = $Collection;
Member = $Bob;
};

instance of PyWBEM_MemberOfPersonCollection {
instance of PyWBEM_MemberOfPersonCollection as $MemOf3 {
Collection = $Collection;
Member = $Charlie;
};
Expand Down Expand Up @@ -160,11 +160,8 @@ instance of PyWBEM_AllTypes {
arraySint32 = {0, -9999};
arrayUint64 = {0, 99999};
arraySint64 = {-99999, 0, 99999};
arrayReal32 = {0, 1.9};
arrayReal64 = {0, 1.9};
arrayReal32 = {1.1, 1.9};
arrayReal64 = {1.2345, 1.9};
arrayString = {"This is a test string", "Second String"};
arrayDateTime = {"19991224120000.000000+360", "19991224120000.000000+360"};
};



6 changes: 6 additions & 0 deletions tests/unittest/pywbem/test_mof_compiler.py
Expand Up @@ -338,6 +338,12 @@ def test_testmof(self):
LocalOnly=False, IncludeQualifiers=True)
self.assertEqual(ccs.properties['Member'].type, 'reference')

ccs = self.mofcomp.handle.GetClass(
'PyWBEM_PersonCollection',
LocalOnly=False, IncludeQualifiers=True)
self.assertEqual(ccs.properties['InstanceID'].type, 'string')
self.assertTrue('Key' in ccs.properties['InstanceID'].qualifiers)

# get the instances
insts = self.mofcomp.handle.instances[NAME_SPACE]

Expand Down

0 comments on commit 5e02a1d

Please sign in to comment.