def getSourcesForCMDB(): # return ["name1", "name2", "name3"] cmdb=SoftwareCMDB(hostname=ComoonicsGlobals.mysqlserver, user=ComoonicsGlobals.mysqluser, password=ComoonicsGlobals.mysqlpassword, database=ComoonicsGlobals.mysqldatabase) clusters=cmdb.getClusters() cmdb.db.close() del cmdb return clusters
def createConverter(source=None, master=None, category=None, where=None, convertertype="coladddiffs/dict"): cmdb=SoftwareCMDB(hostname=ComoonicsGlobals.mysqlserver, user=ComoonicsGlobals.mysqluser, password=ComoonicsGlobals.mysqlpassword, database=ComoonicsGlobals.mysqldatabase) ComoonicsGlobals.mylog.debug("searching for master %s with source %s" %(master, source)) if category: dbsource=Source(dbhandle=cmdb.db) source=dbsource.getSourcesForCategory(category) ComoonicsGlobals.mylog.debug("got %u sources for category %s" %(len(source), category)) if isinstance(source, basestring): source=[source] packages=cmdb.getPackages(source, master, None, 0, 0, where) differences=packages.differences() ComoonicsGlobals.mylog.debug("Searching for converter: %s" %convertertype) converter=getConverter(convertertype)(differences) ComoonicsGlobals.mylog.debug("Got converter: %s" %converter) return converter
class Test(unittest.TestCase): def setUp(self): self.software_cmdb=SoftwareCMDB(hostname="axqad107-1", user="******", password="******", database="software_cmdb", table="software_cmdb") self.packages=self.software_cmdb.getPackages(["lilr642", "lilr602"], "lilr601", None, 0, 0, ['name LIKE "%GFS-kernel%"']) self.differences=self.packages.differences() def tearDown(self): pass def testconvertcolnames(self): self.converter=getConverter("coladdmasterdiffs/dict")(self.differences, "lilr601") self.converter.convert() rescolnames=['source: name', 'name', 'architecture', 'master: version', 'master: subversion', 'source: version', 'source: subversion', "id"] colnames=self.converter.columnnames self.assertEquals(colnames, rescolnames) def testconvert(self): self.converter=getConverter("coladdmasterdiffs/dict")(self.differences, "lilr601") self.converter.convert() rows=self.converter.getvalue() print ",\n".join(map(str, rows)) result=[{'master: subversion': '72.2.0.2', 'name': 'GFS-kernel-debuginfo', 'source: subversion': 'not installed', 'source: name': 'lilr642', 'architecture': 'x86_64', 'source: version': 'not installed', 'id': 'id1', 'master: version': '2.6.9'}, {'master: subversion': '72.2.0.2', 'name': 'GFS-kernel-debuginfo', 'source: subversion': 'not installed', 'source: name': 'lilr602', 'architecture': 'x86_64', 'source: version': 'not installed', 'id': 'id2', 'master: version': '2.6.9'}, {'master: subversion': 'not installed', 'name': 'GFS-kernel-debuginfo', 'architecture': 'x86_64', 'source: name': 'lilr602', 'source: subversion': '80.9.el4_7.5.hotfix.1', 'source: version': '2.6.9', 'id': 'id1', 'master: version': 'not installed'}, {'master: subversion': 'not installed', 'name': 'GFS-kernel-largesmp', 'architecture': 'x86_64', 'source: name': 'lilr642', 'source: subversion': '80.9.el4_7.1', 'source: version': '2.6.9', 'id': 'id2', 'master: version': 'not installed'}, {'master: subversion': '80.9.el4_7.5.hotfix.1', 'name': 'GFS-kernel-largesmp', 'source: subversion': 'not installed', 'source: name': 'lilr642', 'architecture': 'x86_64', 'source: version': 'not installed', 'id': 'id1', 'master: version': '2.6.9'} ] self.assertEquals(rows, result)
class Test(unittest.TestCase): def setUp(self): self.software_cmdb=SoftwareCMDB(hostname="axqad107-1", user="******", password="******", database="software_cmdb", table="software_cmdb") self.packages=self.software_cmdb.getPackages(["lilr642", "lilr602"], "lilr601", None, 0, 0, ['name LIKE "%GFS-kernel%"']) self.differences=self.packages.differences() self.masterreport=MasterReportPackages(self.differences, "lilr601") def tearDown(self): pass def testMasterReport(self): buffer=cStringIO.StringIO() #self.masterreport.report() self.masterreport.report(outputchannel=buffer) print buffer.getvalue() expectedstring=""" source: name name architecture master: version master: subversion source: version source: subversion ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ lilr642 GFS-kernel-debuginfo x86_64 2.6.9 72.2.0.2 not installed not installed lilr602 GFS-kernel-debuginfo x86_64 2.6.9 72.2.0.2 not installed not installed lilr602 GFS-kernel-debuginfo x86_64 not installed not installed 2.6.9 80.9.el4_7.5.hotfix.1 lilr642 GFS-kernel-largesmp x86_64 not installed not installed 2.6.9 80.9.el4_7.1 lilr642 GFS-kernel-largesmp x86_64 2.6.9 80.9.el4_7.5.hotfix.1 not installed not installed ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ """ self.assertEquals(buffer.getvalue(), expectedstring)
class Test(unittest.TestCase): def setUp(self): self.software_cmdb=SoftwareCMDB(hostname="axqad107-1", user="******", password="******", database="software_cmdb", table="software_cmdb") self.packages=self.software_cmdb.getPackages(["lilr642", "lilr602"], "lilr601", None, 0, 0, ['name LIKE "%GFS-kernel%"']) self.differences=self.packages.differences() def tearDown(self): pass def testconvertcolnames(self): self.converter=TableConverter(self.differences) self.converter.convert() rescolnames=['name', 'architecture', 'version', 'subversion', 'lilr601', 'lilr642', 'lilr602'] colnames=self.converter.columnnames self.assertEquals(colnames, rescolnames) def testconvert(self): self.converter=TableConverter(self.differences) self.converter.convert() rows=self.converter.getvalue() #print self.converter.columnnames #print ",\n".join(map(str, rows)) result=[['GFS-kernel-debuginfo', 'x86_64', '2.6.9', '72.2.0.2', 'installed', 'not installed', 'not installed'], ['GFS-kernel-debuginfo', 'x86_64', '2.6.9', '80.9.el4_7.5.hotfix.1', 'not installed', 'not installed', 'installed'], ['GFS-kernel-largesmp', 'x86_64', '2.6.9', '80.9.el4_7.1', 'not installed', 'installed', 'not installed'], ['GFS-kernel-largesmp', 'x86_64', '2.6.9', '80.9.el4_7.5.hotfix.1', 'installed', 'not installed', 'installed']] self.assertEquals(rows, result)
class Test(unittest.TestCase): def setUp(self): self.software_cmdb=SoftwareCMDB(hostname="axqad107-1", user="******", password="******", database="software_cmdb", table="software_cmdb") self.packages=self.software_cmdb.getPackages(["lilr642", "lilr602"], "lilr601", None, 0, 0, ['name LIKE "%GFS-kernel%"']) self.differences=self.packages.differences() self.report=CSVReportPackages(self.differences) def tearDown(self): pass def testReport(self): buffer=cStringIO.StringIO() self.report.report(outputchannel=buffer) print buffer.getvalue() expectedstring=""""name","architecture","version","subversion","lilr601","lilr642","lilr602" "GFS-kernel-debuginfo","x86_64","2.6.9","72.2.0.2","installed","not installed","not installed", "GFS-kernel-debuginfo","x86_64","2.6.9","80.9.el4_7.5.hotfix.1","not installed","not installed","installed", "GFS-kernel-largesmp","x86_64","2.6.9","80.9.el4_7.1","not installed","installed","not installed", "GFS-kernel-largesmp","x86_64","2.6.9","80.9.el4_7.5.hotfix.1","installed","not installed","installed", """ self.assertEquals(buffer.getvalue(), expectedstring)
def setUp(self): self.software_cmdb=SoftwareCMDB(hostname="axqad107-1", user="******", password="******", database="software_cmdb", table="software_cmdb") self.packages=self.software_cmdb.getPackages(["lilr642", "lilr602"], "lilr601", None, 0, 0, ['name LIKE "%GFS-kernel%"']) self.differences=self.packages.differences()
''' def formatRow(_row, _colnames): orderedrow=list() for colname in _colnames: orderedrow.append(str(_row[colname])) return ', '.join(orderedrow) def formatColNames(_row): return ', '.join(_row) from comoonics.cmdb.ComSoftwareCMDB import SoftwareCMDB import logging logging.basicConfig() from comoonics import ComLog ComLog.setLevel(logging.DEBUG) software_cmdb=SoftwareCMDB(hostname="generix4", user="******", password="******", database="hoi_config", table="software_cmdb") result=software_cmdb._getDiffsFromSources(["lilr641", "lilr602"], "lilr601", None, 0, 0, ['name LIKE "%GFS-kernel%"']) print result result=software_cmdb._getDiffsFromSources(["lilr641", "lilr601", "lilr602"], None, None, 0, 0, ['name LIKE "%GFS-kernel%"']) print result #colnames=software_cmdb.getColnamesForMaster() #vrs=software_cmdb.getDiffsFromSourcesByMaster(["lilr641", "lilr602", "lilr621"], "lilr601", colnames, 0, 0, ['name="bash"']) #print vrs #row=vrs.fetch_row(1,1) #select=None #if not colnames: # colnames=row[0].keys() #if not select: # select=colnames #print formatColNames(select)
orderedrow.append(str(_row[colname])) return ', '.join(orderedrow) def formatColNames(_row): return ', '.join(_row) from comoonics.cmdb.ComSoftwareCMDB import SoftwareCMDB import logging logging.basicConfig() from comoonics import ComLog ComLog.setLevel(logging.DEBUG) software_cmdb = SoftwareCMDB(hostname="generix4", user="******", password="******", database="hoi_config", table="software_cmdb") result = software_cmdb._getDiffsFromSources(["lilr641", "lilr602"], "lilr601", None, 0, 0, ['name LIKE "%GFS-kernel%"']) print result result = software_cmdb._getDiffsFromSources(["lilr641", "lilr601", "lilr602"], None, None, 0, 0, ['name LIKE "%GFS-kernel%"']) print result #colnames=software_cmdb.getColnamesForMaster() #vrs=software_cmdb.getDiffsFromSourcesByMaster(["lilr641", "lilr602", "lilr621"], "lilr601", colnames, 0, 0, ['name="bash"']) #print vrs #row=vrs.fetch_row(1,1)
# Import a standard function, and get the HTML request and response objects. from Products.PythonScripts.standard import html_quote request = container.REQUEST RESPONSE = request.RESPONSE from comoonics.cmdb.ComSoftwareCMDB import SoftwareCMDB cmdb=SoftwareCMDB(hostname="mysql-server.gallien.atix", user="******", password="******", database="atix_cmdb") return cmdb.getClusters()
def setUp(self): self.software_cmdb = SoftwareCMDB( hostname="axqad107-1", user="******", password="******", database="software_cmdb", table="software_cmdb" )
class Test(unittest.TestCase): def setUp(self): self.software_cmdb = SoftwareCMDB( hostname="axqad107-1", user="******", password="******", database="software_cmdb", table="software_cmdb" ) def testgetPackages(self): result = self.software_cmdb.getPackages( ["lilr642", "lilr602"], "lilr601", None, 0, 0, ['name LIKE "%GFS-kernel%"'] ) expectedresult = Packages( Package( name="GFS-kernel-largesmp", architecture="x86_64", version="2.6.9", subversion="80.9.el4_7.1", sources=["lilr642"], allsources=["lilr601", "lilr642", "lilr602"], hashlevel=4, ), Package( name="GFS-kernel-debuginfo", architecture="x86_64", version="2.6.9", subversion="80.9.el4_7.5.hotfix.1", sources=["lilr602"], allsources=["lilr601", "lilr642", "lilr602"], hashlevel=4, ), Package( name="GFS-kernel-largesmp", architecture="x86_64", version="2.6.9", subversion="80.9.el4_7.20", sources=["lilr601", "lilr642", "lilr602"], allsources=["lilr601", "lilr642", "lilr602"], hashlevel=4, ), Package( name="GFS-kernel-debuginfo", architecture="x86_64", version="2.6.9", subversion="72.2.0.2", sources=["lilr601"], allsources=["lilr601", "lilr642", "lilr602"], hashlevel=4, ), Package( name="GFS-kernel-largesmp", architecture="x86_64", version="2.6.9", subversion="80.9.el4_7.5.hotfix.1", sources=["lilr601", "lilr602"], allsources=["lilr601", "lilr642", "lilr602"], hashlevel=4, ), ) print repr(result) self.assertEquals(result, expectedresult) def testgetDifferencesMaster(self): expectedresult = Packages( Package( name="GFS-kernel-largesmp", architecture="x86_64", version="2.6.9", subversion="80.9.el4_7.1", sources=["lilr642"], allsources=["lilr601", "lilr642", "lilr602"], hashlevel=4, ), Package( name="GFS-kernel-debuginfo", architecture="x86_64", version="2.6.9", subversion="80.9.el4_7.5.hotfix.1", sources=["lilr602"], allsources=["lilr601", "lilr642", "lilr602"], hashlevel=4, ), Package( name="GFS-kernel-debuginfo", architecture="x86_64", version="2.6.9", subversion="72.2.0.2", sources=["lilr601"], allsources=["lilr601", "lilr642", "lilr602"], hashlevel=4, ), Package( name="GFS-kernel-largesmp", architecture="x86_64", version="2.6.9", subversion="80.9.el4_7.5.hotfix.1", sources=["lilr601", "lilr602"], allsources=["lilr601", "lilr642", "lilr602"], hashlevel=4, ), ) result = self.software_cmdb.getPackages( ["lilr642", "lilr602"], "lilr601", None, 0, 0, ['name LIKE "%GFS-kernel%"'] ) result = result.differences() print repr(result) self.assertEquals(result, expectedresult)