Пример #1
0
    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)
Пример #2
0
 def test_010_args_start_stop(self):
     with mock.patch('sys.argv', [self.prog, 'start']):
         args = jnt_parse_args()
         print args
         self.assertEqual(args.command, 'start')
     with mock.patch('sys.argv', [self.prog, 'stop']):
         args = jnt_parse_args()
         print args
         self.assertEqual(args.command, 'stop')
Пример #3
0
 def test_100_node_state(self):
     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)
     node_state = JNTNodeMan(options, section, thread_uuid)
     print node_state.state
     hadds = { 0 : HADD%(self.add_ctrl,0),
                  }
     node_state.start()
     i = 0
     while node_state.state != 'ONLINE' and i<120:
         i += 1
         print node_state.state
         time.sleep(1)
     self.assertEqual(node_state.state, 'ONLINE')
     node_state.stop()
     i = 0
     while node_state.state != 'OFFLINE' and i<120:
         i += 1
         print node_state.state
         time.sleep(1)
     self.assertEqual(node_state.state, 'OFFLINE')
     node_state = None
Пример #4
0
    def test_100_bus_fsm_boot(self):
        with mock.patch('sys.argv', ['test', 'start', '--conf_file=%s'%'tests/data/test_bus_fsm.conf']):
            options = vars(jnt_parse_args())
        jnt_options = JNTOptions(options)

        bus = self.bus(options=jnt_options)
        bus.nodeman = TestFsmBus.FakeNodeman(bus)
        bus._fsm_timer_delay = 2
        self.assertNotEqual(bus, None)
        bus.start(None)
        i = 0
        self.assertFalse(bus.check_heartbeat())
        while i<30 and bus.state == 'booting':
            time.sleep(0.5)
            i += 1
            print(bus.state)
        self.assertEqual('sleeping', bus.state)
        bus.work()
        time.sleep(0.25)
        self.assertEqual('working', bus.state)
        self.assertTrue(bus.check_heartbeat())
        bus.stop()
        time.sleep(1)
        self.assertEqual('halted', bus.state)
        self.assertFalse(bus.check_heartbeat())
Пример #5
0
 def test_030_server_options(self):
     #~ self.skipTest("Pass but freeze nosetests")
     with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=tests/data/test_server_conf_testing.conf']):
         options = vars(jnt_parse_args())
         server = JNTServer(options)
         self.assertEqual(server.options.get_options('database')['sqlalchemy.url'], 'sqlite:////tmp/janitoo_test/home/test_test.db')
         noptions = server.options.get_options('system')
         self.assertEqual(noptions['service'], options['service'])
         self.assertEqual(noptions['user'], options['user'])
         noptions = server.options.get_options('test')
         self.assertEqual(type(noptions), type({}))
         self.assertEqual(len(noptions), 0)
         noptions['timeout'] = 10
         noptions['tries'] = 3
         server.options.set_options('test2', noptions)
         noptions = None
         noptions = server.options.get_options('test2')
         self.assertEqual(noptions['timeout'], 10)
         self.assertEqual(noptions['tries'], 3)
         server.options.remove_options('test2')
         noptions = None
         noptions = server.options.get_options('test2')
         print noptions
         self.assertEqual(type(noptions), type({}))
         self.assertEqual(len(noptions), 0)
Пример #6
0
 def test_100_node_state(self):
     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)
     node_state = JNTNodeMan(options, section, thread_uuid)
     print node_state.state
     hadds = {0: HADD % (self.add_ctrl, 0)}
     node_state.start()
     i = 0
     while node_state.state != "ONLINE" and i < 120:
         i += 1
         print node_state.state
         time.sleep(1)
     self.assertEqual(node_state.state, "ONLINE")
     node_state.stop()
     i = 0
     while node_state.state != "OFFLINE" and i < 120:
         i += 1
         print node_state.state
         time.sleep(1)
     self.assertEqual(node_state.state, "OFFLINE")
     node_state = None
 def test_101_get(self):
     self.onlyRasperryTest()
     with mock.patch('sys.argv', ['test', 'start', '--conf_file=%s' % self.getDataFile(self.conf)]):
         options = JNTOptions(vars(jnt_parse_args()))
     bus = OnewireBus(options=options)
     compo = components.DS18B20( bus=bus, hexadd="28-00000463b745")
     temp = compo.temperature(None,0)
     self.assertNotEqual(temp, None)
     self.assertTrue(compo.check_heartbeat())
