Skip to content

Commit

Permalink
Bug Fix: Change fast track timestamp default from None to datetime.min (
Browse files Browse the repository at this point in the history
Azure#2577)

(cherry picked from commit 35fed83)
  • Loading branch information
kevinclark19a authored and Kevin committed May 10, 2022
1 parent f0c0fb8 commit 801b109
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 6 deletions.
4 changes: 2 additions & 2 deletions azurelinuxagent/common/protocol/hostplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __init__(self, endpoint):
if not os.path.exists(self._get_fast_track_state_file()):
self._supports_vm_settings = False
self._supports_vm_settings_next_check = datetime.datetime.now()
self._fast_track_timestamp = None
self._fast_track_timestamp = timeutil.create_timestamp(datetime.datetime.min)
else:
self._supports_vm_settings = True
self._supports_vm_settings_next_check = datetime.datetime.now()
Expand Down Expand Up @@ -443,7 +443,7 @@ def get_fast_track_timestamp():
goal state was Fabric or fetch_vm_settings() has not been invoked.
"""
if not os.path.exists(HostPluginProtocol._get_fast_track_state_file()):
return None
return timeutil.create_timestamp(datetime.datetime.min)

try:
with open(HostPluginProtocol._get_fast_track_state_file(), "r") as file_:
Expand Down
192 changes: 192 additions & 0 deletions tests/data/hostgaplugin/vm_settings-fabric-no_thumbprints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
{
"hostGAPluginVersion": "1.0.8.124",
"vmSettingsSchemaVersion": "0.0",
"activityId": "a33f6f53-43d6-4625-b322-1a39651a00c9",
"correlationId": "9a47a2a2-e740-4bfc-b11b-4f2f7cfe7d2e",
"inSvdSeqNo": 1,
"extensionsLastModifiedTickCount": 637726657706205299,
"extensionGoalStatesSource": "Fabric",
"onHold": true,
"statusUploadBlob": {
"statusBlobType": "BlockBlob",
"value": "https://dcrcl3a0xs.blob.core.windows.net/$system/edp0plkw2b.86f4ae0a-61f8-48ae-9199-40f402d56864.status?sv=2018-03-28&sr=b&sk=system-1&sig=KNWgC2%3d&se=9999-01-01T00%3a00%3a00Z&sp=w"
},
"inVMMetadata": {
"subscriptionId": "8e037ad4-618f-4466-8bc8-5099d41ac15b",
"resourceGroupName": "rg-dc-86fjzhp",
"vmName": "edp0plkw2b",
"location": "CentralUSEUAP",
"vmId": "86f4ae0a-61f8-48ae-9199-40f402d56864",
"vmSize": "Standard_B2s",
"osType": "Linux"
},
"requiredFeatures": [
{
"name": "MultipleExtensionsPerHandler"
}
],
"gaFamilies": [
{
"name": "Prod",
"uris": [
"https://zrdfepirv2cdm03prdstr01a.blob.core.windows.net/7d89d439b79f4452950452399add2c90/Microsoft.OSTCLinuxAgent_Prod_uscentraleuap_manifest.xml",
"https://ardfepirv2cdm03prdstr01a.blob.core.windows.net/7d89d439b79f4452950452399add2c90/Microsoft.OSTCLinuxAgent_Prod_uscentraleuap_manifest.xml"
]
},
{
"name": "Test",
"uris": [
"https://zrdfepirv2cdm03prdstr01a.blob.core.windows.net/7d89d439b79f4452950452399add2c90/Microsoft.OSTCLinuxAgent_Test_uscentraleuap_manifest.xml",
"https://ardfepirv2cdm03prdstr01a.blob.core.windows.net/7d89d439b79f4452950452399add2c90/Microsoft.OSTCLinuxAgent_Test_uscentraleuap_manifest.xml"
]
}
],
"extensionGoalStates": [
{
"name": "Microsoft.Azure.Monitor.AzureMonitorLinuxAgent",
"version": "1.9.1",
"location": "https://zrdfepirv2cbn04prdstr01a.blob.core.windows.net/a47f0806d764480a8d989d009c75007d/Microsoft.Azure.Monitor_AzureMonitorLinuxAgent_useast2euap_manifest.xml",
"failoverlocation": "https://zrdfepirv2cbn06prdstr01a.blob.core.windows.net/a47f0806d764480a8d989d009c75007d/Microsoft.Azure.Monitor_AzureMonitorLinuxAgent_useast2euap_manifest.xml",
"additionalLocations": ["https://zrdfepirv2cbn09pr02a.blob.core.windows.net/a47f0806d764480a8d989d009c75007d/Microsoft.Azure.Monitor_AzureMonitorLinuxAgent_useast2euap_manifest.xml"],
"state": "enabled",
"autoUpgrade": true,
"runAsStartupTask": false,
"isJson": true,
"useExactVersion": true,
"settingsSeqNo": 0,
"settings": [
{
"publicSettings": "{\"GCS_AUTO_CONFIG\":true}"
}
]
},
{
"name": "Microsoft.Azure.Security.Monitoring.AzureSecurityLinuxAgent",
"version": "2.15.112",
"location": "https://zrdfepirv2cbn04prdstr01a.blob.core.windows.net/4ef06ad957494df49c807a5334f2b5d2/Microsoft.Azure.Security.Monitoring_AzureSecurityLinuxAgent_useast2euap_manifest.xml",
"failoverlocation": "https://zrdfepirv2cbz06prdstr01a.blob.core.windows.net/4ef06ad957494df49c807a5334f2b5d2/Microsoft.Azure.Security.Monitoring_AzureSecurityLinuxAgent_useast2euap_manifest.xml",
"additionalLocations": ["https://zrdfepirv2cbn06prdstr01a.blob.core.windows.net/4ef06ad957494df49c807a5334f2b5d2/Microsoft.Azure.Security.Monitoring_AzureSecurityLinuxAgent_useast2euap_manifest.xml"],
"state": "enabled",
"autoUpgrade": true,
"runAsStartupTask": false,
"isJson": true,
"useExactVersion": true,
"settingsSeqNo": 0,
"settings": [
{
"publicSettings": "{\"enableGenevaUpload\":true}"
}
]
},
{
"name": "Microsoft.Azure.Extensions.CustomScript",
"version": "2.1.6",
"location": "https://umsavwggj2v40kvqhc0w.blob.core.windows.net/5237dd14-0aad-f051-0fad-1e33e1b63091/5237dd14-0aad-f051-0fad-1e33e1b63091_manifest.xml",
"failoverlocation": "https://umsafwzhkbm1rfrhl0ws.blob.core.windows.net/5237dd14-0aad-f051-0fad-1e33e1b63091/5237dd14-0aad-f051-0fad-1e33e1b63091_manifest.xml",
"additionalLocations": [
"https://umsanh4b5rfz0q0p4pwm.blob.core.windows.net/5237dd14-0aad-f051-0fad-1e33e1b63091/5237dd14-0aad-f051-0fad-1e33e1b63091_manifest.xml"
],
"state": "enabled",
"autoUpgrade": true,
"runAsStartupTask": false,
"isJson": true,
"useExactVersion": true,
"settingsSeqNo": 0,
"isMultiConfig": false,
"settings": [
{
"publicSettings": "{\"commandToExecute\":\"echo 'cee174d4-4daa-4b07-9958-53b9649445c2'\"}"
}
],
"dependsOn": [
{
"DependsOnExtension": [
{
"handler": "Microsoft.Azure.Security.Monitoring.AzureSecurityLinuxAgent"
}
],
"dependencyLevel": 1
}
]
},
{
"name": "Microsoft.CPlat.Core.RunCommandHandlerLinux",
"version": "1.2.0",
"location": "https://umsavbvncrpzbnxmxzmr.blob.core.windows.net/f4086d41-69f9-3103-78e0-8a2c7e789d0f/f4086d41-69f9-3103-78e0-8a2c7e789d0f_manifest.xml",
"failoverlocation": "https://umsajbjtqrb3zqjvgb2z.blob.core.windows.net/f4086d41-69f9-3103-78e0-8a2c7e789d0f/f4086d41-69f9-3103-78e0-8a2c7e789d0f_manifest.xml",
"additionalLocations": [
"https://umsawqtlsshtn5v2nfgh.blob.core.windows.net/f4086d41-69f9-3103-78e0-8a2c7e789d0f/f4086d41-69f9-3103-78e0-8a2c7e789d0f_manifest.xml"
],
"state": "enabled",
"autoUpgrade": true,
"runAsStartupTask": false,
"isJson": true,
"useExactVersion": true,
"settingsSeqNo": 0,
"isMultiConfig": true,
"settings": [
{
"publicSettings": "{\"source\":{\"script\":\"echo '4abb1e88-f349-41f8-8442-247d9fdfcac5'\"}}",
"seqNo": 0,
"extensionName": "MCExt1",
"extensionState": "enabled"
},
{
"publicSettings": "{\"source\":{\"script\":\"echo 'e865c9bc-a7b3-42c6-9a79-cfa98a1ee8b3'\"}}",
"seqNo": 0,
"extensionName": "MCExt2",
"extensionState": "enabled"
},
{
"publicSettings": "{\"source\":{\"script\":\"echo 'f923e416-0340-485c-9243-8b84fb9930c6'\"}}",
"seqNo": 0,
"extensionName": "MCExt3",
"extensionState": "enabled"
}
],
"dependsOn": [
{
"dependsOnExtension": [
{
"extension": "...",
"handler": "..."
},
{
"extension": "...",
"handler": "..."
}
],
"dependencyLevel": 2,
"name": "MCExt1"
},
{
"dependsOnExtension": [
{
"extension": "...",
"handler": "..."
}
],
"dependencyLevel": 1,
"name": "MCExt2"
}
]
},
{
"name": "Microsoft.OSTCExtensions.VMAccessForLinux",
"version": "1.5.11",
"location": "https://umsasc25p0kjg0c1dg4b.blob.core.windows.net/2bbece4f-0283-d415-b034-cc0adc6997a1/2bbece4f-0283-d415-b034-cc0adc6997a1_manifest.xml",
"failoverlocation": "https://umsamfwlmfshvxx2lsjm.blob.core.windows.net/2bbece4f-0283-d415-b034-cc0adc6997a1/2bbece4f-0283-d415-b034-cc0adc6997a1_manifest.xml",
"additionalLocations": [
"https://umsah3cwjlctnmhsvzqv.blob.core.windows.net/2bbece4f-0283-d415-b034-cc0adc6997a1/2bbece4f-0283-d415-b034-cc0adc6997a1_manifest.xml"
],
"state": "enabled",
"autoUpgrade": false,
"runAsStartupTask": false,
"isJson": true,
"useExactVersion": true,
"settingsSeqNo": 0,
"isMultiConfig": false,
"settings": [ ]
}
]
}
55 changes: 51 additions & 4 deletions tests/ga/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
VMAgentUpdateStatuses
from azurelinuxagent.common.protocol.util import ProtocolUtil
from azurelinuxagent.common.protocol.wire import WireProtocol
from azurelinuxagent.common.utils import fileutil, restutil, textutil
from azurelinuxagent.common.utils import fileutil, restutil, textutil, timeutil
from azurelinuxagent.common.utils.archive import ARCHIVE_DIRECTORY_NAME, AGENT_STATUS_FILE
from azurelinuxagent.common.utils.flexible_version import FlexibleVersion
from azurelinuxagent.common.utils.networkutil import FirewallCmdDirectCommands, AddFirewallRules
Expand All @@ -52,7 +52,7 @@
READONLY_FILE_GLOBS, ExtensionsSummary, AgentUpgradeType
from tests.ga.mocks import mock_update_handler
from tests.protocol.mocks import mock_wire_protocol, MockHttpResponse
from tests.protocol.mockwiredata import DATA_FILE, DATA_FILE_MULTIPLE_EXT
from tests.protocol.mockwiredata import DATA_FILE, DATA_FILE_MULTIPLE_EXT, DATA_FILE_VM_SETTINGS
from tests.tools import AgentTestCase, AgentTestCaseWithGetVmSizeMock, data_dir, DEFAULT, patch, load_bin_data, Mock, MagicMock, \
clear_singleton_instances
from tests.protocol import mockwiredata
Expand Down Expand Up @@ -2827,16 +2827,63 @@ def test_it_should_mark_outdated_goal_states_on_service_restart_when_host_ga_plu
def test_it_should_clear_the_timestamp_for_the_most_recent_fast_track_goal_state(self):
data_file = self._prepare_fast_track_goal_state()

if HostPluginProtocol.get_fast_track_timestamp() is None:
if HostPluginProtocol.get_fast_track_timestamp() == timeutil.create_timestamp(datetime.min):
raise Exception("The test setup did not save the Fast Track state")

with patch("azurelinuxagent.common.conf.get_enable_fast_track", return_value=False):
with mock_wire_protocol(data_file) as protocol:
with mock_update_handler(protocol) as update_handler:
update_handler.run()

self.assertIsNone(HostPluginProtocol.get_fast_track_timestamp(), "The Fast Track state was not cleared")
self.assertEqual(HostPluginProtocol.get_fast_track_timestamp(), timeutil.create_timestamp(datetime.min),
"The Fast Track state was not cleared")

def test_it_should_default_fast_track_timestamp_to_datetime_min(self):
data = DATA_FILE_VM_SETTINGS.copy()
# TODO: Currently, there's a limitation in the mocks where bumping the incarnation but the goal
# state will cause the agent to error out while trying to write the certificates to disk. These
# files have no dependencies on certs, so using them does not present that issue.
#
# Note that the scenario this test is representing does not depend on certificates at all, and
# can be changed to use the default files when the above limitation is addressed.
data["vm_settings"] = "hostgaplugin/vm_settings-fabric-no_thumbprints.json"
data['goal_state'] = 'wire/goal_state_no_certs.xml'

def vm_settings_no_change(url, *_, **__):
if HttpRequestPredicates.is_host_plugin_vm_settings_request(url):
return MockHttpResponse(httpclient.NOT_MODIFIED)
return None

def vm_settings_not_supported(url, *_, **__):
if HttpRequestPredicates.is_host_plugin_vm_settings_request(url):
return MockHttpResponse(404)
return None

with mock_wire_protocol(data) as protocol:

def mock_live_migration(iteration):
if iteration == 1:
protocol.mock_wire_data.set_incarnation(2)
protocol.set_http_handlers(http_get_handler=vm_settings_no_change)
elif iteration == 2:
protocol.mock_wire_data.set_incarnation(3)
protocol.set_http_handlers(http_get_handler=vm_settings_not_supported)

with mock_update_handler(protocol, 3, on_new_iteration=mock_live_migration) as update_handler:
with patch("azurelinuxagent.ga.update.logger.error") as patched_error:
def check_for_errors():
msg_fragment = "Error fetching the goal state:"

for (args, _) in filter(lambda a: len(a) > 0, patched_error.call_args_list):
if msg_fragment in args[0]:
self.fail("Found error: {}".format(args[0]))

update_handler.run(debug=True)
check_for_errors()

timestamp = protocol.client.get_host_plugin()._fast_track_timestamp
self.assertEqual(timestamp, timeutil.create_timestamp(datetime.min),
"Expected fast track time stamp to be set to {0}, got {1}".format(datetime.min, timestamp))

class HeartbeatTestCase(AgentTestCase):

Expand Down

0 comments on commit 801b109

Please sign in to comment.