Skip to content

Commit

Permalink
fix: build add-on if config param is present
Browse files Browse the repository at this point in the history
After YAML support implementation there was a bug if `config` is provided, then `ucc-gen` throws an exception (like, here https://github.com/splunk/addonfactory-ucc-library/actions/runs/3379621489/jobs/5611433966).
  • Loading branch information
hetangmodi-crest authored Nov 9, 2022
1 parent 5219b14 commit 536634a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 5 deletions.
2 changes: 2 additions & 0 deletions splunk_add_on_ucc_framework/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ def generate(source, config, ta_version, outputdir=None, python_binary_name="pyt
os.path.join(source, PARENT_DIR, "globalConfig.yaml")
)
is_global_config_yaml = True
else:
is_global_config_yaml = True if config.endswith(".yaml") else False

logger.info(f"Cleaning out directory {outputdir}")
shutil.rmtree(os.path.join(outputdir), ignore_errors=True)
Expand Down
4 changes: 2 additions & 2 deletions splunk_add_on_ucc_framework/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ def main(argv: Optional[Sequence[str]] = None):
"--config",
type=str,
nargs="?",
help="Path to configuration file, defaults to globalConfig.json in parent directory of source provided",
help="Path to configuration file, defaults to globalConfig file in parent directory of source provided",
default=None,
)
parser.add_argument(
"--ta-version",
type=str,
help="Version of TA, default version is version specified in the "
"package such as app.manifest, app.conf, and globalConfig.json",
"package such as app.manifest, app.conf, and globalConfig file.",
default=None,
)
parser.add_argument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@
"meta": {
"name": "Splunk_TA_UCCExample",
"restRoot": "splunk_ta_uccexample",
"version": "5.7.0Rc1c9ff9f",
"version": "5.15.0",
"displayName": "Splunk UCC test Add-on",
"schemaVersion": "0.0.3"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@
"meta": {
"name": "Splunk_TA_UCCExample",
"restRoot": "splunk_ta_uccexample",
"version": "5.7.0Rc1c9ff9f",
"version": "5.15.0",
"displayName": "Splunk UCC test Add-on",
"schemaVersion": "0.0.3"
}
Expand Down
16 changes: 16 additions & 0 deletions tests/data/test_ucc_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ def test_ucc_generate(self):
)
ucc.generate(source=package_folder)

def test_ucc_generate_with_config_param(self):
"""
Checks whether the package is build when the `config` flag is provided in the CLI
"""
package_folder = path.join(
path.dirname(path.realpath(__file__)),
"package_global_config_inputs_configuration_alerts",
"package",
)
config_path = path.join(
path.dirname(path.realpath(__file__)),
"package_global_config_inputs_configuration_alerts",
"globalConfig.json",
)
ucc.generate(source=package_folder, config=config_path)

def test_ucc_generate_with_inputs_configuration_alerts(self):
with tempfile.TemporaryDirectory() as temp_dir:
package_folder = path.join(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_testdata_file(file_name: str) -> str:

def get_testdata(file_name: str) -> Dict:
config = get_testdata_file(file_name)
if file_name[-4] == "json":
if file_name.endswith(".json"):
return json.loads(config)
else:
return yaml_load(config)
18 changes: 18 additions & 0 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@
"python_binary_name": "python.exe",
},
),
(
[
"--source",
"package",
"--config",
"/path/to/globalConfig.yaml",
"--ta-version",
"2.2.0",
"--python-binary-name",
"python.exe",
],
{
"source": "package",
"config": "/path/to/globalConfig.yaml",
"ta_version": "2.2.0",
"python_binary_name": "python.exe",
},
),
],
)
@mock.patch("splunk_add_on_ucc_framework.main.generate")
Expand Down

0 comments on commit 536634a

Please sign in to comment.