Пример #1
0
    def update_confirmation(self,        
                            update_id, 
                            approved,
                            send_reply, 
                            send_error): 

        
        #
        # Send back an immediate reply since DBUS
        # doesn't like python dbus-invoked methods to do 
        # their own calls (nested calls).
        #
        send_reply(True)

        print "Got update_confirmation()."
        print "  Approved: {}".format(approved)
        print "  ID:       {}".format(update_id)
        if approved:
            #
            # Call the SOTA client and ask it to start the download.
            # Once the download is complete, SOTA client will call 
            # download complete on this process to actually
            # process the package.
            #
            print "Approved: Will call initiate_download()"
            self.initiate_download(update_id)
            print "Approved: Called sota_client.initiate_download()"
            print "---"
        else:
            # User did not approve. Send installation report
            print "Declined: Will call installation_report()"
            self.distribute_update_result(update_id, [
                swm.result('N/A',
                           swm.SWM_RES_USER_DECLINED,
                           "Installation declined by user")
            ]) 

            print "Declined. Called sota_client.installation_report()"
            print "---"

        return None
    def updateConfirmation(self,        
                            update_id, 
                            approved,
                            send_reply, 
                            send_error): 

        
        #
        # Send back an immediate reply since DBUS
        # doesn't like python dbus-invoked methods to do 
        # their own calls (nested calls).
        #
        send_reply(True)

        print "Got updateConfirmation()."
        print "  Approved: {}".format(approved)
        print "  ID:       {}".format(update_id)
        if approved:
            #
            # Call the SOTA client and ask it to start the download.
            # Once the download is complete, SOTA client will call 
            # download complete on this process to actually
            # process the package.
            #
            print "Approved: Will call initiate_download()"
            self.initiate_download(update_id)
            print "Approved: Called SotaClient.initiateDownload()"
            print "---"
        else:
            # User did not approve. Send installation report
            print "Declined: Will call installation_report()"
            self.distribute_update_result(update_id, [
                swm.result('N/A',
                           swm.SWMResult.SWM_RES_USER_DECLINED,
                           "Installation declined by user")
            ]) 

            print "Declined. Called sota_client.installation_report()"
            print "---"

        return None
    def updateConfirmation(self, update_id, approved, send_reply, send_error):

        logger.debug(
            'SoftwareLoadingManager.SLMService.updateConfirmation(%s, %s): Called.',
            update_id, approved)

        #
        # Send back an immediate reply since DBUS
        # doesn't like python dbus-invoked methods to do
        # their own calls (nested calls).
        #
        send_reply(True)

        if approved:
            #
            # Call the SOTA client and ask it to start the download.
            # Once the download is complete, SOTA client will call
            # download complete on this process to actually
            # process the package.
            #
            logger.debug(
                'SoftwareLoadingManager.SLMService.updateConfirmation(): Approved: Calling initiate_ownload().'
            )
            self.initiate_download(update_id)
            logger.debug(
                'SoftwareLoadingManager.SLMService.updateConfirmation(): Approved: Called SotaClient.initiateDownload().'
            )
        else:
            # User did not approve. Send installation report
            logger.debug(
                'SoftwareLoadingManager.SLMService.updateConfirmation(): Declined: Calling installation_report().'
            )
            self.distribute_update_result(update_id, [
                swm.result('N/A', swm.SWMResult.SWM_RES_USER_DECLINED,
                           "Installation declined by user")
            ])
            logger.debug(
                'SoftwareLoadingManager.SLMService.updateConfirmation(): Declined: Called SotaClient.installationReport().'
            )

        return None
Пример #4
0
    def complete_operation(self, transaction_id, result_code, result_text):
        """Complete currently pending operation
        
        Callback in response to an operation started with start_next_operation.
        
        @param transaction_id Id of the transaction
        @param result_code Code indicating the result of the operation
        @param result_text Text with result details
        
        @return True Sucessfully completed operation
                False No active operation
        """
        # Check that we have an active operation to
        # work with.
        if not self.active_operation:
            logger.warning('SoftwareLoadingManager.Manifest.complete_operation: No active operation.')
            return False

        # We have completed this specific transaction
        # Store it so that we don't run it again on restart
        swo = self.software_update.getSWOperation(self.active_operation.operation_id)
        swo.finish(result_code,result_text)
        self.software_update.finish()
        self.software_update.update()

        #
        # Add the result code from a software operation to self
        # All operation results will be reported to SOTA.
        #
        self.operation_results.append(
            swm.result(
                self.active_operation.operation_id,
                result_code,
                result_text)
        )

        self.active_operation = None
        return True
