def process_ovsvapp_agent(self, agent): """Inform the OVSvApp agent. To set the other host into maintenance or shutdown mode. """ try: LOG.info(_("Processing the OVSvApp agent to set the other host " "into maintenance or shutdown mode %s."), agent) device_data = {} agent_config = agent['configurations'] source_host = agent_config.get('esx_host_name') chosen_agent = self._get_eligible_ovsvapp_agent( agent_config['cluster_id'], agent_config['vcenter_id']) if chosen_agent and (chosen_agent['id'] in self.active_agents): cluster_id = chosen_agent['configurations'].get('cluster_id') device_data['assigned_agent_host'] = chosen_agent['host'] device_data['esx_host_name'] = source_host device_data['ovsvapp_agent'] = agent['host'] LOG.info(_("Invoking device_update RPC with target host %s."), chosen_agent['host']) self.notifier.device_update(self.context, device_data, cluster_id) else: ovsvapp_db.set_cluster_threshold(agent_config['vcenter_id'], agent_config['cluster_id']) LOG.info(_("No eligible OVSvApp agents found for " "processing. Reverting DB status for the agent.")) self.update_agent_state(agent['id'], True) except Exception: agent_config = agent['configurations'] ovsvapp_db.set_cluster_threshold(agent_config['vcenter_id'], agent_config['cluster_id']) LOG.exception(_("Unable to inform the OVSvApp agent for " "Host - maintenance or shutdown operation."))
def test_update_and_get_cluster_lock_threshold_reached(self): ret = ovsvapp_db.update_and_get_cluster_lock("fake_vcenter", "fake_cluster") self.assertEqual("1", ret) ovsvapp_db.set_cluster_threshold("fake_vcenter", "fake_cluster") with mock.patch("networking_vsphere.db.ovsvapp_db." "LOG.warn") as warn_log: ret_1 = ovsvapp_db.update_and_get_cluster_lock("fake_vcenter", "fake_cluster") self.assertEqual("-1", ret_1) self.assertTrue(warn_log.called)
def test_update_and_get_cluster_lock_threshold_reached(self): ret = ovsvapp_db.update_and_get_cluster_lock('fake_vcenter', 'fake_cluster') self.assertEqual('1', ret) ovsvapp_db.set_cluster_threshold('fake_vcenter', 'fake_cluster') with mock.patch('networking_vsphere.db.ovsvapp_db.' 'LOG.warning') as warn_log: ret_1 = ovsvapp_db.update_and_get_cluster_lock( 'fake_vcenter', 'fake_cluster') self.assertEqual('-1', ret_1) self.assertTrue(warn_log.called)
def test_update_and_get_cluster_lock_threshold_reached(self): ret = ovsvapp_db.update_and_get_cluster_lock('fake_vcenter', 'fake_cluster') self.assertEqual('1', ret) ovsvapp_db.set_cluster_threshold('fake_vcenter', 'fake_cluster') with mock.patch('networking_vsphere.db.ovsvapp_db.' 'LOG.warning') as warn_log: ret_1 = ovsvapp_db.update_and_get_cluster_lock('fake_vcenter', 'fake_cluster') self.assertEqual('-1', ret_1) self.assertTrue(warn_log.called)
def update_cluster_lock(self, rpc_context, **kwargs): vcenter_id = kwargs['vcenter_id'] cluster_id = kwargs['cluster_id'] success = kwargs['success'] if cluster_id and vcenter_id: try: if success: LOG.info(_LI("Releasing the cluster row for " "cluster %(id)s in vCenter %(vc)s."), {'id': cluster_id, 'vc': vcenter_id}) ovsvapp_db.release_cluster_lock(vcenter_id, cluster_id) else: ovsvapp_db.set_cluster_threshold(vcenter_id, cluster_id) except Exception: LOG.exception(_LE("Failed to release/set the cluster lock.")) return
def update_cluster_lock(self, rpc_context, **kwargs): vcenter_id = kwargs['vcenter_id'] cluster_id = kwargs['cluster_id'] success = kwargs['success'] if cluster_id and vcenter_id: try: if success: LOG.info(_LI("Releasing the cluster row for " "cluster %(id)s in vCenter %(vc)s."), {'id': cluster_id, 'vc': vcenter_id}) ovsvapp_db.release_cluster_lock(vcenter_id, cluster_id) else: ovsvapp_db.set_cluster_threshold(vcenter_id, cluster_id) except Exception: LOG.exception(_LE("Failed to release/set the cluster lock.")) return
def process_ovsvapp_agent(self, agent): """Inform the OVSvApp agent. To set the other host into maintenance or shutdown mode. """ try: LOG.info( _LI("Processing the OVSvApp agent to set the other host " "into maintenance or shutdown mode %s."), agent) device_data = {} agent_config = agent['configurations'] source_host = agent_config.get('esx_host_name') chosen_agent = self._get_eligible_ovsvapp_agent( agent_config['cluster_id'], agent_config['vcenter_id']) if chosen_agent and (chosen_agent['id'] in self.active_agents): cluster_id = chosen_agent['configurations'].get('cluster_id') device_data['assigned_agent_host'] = chosen_agent['host'] device_data['esx_host_name'] = source_host device_data['ovsvapp_agent'] = '-'.join( ['ovsvapp', source_host.replace('.', '-')]) LOG.info( _LI("Invoking device_update RPC with" "target host %s."), chosen_agent['host']) self.notifier.device_update(self.context, device_data, cluster_id) else: ovsvapp_db.set_cluster_threshold(agent_config['vcenter_id'], agent_config['cluster_id']) LOG.info( _LI("No eligible OVSvApp agents found for " "processing. Reverting DB status for the agent.")) self.update_agent_state(agent['id'], True) except Exception: agent_config = agent['configurations'] ovsvapp_db.set_cluster_threshold(agent_config['vcenter_id'], agent_config['cluster_id']) LOG.exception( _LE("Unable to inform the OVSvApp agent for " "Host - maintenance or shutdown operation."))