Skip to content

Commit

Permalink
Merge branch 'develop' into fix-nostatus-ut
Browse files Browse the repository at this point in the history
  • Loading branch information
narrieta authored Apr 18, 2022
2 parents 00a1920 + ae5cff8 commit 2e34d19
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 117 deletions.
5 changes: 2 additions & 3 deletions azurelinuxagent/common/protocol/hostplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,8 @@ def format_message(msg):
logger.info(message)
add_event(op=WALAEventOperation.HostPlugin, message=message, is_success=True)

# Don't support HostGAPlugin versions older than 123
# TODO: update the minimum version to 1.0.8.123 before release
if vm_settings.host_ga_plugin_version < FlexibleVersion("1.0.8.117"):
# Don't support HostGAPlugin versions older than 124
if vm_settings.host_ga_plugin_version < FlexibleVersion("1.0.8.124"):
raise_not_supported()

self._supports_vm_settings = True
Expand Down
7 changes: 3 additions & 4 deletions dcr/templates/setup-vm-and-execute-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
displayName: 'Install SSH Key to agent'
name: "InstallKey"
inputs:
knownHostsEntry: '$(SSH_PUBLIC)'
knownHostsEntry: 'github.com $(SSH_PUBLIC)' # Adding a dummy known host for github.com as leaving it empty is not allowed by this task
sshPublicKey: '$(SSH_PUBLIC)'
sshKeySecureFile: 'id_rsa'

Expand All @@ -52,9 +52,8 @@ jobs:
architecture: 'x64'

