Requires new code needing direct access to virsh_*() functions to do
something similar to 'from autotest.client.virt.virsh import *'

Signed-off-by: Chris Evich <[email protected]>
---
 client/tests/libvirt/tests/virsh_freecell.py |    3 +-
 client/tests/libvirt/tests/virsh_migrate.py  |   11 +-
 client/tests/libvirt/tests/virsh_nodeinfo.py |    3 +-
 client/tests/libvirt/tests/virsh_vcpupin.py  |    5 +-
 client/virt/libvirt_monitor.py               |  324 --------------------------
 client/virt/libvirt_vm.py                    |    4 +-
 client/virt/virsh.py                         |    4 +-
 7 files changed, 16 insertions(+), 338 deletions(-)
 delete mode 100644 client/virt/libvirt_monitor.py

diff --git a/client/tests/libvirt/tests/virsh_freecell.py 
b/client/tests/libvirt/tests/virsh_freecell.py
index 05b3705..49e1f6d 100644
--- a/client/tests/libvirt/tests/virsh_freecell.py
+++ b/client/tests/libvirt/tests/virsh_freecell.py
@@ -1,6 +1,7 @@
 import re, logging
 from autotest.client.shared import utils, error
 from autotest.client.virt import libvirt_vm
+from autotest.client.virt.virsh import *
 from autotest.client import *
 
 def run_virsh_freecell(test, params, env):
@@ -23,7 +24,7 @@ def run_virsh_freecell(test, params, env):
 
     # Run test case
     option = params.get("virsh_freecell_options")
-    cmd_result = libvirt_vm.virsh_freecell(ignore_status=True, extra=option)
+    cmd_result = virsh_freecell(ignore_status=True, extra=option)
     logging.info("Output:\n%s", cmd_result.stdout.strip())
     logging.info("Status: %d", cmd_result.exit_status)
     logging.error("Error: %s", cmd_result.stderr.strip())
diff --git a/client/tests/libvirt/tests/virsh_migrate.py 
b/client/tests/libvirt/tests/virsh_migrate.py
index 16fd298..2b97475 100644
--- a/client/tests/libvirt/tests/virsh_migrate.py
+++ b/client/tests/libvirt/tests/virsh_migrate.py
@@ -1,6 +1,7 @@
 import logging, os, re, time, shutil, codecs
 from autotest.client.shared import utils, error
 from autotest.client.virt import libvirt_vm, virt_utils, virt_test_utils
+from autotest.client.virt.virsh import *
 
 def run_virsh_migrate(test, params, env):
     """
@@ -24,7 +25,7 @@ def run_virsh_migrate(test, params, env):
         """
         logging.info("Cleaning up VMs on %s" % vm.connect_uri)
         try:
-            if libvirt_vm.virsh_domain_exists(vm.name, vm.connect_uri):
+            if virsh_domain_exists(vm.name, vm.connect_uri):
                 vm_state = vm.state()
                 if vm_state == "paused":
                     vm.resume()
@@ -78,7 +79,7 @@ def run_virsh_migrate(test, params, env):
 
     vm.connect_uri = params.get("connect_uri", "default")
     if vm.connect_uri == 'default':
-        vm.connect_uri = libvirt_vm.virsh_uri()
+        vm.connect_uri = virsh_uri()
 
     src_uri = vm.connect_uri
     dest_uri = params.get("virsh_migrate_desturi")
@@ -190,7 +191,7 @@ def run_virsh_migrate(test, params, env):
         if options.count("undefinesource") or extra.count("undefinesource"):
             logging.info("Verifying <virsh domstate> DOES return an error."
                          "%s should not exist on %s." % (vm_name, src_uri))
-            if libvirt_vm.virsh_domain_exists(vm_name, src_uri):
+            if virsh_domain_exists(vm_name, src_uri):
                 check_src_undefine = False
 
         # Checking for --dname.
@@ -198,7 +199,7 @@ def run_virsh_migrate(test, params, env):
         check_dest_dname = True
         if options.count("dname") or extra.count("dname"):
             dname = extra.split()[1].strip()
