Exemple #1
0
 def __init__(self, stop_event, options, **kwargs):
     """
     """
     self.tkroot = kwargs.pop('tkroot', None)
     if self.tkroot is None:
         raise RuntimeError("tkroot must be instancied")
     JNTNetwork.__init__(self, stop_event, options, **kwargs)
     self.extend_from_entry_points('janitoo_tkinter')
Exemple #2
0
 def __init__(self, stop_event, options, **kwargs):
     """
     """
     self.tkroot = kwargs.pop('tkroot', None)
     if self.tkroot is None:
         raise RuntimeError("tkroot must be instancied")
     JNTNetwork.__init__(self, stop_event, options, **kwargs)
     self.extend_from_entry_points('janitoo_tkinter')
    def test_001_broadcast_secondary(self):
        #~ self.wipTest("Freeze")
        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')


        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')

        time.sleep(30)

        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)
Exemple #4
0
 def test_050_network_sfm_secondary(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=False, is_secondary=True, do_heartbeat_dispatch=False, test=True)
     net_state.start()
     while net_state.state != 'STARTED':
         net_state.fsm_network_next()
     net_state.stop()
Exemple #5
0
 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')
#!/usr/bin/python
#From https://gist.github.com/svdgraaf/198e2c0cf4cf0a031c84
import pygraphviz as pgv
import threading

from janitoo.options import JNTOptions
from janitoo.dhcp import JNTNetwork
from janitoo.node import JNTNodeMan

network = JNTNetwork(threading.Event(), JNTOptions({}))
network.fsm_network = network.create_fsm()
network.fsm_network .show_graph(fname='rst/images/fsm_network.png', prog='dot')
nodeman = JNTNodeMan(JNTOptions({}), None, None)
nodeman.fsm_state = nodeman.create_fsm()
nodeman.fsm_state .show_graph(fname='rst/images/fsm_nodeman.png', prog='dot')
Exemple #7
0
 def __init__(self, stop_event, options, **kwargs):
     """
     """
     JNTNetwork.__init__(self, stop_event, options, **kwargs)
     self.extend_from_entry_points('janitoo_dhcp')
Exemple #8
0
class TestNetworkState(JNTTBase):
    """Test the network state machine
    """

    prog = 'start.py'

    net_add_ctrl = 111
    node_add_ctrl = 1118

    network = None
    nodeman = None

    def tearDown(self):
        if self.nodeman is not None:
            self.nodeman.stop()
        time.sleep(2)
        if self.network is not None:
            self.network.stop()
        time.sleep(2)

    def test_001_request_secondary(self):

        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 self.network.state != '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, oid=section, 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 self.nodeman.state != 'ONLINE' 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)

    def test_011_request_primary(self):

        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=True, is_secondary=False, do_heartbeat_dispatch=True)
        print self.network.state
        hadds = { 0 : HADD%(self.net_add_ctrl,0),
                     }
        self.network.boot(hadds)
        i = 0
        while self.network.state != '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, oid=section, 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 self.nodeman.state != 'ONLINE' 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)
            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)
Exemple #9
0
 def __init__(self, app, stop_event, options, **kwargs):
     """
     """
     JNTNetwork.__init__(self, stop_event, options, **kwargs)
     self.app = app
     self.extend_from_entry_points('janitoo_flask')
Exemple #10
0
 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')