Пример #5
0
    def complete_transaction(self, transaction_id, result_code, result_text):
        # Check that we have an active transaction to
        # work with.
        if not self.active_operation:
            print "complete_transaction(): Warning: No active transaction for {}.".format(
                transaction_id)
            return False

        # We have completed this specific transaction
        # Store it so that we don't run it again on restart
        self.manifest_processor.add_completed_operation(
            self.active_operation.operation_id)

        #
        # Add the result code from a software operation to self
        # All operation results will be reported to SOTA.
        #
        self.operation_results.append(
            swm.result(self.active_operation.operation_id, result_code,
                       result_text))

        self.active_operation = None
        return True
Пример #6
0
    def updateConfirmation(self,        
                           update_id, 
                           approved,
                           send_reply, 
                           send_error): 

        logger.debug('SoftwareLoadingManager.SLMService.updateConfirmation(%s, %s): Called.',
                     update_id, approved)
        
        #
        # Send back an immediate reply since DBUS
        # doesn't like python dbus-invoked methods to do 
        # their own calls (nested calls).
        #
        send_reply(True)

        if approved:
            #
            # Call the SOTA client and ask it to start the download.
            # Once the download is complete, SOTA client will call 
            # download complete on this process to actually
            # process the package.
            #
            logger.debug('SoftwareLoadingManager.SLMService.updateConfirmation(): Approved: Calling initiate_ownload().')
            self.initiate_download(update_id)
            logger.debug('SoftwareLoadingManager.SLMService.updateConfirmation(): Approved: Called SotaClient.initiateDownload().')
        else:
            # User did not approve. Send installation report
            logger.debug('SoftwareLoadingManager.SLMService.updateConfirmation(): Declined: Calling installation_report().')
            self.distribute_update_result(update_id, [
                swm.result('N/A',
                           swm.SWMResult.SWM_RES_USER_DECLINED,
                           "Installation declined by user")
            ]) 
            logger.debug('SoftwareLoadingManager.SLMService.updateConfirmation(): Declined: Called SotaClient.installationReport().')

        return None
    def complete_transaction(self, transaction_id, result_code, result_text):
        # Check that we have an active transaction to
        # work with.
        if not self.active_operation:
            print "complete_transaction(): Warning: No active transaction for {}.".format(transaction_id)
            return False

        # We have completed this specific transaction
        # Store it so that we don't run it again on restart
        self.manifest_processor.add_completed_operation(self.active_operation.operation_id)

        #
        # Add the result code from a software operation to self
        # All operation results will be reported to SOTA.
        #
        self.operation_results.append(
            swm.result(
                self.active_operation.operation_id,
                result_code,
                result_text)
        )

        self.active_operation = None
        return True
    def load_from_string(self, manifest_string):

        print "Manifest.load_from_string(): Called"
        try:
            manifest = json.loads(manifest_string)
        except ValueError as e:
            print "Manifest: Failed to parse JSON string: {}".format(e)
            return False

        # Retrieve top-level elements
        self.update_id = manifest.get('update_id', False)
        self.name = manifest.get('name', False)
        self.description = manifest.get('description', False)
        self.show_hmi_progress = manifest.get('show_hmi_progress', False)
        self.show_hmi_result = manifest.get('show_hmi_result', False)
        self.allow_downgrade = manifest.get('allow_downgrade', False)
        self.get_user_confirmation = manifest.get('get_user_confirmation', False)
        self.operations = deque()
        print "Manifest.update_id:             {}".format(self.update_id)
        print "Manifest.name:                  {}".format(self.name)
        print "Manifest.description:           {}".format(self.description)
        print "Manifest.get_user_confirmation: {}".format(self.get_user_confirmation)
        print "Manifest.show_hmi_progress:     {}".format(self.show_hmi_progress)
        print "Manifest.show_hmi_result:       {}".format(self.show_hmi_result)
        print "Manifest.allow_downgrade:       {}".format(self.allow_downgrade)

        # Traverse all operations and create / load up a relevant 
        # object for each one.
        try:
            for op in manifest.get('operations', []):

                # Grab opearation id. 
                op_id = op.get('id', False)

                # Skip entire operation if operation_id is not defined.
                if not op_id:
                    print "Manifest operation is missing operation_id. Skipped"
                    continue

                # Check if this operation has already been executed
                if self.manifest_processor.is_operation_completed(op_id):
                    # Add the result code for the given operation id
                    self.operation_results.append(
                        swm.result(op_id,
                                   swm.SWMResult.SWM_RES_ALREADY_PROCESSED,
                                   "Operation already processed")
                        )

                    print "Software operation {} already completed. Deleted from manifest".format(op_id)
                    # Continue with the next operation
                    continue

                # Retrieve the class to instantiate for the given operation
                                

                # Instantiate an object and feed it the manifest file 
                # operation object so that the new object can initialize
                # itself correctly.
                try:
                    op_obj = software_operation.SoftwareOperation(self, op)
                except Exception as e:
                    print "Could not process softare operation {}: {}\nSkipped".format(op_id, e)
                    return False

                # Add new object to operations we need to process
                self.operations.append(op_obj)
        except Exception as e:
            print "Manifest exception: {}".format(e)
            traceback.print_exc()
            return False

        # Check that we have all mandatory fields set
        if False in [ self.update_id, self.name, self.description ]:
            print "One of update_id, name, description, or operations not set"
            return False

        return True
