Skip to content

Commit

Permalink
feat: add UCC version to globalConfig (#984)
Browse files Browse the repository at this point in the history
This PR adds versions of used UCC framework to TA internal files for
traceability.

see: [issue
983](#983)

---------

Co-authored-by: Artem Rys <[email protected]>
  • Loading branch information
MateuszMa and artemrys authored Jan 25, 2024
1 parent c738634 commit e1229b4
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 7 deletions.
1 change: 1 addition & 0 deletions splunk_add_on_ucc_framework/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
7 changes: 7 additions & 0 deletions splunk_add_on_ucc_framework/global_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions splunk_add_on_ucc_framework/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,9 @@
"type": "string",
"pattern": "^(?:\\d{1,3}\\.){2}\\d{1,3}$"
},
"_uccVersion": {
"type": "string"
},
"checkForUpdates": {
"type": "boolean",
"default": true
Expand Down
25 changes: 25 additions & 0 deletions tests/smoke/test_ucc_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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__)),
"..",
Expand All @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit e1229b4

Please sign in to comment.