Пример #1
0
    def _dumpxml(name, to_file="", **dargs):
        """
        Get a xml from name.
        """
        if not name:
            cmd = "virsh dumpxml %s" % name
            stdout = "error: command 'dumpxml' requires <domain> option"
            stderr = stdout
            exit_status = 1
            result = utils.CmdResult(cmd, stdout, stderr, exit_status)
            raise error.CmdError(cmd, result,
                                 "Virsh Command returned non-zero exit status")

        file_path = os.path.join(LibvirtXMLTestBase.__doms_dir__,
                                 '%s.xml' % name)
        if os.path.exists(file_path):
            xml_file = open(file_path, 'r')
            domain_xml = xml_file.read()
        else:
            xml_file = open(file_path, 'w')
            domain_xml = LibvirtXMLTestBase.__domain_xml__ % (name,
                                                              LibvirtXMLTestBase._domuuid(None))
            xml_file.write(domain_xml)
        xml_file.close()

        cmd = "virsh dumpxml %s" % name
        stdout = domain_xml
        stderr = ""
        exit_status = 0
        return utils.CmdResult(cmd, stdout, stderr, exit_status)
Пример #2
0
    def run(self, command, timeout=60, ignore_status=False):
        """
        Method to provide a utils.run-like interface to execute command on
        remote host or guest.

        :param timeout: Total time duration to wait for command return.
        :param ignore_status: If ignore_status=True, do not raise an exception,
                              no matter what the exit code of the command is.
                              Else, raise CmdError if exit code of command is not
                              zero.
        """
        # Redirect the stdout and stderr to file, Deviding error message
        # from output, and taking off the color of output. To return the same
        # result with utils.run() function.
        command = "%s 1>%s 2>%s" % (command, self.stdout_pipe, self.stderr_pipe)
        status, _ = self.session.cmd_status_output(command, timeout=timeout)
        output = self.session.cmd_output("cat %s;rm -f %s" %
                                         (self.stdout_pipe, self.stdout_pipe))
        errput = self.session.cmd_output("cat %s;rm -f %s" %
                                         (self.stderr_pipe, self.stderr_pipe))
        cmd_result = utils.CmdResult(command=command, exit_status=status,
                                     stdout=output, stderr=errput)
        if (status and (not ignore_status)):
            raise error.CmdError(command, cmd_result)
        return cmd_result
Пример #3
0
 def _nodedev_dumpxml(name, options="", to_file=None, **dargs):
     # Must mirror virsh.nodedev_dumpxml() API but can't test this option
     if options != "":
         raise ValueError('Dummy virsh for testing does not support options'
                          ' parameter')
     if to_file is not None:
         raise ValueError('Dummy virsh for testing does not support to_file'
                          ' parameter')
     if name is not 'pci_0000_00_00_0':
         raise ValueError('Dummy virsh for testing only support '
                          ' device name pci_0000_00_00_0')
     xml = ("<device>"
            "<name>pci_0000_00_00_0</name>"
            "<path>/sys/devices/pci0000:00/0000:00:00.0</path>"
            "<parent>computer</parent>"
            "<capability type='pci'>"
            "<domain>0</domain>"
            "<bus>0</bus>"
            "<slot>0</slot>"
            "<function>0</function>"
            "<product id='0x25c0'>5000X Chipset Memory Controller Hub</product>"
            "<vendor id='0x8086'>Intel Corporation</vendor>"
            "</capability>"
            "</device>")
     return utils.CmdResult('virsh nodedev-dumpxml pci_0000_00_00_0',
                            xml, '', 0)
Пример #4
0
 def cmd_result(self, cmd, ignore_status=False):
     """Mimic utils.run()"""
     exit_status, stdout = self.cmd_status_output(cmd)
     stderr = ''  # no way to retrieve this separately
     result = utils.CmdResult(cmd, stdout, stderr, exit_status)
     if not ignore_status and exit_status:
         raise error.CmdError(
             cmd, result, "Guestfish Command returned non-zero exit status")
     return result
Пример #5
0
 def cmdresult(self):
     # FIXME: Can't seem to assign to parent-class property
     #        using private attribute instead, uggg.
     if self._async_job is None:
         return None
     else:
         self._cmdresult = utils.CmdResult(command=self.command,
                                           stdout=self.stdout,
                                           stderr=self.stderr,
                                           exit_status=self.exit_status,
                                           duration=self.duration)
     return super(AsyncDockerCmd, self).cmdresult
Пример #6
0
    def cmdresult(self, value):
        """
        Allow subclasses ability to update the private cache attribute

        :param value:  New CmdResult instance to set (will be copied)
        """

        self._cmdresult = utils.CmdResult(command=value.command,
                                          stdout=value.stdout,
                                          stderr=value.stderr,
                                          exit_status=value.exit_status,
                                          duration=value.duration)
        return self.cmdresult