Repository: Azure/WALinuxAgent

Issue:
[2.1-selfupdate] launched .egg exits
The launched update (.egg package) discovers an update and exits with exitcode=0. This keeps going on forever 

When I run it manually:
```
$ python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers
2016/07/08 21:53:58.005925 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:53:58.008335 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:53:58.010850 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:53:58.092766 INFO Check for agent updates
2016/07/08 21:53:58.241843 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:53:58.243852 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:53:58.244492 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:53:58.244589 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
```

waagent.log

```
2016/07/08 21:51:34.771176 INFO Azure Linux Agent Version:2.1.5.rc4
2016/07/08 21:51:34.778980 INFO OS: ubuntu 16.04
2016/07/08 21:51:34.781242 INFO Python: 3.5.1
2016/07/08 21:51:34.784024 INFO Run daemon
2016/07/08 21:51:34.790937 INFO No RDMA handler exists for distro='Ubuntu' version='16.04'
2016/07/08 21:51:34.793643 INFO Clean protocol
2016/07/08 21:51:34.795094 INFO run Ubuntu provision handler
2016/07/08 21:51:34.836768 INFO Detect protocol endpoints
2016/07/08 21:51:34.848651 INFO Clean protocol
2016/07/08 21:51:34.859205 INFO WireServer endpoint is not found. Rerun dhcp handler
2016/07/08 21:51:34.872036 INFO test for route to 168.63.129.16
2016/07/08 21:51:34.882312 INFO route to 168.63.129.16 exists
2016/07/08 21:51:34.891349 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:34.916104 INFO Fabric preferred wire protocol version:2015-04-05
2016/07/08 21:51:34.928396 INFO Wire protocol version:2012-11-30
2016/07/08 21:51:34.937556 WARNING Server prefered version:2015-04-05
2016/07/08 21:51:39.307372 INFO Start env monitor service.
2016/07/08 21:51:39.307245 INFO Event: name=WALA, op=HeartBeat, message=
2016/07/08 21:51:39.321421 INFO Configure routes
2016/07/08 21:51:39.334137 INFO Gateway:None
2016/07/08 21:51:39.361754 INFO Routes:None
2016/07/08 21:51:39.381291 INFO RDMA capabilities are not enabled, skipping
2016/07/08 21:51:39.409449 INFO Agent WALinuxAgent-2.1.5.rc4 launched with command 'python -u /usr/sbin/waagent -run-exthandlers'
2016/07/08 21:51:39.412830 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.rc4 launched with command 'python -u /usr/sbin/waagent -run-exthandlers'
2016/07/08 21:51:39.804282 INFO Agent WALinuxAgent-2.1.5.rc4 is running as the current agent
2016/07/08 21:51:39.822824 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.rc4 is running as the current agent
2016/07/08 21:51:39.857494 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:39.885288 INFO Check for agent updates
2016/07/08 21:51:39.965964 INFO Initiating download of Agent WALinuxAgent-2.1.5.1
2016/07/08 21:51:39.981689 INFO Event: name=WALinuxAgent, op=, message=Initiating download of Agent WALinuxAgent-2.1.5.1
2016/07/08 21:51:40.041793 INFO Unpacking agent package WALinuxAgent-2.1.5.1
2016/07/08 21:51:40.064324 INFO Agent WALinuxAgent-2.1.5.1 successfully unpacked
2016/07/08 21:51:40.077642 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.1 successfully unpacked
2016/07/08 21:51:40.108340 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:40.139217 INFO Agent WALinuxAgent-2.1.5.1 downloaded successfully
2016/07/08 21:51:40.155397 INFO Event: name=WALinuxAgent, op=Install, message=Agent WALinuxAgent-2.1.5.1 downloaded successfully
2016/07/08 21:51:40.178144 INFO Initiating download of Agent WALinuxAgent-2.1.5.3
2016/07/08 21:51:40.195989 INFO Event: name=WALinuxAgent, op=, message=Initiating download of Agent WALinuxAgent-2.1.5.3
2016/07/08 21:51:40.277986 INFO Unpacking agent package WALinuxAgent-2.1.5.3
2016/07/08 21:51:40.294587 INFO Agent WALinuxAgent-2.1.5.3 successfully unpacked
2016/07/08 21:51:40.307226 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 successfully unpacked
2016/07/08 21:51:40.329189 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:40.343945 INFO Agent WALinuxAgent-2.1.5.3 downloaded successfully
2016/07/08 21:51:40.354808 INFO Event: name=WALinuxAgent, op=Install, message=Agent WALinuxAgent-2.1.5.3 downloaded successfully
2016/07/08 21:51:40.377161 INFO Agent WALinuxAgent-2.1.5.rc4 discovered agent update and will exit
2016/07/08 21:51:40.392069 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.rc4 discovered agent update and will exit
2016/07/08 21:51:40.443552 INFO Agent WALinuxAgent-2.1.5.rc4 launched with command 'python -u /usr/sbin/waagent -run-exthandlers' returned 0
2016/07/08 21:51:40.455908 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.rc4 launched with command 'python -u /usr/sbin/waagent -run-exthandlers' returned 0
2016/07/08 21:51:40.458716 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:40.459940 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:40.518290 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:40.520979 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:41.085353 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:41.093568 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:41.095873 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:41.144559 INFO Check for agent updates
2016/07/08 21:51:41.219800 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:41.222907 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:41.235737 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:41.246668 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:41.292794 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:41.300068 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:41.341243 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:41.362334 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:41.858292 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:41.880601 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:41.909701 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:41.936837 INFO Check for agent updates
2016/07/08 21:51:41.979260 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:41.999360 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:42.027065 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:42.050964 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:42.112336 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:42.135428 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:42.167577 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:42.176380 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:42.765364 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:42.797351 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:42.816600 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:42.850009 INFO Check for agent updates
2016/07/08 21:51:42.901169 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:42.926215 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:42.961311 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:42.991006 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:43.056817 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:43.069516 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:43.142434 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:43.165251 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:43.799678 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:43.802183 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:43.810915 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:43.837580 INFO Check for agent updates
2016/07/08 21:51:43.886126 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:43.888686 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:43.890895 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:43.891648 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:43.951575 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:43.982332 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:44.013181 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:44.038561 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:44.530643 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:44.542035 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:44.544212 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:44.572049 INFO Check for agent updates
2016/07/08 21:51:44.601699 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:44.604319 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:44.614998 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:44.615744 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:44.663500 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:44.683130 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:44.717203 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:44.717801 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:45.327595 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:45.355741 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:45.378140 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:45.425207 INFO Check for agent updates
2016/07/08 21:51:45.511625 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:45.532343 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:45.551889 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:45.572167 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:45.634632 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:45.637357 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:45.730332 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:45.767070 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:46.357507 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:46.365985 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:46.368831 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:46.388904 INFO Check for agent updates
2016/07/08 21:51:46.455008 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:46.457944 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:46.469406 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:46.472261 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:46.533666 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:46.574132 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:46.621227 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:46.622106 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:47.197051 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:47.211052 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:47.228764 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:47.254180 INFO Check for agent updates
2016/07/08 21:51:47.287889 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:47.307351 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:47.323870 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:47.336948 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:47.387282 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:47.389821 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:47.433157 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:47.435597 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:47.918501 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:47.927511 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:47.930193 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:47.955407 INFO Check for agent updates
2016/07/08 21:51:47.997328 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:48.000749 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:48.004041 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:48.011916 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:48.060976 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:48.063291 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:48.117204 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:48.139992 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:48.603085 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:48.605763 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:48.615658 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:48.644782 INFO Check for agent updates
2016/07/08 21:51:48.684577 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:48.687354 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:48.689722 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:48.690430 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:48.743235 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:48.764309 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:48.793241 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:48.825085 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:49.362306 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:49.374656 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:49.395527 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:49.417136 INFO Check for agent updates
2016/07/08 21:51:49.466363 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:49.484546 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:49.502543 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:49.514883 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:49.562007 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:49.565266 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:49.609194 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:49.628816 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:50.168861 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:50.171438 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:50.180856 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:50.213828 INFO Check for agent updates
2016/07/08 21:51:50.248302 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:50.252061 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:50.262508 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:50.263335 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:50.318705 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:50.342626 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:50.377173 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:50.401987 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:50.975030 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:50.987630 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:51.018780 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:51.051524 INFO Check for agent updates
2016/07/08 21:51:51.084308 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:51.108080 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:51.129931 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:51.146710 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:51.208489 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:51.209322 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:51.256133 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:51.258511 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:51.824414 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:51.836174 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:51.853035 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:51.875222 INFO Check for agent updates
2016/07/08 21:51:51.908704 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:51.923015 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:51.938682 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:51.950739 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:51.998146 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:52.000581 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:52.038076 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:52.040270 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:52.586988 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:52.594895 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:52.607576 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:52.628226 INFO Check for agent updates
2016/07/08 21:51:52.665475 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:52.668298 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:52.670476 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:52.680786 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:52.735177 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:52.742582 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:52.805232 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:52.828536 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:53.334569 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:53.342464 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:53.345938 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:53.368600 INFO Check for agent updates
2016/07/08 21:51:53.404426 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:53.407243 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:53.409710 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:53.411951 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:53.466092 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:53.484793 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:53.513155 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:53.549833 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:54.086244 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:54.100320 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:54.118185 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:54.141337 INFO Check for agent updates
2016/07/08 21:51:54.179400 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:54.195961 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:54.212276 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:54.225937 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:54.274542 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:54.277141 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:54.321209 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:54.339802 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:54.820216 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:54.872161 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 is running as the current agent
2016/07/08 21:51:54.876294 INFO Wire server endpoint:168.63.129.16
2016/07/08 21:51:54.912602 INFO Check for agent updates
2016/07/08 21:51:54.947001 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.1/HandlerManifest.json
2016/07/08 21:51:54.955836 INFO Loading Agent manifest from /var/lib/waagent/WALinuxAgent-2.1.5.3/HandlerManifest.json
2016/07/08 21:51:54.970085 INFO Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:54.972439 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 discovered agent update and will exit
2016/07/08 21:51:55.028333 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:55.048616 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers' returned 0
2016/07/08 21:51:55.077202 INFO Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:55.079855 INFO Event: name=WALinuxAgent, op=, message=Agent WALinuxAgent-2.1.5.3 launched with command 'python -u bin/WALinuxAgent-2.1.5.rc3-py2.7.egg -run-exthandlers'
2016/07/08 21:51:55.686370 INFO Agent WALinuxAgent-2.1.5.3 is running as the current agen
```

