[Libvirt-cim] [PATCH 1 of 5] [TEST] Add destroy_diskpool()
Deepti B Kalakeri
deeptik at linux.vnet.ibm.com
Mon Sep 8 12:20:59 UTC 2008
Kaitlin Rupert wrote:
> # HG changeset patch
> # User Kaitlin Rupert <karupert at us.ibm.com>
> # Date 1220559239 25200
> # Node ID 4b80cfce163204588ff4195debe8fdbe94209a0c
> # Parent 8abcd820b6b37e5fbe8ccc30734cefa908dfab78
> [TEST] Add destroy_diskpool()...
>
> Also:
>
> Modify create_diskpool_conf() to take a disk pool name.
> Give default_pool_name a unique name.
> Modify create_diskpool() so that it will use the existing diskpool only if specified. Also, have it check to see if the specified diskpool exists before attempting to create it.
>
> Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>
>
> diff -r 8abcd820b6b3 -r 4b80cfce1632 suites/libvirt-cim/lib/XenKvmLib/common_util.py
> --- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Fri Sep 05 02:47:24 2008 -0700
> +++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Thu Sep 04 13:13:59 2008 -0700
> @@ -39,9 +39,8 @@
> from XenKvmLib.vxml import PoolXML, NetXML
> from XenKvmLib.enumclass import getInstance
> from VirtLib import utils
> -from XenKvmLib import const
> +from XenKvmLib.const import default_pool_name, default_network_name
>
> -test_dpath = "foo"
> disk_file = '/etc/libvirt/diskpool.conf'
>
> back_disk_file = disk_file + "." + "backup"
> @@ -308,7 +307,7 @@
> logger.info("Disk conf file : %s", disk_file)
> try:
> f = open(disk_file, 'w')
> - f.write('%s %s' % (test_dpath, '/'))
> + f.write('%s %s' % (default_pool_name, '/'))
> f.close()
> except Exception,detail:
> logger.error("Exception: %s", detail)
> @@ -354,19 +353,28 @@
>
> return conf_file()
>
> -def create_diskpool(server, virt='KVM'):
> +def create_diskpool(server, virt='KVM', dpool=default_pool_name,
> + useExisting=False):
> status = PASS
> dpoolname = None
> try:
> - dpool_list = diskpool_list(server, virt='KVM')
> - if len(dpool_list) > 0:
> - dpoolname=dpool_list[0]
> - else:
> - diskxml = PoolXML(server, virt=virt)
> + if useExisting == True:
> + dpool_list = diskpool_list(server, virt='KVM')
> + if len(dpool_list) > 0:
> + dpoolname=dpool_list[0]
> +
> + if dpoolname == None:
> + cmd = "virsh -c %s pool-list --all | grep %s" % \
> + (utils.virt2uri(virt), dpool)
> + ret, out = utils.run_remote(server, cmd)
> + if out != "":
> + logger.error("Disk pool with name '%s' already exists", dpool)
> + return FAIL, "Unknown"
>
If the diskpool cinmtest-diskpool already exist on the machine then the
tc execution wont proceed unless we delete manually and then re-run the tc.
I think we should not pass FAIL as status value, instead supply PASS as
the status value.
The same comment applies for network pool also.
> +
> + diskxml = PoolXML(server, virt=virt, poolname=dpool)
> ret = diskxml.create_vpool()
> if not ret:
> - logger.error('Failed to create the disk pool "%s"',
> - dpoolname)
> + logger.error('Failed to create the disk pool "%s"', dpool)
> status = FAIL
> else:
> dpoolname=diskxml.xml_get_diskpool_name()
> @@ -375,20 +383,40 @@
> status=FAIL
> return status, dpoolname
>
> -def create_diskpool_conf(server, virt):
> +def create_diskpool_conf(server, virt, dpool=default_pool_name):
> libvirt_version = virsh_version(server, virt)
> if libvirt_version >= '0.4.1':
> - status, dpoolname = create_diskpool(server, virt=virt)
> + status, dpoolname = create_diskpool(server, virt, dpool)
> diskid = "%s/%s" % ("DiskPool", dpoolname)
> else:
> status = create_diskpool_file()
> - diskid = "%s/%s" % ("DiskPool", test_dpath)
> + diskid = "DiskPool/%s" % default_pool_name
>
> return status, diskid
>
> +def destroy_diskpool(server, virt, dpool):
> + libvirt_version = virsh_version(server, virt)
> + if libvirt_version >= '0.4.1':
> + if dpool == None:
> + logger.error("No disk pool specified")
> + return FAIL
> +
> + pool_xml = PoolXML(server, virt=virt, poolname=dpool)
> + ret = pool_xml.destroy_vpool()
> + if not ret:
> + logger.error("Failed to destroy disk pool '%s'", dpool)
> + return FAIL
> +
> + else:
> + status = cleanup_restore(server, virt)
> + if status != PASS:
> + logger.error("Failed to restore original disk pool file")
> + return status
> +
> + return PASS
>
> def create_netpool_conf(server, virt, use_existing=False,
> - net_name=const.default_network_name):
> + net_name=default_network_name):
> status = PASS
> test_network = None
> try:
> diff -r 8abcd820b6b3 -r 4b80cfce1632 suites/libvirt-cim/lib/XenKvmLib/const.py
> --- a/suites/libvirt-cim/lib/XenKvmLib/const.py Fri Sep 05 02:47:24 2008 -0700
> +++ b/suites/libvirt-cim/lib/XenKvmLib/const.py Thu Sep 04 13:13:59 2008 -0700
> @@ -37,7 +37,7 @@
> default_net_type = 'network'
>
> #vxml.PoolXML
> -default_pool_name = 'testpool'
> +default_pool_name = 'cimtest-diskpool'
>
> # vxml.VirtXML
> default_domname = 'domU1'
> diff -r 8abcd820b6b3 -r 4b80cfce1632 suites/libvirt-cim/lib/XenKvmLib/vxml.py
> --- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py Fri Sep 05 02:47:24 2008 -0700
> +++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py Thu Sep 04 13:13:59 2008 -0700
> @@ -145,14 +145,12 @@
> self.vuri = 'lxc:///system'
>
> def run(self, ip, vcmd, param):
> - file_arg_cmds = ['define', 'create', 'net-create', 'pool-create', 'pool-destroy']
> + file_arg_cmds = ['define', 'create', 'net-create', 'pool-create']
> if vcmd in file_arg_cmds:
> ntf = tempfile.NamedTemporaryFile('w')
> ntf.write(param)
> ntf.flush()
> name = ntf.name
> - elif vcmd == 'pool-destroy':
> - name = param
> elif param is None:
> name = ""
> else:
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim
>
More information about the Libvirt-cim
mailing list