'Ensure we can extract packages from rpm output.'

def testRpmCmdParser(self):

    parser = linux_cmd_parser.RpmCmdParser()
    content = '\n                        glib2-2.12.3-4.el5_3.1\n                        elfutils-libelf-0.137-3.el5\n                        libgpg-error-1.4-2\n                        keyutils-libs-1.2-1.el5\n                        less-436-9.el5\n                        libstdc++-devel-4.1.2-55.el5\n                        gcc-c++-4.1.2-55.el5\n                        -not-valid.123.el5\n                '
    stderr = 'error:    rpmdbNextIterator:    skipping    h#'
    out = list(parser.Parse('/bin/rpm', ['-qa'], content, stderr, 0, 5, None))
    software = {o.name: o.version for o in out if isinstance(o, rdf_client.SoftwarePackage)}
    anomaly = [o for o in out if isinstance(o, rdf_anomaly.Anomaly)]
    self.assertEqual(7, len(software))
    self.assertEqual(1, len(anomaly))
    expected = {'glib2': '2.12.3-4.el5_3.1', 'elfutils-libelf': '0.137-3.el5', 'libgpg-error': '1.4-2', 'keyutils-libs': '1.2-1.el5', 'less': '436-9.el5', 'libstdc++-devel': '4.1.2-55.el5', 'gcc-c++': '4.1.2-55.el5'}
    self.assertItemsEqual(expected, software)
    self.assertEqual('Broken    rpm    database.', anomaly[0].symptom)
