Exemple #1
0
    def finalise_protocol(self, device=None):
        """Called by Finalize action to power down and clean up the assigned
        device.
        """
        # Reboot devices that have adb serial number.
        if 'adb_serial_number' in device:
            reboot_cmd = "lxc-attach -n {0} -- adb reboot bootloader".format(
                self.lxc_name)
            self.logger.debug("%s protocol: executing '%s'", self.name,
                              reboot_cmd)
            shell = ShellCommand("%s\n" % reboot_cmd, self.system_timeout,
                                 logger=self.logger)
            # execute the command.
            shell.expect(pexpect.EOF)
            if shell.exitstatus:
                self.logger.debug("%s command exited %d: %s",
                                  reboot_cmd, shell.exitstatus,
                                  shell.readlines())

        # ShellCommand executes the destroy command
        cmd = "lxc-destroy -n {0} -f".format(self.lxc_name)
        self.logger.debug("%s protocol: executing '%s'", self.name, cmd)
        shell = ShellCommand("%s\n" % cmd, self.system_timeout,
                             logger=self.logger)
        # execute the command.
        shell.expect(pexpect.EOF)
        if shell.exitstatus:
            raise JobError("%s command exited %d: %s" % (cmd, shell.exitstatus,
                                                         shell.readlines()))
        self.logger.debug("%s protocol finalised.", self.name)
Exemple #2
0
    def finalise_protocol(self, device=None):
        """Called by Finalize action to power down and clean up the assigned
        device.
        """
        # Reboot devices that have adb serial number.
        if 'adb_serial_number' in device:
            reboot_cmd = "lxc-attach -n {0} -- adb reboot bootloader".format(
                self.lxc_name)
            self.logger.debug("%s protocol: executing '%s'", self.name,
                              reboot_cmd)
            shell = ShellCommand("%s\n" % reboot_cmd,
                                 self.system_timeout,
                                 logger=self.logger)
            # execute the command.
            shell.expect(pexpect.EOF)
            if shell.exitstatus:
                self.logger.debug("%s command exited %d: %s", reboot_cmd,
                                  shell.exitstatus, shell.readlines())

        # ShellCommand executes the destroy command
        cmd = "lxc-destroy -n {0} -f".format(self.lxc_name)
        self.logger.debug("%s protocol: executing '%s'", self.name, cmd)
        shell = ShellCommand("%s\n" % cmd,
                             self.system_timeout,
                             logger=self.logger)
        # execute the command.
        shell.expect(pexpect.EOF)
        if shell.exitstatus:
            raise JobError("%s command exited %d: %s" %
                           (cmd, shell.exitstatus, shell.readlines()))
        self.logger.debug("%s protocol finalised.", self.name)
Exemple #3
0
 def finalise_protocol(self):
     # ShellCommand executes the destroy command
     cmd = "lxc-destroy -n {0} -f".format(self.lxc_name)
     self.logger.debug("%s protocol: executing '%s'", self.name, cmd)
     shell = ShellCommand("%s\n" % cmd, self.system_timeout,
                          logger=self.logger)
     # execute the command.
     shell.expect(pexpect.EOF)
     if shell.exitstatus:
         raise JobError("%s command exited %d: %s" % (cmd, shell.exitstatus,
                                                      shell.readlines()))
     self.logger.debug("%s protocol finalised." % self.name)
Exemple #4
0
 def finalise_protocol(self, device=None):
     """Called by Finalize action to power down and clean up the assigned
     device.
     """
     # shutdown xnbd for the given device/job based in the port-number used
     try:
         self.logger.debug("%s cleanup", self.name)
         self.port = self.parameters['protocols']['lava-xnbd']['port']
         nbd_cmd = "pkill -f xnbd-server.*%s" % (self.port)
         shell = ShellCommand("%s\n" % nbd_cmd,
                              self.system_timeout,
                              logger=self.logger)
         shell.expect(pexpect.EOF)
     except Exception as e:
         self.logger.debug(str(e))
         self.logger.debug(
             "xnbd-finalize-protocol failed, but continuing anyway.")
    def finalise_protocol(self, device=None):
        """Called by Finalize action to power down and clean up the assigned
        device.
        """
        # Reboot devices to bootloader if required, based on the availability
        # of power cycle option and adb_serial_number.
        # Do not reboot to bootloader if 'reboot_to_fastboot' is set to
        # 'false' in job definition.
        if self.fastboot_reboot:
            if 'adb_serial_number' in device and hasattr(device, 'power_state'):
                if device.power_state not in ['on', 'off']:
                    reboot_cmd = "lxc-attach -n {0} -- adb reboot bootloader".format(self.lxc_name)
                    self.logger.debug("%s protocol: executing '%s'", self.name,
                                      reboot_cmd)
                    shell = ShellCommand("%s\n" % reboot_cmd,
                                         self.system_timeout,
                                         logger=self.logger)
                    # execute the command.
                    shell.expect(pexpect.EOF)
                    if shell.exitstatus:
                        self.logger.debug("%s command exited %d: %s",
                                          reboot_cmd,
                                          shell.exitstatus, shell.readlines())
        else:
            self.logger.info("%s protocol: device not rebooting to fastboot",
                             self.name)

        # Stop the container.
        self.logger.debug("%s protocol: issue stop", self.name)
        cmd = "lxc-stop -n {0} -k".format(self.lxc_name)
        shell = ShellCommand("%s\n" % cmd, self.system_timeout,
                             logger=self.logger)
        # execute the command.
        shell.expect(pexpect.EOF)
        if shell.exitstatus:
            self.logger.debug(
                "%s command exited %d: %s" % (cmd, shell.exitstatus,
                                              shell.readlines()))
        # Check if the container should persist and skip destroying it.
        if self.persistence:
            self.logger.debug("%s protocol: persistence requested",
                              self.name)
        else:
            self.logger.debug("%s protocol: destroy", self.name)
            if self.custom_lxc_path:
                abs_path = os.path.realpath(os.path.join(LXC_PATH,
                                                         self.lxc_name))
                cmd = "lxc-destroy -n {0} -f -P {1}".format(
                    self.lxc_name, os.path.dirname(abs_path))
            else:
                cmd = "lxc-destroy -n {0} -f".format(self.lxc_name)
                self.logger.debug("%s protocol: executing '%s'",
                                  self.name, cmd)
            shell = ShellCommand("%s\n" % cmd, self.system_timeout,
                                 logger=self.logger)
            # execute the command.
            shell.expect(pexpect.EOF)
            if shell.exitstatus:
                self.logger.debug(
                    "%s command exited %d: %s" % (cmd, shell.exitstatus,
                                                  shell.readlines()))
            if self.custom_lxc_path and not self.persistence:
                os.remove(os.path.join(LXC_PATH, self.lxc_name))
        self.logger.debug("%s protocol finalised.", self.name)