Ejemplo n.º 1
0
def _create_application_from_class(
        application_class,
        command_line_config=None,
        file_config=None,
        environment_config=None):

    if file_config is None:
        file_config = FileConfig()
        file_config.database_class = \
            'remoteappmanager.tests.mocking.dummy.DummyDB'
        file_config.database_kwargs = {}

    if command_line_config is None:
        command_line_config = basic_command_line_config()

    if environment_config is not None:
        environment_config = basic_environment_config()

    app = application_class(
        command_line_config,
        file_config,
        environment_config)

    app.hub = create_hub()
    app.reverse_proxy = create_reverse_proxy()
    app.container_manager = create_container_manager()

    return app
Ejemplo n.º 2
0
def _create_application_from_class(application_class,
                                   command_line_config=None,
                                   file_config=None,
                                   environment_config=None):

    if file_config is None:
        file_config = FileConfig()
        file_config.database_class = \
            'remoteappmanager.tests.mocking.dummy.DummyDB'
        file_config.database_kwargs = {}

    if command_line_config is None:
        command_line_config = basic_command_line_config()

    if environment_config is not None:
        environment_config = basic_environment_config()

    app = application_class(command_line_config, file_config,
                            environment_config)

    app.hub = create_hub()
    app.reverse_proxy = create_reverse_proxy()
    app.container_manager = create_container_manager()

    return app
Ejemplo n.º 3
0
    def test_ga_tracking(self):
        with open(self.config_file, 'w') as fhandle:
            print(GA_TRACKING, file=fhandle)

        config = FileConfig()
        config.parse_config(self.config_file)

        self.assertEqual(config.ga_tracking_id, 'UA-12345-6')
Ejemplo n.º 4
0
    def test_ga_tracking(self):
        with open(self.config_file, 'w') as fhandle:
            print(GA_TRACKING, file=fhandle)

        config = FileConfig()
        config.parse_config(self.config_file)

        self.assertEqual(config.ga_tracking_id, 'UA-12345-6')
Ejemplo n.º 5
0
    def test_initialization_with_default_accounting(self):
        with open(self.config_file, 'w') as fhandle:
            print(DOCKER_CONFIG, file=fhandle)

        config = FileConfig()
        config.parse_config(self.config_file)

        self.assertEqual(config.docker_host, "https://192.168.99.100:2376")
        self.assertEqual(config.docker_realm, "myrealm")
Ejemplo n.º 6
0
    def test_initialization_with_default_accounting(self):
        with open(self.config_file, 'w') as fhandle:
            print(DOCKER_CONFIG, file=fhandle)

        config = FileConfig()
        config.parse_config(self.config_file)

        self.assertEqual(config.docker_host, "https://192.168.99.100:2376")
        self.assertEqual(config.docker_realm, "myrealm")
Ejemplo n.º 7
0
    def test_file_parsing_not_overriding_bug_131(self):
        docker_config = textwrap.dedent('''
            tls = True
            ''')
        with open(self.config_file, 'w') as fhandle:
            print(docker_config, file=fhandle)

        config = FileConfig()
        config.parse_config(self.config_file)
        self.assertNotEqual(config.tls_key, '')
        self.assertNotEqual(config.tls_cert, '')
Ejemplo n.º 8
0
    def test_file_parsing_not_overriding_bug_131(self):
        docker_config = textwrap.dedent('''
            tls = True
            ''')
        with open(self.config_file, 'w') as fhandle:
            print(docker_config, file=fhandle)

        config = FileConfig()
        config.parse_config(self.config_file)
        self.assertNotEqual(config.tls_key, '')
        self.assertNotEqual(config.tls_cert, '')
Ejemplo n.º 9
0
    def test_initialization_with_good_accounting(self):
        with open(self.config_file, 'w') as fhandle:
            print(DOCKER_CONFIG, file=fhandle)
            print(GOOD_ACCOUNTING_CONFIG, file=fhandle)

        config = FileConfig()
        config.parse_config(self.config_file)

        self.assertEqual(config.database_class,
                         "remoteappmanager.db.csv_db.CSVDatabase")
        self.assertDictEqual(config.database_kwargs,
                             {"csv_file_path": "file_path.csv"})
