Esempio n. 1
0
    def create_config(self, coord_address):
        host_config = self[coord_address.host]
        process_config = host_config[coord_address.process]
        component_config = process_config[coord_address.component]

        config = ConfigurationManager()
        self._update_config(config, self)
        self._update_config(config, host_config)
        self._update_config(config, process_config)
        self._update_config(config, component_config)
        config.append_value('deployment_dir', self.deployment_dir)
        return config
Esempio n. 2
0
 def setUp(self):
     # Initialize the experiment for testing.
     # We set the archimedes_real_device setting to False so that
     # it doesn't attempt to contact the real ip.
     self.cfg_manager = ConfigurationManager()
     self.cfg_manager._set_value("archimedes_real_device", False)
     self.cfg_manager._set_value("archimedes_instances", {
         "default": "http://localhost:8000",
         "second": "http://localhost:8001"
     })
     self.experiment = Archimedes(None, None, self.cfg_manager)
     self.lab_session_id = SessionId('my-session-id')
Esempio n. 3
0
    def create_config(self, coord_address):
        host_config = self[coord_address.host]
        process_config = host_config[coord_address.process]
        component_config = process_config[coord_address.component]

        config = ConfigurationManager()
        self._update_config(config, self)
        self._update_config(config, host_config)
        self._update_config(config, process_config)
        self._update_config(config, component_config)
        config.append_value('deployment_dir', self.deployment_dir)
        return config
    def setUp(self):
        self.cfg_manager = ConfigurationManager()
        self.cfg_manager.append_module(configuration_module)

        self.cfg_manager._set_value(configuration_doc.FACADE_TIMEOUT, 0.001)

        self.current_port = new_port()
        self.cfg_manager._set_value(configuration_doc.CORE_FACADE_PORT,
                                    self.current_port)

        app = HelloWorldApp()
        self.server = wsgi_manager.WebLabWsgiServer(self.cfg_manager,
                                                    application=app)
Esempio n. 5
0
    def on_dir(directory, configuration_files, configuration_values):
        parser = argparse.ArgumentParser(usage='%(prog)s locations DIR [options]')
        parser.add_argument('--redownload', action='store_true', help='Force redownload of databases')
        parser.add_argument('--reset-database', action='store_true', help='Reset the database, forcing the server to download all the data again')
        parser.add_argument('--reset-cache', action='store_true', help='Reset the database, forcing the server to download all the data again')
        args = parser.parse_args(sys.argv[3:])

        config = ConfigurationManager.create(directory, configuration_files, configuration_values)

        for filename in 'GeoLite2-Country.mmdb', 'GeoLite2-City.mmdb':
            if os.path.exists(filename):
                print("Found %s" % filename)
                if args.redownload:
                    print("Redownloading...")
            else:
                print("%s not found. Downloading..." % filename)

            if args.redownload or not os.path.exists(filename):
                r = requests.get("http://geolite.maxmind.com/download/geoip/database/%s.gz" % filename)
                open('%s.gz' % filename,'w').write(r.content)
                uncompressed = gzip.open('%s.gz' % filename).read()
                open(filename, 'w').write(uncompressed)
                print("Downloaded")

        db = DatabaseGateway(config)

        if args.reset_database:
            print("Resetting database")
            db.reset_locations_database()

        if args.reset_cache:
            print("Resetting cache")
            db.reset_locations_cache()
Esempio n. 6
0
    def on_dir(directory, configuration_files, configuration_values):
        parser = argparse.ArgumentParser(usage='%(prog)s locations DIR [options]')
        parser.add_argument('--redownload', action='store_true', help='Force redownload of databases')
        parser.add_argument('--reset-database', action='store_true', help='Reset the database, forcing the server to download all the data again')
        parser.add_argument('--reset-cache', action='store_true', help='Reset the database, forcing the server to download all the data again')
        args = parser.parse_args(sys.argv[3:])

        config = ConfigurationManager.create(directory, configuration_files, configuration_values)

        for filename in 'GeoLite2-Country.mmdb', 'GeoLite2-City.mmdb':
            if os.path.exists(filename):
                print("Found %s" % filename)
                if args.redownload:
                    print("Redownloading...")
            else:
                print("%s not found. Downloading..." % filename)

            if args.redownload or not os.path.exists(filename):
                r = requests.get("http://geolite.maxmind.com/download/geoip/database/%s.gz" % filename)
                open('%s.gz' % filename,'wb').write(r.content)
                uncompressed = gzip.open('%s.gz' % filename).read()
                open(filename, 'wb').write(uncompressed)
                print("Downloaded")

        db = DatabaseGateway(config)

        if args.reset_database:
            print("Resetting database")
            db.reset_locations_database()

        if args.reset_cache:
            print("Resetting cache")
            db.reset_locations_cache()