Пример #9
0
    def load_from_string(self, manifest_string):

        print "Manifest.load_from_string(): Called"
        try:
            manifest = json.loads(manifest_string)
        except ValueError as e:
            print "Manifest: Failed to parse JSON string: {}".format(e)
            return False

        # Retrieve top-level elements
        self.update_id = manifest.get('update_id', False)
        self.name = manifest.get('name', False)
        self.description = manifest.get('description', False)
        self.show_hmi_progress = manifest.get('show_hmi_progress', False)
        self.show_hmi_result = manifest.get('show_hmi_result', False)
        self.allow_downgrade = manifest.get('allow_downgrade', False)
        self.get_user_confirmation = manifest.get('get_user_confirmation',
                                                  False)
        self.operations = deque()
        print "Manifest.update_id:             {}".format(self.update_id)
        print "Manifest.name:                  {}".format(self.name)
        print "Manifest.description:           {}".format(self.description)
        print "Manifest.get_user_confirmation: {}".format(
            self.get_user_confirmation)
        print "Manifest.show_hmi_progress:     {}".format(
            self.show_hmi_progress)
        print "Manifest.show_hmi_result:       {}".format(self.show_hmi_result)
        print "Manifest.allow_downgrade:       {}".format(self.allow_downgrade)

        # Traverse all operations and create / load up a relevant
        # object for each one.
        try:
            for op in manifest.get('operations', []):

                # Grab opearation id.
                op_id = op.get('id', False)

                # Skip entire operation if operation_id is not defined.
                if not op_id:
                    print "Manifest operation is missing operation_id. Skipped"
                    continue

                # Check if this operation has already been executed
                if self.manifest_processor.is_operation_completed(op_id):
                    # Add the result code for the given operation id
                    self.operation_results.append(
                        swm.result(op_id, swm.SWM_RES_ALREADY_PROCESSED,
                                   "Operation already processed"))

                    print "Software operation {} already completed. Deleted from manifest".format(
                        op_id)
                    # Continue with the next operation
                    continue

                # Retrieve the class to instantiate for the given operation

                # Instantiate an object and feed it the manifest file
                # operation object so that the new object can initialize
                # itself correctly.
                try:
                    op_obj = software_operation.SoftwareOperation(self, op)
                except OperationException as e:
                    print "Could not process softare operation {}: {}\nSkipped".format(
                        op_id, e)
                    return False

                # Add new object to operations we need to process
                self.operations.append(op_obj)
        except Exception as e:
            print "Manifest exception: {}".format(e)
            traceback.print_exc()
            return False

        # Check that we have all mandatory fields set
        if False in [self.update_id, self.name, self.description]:
            print "One of update_id, name, description, or operations not set"
            return False

        return True