-            if not libvirt_vm.virsh_domain_exists(dname, dest_uri):
+            if not virsh_domain_exists(dname, dest_uri):
                 check_dest_dname = False
 
         # Checking for --xml.
@@ -242,7 +243,7 @@ def run_virsh_migrate(test, params, env):
 
     # Recover source (just in case).
     # vm.connect_uri has been set back to src_uri in cleanup_dest().
-    if not libvirt_vm.virsh_domain_exists(vm_name, src_uri):
+    if not virsh_domain_exists(vm_name, src_uri):
         vm.define(vm_xmlfile_bak)
     else:
         #if not vm.shutdown():
diff --git a/client/tests/libvirt/tests/virsh_nodeinfo.py 
b/client/tests/libvirt/tests/virsh_nodeinfo.py
index e5c9900..ecc4644 100644
--- a/client/tests/libvirt/tests/virsh_nodeinfo.py
+++ b/client/tests/libvirt/tests/virsh_nodeinfo.py
@@ -1,6 +1,7 @@
 import re, logging
 from autotest.client.shared import utils, error
 from autotest.client.virt import libvirt_vm
+from autotest.client.virt.virsh import *
 from autotest.client import *
 
 def run_virsh_nodeinfo(test, params, env):
@@ -80,7 +81,7 @@ def run_virsh_nodeinfo(test, params, env):
 
     # Run test case
     option = params.get("virsh_node_options")
-    cmd_result = libvirt_vm.virsh_nodeinfo(ignore_status=True, extra=option)
+    cmd_result = virsh_nodeinfo(ignore_status=True, extra=option)
     logging.info("Output:\n%s", cmd_result.stdout.strip())
     logging.info("Status: %d", cmd_result.exit_status)
     logging.error("Error: %s", cmd_result.stderr.strip())
diff --git a/client/tests/libvirt/tests/virsh_vcpupin.py 
b/client/tests/libvirt/tests/virsh_vcpupin.py
index 4638881..80eaf4a 100644
--- a/client/tests/libvirt/tests/virsh_vcpupin.py
+++ b/client/tests/libvirt/tests/virsh_vcpupin.py
@@ -1,6 +1,7 @@
 import logging, re, os, commands, string, math
 from autotest.client.shared import utils, error
 from autotest.client.virt import libvirt_vm
+from autotest.client.virt.virsh import *
 from autotest.client import *
 
 def run_virsh_vcpupin(test, params, env):
