def install_package(self, transaction_id, image_path, blacklisted_packages, send_reply, send_error): try: print "Package Manager: Install Package" print " Operation Transaction ID: {}".format(transaction_id) print " Image Path: {}".format(image_path) print " Blacklisted packages: {}".format(blacklisted_packages) print "---" # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # Simulate install print "Intalling package: {} (5 sec)".format(image_path) for i in xrange(1, 50): sys.stdout.write('.') sys.stdout.flush() time.sleep(0.1) print print "Done" swm.send_operation_result( transaction_id, swm.SWM_RES_OK, "Installation successful. Path: {}".format(image_path)) except Exception as e: print "install_package() Exception: {}".format(e) traceback.print_exc() swm.send_operation_result(transaction_id, swm.SWM_RES_INTERNAL_ERROR, "Internal_error: {}".format(e)) return None
def patchDiskPartition(self, transaction_id, disk, partition_number, image_path, blacklisted_partitions, send_reply, send_error): """Patch a Partition on a Disk Dbus callback for patching a partition on a disk using the platform's partition management system. @param transaction_id Software Loading Manager transaction id @param disk Disk from which to delete the partition @param partition_number Number of the partition @param image_path Image to write to the partition @param blacklisted_partitions List of blacklisted partitions @param send_reply DBus callback for a standard reply @param send_error DBus callback for error response """ logger.debug('PartitionManager.PartMgrService.patchDiskPartition(%s, %s, %s, %s, %s): Called.', transaction_id, disk, partition_number, image_path, blacklisted_partitions) try: # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # assemble partition patch command #cmd = settings.PKGMGR_INSTALL_CMD #cmd.append(image_path) #logger.info('PartitionManager.PartMgrService.patchDiskPartition(): Command: %s', cmd) if settings.SWM_SIMULATION: # simulate patching the disk partition logger.info('PartitionManager.PartMgrService.patchDiskPartition(): Patching disk partition simulation...') time.sleep(settings.SWM_SIMULATION_WAIT) resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Patching disk partition simulation successful. Disk: {}:{}".format(disk, partition_number) logger.info('PartitionManager.PartMgrService.patchDiskPartition(): Patching disk partition simulation successful.') else: # perform patching the disk partition logger.info('PartitionManager.PartMgrService.patchDiskPartition(): Patching disk partition...') resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Patching disk partition successful. Disk: {}:{}".format(disk, partition_number) logger.info('PartitionManager.PartMgrService.patchDiskPartition(): Patching disk partition successful.') swm.send_operation_result(transaction_id, resultcode, resulttext) except Exception as e: logger.error('PartitionManager.PartMgrService.patchDiskPartition(): Exception: %s.', e) swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_INTERNAL_ERROR, "Internal_error: {}".format(e)) return None
def remove_package(self, transaction_id, package_id, send_reply, send_error): try: print "Package Manager: Remove package" print " Operation Transaction ID: {}".format(transaction_id) print " Package ID: {}".format(package_id) print "---" # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # Simulate remove print "Upgrading package: {} (5 sec)".format(package_id) for i in xrange(1, 50): sys.stdout.write('.') sys.stdout.flush() time.sleep(0.1) print print "Done" swm.send_operation_result( transaction_id, swm.SWM_RES_OK, "Removal successful. Package_id: {}".format(package_id)) except Exception as e: print "upgrade_package() Exception: {}".format(e) traceback.print_exc() swm.send_operation_result(transaction_id, swm.SWM_RES_INTERNAL_ERROR, "Internal_error: {}".format(e)) return None return None
def stopComponents(self, transaction_id, components, send_reply, send_error): print "Lifecycle Manager: Got stopComponents()" print " Operation Transaction ID: {}".format(transaction_id) print " Components: {}".format(", ".join(components)) print "---" # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # Simulate install print "Stopping :" for i in components: print " Stopping: {} (3 sec)".format(i) time.sleep(3.0) print print "Done" swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_OK, "Stopped components {}".format(", ".join(components))) return None
def deleteDiskPartition(self, transaction_id, disk, send_reply, send_error): logger.debug('PartitionManager.PartMgrService.deleteDiskPartition(%s, %s, %s): Called.', transaction_id, disk, partition_number) try: # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # Simulate install sys.stdout.write("Delete partition: disk({}) partiton({}) (5 sec)\n".format(disk, partition_number)) for i in xrange(1,10): sys.stdout.write('.') sys.stdout.flush() time.sleep(0.2) sys.stdout.write("\nDone\n") swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_OK, "Partition delete success. Disk: {}:{}".format(disk, partition_number)) except Exception as e: logger.error('PartitionManager.PartMgrService.deleteDiskPartition(): Exception: %s.', e) swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_INTERNAL_ERROR, "Internal_error: {}".format(e)) return None
def patchDiskPartition( self, transaction_id, disk, partition_number, image_path, blacklisted_partitions, send_reply, send_error ): print "Partition Manager: patchDiskPartition()" print " Operfation Transaction ID: {}".format(transaction_id) print " Disk: {}".format(disk) print " Partition Number: {}".format(partition_number) print " Image Path: {}".format(image_path) print " Blacklisted Partitions: {}".format(blacklisted_partitions) print "---" # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # Simulate patch print "Patching partition: disk({}) partiton({}) (10 sec)".format(disk, partition_number) for i in xrange(1, 50): sys.stdout.patch(".") sys.stdout.flush() time.sleep(0.2) print print "Done" swm.send_operation_result( transaction_id, swm.SWMResult.SWM_RES_OK, "Partition patch success. Disk: {}:{} Image: {}".format(disk, partition_number, image_path), ) return None
def flashModuleFirmware(self, transaction_id, image_path, blacklisted_firmware, allow_downgrade, send_reply, send_error): logger.debug('ModuleLoader.ECU1ModuleLoaderService.flashModuleFirmware(%s, %s, %s, %s): Called.', transaction_id, image_path, blacklisted_firmware, allow_downgrade) # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # Simulate install sys.stdout.write("Intalling on ECU1: {} (5 sec):\n".format(image_path)) for i in xrange(1,50): sys.stdout.write('.') sys.stdout.flush() time.sleep(0.1) sys.stdout.write("\nDone\n") swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_OK, "Firmware flashing successful for ecu1. Path: {}".format(image_path)) return None
def delete_disk_partition(self, transaction_id, disk, send_reply, send_error): print "Partition Manager: delete_disk_partition()" print " Operfation Transaction ID: {}".format(transaction_id) print " Disk: {}".format(disk) print " Partition Number: {}".format(partition_number) print "---" # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # Simulate install print "Delete partition: disk({}) partiton({}) (5 sec)".format(disk, partition_number) for i in xrange(1,10): sys.stdout.write('.') sys.stdout.flush() time.sleep(0.2) print print "Done" swm.send_operation_result(transaction_id, swm.SWM_RES_OK, "Partition delete success. Disk: {}:{}".format(disk, partition_number)) return None
def flashModuleFirmware(self, transaction_id, image_path, blacklisted_firmware, allow_downgrade, send_reply, send_error): print "Package Manager: Got flashModuleFirmware()" print " Operation Transaction ID: {}".format(transaction_id) print " Image Path: {}".format(image_path) print " Blacklisted firmware: {}".format(blacklisted_firmware) print " Allow downgrade: {}".format(allow_downgrade) print "---" # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # Simulate install print "Intalling on ECU1: {} (5 sec):".format(image_path) for i in xrange(1,50): sys.stdout.write('.') sys.stdout.flush() time.sleep(0.1) print print "Done" swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_OK, "Firmware flashing successful for ecu1. Path: {}".format(image_path)) return None
def stop_components(self, transaction_id, components, send_reply, send_error): print "Lifecycle Manager: Got stop_components()" print " Operation Transaction ID: {}".format(transaction_id) print " Components: {}".format(", ".join(components)) print "---" # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # Simulate install print "Stopping :" for i in components: print " Stopping: {} (3 sec)".format(i) time.sleep(3.0) print print "Done" swm.send_operation_result(transaction_id, swm.SWM_RES_OK, "Stopped components {}".format(", ".join(components))) return None
def resizeDiskPartition(self, transaction_id, disk, partition_number, start, size, send_reply, send_error): print "Partition Manager: resizeDiskPartition()" print " Operfation Transaction ID: {}".format(transaction_id) print " Disk: {}".format(disk) print " Partition Number: {}".format(partition_number) print " Start: {}".format(start) print " Size: {}".format(size) print "---" # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # Simulate install print "Resizing partition: disk({}) partiton({}) (10 sec)".format(disk, partition_number) for i in xrange(1, 50): sys.stdout.write(".") sys.stdout.flush() time.sleep(0.2) print print "Done" swm.send_operation_result( transaction_id, swm.SWMResult.SWM_RES_OK, "Partition resize success. Disk: {}:{}".format(disk, partition_number), ) return None
def create_disk_partition(self, transaction_id, disk, partition_number, partition_type, start, size, guid, name, send_reply, send_error): print "Partition Manager: create_disk_partition()" print " Operfation Transaction ID: {}".format(transaction_id) print " Disk: {}".format(disk) print " Partition Number: {}".format(partition_number) print " Partition Type: {}".format(partition_type) print " Start: {}".format(start) print " Size: {}".format(size) print " GUID: {}".format(guid) print " Name: {}".format(name) print "---" # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # Simulate install print "Create partition: disk({}) partiton({}) (3 sec)".format(disk, partition_number) for i in xrange(1,30): sys.stdout.write('.') sys.stdout.flush() time.sleep(0.1) print print "Done" swm.send_operation_result(transaction_id, swm.SWM_RES_OK, "Partition create successful. Disk: {}:{}".format(disk, partition_number)) return None
def upgradePackage(self, transaction_id, image_path, blacklisted_packages, allow_downgrade, send_reply, send_error): try: print "Package Manager: Upgrade package" print " Operation Transaction ID: {}".format(transaction_id) print " Image Path: {}".format(image_path) print " Allow downgrade: {}".format(allow_downgrade) print " Blacklisted packages: {}".format(blacklisted_packages) print "---" # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # Simulate install print "Upgrading package: {} (5 sec)".format(image_path) for i in xrange(1,50): sys.stdout.write('.') sys.stdout.flush() time.sleep(0.1) print print "Done" swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_OK, "Upgrade successful. Path: {}".format(image_path)) except Exception as e: print "upgrade_package() Exception: {}".format(e) traceback.print_exc() swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_INTERNAL_ERROR, "Internal_error: {}".format(e)) return None
def startComponents(self, transaction_id, components, send_reply, send_error): logger.debug('LifecycleManager.LCMgrService.startComponents(%s, %s): Called.', transaction_id, components) # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # Simulate starting components for i in components: logger.debug('LifecycleManager.LCMgrService.startComponents(): Starting: %s', i) time.sleep(3.0) swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_OK, "Started components {}".format(", ".join(components))) return None
def removePackage(self, transaction_id, package_id, send_reply, send_error): try: print "Package Manager: Remove package" print " Operation Transaction ID: {}".format(transaction_id) print " Package ID: {}".format(package_id) print "---" # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # Simulate remove print "Upgrading package: {} (5 sec)".format(package_id) for i in xrange(1,50): sys.stdout.write('.') sys.stdout.flush() time.sleep(0.1) print print "Done" swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_OK, "Removal successful. Package_id: {}".format(package_id)) except Exception as e: print "upgrade_package() Exception: {}".format(e) traceback.print_exc() swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_INTERNAL_ERROR, "Internal_error: {}".format(e)) return None return None
def create_disk_partition(self, transaction_id, disk, partition_number, partition_type, start, size, guid, name, send_reply, send_error): print "Partition Manager: create_disk_partition()" print " Operfation Transaction ID: {}".format(transaction_id) print " Disk: {}".format(disk) print " Partition Number: {}".format(partition_number) print " Partition Type: {}".format(partition_type) print " Start: {}".format(start) print " Size: {}".format(size) print " GUID: {}".format(guid) print " Name: {}".format(name) print "---" # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # Simulate install print "Create partition: disk({}) partiton({}) (3 sec)".format( disk, partition_number) for i in xrange(1, 30): sys.stdout.write('.') sys.stdout.flush() time.sleep(0.1) print print "Done" swm.send_operation_result( transaction_id, swm.SWM_RES_OK, "Partition create successful. Disk: {}:{}".format( disk, partition_number)) return None
def startComponents(self, transaction_id, components, send_reply, send_error): logger.debug( 'LifecycleManager.LCMgrService.startComponents(%s, %s): Called.', transaction_id, components) # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # Simulate starting components for i in components: logger.debug( 'LifecycleManager.LCMgrService.startComponents(): Starting: %s', i) time.sleep(3.0) swm.send_operation_result( transaction_id, swm.SWMResult.SWM_RES_OK, "Started components {}".format(", ".join(components))) return None
def installPackage(self, transaction_id, image_path, blacklisted_packages, send_reply, send_error): """Install Software Package Dbus callback for installing a software package using the platform's package management system. @param transaction_id Software Loading Manager transaction id @param image_path Path to the software package to be installed @param blacklisted_packages List of packages that must not be installed @param send_reply DBus callback for a standard reply @param send_error DBus callback for error response """ logger.debug( 'PackageManager.PkgMgrService.installPackage(%s, %s, %s): Called.', transaction_id, image_path, blacklisted_packages) try: # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # extract package and check for blacklisted pkg = os.path.basename(image_path) if pkg in blacklisted_packages: logger.warning( 'PackageManager.PkgMgrService.installPackage(): Blacklisted Package: %s', pkg) swm.send_operation_result( transaction_id, swm.SWMResult.SWM_RES_OPERATION_BLACKLISTED, "Blacklisted Package: {}".format(pkg)) return None # assemble installation command cmd = list(settings.PKGMGR_INSTALL_CMD) cmd.append(image_path) logger.info( 'PackageManager.PkgMgrService.installPackage(): Command: %s', cmd) if settings.SWM_SIMULATION: # simulate installation logger.info( 'PackageManager.PkgMgrService.installPackage(): Installation Simulation...' ) time.sleep(settings.SWM_SIMULATION_WAIT) resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Installation Simulation successful. Command: {}".format( cmd) logger.info( 'PackageManager.PkgMgrService.installPackage(): Installation Simulation successful.' ) else: # perform installation sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if sp.wait() == 0: (stdout, stderr) = sp.communicate() resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Installation successful. Result: {}".format( stdout) logger.info( 'PackageManager.PkgMgrService.installPackage(): Installation successful.' ) else: (stdout, stderr) = sp.communicate() resultcode = swm.SWMResult.SWM_RES_INSTALL_FAILED resulttext = "Installation failed. Error: {}".format( stderr) logger.error( 'PackageManager.PkgMgrService.installPackage(): Installation failed: %s.', stderr) swm.send_operation_result(transaction_id, resultcode, resulttext) except Exception as e: logger.error( 'PackageManager.PkgMgrService.installPackage(): Exception: %s.', e) swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_INTERNAL_ERROR, "Internal_error: {}".format(e)) return None
def removePackage(self, transaction_id, package_id, send_reply, send_error): """Remove Software Package Dbus callback for installing a software package using the platform's package management system. @param transaction_id Software Loading Manager transaction id @param package_id Name of the software package @param send_error DBus callback for error response """ logger.debug( 'PackageManager.PkgMgrService.removePackage(%s, %s): Called.', transaction_id, package_id) try: # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # assemble remove command cmd = list(settings.PKGMGR_REMOVE_CMD) cmd.append(package_id) logger.info( 'PackageManager.PkgMgrService.removePackage(): Command: %s', cmd) if settings.SWM_SIMULATION: # simulate removal logger.info( 'PackageManager.PkgMgrService.removePackage(): Removal Simulation...' ) time.sleep(settings.SWM_SIMULATION_WAIT) resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Removal Simulation successful. Command: {}".format( cmd) logger.info( 'PackageManager.PkgMgrService.removePackage(): Removal Simulation successful.' ) else: # perform removal sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if sp.wait() == 0: (stdout, stderr) = sp.communicate() resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Removal successful. Result: {}".format( stdout) logger.info( 'PackageManager.PkgMgrService.removePackage(): Removal successful.' ) else: (stdout, stderr) = sp.communicate() resultcode = swm.SWMResult.SWM_RES_REMOVAL_FAILED resulttext = "Removal failed. Error: {}".format(stderr) logger.error( 'PackageManager.PkgMgrService.removePackage(): Removal failed: %s.', stderr) swm.send_operation_result(transaction_id, resultcode, resulttext) except Exception as e: logger.error( 'PackageManager.PkgMgrService.removePackage(): Exception: %s.', e) swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_INTERNAL_ERROR, "Internal_error: {}".format(e)) return None
def removePackage(self, transaction_id, package_id, send_reply, send_error): """Remove Software Package Dbus callback for installing a software package using the platform's package management system. @param transaction_id Software Loading Manager transaction id @param package_id Name of the software package @param send_error DBus callback for error response """ logger.debug('PackageManager.PkgMgrService.removePackage(%s, %s): Called.', transaction_id, package_id) try: # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # assemble remove command cmd = settings.PKGMGR_REMOVE_CMD cmd.append(package_id) logger.info('PackageManager.PkgMgrService.removePackage(): Command: %s', cmd) if settings.SWM_SIMULATION: # simulate removal logger.info('PackageManager.PkgMgrService.removePackage(): Removal Simulation...') time.sleep(settings.SWM_SIMULATION_WAIT) resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Removal Simulation successful. Command: {}".format(cmd) logger.info('PackageManager.PkgMgrService.removePackage(): Removal Simulation successful.') else: # perform removal sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if sp.wait() == 0: (stdout, stderr) = sp.communicate() resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Removal successful. Result: {}".format(stdout) logger.info('PackageManager.PkgMgrService.removePackage(): Removal successful.') else: (stdout, stderr) = sp.communicate() resultcode = swm.SWMResult.SWM_RES_REMOVAL_FAILED resulttext = "Removal failed. Error: {}".format(stderr) logger.error('PackageManager.PkgMgrService.removePackage(): Removal failed: %s.', stderr) swm.send_operation_result(transaction_id, resultcode, resulttext) except Exception as e: logger.error('PackageManager.PkgMgrService.removePackage(): Exception: %s.', e) swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_INTERNAL_ERROR, "Internal_error: {}".format(e)) return None
def createDiskPartition(self, transaction_id, disk, partition_number, partition_type, start, size, guid, name, send_reply, send_error): """Create a Partition on a Disk Dbus callback for creating a partition on a disk using the platform's partition management system. @param transaction_id Software Loading Manager transaction id @param disk Disk to partition @param partition_number Number of the partition @param partition_type Type of the partition @param start Start sector of the partition @param size Size in bytes of the partition @param guid GUID for the partition @param name Name of the partition @param send_reply DBus callback for a standard reply @param send_error DBus callback for error response """ logger.debug( 'PartitionManager.PartMgrService.createDiskPartition(%s, %s, %s, %s, %s, %s, %s, %s): Called.', transaction_id, disk, partition_number, partition_type, start, size, guid, name) try: # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # assemble partition creation command #cmd = settings.PKGMGR_INSTALL_CMD #cmd.append(image_path) #logger.info('PartitionManager.PartMgrService.createDiskPartition(): Command: %s', cmd) if settings.SWM_SIMULATION: # simulate creating the disk partition logger.info( 'PartitionManager.PartMgrService.createDiskPartition(): Creating disk partition simulation...' ) time.sleep(settings.SWM_SIMULATION_WAIT) resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Creating disk partition simulation successful. Disk: {}:{}".format( disk, partition_number) logger.info( 'PartitionManager.PartMgrService.createDiskPartition(): Creating disk partition simulation successful.' ) else: # perform disk partition creation logger.info( 'PartitionManager.PartMgrService.createDiskPartition(): Creating disk partition...' ) resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Creating disk partition successful. Disk: {}:{}".format( disk, partition_number) logger.info( 'PartitionManager.PartMgrService.createDiskPartition(): Creating disk partition successful.' ) swm.send_operation_result(transaction_id, resultcode, resulttext) except Exception as e: logger.error( 'PartitionManager.PartMgrService.createDiskPartition(): Exception: %s.', e) swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_INTERNAL_ERROR, "Internal_error: {}".format(e)) return None
def upgradePackage(self, transaction_id, image_path, blacklisted_packages, allow_downgrade, send_reply, send_error): """Upgrade Software Package Dbus callback for upgrading a software package using the platform's package management system. @param transaction_id Software Loading Manager transaction id @param image_path Path to the software package to be installed @param blacklisted_packages List of packages that must not be installed @param allow_downgrade Permit downgrading of the package to a previous version @param send_reply DBus callback for a standard reply @param send_error DBus callback for error response """ logger.debug( 'PackageManager.PkgMgrService.upgradePackage(%s, %s, %s, %s): Called.', transaction_id, image_path, blacklisted_packages, allow_downgrade) try: # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # extract package and check for blacklisted pkg = os.path.basename(image_path) if pkg in blacklisted_packages: logger.warning( 'PackageManager.PkgMgrService.upgradePackage(): Blacklisted Package: %s', pkg) swm.send_operation_result( transaction_id, swm.SWMResult.SWM_RES_OPERATION_BLACKLISTED, "Blacklisted Package: {}".format(pkg)) return None # check if package is installed and compare versions pkglist = self.checkInstalledPackage(pkg) if len(pkglist) > 0 and not allow_downgrade: # only need to check package version if package is installed # and downgrading is not allowed if not self.isNewer(pkglist, pkg): logger.info( 'PackageManager.PkgMgrService.upgradePackage(): Downgrade prohibited.' ) swm.send_operation_result( transaction_id, swm.SWMResult.SWM_RES_OLD_VERSION, "Package downgrade prohibited.") return None # assemble upgrade command cmd = list(settings.PKGMGR_UPGRADE_CMD) cmd.append(image_path) logger.info( 'PackageManager.PkgMgrService.upgradePackage(): Command: %s', cmd) if settings.SWM_SIMULATION: # simulate upgrade logger.info( 'PackageManager.PkgMgrService.upgradePackage(): Upgrade Simulation...' ) time.sleep(settings.SWM_SIMULATION_WAIT) resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Upgrade Simulation successful. Command: {}".format( cmd) logger.info( 'PackageManager.PkgMgrService.upgradePackage(): Upgrade Simulation successful.' ) else: # perform upgrade sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if sp.wait() == 0: (stdout, stderr) = sp.communicate() resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Upgrade successful. Result: {}".format( stdout) logger.info( 'PackageManager.PkgMgrService.upgradePackage(): Upgrade successful.' ) else: (stdout, stderr) = sp.communicate() resultcode = swm.SWMResult.SWM_RES_UPGRADE_FAILED resulttext = "Upgrade failed. Error: {}".format(stderr) logger.error( 'PackageManager.PkgMgrService.upgradePackage(): Upgrade failed: %s.', stderr) swm.send_operation_result(transaction_id, resultcode, resulttext) except Exception as e: logger.error( 'PackageManager.PkgMgrService.upgradePackage(): Exception: %s.', e) swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_INTERNAL_ERROR, "Internal_error: {}".format(e)) return None
def upgradePackage(self, transaction_id, image_path, blacklisted_packages, allow_downgrade, send_reply, send_error): """Upgrade Software Package Dbus callback for upgrading a software package using the platform's package management system. @param transaction_id Software Loading Manager transaction id @param image_path Path to the software package to be installed @param blacklisted_packages List of packages that must not be installed @param allow_downgrade Permit downgrading of the package to a previous version @param send_reply DBus callback for a standard reply @param send_error DBus callback for error response """ logger.debug('PackageManager.PkgMgrService.upgradePackage(%s, %s, %s, %s): Called.', transaction_id, image_path, blacklisted_packages, allow_downgrade) try: # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # extract package and check for blacklisted pkg = os.path.basename(image_path) if pkg in blacklisted_packages: logger.warning('PackageManager.PkgMgrService.upgradePackage(): Blacklisted Package: %s', pkg) swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_OPERATION_BLACKLISTED, "Blacklisted Package: {}".format(pkg)) return None # check if package is installed and compare versions pkglist = self.checkInstalledPackage(pkg) if len(pkglist) > 0 and not allow_downgrade: # only need to check package version if package is installed # and downgrading is not allowed if not self.isNewer(pkglist, pkg): logger.info('PackageManager.PkgMgrService.upgradePackage(): Downgrade prohibited.') swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_OLD_VERSION, "Package downgrade prohibited.") return None # assemble upgrade command cmd = settings.PKGMGR_UPGRADE_CMD cmd.append(image_path) logger.info('PackageManager.PkgMgrService.upgradePackage(): Command: %s', cmd) if settings.SWM_SIMULATION: # simulate upgrade logger.info('PackageManager.PkgMgrService.upgradePackage(): Upgrade Simulation...') time.sleep(settings.SWM_SIMULATION_WAIT) resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Upgrade Simulation successful. Command: {}".format(cmd) logger.info('PackageManager.PkgMgrService.upgradePackage(): Upgrade Simulation successful.') else: # perform upgrade sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if sp.wait() == 0: (stdout, stderr) = sp.communicate() resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Upgrade successful. Result: {}".format(stdout) logger.info('PackageManager.PkgMgrService.upgradePackage(): Upgrade successful.') else: (stdout, stderr) = sp.communicate() resultcode = swm.SWMResult.SWM_RES_UPGRADE_FAILED resulttext = "Upgrade failed. Error: {}".format(stderr) logger.error('PackageManager.PkgMgrService.upgradePackage(): Upgrade failed: %s.', stderr) swm.send_operation_result(transaction_id, resultcode, resulttext) except Exception as e: logger.error('PackageManager.PkgMgrService.upgradePackage(): Exception: %s.', e) swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_INTERNAL_ERROR, "Internal_error: {}".format(e)) return None
def createDiskPartition(self, transaction_id, disk, partition_number, partition_type, start, size, guid, name, send_reply, send_error): """Create a Partition on a Disk Dbus callback for creating a partition on a disk using the platform's partition management system. @param transaction_id Software Loading Manager transaction id @param disk Disk to partition @param partition_number Number of the partition @param partition_type Type of the partition @param start Start sector of the partition @param size Size in bytes of the partition @param guid GUID for the partition @param name Name of the partition @param send_reply DBus callback for a standard reply @param send_error DBus callback for error response """ logger.debug('PartitionManager.PartMgrService.createDiskPartition(%s, %s, %s, %s, %s, %s, %s, %s): Called.', transaction_id, disk, partition_number, partition_type, start, size, guid, name) try: # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # assemble partition creation command #cmd = settings.PKGMGR_INSTALL_CMD #cmd.append(image_path) #logger.info('PartitionManager.PartMgrService.createDiskPartition(): Command: %s', cmd) if settings.SWM_SIMULATION: # simulate creating the disk partition logger.info('PartitionManager.PartMgrService.createDiskPartition(): Creating disk partition simulation...') time.sleep(settings.SWM_SIMULATION_WAIT) resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Creating disk partition simulation successful. Disk: {}:{}".format(disk, partition_number) logger.info('PartitionManager.PartMgrService.createDiskPartition(): Creating disk partition simulation successful.') else: # perform disk partition creation logger.info('PartitionManager.PartMgrService.createDiskPartition(): Creating disk partition...') resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Creating disk partition successful. Disk: {}:{}".format(disk, partition_number) logger.info('PartitionManager.PartMgrService.createDiskPartition(): Creating disk partition successful.') swm.send_operation_result(transaction_id, resultcode, resulttext) except Exception as e: logger.error('PartitionManager.PartMgrService.createDiskPartition(): Exception: %s.', e) swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_INTERNAL_ERROR, "Internal_error: {}".format(e)) return None
def installPackage(self, transaction_id, image_path, blacklisted_packages, send_reply, send_error): """Install Software Package Dbus callback for installing a software package using the platform's package management system. @param transaction_id Software Loading Manager transaction id @param image_path Path to the software package to be installed @param blacklisted_packages List of packages that must not be installed @param send_reply DBus callback for a standard reply @param send_error DBus callback for error response """ logger.debug('PackageManager.PkgMgrService.installPackage(%s, %s, %s): Called.', transaction_id, image_path, blacklisted_packages) try: # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # extract package and check for blacklisted pkg = os.path.basename(image_path) if pkg in blacklisted_packages: logger.warning('PackageManager.PkgMgrService.installPackage(): Blacklisted Package: %s', pkg) swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_OPERATION_BLACKLISTED, "Blacklisted Package: {}".format(pkg)) return None # assemble installation command cmd = settings.PKGMGR_INSTALL_CMD cmd.append(image_path) logger.info('PackageManager.PkgMgrService.installPackage(): Command: %s', cmd) if settings.SWM_SIMULATION: # simulate installation logger.info('PackageManager.PkgMgrService.installPackage(): Installation Simulation...') time.sleep(settings.SWM_SIMULATION_WAIT) resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Installation Simulation successful. Command: {}".format(cmd) logger.info('PackageManager.PkgMgrService.installPackage(): Installation Simulation successful.') else: # perform installation sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if sp.wait() == 0: (stdout, stderr) = sp.communicate() resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Installation successful. Result: {}".format(stdout) logger.info('PackageManager.PkgMgrService.installPackage(): Installation successful.') else: (stdout, stderr) = sp.communicate() resultcode = swm.SWMResult.SWM_RES_INSTALL_FAILED resulttext = "Installation failed. Error: {}".format(stderr) logger.error('PackageManager.PkgMgrService.installPackage(): Installation failed: %s.', stderr) swm.send_operation_result(transaction_id, resultcode, resulttext) except Exception as e: logger.error('PackageManager.PkgMgrService.installPackage(): Exception: %s.', e) swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_INTERNAL_ERROR, "Internal_error: {}".format(e)) return None
def patchDiskPartition(self, transaction_id, disk, partition_number, image_path, blacklisted_partitions, send_reply, send_error): """Patch a Partition on a Disk Dbus callback for patching a partition on a disk using the platform's partition management system. @param transaction_id Software Loading Manager transaction id @param disk Disk from which to delete the partition @param partition_number Number of the partition @param image_path Image to write to the partition @param blacklisted_partitions List of blacklisted partitions @param send_reply DBus callback for a standard reply @param send_error DBus callback for error response """ logger.debug( 'PartitionManager.PartMgrService.patchDiskPartition(%s, %s, %s, %s, %s): Called.', transaction_id, disk, partition_number, image_path, blacklisted_partitions) try: # # Send back an immediate reply since DBUS # doesn't like python dbus-invoked methods to do # their own calls (nested calls). # send_reply(True) # assemble partition patch command #cmd = settings.PKGMGR_INSTALL_CMD #cmd.append(image_path) #logger.info('PartitionManager.PartMgrService.patchDiskPartition(): Command: %s', cmd) if settings.SWM_SIMULATION: # simulate patching the disk partition logger.info( 'PartitionManager.PartMgrService.patchDiskPartition(): Patching disk partition simulation...' ) time.sleep(settings.SWM_SIMULATION_WAIT) resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Patching disk partition simulation successful. Disk: {}:{}".format( disk, partition_number) logger.info( 'PartitionManager.PartMgrService.patchDiskPartition(): Patching disk partition simulation successful.' ) else: # perform patching the disk partition logger.info( 'PartitionManager.PartMgrService.patchDiskPartition(): Patching disk partition...' ) resultcode = swm.SWMResult.SWM_RES_OK resulttext = "Patching disk partition successful. Disk: {}:{}".format( disk, partition_number) logger.info( 'PartitionManager.PartMgrService.patchDiskPartition(): Patching disk partition successful.' ) swm.send_operation_result(transaction_id, resultcode, resulttext) except Exception as e: logger.error( 'PartitionManager.PartMgrService.patchDiskPartition(): Exception: %s.', e) swm.send_operation_result(transaction_id, swm.SWMResult.SWM_RES_INTERNAL_ERROR, "Internal_error: {}".format(e)) return None