def on_mngr_msg(client, body, routing_key): self.mngr_msg_count += 1 report = Entity.from_json(body) on_report(report) self.assertEqual(report.reporter_oid, self.node_oid) if self.mngr_msg_count == 1: # got NodeOnline Report self.assertEqual(report.__class__.__name__, 'NodeOnlineReport') client.send_task(TestConnectTask(node_oid=self.node_oid)) if self.mngr_msg_count == 2: # TaskUpdated reports self.assertEqual(report.task.node_oid, self.node_oid) self.assertEqual(report.task.status, 'accepted') if self.mngr_msg_count == 3: self.assertEqual(report.task.status, 'inprogress') self.assertEqual(report.task.progress, 50) if self.mngr_msg_count == 4: self.assertEqual(report.__class__.__name__, 'TaskSuccess') self.assertEqual(report.task.status, 'success') self.stop()
def test_vmxml_report_updates_cluster(self): on_report(NodeOnlineReport.create(self.node_oid, hostname='testhost')) report = VmXMLReport.create(self.node_oid, raw_data = LIBVIRT_XML) on_report(report) cluster = Cluster.instance() vms = cluster.entities_by_class('VmProcess') self.assertEqual(len(vms), 1) node = cluster.get(self.node_oid) self.assertEqual(len(node.get_vm_procs()), 1) vm_proc = vms[0] self.assertEqual(vm_proc.vm_config.nics[0].target, 'vnet0')
def test_crud(self): cluster = Cluster.instance() node = Node(hostname='testhost') cluster.store(node) on_report(IFConfigReport.create(node.oid, raw_data=IFCONFIG_DATA)) network = Network(title='TestNetwork') virbr2 = node.get_host_nic('virbr2') network.add_host_nic(virbr2) self.assertTrue(virbr2.oid in network.host_nics) eth2 = node.get_host_nic('eth2') self.assertEqual(len(network.host_nics), 1) self.assertFalse(eth2.oid in network.host_nics) # only bridge should be added
def on_mngr_msg(client, body, routing_key): report = Entity.from_json(body) on_report(report) self.assertEqual(report.reporter_oid, self.node_oid) if report.__class__.__name__ == 'NodeOnlineReport': on_report(IFConfigReport.create(self.node_oid, raw_data=IFCONFIG_DATA)) client.send_task(VMInventoryTask(node_oid=self.node_oid)) if report.__class__.__name__ == 'VmXMLReport': cluster = Cluster.instance() vm_config = cluster.entities_by_class('VmConfig')[0] self.assertEqual(vm_config.oid, 'c2127a40-eb4c-4e3c-af5b-ab455fd8bb40') self.stop()
def test_update_cluster(self): import uuid storage_oid = str(uuid.uuid4()) on_report(NodeOnlineReport.create(self.node_oid, hostname='testhost', storages=[dict( node_oid=self.node_oid, storage_oid=storage_oid, path='/home/storage1')])) on_report(DFReport.create(self.node_oid, raw_data=DF_RAW)) cluster = Cluster.instance() storage = cluster.get(storage_oid) self.assertTrue(storage) self.assertEqual(storage.avail, '702G')
def load_fixtures(node_oid): "Load demo data for development" from swarm.scenarios import on_report from swarm.tests import fixtures from swarm.reports import (NodeOnlineReport, VmXMLReport, IFConfigReport, BrctlShowReport, DFReport) log.debug('Loading test data') storage_oid = str(uuid.uuid4()) on_report(NodeOnlineReport.create(node_oid, hostname='testhost', storages = [dict( storage_oid=storage_oid, path='/home/vgdcloud/storage1')])) on_report(IFConfigReport.create(node_oid, raw_data=fixtures.IFCONFIG_DATA)) on_report(BrctlShowReport.create(node_oid, raw_data=fixtures.BRCTL_SHOW_DATA)) on_report(VmXMLReport.create(node_oid, raw_data=fixtures.LIBVIRT_XML)) on_report(DFReport.create(node_oid, raw_data=fixtures.DF_RAW))