-
Notifications
You must be signed in to change notification settings - Fork 372
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 test for osProfile.linuxConfiguration.provisionVMAgent #2826
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# | ||
# Disables Agent provisioning using osProfile.linuxConfiguration.provisionVMAgent and verifies that the agent is disabled | ||
# and extension operations are not allowed. | ||
# | ||
name: "AgentNotProvisioned" | ||
tests: | ||
- "agent_not_provisioned/agent_not_provisioned.py" | ||
images: "random(endorsed)" | ||
template: "agent_not_provisioned/template.py" | ||
owns_vm: true | ||
install_test_agent: false | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,5 @@ tests: | |
- "bvts/vm_access.py" | ||
- "no_outbound_connections/check_fallback_to_hgap.py" | ||
images: "random(endorsed)" | ||
template: "no_outbound_connections/nsg_template.py" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renamed 'nsg_template.py' to 'template.py' for consistency with the agent_not_provisioned suite |
||
template: "no_outbound_connections/template.py" | ||
owns_vm: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# 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. | ||
# | ||
from assertpy import fail, assert_that | ||
from typing import Any, Dict, List | ||
|
||
from azure.mgmt.compute.models import VirtualMachineInstanceView | ||
|
||
from tests_e2e.tests.lib.agent_test import AgentTest | ||
from tests_e2e.tests.lib.identifiers import VmExtensionIds | ||
from tests_e2e.tests.lib.logging import log | ||
from tests_e2e.tests.lib.shell import CommandError | ||
from tests_e2e.tests.lib.ssh_client import SshClient | ||
from tests_e2e.tests.lib.virtual_machine_client import VirtualMachineClient | ||
from tests_e2e.tests.lib.virtual_machine_extension_client import VirtualMachineExtensionClient | ||
|
||
|
||
class AgentNotProvisioned(AgentTest): | ||
""" | ||
When osProfile.linuxConfiguration.provisionVMAgent is set to 'false', this test verifies that | ||
the agent is disabled and that extension operations are not allowed. | ||
""" | ||
def run(self): | ||
# | ||
# Check the agent's log for the messages that indicate it is disabled. | ||
# | ||
ssh_client: SshClient = self._context.create_ssh_client() | ||
|
||
log.info("Checking the Agent's log to verify that it is disabled.") | ||
try: | ||
output = ssh_client.run_command(""" | ||
grep -E 'WARNING.*Daemon.*Disabling guest agent in accordance with ovf-env.xml' /var/log/waagent.log || \ | ||
grep -E 'WARNING.*Daemon.*Disabling the guest agent by sleeping forever; to re-enable, remove /var/lib/waagent/disable_agent and restart' /var/log/waagent.log | ||
""") | ||
log.info("The Agent is disabled, log message: [%s]", output.rstrip()) | ||
except CommandError as e: | ||
fail(f"The agent's log does not contain the expected messages: {e}") | ||
|
||
# | ||
# Validate that the agent is not reporting status. | ||
# | ||
log.info("Verifying that the Agent status is 'Not Ready' (i.e. it is not reporting status).") | ||
vm: VirtualMachineClient = VirtualMachineClient(self._context.vm) | ||
instance_view: VirtualMachineInstanceView = vm.get_instance_view() | ||
log.info("Instance view of VM Agent:\n%s", instance_view.vm_agent.serialize()) | ||
assert_that(instance_view.vm_agent.statuses).described_as("The VM agent should have exactly 1 status").is_length(1) | ||
assert_that(instance_view.vm_agent.statuses[0].code).described_as("The VM Agent should not be available").is_equal_to('ProvisioningState/Unavailable') | ||
assert_that(instance_view.vm_agent.statuses[0].display_status).described_as("The VM Agent should not ready").is_equal_to('Not Ready') | ||
log.info("The Agent status is 'Not Ready'") | ||
|
||
# | ||
# Validate that extensions cannot be executed. | ||
# | ||
log.info("Verifying that extension processing is disabled.") | ||
log.info("Executing CustomScript; it should fail.") | ||
custom_script = VirtualMachineExtensionClient(self._context.vm, VmExtensionIds.CustomScript, resource_name="CustomScript") | ||
try: | ||
custom_script.enable(settings={'commandToExecute': "date"}, force_update=True, timeout=20 * 60) | ||
fail("CustomScript should have failed") | ||
except Exception as error: | ||
assert_that("OperationNotAllowed" in str(error)) \ | ||
.described_as(f"Expected an OperationNotAllowed: {error}") \ | ||
.is_true() | ||
log.info("CustomScript failed, as expected: %s", error) | ||
|
||
def get_ignore_error_rules(self) -> List[Dict[str, Any]]: | ||
return [ | ||
{'message': 'Disabling guest agent in accordance with ovf-env.xml'}, | ||
{'message': 'Disabling the guest agent by sleeping forever; to re-enable, remove /var/lib/waagent/disable_agent and restart'} | ||
] | ||
|
||
|
||
if __name__ == "__main__": | ||
AgentNotProvisioned.run_from_command_line() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# 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. | ||
# | ||
|
||
from typing import Any | ||
|
||
|
||
def update_arm_template(template: Any) -> None: | ||
""" | ||
Customizes the ARM template to set osProfile.linuxConfiguration.provisionVMAgent to false. | ||
""" | ||
# | ||
# NOTE: LISA's template uses this function to generate the value for osProfile.linuxConfiguration. The function is | ||
# under the 'lisa' namespace. | ||
# | ||
# "getLinuxConfiguration": { | ||
# "parameters": [ | ||
# { | ||
# "name": "keyPath", | ||
# "type": "string" | ||
# }, | ||
# { | ||
# "name": "publicKeyData", | ||
# "type": "string" | ||
# } | ||
# ], | ||
# "output": { | ||
# "type": "object", | ||
# "value": { | ||
# "disablePasswordAuthentication": true, | ||
# "ssh": { | ||
# "publicKeys": [ | ||
# { | ||
# "path": "[parameters('keyPath')]", | ||
# "keyData": "[parameters('publicKeyData')]" | ||
# } | ||
# ] | ||
# }, | ||
# "provisionVMAgent": true | ||
# } | ||
# } | ||
# } | ||
# | ||
# The code below sets template['functions'][i]['members']['getLinuxConfiguration']['output']['value']['provisionVMAgent'] to True, | ||
# where template['functions'][i] is the 'lisa' namespace. | ||
# | ||
functions = template.get("functions") | ||
if functions is None: | ||
raise Exception('Cannot find "functions" in the LISA template.') | ||
for namespace in functions: | ||
name = namespace.get("namespace") | ||
if name is None: | ||
raise Exception(f'Cannot find "namespace" in the LISA template: {namespace}') | ||
if name == "lisa": | ||
members = namespace.get('members') | ||
if members is None: | ||
raise Exception(f'Cannot find the members of the lisa namespace in the LISA template: {namespace}') | ||
get_linux_configuration = members.get('getLinuxConfiguration') | ||
if get_linux_configuration is None: | ||
raise Exception(f'Cannot find the "getLinuxConfiguration" function the lisa namespace in the LISA template: {namespace}') | ||
output = get_linux_configuration.get('output') | ||
if output is None: | ||
raise Exception(f'Cannot find the "output" of the getLinuxConfiguration function in the LISA template: {get_linux_configuration}') | ||
value = output.get('value') | ||
if value is None: | ||
raise Exception(f"Cannot find the output's value of the getLinuxConfiguration function in the LISA template: {get_linux_configuration}") | ||
value['provisionVMAgent'] = False | ||
break | ||
else: | ||
raise Exception(f'Cannot find the "lisa" namespace in the LISA template: {functions}') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import pytz | ||
|
||
from assertpy import assert_that, fail | ||
from typing import Any, Dict, List | ||
|
||
from azure.mgmt.compute.models import VirtualMachineInstanceView | ||
|
||
|
@@ -81,6 +82,11 @@ def run(self): | |
.is_greater_than(pytz.utc.localize(disabled_timestamp)) | ||
log.info("The VM Agent reported status after extensions were disabled, as expected.") | ||
|
||
def get_ignore_error_rules(self) -> List[Dict[str, Any]]: | ||
return [ | ||
{'message': 'No handler status found for Microsoft.Azure.Extensions.CustomScript'}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This message showed up in today's daily run. Will be there or not depending on the timing of the test |
||
] | ||
|
||
|
||
if __name__ == "__main__": | ||
ExtensionsDisabled.run_from_command_line() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -209,6 +209,15 @@ def get_errors(self) -> List[AgentLogRecord]: | |
'if': lambda r: DISTRO_NAME == 'ubuntu' and DISTRO_VERSION >= '22.00' | ||
}, | ||
# | ||
# Old daemons can produce this message | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the new test suite disables the agent, agent update does not happen and this message shows up in some distros. |
||
# | ||
# 2023-05-24T18:04:27.467009Z WARNING Daemon Daemon Could not mount cgroups: [Errno 1] Operation not permitted: '/sys/fs/cgroup/cpu,cpuacct' -> '/sys/fs/cgroup/cpu' | ||
# | ||
{ | ||
'message': r"Could not mount cgroups: \[Errno 1\] Operation not permitted", | ||
'if': lambda r: r.prefix == 'Daemon' | ||
}, | ||
# | ||
# 2022-02-09T04:50:37.384810Z ERROR ExtHandler ExtHandler Error fetching the goal state: [ProtocolError] GET vmSettings [correlation ID: 2bed9b62-188e-4668-b1a8-87c35cfa4927 eTag: 7031887032544600793]: [Internal error in HostGAPlugin] [HTTP Failed] [502: Bad Gateway] b'{ "errorCode": "VMArtifactsProfileBlobContentNotFound", "message": "VM artifacts profile blob has no content in it.", "details": ""}' | ||
# | ||
# Fetching the goal state may catch the HostGAPlugin in the process of computing the vmSettings. This can be ignored, if the issue persist the log would include other errors as well. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding '.' to the tarball was overwriting the attributes of the home directory on the test machine (we extract the tarball with cwd set to $HOME). This was causing SSH issues on some distros, on which the SSH server checks the mode of $HOME and refuses the connection if it is too open.
Instead of adding '.', now we cd to the source directory and add '*'. The other 2 invocations of tar were OK, but I also changed them for consistency.