def test_getManagedDevice(self): self._loadZenossData() host_device1 = self.dmd.Devices.createInstance('host_device1') host_device1.setManageIp('10.208.37.11') host_device1.setPerformanceMonitor('localhost') host_device2 = self.dmd.Devices.createInstance('host_device2') host_device2.setManageIp('12.34.56.78') host_device2.setPerformanceMonitor('localhost') from Products.ZenModel.IpInterface import manage_addIpInterface manage_addIpInterface(host_device2.os.interfaces, 'eth0', False) eth0 = host_device2.os.interfaces._getOb('eth0') eth0.setIpAddresses(['10.208.37.12/24']) zone = self.d.zones._getOb('zone1') pod = zone.pods._getOb('pod1') cluster = pod.clusters._getOb('cluster1') # Test finding host device by manageIp. info1 = IInfo(cluster.hosts._getOb('host1')) self.assertEquals(info1.managed_device.id, 'host_device1') # Test finding host by interface IP. info2 = IInfo(cluster.hosts._getOb('host5')) self.assertEquals(info2.managed_device.id, 'host_device2')
def getZenPackInfos(self, zenpacks=None): zpInfo = {} for zenpack in self._dmd.ZenPackManager.packs(): if zenpacks is None: zpInfo[zenpack.id] = IInfo(zenpack) elif zenpack.id in zenpacks: zpInfo[zenpack.id] = IInfo(zenpack) return zpInfo
def talesEval(express, context, extra=None): """Perform a TALES eval on the express using context. """ try: compiled = talesCompile(express) except Exception as e: compiled = talesCompile("string:%s" % express) contextDict = { 'context': context, 'here': context, 'nothing': None, 'now': DateTime(), } if isinstance(extra, dict): contextDict.update(extra) try: contextDict['info'] = IInfo(context) except TypeError: pass try: res = compiled(getEngine().getContext(contextDict)) except Exception, e: msg = "Error when processing tales expression %s on context %s : Exception Class %s Message: %s" % ( express, context, type(e), e) raise InvalidTalesException(msg)
def testHost(self): self._loadZenossData() zone = self.d.zones._getOb('zone1') pod = zone.pods._getOb('pod1') cluster = pod.clusters._getOb('cluster1') host = cluster.hosts._getOb('host1') self.assertEquals(host.device().id, 'zenoss.CloudStack.testDevice') info = IInfo(host) self.assertEquals(info.entity['name'], 'demo5-xen') self.assertEquals(info.icon, CLOUDSTACK_ICON) self.assertEquals(info.cloudstack_id, 1) self.assertEquals(info.allocation_state, 'Enabled') self.assertEquals(info.host_type, 'Routing') self.assertEquals(info.hypervisor, 'XenServer') self.assertEquals(info.host_version, '2.2.13.20111117191758') self.assertEquals(info.capabilities, 'xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64') self.assertEquals(info.host_state, 'Up') self.assertEquals(info.created, '2011-10-17T21:19:45-0700') self.assertEquals(info.host_tags, '') self.assertEquals(info.ip_address, '10.208.37.11') self.assertEquals(info.host_events, 'ShutdownRequested; AgentDisconnected; AgentConnected; HypervisorVersionChanged; PrepareUnmanaged; HostDown; PingTimeout; ManagementServerDown; StartAgentRebalance; Ping; MaintenanceRequested') self.assertEquals(info.local_storage_active, False) self.assertEquals(info.management_server_id, 257544418526661) self.assertEquals(info.zone.id, 'zone1') self.assertEquals(info.pod.id, 'pod1') self.assertEquals(info.cluster.id, 'cluster1')
def testCloud(self): self._loadZenossData() info = IInfo(self.d) self.assertEquals(info.zone_count, 1) self.assertEquals(info.pod_count, 2) self.assertEquals(info.cluster_count, 2) self.assertEquals(info.host_count, 6)
def _getPasswordFields(self, obj): """ Return fields for obj if it has xtype and it is password. """ fields = IFormBuilder(IInfo(obj)).fields() return [ field for field in fields if fields[field].get('xtype', None) and fields[field].get('xtype') == 'password' ]
def testRabbitMQNode(self): self._loadZenossData() self.assertEquals(self.d.rabbitmq_nodes.countObjects(), 1) info = IInfo(self.d.rabbitmq_nodes()[0]) self.assertEquals(info.vhostCount, 2) self.assertEquals(info.exchangeCount, 23) self.assertEquals(info.queueCount, 11)
def testRabbitMQVHost(self): self._loadZenossData() node = self.d.rabbitmq_nodes()[0] self.assertEquals(node.rabbitmq_vhosts.countObjects(), 2) info = IInfo(node.rabbitmq_vhosts._getOb('-')) self.assertEquals(info.rabbitmq_node.name, 'rabbit@dev1') self.assertEquals(info.exchangeCount, 7) self.assertEquals(info.queueCount, 0)
def testRabbitMQExchange(self): self._loadZenossData() node = self.d.rabbitmq_nodes()[0] vhost = node.rabbitmq_vhosts._getOb('-') exchange = vhost.rabbitmq_exchanges._getOb('amq.default') info = IInfo(exchange) self.assertEquals(info.rabbitmq_node.name, 'rabbit@dev1') self.assertEquals(info.rabbitmq_vhost.name, '/') self.assertEquals(info.exchange_type, 'direct') self.assertTrue(info.durable is True) self.assertTrue(info.auto_delete is False) self.assertEquals(info.arguments, '[]')
def testRabbitMQQueue(self): self._loadZenossData() node = self.d.rabbitmq_nodes()[0] vhost = node.rabbitmq_vhosts._getOb('zenoss') queue = vhost.rabbitmq_queues._getOb('zenoss.queues.zep.zenevents') self.assertEquals(queue.rabbitmq_node_name, 'rabbit@dev1') self.assertEquals(queue.rabbitmq_vhost_name, '/zenoss') info = IInfo(queue) self.assertEquals(info.rabbitmq_node.name, 'rabbit@dev1') self.assertEquals(info.rabbitmq_vhost.name, '/zenoss') self.assertTrue(info.durable is True) self.assertTrue(info.auto_delete is False) self.assertEquals(info.arguments, '[]')
def testPod(self): self._loadZenossData() zone = self.d.zones._getOb('zone1') pod = zone.pods._getOb('pod1') self.assertEquals(pod.device().id, 'zenoss.CloudStack.testDevice') info = IInfo(pod) self.assertEquals(info.entity['name'], 'Pod-A') self.assertEquals(info.icon, CLOUDSTACK_ICON) self.assertEquals(info.cloudstack_id, 1) self.assertEquals(info.allocation_state, 'Enabled') self.assertEquals(info.ip_range, '10.208.37.100 - 10.208.37.120') self.assertEquals(info.netmask, '255.255.255.128') self.assertEquals(info.gateway, '10.208.37.1') self.assertEquals(info.zone.id, 'zone1') self.assertEquals(info.cluster_count, 1) self.assertEquals(info.host_count, 3)
def testCluster(self): self._loadZenossData() zone = self.d.zones._getOb('zone1') pod = zone.pods._getOb('pod1') cluster = pod.clusters._getOb('cluster1') self.assertEquals(cluster.device().id, 'zenoss.CloudStack.testDevice') info = IInfo(cluster) self.assertEquals(info.entity['name'], 'XenCluster1-D5') self.assertEquals(info.icon, CLOUDSTACK_ICON) self.assertEquals(info.cloudstack_id, 1) self.assertEquals(info.allocation_state, 'Enabled') self.assertEquals(info.cluster_type, 'CloudManaged') self.assertEquals(info.hypervisor_type, 'XenServer') self.assertEquals(info.managed_state, 'Managed') self.assertEquals(info.zone.id, 'zone1') self.assertEquals(info.pod.id, 'pod1') self.assertEquals(info.host_count, 3)
def testZone(self): self._loadZenossData() zone = self.d.zones._getOb('zone1') self.assertEquals(zone.device().id, 'zenoss.CloudStack.testDevice') info = IInfo(zone) self.assertEquals(info.entity['name'], 'Demo5') self.assertEquals(info.icon, CLOUDSTACK_ICON) self.assertEquals(info.cloudstack_id, 1) self.assertEquals(info.allocation_state, 'Enabled') self.assertEquals(info.guest_cidr_address, '10.1.1.0/24') self.assertEquals(info.dhcp_provider, 'VirtualRouter') self.assertEquals(info.public_dns, '72.52.126.11, ') self.assertEquals(info.internal_dns, '72.52.126.12, 72.52.126.12') self.assertEquals(info.network_type, 'Advanced') self.assertEquals(info.security_groups_enabled, False) self.assertEquals(info.vlan, '1000-1200') self.assertEquals(info.zone_token, 'f0c6542e-7a1a-39b3-8c92-1a1c67cede0b') self.assertEquals(info.pod_count, 2) self.assertEquals(info.cluster_count, 2) self.assertEquals(info.host_count, 6)