Ejemplo n.º 10
0
    def test_initialization_with_good_accounting(self):
        with open(self.config_file, 'w') as fhandle:
            print(DOCKER_CONFIG, file=fhandle)
            print(GOOD_ACCOUNTING_CONFIG, file=fhandle)

        config = FileConfig()
        config.parse_config(self.config_file)

        self.assertEqual(config.database_class,
                         "remoteappmanager.db.csv_db.CSVDatabase")
        self.assertDictEqual(config.database_kwargs,
                             {"csv_file_path": "file_path.csv"})
Ejemplo n.º 11
0
    def test_overriding(self):
        envs = {"DOCKER_HOST": "tcp://192.168.99.100:12345",
                "DOCKER_TLS_VERIFY": "1",
                "DOCKER_CERT_PATH": self.tempdir}

        with envvars(envs):
            config = FileConfig()
            config.tls = False
            config.tls_verify = False
            config.docker_host = "tcp://192.168.99.100:31337"
            docker_config = config.docker_config()
            self.assertNotIn("tls", docker_config)
            self.assertEqual(docker_config["base_url"],
                             "tcp://192.168.99.100:31337")
Ejemplo n.º 12
0
def main():    # pragma: no cover
    try:
        command_line_config = CommandLineConfig()
        command_line_config.parse_config()
        file_config = FileConfig()

        if command_line_config.config_file:
            file_config.parse_config(command_line_config.config_file)

        environment_config = EnvironmentConfig()
        environment_config.parse_config()

    except Exception as e:
        print_help()
        print("Error: {}".format(e))
        sys.exit(1)

    app = Application(command_line_config, file_config, environment_config)
    app.start()
Ejemplo n.º 13
0
def main():  # pragma: no cover
    try:
        command_line_config = CommandLineConfig()
        command_line_config.parse_config()
        file_config = FileConfig()

        if command_line_config.config_file:
            file_config.parse_config(command_line_config.config_file)

        environment_config = EnvironmentConfig()
        environment_config.parse_config()

    except Exception as e:
        print_help()
        print("Error: {}".format(e))
        sys.exit(1)

    app = Application(command_line_config, file_config, environment_config)
    app.start()
Ejemplo n.º 14
0
    def test_tls_no_verify(self):
        docker_config_tls = textwrap.dedent('''
        tls = True
        tls_verify = False
        tls_cert = '{}'
        tls_key = '{}'
        docker_host = "tcp://192.168.99.100:2376"
        '''.format(os.path.join(self.tempdir, "cert.pem"),
                   os.path.join(self.tempdir, "key.pem")))

        with open(self.config_file, 'w') as fhandle:
            print(docker_config_tls, file=fhandle)

        config = FileConfig()
        config.parse_config(self.config_file)
        docker_dict = config.docker_config()
        self.assertIn("tls", docker_dict)
        self.assertEqual(docker_dict["tls"].verify, False)
        self.assertEqual(docker_dict["tls"].ca_cert, None)
Ejemplo n.º 15
0
    def test_tls_no_verify(self):
        docker_config_tls = textwrap.dedent('''
        tls = True
        tls_verify = False
        tls_cert = '{}'
        tls_key = '{}'
        docker_host = "tcp://192.168.99.100:2376"
        '''.format(
            os.path.join(self.tempdir, "cert.pem"),
            os.path.join(self.tempdir, "key.pem")))

        with open(self.config_file, 'w') as fhandle:
            print(docker_config_tls, file=fhandle)

        config = FileConfig()
        config.parse_config(self.config_file)
        docker_dict = config.docker_config()
        self.assertIn("tls", docker_dict)
        self.assertEqual(docker_dict["tls"].verify, False)
        self.assertEqual(docker_dict["tls"].ca_cert, None)
Ejemplo n.º 16
0
 def test_initialization_on_local_docker_machine(self):
     envs = {
         "DOCKER_HOST": "",
         "DOCKER_TLS_VERIFY": "",
         "DOCKER_CERT_PATH": ""
     }
     with envvars(envs):
         config = FileConfig()
         # False by default, as we don't want CA verification
         self.assertEqual(config.tls, False)
         self.assertEqual(config.tls_verify, False)
         self.assertEqual(config.docker_host, 'unix://var/run/docker.sock')
