diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml old mode 100644 new mode 100755 diff --git a/requirements/py3.10/tests.txt b/requirements/py3.10/tests.txt old mode 100644 new mode 100755 diff --git a/requirements/py3.6/tests.txt b/requirements/py3.6/tests.txt old mode 100644 new mode 100755 diff --git a/requirements/py3.7/tests.txt b/requirements/py3.7/tests.txt old mode 100644 new mode 100755 diff --git a/requirements/py3.8/tests.txt b/requirements/py3.8/tests.txt old mode 100644 new mode 100755 diff --git a/requirements/py3.9/tests.txt b/requirements/py3.9/tests.txt old mode 100644 new mode 100755 diff --git a/src/saltext/cli/__main__.py b/src/saltext/cli/__main__.py old mode 100644 new mode 100755 index 4eb9f92..c0a6486 --- a/src/saltext/cli/__main__.py +++ b/src/saltext/cli/__main__.py @@ -15,12 +15,14 @@ from saltext.cli import PACKAGE_ROOT from saltext.cli.templates import LOADER_MODULE_INTEGRATION_TEST_TEMPLATE from saltext.cli.templates import LOADER_MODULE_UNIT_TEST_TEMPLATE +from saltext.cli.templates import LOADER_SDB_UNIT_TEST_TEMPLATE from saltext.cli.templates import LOADER_STATE_UNIT_TEST_TEMPLATE from saltext.cli.templates import LOADER_TEMPLATE from saltext.cli.templates import LOADER_UNIT_TEST_TEMPLATE from saltext.cli.templates import LOADERS_TEMPLATE from saltext.cli.templates import MODULE_LOADER_TEMPLATE from saltext.cli.templates import PACKAGE_INIT +from saltext.cli.templates import SDB_LOADER_TEMPLATE from saltext.cli.templates import STATE_LOADER_TEMPLATE LICENSES: Dict[str, str] = { @@ -250,7 +252,11 @@ def main( loaders_integration_tests_path = destdir / "tests" / "integration" for loader_name in loader: templating_context["loader"] = loader_name - loader_dir = loaders_package_path / (loader_name.rstrip("s") + "s") + loader_dir = None + if loader_name in ["sdb"]: + loader_dir = loaders_package_path / loader_name.rstrip("s") + else: + loader_dir = loaders_package_path / (loader_name.rstrip("s") + "s") loader_dir.mkdir(0o755) loader_dir_init = loader_dir / "__init__.py" if not loader_dir_init.exists(): @@ -259,6 +265,8 @@ def main( loader_template = MODULE_LOADER_TEMPLATE elif loader_name == "states": loader_template = STATE_LOADER_TEMPLATE + elif loader_name == "sdb": + loader_template = SDB_LOADER_TEMPLATE else: loader_template = LOADER_TEMPLATE loader_module_contents = Template(loader_template).render(**templating_context) @@ -267,7 +275,11 @@ def main( loader_dir_module = loader_dir_module.with_suffix(".new") loader_dir_module.write_text(loader_module_contents.rstrip() + "\n") - loader_unit_tests_dir = loaders_unit_tests_path / (loader_name.rstrip("s") + "s") + loader_unit_tests_dir = None + if loader_name in ["sdb"]: + loader_unit_tests_dir = loaders_unit_tests_path / loader_name.rstrip("s") + else: + loader_unit_tests_dir = loaders_unit_tests_path / (loader_name.rstrip("s") + "s") loader_unit_tests_dir.mkdir(0o755, exist_ok=True) loader_unit_tests_dir_init = loader_unit_tests_dir / "__init__.py" if not loader_unit_tests_dir_init.exists(): @@ -276,6 +288,8 @@ def main( loader_test_template = LOADER_MODULE_UNIT_TEST_TEMPLATE elif loader_name == "states": loader_test_template = LOADER_STATE_UNIT_TEST_TEMPLATE + elif loader_name == "sdb": + loader_test_template = LOADER_SDB_UNIT_TEST_TEMPLATE else: loader_test_template = LOADER_UNIT_TEST_TEMPLATE loader_unit_test_contents = Template(loader_test_template).render(**templating_context) @@ -284,9 +298,13 @@ def main( loader_unit_test_module = loader_unit_test_module.with_suffix(".new") loader_unit_test_module.write_text(loader_unit_test_contents.rstrip() + "\n") - loader_integration_tests_dir = loaders_integration_tests_path / ( - loader_name.rstrip("s") + "s" - ) + loader_integration_tests_dir = None + if loader_name in ["sdb"]: + loader_integration_tests_dir = loaders_integration_tests_path / loader_name.rstrip("s") + else: + loader_integration_tests_dir = loaders_integration_tests_path / ( + loader_name.rstrip("s") + "s" + ) loader_integration_tests_dir.mkdir(0o755, exist_ok=True) loader_integration_tests_dir_init = loader_integration_tests_dir / "__init__.py" if not loader_integration_tests_dir_init.exists(): diff --git a/src/saltext/cli/project/.pre-commit-config.yaml.j2 b/src/saltext/cli/project/.pre-commit-config.yaml.j2 old mode 100644 new mode 100755 diff --git a/src/saltext/cli/project/.pylintrc b/src/saltext/cli/project/.pylintrc old mode 100644 new mode 100755 diff --git a/src/saltext/cli/project/docs/conf.py.j2 b/src/saltext/cli/project/docs/conf.py.j2 old mode 100644 new mode 100755 diff --git a/src/saltext/cli/project/noxfile.py.j2 b/src/saltext/cli/project/noxfile.py.j2 old mode 100644 new mode 100755 diff --git a/src/saltext/cli/project/setup.cfg.j2 b/src/saltext/cli/project/setup.cfg.j2 old mode 100644 new mode 100755 diff --git a/src/saltext/cli/templates.py b/src/saltext/cli/templates.py old mode 100644 new mode 100755 index 6cfee6d..f4688fc --- a/src/saltext/cli/templates.py +++ b/src/saltext/cli/templates.py @@ -134,6 +134,41 @@ def exampled(name): return ret ''' +SDB_LOADER_TEMPLATE = '''\ +{%- set loader_name = loader.rstrip("s") %} +""" +Salt {{ loader_name }} module +""" +import logging + +log = logging.getLogger(__name__) + +__virtualname__ = "{{ package_name }}" + + +def __virtual__(): + # To force a module not to load return something like: + # return (False, "The {{ project_name }} {{ loader_name }} module is not implemented yet") + + # Replace this with your own logic + if "{{package_name}}.example_function" not in __salt__: + return False, "The '{{package_name}}' execution module is not available" + return __virtualname__ + + +def get(key, profile=None): + """ + This example function should be replaced + + CLI Example: + + .. code-block:: bash + + salt '*' sdb.get "sdb://{{ package_name}}/foo" + """ + return key +''' + LOADER_MODULE_UNIT_TEST_TEMPLATE = """\ import pytest import salt.modules.test as testmod @@ -189,6 +224,27 @@ def test_replace_this_this_with_something_meaningful(): assert {{ package_name }}_state.exampled(echo_str) == expected """ +LOADER_SDB_UNIT_TEST_TEMPLATE = """\ +{%- set loader_name = loader.rstrip("s") %} +import pytest +import {{ package_namespace_pkg }}{{ package_name }}.{{ loader.rstrip("s") }}.{{ package_name }}_mod as {{ package_name }}_{{ loader_name }} + + +@pytest.fixture +def configure_loader_modules(): + module_globals = { + "__salt__": {"this_does_not_exist.please_replace_it": lambda: True}, + } + return { + {{ package_name }}_{{ loader_name }}: module_globals, + } + + +def test_replace_this_this_with_something_meaningful(): + assert "this_does_not_exist.please_replace_it" in {{ package_name }}_{{ loader_name }}.__salt__ + assert {{ package_name }}_{{ loader_name }}.__salt__["this_does_not_exist.please_replace_it"]() is True +""" + LOADER_UNIT_TEST_TEMPLATE = """\ {%- set loader_name = loader.rstrip("s") %} import pytest