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

agent publish refactor #3091

Merged
merged 8 commits into from
Mar 28, 2024
Merged

agent publish refactor #3091

merged 8 commits into from
Mar 28, 2024

Conversation

nagworld9
Copy link
Contributor

@nagworld9 nagworld9 commented Mar 13, 2024

Description

Added RSM update verification in agent publish test.

PR includes new pipeline parameter for passing test arguments. Passing all the way from pipeline to each test.
The expected format is comma-separated list of key=value pair like publihsedVersion=2.10.0.8,hostName=Test
This is needed especially for agent publish test to know the published version to validate. This new parameter will be useful for other tests when you want to test something dynamically without needing to change tests locally.

Issue #


PR information

  • The title of the PR is clear and informative.
  • There are a small number of commits, each of which has an informative message. This means that previously merged commits do not appear in the history of the PR. For information on cleaning up the commits in your pull request, see this page.
  • If applicable, the PR references the bug/issue that it fixes in the description.
  • New Unit tests were added for the changes made

Quality of Code and Contribution Guidelines

Copy link

codecov bot commented Mar 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.89%. Comparing base (e72f9e8) to head (fa61288).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3091   +/-   ##
========================================
  Coverage    71.89%   71.89%           
========================================
  Files          110      110           
  Lines        16395    16395           
  Branches      2342     2342           
========================================
  Hits         11788    11788           
  Misses        4055     4055           
  Partials       552      552           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -842,6 +846,18 @@ def _create_test_context(self,) -> AgentTestContext:
username=self._user,
identity_file=self._identity_file)

def _get_test_args(self) -> Dict[str, str]:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

converting list of key=value to dictionary

self._context: AgentTestContext = context
self._test_args: Dict[str, str] = test_args
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These args exposed to all tests

@@ -86,20 +129,6 @@ def _check_cse(self) -> None:
)
custom_script_2_1.assert_instance_view(expected_version="2.1", expected_message=message)

def get_ignore_error_rules(self) -> List[Dict[str, Any]]:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not needed in this test

@@ -146,64 +140,6 @@ def _prepare_agent(self) -> None:
"update-waagent-conf AutoUpdate.UpdateToLatestVersion=y Debug.EnableGAVersioning=y AutoUpdate.GAFamily=Test", use_sudo=True)
log.info('Successfully updated agent update config \n %s', output)

@staticmethod
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to common helper

if not verify_agent_update_flag_enabled(vm):
# enable the flag
log.info("Attempting vm update to set the enableVMAgentPlatformUpdates flag")
enable_agent_update_flag(vm)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this necessary? How is it used vs. our waagent.conf flag

Copy link
Contributor Author

@nagworld9 nagworld9 Mar 13, 2024

Choose a reason for hiding this comment

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

This is different flag need to set in the vm model for CRP/RSM driving RSM updates