Esempio n. 7
0
    def test_unknown_instance(self):
        """
        Check that it replies an error if the instance isn't in the config.
        """
        self.cfg_manager = ConfigurationManager()
        self.cfg_manager._set_value("archimedes_instances", {
            "first": "http://localhost:8000",
            "second": "http://localhost:8001"
        })
        self.experiment = Archimedes(None, None, self.cfg_manager)
        start = self.experiment.do_start_experiment("{}", "{}")

        up_resp = self.experiment.do_send_command_to_device("UP")
        assert up_resp.startswith("ERROR:")

        up_resp = self.experiment.do_send_command_to_device("default:UP")
        assert up_resp.startswith("ERROR:")
 def setUp(self):
     # Initialize the experiment for testing.
     # We set the archimedes_real_device setting to False so that
     # it doesn't attempt to contact the real ip.
     self.cfg_manager = ConfigurationManager()
     self.cfg_manager._set_value("archimedes_real_device", False)
     self.cfg_manager._set_value("archimedes_instances", {"default": "http://localhost:8000", "second": "http://localhost:8001"})
     self.experiment = Archimedes(None, None, self.cfg_manager)
     self.lab_session_id = SessionId('my-session-id')
    def setUp(self):
        self.cfg_manager = ConfigurationManager()
        self.cfg_manager.append_module(configuration_module)

        self.cfg_manager._set_value(configuration_doc.FACADE_TIMEOUT, 0.001)

        self.current_port = new_port()
        self.cfg_manager._set_value(configuration_doc.CORE_FACADE_PORT, self.current_port)

        app = HelloWorldApp()
        self.server = wsgi_manager.WebLabWsgiServer(self.cfg_manager,  application = app)
Esempio n. 10
0
class WsgiManagerTest(unittest.TestCase):
    def setUp(self):
        self.cfg_manager = ConfigurationManager()
        self.cfg_manager.append_module(configuration_module)

        self.cfg_manager._set_value(configuration_doc.FACADE_TIMEOUT, 0.001)

        self.current_port = new_port()
        self.cfg_manager._set_value(configuration_doc.CORE_FACADE_PORT,
                                    self.current_port)

        app = HelloWorldApp()
        self.server = wsgi_manager.WebLabWsgiServer(self.cfg_manager,
                                                    application=app)

    @uses_module(wsgi_manager)
    def test_server(self):
        self.server.start()
        try:
            time.sleep(0.1)
            text = requests.get('http://127.0.0.1:%s/' % self.current_port,
                                timeout=10).text
            self.assertEquals("Hello World\n", text)
        finally:
            self.server.stop()
Esempio n. 11
0
    def test_unknown_instance(self):
        """
        Check that it replies an error if the instance isn't in the config.
        """
        self.cfg_manager = ConfigurationManager()
        self.cfg_manager._set_value("archimedes_instances", {"first": "http://localhost:8000", "second": "http://localhost:8001"})
        self.experiment = Archimedes(None, None, self.cfg_manager)
        start = self.experiment.do_start_experiment("{}", "{}")

        up_resp = self.experiment.do_send_command_to_device("UP")
        assert up_resp.startswith("ERROR:")

        up_resp = self.experiment.do_send_command_to_device("default:UP")
        assert up_resp.startswith("ERROR:")
class WsgiManagerTest(unittest.TestCase):
    def setUp(self):
        self.cfg_manager = ConfigurationManager()
        self.cfg_manager.append_module(configuration_module)

        self.cfg_manager._set_value(configuration_doc.FACADE_TIMEOUT, 0.001)

        self.current_port = new_port()
        self.cfg_manager._set_value(configuration_doc.CORE_FACADE_PORT, self.current_port)

        app = HelloWorldApp()
        self.server = wsgi_manager.WebLabWsgiServer(self.cfg_manager,  application = app)


    @uses_module(wsgi_manager)
    def test_server(self):
        self.server.start()
        try:
            time.sleep(0.1)
            text = requests.get('http://127.0.0.1:%s/' % self.current_port, timeout = 10).text
            self.assertEquals("Hello World\n", text)
        finally:
            self.server.stop()