Discussion:

Patch:
diff --git a/azurelinuxagent/ga/update.py b/azurelinuxagent/ga/update.py
index 635f7e98..1c7d13a9 100644
--- a/azurelinuxagent/ga/update.py
+++ b/azurelinuxagent/ga/update.py
@@ -115,6 +115,7 @@ class UpdateHandler(object):
             cmds = shlex.split(agent_cmd)
             if cmds[0].lower() == "python":
                 cmds[0] = get_python_cmd()
+                agent_cmd = " ".join(cmds)
 
             self.child_process = subprocess.Popen(
                 cmds,
@@ -264,7 +265,7 @@ class UpdateHandler(object):
         available_agents = [agent for agent in self.agents if agent.is_available]
         return available_agents[0] if len(available_agents) >= 1 else None
 
-    def _ensure_latest_agent(self):
+    def _ensure_latest_agent(self, base_version=CURRENT_VERSION):
         # Ignore new agents if updating is disabled
         if not conf.get_autoupdate_enabled():
             return False
@@ -326,15 +327,14 @@ class UpdateHandler(object):
         # Note:
         #  The code leaves on disk available, but blacklisted, agents so as to preserve the state.
         #  Otherwise, those agents could be again downloaded and inappropriately retried.
-        current_version = FlexibleVersion(AGENT_VERSION)
         self._set_agents([GuestAgent(pkg=pkg) for pkg in
                             [pkg for pkg in pkg_list.versions
-                                if FlexibleVersion(pkg.version) > current_version]])
+                                if FlexibleVersion(pkg.version) > base_version]])
         self._purge_agents()
         self._filter_blacklisted_agents()
 
         # Return True if agents more recent than the current are available
