Best Python code snippet using autotest_python
boottool.py
Source:boottool.py  
...1305                return -11306        if bootloader == 'grub':1307            return self.boot_once_grub(entry_index)1308        elif bootloader == 'grub2':1309            return self.boot_once_grub2(entry_index)1310        elif bootloader == 'yaboot':1311            return self.boot_once_yaboot(title)1312        elif bootloader == 'elilo':1313            return self.boot_once_elilo(entry_index)1314        else:1315            self.log.error("Detected bootloader does not implement boot once")1316            return -11317    def boot_once_grub(self, entry_index):1318        '''1319        Implements the boot once feature for the grub bootloader1320        '''1321        # grubonce is a hack present in distros like OpenSUSE1322        grubonce_cmd = find_executable('grubonce')1323        if grubonce_cmd is None:1324            # XXX: check the type of default set (numeric or "saved")1325            grub_instructions = ['savedefault --default=%s --once' %1326                                 entry_index, 'quit']1327            grub_instructions_text = '\n'.join(grub_instructions)1328            grub_binary = find_executable('grub')1329            if grub_binary is None:1330                self.log.error("Could not find the 'grub' binary, aborting")1331                return -11332            p = subprocess.Popen([grub_binary, '--batch'],1333                                 stdin=subprocess.PIPE,1334                                 stdout=subprocess.PIPE,1335                                 stderr=subprocess.PIPE)1336            out, err = p.communicate(grub_instructions_text)1337            complete_out = ''1338            if out is not None:1339                complete_out = out1340            if err is not None:1341                complete_out += "\n%s" % err1342            grub_batch_err = []1343            if complete_out:1344                for l in complete_out.splitlines():1345                    if re.search('error', l, re.IGNORECASE):1346                        grub_batch_err.append(l)1347                if grub_batch_err:1348                    self.log.error("Error while running grub to set boot "1349                                   "once: %s", "\n".join(grub_batch_err))1350                    return -11351            self.log.debug('No error detected while running grub to set boot '1352                           'once')1353            return 01354        else:1355            rc = self._run_get_return([grubonce_cmd, str(entry_index)])1356            if rc:1357                self.log.error('Error running %s', grubonce_cmd)1358            else:1359                self.log.debug('No error detected while running %s',1360                               grubonce_cmd)1361            return rc1362    def boot_once_grub2(self, entry_index):1363        '''1364        Implements the boot once feature for the grub2 bootloader1365        Caveat: this assumes the default set is of type "saved", and not a1366        numeric value.1367        '''1368        default_index_re = re.compile('\s*set\s+default\s*=\s*\"+(\d+)\"+')1369        grub_reboot_names = ['grub-reboot', 'grub2-reboot']1370        grub_reboot_exec = None1371        for grub_reboot in grub_reboot_names:1372            grub_reboot_exec = find_executable(grub_reboot)1373            if grub_reboot_exec is not None:1374                break1375        if grub_reboot_exec is None:1376            self.log.error('Could not find executable among searched names: '...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
