summaryrefslogtreecommitdiff
path: root/tests/ga/test_extension.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ga/test_extension.py')
-rw-r--r--tests/ga/test_extension.py138
1 files changed, 120 insertions, 18 deletions
diff --git a/tests/ga/test_extension.py b/tests/ga/test_extension.py
index 2a60ea3..9a72989 100644
--- a/tests/ga/test_extension.py
+++ b/tests/ga/test_extension.py
@@ -46,8 +46,8 @@ class TestExtensionCleanup(AgentTestCase):
def _install_handlers(self, start=0, count=1,
handler_state=ExtHandlerState.Installed):
- src = os.path.join(data_dir, "ext", "sample_ext-1.2.0.zip")
- version = FlexibleVersion("1.2.0")
+ src = os.path.join(data_dir, "ext", "sample_ext-1.3.0.zip")
+ version = FlexibleVersion("1.3.0")
version += start - version.patch
for i in range(start, start+count):
@@ -318,34 +318,44 @@ class TestExtension(AgentTestCase):
self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.0.0")
self._assert_ext_status(protocol.report_ext_status, "success", 1)
- #Test upgrade
+ #Test hotfix
test_data.goal_state = test_data.goal_state.replace("<Incarnation>2<",
"<Incarnation>3<")
test_data.ext_conf = test_data.ext_conf.replace("1.0.0", "1.1.0")
test_data.ext_conf = test_data.ext_conf.replace("seqNo=\"1\"",
"seqNo=\"2\"")
exthandlers_handler.run()
- self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.1.0")
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.1.1")
self._assert_ext_status(protocol.report_ext_status, "success", 2)
- #Test disable
+ #Test upgrade
test_data.goal_state = test_data.goal_state.replace("<Incarnation>3<",
"<Incarnation>4<")
+ test_data.ext_conf = test_data.ext_conf.replace("1.1.0", "1.2.0")
+ test_data.ext_conf = test_data.ext_conf.replace("seqNo=\"2\"",
+ "seqNo=\"3\"")
+ exthandlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.2.0")
+ self._assert_ext_status(protocol.report_ext_status, "success", 3)
+
+ #Test disable
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>4<",
+ "<Incarnation>5<")
test_data.ext_conf = test_data.ext_conf.replace("enabled", "disabled")
exthandlers_handler.run()
self._assert_handler_status(protocol.report_vm_status, "NotReady",
- 1, "1.1.0")
+ 1, "1.2.0")
#Test uninstall
- test_data.goal_state = test_data.goal_state.replace("<Incarnation>4<",
- "<Incarnation>5<")
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>5<",
+ "<Incarnation>6<")
test_data.ext_conf = test_data.ext_conf.replace("disabled", "uninstall")
exthandlers_handler.run()
self._assert_no_handler_status(protocol.report_vm_status)
#Test uninstall again!
- test_data.goal_state = test_data.goal_state.replace("<Incarnation>5<",
- "<Incarnation>6<")
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>6<",
+ "<Incarnation>7<")
exthandlers_handler.run()
self._assert_no_handler_status(protocol.report_vm_status)
@@ -371,6 +381,95 @@ class TestExtension(AgentTestCase):
exthandlers_handler.run()
self._assert_no_handler_status(protocol.report_vm_status)
+ def test_ext_handler_rollingupgrade(self, *args):
+ test_data = WireProtocolData(DATA_FILE_EXT_ROLLINGUPGRADE)
+ exthandlers_handler, protocol = self._create_mock(test_data, *args)
+
+ #Test enable scenario.
+ exthandlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.0.0")
+ self._assert_ext_status(protocol.report_ext_status, "success", 0)
+
+ #Test goal state not changed
+ exthandlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.0.0")
+
+ #Test goal state changed without new GUID
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>1<",
+ "<Incarnation>2<")
+ exthandlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.0.0")
+ self._assert_ext_status(protocol.report_ext_status, "success", 0)
+
+ #Test GUID change without new version available
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>2<",
+ "<Incarnation>3<")
+ test_data.ext_conf = test_data.ext_conf.replace("FE0987654321", "FE0987654322")
+ exthandlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.0.0")
+ self._assert_ext_status(protocol.report_ext_status, "success", 0)
+
+ #Test hotfix available without GUID change
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>3<",
+ "<Incarnation>4<")
+ test_data.ext_conf = test_data.ext_conf.replace("1.0.0", "1.1.0")
+ exthandlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.0.0")
+ self._assert_ext_status(protocol.report_ext_status, "success", 0)
+
+ #Test GUID change with hotfix
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>4<",
+ "<Incarnation>5<")
+ test_data.ext_conf = test_data.ext_conf.replace("FE0987654322", "FE0987654323")
+ exthandlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.1.1")
+ self._assert_ext_status(protocol.report_ext_status, "success", 0)
+
+ #Test disable
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>5<",
+ "<Incarnation>6<")
+ test_data.ext_conf = test_data.ext_conf.replace("enabled", "disabled")
+ exthandlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "NotReady",
+ 1, "1.1.1")
+
+ #Test uninstall
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>6<",
+ "<Incarnation>7<")
+ test_data.ext_conf = test_data.ext_conf.replace("disabled", "uninstall")
+ exthandlers_handler.run()
+ self._assert_no_handler_status(protocol.report_vm_status)
+
+ #Test uninstall again!
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>7<",
+ "<Incarnation>8<")
+ exthandlers_handler.run()
+ self._assert_no_handler_status(protocol.report_vm_status)
+
+ #Test re-install
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>8<",
+ "<Incarnation>9<")
+ test_data.ext_conf = test_data.ext_conf.replace("uninstall", "enabled")
+ exthandlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.1.1")
+ self._assert_ext_status(protocol.report_ext_status, "success", 0)
+
+ #Test upgrade available without GUID change
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>9<",
+ "<Incarnation>10<")
+ test_data.ext_conf = test_data.ext_conf.replace("1.1.0", "1.2.0")
+ exthandlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.1.1")
+ self._assert_ext_status(protocol.report_ext_status, "success", 0)
+
+ #Test GUID change with upgrade available
+ test_data.goal_state = test_data.goal_state.replace("<Incarnation>10<",
+ "<Incarnation>11<")
+ test_data.ext_conf = test_data.ext_conf.replace("FE0987654323", "FE0987654324")
+ exthandlers_handler.run()
+ self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.2.0")
+ self._assert_ext_status(protocol.report_ext_status, "success", 0)
+
@patch('azurelinuxagent.ga.exthandlers.add_event')
def test_ext_handler_download_failure(self, mock_add_event, *args):
test_data = WireProtocolData(DATA_FILE)
@@ -464,8 +563,8 @@ class TestExtension(AgentTestCase):
for internal in [False, True]:
for autoupgrade in [False, True]:
if internal:
- config_version = '1.2.0'
- decision_version = '1.2.0'
+ config_version = '1.3.0'
+ decision_version = '1.3.0'
if autoupgrade:
datafile = DATA_FILE_EXT_AUTOUPGRADE_INTERNALVERSION
else:
@@ -474,18 +573,18 @@ class TestExtension(AgentTestCase):
config_version = '1.0.0'
if autoupgrade:
datafile = DATA_FILE_EXT_AUTOUPGRADE
- decision_version = '1.1.0'
+ decision_version = '1.2.0'
else:
datafile = DATA_FILE
decision_version = '1.0.0'
_, protocol = self._create_mock(WireProtocolData(datafile), *args)
- ext_handlers, _ = protocol.get_ext_handlers()
+ ext_handlers, etag = protocol.get_ext_handlers()
self.assertEqual(1, len(ext_handlers.extHandlers))
ext_handler = ext_handlers.extHandlers[0]
self.assertEqual('OSTCExtensions.ExampleHandlerLinux', ext_handler.name)
self.assertEqual(config_version, ext_handler.properties.version, "config version.")
- ExtHandlerInstance(ext_handler, protocol).decide_version()
+ ExtHandlerInstance(ext_handler, protocol).decide_version(etag)
self.assertEqual(decision_version, ext_handler.properties.version, "decision version.")
def test_ext_handler_version_decide_between_minor_versions(self, *args):
@@ -500,7 +599,7 @@ class TestExtension(AgentTestCase):
cases = [
(None, '2.0', '2.0.0', '2.2.0'),
(None, '2.0.0', '2.0.0', '2.2.0'),
- ('1.0', '1.0.0', '1.0.0', '1.1.0'),
+ ('1.0', '1.0.0', '1.0.0', '1.2.0'),
(None, '2.1.0', '2.1.1', '2.2.0'),
(None, '2.2.0', '2.2.0', '2.2.0'),
(None, '2.3.0', '2.3.0', '2.3.0'),
@@ -512,6 +611,7 @@ class TestExtension(AgentTestCase):
_, protocol = self._create_mock(WireProtocolData(DATA_FILE), *args)
version_uri = Mock()
version_uri.uri = 'http://some/Microsoft.OSTCExtensions_ExampleHandlerLinux_asiaeast_manifest.xml'
+ incarnation = 1
for (installed_version, config_version, expected_version, autoupgrade_expected_version) in cases:
ext_handler = Mock()
@@ -523,8 +623,9 @@ class TestExtension(AgentTestCase):
ext_handler_instance = ExtHandlerInstance(ext_handler, protocol)
ext_handler_instance.get_installed_version = Mock(return_value=installed_version)
- ext_handler_instance.decide_version()
+ ext_handler_instance.decide_version(incarnation)
self.assertEqual(expected_version, ext_handler.properties.version)
+ incarnation += 1
ext_handler.properties.version = config_version
ext_handler.properties.upgradePolicy = 'auto'
@@ -532,8 +633,9 @@ class TestExtension(AgentTestCase):
ext_handler_instance = ExtHandlerInstance(ext_handler, protocol)
ext_handler_instance.get_installed_version = Mock(return_value=installed_version)
- ext_handler_instance.decide_version()
+ ext_handler_instance.decide_version(incarnation)
self.assertEqual(autoupgrade_expected_version, ext_handler.properties.version)
+ incarnation += 1
if __name__ == '__main__':