-
Notifications
You must be signed in to change notification settings - Fork 376
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 extensions disabled; refactor VirtualMachine and VmExtension #2824
Changes from all commits
d2b4ac7
24d2318
3386806
ccce69f
c045576
9332d7e
51da9fb
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 |
---|---|---|
|
@@ -19,3 +19,4 @@ azure-identity | |
azure-mgmt-compute>=22.1.0 | ||
azure-mgmt-resource>=15.0.0 | ||
msrestazure | ||
pytz |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/usr/bin/env bash | ||
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. utility taken from #2810 |
||
|
||
# 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. | ||
# | ||
|
||
set -euo pipefail | ||
|
||
# | ||
# The service name is walinuxagent in Ubuntu/debian and waagent elsewhere | ||
# | ||
|
||
usage() ( | ||
echo "Usage: agent-service command" | ||
exit 1 | ||
) | ||
|
||
if [ "$#" -lt 1 ]; then | ||
usage | ||
fi | ||
cmd=$1 | ||
shift | ||
|
||
if [ "$#" -ne 0 ] || [ -z ${cmd+x} ] ; then | ||
usage | ||
fi | ||
|
||
if command -v systemctl &> /dev/null; then | ||
service-status() { systemctl --no-pager -l status $1; } | ||
service-stop() { systemctl stop $1; } | ||
service-restart() { systemctl restart $1; } | ||
service-start() { systemctl start $1; } | ||
else | ||
service-status() { service $1 status; } | ||
service-stop() { service $1 stop; } | ||
service-restart() { service $1 restart; } | ||
service-start() { service $1 start; } | ||
fi | ||
|
||
python=$(get-agent-python) | ||
distro=$($python -c 'from azurelinuxagent.common.version import get_distro; print(get_distro()[0])') | ||
distro=$(echo $distro | tr '[:upper:]' '[:lower:]') | ||
|
||
if [[ $distro == *"ubuntu"* || $distro == *"debian"* ]]; then | ||
service_name="walinuxagent" | ||
else | ||
service_name="waagent" | ||
fi | ||
|
||
echo "Service name: $service_name" | ||
|
||
if [[ "$cmd" == "restart" ]]; then | ||
echo "Restarting service..." | ||
service-restart $service_name | ||
echo "Service status..." | ||
service-status $service_name | ||
fi | ||
|
||
if [[ "$cmd" == "start" ]]; then | ||
echo "Starting service..." | ||
service-start $service_name | ||
fi | ||
|
||
if [[ "$cmd" == "stop" ]]; then | ||
echo "Stopping service..." | ||
service-stop $service_name | ||
fi | ||
|
||
if [[ "$cmd" == "status" ]]; then | ||
echo "Service status..." | ||
service-status $service_name | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env bash | ||
|
||
# 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. | ||
# | ||
|
||
# | ||
# Updates waagent.conf with the specified setting and value and restarts the Agent. | ||
# | ||
|
||
set -euo pipefail | ||
|
||
if [[ $# -ne 2 ]]; then | ||
echo "Usage: update-waagent-conf <setting> <value>" | ||
exit 1 | ||
fi | ||
|
||
name=$1 | ||
value=$2 | ||
|
||
PYTHON=$(get-agent-python) | ||
waagent_conf=$($PYTHON -c 'from azurelinuxagent.common.osutil import get_osutil; print(get_osutil().agent_conf_file_path)') | ||
echo "Setting $name=$value in $waagent_conf" | ||
sed -i -E "/^$name=/d" "$waagent_conf" | ||
sed -i -E "\$a $name=$value" "$waagent_conf" | ||
updated=$(grep "$name" "$waagent_conf") | ||
echo "Updated value: $updated" | ||
agent-service restart |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# | ||
# The test suite disables extension processing and verifies that extensions | ||
# are not processed, but the agent continues reporting status. | ||
# | ||
name: "ExtensionsDisabled" | ||
tests: | ||
- "extensions_disabled.py" | ||
images: "random(endorsed)" | ||
owns_vm: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ | |
from tests_e2e.tests.lib.identifiers import VmExtensionIds, VmExtensionIdentifier | ||
from tests_e2e.tests.lib.logging import log | ||
from tests_e2e.tests.lib.ssh_client import SshClient | ||
from tests_e2e.tests.lib.vm_extension import VmExtension | ||
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. the rename is explained in another comment below |
||
from tests_e2e.tests.lib.virtual_machine_extension_client import VirtualMachineExtensionClient | ||
|
||
|
||
class ExtensionOperationsBvt(AgentTest): | ||
|
@@ -47,7 +47,7 @@ def run(self): | |
|
||
is_arm64: bool = ssh_client.get_architecture() == "aarch64" | ||
|
||
custom_script_2_0 = VmExtension( | ||
custom_script_2_0 = VirtualMachineExtensionClient( | ||
self._context.vm, | ||
VmExtensionIds.CustomScript, | ||
resource_name="CustomScript") | ||
|
@@ -65,15 +65,15 @@ def run(self): | |
) | ||
custom_script_2_0.assert_instance_view(expected_version="2.0", expected_message=message) | ||
|
||
custom_script_2_1 = VmExtension( | ||
custom_script_2_1 = VirtualMachineExtensionClient( | ||
self._context.vm, | ||
VmExtensionIdentifier(VmExtensionIds.CustomScript.publisher, VmExtensionIds.CustomScript.type, "2.1"), | ||
resource_name="CustomScript") | ||
|
||
if is_arm64: | ||
log.info("Installing %s", custom_script_2_1) | ||
else: | ||
log.info("Updating %s to %s", custom_script_2_0, custom_script_2_1) | ||
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 was just logging "Updating CustomScript to CustomScript" |
||
log.info("Updating %s", custom_script_2_0) | ||
|
||
message = f"Hello {uuid.uuid4()}!" | ||
custom_script_2_1.enable( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env python3 | ||
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. new test |
||
|
||
# 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. | ||
# | ||
|
||
# | ||
# This test disables extension processing on waagent.conf and verifies that extensions are not processed, but the | ||
# agent continues reporting status. | ||
# | ||
|
||
import datetime | ||
import pytz | ||
|
||
from assertpy import assert_that, fail | ||
|
||
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.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 ExtensionsDisabled(AgentTest): | ||
def run(self): | ||
ssh_client: SshClient = self._context.create_ssh_client() | ||
|
||
# Disable extension processing on the test VM | ||
log.info("Disabling extension processing on the test VM [%s]", self._context.vm.name) | ||
output = ssh_client.run_command("update-waagent-conf Extensions.Enabled n", use_sudo=True) | ||
log.info("Disable completed:\n%s", output) | ||
|
||
# From now on, extensions will time out; set the timeout to the minimum allowed(15 minutes) | ||
log.info("Setting the extension timeout to 15 minutes") | ||
vm: VirtualMachineClient = VirtualMachineClient(self._context.vm) | ||
|
||
vm.update({"extensionsTimeBudget": "PT15M"}) | ||
|
||
disabled_timestamp: datetime.datetime = datetime.datetime.utcnow() - datetime.timedelta(minutes=60) | ||
|
||
# | ||
# Validate that the agent is not processing extensions by attempting to run CustomScript | ||
# | ||
log.info("Executing CustomScript; it should time out after 15 min or so.") | ||
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 timed out") | ||
except Exception as error: | ||
assert_that("VMExtensionProvisioningTimeout" in str(error)) \ | ||
.described_as(f"Expected a VMExtensionProvisioningTimeout: {error}") \ | ||
.is_true() | ||
log.info("CustomScript timed out as expected") | ||
|
||
# | ||
# Validate that the agent continued reporting status even if it is not processing extensions | ||
# | ||
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].display_status).described_as("The VM Agent should be ready").is_equal_to('Ready') | ||
# The time in the status is time zone aware and 'disabled_timestamp' is not; we need to make the latter time zone aware before comparing them | ||
assert_that(instance_view.vm_agent.statuses[0].time)\ | ||
.described_as("The VM Agent should be have reported status even after extensions were disabled")\ | ||
.is_greater_than(pytz.utc.localize(disabled_timestamp)) | ||
log.info("The VM Agent reported status after extensions were disabled, as expected.") | ||
|
||
|
||
if __name__ == "__main__": | ||
ExtensionsDisabled.run_from_command_line() |
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.
The runbook has an option to skip setup. If that option is set, the working directory still needs to be created, so I separated this into its own method, which is always called.
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.
In what cases would we skip setup?
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.
During development when executing a test suite multiple times on the same machine. Once setup is done, skipping it saves some time when executing the test suite. This helps to follow a development model in which one does small changes when writing a test and executes the test frequently to try those changes.