Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/core/src/bootstrap/EnvLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def run_command_output(self, cmd, no_output=False, chk_err=False):
start = time.time()
code, output = self.__run_command_output_raw(cmd, no_output, chk_err)
self.__write_record(operation, code, output, delay=(time.time()-start))
return code, output
else:
return self.__read_record(operation)

Expand Down Expand Up @@ -271,7 +272,7 @@ def open(self, file_path, mode):
def __obtain_file_handle(self, file_path_or_handle, mode='a+'):
""" Pass-through for handle. For path, resolution and handle open with retry. """
is_path = False
if isinstance(file_path_or_handle, str):
if isinstance(file_path_or_handle, str) or isinstance(file_path_or_handle, unicode):
is_path = True
file_path_or_handle = self.open(file_path_or_handle, mode)
file_handle = file_path_or_handle
Expand Down Expand Up @@ -300,6 +301,7 @@ def write_with_retry(self, file_path_or_handle, data, mode='a+'):
for i in range(0, Constants.MAX_FILE_OPERATION_RETRY_COUNT):
try:
file_handle.write(str(data))
break
except Exception as error:
if i <= Constants.MAX_FILE_OPERATION_RETRY_COUNT:
time.sleep(i + 1)
Expand Down Expand Up @@ -359,7 +361,7 @@ def total_minutes_from_time_delta(time_delta):
@staticmethod
def utc_to_standard_datetime(utc_datetime):
""" Converts string of format '"%Y-%m-%dT%H:%M:%SZ"' to datetime object """
return datetime.datetime.strptime(utc_datetime.split(".")[0], "%Y-%m-%dT%H:%M:%SZ")
return datetime.datetime.strptime(utc_datetime.split(".")[0], "%Y-%m-%dT%H:%M:%S")
# endregion - DateTime emulator and extensions

# region - Core Emulator support functions
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/core_logic/PatchAssessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def start_assessment(self):
self.composite_logger.log('\nStarting patch assessment...')

self.status_handler.set_assessment_substatus_json(status=Constants.STATUS_TRANSITIONING)
self.composite_logger.log("\nMachine Id: " + self.env_layer.platform.machine_id)
self.composite_logger.log("\nMachine Id: " + self.env_layer.platform.node())
self.composite_logger.log("Activity Id: " + self.execution_config.activity_id)
self.composite_logger.log("Operation request time: " + self.execution_config.start_time)

Expand Down
2 changes: 1 addition & 1 deletion src/core/src/core_logic/PatchInstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def start_installation(self, simulate=False):
""" Kick off a patch installation run """
self.composite_logger.log('\nStarting patch installation...')

self.composite_logger.log("\nMachine Id: " + self.env_layer.platform.machine_id)
self.composite_logger.log("\nMachine Id: " + self.env_layer.platform.node())
self.composite_logger.log("Activity Id: " + self.execution_config.activity_id)
self.composite_logger.log("Operation request time: " + self.execution_config.start_time + ", Maintenance Window Duration: " + self.execution_config.duration)

Expand Down
13 changes: 13 additions & 0 deletions src/core/src/package_managers/PackageManager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The is base package manager, which defines the package management relevant operations"""
import os
from abc import ABCMeta, abstractmethod
from src.bootstrap.Constants import Constants
import time
Expand Down Expand Up @@ -300,3 +301,15 @@ def set_package_manager_setting(self, setting_key, setting_value=""):
def do_processes_require_restart(self):
"""Signals whether processes require a restart due to updates to files"""
pass

def is_reboot_pending(self):
""" Checks if there is a pending reboot on the machine. """
try:
pending_file_exists = os.path.isfile(self.REBOOT_PENDING_FILE_PATH)
pending_processes_exists = self.do_processes_require_restart()
self.composite_logger.log_debug(" - Reboot required debug flags: " + str(pending_file_exists) + ", " + str(pending_processes_exists) + ".")
return pending_file_exists or pending_processes_exists
except Exception as error:
self.composite_logger.log_error('Error while checking for reboot pending: ' + repr(error))
return True # defaults for safety

4 changes: 2 additions & 2 deletions src/core/src/service_interfaces/LifecycleManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def read_extension_sequence(self):
# Read (with retries for only IO Errors)
for i in range(0, Constants.MAX_FILE_OPERATION_RETRY_COUNT):
try:
with self.env_layer.file_system.open(self.ext_state_file_path) as file_handle:
with self.env_layer.file_system.open(self.ext_state_file_path, mode="r") as file_handle:
return json.load(file_handle)['extensionSequence']
except Exception as error:
if i <= Constants.MAX_FILE_OPERATION_RETRY_COUNT:
Expand All @@ -85,7 +85,7 @@ def read_core_sequence(self):
# Read (with retries for only IO Errors) - TODO: Refactor common code
for i in range(0, Constants.MAX_FILE_OPERATION_RETRY_COUNT):
try:
with self.env_layer.file_system.open(self.core_state_file_path) as file_handle:
with self.env_layer.file_system.open(self.core_state_file_path, mode="r") as file_handle:
core_sequence = json.load(file_handle)['coreSequence']
print(str(core_sequence))
return core_sequence
Expand Down
2 changes: 1 addition & 1 deletion src/extension/src/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ExtensionImage xmlns="http://schemas.microsoft.com/windowsazure">
<ProviderNameSpace>Microsoft.CPlat.Core</ProviderNameSpace>
<Type>LinuxPatchExtension</Type>
<Version>1.4.23</Version>
<Version>1.4.24</Version>
<Label>Microsoft Azure VM InGuest Patch Extension for Linux Virtual Machines</Label>
<HostingResources>VmRole</HostingResources>
<MediaLink></MediaLink>
Expand Down
2 changes: 1 addition & 1 deletion src/tools/Package-Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def read_python_module(source_code_path, module_name):
for line in py_file:
if line.startswith('import'):
imports.append(line)
elif line.strip().startswith('class') or line.strip().startswith('def main(argv):'):
elif line.strip().startswith('class') or line.strip().startswith('def main(argv):') or line.strip().startswith('if __name__ == "__main__"'):
is_code_body = True

if is_code_body is True:
Expand Down