Пример #10
0
    def load_from_string(self, manifest_string):
        """Load manifest from string and process it
        
        Loads a manifest from a string and processes it.
        
        @param manifest_string String containing the manifest
        
        @return True if processing the manifest string was successful,
                False otherwise
        """

        logger.debug('SoftwareLoadingManager.Manifest.load_from_string(%s): Called.', manifest_string)
        try:
            manifest = json.loads(manifest_string)
        except ValueError as e:
            logger.error('SoftwareLoadingManager.Manifest.load_from_string(%s): Failed to parse JSON string: %s.', manifest_string, e)
            return False

        # Retrieve top-level elements
        self.update_id = manifest.get('updateId', False)
        self.name = manifest.get('name', False)
        self.description = manifest.get('description', False)
        self.show_hmi_progress = manifest.get('showHmiProgress', False)
        self.show_hmi_result = manifest.get('showHmiResult', False)
        self.get_user_confirmation = manifest.get('getUserConfirmation', False)
        self.operations = deque()
        logger.debug('SoftwareLoadingManager.Manifest.updateId:            %s', self.update_id)
        logger.debug('SoftwareLoadingManager.Manifest.name:                %s', self.name)
        logger.debug('SoftwareLoadingManager.Manifest.description:         %s', self.description)
        logger.debug('SoftwareLoadingManager.Manifest.getUserConfirmation: %s', self.get_user_confirmation)
        logger.debug('SoftwareLoadingManager.Manifest.showHmiProgress:     %s', self.show_hmi_progress)
        logger.debug('SoftwareLoadingManager.Manifest.showHmiResult:       %s', self.show_hmi_result)

        # Query database
        self.software_update = database.SWUpdate.getSWUpdate(self.dbstore, self.update_id, self.name)
        self.software_update.start()

        # Traverse all operations and create / load up a relevant 
        # object for each one.
        try:
            for op in manifest.get('operations', []):

                # Grab opearation id. 
                op_id = op.get('id', False)
                op_operation = op.get('operation', False)

                # Skip entire operation if operation_id is not defined.
                if not op_id:
                    logger.warning('SoftwareLoadingManager.Manifest.load_from_string(%s): Manifest operation is missing operationId. Skipped.', manifest_string)
                    continue
                    
                # Get operation from database or create a new one if id does not exist
                swo = self.software_update.getSWOperation(op_id)
                if not swo:
                    swo = self.software_update.addSWOperation(op_id, op_operation)

                # Check if this operation has already been executed
                if swo.isfinished():
                    # Add the result code for the given operation id
                    self.operation_results.append(
                        swm.result(op_id,
                                   swm.SWMResult.SWM_RES_ALREADY_PROCESSED,
                                   "Operation already processed")
                        )
                    logger.info('SoftwareLoadingManager.Manifest.load_from_string(%s): Manifest operation %s already completed. Deleted from manifest.', manifest_string, op_id)
                    # Continue with the next operation
                    continue

                # Start the operation
                swo.start()

                # Instantiate an object and feed it the manifest file 
                # operation object so that the new object can initialize
                # itself correctly.
                try:
                    op['mountPoint'] = self.mount_point
                    op_obj = software_operation.SoftwareOperation(op)
                except Exception as e:
                    logger.error('SoftwareLoadingManager.Manifest.load_from_string(%s): Could not process manifest operation: %s.\nSkipped', manifest_string, e)
                    return False

                # Add new object to operations we need to process
                self.operations.append(op_obj)
        except Exception as e:
            logger.error('SoftwareLoadingManager.Manifest.load_from_string(%s): Manifest exception: %s.', manifest_string, e)
            return False

        # Check that we have all mandatory fields set
        if False in [ self.update_id, self.name, self.description ]:
            logger.error('SoftwareLoadingManager.Manifest.load_from_string(%s): One of mandatory updateId, name, description. or operations not set.', manifest_string)
            return False

        return True