def on_node_started(client): "Use it only in node context" import socket report = NodeOnlineReport.create(client.oid, hostname=socket.gethostname()) report.storages = Node.get_storage_points(client) client.publish_report(report)
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_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 test_report_arrived(self): node_oid = str(uuid.uuid1()) on_report(NodeOnlineReport.create(node_oid, hostname='testhost')) on_report(IFConfigReport.create(node_oid, raw_data=IFCONFIG_DATA)) on_report(BrctlShowReport.create(node_oid, raw_data=BRCTL_SHOW_DATA)) cluster = Cluster.instance() node = cluster.get(node_oid) self.assertTrue(node) eth2 = node.get_host_nic('eth2') self.assertTrue(eth2) self.assertEqual(eth2.in_bridge, 'virbr2') virbr2 = node.get_host_nic('virbr2') self.assertEqual(virbr2.bridge_for, ['eth2', 'vnet0', 'vnet1'])
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))