diff --git a/splunk_add_on_ucc_framework/commands/build.py b/splunk_add_on_ucc_framework/commands/build.py index accbc5d5b..a6477856b 100644 --- a/splunk_add_on_ucc_framework/commands/build.py +++ b/splunk_add_on_ucc_framework/commands/build.py @@ -502,6 +502,7 @@ def generate( logger.error(f"globalConfig file is not valid. Error: {e}") sys.exit(1) global_config.update_addon_version(addon_version) + global_config.add_ucc_version(__version__) global_config.dump(global_config.original_path) logger.info( f"Updated and saved add-on version in the globalConfig file to {addon_version}" diff --git a/splunk_add_on_ucc_framework/global_config.py b/splunk_add_on_ucc_framework/global_config.py index 5053b8170..1de6b5104 100644 --- a/splunk_add_on_ucc_framework/global_config.py +++ b/splunk_add_on_ucc_framework/global_config.py @@ -127,6 +127,10 @@ def display_name(self) -> str: def version(self) -> str: return self.meta["version"] + @property + def ucc_version(self) -> str: + return self.meta["_uccVersion"] + @property def original_path(self) -> str: return self._original_path @@ -150,6 +154,9 @@ def update_schema_version(self, new_schema_version: str) -> None: def update_addon_version(self, version: str) -> None: self._content.setdefault("meta", {})["version"] = version + def add_ucc_version(self, version: str) -> None: + self.content.setdefault("meta", {})["_uccVersion"] = version + def has_inputs(self) -> bool: return bool(self.inputs) diff --git a/splunk_add_on_ucc_framework/schema/schema.json b/splunk_add_on_ucc_framework/schema/schema.json index f918ed91f..fafad92fd 100644 --- a/splunk_add_on_ucc_framework/schema/schema.json +++ b/splunk_add_on_ucc_framework/schema/schema.json @@ -1628,6 +1628,9 @@ "type": "string", "pattern": "^(?:\\d{1,3}\\.){2}\\d{1,3}$" }, + "_uccVersion": { + "type": "string" + }, "checkForUpdates": { "type": "boolean", "default": true diff --git a/tests/smoke/test_ucc_build.py b/tests/smoke/test_ucc_build.py index 9613fdbb2..396017b75 100644 --- a/tests/smoke/test_ucc_build.py +++ b/tests/smoke/test_ucc_build.py @@ -11,6 +11,7 @@ import addonfactory_splunk_conf_parser_lib as conf_parser from splunk_add_on_ucc_framework.commands import build +from splunk_add_on_ucc_framework import __version__ PYTEST_SKIP_REASON = """Python 3.8 and higher preserves the order of the attrib fields when `tostring` function is used. @@ -59,7 +60,28 @@ def test_ucc_generate(): def test_ucc_generate_with_config_param(): """ Checks whether the package is build when the `config` flag is provided in the CLI. + Check if globalConfig and app.manifest contains current ucc version """ + + def check_ucc_versions(): + global_config_path = path.join( + path.dirname(path.realpath(__file__)), + "..", + "..", + "output", + "Splunk_TA_UCCExample", + "appserver", + "static", + "js", + "build", + "globalConfig.json", + ) + + with open(global_config_path) as _f: + global_config = json.load(_f) + + assert global_config["meta"]["_uccVersion"] == __version__ + package_folder = path.join( path.dirname(path.realpath(__file__)), "..", @@ -76,8 +98,11 @@ def test_ucc_generate_with_config_param(): "package_global_config_everything", "globalConfig.json", ) + build.generate(source=package_folder, config_path=config_path) + check_ucc_versions() + @pytest.mark.skipif(sys.version_info >= (3, 8), reason=PYTEST_SKIP_REASON) def test_ucc_generate_with_everything(): diff --git a/tests/testdata/test_addons/package_files_conflict_test/globalConfig.json b/tests/testdata/test_addons/package_files_conflict_test/globalConfig.json index 102b67c94..1e645f86b 100644 --- a/tests/testdata/test_addons/package_files_conflict_test/globalConfig.json +++ b/tests/testdata/test_addons/package_files_conflict_test/globalConfig.json @@ -212,8 +212,9 @@ "meta": { "name": "test_addon", "restRoot": "test_addon", - "version": "5.34.1Racdcfb2e", + "version": "5.36.2Ref7d7543", "displayName": "This is my add-on", - "schemaVersion": "0.0.3" + "schemaVersion": "0.0.3", + "_uccVersion": "5.36.2" } } diff --git a/tests/testdata/test_addons/package_global_config_configuration/globalConfig.json b/tests/testdata/test_addons/package_global_config_configuration/globalConfig.json index 13be07054..c30ad3aa8 100644 --- a/tests/testdata/test_addons/package_global_config_configuration/globalConfig.json +++ b/tests/testdata/test_addons/package_global_config_configuration/globalConfig.json @@ -420,6 +420,7 @@ "restRoot": "splunk_ta_uccexample", "version": "1.1.1", "displayName": "Splunk UCC test Add-on", - "schemaVersion": "0.0.3" + "schemaVersion": "0.0.3", + "_uccVersion": "5.36.2" } } diff --git a/tests/testdata/test_addons/package_global_config_everything/globalConfig.json b/tests/testdata/test_addons/package_global_config_everything/globalConfig.json index fcda40154..8de7413b3 100644 --- a/tests/testdata/test_addons/package_global_config_everything/globalConfig.json +++ b/tests/testdata/test_addons/package_global_config_everything/globalConfig.json @@ -1388,8 +1388,9 @@ "meta": { "name": "Splunk_TA_UCCExample", "restRoot": "splunk_ta_uccexample", - "version": "5.35.1R537d4508", + "version": "5.36.2Ref7d7543", "displayName": "Splunk UCC test Add-on", - "schemaVersion": "0.0.3" + "schemaVersion": "0.0.3", + "_uccVersion": "5.36.2" } } diff --git a/tests/testdata/test_addons/package_global_config_multi_input/globalConfig.json b/tests/testdata/test_addons/package_global_config_multi_input/globalConfig.json index 7334e6ec4..996d556b3 100644 --- a/tests/testdata/test_addons/package_global_config_multi_input/globalConfig.json +++ b/tests/testdata/test_addons/package_global_config_multi_input/globalConfig.json @@ -465,8 +465,9 @@ "meta": { "name": "Splunk_TA_UCCExample", "restRoot": "splunk_ta_uccexample", - "version": "0.0.1", + "version": "5.36.2Ref7d7543", "displayName": "Splunk UCC test Add-on", - "schemaVersion": "0.0.3" + "schemaVersion": "0.0.3", + "_uccVersion": "5.36.2" } }