- script: |
rm -rf ~/.ssh/known_hosts
mkdir -p "$(Build.ArtifactStagingDirectory)/harvest"
displayName: "Clear known host keys and create directories"
displayName: "Create harvest directories"
- bash: $(Build.SourcesDirectory)/dcr/scripts/build_agent_zip.sh
displayName: "Build Agent Zip"
Expand Down Expand Up @@ -205,4 +204,4 @@ jobs:
- publish: $(Build.ArtifactStagingDirectory)/harvest
artifact: $(rgName)-harvest
condition: and(failed(), eq(variables.executeTests, 'true'))
displayName: 'Publish Harvest logs'
displayName: 'Publish Harvest logs'
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"hostGAPluginVersion": "1.0.8.123",
"hostGAPluginVersion": "1.0.8.124",
"vmSettingsSchemaVersion": "0.0",
"activityId": "a33f6f53-43d6-4625-b322-1a39651a00c9",
"correlationId": "9a47a2a2-e740-4bfc-b11b-4f2f7cfe7d2e",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/hostgaplugin/vm_settings-empty_depends_on.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"hostGAPluginVersion": "1.0.8.123",
"hostGAPluginVersion": "1.0.8.124",
"vmSettingsSchemaVersion": "0.0",
"activityId": "2e7f8b5d-f637-4721-b757-cb190d49b4e9",
"correlationId": "1bef4c48-044e-4225-8f42-1d1eac1eb158",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/hostgaplugin/vm_settings-invalid_blob_type.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"hostGAPluginVersion": "1.0.8.123",
"hostGAPluginVersion": "1.0.8.124",
"vmSettingsSchemaVersion": "0.0",
"activityId": "2e7f8b5d-f637-4721-b757-cb190d49b4e9",
"correlationId": "1bef4c48-044e-4225-8f42-1d1eac1eb158",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"hostGAPluginVersion": "1.0.8.123",
"hostGAPluginVersion": "1.0.8.124",
"vmSettingsSchemaVersion": "0.0",
"activityId": "89d50bf1-fa55-4257-8af3-3db0c9f81ab4",
"correlationId": "c143f8f0-a66b-4881-8c06-1efd278b0b02",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"hostGAPluginVersion": "1.0.8.123",
"hostGAPluginVersion": "1.0.8.124",
"vmSettingsSchemaVersion": "0.0",
"activityId": "a33f6f53-43d6-4625-b322-1a39651a00c9",
"correlationId": "9a47a2a2-e740-4bfc-b11b-4f2f7cfe7d2e",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/hostgaplugin/vm_settings-out-of-sync.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"hostGAPluginVersion": "1.0.8.123",
"hostGAPluginVersion": "1.0.8.124",
"vmSettingsSchemaVersion": "0.0",
"activityId": "AAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE",
"correlationId": "EEEEEEEE-DDDD-CCCC-BBBB-AAAAAAAAAAAA",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/hostgaplugin/vm_settings-parse_error.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"hostGAPluginVersion": "1.0.8.123",
"hostGAPluginVersion": "1.0.8.124",
"vmSettingsSchemaVersion": THIS_IS_A_SYNTAX_ERROR,
"activityId": "a33f6f53-43d6-4625-b322-1a39651a00c9",
"correlationId": "9a47a2a2-e740-4bfc-b11b-4f2f7cfe7d2e",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/hostgaplugin/vm_settings-requested_version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"hostGAPluginVersion": "1.0.8.123",
"hostGAPluginVersion": "1.0.8.124",
"vmSettingsSchemaVersion": "0.0",
"activityId": "a33f6f53-43d6-4625-b322-1a39651a00c9",
"correlationId": "9a47a2a2-e740-4bfc-b11b-4f2f7cfe7d2e",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/hostgaplugin/vm_settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"hostGAPluginVersion": "1.0.8.123",
"hostGAPluginVersion": "1.0.8.124",
"vmSettingsSchemaVersion": "0.0",
"activityId": "a33f6f53-43d6-4625-b322-1a39651a00c9",
"correlationId": "9a47a2a2-e740-4bfc-b11b-4f2f7cfe7d2e",
Expand Down
36 changes: 27 additions & 9 deletions tests/ga/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,25 @@
def mock_update_handler(protocol, iterations=1, on_new_iteration=lambda _: None, exthandlers_handler=None, remote_access_handler=None, enable_agent_updates=False):
"""
Creates a mock UpdateHandler that executes its main loop for the given 'iterations'.
If 'on_new_iteration' is given, it is invoked at the beginning of each iteration passing the iteration number as argument.
Network requests (e.g. requests for the goal state) are done using the given 'protocol'.
The mock UpdateHandler uses mock no-op ExtHandlersHandler and RemoteAccessHandler, unless they are given by 'exthandlers_handler' and 'remote_access_handler'.
Agent updates are disabled, unless specified otherwise with 'enable_agent_updates'.
Background threads (monitor, env, telemetry, etc) are not started.
* If 'on_new_iteration' is given, it is invoked at the beginning of each iteration passing the iteration number as argument.
* Network requests (e.g. requests for the goal state) are done using the given 'protocol'.
* The mock UpdateHandler uses mock no-op ExtHandlersHandler and RemoteAccessHandler, unless they are given by 'exthandlers_handler' and 'remote_access_handler'.
* Agent updates are disabled, unless specified otherwise with 'enable_agent_updates'.
* Background threads (monitor, env, telemetry, etc) are not started.
* The UpdateHandler is augmented with these extra functions:
* get_exit_code() - returns the code passed to sys.exit() when the handler exits
* get_iterations() - returns the number of iterations executed by the main loop
"""
iteration_count = [0]

def is_running(*args): # mock for property UpdateHandler.is_running, which controls the main loop
if len(args) == 0:
# getter
iteration_count[0] += 1
on_new_iteration(iteration_count[0])
return iteration_count[0] <= iterations
enter_loop = iteration_count[0] < iterations
if enter_loop:
iteration_count[0] += 1
on_new_iteration(iteration_count[0])
return enter_loop
else:
# setter
return None
Expand All @@ -60,9 +65,22 @@ def is_running(*args): # mock for property UpdateHandler.is_running, which cont
with patch.object(UpdateHandler, "_start_threads"):
with patch.object(UpdateHandler, "_check_threads_running"):
with patch('time.sleep', side_effect=lambda _: mock_sleep(0.001)):
with patch('sys.exit', side_effect=lambda _: 0):
with patch('sys.exit', side_effect=lambda _: 0) as mock_exit:
def get_exit_code():
if mock_exit.call_count == 0:
raise Exception("The UpdateHandler did not exit")
if mock_exit.call_count != 1:
raise Exception("The UpdateHandler exited multiple times ({0})".format(mock_exit.call_count))
args, _ = mock_exit.call_args
return args[0]

def get_iterations():
return iteration_count[0]

update_handler = get_update_handler()
update_handler.protocol_util.get_protocol = Mock(return_value=protocol)
update_handler.get_exit_code = get_exit_code
update_handler.get_iterations = get_iterations

yield update_handler

Loading

0 comments on commit 2e34d19

Please sign in to comment.