Repository: Azure/WALinuxAgent
Pull request #1619 (2019-08-26 20:20:48)

Reduce agent provisioning time
<!-- DO NOT DELETE THIS TEMPLATE -->

## Description
This PR is addressing the issue where the daemon waits for >60sec to bring the ext-handler back up in the scenario where the ext-handler is not the latest agent version on the box

Issue # <!-- if any -->
<!--
Please add an informative description that covers that changes made by the pull request. 
This checklist is used to make sure that common issues in a pull request are addressed.
This will expedite the process of getting your pull request merged and avoid extra work on your part to fix issues discovered during the review process.
-->

---

### PR information
- [ ] The title of the PR is clear and informative.
- [ ] There are a small number of commits, each of which has an informative message. This means that previously merged commits do not appear in the history of the PR. For information on cleaning up the commits in your pull request, [see this page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).
- [ ] Except for special cases involving multiple contributors, the PR is started from a fork of the main repository, not a branch.
- [ ] If applicable, the PR references the bug/issue that it fixes in the description.
- [ ] New Unit tests were added for the changes made and Travis.CI is passing.

### Quality of Code and Contribution Guidelines
- [ ] I have read the [contribution guidelines](https://github.com/Azure/WALinuxAgent/blob/master/.github/CONTRIBUTING.md).

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/azure/walinuxagent/1619)
<!-- Reviewable:end -->


codecov[bot]: # [Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/1619?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`develop@46171e6`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference#section-missing-base-commit).
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/Azure/WALinuxAgent/pull/1619/graphs/tree.svg?width=650&token=ae90E2KYCw&height=150&src=pr)](https://codecov.io/gh/Azure/WALinuxAgent/pull/1619?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##             develop    #1619   +/-   ##
==========================================
  Coverage           ?   66.16%           
==========================================
  Files              ?       78           
  Lines              ?    11173           
  Branches           ?     1577           
==========================================
  Hits               ?     7393           
  Misses             ?     3445           
  Partials           ?      335
```


| [Impacted Files](https://codecov.io/gh/Azure/WALinuxAgent/pull/1619?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [azurelinuxagent/ga/update.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/1619/diff?src=pr&el=tree#diff-YXp1cmVsaW51eGFnZW50L2dhL3VwZGF0ZS5weQ==) | `88.29% <100%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/1619?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/1619?src=pr&el=footer). Last update [46171e6...75c718e](https://codecov.io/gh/Azure/WALinuxAgent/pull/1619?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/azurelinuxagent/ga/env.py b/azurelinuxagent/ga/env.py
index fe7a1763..629ae31d 100644
--- a/azurelinuxagent/ga/env.py
+++ b/azurelinuxagent/ga/env.py
@@ -80,7 +80,7 @@ class EnvHandler(object):
         logger.info("Start env monitor service.")
         self.dhcp_handler.conf_routes()
         self.hostname = self.osutil.get_hostname_record()
-        self.dhcp_id_list = get_dhcp_client_pid()
+        self.dhcp_id_list = self.get_dhcp_client_pid()
         self.start()
 
     def is_alive(self):
diff --git a/azurelinuxagent/ga/update.py b/azurelinuxagent/ga/update.py
index 7f4e19d2..14f2ec34 100644
--- a/azurelinuxagent/ga/update.py
+++ b/azurelinuxagent/ga/update.py
@@ -166,14 +166,10 @@ 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
+            # Setting the poll interval to poll every second to reduce the agent provisioning time;
+            # The daemon shouldn't wait for 60secs before starting the ext-handler in case the
+            # ext-handler kills itself during agent-update during the first 15 mins (CHILD_HEALTH_INTERVAL)
+            poll_interval = 1
 
             ret = None
             start_time = time.time()


Test patch:
diff --git a/tests/ga/test_update.py b/tests/ga/test_update.py
index 24430055..a2da3659 100644
--- a/tests/ga/test_update.py
+++ b/tests/ga/test_update.py
@@ -1104,13 +1104,12 @@ class TestUpdate(UpdateTestCase):
         self._test_run_latest(mock_time=mock_time)
         self.assertEqual(1, mock_time.sleep_interval)
 
-    def test_run_latest_polls_moderately_if_installed_not_latest(self):
+    def test_run_latest_polls_every_second_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)
+        self.assertEqual(1, mock_time.sleep_interval)
 
     def test_run_latest_defaults_to_current(self):
         self.assertEqual(None, self.update_handler.get_latest_agent())