Esempio n. 13
0
class WsgiManagerTest(unittest.TestCase):
    def setUp(self):
        self.cfg_manager = ConfigurationManager()
        self.cfg_manager.append_module(configuration_module)

        self.cfg_manager._set_value(configuration_doc.FACADE_TIMEOUT, 0.001)

        self.current_port = new_port()
        # TODO
        self.cfg_manager._set_value(configuration_doc.CORE_FACADE_PORT, self.current_port)

        app = HelloWorldApp()
        self.server = wsgi_manager.WebLabWsgiServer(self.cfg_manager,  application = app)


    @uses_module(wsgi_manager)
    def test_mofa(self):
        self.server.start()
        try:
            text = urllib2.urlopen('http://127.0.0.1:%s/' % self.current_port).read()
            self.assertEquals("Hello World\n", text)
        finally:
            self.server.stop()
 def setUp(self):
     cfg_manager = ConfigurationManager()
     cfg_manager.append_module(configuration_module)
     self.device = digilent_adept.DigilentAdept(cfg_manager)
Esempio n. 15
0
                pass
        return None


#############################################
# 
# The code below is only used for testing
# 

if __name__ == '__main__':
    from voodoo.configuration import ConfigurationManager
    from weblab.core.server import UserProcessingServer
    from weblab.core.i18n import initialize_i18n
    from flask_debugtoolbar import DebugToolbarExtension

    cfg_manager = ConfigurationManager()
    cfg_manager.append_path('test/unit/configuration.py')

    ups = UserProcessingServer(None, None, cfg_manager, dont_start = True)

    app = Flask('weblab.core.server')
    app.config['SECRET_KEY'] = os.urandom(32)
    app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False
    app.config['DEBUG'] = True

    @app.route("/site-map")
    def site_map():
        lines = []
        for rule in app.url_map.iter_rules():
            line = str(escape(repr(rule)))
            lines.append(line)
Esempio n. 16
0
class TestArchimedes(unittest.TestCase):

    def setUp(self):
        # Initialize the experiment for testing.
        # We set the archimedes_real_device setting to False so that
        # it doesn't attempt to contact the real ip.
        self.cfg_manager = ConfigurationManager()
        self.cfg_manager._set_value("archimedes_real_device", False)
        self.cfg_manager._set_value("archimedes_instances", {"default": "http://localhost:8000", "second": "http://localhost:8001"})
        self.experiment = Archimedes(None, None, self.cfg_manager)
        self.lab_session_id = SessionId('my-session-id')

    def tearDown(self):
        self.experiment.do_dispose()

    def test_start(self):
        m = MagicMock(return_value="")
        self.experiment._send = m
        start = self.experiment.do_start_experiment("{}", "{}")

        assert m.mock_calls[0][1][1] == "up"
        assert m.mock_calls[1][1][1] == "up"

    def test_unknown_instance(self):
        """
        Check that it replies an error if the instance isn't in the config.
        """
        self.cfg_manager = ConfigurationManager()
        self.cfg_manager._set_value("archimedes_instances", {"first": "http://localhost:8000", "second": "http://localhost:8001"})
        self.experiment = Archimedes(None, None, self.cfg_manager)
        start = self.experiment.do_start_experiment("{}", "{}")

        up_resp = self.experiment.do_send_command_to_device("UP")
        assert up_resp.startswith("ERROR:")

        up_resp = self.experiment.do_send_command_to_device("default:UP")
        assert up_resp.startswith("ERROR:")

    def test_control_ball_commands(self):
        start = self.experiment.do_start_experiment("{}", "{}")
        up_resp = self.experiment.do_send_command_to_device("UP")
        down_resp = self.experiment.do_send_command_to_device("DOWN")
        slow_resp = self.experiment.do_send_command_to_device("SLOW")

    def test_basic_data_commands(self):
        start = self.experiment.do_start_experiment("{}", "{}")
        level_resp = self.experiment.do_send_command_to_device("LEVEL")
        assert float(level_resp) == 1200

        load_resp = self.experiment.do_send_command_to_device("LOAD")
        assert float(load_resp) == 1300

    def test_advanced_data_commands(self):
        start = self.experiment.do_start_experiment("{}", "{}")
        image_resp = self.experiment.do_send_command_to_device("IMAGE")
        dec = base64.b64decode(image_resp)
        assert len(dec) > 100

        plot_resp = self.experiment.do_send_command_to_device("PLOT")

        f = file("/tmp/img.html", "w+")
        f.write("""
            <html><body><img alt="embedded" src="data:image/jpg;base64,%s"/></body></html>
            """ % (image_resp)
        )
        f.close()

    def test_explicit_instance_commands(self):
        """
        Test that commands can be sent to a specific instance.
        """
        start = self.experiment.do_start_experiment("{}", "{}")
        up_resp = self.experiment.do_send_command_to_device("default:UP")
        down_resp = self.experiment.do_send_command_to_device("default:DOWN")
        slow_resp = self.experiment.do_send_command_to_device("default:SLOW")
        level_resp = self.experiment.do_send_command_to_device("default:LEVEL")
        assert float(level_resp) == 1200
        load_resp = self.experiment.do_send_command_to_device("default:LOAD")
        assert float(load_resp) == 1300

    def test_allinfo_command(self):
        start = self.experiment.do_start_experiment("{}", "{}")
        resp = self.experiment.do_send_command_to_device("ALLINFO:default")
        r = json.loads(resp)
        assert float(r["default"]["level"]) == 1200
        assert float(r["default"]["load"]) == 1300

    def test_allinfo_command_multiple(self):
        start = self.experiment.do_start_experiment("{}", "{}")
        resp = self.experiment.do_send_command_to_device("ALLINFO:default:second")
        r = json.loads(resp)
        assert float(r["default"]["level"]) == 1200
        assert float(r["default"]["load"]) == 1300

        assert float(r["second"]["level"]) == 1200
        assert float(r["second"]["load"]) == 1300
