def skiptestProcessUpdates_network_stopped(self): vmHost = VmHost() vmHost.set_id('1') vmHost.set_connectionState(Constants.VMHOST_CONNECTED) InventoryCacheManager.update_object_in_cache('1', vmHost) self.mock.StubOutWithMock( self.libvirtVmHost, '_get_compute_running_status') self.libvirtVmHost._get_compute_running_status().AndReturn( (True, 'host')) self.mock.StubOutWithMock(api, 'vm_host_save') api.vm_host_save( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) fake_networks = { 'id': '1', 'created_at': 'created', 'updated_at': 'updated'} self.mock.StubOutWithMock(novadb, 'service_get_by_host_and_topic') novadb.service_get_by_host_and_topic( mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(fake_networks) self.mock.StubOutWithMock(hnm_utils, 'is_service_alive') hnm_utils.is_service_alive( mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(False) self.mock.StubOutWithMock(event_api, 'notify_host_update') event_api.notify_host_update( mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(None) self.mock.ReplayAll() self.assertEquals(self.libvirtVmHost.processUpdates(), None) self.assertEquals( self.libvirtVmHost.cachedvmHost.get_connectionState(), 'Disconnected') self.mock.stubs.UnsetAll()
def generate_data(): def _generate_stats(id_num): stats = {} i = 0 while i < CONF.num_stat: key = 'key%d' % i stats[key] = id_num + i i = i + 1 return stats print "Starting prepare data in DB" ctx = context.get_admin_context() for i in range(CONF.num_comp): if i *100.0 % CONF.num_comp == 0: sys.stdout.write("prepared %d%% data\r" % (i * 100.0 / CONF.num_comp)) sys.stdout.flush() svc_values = { 'host': 'host-%d' % i, 'binary': 'novadbtest', 'topic': 'novadbtest', 'report_count': 0, } #created service record service_ref = jsonutils.to_primitive( db.service_get_by_host_and_topic(ctx, svc_values['host'], svc_values['topic'])) if not service_ref: service_ref = jsonutils.to_primitive( db.service_create(ctx, svc_values)) LOG.info('Service record created for id %d', service_ref['id']) #create/update compute node record comp_values = { 'service_id': service_ref['id'], 'vcpus': i, 'memory_mb': i, 'local_gb': i, 'vcpus_used': i, 'memory_mb_used': i, 'local_gb_used': i, 'hypervisor_type': 'qemu', 'hypervisor_version': 1, 'hypervisor_hostname': 'test', 'free_ram_mb': i, 'free_disk_gb': i, 'current_workload': i, 'running_vms': i, 'disk_available_least': i, } comp_values['cpu_info'] = jsonutils.dumps(_generate_stats(i)) if hasattr(ComputeNode, 'metrics'): comp_values['metrics'] = jsonutils.dumps(_generate_stats(i)) if CONF.join_stats: comp_values['stats'] = _generate_stats(i) compute_ref = jsonutils.to_primitive( db.compute_node_create(ctx, comp_values)) LOG.info('Compute node record created for id %d', compute_ref['id']) print "Finish preparing data in DB"
def _get_phy_hosts(self, context): service = db.service_get_by_host_and_topic(context, FLAGS.host, "compute") if not service: LOG.warn("Could not get service_get_by_host_and_topic host=%s topic=%s", FLAGS.host, "compute") return [] phy_hosts = db.phy_host_get_all(context) hosts = [] for i in phy_hosts: if i.service_id == service.id: hosts.append(i) return hosts
def _capture_dom0_hostname(self): """Find dom0's hostname and log it to the DB.""" ctxt = context.get_admin_context() service = db.service_get_by_host_and_topic(ctxt, FLAGS.host, "compute") try: compute_node = db.compute_node_get_for_service(ctxt, service["id"]) except TypeError: return host_stats = self.get_host_stats() db.compute_node_update( ctxt, compute_node["id"], {"hypervisor_hostname": host_stats["host_hostname"]}, auto_adjust=False)
def get_by_host_and_topic(cls, context, host, topic): db_service = db.service_get_by_host_and_topic(context, host, topic) return cls._from_db_object(context, cls(), db_service)