-        return len(self.agents) > 0 and self.agents[0].version > current_version
+        return len(self.agents) > 0 and self.agents[0].version > base_version
 
     def _filter_blacklisted_agents(self):
         self.agents = [agent for agent in self.agents if not agent.is_blacklisted]


Test patch:
diff --git a/tests/ga/test_update.py b/tests/ga/test_update.py
index 3c81437c..cfa537e7 100644
--- a/tests/ga/test_update.py
+++ b/tests/ga/test_update.py
@@ -577,6 +577,7 @@ class TestUpdate(UpdateTestCase):
 
     def _test_ensure_latest_agent(
             self,
+            base_version=FlexibleVersion(AGENT_VERSION),
             protocol=None,
             versions=None):
         
@@ -591,7 +592,7 @@ class TestUpdate(UpdateTestCase):
         self.update_handler.protocol_util = protocol
         conf.get_autoupdate_gafamily = Mock(return_value=protocol.family)
 
-        return self.update_handler._ensure_latest_agent()
+        return self.update_handler._ensure_latest_agent(base_version=base_version)
 
     def test_ensure_latest_agent_returns_true_on_first_use(self):
         self.assertEqual(None, self.update_handler.last_etag)
@@ -633,7 +634,13 @@ class TestUpdate(UpdateTestCase):
         self.assertFalse(self._test_ensure_latest_agent())
         return
 
-    def test_ensure_latest_agent_skips_when_no_new_versions(self):
+    def test_ensure_latest_agent_skips_if_when_no_new_versions(self):
+        self.prepare_agents()
+        base_version = self.agent_versions()[0] + 1
+        self.assertFalse(self._test_ensure_latest_agent(base_version=base_version))
+        return
+
+    def test_ensure_latest_agent_skips_when_no_versions(self):
         self.assertFalse(self._test_ensure_latest_agent(protocol=ProtocolMock()))
         return