Edge monitoring agent to report current iperf stats in every report

Change-Id: Icf1e58c2766b2600eef2d9c7aa2cc355749ebe0c
diff --git a/VERSION b/VERSION
index bf7b715..b22af29 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.7.16
+0.7.17
diff --git a/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py b/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py
index 7e21416..d377d69 100755
--- a/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py
+++ b/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py
@@ -26,13 +26,9 @@
 
 USE_MODEM_CMDS = False
 
-# Parse config with backwards compatibility with config.json pre 0.6.6
 config_file_contents = open(os.getenv('CONFIG_FILE', "./config.json")).read()
-config_file_contents = config_file_contents.replace("user_plane_ping_test", "dns")
-config_file_contents = config_file_contents.replace("speedtest_iperf", "iperf_server")
-config_file_contents = config_file_contents.replace("\"speedtest_ping_dns\": \"8.8.8.8\",", "")
 # replace 1.1.1.1 with 8.8.8.8
-config_file_contents = config_file_contents.replace('1.1.1.1', '8.8.8.8')
+# config_file_contents = config_file_contents.replace('1.1.1.1', '8.8.8.8')
 CONF = json.loads(
     config_file_contents, object_hook=lambda d: namedtuple('X', d.keys())(*d.values())
 )
@@ -307,26 +303,21 @@
     return result
 
 
-def iperf_test(counters):
-    '''
-    Prepares the iperf test.
-    '''
+def update_iperf_stats(iperf_stats, counters):
+    global cycles
     global hour_iperf_scheduled_time_last_ran
-    speedtest_iperf = {}
-    speedtest_iperf['cluster'] = {}
 
-    if "iperf_schedule" in CONF._fields and len(CONF.iperf_schedule) > 0:
-        if int(time.strftime("%H")) not in CONF.iperf_schedule: # not in the schedule
-            hour_iperf_scheduled_time_last_ran = -1
-            return None
-        elif int(time.strftime("%H")) == hour_iperf_scheduled_time_last_ran: # already ran this hour
-            return None
+    if cycles != 0:
+        if "iperf_schedule" in CONF._fields and len(CONF.iperf_schedule) > 0:
+            if int(time.strftime("%H")) not in CONF.iperf_schedule: # not in the schedule
+                hour_iperf_scheduled_time_last_ran = -1
+                return
+            elif int(time.strftime("%H")) == hour_iperf_scheduled_time_last_ran: # already ran this hour
+                return
     hour_iperf_scheduled_time_last_ran = int(time.strftime("%H"))
 
-    speedtest_iperf['cluster']['downlink'] = run_iperf_test(CONF.ips.iperf_server, CONF.iperf_port, 10, True, counters)
-    speedtest_iperf['cluster']['uplink'] = run_iperf_test(CONF.ips.iperf_server, CONF.iperf_port, 10, False, counters)
-
-    return speedtest_iperf
+    iperf_stats['cluster']['downlink'] = run_iperf_test(CONF.ips.iperf_server, CONF.iperf_port, 10, True, counters)
+    iperf_stats['cluster']['uplink'] = run_iperf_test(CONF.ips.iperf_server, CONF.iperf_port, 10, False, counters)
 
 
 def get_signal_quality(modem, counters, dongle_stats=None):
@@ -408,7 +399,7 @@
     return result
 
 
-def report_status(counters, signal_quality, dongle_stats, cp_state=None, up_state=None, speedtest_ping=None, speedtest_iperf=None):
+def report_status(counters, signal_quality, dongle_stats, cp_state=None, up_state=None, speedtest_ping=None, iperf_stats=None):
     report = {
         'name': CONF.edge_name,
         'status': {
@@ -429,12 +420,6 @@
                     'max': 0.0,
                     'stddev': 0.0
                 }
-            },
-            'iperf': {
-                'cluster': {
-                    'downlink': 0.0,
-                    'uplink': 0.0
-                }
             }
         },
         'signal_quality': {
@@ -449,8 +434,8 @@
         report['status']['user_plane'] = up_state.name
     if speedtest_ping is not None:
         report['speedtest']['ping'] = speedtest_ping
-    if speedtest_iperf is not None:
-        report['speedtest']['iperf'] = speedtest_iperf
+    if iperf_stats is not None:
+        report['speedtest']['iperf'] = iperf_stats
     report['signal_quality'] = signal_quality
     report['dongle_stats'] = dongle_stats
     report['counters'] = counters
@@ -527,6 +512,9 @@
     time.sleep(delay)
     subprocess.check_output("sudo shutdown -r now", shell=True)
 
+def init_iperf_stats():
+    return {'cluster': {'downlink': 0.0, 'uplink': 0.0}}
+
 def init_counters():
     return {
         'dongle_read_error': 0,
@@ -553,6 +541,7 @@
     hour_iperf_scheduled_time_last_ran = -1
 
     counters = init_counters()
+    iperf_stats = init_iperf_stats()
 
     try:
         if "report_in_band" in CONF._fields and \
@@ -625,9 +614,9 @@
         else:
             up_state = State.disconnected
 
-        speedtest_iperf = iperf_test(counters)
+        update_iperf_stats(iperf_stats, counters)
 
-        report_status(counters, signal_quality, dongle_stats, cp_state, up_state, ping_latency, speedtest_iperf)
+        report_status(counters, signal_quality, dongle_stats, cp_state, up_state, ping_latency, iperf_stats)
         # counters = clear_counters(counters)
         time.sleep(CONF.report_interval)