@@ -28,7 +29,7 @@ def run_virsh_vcpupin(test, params, env):
         @param: vcpu: vcpu number for which the affinity is required
         """
 
-        output = libvirt_vm.virsh_vcpuinfo(domname)
+        output = virsh_vcpuinfo(domname)
         cmd = re.findall('[^Affinity:][-y]+', str(output))
         total_affinity = cmd[vcpu].lstrip()
         actual_affinity = list(total_affinity)
@@ -106,7 +107,7 @@ def run_virsh_vcpupin(test, params, env):
     host_cpu_count = utils.count_cpus()
 
     # Get the guest vcpu count
-    guest_vcpu_count = libvirt_vm.virsh_vcpucount_live(vm_name)
+    guest_vcpu_count = virsh_vcpucount_live(vm_name)
 
     # Run test case
     for vcpu in range(int(guest_vcpu_count)):
diff --git a/client/virt/libvirt_monitor.py b/client/virt/libvirt_monitor.py
deleted file mode 100644
index 5b20e5d..0000000
--- a/client/virt/libvirt_monitor.py
+++ /dev/null
@@ -1,324 +0,0 @@
-import re, tempfile, xml.dom.minidom, logging
-from autotest.client import utils
-import aexpect, virt_remote
-
-
-class VirshMonitor:
-    """
-    Wraps "Virsh monitor" commands.
-    """
-
-    LOGIN_TIMEOUT = 10
-
-    def __init__(self, virsh_exec, name, vmname, password=None,
-                 prompt=None, hostname='localhost', driver=None, username=None,
-                 linesep="\\n"):
-        """
-        Connect to the hypervisor and get virsh prompt.
-
-        @param virsh_exec: Virsh executable
-        @param name: Monitor identifier (a string)
-        @param vmname: VM name
-        @param password: Hypervisor user password
-        @param prompt: Virsh prompt
-        @param hostname: Hypervisor IP
-        @param driver: Hypervisor driver type
-        @param username: Hypervisor  username
-        @param linesep: The line separator to use when sending lines
-                (e.g. '\\n' or '\\r\\n')
-        """
-        self.virsh_exec = virsh_exec
-        self.name = name
-        self.vmname = vmname
-        self.password = password
-        self.prompt = prompt
-        self.hostname = hostname
-        self.driver = driver
-        self.username = username
-        self.session = self.login()
-        self.virsh_cmd = {"help":"help", "quit":"destroy " + self.vmname,
-                           "stop":"suspend", "cont":"resume"}
-        self.drive_map = {}
-        self.network_info = []
-        self.disk_info = []
-        self._parse_domxml()
-
-
-    def __del__(self):
-        self.session.sendline("quit")
-
-
-    def __getstate__(self):
-        pass
-
-
-    def __setstate__(self, state):
-        pass
-
-
-    def __getinitargs__(self):
-        # Save some information when pickling -- will be passed to the
-        # constructor upon unpickling
-        return (self.name, self.vmname, self.password, self.prompt,
-                self.hostname, self.driver, self.username)
-
-
-    def login(self, timeout=LOGIN_TIMEOUT):
-        """
-        Log into the hypervisor using required URIs .
-
-        @timeout: Time in seconds that we will wait before giving up on logging
-                into the host.
-        @return: A ShellSession object.
-        """
-        if self.driver is None:
-            uri = utils.system_output('%s uri' % self.virsh_exec)
-        else:
-            uri = "%s+ssh://%s@%s/system" % (self.driver, self.username,
-                                             self.host)
-
-        command = "%s --connect  %s" % (self.virsh_exec, uri)
-
-        session = aexpect.ShellSession(command, linesep=self.linesep,
-                                       prompt=self.prompt)
-
-        if self.username is not None:
-            try:
-                virt_remote._remote_login(session, self.username, 
self.password,
-                                          self.prompt, timeout)
-            except aexpect.ShellError:
-                session.close()
-                session = None
-
-        return session
-
-
-    def _parse_domxml(self):
-        self.session.cmd_output("\n")
-        domxml = self.session.cmd_output("dumpxml %s \n" % self.vmname)
-        self._parse_dev(domxml)
-
-
-    def _parse_dev(self, domxml):
-        dom = xml.dom.minidom.parseString(domxml)
-        self.network_info = []
-        for elems in dom.getElementsByTagName('interface'):
-            self.network_info.append(elems.toxml())
-
-        self.disk_info = []
-        for elems in dom.getElementsByTagName('disk'):
-            self.disk_info.append(elems.toxml())
-
-
-    def verify_responsive(self):
-        """
-        Make sure the monitor is responsive by sending a command.
-        """
-        self.cmd("help")
-
-
-    def cmd(self, command):
-        """
-        Send command to the monitor.
-
-        @param command: Command to send to the monitor
-        @return: Output received from the monitor
-        """
-        def dev_add(command):
-            """
-            Create the xml file for the device to be attached
-            """
-            parm_dic = dict(re.findall("(id|driver|mac|drive)=([^,\s]+)",
-                                         command))
-            self.session.cmd_output("\n")
-            if parm_dic.has_key("drive"):
-                self.drive_map[parm_dic["drive"]]["driver"] = parm_dic\
-                                                              ["driver"]
-                self.drive_map[parm_dic["drive"]]["device_id"] = parm_dic["id"]
-                self.drive_map[parm_dic["drive"]]["dev"] = "vd" + str(len(
-                                                              self.drive_map))
-                doc = xml.dom.minidom.Document()
-                topelem = doc.createElement("disk")
-                topelem.setAttribute('device', 'disk')
-                topelem.setAttribute('type', 'file')
-                doc.appendChild(topelem)
-                chld_elem = doc.createElement("driver")
-                chld_elem.setAttribute('name', "qemu")
-                topelem.appendChild(chld_elem)
-                chld_elem = doc.createElement("source")
-                chld_elem.setAttribute('file', self.drive_map[parm_dic["drive"]
-                                                             ]["file"])
-                topelem.appendChild(chld_elem)
-                chld_elem = doc.createElement("target")
-                if "virtio-blk-pci" in command:
-                    self.drive_map[parm_dic["drive"]]["driver"] = "virtio"
-                chld_elem.setAttribute('bus', self.drive_map[parm_dic["drive"]
-                                                            ]["driver"])
-                chld_elem.setAttribute('dev', self.drive_map[parm_dic["drive"]
-                                                            ]["dev"])
-                topelem.appendChild(chld_elem)
-            else:
-                netpool_lst = self.session.cmd_output("net-list"
-                                                               ).split('\n')
-                netpool = []
-                for r in range(2, len(netpool_lst) - 2):
-                    netpool.append(netpool_lst[r].split()[0])
-
-                doc = xml.dom.minidom.Document()
-                topelem = doc.createElement("interface")
-                doc.appendChild(topelem)
-
-                chld_elem = doc.createElement("source")
-                chld_elem.setAttribute('network', netpool[-1])
-                topelem.appendChild(chld_elem)
-                if parm_dic.has_key("mac"):
-                    mac = parm_dic.get("mac")
-                    chld_elem = doc.createElement("mac")
-                    chld_elem.setAttribute('address', mac)
-                    topelem.appendChild(chld_elem)
-                if not parm_dic.has_key("driver"):
-                    model = re.findall("device_add ([^,\s]+)", command)[0]
-                else:
-                    model = parm_dic.get("driver")
-                if model == "virtio-net-pci":
-                    model = "virtio"
-                chld_elem = doc.createElement("model")
-                chld_elem.setAttribute('type', model)
-                topelem.appendChild(chld_elem)
-                if parm_dic.has_key("id"):
-                    id = parm_dic.get("id")
-                    chld_elem = doc.createElement("target")
-                    chld_elem.setAttribute('dev', id)
-                    topelem.appendChild(chld_elem)
-
-            tmp_xml = doc.toxml()
-            devfl = tempfile.mktemp(prefix='dev')
-            devfd = open(devfl, 'w')
-            devfd.write(tmp_xml)
-            devfd.close()
-            return devfl
-
-        def net_del(command):
-            """
-            Create the xml file for the device to be detached
-            """
-            xml_str = ""
-            id = re.findall("device_del ([^,\s]+)", command)[0]
-            for i in range(len(self.network_info)):
-                if id in str(self.network_info[i]):
-                    xml_str = str(self.network_info[i])
-            for i in self.drive_map:
-                if id in str(self.drive_map[i]):
-                    map_key = self.drive_map[i]["dev"]
-                    for i in range(len(self.disk_info)):
-                        if map_key in str(self.disk_info[i]):
-                            xml_str = str(self.disk_info[i])
-            devfl = tempfile.mktemp(prefix='dev')
-            devfd = open(devfl, 'w')
-            devfd.write(xml_str)
-            devfd.close()
-            return devfl
-
-        if "device_add ?" in command:
-            return "virtio-net-pci virtio-blk-pci e1000 rtl8139"
-
-        if "?" in command:
-            output = "\nhelp|? [cmd]\ndevice_add\ndevice_del\ndrive_add"\
-                                                "\n__com.redhat_drive_add"
-            return output
-
-        if "redhat_drive" in command:
-            drive_dic = dict(re.findall("(file|id)=([^,\s]+)", command))
-            self.drive_map[drive_dic["id"]] = drive_dic
-            return
-
-        if "netdev_add" in command:
-            id = re.findall("id=(.*?),", command)[0]
-            net_str = " peer=%s" % id
-            self.network_info[id] = net_str
-            return
-
-        if "device_add"  in command:
-            devfile = dev_add(command)
-            xml_handle = open(devfile)
-            xml_pars = xml.dom.minidom.parse(xml_handle)
-            self.session.cmd_output("attach-device %s %s" %
-                                    (self.vmname, devfile))
-            domxml = self.session.cmd_output("dumpxml %s \n" % self.vmname)
-            self._parse_dev(domxml)
-            return
-
-        if "device_del" in command:
-            devfile = net_del(command)
-            xml_handle = open(devfile)
-            xml_pars = xml.dom.minidom.parse(xml_handle)
-            self.session.cmd_output("detach-device %s %s" %
-                                    (self.vmname, devfile))
-            domxml = self.session.cmd_output("dumpxml %s \n" % self.vmname)
-            self._parse_dev(domxml)
-            return
-
-        if "balloon" in command:
-            new_mem = re.findall("balloon\s+(\d+)", command)[0]
-            new_mem = str(int(new_mem) * 1024)
-            output = self.session.cmd_output("setmem  %s %s" %
-                                                      (self.vmname, new_mem))
-            return
-
-        if "system_reset" in command:
-            self.session.cmd_output("destroy %s" % self.vmname)
-            self.session.cmd_output("start %s" % self.vmname)
-            return
-
-        data = self.session.cmd_output(" %s \n" % self.virsh_cmd.get(
-                                                            command, command))
-        return data
-
-
-    def is_responsive(self):
-        """
-        Return True if the monitor is responsive.
-        """
-        return True
-
-
-    def quit(self):
-        """
-        Send "quit" without waiting for output.
-        """
-        self.cmd("quit")
-
-
-    def screendump(self, filename, debug=True):
-        """
-        Request a screendump.
-
-        @param filename: Location for the screendump
-        @return: The command's output
-        """
-        if debug:
-            logging.debug("Requesting screendump %s" % filename)
-        return self.cmd("screenshot %s" % filename)
-
-
-    def info(self, what):
-        """
-        Request info about something and return the output.
-        """
-        if "network" in what:
-            return self.network_info
-
-        if "pci" in what:
-            domxml = self.session.cmd_output("dumpxml %s \n" %
-                                                       self.vmname)
-            self._parse_dev(domxml)
-            return str(self.network_info) + str(self.drive_map)
-
-        if "balloon" in what:
-            self.session.cmd_output("\n")
-            netpool_lst = self.session.cmd_output("dominfo %s" %
-                                                            self.vmname)
-            return str(int(re.findall("Used memory:\s+(\d+)", netpool_lst)
-                                       [0]) / 1024)
-
-        return self.cmd("info %s" % what)
diff --git a/client/virt/libvirt_vm.py b/client/virt/libvirt_vm.py
index 96f2801..c45dd46 100644
--- a/client/virt/libvirt_vm.py
+++ b/client/virt/libvirt_vm.py
@@ -8,8 +8,8 @@ import time, os, logging, fcntl, re, commands, shutil, 
urlparse, tempfile
 from autotest.client.shared import error
 from autotest.client import utils, os_dep
 from xml.dom import minidom
-import virt_utils, virt_vm, virt_storage, aexpect, virt_remote, virsh
-
+import virt_utils, virt_vm, virt_storage, aexpect, virt_remote
+from virsh import *
 
 def libvirtd_restart():
     """
diff --git a/client/virt/virsh.py b/client/virt/virsh.py
index ba89b17..8792aa7 100644
--- a/client/virt/virsh.py
+++ b/client/virt/virsh.py
@@ -4,11 +4,9 @@ Libvirt utility function virsh interface.
 @copyright: 2012 Red Hat Inc.
 """
 
-import time, os, logging, fcntl, re, commands, shutil, urlparse, tempfile
+import time, logging
 from autotest.client.shared import error
 from autotest.client import utils, os_dep
-from xml.dom import minidom
-import aexpect, virt_remote
 
 DEBUG = False
 try:
-- 
1.7.1

_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

Reply via email to