Пример #8
0
 def test_020_server_start(self):
     #~ self.wipTest("Pass but freeze nosetests")
     server = None
     with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=tests/data/test_runner_conf_complete.conf']):
         options = vars(jnt_parse_args())
         server = JNTServer(options)
     server.start()
     time.sleep(5)
     server.stop()
 def test_101_get_bad(self):
     self.skipRasperryTest()
     with mock.patch('sys.argv', ['test', 'start', '--conf_file=%s' % self.getDataFile(self.conf)]):
         options = JNTOptions(vars(jnt_parse_args()))
     bus = OnewireBus(options=options)
     compo = components.DS18B20( bus=bus)
     temp = compo.temperature(None,0)
     self.assertEqual(temp, None)
     self.assertFalse(compo.check_heartbeat())
Пример #10
0
 def get_main_value(self, node_uuid='test_node', **kwargs):
     print "entry_name ", self.entry_name
     entry_points = { }
     for entrypoint in iter_entry_points(group = 'janitoo.values'):
         entry_points[entrypoint.name] = entrypoint.load()
     options = {}
     with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=%s'%self.conf_file]):
         options = vars(jnt_parse_args())
     return entry_points[self.entry_name](options=JNTOptions(options), node_uuid=node_uuid, **kwargs)
Пример #11
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()
Пример #12
0
 def startServer(self):
     if self.server is None:
         with mock.patch(
             "sys.argv", ["%s" % self.server_class, "start", "--conf_file=%s" % self.getDataFile(self.server_conf)]
         ):
             options = vars(jnt_parse_args())
             self.server = self.server_class(options)
         self.server.start()
         self.running_server = threading.Timer(0.01, self.server.run)
         self.running_server.start()
         time.sleep(1.5)
 def test_021_rotate_cycle(self):
     logging_fileConfig(self.conf_file)
     with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=%s'%self.conf_file]):
         options = vars(jnt_parse_args())
     self.options = JNTOptions(options)
     bus = FishtankBus(options=self.options)
     bus.nodeman=FakeNodeman()
     #~ bus.start(None)
     bc = MoonComponent(bus=bus, cycle=28, current=0, min=0, max=60, options=self.options, node_uuid='fishtank__moon')
     print bc.values['current'].get_data_index(node_uuid='moon', index=0)
     bc.current_rotate()
     print bc.values['current'].get_data_index(node_uuid='moon', index=0)
Пример #14
0
 def test_010_nodeman_sfm_states(self):
     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)
     node_state = JNTNodeMan(options, section, thread_uuid, test=True)
     node_state.start()
     #~ net_state.fsm_network_start()
     while node_state.state != 'ONLINE':
         node_state.fsm_state_next()
     node_state.stop()
Пример #15
0
 def test_010_nodeman_sfm_states(self):
     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)
     node_state = JNTNodeMan(options, section, thread_uuid, test=True)
     node_state.start()
     # ~ net_state.fsm_network_start()
     while node_state.state != "ONLINE":
         node_state.fsm_state_next()
     node_state.stop()
Пример #16
0
 def test_050_args_to_dict(self):
     with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=tests/data/test_runner_conf_complete.conf']):
         args = vars(jnt_parse_args())
         print args
         self.assertEqual(args['service'], 'jnt_test')
         self.assertEqual(args['user'], 'janitoo')
         self.assertEqual(args['log_dir'], '/tmp/janitoo_test/log')
         self.assertEqual(args['home_dir'], '/tmp/janitoo_test/home')
         self.assertEqual(args['pid_dir'], '/tmp/janitoo_test/run')
         self.assertEqual(args['conf_dir'], '/tmp/janitoo_test/etc')
         self.assertEqual(args['broker_ip'], '127.0.0.1')
         self.assertEqual(args['broker_port'], '1883')
         self.assertEqual(args['broker_user'], 'myuser')
         self.assertEqual(args['broker_password'], 'mypassword')
         self.assertEqual(args['conf_file'], 'tests/data/test_runner_conf_complete.conf')
Пример #17
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')
Пример #18
0
    def test_301_busnode_find_helpers(self):
        with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=tests/data/test_bus.conf']):
            options = vars(jnt_parse_args())
            options = JNTOptions(options)
        bus = FakeBus(options=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)
        node_state = JNTBusNodeMan(options, bus, section, thread_uuid)
        print node_state.state
        hadds = { 0 : HADD%(self.add_ctrl,0),
                     }
        node_state.start()
        i = 0
        while node_state.state != 'ONLINE' and i<120:
            i += 1
            print node_state.state
            time.sleep(1)
        self.assertEqual(node_state.state, 'ONLINE')
        try:

            node = node_state.find_node('component1')
            self.assertTrue('rrd1' in node.name)
            node = node_state.find_node('componentbad')
            self.assertEqual(node, None)
            value = node_state.find_value('component1', 'heartbeat')
            self.assertTrue('component1' in value.node_uuid)
            self.assertEqual('heartbeat',value.uuid)
            value = node_state.find_value('componentbad', 'heartbeat')
            self.assertEqual(value, None)
            value = node_state.find_value('component1', 'badbeat')
            self.assertEqual(value, None)

        finally:
            node_state.stop()
            i = 0
            while node_state.state != 'OFFLINE' and i<120:
                i += 1
                print node_state.state
                time.sleep(1)
            self.assertEqual(node_state.state, 'OFFLINE')