Ejemplo n.º 17
0
    def test_initialization_on_nonlocal_docker_machine(self):
        envs = {"DOCKER_HOST": "tcp://192.168.99.100:12345",
                "DOCKER_TLS_VERIFY": "1",
                "DOCKER_CERT_PATH": self.tempdir}

        with envvars(envs):
            config = FileConfig()
            self.assertEqual(config.tls, True)
            self.assertEqual(config.tls_verify, True)
            self.assertEqual(config.tls_ca,
                             os.path.join(self.tempdir, "ca.pem"))
            self.assertEqual(config.tls_cert,
                             os.path.join(self.tempdir, "cert.pem"))
            self.assertEqual(config.tls_key,
                             os.path.join(self.tempdir, "key.pem"))
            self.assertEqual(config.docker_host,
                             "https://192.168.99.100:12345")
            docker_conf = config.docker_config()
            self.assertIn("tls", docker_conf)
            self.assertEqual(docker_conf["tls"].verify, True)
            self.assertEqual(docker_conf["tls"].ca_cert,
                             os.path.join(self.tempdir, "ca.pem"))
Ejemplo n.º 18
0
    def test_initialization_on_nonlocal_docker_machine(self):
        envs = {
            "DOCKER_HOST": "tcp://192.168.99.100:12345",
            "DOCKER_TLS_VERIFY": "1",
            "DOCKER_CERT_PATH": self.tempdir
        }

        with envvars(envs):
            config = FileConfig()
            self.assertEqual(config.tls, True)
            self.assertEqual(config.tls_verify, True)
            self.assertEqual(config.tls_ca,
                             os.path.join(self.tempdir, "ca.pem"))
            self.assertEqual(config.tls_cert,
                             os.path.join(self.tempdir, "cert.pem"))
            self.assertEqual(config.tls_key,
                             os.path.join(self.tempdir, "key.pem"))
            self.assertEqual(config.docker_host,
                             "https://192.168.99.100:12345")
            docker_conf = config.docker_config()
            self.assertIn("tls", docker_conf)
            self.assertEqual(docker_conf["tls"].verify, True)
            self.assertEqual(docker_conf["tls"].ca_cert,
                             os.path.join(self.tempdir, "ca.pem"))
Ejemplo n.º 19
0
    def test_overriding(self):
        envs = {
            "DOCKER_HOST": "tcp://192.168.99.100:12345",
            "DOCKER_TLS_VERIFY": "1",
            "DOCKER_CERT_PATH": self.tempdir
        }

        with envvars(envs):
            config = FileConfig()
            config.tls = False
            config.tls_verify = False
            config.docker_host = "tcp://192.168.99.100:31337"
            docker_config = config.docker_config()
            self.assertNotIn("tls", docker_config)
            self.assertEqual(docker_config["base_url"],
                             "tcp://192.168.99.100:31337")
Ejemplo n.º 20
0
 def get_file_config(self):
     file_config = FileConfig()
     file_config.database_class = \
         'remoteappmanager.tests.mocking.dummy.DummyDB'
     file_config.database_kwargs = {}
     return file_config
Ejemplo n.º 21
0
def basic_file_config():
    return FileConfig()
Ejemplo n.º 22
0
 def get_file_config(self):
     file_config = FileConfig()
     file_config.database_class = \
         'remoteappmanager.tests.mocking.dummy.DummyDB'
     file_config.database_kwargs = {}
     return file_config
Ejemplo n.º 23
0
    def test_if_docker_config_result_is_acceptable_for_dockerpy(self):
        config = FileConfig()
        docker_config = config.docker_config()

        with contextlib.closing(docker.Client(**docker_config)) as client:
            self.assertIsNotNone(client.info())
Ejemplo n.º 24
0
    def test_if_docker_config_result_is_acceptable_for_dockerpy(self):
        config = FileConfig()
        docker_config = config.docker_config()

        with contextlib.closing(docker.Client(**docker_config)) as client:
            self.assertIsNotNone(client.info())
Ejemplo n.º 25
0
 def test_tls_init(self):
     config = FileConfig(tls=True)
     self.assertNotEqual(config.tls_key, '')
     self.assertNotEqual(config.tls_cert, '')