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

Add tests for extension workflow #2843

Merged
merged 140 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 120 commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
da72c37
Update version to dummy 1.0.0.0'
maddieford Nov 8, 2022
59dbd22
Revert version change
maddieford Nov 8, 2022
633a826
Merge remote-tracking branch 'upstream/develop' into develop
maddieford Nov 21, 2022
14a743f
Merge remote-tracking branch 'upstream/develop' into develop
maddieford Dec 8, 2022
54ea0f3
Merge remote-tracking branch 'upstream/develop' into develop
maddieford Jan 10, 2023
e79c4c5
Merge remote-tracking branch 'upstream/develop' into develop
maddieford Feb 8, 2023
498b612
Merge remote-tracking branch 'upstream/develop' into develop
maddieford Feb 14, 2023
1e269f4
Merge remote-tracking branch 'upstream/develop' into develop
maddieford Mar 13, 2023
7b49e76
Merge remote-tracking branch 'upstream/develop' into develop
maddieford Mar 24, 2023
0a426cc
Merge remote-tracking branch 'upstream/develop' into develop
maddieford Apr 6, 2023
17fbf6a
Merge remote-tracking branch 'upstream/develop' into develop
maddieford Apr 7, 2023
995cbb9
Merge remote-tracking branch 'upstream/develop' into develop
maddieford Apr 13, 2023
eaadc83
Merge remote-tracking branch 'upstream/develop' into develop
maddieford Apr 24, 2023
fb03e07
Merge remote-tracking branch 'upstream/develop' into develop
maddieford Apr 27, 2023
6a8e0d6
Merge remote-tracking branch 'upstream/develop' into develop
maddieford May 19, 2023
8e62c05
Basic structure
maddieford May 19, 2023
9999aef
Test must run in SCUS for test ext
maddieford May 19, 2023
9d6cb62
Add GuestAgentDCRTest Extension id
maddieford May 22, 2023
e7c010c
Test stucture
maddieford May 22, 2023
193662b
Update test file name
maddieford May 22, 2023
bf7fc04
test no location
maddieford May 22, 2023
f7f7a54
Test location as southcentralus
maddieford May 22, 2023
5aad0ac
Assert ext is installed
maddieford May 22, 2023
acd4ae5
Try changing version for dcr test ext
maddieford May 22, 2023
1fc51a1
Update expected message in instance view
maddieford May 22, 2023
7b43af7
try changing message to string
maddieford May 22, 2023
11b73e0
Limit images for ext workflow
maddieford May 22, 2023
d8c1d21
Merge in virtual_machine_client changes
maddieford May 23, 2023
6cf987a
Update classes after refactor
maddieford Jun 2, 2023
4b56360
Update class name
maddieford Jun 2, 2023
bda8708
Refactor tests
maddieford Jun 2, 2023
2ba6238
Rename extension_install to extension_workflow
maddieford Jun 5, 2023
79cae43
Assert ext status
maddieford Jun 5, 2023
40f98a6
Assert operation sequence is expected
maddieford Jun 5, 2023
8aef67d
Remove logger reference
maddieford Jun 5, 2023
d4c9a99
Pass ssh client
maddieford Jun 5, 2023
2f3731c
Update ssh
maddieford Jun 5, 2023
788584c
Add permission to run script
maddieford Jun 5, 2023
8de7846
Correct permissions
maddieford Jun 5, 2023
0a4d328
Add execute permissions for helper script
maddieford Jun 5, 2023
83d3c8e
Make scripts executable
maddieford Jun 5, 2023
2788d53
Change args to string
maddieford Jun 5, 2023
4f8a31b
Add required parameter
maddieford Jun 5, 2023
a329a46
Add shebang for retart_agent
maddieford Jun 5, 2023
d440058
Fix arg format
maddieford Jun 5, 2023
dcde7ea
Use restart utility
maddieford Jun 5, 2023
b8c2605
Run restart with sudo
maddieford Jun 5, 2023
ec7bed6
Add enable scenario
maddieford Jun 5, 2023
cde74ad
Attempt to remove start_time
maddieford Jun 5, 2023
4b44b7e
Only assert enable
maddieford Jun 5, 2023
104a623
Add delete scenario
maddieford Jun 5, 2023
1f4bd31
Fix uninstall scenario
maddieford Jun 5, 2023
a318adc
Add extension update scenario
maddieford Jun 5, 2023
81eca75
Run assert scenario on update scenario
maddieford Jun 5, 2023
976cbb4
Fix reference to ext
maddieford Jun 5, 2023
9637ea3
Format args as str instead of arr
maddieford Jun 5, 2023
df94a37
Update test args
maddieford Jun 5, 2023
1950555
Add test case for update without install
maddieford Jun 5, 2023
ed51360
Fix delete
maddieford Jun 5, 2023
5604d3c
Keep changes
maddieford Jun 6, 2023
b4951c8
Merge branch 'develop' of github.com:Azure/WALinuxAgent into develop
maddieford Jun 6, 2023
54184e7
Save changes
maddieford Jun 6, 2023
7dac115
Add special chars test case
maddieford Jun 6, 2023
84946b3
Fix dcr_ext issue{
maddieford Jun 6, 2023
e5dcd98
Add validate no lag scenario
maddieford Jun 6, 2023
f97197e
Fix testguid reference
maddieford Jun 6, 2023
f46afae
Add additional log statements for debugging
maddieford Jun 11, 2023
8ff742d
Fix message to check before encoding
maddieford Jun 11, 2023
6d388f8
Encode setting name
maddieford Jun 11, 2023
b929556
Correctly check data
maddieford Jun 12, 2023
b0d1e22
Make check data executable
maddieford Jun 12, 2023
d3d71f9
Fix command args for special char test
maddieford Jun 12, 2023
deef228
Fix no lag time
maddieford Jun 12, 2023
fe2f2c2
Fix ssh client reference
maddieford Jun 12, 2023
482f3fe
Try message instead of text
maddieford Jun 12, 2023
8bda6b5
Remove unused method
maddieford Jun 12, 2023
75cf5a0
Start clean up
maddieford Jun 12, 2023
2b0ed08
Continue code cleanup
maddieford Jun 12, 2023
48949e0
Fix pylint errors
maddieford Jun 12, 2023
3ba0f05
Fix pylint errors
maddieford Jun 12, 2023
c14125a
Start refactor
maddieford Jun 13, 2023
0380130
Debug agent lag
maddieford Jun 13, 2023
ef9291a
Update lag logging
maddieford Jun 13, 2023
30a1740
Fix assert_that for lag
maddieford Jun 13, 2023
dbecb19
Remove typo
maddieford Jun 13, 2023
8343df1
Add readme for extension_workflow scenario
maddieford Jun 14, 2023
5dce3dd
Reformat comment
maddieford Jun 14, 2023
8c5bd6d
Improve logging
maddieford Jun 14, 2023
d3c06b4
Refactor assert scenario
maddieford Jun 14, 2023
c34aa27
Remove unused constants
maddieford Jun 14, 2023
b9c9ada
Remove unusued parameter in assert scenario
maddieford Jun 14, 2023
7f208f9
Add logging
maddieford Jun 14, 2023
5466804
Improve logging
maddieford Jun 14, 2023
8e6a672
Improve logging
maddieford Jun 14, 2023
2a88fd0
Fix soft assertions issue
maddieford Jun 14, 2023
fb49cfc
Remove todo for delete polling
maddieford Jun 14, 2023
dd46d51
Remove unnecessary new line
maddieford Jun 14, 2023
947134b
removed unnecessary function
maddieford Jun 14, 2023
0d16066
Make special chars log more readable
maddieford Jun 14, 2023
356f9a9
remove unnecessary log
maddieford Jun 14, 2023
d081330
Add version to add or update log
maddieford Jun 14, 2023
bdd4934
Remove unnecessary assert instance view
maddieford Jun 14, 2023
2e0303e
Add empty log line
maddieford Jun 14, 2023
cf7d6ca
Add update back to restart args to debug
maddieford Jun 14, 2023
2613d40
Add update back to restart args to debug
maddieford Jun 14, 2023
2a1c260
Merge changes from develop
maddieford Jun 14, 2023
bc842b1
Merge branch 'develop' into ext-workflow
maddieford Jun 14, 2023
746689d
Remove unused init
maddieford Jun 14, 2023
9db7ce4
Merge branch 'ext-workflow' of github.com:maddieford/WALinuxAgent int…
maddieford Jun 14, 2023
9735035
Merge branch 'develop' into ext-workflow
maddieford Jun 14, 2023
ed6e900
Merge branch 'develop' into ext-workflow
maddieford Jun 23, 2023
ebd1e03
Merge branch 'develop' into ext-workflow
maddieford Jun 29, 2023
b3dabdb
Remove test_suites from pipeline yml
maddieford Jun 29, 2023
0abeec2
Update location in test suite yml
maddieford Jun 29, 2023
59c9456
Add comment for location restriction
maddieford Jun 29, 2023
627be4a
Remove unused init and fix comments
maddieford Jun 29, 2023
9f9ecea
Improve method header
maddieford Jun 29, 2023
666fac5
Rename scripts
maddieford Jun 29, 2023
e643fc1
Remove print_function
maddieford Jun 29, 2023
ab487b7
Rename is_data_in_waagent_log
maddieford Jun 29, 2023
96f9a3e
Add comments describing assert operation sequence script
maddieford Jul 3, 2023
30f9f6b
Merge branch 'develop' into ext-workflow
maddieford Jul 3, 2023
08f473b
add comments to scripts and type annotate assert operation sequence
maddieford Jul 3, 2023
f845bd5
Add GuestAgentDcrExtension source code to repo
maddieford Jul 3, 2023
5aeee72
Fix typing.dict error
maddieford Jul 3, 2023
60b04d4
Fix typing issue
maddieford Jul 3, 2023
eef24e8
Remove outdated comment
maddieford Jul 3, 2023
5b48168
Add comments to extension_workflow.py
maddieford Jul 3, 2023
6adbf50
rename scripts to match test suite name
maddieford Jul 3, 2023
17764c1
Ignore pylint warnings on test ext
maddieford Jul 3, 2023
549b8ef
Update pylint rc to ignore tests_e2e/GuestAgentDcrTestExtension
maddieford Jul 3, 2023
56e0edb
Update pylint rc to ignore tests_e2e/GuestAgentDcrTestExtension
maddieford Jul 3, 2023
86a0212
disable all errors/warnings dcr test ext
maddieford Jul 3, 2023
2aa1cc3
disable all errors/warnings dcr test ext
maddieford Jul 3, 2023
40a25f4
Run workflow on debian
maddieford Jul 3, 2023
bf4cf31
Revert to dcr config distros
maddieford Jul 3, 2023
9010e01
Move enable increment to beginning of function
maddieford Jul 3, 2023
22a8b81
Fix gs completed regex
maddieford Jul 3, 2023
dbee33e
Remove unnessary files from dcr test ext dir
maddieford Jul 3, 2023
40b112c
Merge branch 'develop' into ext-workflow
maddieford Jul 6, 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
2 changes: 1 addition & 1 deletion tests_e2e/orchestrator/runbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ variable:
#
# The test suites to execute
- name: test_suites
value: "agent_bvt, no_outbound_connections, extensions_disabled, agent_not_provisioned, fips"
value: "agent_bvt, no_outbound_connections, extensions_disabled, agent_not_provisioned, fips, agent_ext_workflow"
- name: cloud
value: "AzureCloud"
is_case_visible: true
Expand Down
11 changes: 11 additions & 0 deletions tests_e2e/test_suites/agent_ext_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "AgentExtWorkflow"
tests:
- "agent_ext_workflow/extension_workflow.py"
images:
Copy link
Member

Choose a reason for hiding this comment

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

I think this should run on all endorsed distros

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now I have it matching the config from the dcr repo: https://msazure.visualstudio.com/One/_git/Compute-Runtime-Tux-Pipeline?path=/dungeon_crawler/scenarios/agent-ext-workflow/config.json

The DCR Test Extension has issues when installed/enabled on other distros. For example, I tried to run this test workflow on debian_9 and the extension fails to be installed:

`azure.core.exceptions.HttpResponseError: (VMExtensionHandlerNonTransientError) The handler for VM extension type Microsoft.Azure.TestExtensions.Edp.GuestAgentDcrTest has reported terminal failure for VM extension GuestAgentDcrTestExt with error message: [ExtensionOperationError] Non-zero exit code: 1, /var/lib/waagent/Microsoft.Azure.TestExtensions.Edp.GuestAgentDcrTest-1.1.5/./GuestAgentDcrTest.py --install
[stdout]

[stderr]
Traceback (most recent call last):
File "/var/lib/waagent/Microsoft.Azure.TestExtensions.Edp.GuestAgentDcrTest-1.1.5/./GuestAgentDcrTest.py", line 4, in
from Utils.WAAgentUtil import waagent
File "/var/lib/waagent/Microsoft.Azure.TestExtensions.Edp.GuestAgentDcrTest-1.1.5/Utils/WAAgentUtil.py", line 50, in
waagent = imp.load_source('waagent', agentPath)
File "/usr/sbin/waagent", line 6, in
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources

Install handler failed for the extension. More information on troubleshooting is available at https://aka.ms/vmextensionlinuxtroubleshoot
`

If we wanted to run on all endorsed distros, we'd need to do some work to improve the test extension. I think we should include this as part of the work to implement the extension in Rust, and limit this workflow to these images for now

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 sync offline... we may need to fix this even before thinking of rewriting the extension

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created task to circle back on this after I migrate remaining scenarios: https://dev.azure.com/msazure/One/_workitems/edit/24442982

- "centos_79"
- "suse_12"
- "rhel_79"
- "ubuntu_1604"
- "ubuntu_1804"
# This test suite uses the DCR Test Extension, which is only published in South Central US
locations: "AzureCloud:southcentralus"
45 changes: 45 additions & 0 deletions tests_e2e/tests/agent_ext_workflow/README.md
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this readme directly from DCR because it contains a lot of useful information about the GuestAgentDcrTestExtension.

Let me know if I should add this information as comments to the test file.

Copy link
Member

Choose a reason for hiding this comment

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

readme is fine, though a summary in the suite file would be helpful

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Agent Extension Worflow Test

This scenario tests if the correct extension workflow sequence is being executed from the agent.

### GuestAgentDcrTestExtension

This is a test extension that exists for the sole purpose of testing the extension workflow of agent. This is currently deployed to SCUS only.
Copy link
Member

Choose a reason for hiding this comment

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

do we have a publishing pipeline for the test extension? could you create one and publish it to all regions? thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

we have CAPS pipeline already and deployed few other regions too. I would restrict to few regions where we create vms and deploying to all of no use.

https://msazure.visualstudio.com/One/_releaseProgress?_a=release-pipeline-progress&releaseId=7405435

https://msazure.visualstudio.com/One/_git/Compute-ART-LinuxExtensions?path=/src/EV2/GATestExtension_ExtensionInfo.xml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we wait on this until we've implemented the test extension in Rust?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nagworld9 those links are for a different test extension. The type name for that extension is GATestExtGo, but the type name for the extension we use in this test suite is GuestAgentDcrTest


All the extension does is prints the settings['name'] out to stdout. It is run everytime enable is called.

Another important feature of this extension is that it maintains a `operations-<VERSION_NO>.log` **for every operation that the agent executes on that extension**. We use this to confirm that the agent executed the correct sequence of operations.

Sample operations-<version>.log file snippet -
```text
Date:2019-07-30T21:54:03Z; Operation:install; SeqNo:0
Date:2019-07-30T21:54:05Z; Operation:enable; SeqNo:0
Date:2019-07-30T21:54:37Z; Operation:enable; SeqNo:1
Date:2019-07-30T21:55:20Z; Operation:disable; SeqNo:1
Date:2019-07-30T21:55:22Z; Operation:uninstall; SeqNo:1
```
The setting for this extension is of the format -
```json
{
"name": String
}
```
##### Repo link
https://github.com/larohra/GuestAgentDcrTestExtension
maddieford marked this conversation as resolved.
Show resolved Hide resolved

##### Available Versions:
- 1.1.5 - Version with Basic functionalities as mentioned above
- 1.2.0 - Same functionalities as above with `"updateMode": "UpdateWithInstall"` in HandlerManifest.json to test update case
- 1.3.0 - Same functionalities as above with `"updateMode": "UpdateWithoutInstall"` in HandlerManifest.json to test update case

### Test Sequence

- Install the test extension on the VM
- Assert the extension status by checking if our Enable string matches the status message (We receive the status message by using the Azure SDK by polling for the VM instance view and parsing the extension status message)

The Enable string of our test is of the following format (this is set in the `Settings` object when we call enable from the tests ) -
```text
[ExtensionName]-[Version], Count: [Enable-count]
```
- Match the operation sequence as per the test and make sure they are in the correct chronological order
- Restart the agent and verify if the correct operation sequence is followed
358 changes: 358 additions & 0 deletions tests_e2e/tests/agent_ext_workflow/extension_workflow.py

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions tests_e2e/tests/lib/agent_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,17 @@ def is_error(r: AgentLogRecord) -> bool:

return errors

def agent_log_contains(self, data: str):
"""
This function looks for the specified test data string in the WALinuxAgent logs and returns if found or not.
:param data: The string to look for in the agent logs
:return: True if test data string found in the agent log and False if not.
"""
for record in self.read():
if data in record.text:
return True
return False

@staticmethod
def _is_systemd():
# Taken from azurelinuxagent/common/osutil/systemd.py; repeated here because it is available only on agents >= 2.3
Expand Down
1 change: 1 addition & 0 deletions tests_e2e/tests/lib/identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ class VmExtensionIds(object):
# New run command extension, with support for multi-config
RunCommandHandler: VmExtensionIdentifier = VmExtensionIdentifier(publisher='Microsoft.CPlat.Core', ext_type='RunCommandHandlerLinux', version="1.0")
VmAccess: VmExtensionIdentifier = VmExtensionIdentifier(publisher='Microsoft.OSTCExtensions', ext_type='VMAccessForLinux', version="1.0")
GuestAgentDcrTestExtension: VmExtensionIdentifier = VmExtensionIdentifier(publisher='Microsoft.Azure.TestExtensions.Edp', ext_type='GuestAgentDcrTest', version='1.0')
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#!/usr/bin/env pypy3

# Microsoft Azure Linux Agent
#
# Copyright 2018 Microsoft Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


import argparse
import os
import sys
import time
from datetime import datetime

DELIMITER = ";"
OPS_FILE_DIR = "/var/log/azure/Microsoft.Azure.TestExtensions.Edp.GuestAgentDcrTest/"
# In general most of the distros use the above directory for extension log logging except RHEL-69,
# they use the 2nd File pattern (i.e. /var/log/azure/{ext-publisher-type}/{version}/extensions.log)
OPS_FILE_PATTERN = ["operations-%s.log", "%s/operations-%s.log"]
MAX_RETRY = 5
SLEEP_TIMER = 30


def parse_ops_log(ops_version, input_ops, start_time):
# input_ops are the expected operations that we expect to see in the operations log file
ver = (ops_version,)
ops_file_name = None
for file_pat in OPS_FILE_PATTERN:
ops_file_name = os.path.join(OPS_FILE_DIR, file_pat % ver)
if not os.path.exists(ops_file_name):
ver = ver + (ops_version,)
ops_file_name = None
continue
break

if not ops_file_name:
raise IOError("Operations File %s not found" % os.path.join(OPS_FILE_DIR, OPS_FILE_PATTERN[0] % ops_version))

ops = []
with open(ops_file_name, 'r') as ops_log:
# we get the last len(input_ops) from the log file and ensure they match with the input_ops
# Example of a line in the log file - `Date:2019-07-30T21:54:03Z; Operation:install; SeqNo:0`
content = ops_log.readlines()[-len(input_ops):]
for op_log in content:
data = op_log.split(DELIMITER)
date = datetime.strptime(data[0].split("Date:")[1], "%Y-%m-%dT%H:%M:%SZ")
op = data[1].split("Operation:")[1]
seq_no = data[2].split("SeqNo:")[1].strip('\n')

# We only capture the operations that > start_time of the test
if start_time > date:
continue

ops.append({'date': date, 'op': op, 'seq_no': seq_no})
return ops


def assert_ops_in_sequence(actual_ops, expected_ops):
exit_code = 0

if len(actual_ops) != len(expected_ops):
print("Operation sequence length doesn't match, exit code 2")
exit_code = 2

last_date = datetime(70, 1, 1)
for idx, val in enumerate(actual_ops):
if exit_code != 0:
break

if val['date'] < last_date or val['op'] != expected_ops[idx]:
print("Operation sequence doesn't match, exit code 2")
exit_code = 2

last_date = val['date']

return exit_code


def check_update_sequence(args):
# old_ops_file_name = OPS_FILE_PATTERN % args.old_version
# new_ops_file_name = OPS_FILE_PATTERN % args.new_version

actual_ops = parse_ops_log(args.old_version, args.old_ops, args.start_time)
actual_ops.extend(parse_ops_log(args.new_version, args.new_ops, args.start_time))
actual_ops = sorted(actual_ops, key=lambda op: op['date'])

exit_code = assert_ops_in_sequence(actual_ops, args.ops)

return exit_code, actual_ops


def check_operation_sequence(args):
# ops_file_name = OPS_FILE_PATTERN % args.version

actual_ops = parse_ops_log(args.version, args.ops, args.start_time)
exit_code = assert_ops_in_sequence(actual_ops, args.ops)

return exit_code, actual_ops


def main():
# There are 2 main ways you can call this file - normal_ops_sequence or update_sequence
parser = argparse.ArgumentParser()
cmd_parsers = parser.add_subparsers(help="sub-command help", dest="command")

# We use start_time to make sure we're testing the correct test and not some other test
parser.add_argument("--start-time", dest='start_time', required=True)

# Normal_ops_sequence gets the version of the ext and parses the corresponding operations file to get the operation
# sequence that were run on the extension
normal_ops_sequence_parser = cmd_parsers.add_parser("normal_ops_sequence", help="Test the normal operation sequence")
normal_ops_sequence_parser.add_argument('--version', dest='version')
normal_ops_sequence_parser.add_argument('--ops', nargs='*', dest='ops', default=argparse.SUPPRESS)

# Update_sequence mode is used to check for the update scenario. We get the expected old operations, expected
# new operations and the final operation list and verify if the expected operations match the actual ones
update_sequence_parser = cmd_parsers.add_parser("update_sequence", help="Test the update operation sequence")
update_sequence_parser.add_argument("--old-version", dest="old_version")
update_sequence_parser.add_argument("--new-version", dest="new_version")
update_sequence_parser.add_argument("--old-ver-ops", nargs="*", dest="old_ops", default=argparse.SUPPRESS)
update_sequence_parser.add_argument("--new-ver-ops", nargs="*", dest="new_ops", default=argparse.SUPPRESS)
update_sequence_parser.add_argument("--final-ops", nargs="*", dest="ops", default=argparse.SUPPRESS)

args, unknown = parser.parse_known_args()

if unknown or len(unknown) > 0:
# Print any unknown arguments passed to this script and fix them with low priority
print("[Low Proiority][To-Fix] Found unknown args: %s" % ', '.join(unknown))

args.start_time = datetime.strptime(args.start_time, "%Y-%m-%dT%H:%M:%SZ")

exit_code = 999
actual_ops = []

for i in range(0, MAX_RETRY):
if args.command == "update_sequence":
exit_code, actual_ops = check_update_sequence(args)
elif args.command == "normal_ops_sequence":
exit_code, actual_ops = check_operation_sequence(args)
else:
print("No such command %s, exit code 5\n" % args.command)
exit_code, actual_ops = 5, []
break

if exit_code == 0:
break

print("{0} test failed with exit code: {1}; Retry attempt: {2}; Retrying in {3} secs".format(args.command,
exit_code, i,
SLEEP_TIMER))
time.sleep(SLEEP_TIMER)

if exit_code != 0:
print("Expected Operations: %s" % ", ".join(args.ops))
print("Actual Operations: %s" %
','.join(["[%s, Date: %s]" % (op['op'], op['date'].strftime("%Y-%m-%dT%H:%M:%SZ")) for op in actual_ops]))

print("Assertion completed, exiting with code: %s" % exit_code)
sys.exit(exit_code)


if __name__ == "__main__":
print("Asserting operations\n")
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env pypy3

# Microsoft Azure Linux Agent
#
# Copyright 2018 Microsoft Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import argparse
import sys

from pathlib import Path
from tests_e2e.tests.lib.agent_log import AgentLog


def main():
parser = argparse.ArgumentParser()
parser.add_argument("--data", dest='data', required=True)
args, _ = parser.parse_known_args()

print("Verifying data: {0} in waagent.log".format(args.data))
found = False

try:
found = AgentLog(Path('/var/log/waagent.log')).agent_log_contains(args.data)
if found:
print("Found data: {0} in agent log".format(args.data))
else:
print("Did not find data: {0} in agent log".format(args.data))
except Exception as e:
print("Error thrown when searching for test data in agent log: {0}".format(str(e)))

sys.exit(0 if found else 1)


if __name__ == "__main__":
main()
Loading