@@ -209,6 +211,7 @@ def _initialize(self, environment: Environment, variables: Dict[str, Any], lisa_
self._environment_name = variables["c_env_name"]

self._test_suites = variables["c_test_suites"]
self._test_args = variables["test_args"]
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like there may be inconsistency in type here. variables["test_argd"] is str while self._test_args is dict

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's still a string, later we convert to dict. The variables exposed to user in pipeline, runbook or command line is in string in the form of list of comma-separated key=value pair
Example
publihsedVersion=2.10.0.8,hostName=Test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, you are right. It should be string. I just noticed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Copy link
Member

@narrieta narrieta left a comment

Choose a reason for hiding this comment

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

Added some comments, could you also describe how you are planning to planning to pass the arguments to the publish test from the pipeline? If the new argument is required, we should probably create a new pipeline.yml for the publish pipeline.

if self._test_args == "":
return test_args
for arg in self._test_args.split(','):
key, value = arg.split('=')
Copy link
Member

Choose a reason for hiding this comment

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

we should trim spaces after splitting on comma

@@ -565,6 +568,7 @@ def _execute(self) -> None:

try:
test_context = self._create_test_context()
test_args = self._get_test_args()
Copy link
Member

Choose a reason for hiding this comment

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

we should do the conversion in _initialize() and keep the result in self._test_args, to avoid adding more parameters to the execute method

@@ -645,7 +649,7 @@ def _execute_test_suite(self, suite: TestSuiteInfo, test_context: AgentTestConte

test_success: bool = True

test_instance = test.test_class(test_context)
test_instance = test.test_class(test_context, test_args)
Copy link
Member

Choose a reason for hiding this comment

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

Rather than passing test_args as a new argument to the test, each test_arg should be added to the text_context as a new property (or if the property already exists in the context, the just set its value).

Then AgentPublishTest.run_from_command_line should read the new parameters from the command line and add them to the test context as well. That is, it would parse the publishedVersion argument, instead of the test_args argument

log.info("Modifying agent update related config flags and renaming the log file")
self._run_remote_test(self._ssh_client, "sh -c 'agent-service stop && mv /var/log/waagent.log /var/log/waagent.$(date --iso-8601=seconds).log && update-waagent-conf AutoUpdate.UpdateToLatestVersion=y AutoUpdate.GAFamily=Test AutoUpdate.Enabled=y Extensions.Enabled=y'", use_sudo=True)
log.info('Renamed log file and updated agent-update DownloadNewAgents GAFamily config flags')
self._run_remote_test(self._ssh_client, "sh -c 'agent-service stop && mv /var/log/waagent.log /var/log/waagent.$(date --iso-8601=seconds).log && rm -rf /var/lib/waagent/WALinuxAgent-* && update-waagent-conf AutoUpdate.UpdateToLatestVersion=y AutoUpdate.GAFamily=Test AutoUpdate.Enabled=y Extensions.Enabled=y Debug.EnableGAVersioning=n'", use_sudo=True)
Copy link
Member

Choose a reason for hiding this comment

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

could you split this in multiple lines to make it more readable? thanks

@nagworld9
Copy link
Contributor Author

Added some comments, could you also describe how you are planning to planning to pass the arguments to the publish test from the pipeline? If the new argument is required, we should probably create a new pipeline.yml for the publish pipeline.

My idea is to it would benefit for other test_suites(for dev runs etc) if we added to main pipeline because the internal implementation is going to be same regardless.

When we run the pipeline, one need to pass like list of key=value pair in the pipeline arg. This converted to dict and added to agenttestcontext, so that all the tests access to dict. Whichever test needed, they read the keys to get value.

For publish test when I run the pipeline with agent_publish as test_suite, I pass publishedVersion={version}, the publish test reads this key publihsedVersion

@narrieta
Copy link
Member

My idea is to it would benefit for other test_suites(for dev runs etc) if we added to main pipeline because the internal implementation is going to be same regardless.

Yes, I agree that it is useful and can be added as an optional parameter in the main pipeline

For publish test when I run the pipeline with agent_publish as test_suite, I pass publishedVersion={version}, the publish test reads this key publihsedVersion

If this parameter is required by the publish test, then maybe should have a pipeline just for publish,

@nagworld9
Copy link
Contributor Author

nagworld9 commented Mar 19, 2024

My idea is to it would benefit for other test_suites(for dev runs etc) if we added to main pipeline because the internal implementation is going to be same regardless.

Yes, I agree that it is useful and can be added as an optional parameter in the main pipeline

For publish test when I run the pipeline with agent_publish as test_suite, I pass publishedVersion={version}, the publish test reads this key publihsedVersion

If this parameter is required by the publish test, then maybe should have a pipeline just for publish,

Not sure I followed here. I wouldn't send this as parameter, rather I send this parameter as value in the new test_arg parameter. That way I don't have deal with separate code path just for agent publish

@codecov-commenter
Copy link

codecov-commenter commented Mar 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.87%. Comparing base (c125edc) to head (2395615).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3091   +/-   ##
========================================
  Coverage    71.87%   71.87%           
========================================
  Files          110      110           
  Lines        16406    16406           
  Branches      2344     2344           
========================================
  Hits         11791    11791           
  Misses        4064     4064           
  Partials       551      551           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nagworld9
Copy link
Contributor Author

@narrieta Updated my pr. I added todo for reading it from cmd line. I couldn't get the flow right, maybe I'm missing something and also, I have different thought like we can directly use argparser for reading test specific arguments in the test itself.

@@ -73,6 +73,8 @@ def run_from_command_line(cls):
"""
Convenience method to execute the test when it is being invoked directly from the command line (as opposed as
being invoked from a test framework or library.)

Todo: Need to implement for reading test specific arguments from command line
Copy link
Member

Choose a reason for hiding this comment

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

Let's use capitals: TODO. Then some tools highlight that comment

@nagworld9 nagworld9 merged commit 101cc1e into Azure:develop Mar 28, 2024
11 checks passed
@nagworld9 nagworld9 deleted the agentpublish-test branch March 28, 2024 16:25
maddieford pushed a commit to maddieford/WALinuxAgent that referenced this pull request Apr 29, 2024
* agent publish refactor

* support arm 64vm

* convert dict to str

* address comments

* pylint

* new comments

* updated comment
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