def updateIface(evt, device, component): """ incremental interface modeling based on events sent here we only consider interface UP or DOWN """ if 'interface' not in evt.component: # for interface only return 0 log.info("event: %s", str(evt)) astate = 'UP' lstate = 'UP' if 'admin state: DOWN' in evt.summary: astate = 'DOWN' if 'link state: DOWN' in evt.summary: lstate = 'DOWN' objmap = ObjectMap( modname='ZenPacks.zenoss.OpenvSwitch.Interface', compname='', data={ 'id': evt.component, 'lstate': lstate, 'astate': astate, }, ) adm = ApplyDataMap(device) adm.applyDataMap(component, objmap) return 1
class TestDellDeviceMap(BaseTestCase): def afterSetUp(self): super(TestDellDeviceMap, self).afterSetUp() self.adm = ApplyDataMap() self.ddmap = DellDeviceMap() self.device = self.dmd.Devices.createInstance('testDevice') def testWin2003Server(self): results = loads( "((dp1\nS'setHWSerialNumber'\np2\nS'DTG4C91'\np3\nsS'setHWProductKey'\np4\nS'PowerEdge 850'\np5\nsS'setOSProductKey'\np6\nS'Microsoft Windows Server 2003, Enterprise Edition'\np7\ns(dtp8\n." ) # Verify that the modeler plugin processes the data properly. om = self.ddmap.process(self.device, results, log) self.assertEquals(om.setHWSerialNumber, 'DTG4C91') self.assertEquals(om.setHWProductKey.args[0], 'PowerEdge 850') self.assertEquals(om.setHWProductKey.args[1], 'Dell') self.assertEquals(om.setOSProductKey.args[0], 'Microsoft Windows Server 2003, Enterprise Edition') self.assertEquals(om.setOSProductKey.args[1], 'Microsoft') # Verify that the data made it into the model properly. self.adm._applyDataMap(self.device, om) self.assertEquals(self.device.getHWSerialNumber(), 'DTG4C91') self.assertEquals(self.device.getHWManufacturerName(), 'Dell') self.assertEquals(self.device.getHWProductName(), 'PowerEdge 850') self.assertEquals(self.device.getOSManufacturerName(), 'Microsoft') self.assertEquals(self.device.getOSProductName(), 'Microsoft Windows Server 2003, Enterprise Edition')
class TestDellDeviceMap(BaseTestCase): def afterSetUp(self): super(TestDellDeviceMap, self).afterSetUp() self.adm = ApplyDataMap() self.ddmap = DellDeviceMap() self.device = self.dmd.Devices.createInstance('testDevice') def testWin2003Server(self): results = loads("((dp1\nS'setHWSerialNumber'\np2\nS'DTG4C91'\np3\nsS'setHWProductKey'\np4\nS'PowerEdge 850'\np5\nsS'setOSProductKey'\np6\nS'Microsoft Windows Server 2003, Enterprise Edition'\np7\ns(dtp8\n.") # Verify that the modeler plugin processes the data properly. om = self.ddmap.process(self.device, results, log) self.assertEquals(om.setHWSerialNumber, 'DTG4C91') self.assertEquals(om.setHWProductKey.args[0], 'PowerEdge 850') self.assertEquals(om.setHWProductKey.args[1], 'Dell') self.assertEquals(om.setOSProductKey.args[0], 'Microsoft Windows Server 2003, Enterprise Edition') self.assertEquals(om.setOSProductKey.args[1], 'Microsoft') # Verify that the data made it into the model properly. self.adm._applyDataMap(self.device, om) self.assertEquals(self.device.getHWSerialNumber(), 'DTG4C91') self.assertEquals(self.device.getHWManufacturerName(), 'Dell') self.assertEquals(self.device.getHWProductName(), 'PowerEdge 850') self.assertEquals(self.device.getOSManufacturerName(), 'Microsoft') self.assertEquals(self.device.getOSProductName(), 'Microsoft Windows Server 2003, Enterprise Edition')
def remote_applyDataMaps(self, device, maps, devclass=None, setLastCollection=False): from Products.DataCollector.ApplyDataMap import ApplyDataMap device = self.getPerformanceMonitor().findDevice(device) adm = ApplyDataMap(self) adm.setDeviceClass(device, devclass) def inner(map): def action(): start_time = time.time() completed= bool(adm._applyDataMap(device, map)) end_time=time.time()-start_time if hasattr(map, "relname"): log.debug("Time in _applyDataMap for Device %s with relmap %s objects: %.2f", device.getId(),map.relname,end_time) elif hasattr(map,"modname"): log.debug("Time in _applyDataMap for Device %s with objectmap, size of %d attrs: %.2f",device.getId(),len(map.items()),end_time) else: log.debug("Time in _applyDataMap for Device %s: %.2f . Could not find if relmap or objmap",device.getId(),end_time) return completed return self._do_with_retries(action) changed = False for map in maps: result = inner(map) changed = changed or result if setLastCollection: self._setSnmpLastCollection(device) return changed
def setApplyDataMapToProxyComponent(self, datamap): mapper = ApplyDataMap() component = DeviceProxyComponent.component_for_proxy_device(self) if not component: LOG.error("Unable to apply datamap to proxy component for %s (component not found)" % self) else: mapper._applyDataMap(component, datamap)
def setApplyDataMapToOpenStackInfrastructureHost(self, datamap): mapper = ApplyDataMap() component = DeviceProxyComponent.component_for_proxy_device(self) if not component: log.error("Unable to apply datamap to proxy component for %s (component not found)" % self) else: mapper._applyDataMap(component, datamap)
def xmlrpc_applyDataMap(self, devName, datamap, relname="", compname="", modname=""): """Apply a datamap passed as a list of dicts through XML-RPC. """ dev = self.dmd.findDevice(devName) adm = ApplyDataMap() adm.applyDataMap(dev, datamap, relname=relname, compname=compname, modname=modname)
def setApplyDataMapToProxyComponent(self, datamap): mapper = ApplyDataMap() component = DeviceProxyComponent.component_for_proxy_device(self) if not component: LOG.error( "Unable to apply datamap to proxy component for %s (component not found)" % self) else: mapper._applyDataMap(component, datamap)
def afterSetUp(self): """Preparation invoked before each test is run.""" super(applyDataMapTests, self).afterSetUp() self.service = ApplyDataMap() self.deviceclass = self.dmd.Devices.createOrganizer("/Test") self.device = self.deviceclass.createInstance("test-device") self.device.setPerformanceMonitor("localhost") self.device.setManageIp("192.0.2.77") self.device.index_object() transaction.commit()
def remote_applyDataMaps(self, device, datamaps): device = self.getPerformanceMonitor().findDevice(device) applicator = ApplyDataMap(self) changed = False for datamap in datamaps: if applicator._applyDataMap(device, datamap): changed = True return changed
def setApplyDataMapToOpenStackInfrastructureHost(self, datamap): mapper = ApplyDataMap() component = DeviceProxyComponent.component_for_proxy_device(self) if not component: log.error( "Unable to apply datamap to proxy component for %s (component not found)" % self) else: mapper._applyDataMap(component, datamap)
def remote_applyDataMaps(self, device, datamaps): """Patching command datasource to add partial remodeling""" from Products.DataCollector.ApplyDataMap import ApplyDataMap device = self.getPerformanceMonitor().findDevice(device) applicator = ApplyDataMap(self) changed = False for datamap in datamaps: if applicator._applyDataMap(device, datamap): changed = True return changed
def remote_applyDataMaps(self, device, datamaps): device_obj = self.getPerformanceMonitor().findDevice(device) if device_obj is None: log.warn("Device '%s' no longer exists. Discarding pending datamaps." % device) return False applicator = ApplyDataMap(self) changed = False for datamap in datamaps: if applicator._applyDataMap(device_obj, datamap): changed = True return changed
class TestInterfaceAliasMap(BaseTestCase): def afterSetUp(self): super(TestInterfaceAliasMap, self).afterSetUp() self.adm = ApplyDataMap() self.iamap = InterfaceAliasMap() self.device = self.dmd.Devices.createInstance('testDevice') def testCisco3560(self): pickle = open( "%s/data/InterfaceAliasMap_cisco3560.pickle" % os.path.dirname(__file__), 'rb') results = load(pickle) pickle.close() # Verify that the modeler plugin processes the data properly. relmap = self.iamap.process(self.device, results, log) relmap_orig = copy.deepcopy(relmap) self.assertEquals(relmap.compname, 'os') self.assertEquals(relmap.relname, 'interfaces') self.assertEquals(len(relmap.maps), 58) om = relmap.maps[0] self.assertEquals(om.id, 'Vl1') self.assertEquals(om.description, 'Description of Vlan1') # Verify that the data made it into the model properly. self.adm.applyDataMap(self.device, relmap) iface = self.device.os.interfaces.Vl1 self.assertEquals(iface.id, 'Vl1') self.assertEquals(iface.description, 'Description of Vlan1') #print( # '\n========================================\n' # ' UPDATE MODEL' # '\n========================================\n' #) # clear old directives relmap = relmap_orig om = relmap.maps[0] # update the device om.description = 'New Description of Vlan1' om._do_not_include = 'ignore me!' self.assertEquals(om.description, 'New Description of Vlan1') self.adm.applyDataMap(self.device, relmap) iface = self.device.os.interfaces.Vl1 self.assertEquals(iface.id, 'Vl1') self.assertEquals(iface.description, 'New Description of Vlan1') self.assertFalse(hasattr(iface, '_do_not_include'))
def updateBridgePort(evt, device, component): """ incremental bridge modeling based on events sent here we only consider delete event We can only incrementally model for delete events, but not for add event. The reason being that for deleting, we only need to know the component name. But for adding, we need to know much more ovsdb-tool show-log would not give us all info needed for adding """ existingBridgeObjects = device.getDeviceComponents(type='OpenvSwitchBridge') bridgeTitleOrIds = [bridge.titleOrId() for bridge in existingBridgeObjects] bridgeIDs = [bridge.id for bridge in existingBridgeObjects] if evt.component not in bridgeTitleOrIds and \ evt.component not in bridgeIDs: # for existing bridge only return 0 log.info("event: %s", str(evt)) bridges = [] compname = '' relname = '' modname = '' if 'del bridge' in evt.summary: relname = 'bridges' modname = 'ZenPacks.zenoss.OpenvSwitch.Bridge' for brdg in existingBridgeObjects: if brdg and evt.component in (brdg.id, brdg.titleOrId()): continue bridges.append(ObjectMap( data={ 'id': brdg.id, 'title': brdg.titleOrId(), 'bridgeId': brdg.uuid, })) relmap = RelationshipMap( objmaps=bridges) if len(bridges) > 0: adm = ApplyDataMap(device) adm.applyDataMap(device, relmap, relname=relname, compname=compname, modname=modname) return 1 else: return 0
def afterSetUp(self): super(TestXen, self).afterSetUp() self.adm = ApplyDataMap() self.plugin = Xen() self.device = self.dmd.Devices.createInstance('testDevice') self.device.guestDevices = [] log.setLevel(logging.ERROR)
def setUp(cls): zope.component.testing.setUp(cls) zope.component.provideAdapter(DefaultTraversable, (None, )) zcml.load_config('testing-noevent.zcml', Products.ZenTestCase) # Silly trickery here. # We create a single TestCase, and share the environment that it creates # across all our ZPLLayeredTestCase (which we have inheriting # from unittest.TestCase instead) if not cls.tc or cls.reset: cls.tc = InitializerTestCase("test_nothing") if isinstance(cls.tc_attributes, dict): for k, v in cls.tc_attributes.iteritems(): setattr(cls.tc, k, v) cls.tc.setUp() cls.tc.dmd.REQUEST = None if cls.yaml_doc: cls.load_yaml() try: from Products.ZenTestCase.BaseTestCase import ( init_model_catalog_for_tests) init_model_catalog_for_tests() except ImportError: pass cls.mapper = ApplyDataMap()
class ApplyDataMapTest(BaseTestCase): def afterSetUp(self): super(ApplyDataMapTest, self).afterSetUp() self.adm = ApplyDataMap() def test_updateObject_encoding(self): for enc in ('ascii', 'latin-1', 'utf-8', 'utf-16'): obj = _obj() obj.zCollectorDecoding = enc objmap = eval(enc.replace('-','')+'_objmap') self.adm._updateObject(obj, objmap) for key in objmap: self.assertEqual(getattr(obj, key), objmap[key].decode(enc)) def test_applyDataMap_relmap(self): dmd = self.dmd class datamap(list): compname = "a/b" relname = "c" class Device(object): def deviceClass(self): return dmd.Devices class dmd: "Used for faking sync()" class _p_jar: @staticmethod def sync(): pass def getObjByPath(self, path): return reduce(getattr, path.split("/"), self) def getId(self): return "testDevice" class a: class b: class c: "The relationship to populate" @staticmethod def objectIdsAll(): "returns the list of object ids in this relationship" return [] self.adm.applyDataMap(Device(), datamap(), datamap.relname, datamap.compname)
def process(evt, device, dmd, txnCommit): (idfunc, mapper) = MAPPERS.get(evt.eventClassKey, (None, None)) if idfunc: evt.component = idfunc(evt) if mapper: datamaps = mapper(device, dmd, evt) if datamaps: adm = ApplyDataMap(device) for datamap in datamaps: # LOG.debug("Applying %s" % datamap) adm._applyDataMap(device, datamap) return len(datamaps) else: return 0
def remote_applyDataMaps(self, device, maps, devclass=None, setLastCollection=False): from Products.DataCollector.ApplyDataMap import ApplyDataMap device = self.getPerformanceMonitor().findDeviceByIdExact(device) adm = ApplyDataMap(self) adm.setDeviceClass(device, devclass) changed = False #with pausedAndOptimizedIndexing(): for map in maps: preadmdata = self.pre_adm_check(map, device) start_time = time.time() if adm._applyDataMap(device, map, commit=False): changed = True end_time = time.time() - start_time changesubject = "device" if changed else "nothing" if hasattr(map, "relname"): log.debug( "Time in _applyDataMap for Device %s with relmap %s objects: %.2f, %s changed.", device.getId(), map.relname, end_time, changesubject) elif hasattr(map, "modname"): log.debug( "Time in _applyDataMap for Device %s with objectmap, size of %d attrs: %.2f, %s changed.", device.getId(), len(map.items()), end_time, changesubject) else: log.debug( "Time in _applyDataMap for Device %s: %.2f . Could not find if relmap or objmap, %s changed.", device.getId(), end_time, changesubject) self.post_adm_process(map, device, preadmdata) if setLastCollection: device.setSnmpLastCollection() return changed
def remote_applyDataMaps(self, device, maps, devclass=None, setLastCollection=False): from Products.DataCollector.ApplyDataMap import ApplyDataMap device = self.getPerformanceMonitor().findDeviceByIdExact(device) adm = ApplyDataMap(self) adm.setDeviceClass(device, devclass) changed = False #with pausedAndOptimizedIndexing(): for map in maps: # make a copy because ApplyDataMap will modify the data map. datamap = copy.deepcopy(map) preadmdata = self.pre_adm_check(datamap, device) start_time = time.time() if adm._applyDataMap(device, datamap, commit=False): changed = True end_time = time.time() - start_time changesubject = "device" if changed else "nothing" if hasattr(datamap, "relname"): log.debug( "Time in _applyDataMap for Device %s with relmap %s objects: %.2f, %s changed.", device.getId(), datamap.relname, end_time, changesubject) elif hasattr(datamap, "modname"): log.debug( "Time in _applyDataMap for Device %s with objectmap, size of %d attrs: %.2f, %s changed.", device.getId(), len(datamap.items()), end_time, changesubject) else: log.debug( "Time in _applyDataMap for Device %s: %.2f . Could not find if relmap or objmap, %s changed.", device.getId(), end_time, changesubject) self.post_adm_process(datamap, device, preadmdata) if setLastCollection: device.setSnmpLastCollection() return changed
def remote_applyDataMaps(self, device, maps, devclass=None, setLastCollection=False): from Products.DataCollector.ApplyDataMap import ApplyDataMap device = self.getPerformanceMonitor().findDevice(device) adm = ApplyDataMap(self) adm.setDeviceClass(device, devclass) def inner(map): def action(): return bool(adm._applyDataMap(device, map)) return self._do_with_retries(action) changed = False for map in maps: result = inner(map) changed = changed or result if setLastCollection: self._setSnmpLastCollection(device) return changed
def setUp(self): super(TestModelOSIPAdmin, self).setUp() self.applyDataMap = ApplyDataMap()._applyDataMap if not self.device: json_filename = os.path.dirname( __file__) + "/data/model/osi_p_admin.json" self.createDevice('testmodelOSIPAdmin', json_filename=json_filename)
def create_device(dmd, zPythonClass, device_id, datamaps): device = dmd.Devices.findDeviceByIdExact(device_id) if not device: deviceclass = dmd.Devices.createOrganizer("/Server/SSH/Linux") deviceclass.setZenProperty("zPythonClass", zPythonClass) device = deviceclass.createInstance(device_id) adm = ApplyDataMap()._applyDataMap [adm(device, datamap) for datamap in datamaps] return device
def create_device(dmd, device_id, data): device = dmd.Devices.findDeviceByIdExact(device_id) if not device: deviceclass = dmd.Devices.createOrganizer(data.get("deviceClass", "/")) deviceclass.setZenProperty("zPythonClass", data.get("zPythonClass", "")) device = deviceclass.createInstance(device_id) adm = ApplyDataMap()._applyDataMap map(lambda x: adm(device, x), data.get("dataMaps", [])) return device
def afterSetUp(self): # needed if this is run directly on the commandline, # since otherwise it will be __main__, and ZPL's afterSetup # will get confused. self.__module__ = 'ZenPacks.zenoss.OpenStackInfrastructure.tests.test_impact' super(TestEventMappings, self).afterSetUp() # Quiet down some noisy logging. # logging.getLogger('zen.OpenStackDeviceProxyComponent').setLevel(logging.ERROR) self._loadEventsData() self.adm = ApplyDataMap() self.queue = ConsolidatingObjectMapQueue() self.clock = 1000.0 def _now(): return self.clock self.queue.now = _now
def remote_applyDataMaps(self, device, maps, devclass=None, setLastCollection=False): from Products.DataCollector.ApplyDataMap import ApplyDataMap device = self.getPerformanceMonitor().findDevice(device) adm = ApplyDataMap(self) adm.setDeviceClass(device, devclass) def inner(map): def action(): start_time = time.time() completed = bool(adm._applyDataMap(device, map)) end_time = time.time() - start_time if hasattr(map, "relname"): log.debug( "Time in _applyDataMap for Device %s with relmap %s objects: %.2f", device.getId(), map.relname, end_time) elif hasattr(map, "modname"): log.debug( "Time in _applyDataMap for Device %s with objectmap, size of %d attrs: %.2f", device.getId(), len(map.items()), end_time) else: log.debug( "Time in _applyDataMap for Device %s: %.2f . Could not find if relmap or objmap", device.getId(), end_time) return completed return self._do_with_retries(action) changed = False for map in maps: result = inner(map) changed = changed or result if setLastCollection: self._setSnmpLastCollection(device) return changed
def afterSetUp(self): super(HBaseModelerPluginsTestCase, self).afterSetUp() dc = self.dmd.Devices.createOrganizer('/Server') self.d = dc.createInstance('hbase.testDevice') self.d.dmd._p_jar = MockJar() self.applyDataMap = ApplyDataMap()._applyDataMap # Mock clear events function. from Products.ZenModel.Device import Device mock = lambda *args, **kwargs: None Device.getClearEvents = mock Device.setClearEvents = mock
def afterSetUp(self): super(TestModeler, self).afterSetUp() self.d = self.dmd.Devices.createInstance('zenoss.RabbitMQ.testDevice') self.applyDataMap = ApplyDataMap()._applyDataMap # Required to prevent erroring out when trying to define viewlets in # ../browser/configure.zcml. import zope.viewlet zcml.load_config('meta.zcml', zope.viewlet) import ZenPacks.zenoss.RabbitMQ zcml.load_config('configure.zcml', ZenPacks.zenoss.RabbitMQ)
def create_device(dmd, zPythonClass, device_id, datamaps): deviceclass = dmd.Devices.createOrganizer("/Test") deviceclass.setZenProperty("zPythonClass", zPythonClass) device = deviceclass.createInstance(device_id) device.setPerformanceMonitor("localhost") device.setManageIp("127.1.2.3") device.index_object() notify(IndexingEvent(device)) adm = ApplyDataMap()._applyDataMap [adm(device, datamap) for datamap in datamaps] for component in device.getDeviceComponentsNoIndexGen(): component.index_object() notify(IndexingEvent(component)) return device
def afterSetUp(self): super(TestModel, self).afterSetUp() dc = self.dmd.Devices.createOrganizer('/CloudStack') dc.setZenProperty('zPythonClass', 'ZenPacks.zenoss.CloudStack.Cloud') self.d = dc.createInstance('zenoss.CloudStack.testDevice') if not ZVersion.VERSION.startswith('3.'): self.d.dmd._p_jar = MockJar() self.applyDataMap = ApplyDataMap()._applyDataMap # Required to prevent erroring out when trying to define viewlets in # ../browser/configure.zcml. import zope.viewlet zcml.load_config('meta.zcml', zope.viewlet) import ZenPacks.zenoss.CloudStack zcml.load_config('configure.zcml', ZenPacks.zenoss.CloudStack)
def afterSetUp(self): super(TestModel, self).afterSetUp() dc = self.dmd.Devices.createOrganizer('/Devices/OpenStack') dc.setZenProperty('zPythonClass', 'ZenPacks.zenoss.OpenStack.Endpoint') dc.setZenProperty('zOpenStackAuthUrl', '') dc.setZenProperty('zOpenstackComputeApiVersion', []) dc.setZenProperty('zOpenStackProjectId', []) dc.setZenProperty('zOpenStackInsecure', []) dc.setZenProperty('zOpenStackRegionName', 'RegionOne') self.d = dc.createInstance('zenoss.OpenStack.testDevice') self.d.setPerformanceMonitor('localhost') self.d.index_object() notify(IndexingEvent(self.d)) self.applyDataMap = ApplyDataMap()._applyDataMap zcml.load_config('configure.zcml', ZenPacks.zenoss.OpenStack) self._loadModelData()
def afterSetUp(self): super(TestModel, self).afterSetUp() # BaseTestCast.afterSetUp already hides transaction.commit. So we also # need to hide transaction.abort. self._transaction_abort = Transaction.abort Transaction.abort = lambda *x: None self.d = self.dmd.Devices.createInstance('zenoss.RabbitMQ.testDevice') if not ZVersion.VERSION.startswith('3.'): self.d.dmd._p_jar = MockJar() self.applyDataMap = ApplyDataMap()._applyDataMap # Required to prevent erroring out when trying to define viewlets in # ../browser/configure.zcml. import zope.viewlet zcml.load_config('meta.zcml', zope.viewlet) import ZenPacks.zenoss.RabbitMQ zcml.load_config('configure.zcml', ZenPacks.zenoss.RabbitMQ)
class ApplyDataMapTest(BaseTestCase): def afterSetUp(self): super(ApplyDataMapTest, self).afterSetUp() self.adm = ApplyDataMap() def test_updateObject_encoding(self): for enc in ('ascii', 'latin-1', 'utf-8', 'utf-16'): obj = _obj() obj.zCollectorDecoding = enc objmap = eval(enc.replace('-','')+'_objmap') self.adm._updateObject(obj, objmap) for key, val in objmap.items(): self.assertEqual(getattr(obj, key), val.decode(enc)) def test_applyDataMap_relmap(self): dmd = self.dmd class datamap(list): compname = "a/b" relname = "c" class Device(object): def deviceClass(self): return dmd.Devices def getPrimaryId(self): return "{}/{}".format(self.deviceClass().getPrimaryId(), self.getId()) class dmd: "Used for faking sync()" class _p_jar: @staticmethod def sync(): pass def getObjByPath(self, path): return reduce(getattr, path.split("/"), self) def getId(self): return "testDevice" class a: class b: class c: "The relationship to populate" @staticmethod def objectIdsAll(): "returns the list of object ids in this relationship" return [] self.adm.applyDataMap(Device(), datamap(), datamap.relname, datamap.compname) def test_applyDataMap_relmapException(self): '''test_applyDataMap_exception is mostly the same as test_applyDataMap_relmap - difference #1: compname is commented out - difference #2: with self.assertRaises(AttributeError) is added ''' dmd = self.dmd class datamap(list): #compname = "a/b" relname = "c" class Device(object): def deviceClass(self): return dmd.Devices class dmd: "Used for faking sync()" class _p_jar: @staticmethod def sync(): pass def getObjByPath(self, path): return reduce(getattr, path.split("/"), self) class a: class b: class c: "The relationship to populate" @staticmethod def objectIdsAll(): "returns the list of object ids in this relationship" return [] with self.assertRaises(AttributeError) as theException: self.adm.applyDataMap(Device(), datamap(), datamap.relname, datamap.compname) self.assertEqual(theException.exception.message, "type object 'datamap' has no attribute 'compname'") def testNoChangeAllComponentsLocked(self): device = self.dmd.Devices.createInstance('testDevice') # Create an IP interface device.os.addIpInterface('eth0', False) iface = device.os.interfaces._getOb('eth0') iface.lockFromDeletion() # Apply a RelMap with no interfaces relmap = RelationshipMap("interfaces", "os", "Products.ZenModel.IpInterface") self.assertFalse(self.adm._applyDataMap(device, relmap)) self.assertEquals(1, len(device.os.interfaces))
def afterSetUp(self): super(TestDellDeviceMap, self).afterSetUp() self.adm = ApplyDataMap() self.ddmap = DellDeviceMap() self.device = self.dmd.Devices.createInstance('testDevice')
def afterSetUp(self): super(ApplyDataMapTest, self).afterSetUp() self.adm = ApplyDataMap()
class ApplyDataMapTest(BaseTestCase): def afterSetUp(self): super(ApplyDataMapTest, self).afterSetUp() self.adm = ApplyDataMap() def test_updateObject_encoding(self): for enc in ('ascii', 'latin-1', 'utf-8', 'utf-16'): obj = _obj() obj.zCollectorDecoding = enc objmap = eval(enc.replace('-', '') + '_objmap') self.adm._updateObject(obj, objmap) for key in objmap: self.assertEqual(getattr(obj, key), objmap[key].decode(enc)) def test_applyDataMap_relmap(self): dmd = self.dmd class datamap(list): compname = "a/b" relname = "c" class Device(object): def deviceClass(self): return dmd.Devices class dmd: "Used for faking sync()" class _p_jar: @staticmethod def sync(): pass def getObjByPath(self, path): return reduce(getattr, path.split("/"), self) def getId(self): return "testDevice" class a: class b: class c: "The relationship to populate" @staticmethod def objectIdsAll(): "returns the list of object ids in this relationship" return [] self.adm.applyDataMap(Device(), datamap(), datamap.relname, datamap.compname) def test_applyDataMap_relmapException(self): '''test_applyDataMap_exception is mostly the same as test_applyDataMap_relmap - difference #1: compname is commented out - difference #2: with self.assertRaises(AttributeError) is added ''' dmd = self.dmd class datamap(list): #compname = "a/b" relname = "c" class Device(object): def deviceClass(self): return dmd.Devices class dmd: "Used for faking sync()" class _p_jar: @staticmethod def sync(): pass def getObjByPath(self, path): return reduce(getattr, path.split("/"), self) class a: class b: class c: "The relationship to populate" @staticmethod def objectIdsAll(): "returns the list of object ids in this relationship" return [] with self.assertRaises(AttributeError) as theException: self.adm.applyDataMap(Device(), datamap(), datamap.relname, datamap.compname) self.assertEqual(theException.exception.message, "type object 'datamap' has no attribute 'compname'") def testNoChangeAllComponentsLocked(self): device = self.dmd.Devices.createInstance('testDevice') # Create an IP interface device.os.addIpInterface('eth0', False) iface = device.os.interfaces._getOb('eth0') iface.lockFromDeletion() # Apply a RelMap with no interfaces relmap = RelationshipMap("interfaces", "os", "Products.ZenModel.IpInterface") self.assertFalse(self.adm._applyDataMap(device, relmap)) self.assertEquals(1, len(device.os.interfaces))
class TestEventMappings(zenpacklib.TestCase): disableLogging = False _eventData = None _eventsloaded = False def afterSetUp(self): # needed if this is run directly on the commandline, # since otherwise it will be __main__, and ZPL's afterSetup # will get confused. self.__module__ = 'ZenPacks.zenoss.OpenStackInfrastructure.tests.test_impact' super(TestEventMappings, self).afterSetUp() # Quiet down some noisy logging. # logging.getLogger('zen.OpenStackDeviceProxyComponent').setLevel(logging.ERROR) self._loadEventsData() self.adm = ApplyDataMap() self.queue = ConsolidatingObjectMapQueue() self.clock = 1000.0 def _now(): return self.clock self.queue.now = _now def _loadEventsData(self): if self._eventsloaded: return with open(os.path.join(os.path.dirname(__file__), 'data', 'eventdata.json')) as json_file: self._eventData = json.load(json_file) for event in self._eventData.values(): event['openstack_event_type'] = \ re.sub(r'^openstack-', '', event.get('eventClassKey', '')) if self._eventData: self._eventsloaded = True def model_data(self): if not hasattr(self, '_model_data'): self._model_data = create_model_data(self.dmd) return self._model_data def endpoint(self): ''' Return a OpenStackInfrastructureEndpoint populated in a suitable way for Impact testing. ''' return self.model_data()['endpoint'] def getObjByPath(self, path): try: return self.endpoint().getObjByPath(path) except NotFound: return None def process_event(self, evt): objmap = map_event(evt) if objmap: self.adm._applyDataMap(self.endpoint(), objmap) def test_instance_creation(self): self.assertTrue(self._eventsloaded) self.process_event(self._eventData['scheduler.run_instance.end']) self.process_event(self._eventData['compute.instance.create.start']) self.process_event(self._eventData['compute.instance.create.end']) instance5 = self.getObjByPath('components/server-instance5') self.assertIsNotNone(instance5, msg="Incremental model created instance 'instance5'") self.assertTrue(instance5.publicIps is None or instance5.publicIps == []) self.assertTrue(instance5.privateIps is None or instance5.privateIps == []) evt = self._eventData['compute.instance.create.end'] # json would not allow evt.trait_fixed_ips to be a string # but events.py requires it to be a string evt['trait_fixed_ips'] = str(evt['trait_fixed_ips']) self.process_event(evt) self.assertTrue(instance5.privateIps == [u'172.24.4.229']) self.assertTrue(instance5.publicIps is None or instance5.publicIps == []) def _create_instance5(self): self.assertTrue(self._eventsloaded) # # Dummy up the instance (as if test_instance_creation had run, and we had instance5 in the system) from ZenPacks.zenoss.OpenStackInfrastructure.tests.utils import addContained, addNonContained from ZenPacks.zenoss.OpenStackInfrastructure.Instance import Instance instance1 = self.getObjByPath('components/instance1') instance5 = self.getObjByPath('components/server-instance5') self.assertIsNotNone(instance1, msg="Instance1 is missing from the model!") self.assertIsNone(instance5, msg="Instance5 is already present in model!") instance5 = addContained(self.endpoint(), "components", Instance("server-instance5")) instance5.title = u'instance5' instance5.hostName = 'instance5' instance5.resourceId = u'instance5' instance5.serverId = u'instance5' instance5.serverStatus = u'ACTIVE' addNonContained(instance5, "flavor", instance1.flavor()) addNonContained(instance5, "image", instance1.image()) addNonContained(instance5, "hypervisor", instance1.hypervisor()) addNonContained(instance5, "tenant", instance1.tenant()) return instance5 def test_instance_power_off(self): self.assertTrue(self._eventsloaded) self._create_instance5() instance5 = self.getObjByPath('components/server-instance5') self.assertIsNotNone(instance5) self.process_event(self._eventData['compute.instance.power_off.start']) self.process_event(self._eventData['compute.instance.power_off.end']) self.assertTrue(instance5.serverStatus == 'shutoff') self.assertTrue(instance5.vmState == 'stopped') self.assertTrue(instance5.powerState == 'shutdown') def test_instance_power_on(self): self.assertTrue(self._eventsloaded) self._create_instance5() instance5 = self.getObjByPath('components/server-instance5') self.assertIsNotNone(instance5) instance5.serverStatus = 'shutoff' self.assertTrue(instance5.serverStatus == 'shutoff') self.process_event(self._eventData['compute.instance.power_on.start']) self.process_event(self._eventData['compute.instance.power_on.end']) self.assertTrue(instance5.serverStatus == 'active') self.assertTrue(instance5.powerState == 'running') def test_instance_reboot(self): self.assertTrue(self._eventsloaded) self._create_instance5() instance5 = self.getObjByPath('components/server-instance5') self.assertIsNotNone(instance5) self.process_event(self._eventData['compute.instance.reboot.start']) self.process_event(self._eventData['compute.instance.reboot.end']) self.assertTrue(instance5.serverStatus == 'active') def test_instance_rebuild(self): self.assertTrue(self._eventsloaded) self._create_instance5() instance5 = self.getObjByPath('components/server-instance5') self.assertIsNotNone(instance5) self.process_event(self._eventData['compute.instance.rebuild.start']) self.process_event(self._eventData['compute.instance.power_off.start']) self.process_event(self._eventData['compute.instance.power_off.end']) self.process_event(self._eventData['compute.instance.rebuild.end']) def test_instance_suspend_resume(self): self.assertTrue(self._eventsloaded) self._create_instance5() instance5 = self.getObjByPath('components/server-instance5') self.assertIsNotNone(instance5) self.process_event(self._eventData['compute.instance.suspend']) self.assertTrue(instance5.serverStatus == 'suspended') self.assertTrue(instance5.powerState == 'suspended') self.process_event(self._eventData['compute.instance.resume']) self.assertTrue(instance5.serverStatus == 'active') self.assertTrue(instance5.powerState == 'running') def test_instance_delete(self): self.assertTrue(self._eventsloaded) self._create_instance5() instance5 = self.getObjByPath('components/server-instance5') self.assertIsNotNone(instance5) self.process_event(self._eventData['compute.instance.delete.start']) self.process_event(self._eventData['compute.instance.shutdown.start']) self.process_event(self._eventData['compute.instance.shutdown.end']) self.process_event(self._eventData['compute.instance.delete.end']) instance5 = self.getObjByPath('components/server-instance5') self.assertIsNone(instance5) def test_instance_rescue_unrescue(self): self.assertTrue(self._eventsloaded) self._create_instance5() instance5 = self.getObjByPath('components/server-instance5') self.assertIsNotNone(instance5) self.process_event(self._eventData['compute.instance.rescue.start']) self.process_event(self._eventData['compute.instance.exists']) self.process_event(self._eventData['compute.instance.rescue.end']) self.assertTrue(instance5.vmState == 'rescued') self.assertTrue(instance5.serverStatus == 'rescue') self.process_event(self._eventData['compute.instance.unrescue.start']) self.process_event(self._eventData['compute.instance.unrescue.end']) self.assertTrue(instance5.serverStatus == 'active') def _create_network(self, network_id): self.assertTrue(self._eventsloaded) ''' Build network using events and network_id''' log.info("Create network '%s'" % network_id) self.process_event(self._eventData['network.create.end']) network = self.getObjByPath('components/network-' + network_id) return network def _delete_network(self, network_id): self.assertTrue(self._eventsloaded) ''' Delete network using events and network_id''' log.info("Delete network '%s'" % network_id) self.process_event(self._eventData['network.delete.end']) network = self.getObjByPath('components/network-' + network_id) return network def _create_subnet(self, network_id, subnet_id): self.assertTrue(self._eventsloaded) ''' Build subnet_id using events and network_id. The network/network_id must already exist. ''' log.info("Create Subnet '%s'" % subnet_id) self.process_event(self._eventData['subnet.create.end']) subnet = self.getObjByPath('components/subnet-' + subnet_id) return subnet def _delete_subnet(self, subnet_id): self.assertTrue(self._eventsloaded) ''' Delete subnet using events and subnet_id''' log.info("Delete Subnet '%s'" % subnet_id) self.process_event(self._eventData['subnet.delete.end']) subnet = self.getObjByPath('components/subnet-' + subnet_id) return subnet def _create_port(self, network_id, port_id): self.assertTrue(self._eventsloaded) ''' Build port_id using events and network_id. The network/network_id must already exist. ''' log.info("Create port '%s'" % port_id) self.process_event(self._eventData['port.create.end']) port = self.getObjByPath('components/port-' + port_id) return port def _delete_port(self, port_id): self.assertTrue(self._eventsloaded) ''' Delete port using events and port_id''' log.info("Delete port '%s'" % port_id) self.process_event(self._eventData['port.delete.end']) port = self.getObjByPath('components/port-' + port_id) return port def _create_router(self, network_id, subnet_id, router_id): self.assertTrue(self._eventsloaded) ''' Build router_id using events, network_id, subnet_id. The network_id, subnet_id must already exist. ''' log.info("Create router '%s'" % router_id) self.process_event(self._eventData['router.create.end']) router = self.getObjByPath('components/router-' + router_id) return router def _delete_router(self, router_id): self.assertTrue(self._eventsloaded) ''' Delete router using events and router_id''' log.info("Delete router '%s'" % router_id) self.process_event(self._eventData['router.delete.end']) router = self.getObjByPath('components/router-' + router_id) return router def _create_floatingip(self, network_id, router_id, port_id, floatingip_id): self.assertTrue(self._eventsloaded) ''' Build floatingip_id using events, network_id, subnet_id. The network_id, subnet_id must already exist. ''' log.info("Create floatingip '%s'" % floatingip_id) self.process_event(self._eventData['floatingip.create.end']) floatingip = self.getObjByPath('components/floatingip-' + floatingip_id) return floatingip def _delete_floatingip(self, floatingip_id): self.assertTrue(self._eventsloaded) ''' Delete floatingip using events and floatingip_id''' log.info("Delete floatingip '%s'" % floatingip_id) self.process_event(self._eventData['floatingip.delete.end']) floatingip = self.getObjByPath('components/floatingip-' + floatingip_id) return floatingip def test_network(self): ''' Test Creation/Deletion of network ''' net = self._create_network("test") self.assertIsNotNone(net, msg="Failure: network doesn't exist!") net = self._delete_network(net.netId) self.assertIsNone(net, msg="Failure: network exists!") def test_subnet(self): ''' Test Creation/Deletion of subnet ''' net = self._create_network("test") self.assertIsNotNone(net, msg="Subnet: network doesn't exist!") subnet = self._create_subnet(net.netId, 'test') self.assertIsNotNone(subnet, msg="Failure: subnet doesn't exist!") subnet = self._delete_subnet(subnet.subnetId) self.assertIsNone(subnet, msg="Failure: subnet exist!") def test_port(self): self.assertTrue(self._eventsloaded) ''' Test Creation/Deletion of port ''' net = self._create_network("test") self.assertIsNotNone(net, msg="CreatePort: network doesn't exist!") port = self._create_port(net.netId, 'test') self.assertIsNotNone(port, msg="CreatePort: port doesn't exist!") port = self._delete_port(port.portId) self.assertIsNone(port, msg="Failure: port exists!") def test_router_and_floatingip(self): self.assertTrue(self._eventsloaded) ''' Test Creation/Deletion of port ''' net = self._create_network("test") subnet = self._create_subnet(net.netId, 'test') port = self._create_port(net.netId, 'test') router = self._create_router(net.netId, subnet.subnetId, 'test') self.assertIsNotNone(router, msg="CreateRouter: router doesn't exist!") f_ip = self._create_floatingip(net.netId, router.routerId, port.portId, 'test') self.assertIsNotNone(f_ip, msg="CreateRouter: FloatingIP doesn't exist!") router = self._delete_router(router.routerId) self.assertIsNone(router, msg="Failure: router exists!") f_ip = self._delete_floatingip(f_ip.floatingipId) self.assertIsNone(f_ip, msg="Failure: floatingip exists!") def _create_volume_start(self, volume_id): self.assertTrue(self._eventsloaded) ''' Build volume_id using events. ''' log.info("Create volume '%s'" % volume_id) self.process_event(self._eventData['volume.create.start']) volume = self.getObjByPath('components/volume-' + volume_id) return volume def _create_volume_end(self, volume_id): self.assertTrue(self._eventsloaded) ''' Build volume_id using events. ''' log.info("Create volume '%s'" % volume_id) self.process_event(self._eventData['volume.create.end']) volume = self.getObjByPath('components/volume-' + volume_id) return volume def _update_volume_start(self, volume_id): self.assertTrue(self._eventsloaded) ''' Build volume_id using events. ''' log.info("Update volume '%s'" % volume_id) self.process_event(self._eventData['volume.update.start']) volume = self.getObjByPath('components/volume-' + volume_id) return volume def _update_volume_end(self, volume_id): self.assertTrue(self._eventsloaded) ''' Build volume_id using events. ''' log.info("Update volume '%s'" % volume_id) self.process_event(self._eventData['volume.update.end']) volume = self.getObjByPath('components/volume-' + volume_id) return volume def _attach_volume_start(self, volume_id): self.assertTrue(self._eventsloaded) ''' Build volume_id using events. ''' log.info("Attach volume '%s'" % volume_id) self.process_event(self._eventData['volume.attach.start']) volume = self.getObjByPath('components/volume-' + volume_id) return volume def _attach_volume_end(self, volume_id): self.assertTrue(self._eventsloaded) ''' Build volume_id using events. ''' log.info("Attach volume '%s'" % volume_id) self.process_event(self._eventData['volume.attach.end']) volume = self.getObjByPath('components/volume-' + volume_id) return volume def _detach_volume_start(self, volume_id): self.assertTrue(self._eventsloaded) ''' Build volume_id using events. ''' log.info("Detach volume '%s'" % volume_id) self.process_event(self._eventData['volume.detach.start']) volume = self.getObjByPath('components/volume-' + volume_id) return volume def _detach_volume_end(self, volume_id): self.assertTrue(self._eventsloaded) ''' Build volume_id using events. ''' log.info("Detach volume '%s'" % volume_id) self.process_event(self._eventData['volume.detach.end']) volume = self.getObjByPath('components/volume-' + volume_id) return volume def _delete_volume_start(self, volume_id): self.assertTrue(self._eventsloaded) ''' Build volume_id using events. ''' log.info("Delete volume '%s'" % volume_id) self.process_event(self._eventData['volume.delete.start']) volume = self.getObjByPath('components/volume-' + volume_id) return volume def _delete_volume_end(self, volume_id): self.assertTrue(self._eventsloaded) ''' Build volume_id using events. ''' log.info("Delete volume '%s'" % volume_id) self.process_event(self._eventData['volume.delete.end']) volume = self.getObjByPath('components/volume-' + volume_id) return volume def _create_volsnapshot_start(self, volsnapshot_id): self.assertTrue(self._eventsloaded) ''' Build volume snapshot using events. ''' log.info("Create volume snapshot '%s'" % volsnapshot_id) self.process_event(self._eventData['volsnapshot.create.start']) volsnapshot = self.getObjByPath('components/volsnapshot-' + volsnapshot_id) return volsnapshot def _create_volsnapshot_end(self, volsnapshot_id): self.assertTrue(self._eventsloaded) ''' Build volume snapshot using events. ''' log.info("Create volume snapshot '%s'" % volsnapshot_id) self.process_event(self._eventData['volsnapshot.create.end']) volsnapshot = self.getObjByPath('components/volsnapshot-' + volsnapshot_id) return volsnapshot def _delete_volsnapshot_start(self, volsnapshot_id): self.assertTrue(self._eventsloaded) ''' Build volume snapshot using events. ''' log.info("Delete volume snapshot '%s'" % volsnapshot_id) self.process_event(self._eventData['volsnapshot.delete.start']) volsnapshot = self.getObjByPath('components/volsnapshot-' + volsnapshot_id) return volsnapshot def _delete_volsnapshot_end(self, volsnapshot_id): self.assertTrue(self._eventsloaded) ''' Build volume snapshot using events. ''' log.info("Delete volume snapshot '%s'" % volsnapshot_id) self.process_event(self._eventData['volsnapshot.delete.end']) volsnapshot = self.getObjByPath('components/volsnapshot-' + volsnapshot_id) return volsnapshot def test_volume_create_end(self): ''' volume create end This event does return a volume object ''' volume = self._create_volume_end('test') self.assertIsNotNone(volume) self.assertEquals(volume.tenant.id, 'tenant') self.assertEquals(volume.id, 'volume-test') self.assertEquals(volume.size, 1) def test_volume_update_start(self): ''' volume update start This event does not return a volume object ''' volume = self._create_volume_end('test') self.assertIsNotNone(volume) volume = self._update_volume_start('test') self.assertIsNotNone(volume) def test_volume_update_end(self): ''' volume update end This event does return a volume object ''' volume = self._create_volume_end('test') self.assertIsNotNone(volume) volume = self._update_volume_end('test') self.assertIsNotNone(volume) self.assertEquals(volume.tenant.id, 'tenant') self.assertEquals(volume.id, 'volume-test') self.assertEquals(volume.size, 2) def test_volume_attach_end(self): ''' volume attach end This event does return a volume object ''' instance5 = self._create_instance5() volume = self._create_volume_end('test') self.assertIsNotNone(volume) self._attach_volume_start('test') self._attach_volume_end('test') self.assertIsNotNone(volume.instance()) self.assertEquals(volume.instance().id, instance5.id) self.assertEquals(volume.tenant.id, 'tenant') self.assertEquals(volume.id, 'volume-test') self.assertEquals(volume.size, 1) self.assertEquals(volume.title, 'test volume') def test_volume_detach_end(self): ''' volume detach end This event does return a volume object ''' self._create_instance5() volume = self._create_volume_end('test') self.assertIsNotNone(volume) self._attach_volume_start('test') self._attach_volume_end('test') self.assertIsNotNone(volume.instance()) self._detach_volume_start('test') self._detach_volume_end('test') self.assertIsNone(volume.instance()) self.assertEquals(volume.tenant.id, 'tenant') self.assertEquals(volume.id, 'volume-test') self.assertEquals(volume.size, 1) self.assertEquals(volume.title, 'test volume') self.assertIsNone(volume.instance()) def test_volume_delete_end(self): ''' volume delete end This event does not return a volume object ''' volume = self._create_volume_end('test') self.assertIsNotNone(volume) volume = self._delete_volume_end('test') self.assertIsNone(volume) def test_volsnapshot_create_end(self): ''' volume snapshot create end This event does return a volume snapshot object ''' volume = self._create_volume_end('test') self.assertIsNotNone(volume) volsnapshot = self._create_volsnapshot_end('test') self.assertIsNotNone(volsnapshot) self.assertEquals(volsnapshot.tenant.id, 'tenant') self.assertEquals(volsnapshot.id, 'volsnapshot-test') def test_volsnapshot_delete_end(self): ''' volsnapshot delete end This event does not return a volsnapshot object ''' volume = self._create_volume_end('test') self.assertIsNotNone(volume) volsnapshot = self._create_volsnapshot_end('test') self.assertIsNotNone(volsnapshot) volsnapshot = self._delete_volsnapshot_end('test') self.assertIsNone(volsnapshot) def test_instance_shortlived(self): self.assertTrue(self._eventsloaded) datamaps = [] self.queue.append(map_event(self._eventData['scheduler.run_instance.end'])) datamaps.extend(self.queue.drain()) self.queue.append(map_event(self._eventData['compute.instance.create.start'])) datamaps.extend(self.queue.drain()) self.clock += 1.0 self.queue.append(map_event(self._eventData['compute.instance.create.end'])) datamaps.extend(self.queue.drain()) self.clock += 1.0 datamaps.extend(self.queue.drain()) self.assertEquals(len(datamaps), 0, "No instances were created early") self.clock += 5.0 self.queue.append(map_event(self._eventData['compute.instance.delete.start'])) datamaps.extend(self.queue.drain()) self.queue.append(map_event(self._eventData['compute.instance.shutdown.start'])) datamaps.extend(self.queue.drain()) self.clock += 1.0 self.queue.append(map_event(self._eventData['compute.instance.shutdown.end'])) datamaps.extend(self.queue.drain()) self.queue.append(map_event(self._eventData['compute.instance.delete.end'])) datamaps.extend(self.queue.drain()) # indeed, there should be no objmaps at all. self.assertEquals(len(datamaps), 0, "No model changes were made") def test_instance_longerlived(self): self.assertTrue(self._eventsloaded) datamaps = [] self.queue.append(map_event(self._eventData['scheduler.run_instance.end'])) datamaps.extend(self.queue.drain()) self.queue.append(map_event(self._eventData['compute.instance.create.start'])) datamaps.extend(self.queue.drain()) self.clock += 1.0 self.queue.append(map_event(self._eventData['compute.instance.create.end'])) datamaps.extend(self.queue.drain()) instance5 = self.getObjByPath('components/server-instance5') self.assertIsNone(instance5, msg="Incremental model deferred creation of instance 'instance5'") self.assertEquals(len(datamaps), 0, "No instances were created early") # allow time for the events to be released self.clock += 120.0 datamaps.extend(self.queue.drain()) self.assertEquals(len(datamaps), 1, "Instance created after sufficient time has passed") self.clock += 5.0 self.queue.append(map_event(self._eventData['compute.instance.delete.start'])) datamaps.extend(self.queue.drain()) self.queue.append(map_event(self._eventData['compute.instance.shutdown.start'])) datamaps.extend(self.queue.drain()) self.clock += 1.0 self.queue.append(map_event(self._eventData['compute.instance.shutdown.end'])) datamaps.extend(self.queue.drain()) self.queue.append(map_event(self._eventData['compute.instance.delete.end'])) datamaps.extend(self.queue.drain()) self.assertTrue( (len(datamaps) == 2 and datamaps[1]._remove), msg="Instance deleted as expected") def test_component_ids(self): self.assertTrue(self._eventsloaded) # When using zOpenStackProcessEventTypes, the event_component_id method # is used to assign a component to the events that we pass on to zenoss. # This test verifies that it can successfully identify these component IDs.component component_id = {} for event_type, evt in self._eventData.iteritems(): component_id[event_type] = event_component_id(evt) self.assertEquals(component_id['compute.instance.create.start'], 'server-instance5') self.assertEquals(component_id['compute.instance.delete.end'], 'server-instance5') self.assertEquals(component_id['compute.instance.delete.start'], 'server-instance5') self.assertEquals(component_id['compute.instance.exists'], 'server-instance5') self.assertEquals(component_id['compute.instance.power_off.end'], 'server-instance5') self.assertEquals(component_id['compute.instance.power_off.start'], 'server-instance5') self.assertEquals(component_id['compute.instance.power_on.end'], 'server-instance5') self.assertEquals(component_id['compute.instance.power_on.start'], 'server-instance5') self.assertEquals(component_id['compute.instance.reboot.end'], 'server-instance5') self.assertEquals(component_id['compute.instance.reboot.start'], 'server-instance5') self.assertEquals(component_id['compute.instance.rebuild.end'], 'server-instance5') self.assertEquals(component_id['compute.instance.rebuild.start'], 'server-instance5') self.assertEquals(component_id['compute.instance.rescue.end'], 'server-instance5') self.assertEquals(component_id['compute.instance.rescue.start'], 'server-instance5') self.assertEquals(component_id['compute.instance.resume'], 'server-instance5') self.assertEquals(component_id['compute.instance.shutdown.end'], 'server-instance5') self.assertEquals(component_id['compute.instance.shutdown.start'], 'server-instance5') self.assertEquals(component_id['compute.instance.suspend'], 'server-instance5') self.assertEquals(component_id['compute.instance.unrescue.end'], 'server-instance5') self.assertEquals(component_id['compute.instance.unrescue.start'], 'server-instance5') self.assertEquals(component_id['floatingip.create.end'], 'floatingip-test') self.assertEquals(component_id['floatingip.delete.end'], 'floatingip-test') self.assertEquals(component_id['network.create.end'], 'network-test') self.assertEquals(component_id['network.delete.end'], 'network-test') self.assertEquals(component_id['port.create.end'], 'port-test') self.assertEquals(component_id['port.delete.end'], 'port-test') self.assertEquals(component_id['router.create.end'], 'router-test') self.assertEquals(component_id['router.delete.end'], 'router-test') self.assertEquals(component_id['scheduler.run_instance.end'], None) self.assertEquals(component_id['security_group.create.end'], None) self.assertEquals(component_id['security_group.delete.end'], None) self.assertEquals(component_id['subnet.create.end'], 'subnet-test') self.assertEquals(component_id['subnet.delete.end'], 'subnet-test') self.assertEquals(component_id['volsnapshot.create.end'], 'volsnapshot-test') self.assertEquals(component_id['volsnapshot.create.start'], 'volsnapshot-test') self.assertEquals(component_id['volsnapshot.delete.end'], 'volsnapshot-test') self.assertEquals(component_id['volsnapshot.delete.start'], 'volsnapshot-test') self.assertEquals(component_id['volume.attach.end'], 'volume-test') self.assertEquals(component_id['volume.attach.start'], 'volume-test') self.assertEquals(component_id['volume.create.end'], 'volume-test') self.assertEquals(component_id['volume.create.start'], 'volume-test') self.assertEquals(component_id['volume.delete.end'], 'volume-test') self.assertEquals(component_id['volume.delete.start'], 'volume-test') self.assertEquals(component_id['volume.detach.end'], 'volume-test') self.assertEquals(component_id['volume.detach.start'], 'volume-test') self.assertEquals(component_id['volume.update.end'], 'volume-test') self.assertEquals(component_id['volume.update.start'], 'volume-test')
class applyDataMapTests(BaseTestCase): def afterSetUp(self): """Preparation invoked before each test is run.""" super(applyDataMapTests, self).afterSetUp() self.service = ApplyDataMap() self.deviceclass = self.dmd.Devices.createOrganizer("/Test") self.device = self.deviceclass.createInstance("test-device") self.device.setPerformanceMonitor("localhost") self.device.setManageIp("192.0.2.77") self.device.index_object() transaction.commit() def test_updateDevice(self): """Test updating device properties.""" DATA = {"rackSlot": "near-the-top"} changed = self.service.applyDataMap(self.device, ObjectMap(DATA)) self.assertTrue(changed, "update Device failed") self.assertEqual("near-the-top", self.device.rackSlot) changed = self.service.applyDataMap(self.device, ObjectMap(DATA)) self.assertFalse(changed, "updateDevice not idempotent") def test_updateDeviceHW(self): """Test updating device.hw properties.""" DATA = { "compname": "hw", "totalMemory": 45097156608, } changed = self.service.applyDataMap(self.device, ObjectMap(DATA)) self.assertTrue(changed, "device.hw not changed by first ObjectMap") self.assertEqual(45097156608, self.device.hw.totalMemory) changed = self.service.applyDataMap(self.device, ObjectMap(DATA)) self.assertFalse(changed, "update is not idempotent") def test_updateComponent_implicit(self): """Test updating a component with implicit _add and _remove.""" # Test implicit add directive DATA = { "id": "eth0", "compname": "os", "relname": "interfaces", "modname": "Products.ZenModel.IpInterface", "speed": 10e9, } changed = self.service.applyDataMap(self.device, ObjectMap(DATA)) self.assertTrue(changed, "update failed") self.assertEqual(1, self.device.os.interfaces.countObjects(), "wrong number of interfaces created by ObjectMap") self.assertEqual(10e9, self.device.os.interfaces.eth0.speed, "eth0.speed not updated by ObjectMap") # Test implicit nochange directive changed = self.service.applyDataMap(self.device, ObjectMap(DATA)) self.assertFalse(changed, "update is not idempotent") def test_updateComponent_addFalse(self): """Test updating a component with _add set to False.""" DATA = { "id": "eth0", "compname": "os", "relname": "interfaces", "modname": "Products.ZenModel.IpInterface", "speed": 10e9, "_add": False, } changed = self.service.applyDataMap(self.device, ObjectMap(DATA)) self.assertFalse(changed, "_add = False resulted in change") self.assertEqual(0, self.device.os.interfaces.countObjects(), "ObjectMap with _add = False created a component") def test_updatedComponent_removeTrue(self): """Test updating a component with _remove or remove set to True.""" for remove_key in ('_remove', 'remove'): DATA = { "id": "eth0", "compname": "os", "relname": "interfaces", remove_key: True, } changed = self.service.applyDataMap(self.device, ObjectMap(DATA)) self.assertFalse(changed, 'update is not idempotent') self.service.applyDataMap( self.device, ObjectMap({ "id": "eth0", "compname": "os", "relname": "interfaces", "modname": "Products.ZenModel.IpInterface", "speed": 10e9, })) self.assertEqual(1, self.device.os.interfaces.countObjects(), 'failed to add object') changed = self.service.applyDataMap(self.device, ObjectMap(DATA)) self.assertTrue(changed, "remove object failed") self.assertEqual(0, self.device.os.interfaces.countObjects(), "failed to remove component") def base_relmap(self): return RelationshipMap(compname="os", relname="interfaces", modname="Products.ZenModel.IpInterface", objmaps=[ ObjectMap({"id": "eth0"}), ObjectMap({"id": "eth1"}), ]) def test_updateRelationship(self): """Test relationship creation.""" changed = self.service.applyDataMap(self.device, self.base_relmap()) self.assertTrue(changed, "relationship creation failed") self.assertEqual( 2, self.device.os.interfaces.countObjects(), "wrong number of interfaces created by first RelationshipMap") def test_updateRelationship_is_idempotent(self): changed = self.service.applyDataMap(self.device, self.base_relmap()) self.assertTrue(changed) self.assertEqual(2, self.device.os.interfaces.countObjects()) changed = self.service.applyDataMap(self.device, self.base_relmap()) self.assertFalse(changed, "RelationshipMap is not idempotent") def test_updateRelationship_remove_object(self): changed = self.service.applyDataMap(self.device, self.base_relmap()) self.assertTrue(changed) self.assertEqual(2, self.device.os.interfaces.countObjects()) rm = self.base_relmap() rm.maps = rm.maps[:1] changed = self.service.applyDataMap(self.device, rm) self.assertTrue(changed, "remove related item failed") self.assertEquals( 1, self.device.os.interfaces.countObjects(), "wrong number of interfaces after trimmed RelationshipMap") def test_updateRelationship_remove_all_objects(self): changed = self.service.applyDataMap(self.device, self.base_relmap()) self.assertTrue(changed) self.assertEqual(2, self.device.os.interfaces.countObjects()) rm = self.base_relmap() rm.maps = [] changed = self.service.applyDataMap(self.device, rm) self.assertTrue(changed, "failed to remove related objects") self.assertEquals( 0, self.device.os.interfaces.countObjects(), "wrong number of interfaces after empty RelationshipMap")
def run(self): with open('model.yaml', 'r') as f: self.model_config = yaml.load(f) self.connect() objmaps = [] for modname, obj_attrs in self.get_model_template("Global"): objmaps.append(ObjectMap(modname=modname, data=obj_attrs)) for controller_num in range(1, self.options.controllers + 1): for modname, obj_attrs in self.get_model_template("Controller"): self.talesEvalAttrs( obj_attrs, num=controller_num, device_name=self.options.device ) objmaps.append(ObjectMap(modname=modname, data=obj_attrs)) for compute_num in range(1, self.options.computes + 1): for modname, obj_attrs in self.get_model_template("Compute"): self.talesEvalAttrs( obj_attrs, num=compute_num, device_name=self.options.device ) objmaps.append(ObjectMap(modname=modname, data=obj_attrs)) for tenant_num in range(3, self.options.tenants + 3): for modname, obj_attrs in self.get_model_template("Tenant"): self.talesEvalAttrs( obj_attrs, num=tenant_num, device_name=self.options.device ) objmaps.append(ObjectMap(modname=modname, data=obj_attrs)) compute_nums = range(1, self.options.computes + 1) tenant_nums = range(3, self.options.tenants + 3) for instance_num in range(1, self.options.instances + 1): for modname, obj_attrs in self.get_model_template("Instance"): tenant_num = tenant_nums[instance_num % self.options.tenants] compute_num = compute_nums[instance_num % self.options.computes] self.talesEvalAttrs( obj_attrs, num=instance_num, device_name=self.options.device, tenant_num=tenant_num, compute_num=compute_num ) objmaps.append(ObjectMap(modname=modname, data=obj_attrs)) device = self.dmd.Devices.OpenStack.Infrastructure.findDevice(self.options.device) if not device: print "Creating OpenStackInfrastructure device %s" % self.options.device device = self.dmd.Devices.OpenStack.Infrastructure.createInstance(self.options.device) device.setPerformanceMonitor('localhost') for controller_num in range(1, self.options.controllers + 1): device_name = "%s_controller%d" % (self.options.device, controller_num) d = self.dmd.Devices.Server.SSH.Linux.NovaHost.findDevice(device_name) if not d: print "Creating controller device %s" % device_name d = self.dmd.Devices.Server.SSH.Linux.NovaHost.createInstance(device_name) d.setZenProperty('zIpServiceMapMaxPort', 32767) for compute_num in range(1, self.options.computes + 1): device_name = "%s_compute%d" % (self.options.device, compute_num) d = self.dmd.Devices.Server.SSH.Linux.NovaHost.findDevice(device_name) if not d: print "Creating compute device %s" % device_name d = self.dmd.Devices.Server.SSH.Linux.NovaHost.createInstance(device_name) d.setZenProperty('zIpServiceMapMaxPort', 32767) relmap = RelationshipMap(relname='components') for objmap in objmaps: relmap.append(objmap) endpoint_om = ObjectMap( modname='ZenPacks.zenoss.OpenStackInfrastructure.Endpoint', data=dict( set_maintain_proxydevices=True ) ) print "Applying datamaps (1/2) (%d objects)" % len(objmaps) adm = ApplyDataMap() adm._applyDataMap(device, relmap) adm._applyDataMap(device, endpoint_om) print "Gathering network information" l3_agent_ids = [x.id for x in device.getDeviceComponents(type="OpenStackInfrastructureNeutronAgent") if x.type == 'L3 agent'] dhcp_agent_ids = [x.id for x in device.getDeviceComponents(type="OpenStackInfrastructureNeutronAgent") if x.type == 'DHCP agent'] all_network_ids = [x.id for x in device.getDeviceComponents(type="OpenStackInfrastructureNetwork")] all_router_ids = [x.id for x in device.getDeviceComponents(type="OpenStackInfrastructureRouter")] all_subnet_ids = [x.id for x in device.getDeviceComponents(type="OpenStackInfrastructureSubnet")] instance_network_ids = [x.id for x in device.getDeviceComponents(type="OpenStackInfrastructureNetwork") if x.ports() and len([y for y in x.ports() if y.instance()])] instance_subnet_ids = [y.id for y in set(chain.from_iterable([x.subnets() for x in device.getDeviceComponents(type="OpenStackInfrastructureNetwork") if x.ports() and len([y for y in x.ports() if y.instance()])]))] objmaps = [] print "Adding L3 Agent Relationships" for agent_id in l3_agent_ids: objmaps.append(ObjectMap( modname="ZenPacks.zenoss.OpenStackInfrastructure.NeutronAgent", compname="components/%s" % agent_id, data=dict( id=agent_id, set_networks=all_network_ids, set_routers=all_router_ids, set_subnets=all_subnet_ids ))) print "Adding DHCP agent Relationships" for agent_id in dhcp_agent_ids: objmaps.append(ObjectMap( modname="ZenPacks.zenoss.OpenStackInfrastructure.NeutronAgent", compname="components/%s" % agent_id, data=dict( id=agent_id, set_networks=instance_network_ids, set_subnets=instance_subnet_ids ))) print "Adding instance <-> hypervisor relationship" hypervisor_instances = defaultdict(list) for instance_num in range(1, self.options.instances + 1): instance_id = "server-%d" % instance_num compute_num = compute_nums[instance_num % self.options.computes] hypervisor_id = "hypervisor-compute%d.1" % compute_num hypervisor_instances[hypervisor_id].append(instance_id) for hypervisor_id, instance_ids in hypervisor_instances.iteritems(): objmaps.append(ObjectMap( modname="ZenPacks.zenoss.OpenStackInfrastructure.Hypervisor", compname="components/%s" % hypervisor_id, data=dict( id=hypervisor_id, set_instances=instance_ids ))) print "Applying datamaps (2/2) (%d objects)" % len(objmaps) adm = ApplyDataMap() for objmap in objmaps: adm._applyDataMap(device, objmap) print "Committing model changes." transaction.commit()
class TestNewDeviceMap(BaseTestCase): def afterSetUp(self): super(TestNewDeviceMap, self).afterSetUp() self.adm = ApplyDataMap() self.ndmap = NewDeviceMap() self.device = self.dmd.Devices.createInstance('testDevice') def testWin2003Server(self): results = loads("((dp1\nS'snmpDescr'\np2\nS'Hardware: x86 Family 15 Model 4 Stepping 9 AT/AT COMPATIBLE - Software: Windows Version 5.2 (Build 3790 Uniprocessor Free)'\np3\nsS'snmpOid'\np4\nS'.1.3.6.1.4.1.311.1.1.3.1.2'\np5\ns(dtp6\n.") # Verify that the modeler plugin processes the data properly. om = self.ndmap.process(self.device, results, log) self.assertEquals(om.setHWProductKey.args[0], '.1.3.6.1.4.1.311.1.1.3.1.2') self.assertEquals(om.setHWProductKey.args[1], 'Microsoft') self.assertEquals(om.setOSProductKey, 'Windows Version 5.2') self.assertEquals(om.snmpDescr, 'Hardware: x86 Family 15 Model 4 Stepping 9 AT/AT COMPATIBLE - Software: Windows Version 5.2 (Build 3790 Uniprocessor Free)') self.assertEquals(om.snmpOid, '.1.3.6.1.4.1.311.1.1.3.1.2') # Verify that the data made it into the model properly. self.adm._applyDataMap(self.device, om) self.assertEquals(self.device.getHWManufacturerName(), 'Microsoft') self.assertEquals(self.device.getHWProductName(), '.1.3.6.1.4.1.311.1.1.3.1.2') self.assertEquals(self.device.getOSManufacturerName(), 'Unknown') self.assertEquals(self.device.getOSProductName(), 'Windows Version 5.2') self.assertEquals(self.device.snmpDescr, 'Hardware: x86 Family 15 Model 4 Stepping 9 AT/AT COMPATIBLE - Software: Windows Version 5.2 (Build 3790 Uniprocessor Free)') self.assertEquals(self.device.snmpOid, '.1.3.6.1.4.1.311.1.1.3.1.2') def testCentOS5Server(self): results = loads("((dp1\nS'snmpDescr'\np2\nS'Linux centos32.damsel.loc 2.6.18-128.1.6.el5 #1 SMP Wed Apr 1 09:19:18 EDT 2009 i686'\np3\nsS'snmpOid'\np4\nS'.1.3.6.1.4.1.8072.3.2.10'\np5\ns(dtp6\n.") # Verify that the modeler plugin processes the data properly. om = self.ndmap.process(self.device, results, log) self.assertEquals(om.setHWProductKey.args[0], '.1.3.6.1.4.1.8072.3.2.10') self.assertEquals(om.setHWProductKey.args[1], 'net snmp') self.assertEquals(om.setOSProductKey, 'Linux 2.6.18-128.1.6.el5') self.assertEquals(om.snmpDescr, 'Linux centos32.damsel.loc 2.6.18-128.1.6.el5 #1 SMP Wed Apr 1 09:19:18 EDT 2009 i686') self.assertEquals(om.snmpOid, '.1.3.6.1.4.1.8072.3.2.10') # Verify that the data made it into the model properly. self.adm._applyDataMap(self.device, om) self.assertEquals(self.device.getHWManufacturerName(), 'net snmp') self.assertEquals(self.device.getHWProductName(), '.1.3.6.1.4.1.8072.3.2.10') self.assertEquals(self.device.getOSManufacturerName(), 'Unknown') self.assertEquals(self.device.getOSProductName(), 'Linux 2.6.18-128.1.6.el5') self.assertEquals(self.device.snmpDescr, 'Linux centos32.damsel.loc 2.6.18-128.1.6.el5 #1 SMP Wed Apr 1 09:19:18 EDT 2009 i686') self.assertEquals(self.device.snmpOid, '.1.3.6.1.4.1.8072.3.2.10') def testSolaris(self): results = loads("((dp1\nS'snmpDescr'\np2\nS'SunOS testHost 5.10 Generic_138889-05 i86pc'\np3\nsS'snmpOid'\np4\nS'.1.3.6.1.4.1.8072.3.2.3'\np5\ns(dtp6\n.") # Verify that the modeler plugin processes the data properly. om = self.ndmap.process(self.device, results, log) # Verify that the data made it into the model properly. self.adm._applyDataMap(self.device, om) self.assertEquals(self.device.getOSManufacturerName(), 'Sun') self.assertEquals(self.device.getOSProductName(), 'SunOS 5.10 Generic_138889-05')
def afterSetUp(self): super(TestCpuMap, self).afterSetUp() self.adm = ApplyDataMap() self.cmap = CpuMap() self.device = self.dmd.Devices.createInstance('testDevice')
class TestCpuMap(BaseTestCase): def afterSetUp(self): super(TestCpuMap, self).afterSetUp() self.adm = ApplyDataMap() self.cmap = CpuMap() self.device = self.dmd.Devices.createInstance('testDevice') def testWin2003Server(self): results = loads("((dp1\n(dp2\nS'deviceTableOid'\np3\n(dp4\nS'11'\np5\n(dp6\nS'_type'\np7\nS'.1.3.6.1.2.1.25.3.1.4'\np8\nsS'_description'\np9\nS'Broadcom NetXtreme Gigabit Ethernet - SecuRemote Miniport'\np10\nssS'10'\np11\n(dp12\ng7\nS'.1.3.6.1.2.1.25.3.1.4'\np13\nsg9\nS'Broadcom NetXtreme Gigabit Ethernet #2 - SecuRemote Miniport'\np14\nssS'13'\np15\n(dp16\ng7\nS'.1.3.6.1.2.1.25.3.1.6'\np17\nsg9\nS'Fixed Disk'\np18\nssS'12'\np19\n(dp20\ng7\nS'.1.3.6.1.2.1.25.3.1.6'\np21\nsg9\nS'D:\\\\'\np22\nssS'15'\np23\n(dp24\ng7\nS'.1.3.6.1.2.1.25.3.1.16'\np25\nsg9\nS'5-Buttons (with wheel)'\np26\nssS'14'\np27\n(dp28\ng7\nS'.1.3.6.1.2.1.25.3.1.13'\np29\nsg9\nS'IBM enhanced (101- or 102-key) keyboard, Subtype=(0)'\np30\nssS'16'\np31\n(dp32\ng7\nS'.1.3.6.1.2.1.25.3.1.17'\np33\nsg9\nS'COM1:'\np34\nssS'1'\n(dp35\ng7\nS'.1.3.6.1.2.1.25.3.1.5'\np36\nsg9\nS'WebEx Document Loader'\np37\nssS'3'\n(dp38\ng7\nS'.1.3.6.1.2.1.25.3.1.5'\np39\nsg9\nS'Lexmark X500 Series'\np40\nssS'2'\n(dp41\ng7\nS'.1.3.6.1.2.1.25.3.1.5'\np42\nsg9\nS'Microsoft XPS Document Writer'\np43\nssS'5'\n(dp44\ng7\nS'.1.3.6.1.2.1.25.3.1.5'\np45\nsg9\nS'HP LaserJet 2100 PCL6'\np46\nssS'4'\n(dp47\ng7\nS'.1.3.6.1.2.1.25.3.1.5'\np48\nsg9\nS'HP LaserJet 3050 Series PCL 6'\np49\nssS'7'\n(dp50\ng7\nS'.1.3.6.1.2.1.25.3.1.4'\np51\nsg9\nS'MS TCP Loopback interface'\np52\nssS'6'\n(dp53\ng7\nS'.1.3.6.1.2.1.25.3.1.3'\np54\nsg9\nS'Intel'\np55\nssS'9'\n(dp56\ng7\nS'.1.3.6.1.2.1.25.3.1.4'\np57\nsg9\nS'VMware Virtual Ethernet Adapter for VMnet1'\np58\nssS'8'\n(dp59\ng7\nS'.1.3.6.1.2.1.25.3.1.4'\np60\nsg9\nS'VMware Virtual Ethernet Adapter for VMnet8'\np61\nssstp62\n.") # Verify that the modeler plugin processes the data properly. relmap = self.cmap.process(self.device, results, log) self.assertEquals(relmap.relname, 'cpus') om = relmap.maps[0] self.assertEquals(om.compname, 'hw') self.assertEquals(om.setProductKey.args[0], 'Intel') self.assertEquals(om.setProductKey.args[1], 'Intel') # Verify that the data made it into the model properly. self.adm._applyDataMap(self.device, relmap) cpu = self.device.hw.cpus()[0] self.assertEquals(cpu.getManufacturerName(), 'Intel') self.assertEquals(cpu.getProductName(), 'Intel') def testCentOS5Server(self): results = loads('((dp1\n(dp2\nS\'deviceTableOid\'\np3\n(dp4\nS\'1025\'\np5\n(dp6\nS\'_type\'\np7\nS\'.1.3.6.1.2.1.25.3.1.4\'\np8\nsS\'_description\'\np9\nS\'network interface lo\'\np10\nssS\'768\'\np11\n(dp12\ng7\nS\'.1.3.6.1.2.1.25.3.1.3\'\np13\nsg9\nS\'GenuineIntel: Intel(R) Core(TM)2 CPU T7400 @ 2.16GHz\'\np14\nssS\'1026\'\np15\n(dp16\ng7\nS\'.1.3.6.1.2.1.25.3.1.4\'\np17\nsg9\nS\'network interface eth0\'\np18\nssS\'1027\'\np19\n(dp20\ng7\nS\'.1.3.6.1.2.1.25.3.1.4\'\np21\nsg9\nS\'network interface sit0\'\np22\nssS\'3072\'\np23\n(dp24\ng7\nS\'.1.3.6.1.2.1.25.3.1.12\'\np25\nsg9\nS"Guessing that there\'s a floating point co-processor"\np26\nssstp27\n.') # Verify that the modeler plugin processes the data properly. relmap = self.cmap.process(self.device, results, log) self.assertEquals(relmap.relname, 'cpus') om = relmap.maps[0] self.assertEquals(om.compname, 'hw') self.assertEquals(om.clockspeed, 2160) self.assertEquals(om.setProductKey.args[0], 'GenuineIntel: Intel(R) Core(TM)2 CPU T7400 @ 2.16GHz') self.assertEquals(om.setProductKey.args[1], 'Intel') # Verify that the data made it into the model properly. self.adm._applyDataMap(self.device, relmap) cpu = self.device.hw.cpus()[0] self.assertEquals(cpu.clockspeed, 2160) self.assertEquals(cpu.getManufacturerName(), 'Intel') self.assertEquals(cpu.getProductName(), 'GenuineIntel_ Intel(R) Core(TM)2 CPU T7400 _ 2.16GHz') def testGetManufacturerAndModel(self): r = getManufacturerAndModel("Unknown CPU Type") self.assertEquals(r.args[0], "Unknown CPU Type") self.assertEquals(r.args[1], "Unknown") r = getManufacturerAndModel("Intel CPU") self.assertEquals(r.args[0], "Intel CPU") self.assertEquals(r.args[1], "Intel") r = getManufacturerAndModel("Xeon") self.assertEquals(r.args[0], "Xeon") self.assertEquals(r.args[1], "Intel") r = getManufacturerAndModel("Opteron Quad-Core") self.assertEquals(r.args[0], "Opteron Quad-Core") self.assertEquals(r.args[1], "AMD")