Skip to content

Collect xsiam items for tests even when xsoar supported #23839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
600ad93
trying to trigger build
DinaMeylakh Jan 15, 2023
8ca7d6c
Merge branch 'master' into collect_xsiam_items_for_tests
DinaMeylakh Jan 15, 2023
5757c69
trying to trigger build
DinaMeylakh Jan 15, 2023
d381feb
trying to see if tests will be collected for xsiam this time
DinaMeylakh Jan 30, 2023
fbda311
Merge branch 'master' into collect_xsiam_items_for_tests
DinaMeylakh Jan 30, 2023
36f3723
removed check if also xsoar, not sure thats right
DinaMeylakh Jan 30, 2023
16a6629
updating to see if avidan fixed the problem
DinaMeylakh Jan 30, 2023
ee7a1bd
collecting packs of xsiam components
DinaMeylakh Jan 30, 2023
3558525
added some debug logs
DinaMeylakh Jan 30, 2023
d91a5d0
Merge branch 'master' into collect_xsiam_items_for_tests
DinaMeylakh Jan 30, 2023
a30346b
syntax fix
DinaMeylakh Jan 30, 2023
a8233b7
making pretty for review
DinaMeylakh Jan 31, 2023
015ee08
Merge branch 'master' into collect_xsiam_items_for_tests
DinaMeylakh Jan 31, 2023
5f7f4a3
making pretty for review
DinaMeylakh Jan 31, 2023
37d4526
making pretty for review
DinaMeylakh Jan 31, 2023
272c6cc
cleaning up for review
DinaMeylakh Jan 31, 2023
d3ead6c
Merge branch 'master' into collect_xsiam_items_for_tests
DinaMeylakh Jan 31, 2023
bff55d9
checking changes according to review review
DinaMeylakh Jan 31, 2023
2e2bd00
Merge branch 'master' into collect_xsiam_items_for_tests
DinaMeylakh Jan 31, 2023
3de5ad8
removed black lines
DinaMeylakh Jan 31, 2023
da0486a
Merge branch 'master' into collect_xsiam_items_for_tests
DinaMeylakh Jan 31, 2023
be0bc63
added dev comment
DinaMeylakh Jan 31, 2023
d25f435
added dev comment
DinaMeylakh Jan 31, 2023
a0429ea
Merge branch 'master' into collect_xsiam_items_for_tests
DinaMeylakh Jan 31, 2023
6fdbc28
cleanup after testing
DinaMeylakh Jan 31, 2023
82fb100
Merge branch 'master' into collect_xsiam_items_for_tests
DinaMeylakh Jan 31, 2023
7b40267
Merge branch 'master' into collect_xsiam_items_for_tests
DinaMeylakh Feb 9, 2023
96faaff
Merge branch 'master' into collect_xsiam_items_for_tests
DinaMeylakh Feb 12, 2023
fcfef50
added layoutrule
DinaMeylakh Feb 12, 2023
364a6fe
Merge branch 'master' into collect_xsiam_items_for_tests
DinaMeylakh Feb 12, 2023
949a7e5
Merge branch 'master' into collect_xsiam_items_for_tests
DinaMeylakh Feb 12, 2023
2261155
Merge branch 'master' into collect_xsiam_items_for_tests
DinaMeylakh Feb 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 61 additions & 3 deletions Tests/scripts/collect_tests/collect_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
DEFAULT_REPUTATION_TESTS, IGNORED_FILE_TYPES, NON_CONTENT_FOLDERS,
ONLY_INSTALL_PACK_FILE_TYPES, SANITY_TEST_TO_PACK,
SKIPPED_CONTENT_ITEMS__NOT_UNDER_PACK, XSOAR_SANITY_TEST_NAMES,
ALWAYS_INSTALLED_PACKS_MAPPING, MODELING_RULE_COMPONENT_FILES)
ALWAYS_INSTALLED_PACKS_MAPPING, MODELING_RULE_COMPONENT_FILES, XSIAM_COMPONENT_FILES)
from Tests.scripts.collect_tests.exceptions import (
DeprecatedPackException, IncompatibleMarketplaceException,
InvalidTestException, NonDictException, NonXsoarSupportedPackException,
Expand Down Expand Up @@ -61,6 +61,7 @@ class CollectionReason(str, Enum):
MODELING_RULE_TEST_DATA_CHANGED = 'modeling rule\'s associated testdata file was changed'
MODELING_RULE_NIGHTLY = 'nightly testing of modeling rules'
DUMMY_OBJECT_FOR_COMBINING = 'creating an empty object, to combine two CollectionResult objects'
XSIAM_COMPONENT_CHANGED = 'xsiam component was changed'


REASONS_ALLOWING_NO_ID_SET_OR_CONF = {
Expand Down Expand Up @@ -594,6 +595,54 @@ def _collect_pack_for_modeling_rule(
is_nightly=is_nightly
)

def _collect_pack_for_xsiam_component(
self, pack_id: str, reason_description: str, changed_file_path: Path,
content_item_range: Optional[VersionRange] = None, is_nightly: bool = False,
reason: Optional[CollectionReason] = None
) -> CollectionResult:
"""Create a CollectionResult for a pack because of an xsiam component.

Marks the pack being collected and the modeling rule that needs to be tested

Args:
pack_id (str): the id of the pack being collected
reason (Optional[CollectionReason]): the reason the pack is being collected. Defaults to None.
reason_description (str): the reason the pack is being collected
changed_file_path (Path): the path to the file that was modified
content_item_range (Optional[VersionRange], optional): version range. Defaults to None.
is_nightly (Optional[bool]): whether this is a nightly flow. Defaults to False.

Returns:
CollectionResult: the object detailing the pack to collect and the modeling rule that should be tested
"""
if self.marketplace != MarketplaceVersions.MarketplaceV2:
logger.info(f'Not collecting pack {pack_id} for XSIAM component {changed_file_path} because '
f'it is not a collection for an XSIAM (MarketplaceV2) marketplace - '
f'marketplace is {self.marketplace}')
raise NothingToCollectException(changed_file_path, 'packs for XSIAM components are only collected for XSIAM')

pack = PACK_MANAGER.get_pack_metadata(pack_id)

version_range = content_item_range \
if pack.version_range.is_default \
else (pack.version_range | content_item_range)

if not reason:
file_type = find_type(changed_file_path.as_posix())
reason = f"{CollectionReason.XSIAM_COMPONENT_CHANGED} {file_type.value}"

return CollectionResult(
test=None,
modeling_rule_to_test=None,
pack=pack_id,
reason=reason,
version_range=version_range,
reason_description=reason_description,
conf=self.conf,
id_set=self.id_set,
is_nightly=is_nightly
)

def __validate_skipped_integration(self, id_: str, path: Path):
if id_ in self.conf.skipped_integrations:
raise NothingToCollectException(path, 'integration is skipped')
Expand Down Expand Up @@ -854,7 +903,7 @@ def _collect_single(self, path: Path) -> Optional[CollectionResult]:
content_item = ContentItem(path)
self._validate_content_item_compatibility(content_item, is_integration='Integrations' in path.parts)
except IncompatibleMarketplaceException:
if file_type not in MODELING_RULE_COMPONENT_FILES:
if (file_type not in MODELING_RULE_COMPONENT_FILES) and (file_type not in XSIAM_COMPONENT_FILES):
raise
except NonDictException:
content_item = None # py, md, etc. Anything not dictionary-based. Suitable logic follows, see collect_yml
Expand All @@ -871,6 +920,14 @@ def _collect_single(self, path: Path) -> Optional[CollectionResult]:
pack_id=pack_id, reason_description=reason_description,
changed_file_path=path, content_item_range=content_item_range
)

if file_type in XSIAM_COMPONENT_FILES:
# if the file is an xsiam component and is not a modeling rule
return self._collect_pack_for_xsiam_component(
pack_id=pack_id, reason_description=reason_description,
changed_file_path=path, content_item_range=content_item_range
)

else:
# install pack without collecting tests.
return self._collect_pack(
Expand Down Expand Up @@ -1225,7 +1282,8 @@ def output(result: Optional[CollectionResult]):
logger.info(f'collected {len(tests)} test playbooks:\n{test_str}')
logger.info(f'collected {len(packs_to_install)} packs to install:\n{packs_to_install_str}')
logger.info(f'collected {len(packs_to_upload)} packs to upload:\n{packs_to_upload_str}')
logger.info(f'collected {len(modeling_rules_to_test_str)} modeling rules to test:\n{modeling_rules_to_test_str}')
num_of_modeling_rules = len(modeling_rules_to_test_str.split("\n"))
logger.info(f'collected {num_of_modeling_rules} modeling rules to test:\n{modeling_rules_to_test_str}')
logger.info(f'collected {len(machines)} machines: {machine_str}')

PATHS.output_tests_file.write_text(test_str)
Expand Down
11 changes: 10 additions & 1 deletion Tests/scripts/collect_tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
FileType.CORRELATION_RULE,
FileType.XSIAM_DASHBOARD,
FileType.XSIAM_REPORT,
FileType.REPORT,
FileType.GENERIC_TYPE,
FileType.GENERIC_FIELD,
FileType.GENERIC_MODULE,
Expand Down Expand Up @@ -122,3 +121,13 @@
FileType.MODELING_RULE_SCHEMA,
FileType.MODELING_RULE_TEST_DATA,
}

XSIAM_COMPONENT_FILES: set[FileType] = {
FileType.PARSING_RULE,
FileType.CORRELATION_RULE,
FileType.XSIAM_DASHBOARD,
FileType.XSIAM_REPORT,
FileType.TRIGGER,
FileType.MODELING_RULE_SCHEMA,
FileType.XDRC_TEMPLATE
}
6 changes: 3 additions & 3 deletions Tests/scripts/infrastructure_tests/test_collect_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
XSOARNightlyTestCollector)
from Tests.scripts.collect_tests.constants import (
ALWAYS_INSTALLED_PACKS_MARKETPLACE_V2, MODELING_RULE_COMPONENT_FILES,
XSOAR_SANITY_TEST_NAMES, ONLY_INSTALL_PACK_FILE_TYPES)
XSOAR_SANITY_TEST_NAMES, ONLY_INSTALL_PACK_FILE_TYPES, XSIAM_COMPONENT_FILES)
from Tests.scripts.collect_tests.path_manager import PathManager
from Tests.scripts.collect_tests.utils import FilesToCollect, PackManager

Expand Down Expand Up @@ -553,8 +553,8 @@ def test_only_collect_pack(mocker, monkeypatch, file_type: collect_tests.FileTyp
return_value=FilesToCollect(('Packs/myPack/some_file',), ()))
mocker.patch('Tests.scripts.collect_tests.collect_tests.find_type', return_value=file_type)

# packs of modeling rules aren't expected to be collected when collecting for an XSOAR marketplace build
expected_packs = ('myPack',) if file_type not in MODELING_RULE_COMPONENT_FILES else ()
# packs of xsiam component files aren't expected to be collected when collecting for an XSOAR marketplace build
expected_packs = ('myPack',) if file_type not in MODELING_RULE_COMPONENT_FILES.union(XSIAM_COMPONENT_FILES) else ()

# noinspection PyTypeChecker
_test(monkeypatch, case_mocker=MockerCases.H, collector_class=BranchTestCollector,
Expand Down