Esempio n. 17
0
 def setUp(self):
     cfg_manager = ConfigurationManager()
     cfg_manager.append_module(configuration_module)
     self.jtag_blazer = jtag_blazer.JTagBlazer(cfg_manager)
Esempio n. 18
0
 def setUp(self):
     cfg_manager = ConfigurationManager()
     cfg_manager.append_module(configuration_module)
     self.jtag_blazer = jtag_blazer.JTagBlazer(cfg_manager)
Esempio n. 19
0
            first_pump = 10
        else:
            first_pump = 0
        if second_pump:
            second_pump = 10
        else:
            second_pump = 0
        self._watertank.set_input(0, first_pump)
        self._watertank.set_input(1, second_pump)


if __name__ == "__main__":
    from voodoo.configuration import ConfigurationManager
    from voodoo.sessions.session_id import SessionId

    cfg_manager = ConfigurationManager()
    try:
        cfg_manager.append_path("../../../launch/sample/main_machine/main_instance/experiment_fpga/server_config.py")
    except:
        cfg_manager.append_path("../launch/sample/main_machine/main_instance/experiment_fpga/server_config.py")

    experiment = UdXilinxExperiment(None, None, cfg_manager)

    lab_session_id = SessionId("my-session-id")
    experiment.do_start_experiment()

    experiment._max_use_time = 10
    print experiment.do_send_command_to_device("REPORT_USE_TIME_LEFT")
    print experiment.do_send_command_to_device("STATE")
    print experiment.do_send_command_to_device("STATE")
    print experiment.do_should_finish()
Esempio n. 20
0
 def setUp(self):
     digilent_adept.DEBUG = False
     cfg_manager = ConfigurationManager()
     cfg_manager.append_module(configuration_module)
     self.device = digilent_adept.DigilentAdept(cfg_manager)
Esempio n. 21
0
            first_pump = 10
        else:
            first_pump = 0
        if second_pump:
            second_pump = 10
        else:
            second_pump = 0
        self._watertank.set_input(0, first_pump)
        self._watertank.set_input(1, second_pump)


if __name__ == "__main__":
    from voodoo.configuration import ConfigurationManager
    from voodoo.sessions.session_id import SessionId

    cfg_manager = ConfigurationManager()
    try:
        cfg_manager.append_path(
            "../../../launch/sample/main_machine/main_instance/experiment_fpga/server_config.py"
        )
    except:
        cfg_manager.append_path(
            "../launch/sample/main_machine/main_instance/experiment_fpga/server_config.py"
        )

    experiment = ElevatorExperiment(None, None, cfg_manager)

    lab_session_id = SessionId('my-session-id')
    experiment.do_start_experiment()

    experiment._max_use_time = 10
Esempio n. 22
0
        session_id = (request.cookies.get('weblabsessionid') or '').split('.')[0]
        try:
            with weblab_api(self.ups, session_id = session_id):
                return weblab.core.server.get_user_information()
        except SessionNotFoundError:
            return None

#############################################
# 
# The code below is only used for testing
# 

