Repository: Azure/WALinuxAgent
Pull request #669 (2017-04-14 18:38:25)

Fix for #667
Change the poll interval used to monitor newly spawned goal state extensions. This change addresses
#667.

Signed-off-by: Brendan Dixon <brendandixon@me.com>


Patch:
diff --git a/azurelinuxagent/ga/update.py b/azurelinuxagent/ga/update.py
index fc19d486..203bb417 100644
--- a/azurelinuxagent/ga/update.py
+++ b/azurelinuxagent/ga/update.py
@@ -146,10 +146,19 @@ class UpdateHandler(object):
 
             logger.verbose(u"Agent {0} launched with command '{1}'", agent_name, agent_cmd)
 
+            # If the most current agent is the installed agent and update is enabled,
+            # assume updates are likely available and poll every second.
+            # This reduces the start-up impact of finding / launching agent updates on
+            # fresh VMs.
+            if latest_agent is None and conf.get_autoupdate_enabled():
+                poll_interval = 1
+            else:
+                poll_interval = CHILD_POLL_INTERVAL
+
             ret = None
             start_time = time.time()
             while (time.time() - start_time) < CHILD_HEALTH_INTERVAL:
-                time.sleep(CHILD_POLL_INTERVAL)
+                time.sleep(poll_interval)
                 ret = self.child_process.poll()
                 if ret is not None:
                     break


Test patch:
diff --git a/tests/ga/test_update.py b/tests/ga/test_update.py
index 46d06735..e7a7af4e 100644
--- a/tests/ga/test_update.py
+++ b/tests/ga/test_update.py
@@ -1040,7 +1040,7 @@ class TestUpdate(UpdateTestCase):
 
         with patch('subprocess.Popen', return_value=mock_child) as mock_popen:
             with patch('time.time', side_effect=mock_time.time):
-                with patch('time.sleep', return_value=mock_time.sleep):
+                with patch('time.sleep', side_effect=mock_time.sleep):
                     self.update_handler.run_latest()
                     self.assertEqual(1, mock_popen.call_count)
 
@@ -1085,6 +1085,22 @@ class TestUpdate(UpdateTestCase):
         self.assertEqual(0, mock_child.wait.call_count)
         return
 
+    def test_run_latest_polls_frequently_if_installed_is_latest(self):
+        mock_child = ChildMock(return_value=0)
+        mock_time = TimeMock(time_increment=CHILD_HEALTH_INTERVAL/2)
+        self._test_run_latest(mock_time=mock_time)
+        self.assertEqual(1, mock_time.sleep_interval)
+        return
+
+    def test_run_latest_polls_moderately_if_installed_not_latest(self):
+        self.prepare_agents()
+
+        mock_child = ChildMock(return_value=0)
+        mock_time = TimeMock(time_increment=CHILD_HEALTH_INTERVAL/2)
+        self._test_run_latest(mock_time=mock_time)
+        self.assertNotEqual(1, mock_time.sleep_interval)
+        return
+
     def test_run_latest_defaults_to_current(self):
         self.assertEqual(None, self.update_handler.get_latest_agent())
 
@@ -1137,7 +1153,6 @@ class TestUpdate(UpdateTestCase):
         return
 
     def test_run_latest_exception_blacklists(self):
-        # logger.add_logger_appender(logger.AppenderType.STDOUT)
         self.prepare_agents()
 
         latest_agent = self.update_handler.get_latest_agent()
@@ -1389,7 +1404,11 @@ class TimeMock(Mock):
         self.time_call_count = 0
         self.time_increment = time_increment
 
-        self.sleep = Mock(return_value=0)
+        self.sleep_interval = None
+        return
+
+    def sleep(self, n):
+        self.sleep_interval = n
         return
 
     def time(self):