Exemplo n.º 1
0
 def add_dm(self):
     self.dm = DeviceManager()
     self.dm.configure({'parent':as_internal_node('/services')})
     return
Exemplo n.º 2
0
def device_manager_node():
    # Too much voodoo...
    from manager import DeviceManager
    return DeviceManager.DEVICE_MANAGER_NODE()
Exemplo n.º 3
0
class TestCase(DefaultTestFixture):
    def __init__(self, *args, **kw):
        DefaultTestFixture.__init__(self, *args ,**kw)
        return
    def setUp(self):
        DefaultTestFixture.setUp(self)
        self.new_node_tree()
        self.dm = None
        return
    def tearDown(self):
        self.del_node_tree()
        DefaultTestFixture.tearDown(self)
        return
    def add_dm(self):
        self.dm = DeviceManager()
        self.dm.configure({'parent':as_internal_node('/services')})
        return
    def test_instanciate_udins(self):
        UDINS()
        return
    def test_instanciate_device_manager(self):
        DeviceManager()
        return
    def test_add_dm(self):
        self.add_dm()
        return
    def test_udi_methods(self):
        self.add_dm()
        udi1 = self.dm.udi_from_kw(UniqueDeviceIdentifier,
                                   device_class='udi')
        udi2 = self.dm.udi_from_kw(UniqueDeviceIdentifier,
                                   device_class='udi')
        self.assert_comparison('udi2', 'is', 'udi1')
        udi3 = UniqueDeviceIdentifier(device_class='udi')
        self.assert_comparison('udi3', '==', 'udi1')
        self.assert_comparison('udi3', 'is not', 'udi1')
        udi4 = self.dm.udi_from_udi(udi3)
        self.assert_comparison('udi4', 'is', 'udi1')
        test_1_1 = self.dm.udi_from_kw(UniqueTestIdentifier,
                                       device_class='test',
                                       port='/interfaces/com1',
                                       address=1)
        test_1_2 = self.dm.udi_from_kw(UniqueTestIdentifier,
                                       device_class='test',
                                       port='/interfaces/com1',
                                       address=2)
        self.assert_comparison('test_1_2', 'is not', 'test_1_1')
        test_2_1 = self.dm.udi_from_kw(UniqueTestIdentifier,
                                       device_class='test',
                                       port='/interfaces/com2',
                                       address=1)
        test_2_2 = self.dm.udi_from_kw(UniqueTestIdentifier,
                                       device_class='test',
                                       port='/interfaces/com2',
                                       address=2)
        self.assert_comparison('test_2_2', 'is not', 'test_2_1')
        
        self.assert_comparison('test_2_1', 'is not', 'test_1_1')
        self.assert_comparison('test_2_2', 'is not', 'test_1_2')
        test_1_1b = self.dm.udi_from_kw(UniqueTestIdentifier,
                                        device_class='test',
                                        port='/interfaces/com1',
                                        address=1)
        test_1_2b = self.dm.udi_from_kw(UniqueTestIdentifier,
                                        device_class='test',
                                        port='/interfaces/com1',
                                        address=2)
        test_2_1b = self.dm.udi_from_kw(UniqueTestIdentifier,
                                        device_class='test',
                                        port='/interfaces/com2',
                                        address=1)
        test_2_2b = self.dm.udi_from_kw(UniqueTestIdentifier,
                                        device_class='test',
                                        port='/interfaces/com2',
                                        address=2)
        self.assert_comparison('test_1_1', 'is', 'test_1_1b')
        self.assert_comparison('test_1_2', 'is', 'test_1_2b')
        self.assert_comparison('test_2_1', 'is', 'test_2_1b')
        self.assert_comparison('test_2_2', 'is', 'test_2_2b')
        return
    def test_monitor_from_methods_and_start(self):
        self.add_dm()
        monitor1 = self.dm.monitor_from_kw(UniqueDeviceIdentifier,
                                           device_class='udi')
        monitor2 = self.dm.monitor_from_kw(UniqueDeviceIdentifier,
                                           device_class='udi')
        self.assert_comparison('monitor2', 'is', 'monitor1')
        monitor_1_1 = self.dm.monitor_from_kw(UniqueTestIdentifier,
                                              device_class='test',
                                              port='/interfaces/com1',
                                              address=1)
        monitor_1_2 = self.dm.monitor_from_kw(UniqueTestIdentifier,
                                              device_class='test',
                                              port='/interfaces/com1',
                                              address=2)
        self.assert_comparison('monitor_1_1', 'is not', 'monitor_1_2')
        monitor_2_1 = self.dm.monitor_from_udi(
            UniqueTestIdentifier(
                device_class='test',
                port='/interfaces/com2',
                address=1
                )
            )
        monitor_2_2 = self.dm.monitor_from_udi(
            UniqueTestIdentifier(
                device_class='test',
                port='/interfaces/com2',
                address=2
                )
            )
        self.assert_comparison('monitor_2_1', 'is not', 'monitor_2_2')
        instance_list = [monitor1, monitor_1_1, monitor_1_2, monitor_2_1,
                         monitor_2_2]
        node_list = self.dm.dynamic_container().children_nodes()
        while node_list:
            node = node_list.pop()
            self.assert_comparison('node', 'in', 'instance_list')
            instance_list.remove(node)
        self.assert_comparison('instance_list', '==', '[]')
        # Start will cause the monitors to "register" with the Device Manager.
        as_internal_node('/').start()
        return
    def test_start(self):
        self.add_dm()
        self.dm.start()
        return
Exemplo n.º 4
0
 def test_instanciate_device_manager(self):
     DeviceManager()
     return
Exemplo n.º 5
0
 def add_dm(self):
     self.dm = DeviceManager()
     self.dm.configure({'parent': as_internal_node('/services')})
     return