if __name__ == '__main__':
    from voodoo.configuration import ConfigurationManager
    from weblab.core.server import UserProcessingServer
    cfg_manager = ConfigurationManager()
    cfg_manager.append_path('test/unit/configuration.py')

    ups = UserProcessingServer(None, None, cfg_manager, dont_start = True)

    app = Flask('weblab.core.server')
    app.config['SECRET_KEY'] = os.urandom(32)
    @app.route("/site-map")
    def site_map():
        lines = []
        for rule in app.url_map.iter_rules():
            line = str(escape(repr(rule)))
            lines.append(line)

        ret = "<br>".join(lines)
        return ret
Esempio n. 23
0
class TestArchimedes(unittest.TestCase):
    def setUp(self):
        # Initialize the experiment for testing.
        # We set the archimedes_real_device setting to False so that
        # it doesn't attempt to contact the real ip.
        self.cfg_manager = ConfigurationManager()
        self.cfg_manager._set_value("archimedes_real_device", False)
        self.cfg_manager._set_value("archimedes_instances", {
            "default": "http://localhost:8000",
            "second": "http://localhost:8001"
        })
        self.experiment = Archimedes(None, None, self.cfg_manager)
        self.lab_session_id = SessionId('my-session-id')

    def tearDown(self):
        self.experiment.do_dispose()

    def test_start(self):
        m = MagicMock(return_value="")
        self.experiment._send = m
        start = self.experiment.do_start_experiment("{}", "{}")

        assert m.mock_calls[0][1][1] == "up"
        assert m.mock_calls[1][1][1] == "up"

    def test_unknown_instance(self):
        """
        Check that it replies an error if the instance isn't in the config.
        """
        self.cfg_manager = ConfigurationManager()
        self.cfg_manager._set_value("archimedes_instances", {
            "first": "http://localhost:8000",
            "second": "http://localhost:8001"
        })
        self.experiment = Archimedes(None, None, self.cfg_manager)
        start = self.experiment.do_start_experiment("{}", "{}")

        up_resp = self.experiment.do_send_command_to_device("UP")
        assert up_resp.startswith("ERROR:")

        up_resp = self.experiment.do_send_command_to_device("default:UP")
        assert up_resp.startswith("ERROR:")

    def test_control_ball_commands(self):
        start = self.experiment.do_start_experiment("{}", "{}")
        up_resp = self.experiment.do_send_command_to_device("UP")
        down_resp = self.experiment.do_send_command_to_device("DOWN")
        slow_resp = self.experiment.do_send_command_to_device("SLOW")

    def test_basic_data_commands(self):
        start = self.experiment.do_start_experiment("{}", "{}")
        level_resp = self.experiment.do_send_command_to_device("LEVEL")
        assert float(level_resp) == 1200

        load_resp = self.experiment.do_send_command_to_device("LOAD")
        assert float(load_resp) == 1300

    def test_advanced_data_commands(self):
        start = self.experiment.do_start_experiment("{}", "{}")
        image_resp = self.experiment.do_send_command_to_device("IMAGE")
        dec = base64.b64decode(image_resp)
        assert len(dec) > 100

        plot_resp = self.experiment.do_send_command_to_device("PLOT")

        f = file("/tmp/img.html", "w+")
        f.write("""
            <html><body><img alt="embedded" src="data:image/jpg;base64,%s"/></body></html>
            """ % (image_resp))
        f.close()

    def test_explicit_instance_commands(self):
        """
        Test that commands can be sent to a specific instance.
        """
        start = self.experiment.do_start_experiment("{}", "{}")
        up_resp = self.experiment.do_send_command_to_device("default:UP")
        down_resp = self.experiment.do_send_command_to_device("default:DOWN")
        slow_resp = self.experiment.do_send_command_to_device("default:SLOW")
        level_resp = self.experiment.do_send_command_to_device("default:LEVEL")
        assert float(level_resp) == 1200
        load_resp = self.experiment.do_send_command_to_device("default:LOAD")
        assert float(load_resp) == 1300

    def test_allinfo_command(self):
        start = self.experiment.do_start_experiment("{}", "{}")
        resp = self.experiment.do_send_command_to_device("ALLINFO:default")
        r = json.loads(resp)
        assert float(r["default"]["level"]) == 1200
        assert float(r["default"]["load"]) == 1300

    def test_allinfo_command_multiple(self):
        start = self.experiment.do_start_experiment("{}", "{}")
        resp = self.experiment.do_send_command_to_device(
            "ALLINFO:default:second")
        r = json.loads(resp)
        assert float(r["default"]["level"]) == 1200
        assert float(r["default"]["load"]) == 1300

        assert float(r["second"]["level"]) == 1200
        assert float(r["second"]["load"]) == 1300