def test_core_map(self): print '*' * 80 print "start to test interface fail" mgr = ManagerProcess(simulator=False) mgr.is_ip_in_core_map('eth0', '1.1.1.1') mgr.remove_ip_in_core_map('eth0', '1.1.1.1') mgr.add_ip_to_core_map('eth0', ('1.1.1.1', '', 4)) mgr.get_core_map('eth0', '1.1.1.1') mgr.get_core_map('eth0', '1.1.1.1') mgr.is_valid_ip('1.1')
def test_gcp_Ha(self): print '*' * 80 print "start to test _handle_mgr_gcp_event HA" 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 ccap_core = CCAPCore.ccap_core_db.values() ccap_core[0].interface = 'eth0' ccap_core[0].ccap_core_network_address = '1.1.1.5' print 'Redundant core Add' # invalid ip caps = { "ActiveCoreIpAddress": '0.0.0.0', "StandbyCoreIpAddress": '1.1.1.10', 'interface': 'eth0', "operation": 0 } event_request_rsp.mgr_event.data = json.dumps("Ha/" + json.dumps(caps)) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) # not exist core caps = { "ActiveCoreIpAddress": '1.1.1.10', "StandbyCoreIpAddress": '1.1.1.11', 'interface': 'eth0', "operation": 0 } event_request_rsp.mgr_event.data = json.dumps("Ha/" + json.dumps(caps)) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) # active core mode active caps = { "ActiveCoreIpAddress": '1.1.1.5', "StandbyCoreIpAddress": '1.1.1.11', 'interface': 'eth0', "operation": 0 } ccap_core[0].is_active = CoreDescription.CORE_MODE_ACTIVE event_request_rsp.mgr_event.data = json.dumps("Ha/" + json.dumps(caps)) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) # active core mode standby caps = { "ActiveCoreIpAddress": '1.1.1.5', "StandbyCoreIpAddress": '1.1.1.11', 'interface': 'eth0', "operation": 0 } ccap_core[0].is_active = CoreDescription.CORE_MODE_STANDBY event_request_rsp.mgr_event.data = json.dumps("Ha/" + json.dumps(caps)) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) # standby core mode active caps = { "ActiveCoreIpAddress": '1.1.1.10', "StandbyCoreIpAddress": '1.1.1.5', 'interface': 'eth0', "operation": 0 } ccap_core[0].is_active = CoreDescription.CORE_MODE_ACTIVE event_request_rsp.mgr_event.data = json.dumps("Ha/" + json.dumps(caps)) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) # standby core mode standby caps = { "ActiveCoreIpAddress": '1.1.1.10', "StandbyCoreIpAddress": '1.1.1.5', 'interface': 'eth0', "operation": 0 } ccap_core[0].is_active = CoreDescription.CORE_MODE_STANDBY mgr.add_ip_to_core_map('eth0', ('1.1.1.5', '', 0)) event_request_rsp.mgr_event.data = json.dumps("Ha/" + json.dumps(caps)) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) print 'Redundant core Change' ccap_core[0].is_principal = CoreDescription.CORE_ROLE_PRINCIPAL # standby core mode active caps = { "ActiveCoreIpAddress": '1.1.1.10', "StandbyCoreIpAddress": '1.1.1.5', 'interface': 'eth0', "operation": 2 } ccap_core[0].is_active = CoreDescription.CORE_MODE_ACTIVE event_request_rsp.mgr_event.data = json.dumps("Ha/" + json.dumps(caps)) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) # standby core mode standby caps = { "ActiveCoreIpAddress": '1.1.1.10', "StandbyCoreIpAddress": '1.1.1.5', 'interface': 'eth0', "operation": 2 } ccap_core[0].is_active = CoreDescription.CORE_MODE_STANDBY event_request_rsp.mgr_event.data = json.dumps("Ha/" + json.dumps(caps)) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) print 'Redundant core Delete' # standby core mode active caps = { "ActiveCoreIpAddress": '1.1.1.10', "StandbyCoreIpAddress": '1.1.1.5', 'interface': 'eth0', "operation": 1 } ccap_core[0].is_active = CoreDescription.CORE_MODE_ACTIVE event_request_rsp.mgr_event.data = json.dumps("Ha/" + json.dumps(caps)) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) # standby core mode standby caps = { "ActiveCoreIpAddress": '1.1.1.10', "StandbyCoreIpAddress": '1.1.1.5', 'interface': 'eth0', "operation": 1 } ccap_core[0].is_active = CoreDescription.CORE_MODE_STANDBY event_request_rsp.mgr_event.data = json.dumps("Ha/" + json.dumps(caps)) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) mgr.fsm.Error(msg='test fsm error')
def test_config_table(self): print '*' * 80 print "start to test _handle_mgr_gcp_event config_table" 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 # invalid ip caps = {"ccap_core": '0.0.0.0', 'interface': 'eth0', "operation": 0} event_request_rsp.mgr_event.data = json.dumps("config_table/" + json.dumps(caps)) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) # add existed ip ccap_core = CCAPCore.ccap_core_db.values() ccap_core[0].interface = 'eth0' ccap_core[0].ccap_core_network_address = '1.1.1.5' ccap_core[0].is_principal = CoreDescription.CORE_ROLE_PRINCIPAL ccap_core[0].is_active = CoreDescription.CORE_MODE_ACTIVE # CCAPCore('CORE-1234567890', CoreDescription.CORE_ROLE_PRINCIPAL, # CoreDescription.CORE_MODE_ACTIVE, mgr=mgr, # ccap_core_interface='etho0', ccap_core_network_address='1.1.1.5') caps = { "ccap_core": '1.1.1.5', 'interface': 'eth0', "operation": 0 } # add event_request_rsp.mgr_event.data = json.dumps("config_table/" + json.dumps(caps)) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) # add a new one caps = { "ccap_core": '1.1.1.6', 'interface': 'eth0', "operation": 0 } # add event_request_rsp.mgr_event.data = json.dumps("config_table/" + json.dumps(caps)) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) caps = { "ccap_core": '1.1.1.5', 'interface': 'eth0', "operation": 2 } # change event_request_rsp.mgr_event.data = json.dumps("config_table/" + json.dumps(caps)) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) mgr.add_ip_to_core_map('eth0', ('1.1.1.5', '', 4)) caps = { "ccap_core": '1.1.1.5', 'interface': 'eth0', "operation": 1 } # delete event_request_rsp.mgr_event.data = json.dumps("config_table/" + json.dumps(caps)) mgr._handle_mgr_gcp_event(event_request_rsp.mgr_event) 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)
def test_start_process(self): """Start provision process with real agent.""" print '*' * 80 print "start to test provision manager with real agent" mgr = ManagerProcess(simulator=False) mgr.dhcp_parameter['eth0'] = { 'TimeServers': [ '1.1.1.1', ], 'TimeOffset': 100, 'CCAPCores': [ '1.1.1.1', ], 'LogServers': [ '1.1.1.1', ] } # no core mgr.core_orchestrator.orchestrator_cb(None) # startup mgr.fsm.INTERFACE_SCAN(interface='eth0') mgr.add_ip_to_core_map('eth0', ('1.1.1.1', '', mgr.HA_CORE_TRIGGER)) mgr.core_orchestrator.orchestrator_cb(None) mgr.remove_ip_in_core_map('eth0', ('1.1.1.1', '', mgr.HA_CORE_TRIGGER)) # cb w/o candidate list mgr.core_orchestrator.orchestrator_cb(None) mgr.add_ip_to_core_map('eth0', ('1.1.1.1', '', mgr.HA_CORE_TRIGGER)) mgr.interface_list.append({ "interface": 'eth0', "status": mgr.INTERFACE_UP, }) mgr.core_orchestrator.orchestrator_cb(None) # is system time confirmed. mgr.set_time(time.time()) mgr.is_system_time_confirmed() # mgr state transmit mgr.fsm.STARTUP_DHCP_OK() mgr.core_orchestrator.orchestrator_cb(None) # operational mgr.fsm.OPERATIONAL_OK() print mgr.fsm.current, mgr.core_orchestrator.active_list mgr.core_orchestrator.orchestrator_cb(None) # check ka mgr.check_ka_status(None) mgr.check_ka_status(None) mgr.check_ka_status(None) keys = CCAPCore.ccap_core_db.keys() for key in keys: CCAPCore.ccap_core_db.pop(key) mgr.process_agent_db[ProcessAgent.AGENTTYPE_INTERFACE_STATUS][ "status"] = mgr.MGR_UNREGISTERED mgr.check_ka_status(None) # fail mgr.core_orchestrator.orchestrator_cb(None) mgr.fsm.Error(msg='test fsm error')