def test_100_network_state_primary(self): logging.config.fileConfig("tests/data/test_runner_conf_complete.conf") with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=tests/data/test_runner_conf_complete.conf']): options = vars(jnt_parse_args()) stopevent = threading.Event() net_state = JNTNetwork(stopevent, JNTOptions(options), is_primary=True, is_secondary=False, do_heartbeat_dispatch=True) print net_state.state hadds = { 0 : HADD%(self.add_ctrl,0), } net_state.boot(hadds) i = 0 while net_state.state != 'STARTED' and i<150: i += 1 print net_state.state time.sleep(1) self.assertEqual(net_state.state, 'STARTED') net_state.stop() i = 0 while net_state.state != 'STOPPED' and i<150: i += 1 print net_state.state time.sleep(1) self.assertEqual(net_state.state, 'STOPPED')
def test_141_network_state_primary_random_more(self): #~ self.skipTest("Pass but freeze on Docker/CI. Surely a non stopped thread in the state machine") self.onlyCITest() logging.config.fileConfig("tests/data/test_runner_conf_complete.conf") with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=tests/data/test_runner_conf_complete.conf']): options = vars(jnt_parse_args()) stopevent = threading.Event() net_state = JNTNetwork(stopevent, JNTOptions(options), is_primary=True, is_secondary=False, do_heartbeat_dispatch=True, resolv_timeout=5) print net_state.state hadds = { 0 : HADD%(self.add_ctrl,0), } net_state.boot(hadds) time.sleep(5) net_state.stop() i = 0 while net_state.state != 'STOPPED' and i<150: i += 1 print net_state.state time.sleep(1) self.assertEqual(net_state.state, 'STOPPED') net_state.boot(hadds) time.sleep(25) net_state.stop() i = 0 while net_state.state != 'STOPPED' and i<150: i += 1 print net_state.state time.sleep(1) self.assertEqual(net_state.state, 'STOPPED') net_state.boot(hadds) time.sleep(31) net_state.stop() i = 0 while net_state.state != 'STOPPED' and i<150: i += 1 print net_state.state time.sleep(1) self.assertEqual(net_state.state, 'STOPPED') net_state.boot(hadds) time.sleep(52) net_state.stop() i = 0 while net_state.state != 'STOPPED' and i<150: i += 1 print net_state.state time.sleep(1) self.assertEqual(net_state.state, 'STOPPED')
class TestNetworkState1(CommonNetworkState): """Test the network state machine Split cause freeze """ def test_001_request_secondary(self): #~ self.wipTest("Freeze") with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=tests/data/test_network.conf']): options = vars(jnt_parse_args()) stopevent = threading.Event() self.network = JNTNetwork(stopevent, JNTOptions(options), is_primary=False, is_secondary=True, do_heartbeat_dispatch=True) print self.network.state hadds = { 0 : HADD%(self.net_add_ctrl,0), } self.network.boot(hadds) i = 0 while not self.network.is_started and i<150: i += 1 print self.network.state time.sleep(1) print self.network.state self.assertEqual(self.network.state, 'STARTED') with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=tests/data/test_nodeman.conf']): options = vars(jnt_parse_args()) options = JNTOptions(options) section = 'fake' thread_uuid = options.get_option(section, 'uuid') if thread_uuid == None: thread_uuid = muuid.uuid1() options.set_option(section, 'uuid', "%s"%thread_uuid) self.nodeman = JNTBusNodeMan(options, FakeBus(options=options, product_name="Http server"), section, thread_uuid) print self.nodeman.state #~ hadds = { 0 : HADD%(self.node_add_ctrl,0), #~ } self.nodeman.start() i = 0 while not self.nodeman.is_started and i<120: i += 1 print self.nodeman.state time.sleep(1) self.assertEqual(self.nodeman.state, 'ONLINE') timeout = 30 stopevent = threading.Event() for i in range(0,timeout*10): self.nodeman.loop(stopevent) #~ self.network.loop(None, stopevent) time.sleep(0.1) print "network.nodes", self.network.nodes print "network.users", self.network.users print "network.configs", self.network.configs print "network.basics", self.network.basics print "network.systems", self.network.systems print "network.commands", self.network.commands print "HADD", HADD%(self.node_add_ctrl,0) self.assertTrue(HADD%(self.node_add_ctrl,0) in self.network.nodes) self.assertTrue(HADD%(self.node_add_ctrl,0) in self.network.systems) self.assertTrue(HADD%(self.node_add_ctrl,0) in self.network.configs) self.assertTrue(HADD%(self.node_add_ctrl,1) in self.network.nodes) self.assertTrue(HADD%(self.node_add_ctrl,1) in self.network.systems) self.assertTrue(HADD%(self.node_add_ctrl,1) in self.network.configs) self.assertTrue(HADD%(self.node_add_ctrl,1) in self.network.basics) self.assertTrue(HADD%(self.node_add_ctrl,1) in self.network.users) self.assertTrue(HADD%(self.node_add_ctrl,1) in self.network.commands)