Пример #1
0
 def __init__(self, root: str, config: Config):
     """
     Load docker-compose files from dev/ and local/
     """
     super().__init__(root, config)
     self.project_name = get_typed(self.config, "DEV_PROJECT_NAME", str)
     self.docker_compose_tmp_path = tutor_env.pathjoin(
         self.root, "dev", "docker-compose.tmp.yml"
     )
     self.docker_compose_jobs_tmp_path = tutor_env.pathjoin(
         self.root, "dev", "docker-compose.jobs.tmp.yml"
     )
     self.docker_compose_files += [
         tutor_env.pathjoin(self.root, "local", "docker-compose.yml"),
         tutor_env.pathjoin(self.root, "dev", "docker-compose.yml"),
         self.docker_compose_tmp_path,
         tutor_env.pathjoin(self.root, "local", "docker-compose.override.yml"),
         tutor_env.pathjoin(self.root, "dev", "docker-compose.override.yml"),
     ]
     self.docker_compose_job_files += [
         tutor_env.pathjoin(self.root, "local", "docker-compose.jobs.yml"),
         tutor_env.pathjoin(self.root, "dev", "docker-compose.jobs.yml"),
         self.docker_compose_jobs_tmp_path,
         tutor_env.pathjoin(self.root, "local", "docker-compose.jobs.override.yml"),
         tutor_env.pathjoin(self.root, "dev", "docker-compose.jobs.override.yml"),
     ]
Пример #2
0
def get_enabled_plugins(config: Config) -> t.List[str]:
    """
    Return the list of plugins that are enabled, as per the configuration. Note that
    this may differ from the list of loaded plugins. For instance when a plugin is
    present in the configuration but it's not installed.
    """
    return get_typed(config, PLUGINS_CONFIG_KEY, list, [])
Пример #3
0
def resource_selector(config: Config, *selectors: str) -> List[str]:
    """
    Convenient utility to filter the resources that belong to this project.
    """
    selector = ",".join(
        ["app.kubernetes.io/instance=openedx-" +
         get_typed(config, "ID", str)] + list(selectors))
    return resource_namespace_selector(config) + ["--selector=" + selector]
Пример #4
0
    def test_configure_set_random_string(self) -> None:
        config: Config = {}

        class plugin1:
            config: Config = {"set": {"PARAM1": "{{ 128|random_string }}"}}

        with patch.object(
                plugins.Plugins,
                "iter_enabled",
                return_value=[plugins.BasePlugin("plugin1", plugin1)],
        ):
            tutor_config.load_plugins(config, {})
        self.assertEqual(128, len(get_typed(config, "PARAM1", str)))
Пример #5
0
    def test_interactive(self) -> None:
        def mock_prompt(*_args: None, **kwargs: str) -> str:
            return kwargs["default"]

        with tempfile.TemporaryDirectory() as rootdir:
            with patch.object(click, "prompt", new=mock_prompt):
                with patch.object(click, "confirm", new=mock_prompt):
                    config = interactive.load_user_config(rootdir,
                                                          interactive=True)

        self.assertIn("MYSQL_ROOT_PASSWORD", config)
        self.assertEqual(8, len(get_typed(config, "MYSQL_ROOT_PASSWORD", str)))
        self.assertEqual("www.myopenedx.com", config["LMS_HOST"])
        self.assertEqual("studio.www.myopenedx.com", config["CMS_HOST"])
Пример #6
0
    def test_configure_set_random_string(self) -> None:
        plugins_v0.DictPlugin({
            "name": "plugin1",
            "config": {
                "set": {
                    "PARAM1": "{{ 128|random_string }}"
                }
            },
        })
        plugins.load("plugin1")
        config = tutor_config.get_base()
        tutor_config.render_full(config)

        self.assertEqual(128, len(get_typed(config, "PARAM1", str)))
Пример #7
0
    def test_interactive(self) -> None:
        def mock_prompt(*_args: None, **kwargs: str) -> str:
            return kwargs["default"]

        with temporary_root() as rootdir:
            with patch.object(click, "prompt", new=mock_prompt):
                with patch.object(click, "confirm", new=mock_prompt):
                    config = tutor_config.load_minimal(rootdir)
                    interactive.ask_questions(config)

        self.assertIn("MYSQL_ROOT_PASSWORD", config)
        self.assertEqual(8, len(get_typed(config, "MYSQL_ROOT_PASSWORD", str)))
        self.assertEqual("www.myopenedx.com", config["LMS_HOST"])
        self.assertEqual("studio.www.myopenedx.com", config["CMS_HOST"])
Пример #8
0
def get_all_openedx_domains(config: Config) -> t.List[str]:
    return [
        get_typed(config, "LMS_HOST", str),
        get_typed(config, "LMS_HOST", str) + ":8000",
        get_typed(config, "CMS_HOST", str),
        get_typed(config, "CMS_HOST", str) + ":8001",
        get_typed(config, "PREVIEW_LMS_HOST", str),
        get_typed(config, "PREVIEW_LMS_HOST", str) + ":8000",
    ]
Пример #9
0
    def test_configure_add_twice(self) -> None:
        config: Config = {}

        class plugin1:
            config: Config = {"add": {"PARAM1": "{{ 10|random_string }}"}}

        with patch.object(
                plugins.Plugins,
                "iter_enabled",
                return_value=[plugins.BasePlugin("plugin1", plugin1)],
        ):
            tutor_config.load_plugins(config, {})
        value1 = get_typed(config, "PLUGIN1_PARAM1", str)
        with patch.object(
                plugins.Plugins,
                "iter_enabled",
                return_value=[plugins.BasePlugin("plugin1", plugin1)],
        ):
            tutor_config.load_plugins(config, {})
        value2 = get_typed(config, "PLUGIN1_PARAM1", str)

        self.assertEqual(10, len(value1))
        self.assertEqual(10, len(value2))
        self.assertEqual(value1, value2)
Пример #10
0
    def test_config_load_from_plugins(self) -> None:
        config: Config = {}

        class plugin1:
            config: Config = {"add": {"PARAM1": "{{ 10|random_string }}"}}

        with patch.object(
                plugins.Plugins,
                "iter_enabled",
                return_value=[plugins.BasePlugin("plugin1", plugin1)],
        ):
            tutor_config.update_with_base(config)
            tutor_config.update_with_defaults(config)
        tutor_config.render_full(config)
        value1 = get_typed(config, "PLUGIN1_PARAM1", str)

        self.assertEqual(10, len(value1))
Пример #11
0
    def test_config_load_from_plugins(self) -> None:
        config: Config = {}

        plugins_v0.DictPlugin({
            "name": "plugin1",
            "config": {
                "add": {
                    "PARAM1": "{{ 10|random_string }}"
                }
            }
        })
        plugins.load("plugin1")

        tutor_config.update_with_base(config)
        tutor_config.update_with_defaults(config)
        tutor_config.render_full(config)
        value1 = get_typed(config, "PLUGIN1_PARAM1", str)

        self.assertEqual(10, len(value1))
Пример #12
0
def k8s_namespace(config: Config) -> str:
    return get_typed(config, "K8S_NAMESPACE", str)