Exemplo n.º 6
0
class TestCase(DefaultTestFixture):
    def __init__(self, *args, **kw):
        DefaultTestFixture.__init__(self, *args, **kw)
        return

    def setUp(self):
        DefaultTestFixture.setUp(self)
        self.new_node_tree()
        self.dm = None
        return

    def tearDown(self):
        self.del_node_tree()
        DefaultTestFixture.tearDown(self)
        return

    def add_dm(self):
        self.dm = DeviceManager()
        self.dm.configure({'parent': as_internal_node('/services')})
        return

    def test_instanciate_udins(self):
        UDINS()
        return

    def test_instanciate_device_manager(self):
        DeviceManager()
        return

    def test_add_dm(self):
        self.add_dm()
        return

    def test_udi_methods(self):
        self.add_dm()
        udi1 = self.dm.udi_from_kw(UniqueDeviceIdentifier, device_class='udi')
        udi2 = self.dm.udi_from_kw(UniqueDeviceIdentifier, device_class='udi')
        self.assert_comparison('udi2', 'is', 'udi1')
        udi3 = UniqueDeviceIdentifier(device_class='udi')
        self.assert_comparison('udi3', '==', 'udi1')
        self.assert_comparison('udi3', 'is not', 'udi1')
        udi4 = self.dm.udi_from_udi(udi3)
        self.assert_comparison('udi4', 'is', 'udi1')
        test_1_1 = self.dm.udi_from_kw(UniqueTestIdentifier,
                                       device_class='test',
                                       port='/interfaces/com1',
                                       address=1)
        test_1_2 = self.dm.udi_from_kw(UniqueTestIdentifier,
                                       device_class='test',
                                       port='/interfaces/com1',
                                       address=2)
        self.assert_comparison('test_1_2', 'is not', 'test_1_1')
        test_2_1 = self.dm.udi_from_kw(UniqueTestIdentifier,
                                       device_class='test',
                                       port='/interfaces/com2',
                                       address=1)
        test_2_2 = self.dm.udi_from_kw(UniqueTestIdentifier,
                                       device_class='test',
                                       port='/interfaces/com2',
                                       address=2)
        self.assert_comparison('test_2_2', 'is not', 'test_2_1')

        self.assert_comparison('test_2_1', 'is not', 'test_1_1')
        self.assert_comparison('test_2_2', 'is not', 'test_1_2')
        test_1_1b = self.dm.udi_from_kw(UniqueTestIdentifier,
                                        device_class='test',
                                        port='/interfaces/com1',
                                        address=1)
        test_1_2b = self.dm.udi_from_kw(UniqueTestIdentifier,
                                        device_class='test',
                                        port='/interfaces/com1',
                                        address=2)
        test_2_1b = self.dm.udi_from_kw(UniqueTestIdentifier,
                                        device_class='test',
                                        port='/interfaces/com2',
                                        address=1)
        test_2_2b = self.dm.udi_from_kw(UniqueTestIdentifier,
                                        device_class='test',
                                        port='/interfaces/com2',
                                        address=2)
        self.assert_comparison('test_1_1', 'is', 'test_1_1b')
        self.assert_comparison('test_1_2', 'is', 'test_1_2b')
        self.assert_comparison('test_2_1', 'is', 'test_2_1b')
        self.assert_comparison('test_2_2', 'is', 'test_2_2b')
        return

    def test_monitor_from_methods_and_start(self):
        self.add_dm()
        monitor1 = self.dm.monitor_from_kw(UniqueDeviceIdentifier,
                                           device_class='udi')
        monitor2 = self.dm.monitor_from_kw(UniqueDeviceIdentifier,
                                           device_class='udi')
        self.assert_comparison('monitor2', 'is', 'monitor1')
        monitor_1_1 = self.dm.monitor_from_kw(UniqueTestIdentifier,
                                              device_class='test',
                                              port='/interfaces/com1',
                                              address=1)
        monitor_1_2 = self.dm.monitor_from_kw(UniqueTestIdentifier,
                                              device_class='test',
                                              port='/interfaces/com1',
                                              address=2)
        self.assert_comparison('monitor_1_1', 'is not', 'monitor_1_2')
        monitor_2_1 = self.dm.monitor_from_udi(
            UniqueTestIdentifier(device_class='test',
                                 port='/interfaces/com2',
                                 address=1))
        monitor_2_2 = self.dm.monitor_from_udi(
            UniqueTestIdentifier(device_class='test',
                                 port='/interfaces/com2',
                                 address=2))
        self.assert_comparison('monitor_2_1', 'is not', 'monitor_2_2')
        instance_list = [
            monitor1, monitor_1_1, monitor_1_2, monitor_2_1, monitor_2_2
        ]
        node_list = self.dm.dynamic_container().children_nodes()
        while node_list:
            node = node_list.pop()
            self.assert_comparison('node', 'in', 'instance_list')
            instance_list.remove(node)
        self.assert_comparison('instance_list', '==', '[]')
        # Start will cause the monitors to "register" with the Device Manager.
        as_internal_node('/').start()
        return

    def test_start(self):
        self.add_dm()
        self.dm.start()
        return
Exemplo n.º 7
0
Arquivo: main.py Projeto: nemani/IDS
import builtins
import argparse
from manager import DeviceManager

parser = argparse.ArgumentParser(description='Start a new Device Simulator')
parser.add_argument('--broker',
                    type=str,
                    help='Broker Host to connect to',
                    required=True)

args = parser.parse_args()
manager = DeviceManager(args.broker)

builtins.manager = manager
from app import app

if __name__ == "__main__":
    manager.client.loop_start()
    app.run(debug=False)