nebius/SWE-bench-extra huggingface dataset:
Repository: Azure/WALinuxAgent

Issue:
Track Boot Time in Provision Event
To better understand and break down the provision process please include the boot time in the provision event, or emit a boot event with an appropriate duration.

Comments:

Patch:
diff --git a/azurelinuxagent/pa/provision/cloudinit.py b/azurelinuxagent/pa/provision/cloudinit.py
index 60d42fd2..de07ea93 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",
+            self.report_event("Provisioning with cloud-init succeeded ({0})".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 5d07fdf4..5df572cb 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",
+            self.report_event("Provisioning succeeded ({0})".format(self._get_uptime_seconds()),
                 is_success=True,
                 duration=elapsed_milliseconds(utc_start))
 
@@ -125,6 +125,15 @@ class ProvisionHandler(object):
                 continue
         return is_running == is_expected
 
+    @staticmethod
+    def _get_uptime_seconds():
+        try:
+            with open('/proc/uptime') as fh:
+                uptime, _ = fh.readline().split()
+                return uptime
+        except:
+            return 0
+
     def reg_ssh_host_key(self):
         keypair_type = conf.get_ssh_host_keypair_type()
         if conf.get_regenerate_ssh_host_key():


Test patch:
diff --git a/tests/pa/test_provision.py b/tests/pa/test_provision.py
index 1004547b..52098f2f 100644
--- a/tests/pa/test_provision.py
+++ b/tests/pa/test_provision.py
@@ -146,8 +146,12 @@ class TestProvision(AgentTestCase):
 
         ph.run()
 
-        call1 = call("Provisioning succeeded", duration=ANY, is_success=True)
-        ph.report_event.assert_has_calls([call1])
+        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)
+        self.assertTrue(isinstance(kw_args['duration'], int))
+        self.assertTrue(kw_args['is_success'])
 
     @distros()
     @patch(
Repository: Azure/WALinuxAgent

Issue:
Record OS boot time for Failed Provisions Too
The OS boot time is recorded in the Provision event **only** in the case of a successful provision.  The OS boot time should be recorded in the case of a failed provision too.

Comments:

Patch:
diff --git a/azurelinuxagent/pa/provision/cloudinit.py b/azurelinuxagent/pa/provision/cloudinit.py
index 9609d7da..3f3cdb04 100644
--- a/azurelinuxagent/pa/provision/cloudinit.py
+++ b/azurelinuxagent/pa/provision/cloudinit.py
@@ -69,9 +69,10 @@ class CloudInitProvisionHandler(ProvisionHandler):
                 duration=elapsed_milliseconds(utc_start))
 
         except ProvisionError as e:
-            logger.error("Provisioning failed: {0}", ustr(e))
+            msg = "Provisioning with cloud-init failed: {0} ({1}s)".format(ustr(e), self._get_uptime_seconds())
+            logger.error(msg)
             self.report_not_ready("ProvisioningFailed", ustr(e))
-            self.report_event(ustr(e))
+            self.report_event(msg)
             return
 
     def wait_for_ovfenv(self, max_retry=1800, sleep_time=1):
diff --git a/azurelinuxagent/pa/provision/default.py b/azurelinuxagent/pa/provision/default.py
index a6e50824..0eb0823c 100644
--- a/azurelinuxagent/pa/provision/default.py
+++ b/azurelinuxagent/pa/provision/default.py
@@ -98,9 +98,10 @@ class ProvisionHandler(object):
             logger.info("Provisioning complete")
 
         except (ProtocolError, ProvisionError) as e:
+            msg = "Provisioning failed: {0} ({1}s)".format(ustr(e), self._get_uptime_seconds())
+            logger.error(msg)
             self.report_not_ready("ProvisioningFailed", ustr(e))
-            self.report_event(ustr(e), is_success=False)
-            logger.error("Provisioning failed: {0}", ustr(e))
+            self.report_event(msg, is_success=False)
             return
 
     @staticmethod


Test patch:
diff --git a/tests/pa/test_provision.py b/tests/pa/test_provision.py
index 0335bc9c..27f75266 100644
--- a/tests/pa/test_provision.py
+++ b/tests/pa/test_provision.py
@@ -268,8 +268,8 @@ class TestProvision(AgentTestCase):
         fileutil.write_file(ovfenv_file, ovfenv_data)
 
         ph.run()
-        ph.report_event.assert_called_once_with(
-            '[ProvisionError] --unit-test--', is_success=False)
+        positional_args, kw_args = ph.report_event.call_args_list[0]
+        self.assertTrue(re.match(r'Provisioning failed: \[ProvisionError\] --unit-test-- \(\d+\.\d+s\)', positional_args[0]) is not None)
 
     @patch('azurelinuxagent.pa.provision.default.ProvisionHandler.write_agent_disabled')
     @distros()