Skip to content

Commit

Permalink
Add tests for extension workflow (#2843)
Browse files Browse the repository at this point in the history
* Update version to dummy 1.0.0.0'

* Revert version change

* Basic structure

* Test must run in SCUS for test ext

* Add GuestAgentDCRTest Extension id

* Test stucture

* Update test file name

* test no location

* Test location as southcentralus

* Assert ext is installed

* Try changing version for dcr test ext

* Update expected message in instance view

* try changing message to string

* Limit images for ext workflow

* Update classes after refactor

* Update class name

* Refactor tests

* Rename extension_install to extension_workflow

* Assert ext status

* Assert operation sequence is expected

* Remove logger reference

* Pass ssh client

* Update ssh

* Add permission to run script

* Correct permissions

* Add execute permissions for helper script

* Make scripts executable

* Change args to string

* Add required parameter

* Add shebang for retart_agent

* Fix arg format

* Use restart utility

* Run restart with sudo

* Add enable scenario

* Attempt to remove start_time

* Only assert enable

* Add delete scenario

* Fix uninstall scenario

* Add extension update scenario

* Run assert scenario on update scenario

* Fix reference to ext

* Format args as str instead of arr

* Update test args

* Add test case for update without install

* Fix delete

* Keep changes

* Save changes

* Add special chars test case

* Fix dcr_ext issue{

* Add validate no lag scenario

* Fix testguid reference

* Add additional log statements for debugging

* Fix message to check before encoding

* Encode setting name

* Correctly check data

* Make check data executable

* Fix command args for special char test

* Fix no lag time

* Fix ssh client reference

* Try message instead of text

* Remove unused method

* Start clean up

* Continue code cleanup

* Fix pylint errors

* Fix pylint errors

* Start refactor

* Debug agent lag

* Update lag logging

* Fix assert_that for lag

* Remove typo

* Add readme for extension_workflow scenario

* Reformat comment

* Improve logging

* Refactor assert scenario

* Remove unused constants

* Remove unusued parameter in assert scenario

* Add logging

* Improve logging

* Improve logging

* Fix soft assertions issue

* Remove todo for delete polling

* Remove unnecessary new line

* removed unnecessary function

* Make special chars log more readable

* remove unnecessary log

* Add version to add or update log

* Remove unnecessary assert instance view

* Add empty log line

* Add update back to restart args to debug

* Add update back to restart args to debug

* Remove unused init

* Remove test_suites from pipeline yml

* Update location in test suite yml

* Add comment for location restriction

* Remove unused init and fix comments

* Improve method header

* Rename scripts

* Remove print_function

* Rename is_data_in_waagent_log

* Add comments describing assert operation sequence script

* add comments to scripts and type annotate assert operation sequence

* Add GuestAgentDcrExtension source code to repo

* Fix typing.dict error

* Fix typing issue

* Remove outdated comment

* Add comments to extension_workflow.py

* rename scripts to match test suite name

* Ignore pylint warnings on test ext

* Update pylint rc to ignore tests_e2e/GuestAgentDcrTestExtension

* Update pylint rc to ignore tests_e2e/GuestAgentDcrTestExtension

* disable all errors/warnings dcr test ext

* disable all errors/warnings dcr test ext

* Run workflow on debian

* Revert to dcr config distros

* Move enable increment to beginning of function

* Fix gs completed regex

* Remove unnessary files from dcr test ext dir
  • Loading branch information
maddieford authored Jul 6, 2023
1 parent a168e25 commit 307e880
Show file tree
Hide file tree
Showing 25 changed files with 2,001 additions and 1 deletion.
123 changes: 123 additions & 0 deletions tests_e2e/GuestAgentDcrTestExtension/GuestAgentDcrTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env python
# pylint: disable=all
from __future__ import print_function

from Utils.WAAgentUtil import waagent
import Utils.HandlerUtil as Util
import sys
import re
import traceback
import os
import datetime

ExtensionShortName = "GADcrTestExt"
OperationFileName = "operations-{0}.log"


def install():
operation = "install"
status = "success"
msg = "Installed successfully"

hutil = parse_context(operation)
hutil.log("Start to install.")
hutil.log(msg)
hutil.do_exit(0, operation, status, '0', msg)


def enable():
# Global Variables definition
operation = "enable"
status = "success"
msg = "Enabled successfully."

# Operations.append(operation)
hutil = parse_context(operation)
hutil.log("Start to enable.")
public_settings = hutil.get_public_settings()
name = public_settings.get("name")
if name:
name = "Name: {0}".format(name)
hutil.log(name)
msg = "{0} {1}".format(msg, name)
print(name)
else:
hutil.error("The name in public settings is not provided.")
# msg = msg % ','.join(Operations)
hutil.log(msg)
hutil.do_exit(0, operation, status, '0', msg)


def disable():
operation = "disable"
status = "success"
msg = "Disabled successfully."

# Operations.append(operation)
hutil = parse_context(operation)
hutil.log("Start to disable.")
# msg % ','.join(Operations)
hutil.log(msg)
hutil.do_exit(0, operation, status, '0', msg)


def uninstall():
operation = "uninstall"
status = "success"
msg = "Uninstalled successfully."

# Operations.append(operation)
hutil = parse_context(operation)
hutil.log("Start to uninstall.")
# msg % ','.join(Operations)
hutil.log(msg)
hutil.do_exit(0, operation, status, '0', msg)


def update():
operation = "update"
status = "success"
msg = "Updated successfully."

# Operations.append(operation)
hutil = parse_context(operation)
hutil.log("Start to update.")
# msg % ','.join(Operations)
hutil.log(msg)
hutil.do_exit(0, operation, status, '0', msg)


def parse_context(operation):
hutil = Util.HandlerUtility(waagent.Log, waagent.Error)
hutil.do_parse_context(operation)
op_log = os.path.join(hutil.get_log_dir(), OperationFileName.format(hutil.get_extension_version()))
with open(op_log, 'a+') as oplog_handler:
oplog_handler.write("Date:{0}; Operation:{1}; SeqNo:{2}\n"
.format(datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"),
operation, hutil.get_seq_no()))
return hutil


def main():
waagent.LoggerInit('/var/log/waagent.log', '/dev/stdout')
waagent.Log("%s started to handle." % (ExtensionShortName))

try:
for a in sys.argv[1:]:
if re.match("^([-/]*)(disable)", a):
disable()
elif re.match("^([-/]*)(uninstall)", a):
uninstall()
elif re.match("^([-/]*)(install)", a):
install()
elif re.match("^([-/]*)(enable)", a):
enable()
elif re.match("^([-/]*)(update)", a):
update()
except Exception as e:
err_msg = "Failed with error: {0}, {1}".format(e, traceback.format_exc())
waagent.Error(err_msg)


if __name__ == '__main__':
main()
14 changes: 14 additions & 0 deletions tests_e2e/GuestAgentDcrTestExtension/HandlerManifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[{
"name": "GuestAgentDcrTestExtension",
"version": 1.0,
"handlerManifest": {
"installCommand": "./GuestAgentDcrTest.py --install",
"uninstallCommand": "./GuestAgentDcrTest.py --uninstall",
"updateCommand": "./GuestAgentDcrTest.py --update",
"enableCommand": "./GuestAgentDcrTest.py --enable",
"disableCommand": "./GuestAgentDcrTest.py --disable",
"updateMode": "UpdateWithoutInstall",
"rebootAfterInstall": false,
"reportHeartbeat": false
}
}]
8 changes: 8 additions & 0 deletions tests_e2e/GuestAgentDcrTestExtension/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
default: build

build:
$(eval NAME = $(shell grep -Pom1 "(?<=<Type>)[^<]+" manifest.xml))
$(eval VERSION = $(shell grep -Pom1 "(?<=<Version>)[^<]+" manifest.xml))

@echo "Building '$(NAME)-$(VERSION).zip' ..."
zip -r9 $(NAME)-$(VERSION).zip *
Loading

0 comments on commit 307e880

Please sign in to comment.