This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/847/

On September 11th, 2013, 6:45 a.m. UTC, Michal Minar wrote:

And if you'd stick to 80 chars per line, you could even double the lines of code :-).
I'm not a fan of 80 chars per line especially when python code is so strict with indenting. Reformatted some lines though.
I'm not paid by SLOC btw. ;-)

On September 11th, 2013, 6:39 a.m. UTC, Michal Minar wrote:

src/journald/test/TestIterators.py (Diff revision 1)
64
        iter_id = "LMI_JournalMessageLog_CMPI_Iter_9878972#0x7f8504021380#s=a13c10bf472048e69dceeee118cd7f84;i=3;b=5b96431d996a416ebf11dbb6543a5084;m=221f7b;t=4dcc1b6e70a7a;x=b1b572ade816b92e"
Wow, I wonder whether this id is unique enough... :-D
IPv6 address sucks!
The third (largest) part is a standard journald cursor string, unique enough :-)
Each part of the ID has its own role, allowing us to do nice things like session recovery.

On September 11th, 2013, 6:39 a.m. UTC, Michal Minar wrote:

src/journald/test/TestIterators.py (Diff revision 1)
65
        try:
66
            self.wbemconnection.InvokeMethod(MethodName="CancelIteration", ObjectName=inst.path, IterationIdentifier=iter_id)
67
            raise AssertionError("Should not be reached")
68
        except pywbem.CIMError as e:
69
            self.assertTrue(e.args[0] == pywbem.CIM_ERR_INVALID_PARAMETER)
unittest has means even for exception handling:

with self.assertRaises(pywbem.CIMError) as cm:
    func(*args, **kwds)
self.assertEqual(pywbem.CIM_ERR_INVALID_PARAMETER, cm.exception.args[0])

And since this is a common use case in your test, you may save a lot by defining this method:
    def assertRaisesCIM(self, cim_err_code, func, *args, **kwds):
        """
        This test passes if given function called with supplied arguements
        raises pywbem.CIMError with given cim error code.
        """
        with self.assertRaises(pywbem.CIMError) as cm:
            func(*args, **kwds)
        self.assertEqual(cim_err_code, cm.exception.args[0])
resulting in:
    self.assertRaisesCIM(pywbem.CIM_ERR_INVALID_PARAMETER,
        self.wbemconnection.InvokeMethod,
        MethodName="CancelIteration",
        ObjectName=inst.path,
        IterationIdentifier=rfirst['IterationIdentifier'])

Oh nice, I was not aware of such option. Thanks for pointing this out, at least I learned something new.

On September 11th, 2013, 6:39 a.m. UTC, Michal Minar wrote:

src/journald/test/list-journal (Diff revision 1)
3
c = connect("localhost", "pegasus", "heslo")
I know it's a bit more code, but makes it usable elsewhere:
url = os.environ.get('LMI_CIMOM_URL', 'localhost')
username = os.environ.get('LMI_CIMOM_USERNAME', "pegasus")
password = os.environ.get('LMI_CIMOM_PASSWORD', "heslo")
c = connect(url, username, password)
To be honest, I'm not even sure this belongs to openlmi-providers since it requires lmishell to run. It was meant as a very simple example, with planned publishing on the docs page/wiki.

- Tomáš


On September 10th, 2013, 2:32 p.m. UTC, Tomáš Bžatek wrote:

Review request for OpenLMI Developers.
By Tomáš Bžatek.

Updated Sept. 10, 2013, 2:32 p.m.

Repository: openlmi-providers

Description

  journald: Add iterator tests
    
    Tests basic iterator operations, assumes accessible journal and several (> 10)
    records available.
    
    Also comes with a simple example script for downloading complete journal.

--
This is the largest chunk of Python code I've ever written! \o/

Diffs

  • src/journald/test/TestIterators.py (PRE-CREATION)
  • src/journald/test/list-journal (PRE-CREATION)

View Diff