Пример #19
0
    def test_301_busnode_find_helpers(self):
        with mock.patch("sys.argv", [self.prog, "start", "--conf_file=tests/data/test_bus.conf"]):
            options = vars(jnt_parse_args())
            options = JNTOptions(options)
        bus = FakeBus(options=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)
        node_state = JNTBusNodeMan(options, bus, section, thread_uuid)
        print node_state.state
        hadds = {0: HADD % (self.add_ctrl, 0)}
        node_state.start()
        i = 0
        while node_state.state != "ONLINE" and i < 120:
            i += 1
            print node_state.state
            time.sleep(1)
        self.assertEqual(node_state.state, "ONLINE")
        try:

            node = node_state.find_node("component1")
            self.assertTrue("rrd1" in node.name)
            node = node_state.find_node("componentbad")
            self.assertEqual(node, None)
            value = node_state.find_value("component1", "heartbeat")
            self.assertTrue("component1" in value.node_uuid)
            self.assertEqual("heartbeat", value.uuid)
            value = node_state.find_value("componentbad", "heartbeat")
            self.assertEqual(value, None)
            value = node_state.find_value("component1", "badbeat")
            self.assertEqual(value, None)

        finally:
            node_state.stop()
            i = 0
            while node_state.state != "OFFLINE" and i < 120:
                i += 1
                print node_state.state
                time.sleep(1)
            self.assertEqual(node_state.state, "OFFLINE")
Пример #20
0
 def test_112_node_start_wait_random_stop_more(self):
     #~ self.skipTest("Pass but freeze on Docker/CI. Surely a non stopped thread in the state machine")
     self.onlyCITest()
     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)
     node_state = JNTNodeMan(options, section, thread_uuid)
     print node_state.state
     hadds = { 0 : HADD%(self.add_ctrl,0),
                  }
     node_state.start()
     time.sleep(6)
     node_state.stop()
     i = 0
     while node_state.state != 'OFFLINE' and i<120:
         i += 1
         print node_state.state
         time.sleep(1)
     node_state.start()
     time.sleep(15)
     node_state.stop()
     i = 0
     while node_state.state != 'OFFLINE' and i<120:
         i += 1
         print node_state.state
         time.sleep(1)
     node_state.start()
     time.sleep(32)
     node_state.stop()
     i = 0
     while node_state.state != 'OFFLINE' and i<120:
         i += 1
         print node_state.state
         time.sleep(1)
Пример #21
0
 def test_111_node_start_wait_random_stop(self):
     # ~ self.skipTest("Pass but freeze on Docker/CI. Surely a non stopped thread in the state machine")
     self.onlyCITest()
     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)
     node_state = JNTNodeMan(options, section, thread_uuid)
     print node_state.state
     hadds = {0: HADD % (self.add_ctrl, 0)}
     node_state.start()
     time.sleep(4)
     node_state.stop()
     i = 0
     while node_state.state != "OFFLINE" and i < 120:
         i += 1
         print node_state.state
         time.sleep(1)
     node_state.start()
     time.sleep(8)
     node_state.stop()
     i = 0
     while node_state.state != "OFFLINE" and i < 120:
         i += 1
         print node_state.state
         time.sleep(1)
     node_state.start()
     time.sleep(22)
     node_state.stop()
     i = 0
     while node_state.state != "OFFLINE" and i < 120:
         i += 1
         print node_state.state
         time.sleep(1)
Пример #22
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')
Пример #23
0
 def test_010_server_service_to_dict(self):
     with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=tests/data/test_server_conf_testing.conf']):
         options = vars(jnt_parse_args())
         server = JNTServer(options)
         self.assertEqual(server.options.get_options('database')['sqlalchemy.url'], 'sqlite:////tmp/janitoo_test/home/test_test.db')
Пример #24
0
 def test_030_args_service_from_conf(self):
     with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=tests/data/test_runner_conf1.conf']):
         args = jnt_parse_args()
         print args
         self.assertEqual(args.command, 'start')
         self.assertEqual(args.service, 'jnt_test')
Пример #25
0
 def test_020_args_service(self):
     with mock.patch('sys.argv', [self.prog, 'start', '--service=jnt_test']):
         args = jnt_parse_args()
         print args
         self.assertEqual(args.command, 'start')
         self.assertEqual(args.service, 'jnt_test')