def test_seek_principal_core(self): print '*' * 80 print "start to test orchestrator seek_principal_core" mgr = ManagerProcess(simulator=False) mgr.fsm.INTERFACE_SCAN(interface='eth0') mgr.interface_candidate.append('eth0') ccap_core = CCAPCore.ccap_core_db.values() # principal core is none mgr.core_orchestrator.seek_principal_core() # ccap_core_id not in db mgr.core_orchestrator.active_list.append(('eth0', '1.1.1.1', 'test')) mgr.core_orchestrator.seek_principal_core() # ccap_core_id in db mgr.core_orchestrator.active_list.append( ('eth0', '1.1.1.1', ccap_core[0].ccap_core_id)) mgr.core_orchestrator.seek_principal_core() # no principal active ccap_core[0].agent_status[ProcessAgent.AGENTTYPE_IPSEC] = True ccap_core[0].is_principal = CoreDescription.CORE_ROLE_NONE mgr.core_orchestrator.seek_principal_core() # principal active ccap_core[0].is_principal = CoreDescription.CORE_ROLE_PRINCIPAL mgr.core_orchestrator.seek_principal_core() second_core = CCAPCore('CORE-1234567890', CoreDescription.CORE_ROLE_PRINCIPAL, CoreDescription.CORE_MODE_ACTIVE, mgr=mgr, ccap_core_interface='eth0', ccap_core_network_address='1.1.1.6') CCAPCore.ccap_core_db[second_core.ccap_core_id] = second_core mgr.core_orchestrator.active_list.append( ('eth0', '1.1.1.1', second_core.ccap_core_id)) second_core.agent_status[ProcessAgent.AGENTTYPE_IPSEC] = True mgr.core_orchestrator.seek_principal_core() # principal core not none mgr.principal_core = ccap_core[0] mgr.core_orchestrator.seek_principal_core() mgr.fsm.Error(msg='test fsm error')
def test_handle_mgr_gcp_event(self): print '*' * 80 print "start to test _handle_mgr_gcp_event" mgr = ManagerProcess(simulator=False) mgr.fsm.INTERFACE_SCAN(interface='eth0') mgr.fsm.STARTUP_DHCP_OK(interface='eth0') event_request_rsp = protoDef.msg_event_notification() event_request_rsp.mgr_event.mgr_id = mgr.mgr_id event_request_rsp.mgr_event.event_id = ProcessAgent.AGENTTYPE_GCP # interface set to '' event_request_rsp.mgr_event.data = json.dumps("reboot/;1.1.1.1;info") mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) event_request_rsp.mgr_event.data = json.dumps( "connect_closed/;1.1.1.1;" + str(True)) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) event_request_rsp.mgr_event.data = json.dumps( "gcp_flapping/;1.1.1.1/recovering") mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) event_request_rsp.mgr_event.data = json.dumps( "redirect/1.1.1.3;/;1.1.1.1/") mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) # interface and ip valid ccap_core = CCAPCore.ccap_core_db.values() ccap_core[0].interface = 'eth0' ccap_core[0].ccap_core_network_address = '1.1.1.5' mgr.add_ip_to_core_map('eth0', ('1.1.1.5', '', 4)) mgr.principal_core = ccap_core[0] second_core = CCAPCore('CORE-1234567890', CoreDescription.CORE_ROLE_PRINCIPAL, CoreDescription.CORE_MODE_ACTIVE, mgr=mgr, ccap_core_interface='eth0', ccap_core_network_address='1.1.1.6') CCAPCore.ccap_core_db[second_core.ccap_core_id] = second_core event_request_rsp.mgr_event.data = json.dumps( "reboot/eth0;1.1.1.5;info") mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) ccap_core = CCAPCore('CORE-1234567890', CoreDescription.CORE_ROLE_PRINCIPAL, CoreDescription.CORE_MODE_ACTIVE, mgr=mgr, ccap_core_interface='eth0', ccap_core_network_address='1.1.1.5') CCAPCore.ccap_core_db[ccap_core.ccap_core_id] = ccap_core event_request_rsp.mgr_event.data = json.dumps( "connect_closed/eth0;1.1.1.5;" + str(True)) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) event_request_rsp.mgr_event.data = json.dumps( "gcp_flapping/eth0;1.1.1.5/recovering") mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) event_request_rsp.mgr_event.data = json.dumps( "gcp_flapping/eth0;1.1.1.5/done") mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) mgr.add_ip_to_core_map('eth0', ('1.1.1.5', '', 4)) event_request_rsp.mgr_event.data = json.dumps( "redirect/1.1.1.3;/eth0;1.1.1.5") mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) mgr.add_ip_to_core_map('eth0', ('1.1.1.5', '', 4)) event_request_rsp.mgr_event.data = json.dumps( "get_active_principal/3,1.1.1.1/") mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event)