Example #1
0
def main(args_string=None):
    p = argparse.ArgumentParser(prog='Paradrop', description='Paradrop API server running on client')
    p.add_argument('-s', '--settings', help='Overwrite settings, format is "KEY:VALUE"',
                   action='append', type=str, default=[])
    p.add_argument('--config', help='Run as the configuration daemon',
                   action='store_true')
    p.add_argument('--mode', '-m', help='Set the mode to one of [development, production, test, local]',
                   action='store', type=str, default='production')

    # Things to replace
    p.add_argument('--local', '-l', help='Run on local machine', action='store_true')
    p.add_argument('--development', help='Enable the development environment variables',
                   action='store_true')

    # No longer used
    p.add_argument('--unittest', help="Run the server in unittest mode", action='store_true')
    p.add_argument('--verbose', '-v', help='Enable verbose', action='store_true')

    # Some very strange formatting going on here when passing in (from go :())
    if args_string is None:
        args = p.parse_args()
    else:
        args_string = args_string if args_string == "" else args_string.split(" ")
        args = p.parse_args(args_string)

    # TESTING
    args.local = True

    # Temp- this should go to nexus (the settings portion of it, at least)
    # Change the confd directories so we can run locally
    if args.local:
        settings.PDCONFD_WRITE_DIR = "/tmp/pdconfd"
        settings.UCI_CONFIG_DIR = "/tmp/config.d"
        settings.HOST_CONFIG_PATH = "/tmp/hostconfig.yaml"

    # Check for settings to overwrite (MOVE TO NEXUS)
    settings.updateSettings(args.settings)

    # Globally assign the nexus object so anyone else can access it.
    # Sorry, programming gods. If it makes you feel better this class
    # replaces about half a dozen singletons
    nexus.core = Nexus(args.mode, settings=args.settings)

    if args.config:
        from paradrop.backend import pdconfd

        # Start the configuration daemon
        pdconfd.main.run_pdconfd()

    else:
        from paradrop.backend import pdconfd
        from paradrop.backend import pdfcd

        # Start the configuration service as a thread
        pdconfd.main.run_thread()

        # Now setup the RESTful API server for Paradrop
        pdfcd.server.setup(args)
Example #2
0
def test_update_settings():
    """
    Test updateSettings function
    """
    from paradrop.lib import settings

    with patch.dict(os.environ, {'PDFCD_PORT': '-1'}):
        settings.updateSettings(["PD_TEST_VAR:stuff"])

        assert settings.PD_TEST_VAR == "stuff"
        assert settings.PDFCD_PORT == -1

    with patch.dict(os.environ, {'SNAP_APP_DATA_PATH': '/stuff'}):
        settings.updateSettings()

        assert settings.FC_CHUTESTORAGE_SAVE_PATH.startswith("/stuff")
        assert settings.UCI_CONFIG_DIR.startswith("/stuff")