Skip to content
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

Ciac 11100 playbook run in build #4658

Open
wants to merge 62 commits into
base: master
Choose a base branch
from

Conversation

JasBeilin
Copy link
Contributor

@JasBeilin JasBeilin commented Nov 12, 2024

Added test-use-case command, to run use case flows on cloud machines.

Related Issues

fixes: https://jira-dc.paloaltonetworks.com/browse/CIAC-11867

@JasBeilin JasBeilin self-assigned this Nov 12, 2024
@JasBeilin JasBeilin marked this pull request as draft November 12, 2024 08:41
@eyalpalo eyalpalo marked this pull request as ready for review December 31, 2024 09:23
@eyalpalo eyalpalo requested a review from AradCarmi as a code owner December 31, 2024 09:23
@eyalpalo eyalpalo requested a review from dantavori December 31, 2024 09:24
@eyalpalo eyalpalo assigned eyalpalo and unassigned JasBeilin Dec 31, 2024
Copy link
Contributor

@dantavori dantavori left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some minor comments but looks very good!

@@ -0,0 +1,4 @@
changes:
- description: Adding new command **test-use-case** to test use case flows on cloud machines.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- description: Adding new command **test-use-case** to test use case flows on cloud machines.
- description: Added the **test-use-case** command to test use-case flows on cloud machines.

@@ -132,6 +133,7 @@ def get_client_from_server_type(
auth_id: Optional[str] = None,
username: Optional[str] = None,
password: Optional[str] = None,
lcas_id: Optional[str] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lcas_id: Optional[str] = None,
lcaas_id: Optional[str] = None,

I'd go with "project_id", quicker to understand than the ugly devops term "lcaas", but not super critical

# Manually parse command-line argument
for arg in request.config.invocation_params.args:
if isinstance(arg, str) and arg.startswith("--client_conf="):
logger.info("there is --client_conf recognized")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.info("there is --client_conf recognized")
logger.debug("Parsing --client_conf argument")

"""

def _process_response(self, response, status_code, expected_status=200):
"""Process the HTTP response coming from the XSOAR client."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Process the HTTP response coming from the XSOAR client."""
"""Process the HTTP response coming from the XSIAM client."""

@@ -2218,3 +2219,4 @@ class PlaybookTaskType(StrEnum):
# Test types:
TEST_PLAYBOOKS = "TestPlaybooks"
TEST_MODELING_RULES = "TestModelingRules"
Test_Use_Cases = "TestUseCases"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Test_Use_Cases = "TestUseCases"
TEST_USE_CASES = "TestUseCases"

pyproject.toml Outdated
@@ -126,6 +126,7 @@ pytest-github-actions-annotate-failures = "^0.2.0"
pytest-sugar = "^1.0.0"
pytest-loguru = "^0.4.0"


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there's no change then we can revert the changes in both poetry files

Comment on lines 151 to 164
logging_module.info("Start uploading test use case results file to bucket")

storage_client = storage.Client.from_service_account_json(self.service_account)
storage_bucket = storage_client.bucket(self.artifacts_bucket)

blob = storage_bucket.blob(
f"content-test-use-case/{repository_name}/{file_name}"
)
blob.upload_from_filename(
original_file_path.as_posix(),
content_type="application/xml",
)

logging_module.info("Finished uploading test use case results file to bucket")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logging_module.info("Start uploading test use case results file to bucket")
storage_client = storage.Client.from_service_account_json(self.service_account)
storage_bucket = storage_client.bucket(self.artifacts_bucket)
blob = storage_bucket.blob(
f"content-test-use-case/{repository_name}/{file_name}"
)
blob.upload_from_filename(
original_file_path.as_posix(),
content_type="application/xml",
)
logging_module.info("Finished uploading test use case results file to bucket")
logging_module.debug("Start uploading test use case results file to bucket")
storage_client = storage.Client.from_service_account_json(self.service_account)
storage_bucket = storage_client.bucket(self.artifacts_bucket)
blob = storage_bucket.blob(
f"content-test-use-case/{repository_name}/{file_name}"
)
blob.upload_from_filename(
original_file_path.as_posix(),
content_type="application/xml",
)
logging_module.debug("Finished uploading test use case results file to bucket")


# --------------------------- Env Setup -------------------------------

logger.info("installing pyxdr...")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.info("installing pyxdr...")
logger.debug("installing pyxdr...")

generally go over everything and ensure logs are info only for "user messages" and not for "developer messages"
I recommend reading the job logs in the gitlab UI to easily understand which info logs we actually want to be debug

Comment on lines +367 to +369
except Exception:
self.build_context.logging_module.exception("~~ Thread failed ~~")
self.build_context.tests_data_keeper.errors = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does it behave in case of exception?

  1. will the rest of the threads continue?
  2. will we see the error message?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, each thread should run its tests, the rest of the threads should keep running.
Also logs per thread are printed (with thread number)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have one sanity E2E test (from the main command method)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the file_name to end with _setup.py at the end.
Also, keep the logic of the command options here and then the call to the command itself.
The rest of the code - should be in a different file (the logic should be in a different file) - see examples in the other SDK commands (upload, download etc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants