Repository: Azure/WALinuxAgent
Pull request #1126 (2018-04-19 23:36:39)

add seconds unit to the value


Patch:
diff --git a/azurelinuxagent/pa/provision/cloudinit.py b/azurelinuxagent/pa/provision/cloudinit.py
index de07ea93..2b10c440 100644
--- a/azurelinuxagent/pa/provision/cloudinit.py
+++ b/azurelinuxagent/pa/provision/cloudinit.py
@@ -64,7 +64,7 @@ class CloudInitProvisionHandler(ProvisionHandler):
             logger.info("Finished provisioning")
 
             self.report_ready(thumbprint)
-            self.report_event("Provisioning with cloud-init succeeded ({0})".format(self._get_uptime_seconds()),
+            self.report_event("Provisioning with cloud-init succeeded ({0}s)".format(self._get_uptime_seconds()),
                 is_success=True,
                 duration=elapsed_milliseconds(utc_start))
 
diff --git a/azurelinuxagent/pa/provision/default.py b/azurelinuxagent/pa/provision/default.py
index 5df572cb..ea587169 100644
--- a/azurelinuxagent/pa/provision/default.py
+++ b/azurelinuxagent/pa/provision/default.py
@@ -88,7 +88,7 @@ class ProvisionHandler(object):
 
             self.write_provisioned()
 
-            self.report_event("Provisioning succeeded ({0})".format(self._get_uptime_seconds()),
+            self.report_event("Provisioning succeeded ({0}s)".format(self._get_uptime_seconds()),
                 is_success=True,
                 duration=elapsed_milliseconds(utc_start))
 


Test patch:
diff --git a/tests/pa/test_provision.py b/tests/pa/test_provision.py
index 4ee8d469..cc848b32 100644
--- a/tests/pa/test_provision.py
+++ b/tests/pa/test_provision.py
@@ -147,8 +147,8 @@ class TestProvision(AgentTestCase):
 
         self.assertEqual(1, ph.report_event.call_count)
         positional_args, kw_args = ph.report_event.call_args
-        # [call('Provisioning succeeded (146473.68)', duration=65, is_success=True)]
-        self.assertTrue(re.match(r'Provisioning succeeded \(\d+\.\d+\)', positional_args[0]) is not None)
+        # [call('Provisioning succeeded (146473.68s)', duration=65, is_success=True)]
+        self.assertTrue(re.match(r'Provisioning succeeded \(\d+\.\d+s\)', positional_args[0]) is not None)
         self.assertTrue(isinstance(kw_args['duration'], int))
         self.assertTrue(kw_args['is_success'])
 
diff --git a/tests/utils/test_archive.py b/tests/utils/test_archive.py
index 1016c9aa..f0564c88 100644
--- a/tests/utils/test_archive.py
+++ b/tests/utils/test_archive.py
@@ -164,18 +164,9 @@ class TestArchive(AgentTestCase):
             'Microsoft.Azure.Extensions.CustomScript.0.xml'
         ]
 
-        def _write_goal_state_files(temp_files, content=None):
+        def _write_goal_state_files(temp_files):
             for f in temp_files:
-                self._write_file(f, content)
-
-        def _check_history_files(timestamp_dir, files, content=None):
-            for f in files:
-                history_path = os.path.join(self.history_dir, timestamp_dir, f)
-                msg = "expected the temp file {0} to exist".format(history_path)
-                self.assertTrue(os.path.exists(history_path), msg)
-                expected_content = f if content is None else content
-                actual_content = fileutil.read_file(history_path)
-                self.assertEqual(expected_content, actual_content)
+                self._write_file(f)
 
         timestamp = datetime.utcnow()
 
@@ -183,7 +174,24 @@ class TestArchive(AgentTestCase):
         test_subject = StateFlusher(self.tmp_dir)
         test_subject.flush(timestamp)
 
-        # Ensure history directory exists, has proper timestamped-based name,
+        # Ensure that the file contets are what we expect after a flush.
+        # The file contents are simply the name of the file.
+        fn = os.path.join(self.history_dir, timestamp.isoformat(), 'Prod.0.manifest.xml')
+        self.assertEqual('Prod.0.manifest.xml', fileutil.read_file(fn))
+
+        # Modify the contents of the file on disk, and re-flush().
+        fileutil.write_file(fn, "--this-has-been-changed--")
+        self.assertEqual("--this-has-been-changed--", fileutil.read_file(fn))
+
+        # re-write all of the same files, and flush again. .flush()
+        # should overwrite the existing ones
+
+        _write_goal_state_files(temp_files)
+        test_subject.flush(timestamp)
+
+        # The contents of the file were overwritten as a result of the flush.
+        self.assertEqual('Prod.0.manifest.xml', fileutil.read_file(fn))
+
         self.assertTrue(os.path.exists(self.history_dir))
         self.assertTrue(os.path.isdir(self.history_dir))
 
@@ -194,16 +202,10 @@ class TestArchive(AgentTestCase):
         ts = self.parse_isoformat(timestamp_dirs[0])
         self.assertDateTimeCloseTo(ts, datetime.utcnow(), timedelta(seconds=30))
 
-        # Ensure saved files contain the right content
-        _check_history_files(timestamp_dirs[0], temp_files)
-
-        # re-write all of the same files with different content, and flush again.
-        # .flush() should overwrite the existing ones
-        _write_goal_state_files(temp_files, "--this-has-been-changed--")
-        test_subject.flush(timestamp)
-
-        # The contents of the saved files were overwritten as a result of the flush.
-        _check_history_files(timestamp_dirs[0], temp_files, "--this-has-been-changed--")
+        for f in temp_files:
+            history_path = os.path.join(self.history_dir, timestamp_dirs[0], f)
+            msg = "expected the temp file {0} to exist".format(history_path)
+            self.assertTrue(os.path.exists(history_path), msg)
 
     def test_archive04(self):
         """