Friday, January 21, 2011

Fixes for compareIntLists(), etc.

Here are fixes for two problems reported by a user...

The first problem, in method compareIntLists(), is significant. This method is used to determine whether one version of WAS is greater than another. The original method has two tests at the bottom, for greater-than and less-than, and both tests returned the same value of 'negative one'. Not good.

 Unfortunately, this bug has been present for several years. If you are using it to steer config options or to select testcases, beware they might change with this fix.

I rewrote the method to be simpler and more understandable than the original, and I tested it well. A complete replacement appears below the jump...


def compareIntLists(a, b):
    """Compares two python lists containing ints.
       Handles arrays of different lengths by padding with zeroes.
       Returns -1 if array a is less than array b. For example,
          [6,0,0,13] < [6,1]
       Returns 0 if they're the same.  For example,
           [7,0] = [7,0,0,0]
       Returns +1 if array a is greater than array b.  For example,
           [8,0,0,12] > [8,0,0,11]
       """
    m = "compareIntLists:"
    sop(m,"Entry. a=%s b=%s" % ( a, b, ))

    # Make both arrays the same length. Pad the smaller array with trailing zeroes.
    while (len(a) < len(b)):
        a.append(0)
    while (len(b) < len(a)):
        b.append(0)

    # Compare each element in the arrays.
    rc = cmp(a,b)

    sop(m,"Exit. Returning %i" % ( rc ))
    return rc


The second problem is a small logging bug in method createProtocolProvider(). The initial logging message has single-quotes and double-quotes mismatched. Here is the original buggy line:

    sop (m, "Create Mail Protocol Provider '+protocol+', if it does not exist")

and here is the fix:

    sop (m, "Create Mail Protocol Provider "+protocol+", if it does not exist")

The python language allows use of single and double quotes for strings, but they must be in matched pairs.


Many thanks to wsadminlib user Bryan for reporting these problems.