[PATCH 0 of 2] [TEST] VSMS: ModifyResourceSettings to change cdrom media
by Eduardo Lima (Etrunko)
This series introduces a new test case which covers a requirement to change the
media in the CDROM using libvirt-cim, done via a ModifyResourceSettings call.
Also changes the default domain created by cimtest to include a cdrom device.
Signed-off-by: Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
suites/libvirt-cim/cimtest/VirtualSystemManagementService/32_modify_cdrom_media.py | 221 ++++++++++
suites/libvirt-cim/lib/XenKvmLib/const.py | 1 +
suites/libvirt-cim/lib/XenKvmLib/vxml.py | 15 +
3 files changed, 237 insertions(+), 0 deletions(-)
13 years
[PATCH] #2 [TEST] 31_unset_netrasd.py: new test for VirtualSystemManagementService
by Eduardo Lima (Etrunko)
suites/libvirt-cim/cimtest/VirtualSystemManagementService/31_unset_netrasd.py | 193 ++++++++++
1 files changed, 193 insertions(+), 0 deletions(-)
# HG changeset patch
# User Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
# Date 1317153134 10800
# Node ID eac4909ac68adc28cad9cb6389ea93a053b23aec
# Parent 83921669cae17a4f0a18bb440ebec01de1a3e691
[TEST] 31_unset_netrasd.py: new test for VirtualSystemManagementService
This test case covers a recent bug found in Pegasus which makes impossible for
libvirt-cim to set a property values if the value is an empty string via a
ModifyResourceSettings call.
Link to Pegasus bug follows:
http://bugzilla.openpegasus.org/show_bug.cgi?id=9053
Signed-off-by: Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/31_unset_netrasd.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/31_unset_netrasd.py
new file mode 100755
--- /dev/null
+++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/31_unset_netrasd.py
@@ -0,0 +1,193 @@
+#!/usr/bin/env python
+
+#
+# Copyright 2011 IBM Corp.
+#
+# Authors:
+# Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+#
+# ModifyResourceSettings call to set/unset NetRASD ResourceType property
+#
+
+import sys
+import pywbem
+
+from CimTest.ReturnCodes import PASS, FAIL
+from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS
+from XenKvmLib.const import do_main
+from XenKvmLib.classes import get_typed_class
+from XenKvmLib.vxml import get_class
+
+supported = ['Xen', 'KVM', 'XenFV', 'LXC']
+domain = None
+
+class CIMDomain(object):
+
+ def __init__(self, name, virt, server):
+ self.name = name
+ self.server = server
+ self._domain = get_class(virt)(name)
+ #__init__
+
+ def define(self):
+ return self._domain.cim_define(self.server)
+ # define
+
+ def undefine(self):
+ return self._domain.undefine(self.server)
+ # undefine
+
+ def destroy(self):
+ return self._domain.cim_destroy(self.server)
+ #destroy
+# CIMDomain
+
+
+def resource_settings(inst, virt, resource_subtype):
+ return """
+instance of %s {
+ InstanceID="%s";
+ ResourceType=%d;
+ Address="%s";
+ VirtualQuantityUnits="%s";
+ NetworkType="%s";
+ NetworkName="%s";
+ ResourceSubType="%s";
+};""" % (get_typed_class(virt, "NetResourceAllocationSettingData"),
+ inst["InstanceID"],
+ inst["ResourceType"],
+ inst["Address"],
+ inst["VirtualQuantityUnits"],
+ inst["NetworkType"],
+ inst["NetworkName"],
+ resource_subtype)
+# resource_settings()
+
+
+@do_main(supported)
+def main():
+ # init
+ options = main.options
+ server = options.ip
+ virt = options.virt
+
+ server_url = "http://%s" % server
+ cim = pywbem.WBEMConnection(server_url, (CIM_USER, CIM_PASS), CIM_NS)
+
+ _class = get_typed_class(virt, "VirtualSystemManagementService")
+ sys_mgmt_service = cim.EnumerateInstanceNames(_class)[0]
+
+ # Create new domain
+ global domain
+ domain = CIMDomain("cimtest_unset_netrasd", virt, server)
+ if not domain.define():
+ logger.error("Error defining test domain")
+ return FAIL
+
+ # ein KVM_ComputerSystem
+ _class = get_typed_class(virt, "ComputerSystem")
+ computer_system_names = [i for i in cim.EnumerateInstanceNames(_class) if i["Name"] == domain.name]
+
+ logger.info("ComputerSystem Names\n%s", computer_system_names)
+
+ if not computer_system_names:
+ logger.info("Host has no domains defined")
+ return SKIP
+
+ # ain -ac KVM_SystemDevice -arc KVM_NetworkPort <KVM_ComputerSytem Name>
+ a_class = get_typed_class(virt, "SystemDevice")
+ r_class = get_typed_class(virt, "NetworkPort")
+ network_port_names = []
+
+ for inst_name in computer_system_names:
+ assoc_names = cim.AssociatorNames(inst_name, AssocClass=a_class, ResultClass=r_class)
+ network_port_names.extend(assoc_names)
+
+ logger.info("NetworkPort Names\n%s", network_port_names)
+
+ if not network_port_names:
+ logger.info("No NetworkPort instances returned")
+ return XFAIL
+
+ # ai -arc KVM_NetResourceAllocationSettingData <KVM_NetworkPort Name>
+ r_class = get_typed_class(virt, "NetResourceAllocationSettingData")
+ net_rasd_names = []
+
+ for inst_name in network_port_names:
+ assoc_names = cim.AssociatorNames(inst_name, ResultClass=r_class)
+ net_rasd_names.extend(assoc_names)
+
+ logger.info("NetRASD names\n%s", net_rasd_names)
+
+ if not net_rasd_names:
+ logger.info("No NetRASD instances returned")
+ return XFAIL
+
+ for subtype in ["virtio", "",]:
+ logger.info("Setting ResourceSubType to '%s'", subtype)
+
+ modified_net_rasd_names = []
+
+ for inst_name in net_rasd_names:
+ # Get current instance data
+ inst = cim.GetInstance(inst_name)
+ cur_id = inst["InstanceID"]
+ cur_subtype = inst["ResourceSubType"]
+ logger.info("Current ResourceSubType of %s: '%s'", cur_id, cur_subtype)
+
+ # Invoke ModifyResourceSettings
+ val = resource_settings(inst, virt, subtype)
+ ret = cim.InvokeMethod("ModifyResourceSettings", sys_mgmt_service, **{"ResourceSettings": [val,],})
+
+ if ret[0]:
+ logger.error("ERROR Setting ResourceSubtype to '%s': %s", subtype, ret)
+ return FAIL
+
+ modified_net_rasd_names.extend(ret[1]["ResultingResourceSettings"])
+
+ # Get modified instance data
+ inst = cim.GetInstance(ret[1]["ResultingResourceSettings"][0])
+ new_id = inst["InstanceID"]
+ new_subtype = inst["ResourceSubType"]
+
+ logger.info("Modified ResourceSubType of %s: '%s'", new_id, new_subtype)
+
+ if cur_id != new_id:
+ logger.error("Current '%s' and new '%s' InstanceID differ", cur_id, new_id)
+ return FAIL
+
+ if new_subtype != subtype:
+ logger.error("Current '%s' and expected '%s' ResourceSubType differ", new_subtype, subtype)
+ return FAIL
+ # for inst_name...
+
+ net_rasd_names = modified_net_rasd_names
+ #for subtype...
+
+ return PASS
+#main()
+
+if __name__ == "__main__":
+ ret = main()
+
+ if domain:
+ domain.destroy()
+ domain.undefine()
+
+ sys.exit(ret)
13 years
[PATCH] VirtualSystemManagementService: Avoid extra connection to libvirt
by Eduardo Lima (Etrunko)
src/Virt_VirtualSystemManagementService.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
# HG changeset patch
# User Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
# Date 1317242639 10800
# Node ID e02b7fef37d7f1f6a18d68991dc1409eef8905ec
# Parent 942e9fa22bcb2681884cb39e1dcfc459c67ce197
VirtualSystemManagementService: Avoid extra connection to libvirt
Function update_device_info() has been called in after a creating a connection
to libvirt, while the itself creates a new connection. Moving the function call
a few lines above adresses this issue.
Signed-off-by: Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
diff --git a/src/Virt_VirtualSystemManagementService.c b/src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c
+++ b/src/Virt_VirtualSystemManagementService.c
@@ -2331,6 +2331,8 @@
return s;
}
+ update_dominfo(dominfo, refcn);
+
conn = connect_by_classname(_BROKER, refcn, &s);
if (conn == NULL) {
CU_DEBUG("Failed to connect");
@@ -2347,8 +2349,6 @@
goto out;
}
- update_dominfo(dominfo, refcn);
-
if (!domain_online(dom)) {
CU_DEBUG("VS `%s' not online; skipping dynamic update",
dominfo->name);
13 years
[PATCH] (#2) Fix the problem that libvirt-cim can't find cdrom device that do not have disk
by Wayne Xia
# HG changeset patch
# User Wayne Xia <xiawenc(a)linux.vnet.ibm.com>
# Date 1316154275 -28800
# Node ID afee8d9b7214884ab74690b3ca9fd3d4f139f455
# Parent db809376d763493849c2a19f587969eaec619b75
(#2) Fix the problem that libvirt-cim can't find cdrom device that do not have disk
This patch would allow define a system with an empty CDROM device, and allow method modify
resource settings to insert ISO files into an empty CDROM device.
Examples:
InvokeMethod(ModifyResourceSettings):
ResourceSettings: ['instance of KVM_DiskResourceAllocationSettingData {\nResourceType = 17;\nInstanceID = "test/hdc";\nEmulatedType = 1;\nVirtualDevice = "hdc";\nAddress = "";\n};']
InvokeMethod(ModifyResourceSettings):
ResourceSettings: ['instance of KVM_DiskResourceAllocationSettingData {\nResourceType = 17;\nInstanceID = "test/hdc";\nEmulatedType = 1;\nVirtualDevice = "hdc";\nAddress = "/var/lib/libvirt/images/test-disk.iso";\n};']
Note that the Address property should be set to "", not None(not set), to tell that user want
an ejection.
(#2) Add comments that saying what the code does, and improved some codes to avoid doing duplicated things.
Signed-off-by: Wayne Xia <xiawenc(a)linux.vnet.ibm.com>
diff -r db809376d763 -r afee8d9b7214 libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c Thu Jul 28 13:56:00 2011 -0300
+++ b/libxkutil/device_parsing.c Fri Sep 16 14:24:35 2011 +0800
@@ -287,6 +287,13 @@
ddev->shareable = true;
}
}
+
+ /* handle the situation that a cdrom device have no disk in it, no ISO file */
+ if ((XSTREQ(ddev->device, "cdrom")) && (ddev->source == NULL)) {
+ ddev->source = strdup("");
+ ddev->disk_type = DISK_FILE;
+ }
+
if ((ddev->source == NULL) || (ddev->virtual_dev == NULL))
goto err;
diff -r db809376d763 -r afee8d9b7214 libxkutil/xmlgen.c
--- a/libxkutil/xmlgen.c Thu Jul 28 13:56:00 2011 -0300
+++ b/libxkutil/xmlgen.c Fri Sep 16 14:24:35 2011 +0800
@@ -110,10 +110,18 @@
xmlNewProp(tmp, BAD_CAST "cache", BAD_CAST dev->cache);
}
- tmp = xmlNewChild(disk, NULL, BAD_CAST "source", NULL);
- if (tmp == NULL)
- return XML_ERROR;
- xmlNewProp(tmp, BAD_CAST "file", BAD_CAST dev->source);
+ if ((XSTREQ(dev->device, "cdrom")) &&
+ (XSTREQ(dev->source, ""))) {
+ /* This is the situation that user defined a cdrom device without
+ disk in it, so skip generating a line saying "source", for that
+ xml defination for libvirt should not have this defined in this
+ situation. */
+ } else {
+ tmp = xmlNewChild(disk, NULL, BAD_CAST "source", NULL);
+ if (tmp == NULL)
+ return XML_ERROR;
+ xmlNewProp(tmp, BAD_CAST "file", BAD_CAST dev->source);
+ }
tmp = xmlNewChild(disk, NULL, BAD_CAST "target", NULL);
if (tmp == NULL)
diff -r db809376d763 -r afee8d9b7214 src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c Thu Jul 28 13:56:00 2011 -0300
+++ b/src/Virt_VirtualSystemManagementService.c Fri Sep 16 14:24:35 2011 +0800
@@ -879,6 +879,17 @@
dev->dev.disk.device = strdup("disk");
else if (type == VIRT_DISK_TYPE_CDROM) {
dev->dev.disk.device = strdup("cdrom");
+ /* following code is for the case that user defined cdrom device
+ without disk in it, or a empty disk "" */
+ if (XSTREQ(dev->dev.disk.source, "")) {
+ dev->dev.disk.disk_type = DISK_FILE;
+ }
+ if (XSTREQ(dev->dev.disk.source, "/dev/null")) {
+ dev->dev.disk.disk_type = DISK_FILE;
+ free(dev->dev.disk.source);
+ dev->dev.disk.source = strdup("");
+ }
+
if (dev->dev.disk.disk_type == DISK_UNKNOWN)
dev->dev.disk.disk_type = DISK_PHY;
}
13 years
[PATCH] device_parsing: Small code cleanup
by Eduardo Lima (Etrunko)
libxkutil/device_parsing.c | 72 ++++++++++++++++++++++++++-------------------
1 files changed, 42 insertions(+), 30 deletions(-)
# HG changeset patch
# User Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
# Date 1317238828 10800
# Node ID 4e1f0b6dc5e512d98b8258c2c68ac5b1f28e83b6
# Parent 2448b5a111e723902603ed5430aa0f0b1972732d
device_parsing: Small code cleanup
Use the specific device parsing function as parameter in do_parse() instead
of checking for the device type in both caller and callee.
Signed-off-by: Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -49,6 +49,9 @@
#define MAX(a,b) (((a)>(b))?(a):(b))
+/* Device parse function */
+typedef int (*dev_parse_func_t)(xmlNode *, struct virt_device **);
+
static void cleanup_disk_device(struct disk_device *dev)
{
free(dev->type);
@@ -669,32 +672,15 @@
return true;
}
-static int do_parse(xmlNodeSet *nsv, int type, struct virt_device **l)
+
+static int do_parse(xmlNodeSet *nsv, dev_parse_func_t do_real_parse,
+ struct virt_device **l)
{
int devidx;
int lstidx = 0;
int count = 0;
struct virt_device *list = NULL;
xmlNode **dev_nodes = NULL;
- int (*do_real_parse)(xmlNode *, struct virt_device **) = NULL;
-
- /* point to correct parser function according to type */
- if (type == CIM_RES_TYPE_NET)
- do_real_parse = &parse_net_device;
- else if (type == CIM_RES_TYPE_DISK)
- do_real_parse = &parse_disk_device;
- else if (type == CIM_RES_TYPE_PROC)
- do_real_parse = parse_vcpu_device;
- else if (type == CIM_RES_TYPE_EMU)
- do_real_parse = parse_emu_device;
- else if (type == CIM_RES_TYPE_MEM)
- do_real_parse = parse_mem_device;
- else if (type == CIM_RES_TYPE_GRAPHICS)
- do_real_parse = parse_graphics_device;
- else if (type == CIM_RES_TYPE_INPUT)
- do_real_parse = parse_input_device;
- else
- goto out;
if (nsv == NULL)
goto out;
@@ -743,29 +729,55 @@
{
int len = 0;
int count = 0;
+ dev_parse_func_t func = NULL;
- CU_DEBUG("In parse_deviceso - type is %d", type);
xmlDoc *xmldoc;
xmlXPathContext *xpathCtx;
xmlXPathObject *xpathObj;
xmlChar *xpathstr;
- if (type == CIM_RES_TYPE_NET)
+ CU_DEBUG("In parse_devices - type is %d", type);
+
+ switch (type) {
+ case CIM_RES_TYPE_NET:
xpathstr = NET_XPATH;
- else if (type == CIM_RES_TYPE_DISK)
+ func = &parse_net_device;
+ break;
+
+ case CIM_RES_TYPE_DISK:
xpathstr = DISK_XPATH;
- else if (type == CIM_RES_TYPE_PROC)
+ func = &parse_disk_device;
+ break;
+
+ case CIM_RES_TYPE_PROC:
xpathstr = VCPU_XPATH;
- else if (type == CIM_RES_TYPE_EMU)
+ func = &parse_vcpu_device;
+ break;
+
+ case CIM_RES_TYPE_EMU:
xpathstr = EMU_XPATH;
- else if (type == CIM_RES_TYPE_MEM)
+ func = &parse_emu_device;
+ break;
+
+ case CIM_RES_TYPE_MEM:
xpathstr = MEM_XPATH;
- else if (type == CIM_RES_TYPE_GRAPHICS)
+ func = &parse_mem_device;
+ break;
+
+ case CIM_RES_TYPE_GRAPHICS:
xpathstr = GRAPHICS_XPATH;
- else if (type == CIM_RES_TYPE_INPUT)
+ func = &parse_graphics_device;
+ break;
+
+ case CIM_RES_TYPE_INPUT:
xpathstr = INPUT_XPATH;
- else
+ func = &parse_input_device;
+ break;
+
+ default:
+ CU_DEBUG("Unrecognized device type. Returning.");
goto err1;
+ };
len = strlen(xml) + 1;
@@ -780,7 +792,7 @@
== NULL)
goto err3;
- count = do_parse(xpathObj->nodesetval, type, _list);
+ count = do_parse(xpathObj->nodesetval, func, _list);
xmlSetGenericErrorFunc(NULL, NULL);
xmlXPathFreeObject(xpathObj);
13 years, 1 month
[PATCH] device_parsing: Use default values for vnc graphics device
by Eduardo Lima (Etrunko)
libxkutil/device_parsing.c | 24 ++++++++++++++++++++----
1 files changed, 20 insertions(+), 4 deletions(-)
# HG changeset patch
# User Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
# Date 1317234028 10800
# Node ID 2313e472149a557143228949878f946278d0dd3a
# Parent adc78792781448aca7a1356bd253cbdd689839cb
device_parsing: Use default values for vnc graphics device
This patch fixes the behavior where libvirt-cim loses the graphics device
description after a call to ModifyResourceSettings method. Actually it has
nothing to do with the fact that the domain is running or not. What happens is
that if somehow we can't read either 'listen' or 'port' attributes, the
function will fail and return immediately, skipping the device inclusion.
The default values are based on the ones found in the default_graphics_device
function in src/Virt_VirtualSystemManagementService.c.
Signed-off-by: Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -527,6 +527,17 @@
return 0;
}
+static char *get_attr_value_default(xmlNode *node, char *attrname,
+ const char *default_value)
+{
+ char *ret = get_attr_value(node, attrname);
+
+ if (ret == NULL && default_value != NULL)
+ ret = strdup(default_value);
+
+ return ret;
+}
+
static int parse_graphics_device(xmlNode *node, struct virt_device **vdevs)
{
struct virt_device *vdev = NULL;
@@ -547,13 +558,18 @@
CU_DEBUG("graphics device type = %s", gdev->type);
if (STREQC(gdev->type, "vnc")) {
- gdev->dev.vnc.port = get_attr_value(node, "port");
- gdev->dev.vnc.host = get_attr_value(node, "listen");
+ gdev->dev.vnc.port = get_attr_value_default(node, "port",
+ "-1");
+ gdev->dev.vnc.host = get_attr_value_default(node, "listen",
+ "127.0.0.1");
gdev->dev.vnc.keymap = get_attr_value(node, "keymap");
gdev->dev.vnc.passwd = get_attr_value(node, "passwd");
-
- if (gdev->dev.vnc.port == NULL || gdev->dev.vnc.host == NULL)
+
+ if (gdev->dev.vnc.port == NULL || gdev->dev.vnc.host == NULL) {
+ CU_DEBUG("Error vnc port '%p' host '%p'",
+ gdev->dev.vnc.port, gdev->dev.vnc.host);
goto err;
+ }
}
else if (STREQC(gdev->type, "sdl")) {
gdev->dev.sdl.display = get_attr_value(node, "display");
13 years, 1 month
[PATCH] #2 ACL: Add KVM_FilterEntry class
by Eduardo Lima (Etrunko)
schema/FilterEntry.mof | 30 ++++
schema/FilterEntry.registration | 1 +
src/Virt_EntriesInFilterList.c | 1 +
src/Virt_FilterEntry.c | 245 ++++++++++++++-------------------------
4 files changed, 122 insertions(+), 155 deletions(-)
# HG changeset patch
# User Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
# Date 1315334426 10800
# Node ID 536f49720a45b08e30d97fc25ccad3a83e86bfb5
# Parent db809376d763493849c2a19f587969eaec619b75
ACL: Add KVM_FilterEntry class
This is the generic rule meant to match simple rules such the one in
'allow-arp' filter. For instance:
<filter name='allow-arp' chain='arp'>
<uuid>15fea95d-4300-19ea-2685-5f1b14c6759b</uuid>
<rule action='accept' direction='inout' priority='500'/>
</filter>
This patch also refactors the provider code to share the conversion of
common properties between the various types of filter entries.
Changes since #1:
- Respect 80 columns limit
Signed-off-by: Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
diff --git a/schema/FilterEntry.mof b/schema/FilterEntry.mof
--- a/schema/FilterEntry.mof
+++ b/schema/FilterEntry.mof
@@ -74,3 +74,33 @@
MaxValue(1000)]
uint16 Priority = 500;
};
+
+[Provider("cmpi::Virt_FilterEntry")]
+class KVM_FilterEntry : CIM_FilterEntry
+{
+ [Description("This defines whether the Filter is used for input, "
+ "output, or both input and output filtering. All values are "
+ "used with respect to the interface for which the Filter "
+ "applies. \"Not Applicable\" (0) is used when there is no "
+ "direction applicable to the Filter. \"Input\" (1) is "
+ "used when the Filter applies to packets that are inbound "
+ "on the related interface. \"Output\" (2) is used when the "
+ "Filter applies to packets that are outbound on the "
+ "related interface. \"Both\" (3) is used to indicate that "
+ "the direction is immaterial, e.g., to filter on a source "
+ "subnet regardless of whether the flow is inbound or "
+ "outbound."),
+ ValueMap { "0", "1", "2", "3", "4" },
+ Values { "Not Applicable", "Input, Output", "Both", "Mirrored" }]
+ uint16 Direction;
+
+ [Description("The priority of the rule controls the order in which "
+ "the rule will be, instantiated relative to other rules. "
+ "Rules with lower value will be instantiated and therefore "
+ "evaluated before rules with higher value. Valid values are "
+ "in the range of 0 to 1000. If this attribute is not "
+ "provided, the value 500 will automatically be assigned."),
+ MinValue(0),
+ MaxValue(1000)]
+ uint16 Priority = 500;
+};
diff --git a/schema/FilterEntry.registration b/schema/FilterEntry.registration
--- a/schema/FilterEntry.registration
+++ b/schema/FilterEntry.registration
@@ -2,3 +2,4 @@
# Classname Namespace ProviderName ProviderModule ProviderTypes
KVM_Hdr8021Filter root/virt Virt_FilterEntry Virt_FilterEntry instance
KVM_IPHeadersFilter root/virt Virt_FilterEntry Virt_FilterEntry instance
+KVM_FilterEntry root/virt Virt_FilterEntry Virt_FilterEntry instance
diff --git a/src/Virt_EntriesInFilterList.c b/src/Virt_EntriesInFilterList.c
--- a/src/Virt_EntriesInFilterList.c
+++ b/src/Virt_EntriesInFilterList.c
@@ -160,6 +160,7 @@
};
static char *part_component[] = {
+ "KVM_FilterEntry",
"KVM_Hdr8021Filter",
"KVM_IPHeadersFilter",
NULL
diff --git a/src/Virt_FilterEntry.c b/src/Virt_FilterEntry.c
--- a/src/Virt_FilterEntry.c
+++ b/src/Virt_FilterEntry.c
@@ -36,23 +36,6 @@
const static CMPIBroker *_BROKER;
-static bool is_mac_rule(int type)
-{
- if (type == MAC_RULE || type == ARP_RULE)
- return 1;
-
- return 0;
-}
-
-static bool is_ip_rule(int type)
-{
- if (type == IP_RULE || type == TCP_RULE || type == ICMP_RULE ||
- type == IGMP_RULE)
- return 1;
-
- return 0;
-}
-
static int octets_from_mac(const char * s, unsigned int *buffer,
unsigned int size)
{
@@ -172,59 +155,15 @@
return action;
}
-static CMPIInstance *convert_mac_rule_to_instance(
+static void convert_mac_rule_to_instance(
struct acl_rule *rule,
- const CMPIBroker *broker,
- const CMPIContext *context,
- const CMPIObjectPath *reference,
- CMPIStatus *s)
+ CMPIInstance *inst,
+ const CMPIBroker *broker)
{
- CMPIInstance *inst = NULL;
- const char *sys_name = NULL;
- const char *sys_ccname = NULL;
- int action, direction, priority = 0;
unsigned int bytes[48];
unsigned int size = 0;
CMPIArray *array = NULL;
- inst = get_typed_instance(broker,
- CLASSNAME(reference),
- "Hdr8021Filter",
- NAMESPACE(reference));
- if (inst == NULL) {
- cu_statusf(broker, s,
- CMPI_RC_ERR_FAILED,
- "Unable to get 8021 filter instance");
-
- goto out;
- }
-
- *s = get_host_system_properties(&sys_name,
- &sys_ccname,
- reference,
- broker,
- context);
-
- if (s->rc != CMPI_RC_OK) {
- cu_statusf(broker, s,
- CMPI_RC_ERR_FAILED,
- "Unable to get host attributes");
- goto out;
- }
-
- CMSetProperty(inst, "SystemName", sys_name, CMPI_chars);
- CMSetProperty(inst, "SystemCreationClassName", sys_ccname, CMPI_chars);
- CMSetProperty(inst, "Name", (CMPIValue *)rule->name, CMPI_chars);
-
- action = convert_action(rule->action);
- CMSetProperty(inst, "Action", (CMPIValue *)&action, CMPI_uint16);
-
- direction = convert_direction(rule->direction);
- CMSetProperty(inst, "Direction", (CMPIValue *)&direction, CMPI_uint16);
-
- priority = convert_priority(rule->priority);
- CMSetProperty(inst, "Priority", (CMPIValue *)&priority, CMPI_uint16);
-
memset(bytes, 0, sizeof(bytes));
size = octets_from_mac(rule->var.mac.srcmacaddr,
bytes, sizeof(bytes));
@@ -260,64 +199,18 @@
if (array != NULL)
CMSetProperty(inst, "HdrDestMACMask8021", (CMPIValue *)
(CMPIValue *)&array, CMPI_uint8A);
-
- out:
- return inst;
}
-static CMPIInstance *convert_ip_rule_to_instance(
+static void convert_ip_rule_to_instance(
struct acl_rule *rule,
- const CMPIBroker *broker,
- const CMPIContext *context,
- const CMPIObjectPath *reference,
- CMPIStatus *s)
+ CMPIInstance *inst,
+ const CMPIBroker *broker)
{
- CMPIInstance *inst = NULL;
- const char *sys_name = NULL;
- const char *sys_ccname = NULL;
- int action, direction, priority = 0;
unsigned int bytes[48];
unsigned int size = 0;
unsigned int n = 0;
CMPIArray *array = NULL;
- inst = get_typed_instance(broker,
- CLASSNAME(reference),
- "IPHeadersFilter",
- NAMESPACE(reference));
- if (inst == NULL) {
- cu_statusf(broker, s,
- CMPI_RC_ERR_FAILED,
- "Unable to get ip headers filter instance");
- goto out;
- }
-
- *s = get_host_system_properties(&sys_name,
- &sys_ccname,
- reference,
- broker,
- context);
-
- if (s->rc != CMPI_RC_OK) {
- cu_statusf(broker, s,
- CMPI_RC_ERR_FAILED,
- "Unable to get host attributes");
- goto out;
- }
-
- CMSetProperty(inst, "SystemName", sys_name, CMPI_chars);
- CMSetProperty(inst, "SystemCreationClassName", sys_ccname, CMPI_chars);
- CMSetProperty(inst, "Name", (CMPIValue *)rule->name, CMPI_chars);
-
- action = convert_action(rule->action);
- CMSetProperty(inst, "Action", (CMPIValue *)&action, CMPI_uint16);
-
- direction = convert_direction(rule->direction);
- CMSetProperty(inst, "Direction", (CMPIValue *)&direction, CMPI_uint16);
-
- priority = convert_priority(rule->priority);
- CMSetProperty(inst, "Priority", (CMPIValue *)&priority, CMPI_uint16);
-
if (strstr(rule->protocol_id, "v6"))
n = 6;
else
@@ -427,8 +320,6 @@
}
}
- out:
- return inst;
}
static CMPIInstance *convert_rule_to_instance(
@@ -438,27 +329,79 @@
const CMPIObjectPath *reference,
CMPIStatus *s)
{
- CMPIInstance *instance = NULL;
+ CMPIInstance *inst = NULL;
+ const char *sys_name = NULL;
+ const char *sys_ccname = NULL;
+ const char *basename = NULL;
+ int action, direction, priority = 0;
+
+ void (*convert_f)(struct acl_rule*, CMPIInstance*, const CMPIBroker*);
if (rule == NULL)
return NULL;
- if(is_mac_rule(rule->type)) {
- instance = convert_mac_rule_to_instance(rule,
- broker,
- context,
- reference,
- s);
- }
- else if(is_ip_rule(rule->type)) {
- instance = convert_ip_rule_to_instance(rule,
- broker,
- context,
- reference,
- s);
+ switch (rule->type) {
+ case MAC_RULE:
+ case ARP_RULE:
+ basename = "Hdr8021Filter";
+ convert_f = convert_mac_rule_to_instance;
+ break;
+ case IP_RULE:
+ case TCP_RULE:
+ case ICMP_RULE:
+ case IGMP_RULE:
+ basename = "IPHeadersFilter";
+ convert_f = convert_ip_rule_to_instance;
+ break;
+ default:
+ basename = "FilterEntry";
+ convert_f = NULL;
+ break;
}
- return instance;
+ inst = get_typed_instance(broker,
+ CLASSNAME(reference),
+ basename,
+ NAMESPACE(reference));
+
+ if (inst == NULL) {
+ cu_statusf(broker, s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to get filter entry instance");
+ goto out;
+ }
+
+ *s = get_host_system_properties(&sys_name,
+ &sys_ccname,
+ reference,
+ broker,
+ context);
+
+ if (s->rc != CMPI_RC_OK) {
+ cu_statusf(broker, s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to get host attributes");
+ goto out;
+ }
+
+ CMSetProperty(inst, "SystemName", sys_name, CMPI_chars);
+ CMSetProperty(inst, "SystemCreationClassName", sys_ccname, CMPI_chars);
+ CMSetProperty(inst, "Name", (CMPIValue *)rule->name, CMPI_chars);
+
+ action = convert_action(rule->action);
+ CMSetProperty(inst, "Action", (CMPIValue *)&action, CMPI_uint16);
+
+ direction = convert_direction(rule->direction);
+ CMSetProperty(inst, "Direction", (CMPIValue *)&direction, CMPI_uint16);
+
+ priority = convert_priority(rule->priority);
+ CMSetProperty(inst, "Priority", (CMPIValue *)&priority, CMPI_uint16);
+
+ if (convert_f)
+ convert_f(rule, inst, broker);
+
+ out:
+ return inst;
}
CMPIStatus enum_filter_rules(
@@ -475,10 +418,19 @@
CU_DEBUG("Reference = %s", REF2STR(reference));
- if (STREQC(CLASSNAME(reference), "KVM_Hdr8021Filter"))
+ if (STREQC(CLASSNAME(reference), "KVM_Hdr8021Filter")) {
class_type = MAC;
- else if (STREQC(CLASSNAME(reference), "KVM_IPHeadersFilter"))
+ } else if (STREQC(CLASSNAME(reference), "KVM_IPHeadersFilter")) {
class_type = IP;
+ } else if (STREQC(CLASSNAME(reference), "KVM_FilterEntry")) {
+ class_type = NONE;
+ } else {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unrecognized class type");
+ goto out;
+ }
+
conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s);
if (conn == NULL)
@@ -490,29 +442,12 @@
for (j = 0; j < filters[i].rule_ct; j++) {
CMPIInstance *instance = NULL;
- if (((class_type == NONE) ||
- (class_type == MAC)) &&
- is_mac_rule(filters[i].rules[j]->type)) {
- instance = convert_mac_rule_to_instance(
- filters[i].rules[j],
- broker,
- context,
- reference,
- &s);
- }
- else if (((class_type == NONE) ||
- (class_type == IP)) &&
- is_ip_rule(filters[i].rules[j]->type)) {
- instance = convert_ip_rule_to_instance(
- filters[i].rules[j],
- broker,
- context,
- reference,
- &s);
- }
- else
- CU_DEBUG("Unrecognized rule type %u",
- filters[i].rules[j]->type);
+ instance = convert_rule_to_instance(
+ filters[i].rules[j],
+ broker,
+ context,
+ reference,
+ &s);
if (instance != NULL)
inst_list_add(list, instance);
13 years, 1 month
[PATCH] ACL: Add KVM_FilterEntry class
by Eduardo Lima (Etrunko)
schema/FilterEntry.mof | 30 ++++
schema/FilterEntry.registration | 1 +
src/Virt_EntriesInFilterList.c | 1 +
src/Virt_FilterEntry.c | 241 ++++++++++++++-------------------------
4 files changed, 120 insertions(+), 153 deletions(-)
# HG changeset patch
# User Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
# Date 1315334426 10800
# Node ID 9a59a56e226f3f800ff7214b81ab5f2fe6362fcc
# Parent db809376d763493849c2a19f587969eaec619b75
ACL: Add KVM_FilterEntry class
This is the generic rule meant to match simple rules such the one in
'allow-arp' filter. For instance:
<filter name='allow-arp' chain='arp'>
<uuid>15fea95d-4300-19ea-2685-5f1b14c6759b</uuid>
<rule action='accept' direction='inout' priority='500'/>
</filter>
This patch also refactors the provider code to share the conversion of
common properties between the various types of filter entries.
Signed-off-by: Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
diff --git a/schema/FilterEntry.mof b/schema/FilterEntry.mof
--- a/schema/FilterEntry.mof
+++ b/schema/FilterEntry.mof
@@ -74,3 +74,33 @@
MaxValue(1000)]
uint16 Priority = 500;
};
+
+[Provider("cmpi::Virt_FilterEntry")]
+class KVM_FilterEntry : CIM_FilterEntry
+{
+ [Description("This defines whether the Filter is used for input, "
+ "output, or both input and output filtering. All values are "
+ "used with respect to the interface for which the Filter "
+ "applies. \"Not Applicable\" (0) is used when there is no "
+ "direction applicable to the Filter. \"Input\" (1) is "
+ "used when the Filter applies to packets that are inbound "
+ "on the related interface. \"Output\" (2) is used when the "
+ "Filter applies to packets that are outbound on the "
+ "related interface. \"Both\" (3) is used to indicate that "
+ "the direction is immaterial, e.g., to filter on a source "
+ "subnet regardless of whether the flow is inbound or "
+ "outbound."),
+ ValueMap { "0", "1", "2", "3", "4" },
+ Values { "Not Applicable", "Input, Output", "Both", "Mirrored" }]
+ uint16 Direction;
+
+ [Description("The priority of the rule controls the order in which "
+ "the rule will be, instantiated relative to other rules. "
+ "Rules with lower value will be instantiated and therefore "
+ "evaluated before rules with higher value. Valid values are "
+ "in the range of 0 to 1000. If this attribute is not "
+ "provided, the value 500 will automatically be assigned."),
+ MinValue(0),
+ MaxValue(1000)]
+ uint16 Priority = 500;
+};
diff --git a/schema/FilterEntry.registration b/schema/FilterEntry.registration
--- a/schema/FilterEntry.registration
+++ b/schema/FilterEntry.registration
@@ -2,3 +2,4 @@
# Classname Namespace ProviderName ProviderModule ProviderTypes
KVM_Hdr8021Filter root/virt Virt_FilterEntry Virt_FilterEntry instance
KVM_IPHeadersFilter root/virt Virt_FilterEntry Virt_FilterEntry instance
+KVM_FilterEntry root/virt Virt_FilterEntry Virt_FilterEntry instance
diff --git a/src/Virt_EntriesInFilterList.c b/src/Virt_EntriesInFilterList.c
--- a/src/Virt_EntriesInFilterList.c
+++ b/src/Virt_EntriesInFilterList.c
@@ -160,6 +160,7 @@
};
static char *part_component[] = {
+ "KVM_FilterEntry",
"KVM_Hdr8021Filter",
"KVM_IPHeadersFilter",
NULL
diff --git a/src/Virt_FilterEntry.c b/src/Virt_FilterEntry.c
--- a/src/Virt_FilterEntry.c
+++ b/src/Virt_FilterEntry.c
@@ -36,23 +36,6 @@
const static CMPIBroker *_BROKER;
-static bool is_mac_rule(int type)
-{
- if (type == MAC_RULE || type == ARP_RULE)
- return 1;
-
- return 0;
-}
-
-static bool is_ip_rule(int type)
-{
- if (type == IP_RULE || type == TCP_RULE || type == ICMP_RULE ||
- type == IGMP_RULE)
- return 1;
-
- return 0;
-}
-
static int octets_from_mac(const char * s, unsigned int *buffer,
unsigned int size)
{
@@ -172,59 +155,15 @@
return action;
}
-static CMPIInstance *convert_mac_rule_to_instance(
+static void convert_mac_rule_to_instance(
struct acl_rule *rule,
- const CMPIBroker *broker,
- const CMPIContext *context,
- const CMPIObjectPath *reference,
- CMPIStatus *s)
+ CMPIInstance *inst,
+ const CMPIBroker *broker)
{
- CMPIInstance *inst = NULL;
- const char *sys_name = NULL;
- const char *sys_ccname = NULL;
- int action, direction, priority = 0;
unsigned int bytes[48];
unsigned int size = 0;
CMPIArray *array = NULL;
- inst = get_typed_instance(broker,
- CLASSNAME(reference),
- "Hdr8021Filter",
- NAMESPACE(reference));
- if (inst == NULL) {
- cu_statusf(broker, s,
- CMPI_RC_ERR_FAILED,
- "Unable to get 8021 filter instance");
-
- goto out;
- }
-
- *s = get_host_system_properties(&sys_name,
- &sys_ccname,
- reference,
- broker,
- context);
-
- if (s->rc != CMPI_RC_OK) {
- cu_statusf(broker, s,
- CMPI_RC_ERR_FAILED,
- "Unable to get host attributes");
- goto out;
- }
-
- CMSetProperty(inst, "SystemName", sys_name, CMPI_chars);
- CMSetProperty(inst, "SystemCreationClassName", sys_ccname, CMPI_chars);
- CMSetProperty(inst, "Name", (CMPIValue *)rule->name, CMPI_chars);
-
- action = convert_action(rule->action);
- CMSetProperty(inst, "Action", (CMPIValue *)&action, CMPI_uint16);
-
- direction = convert_direction(rule->direction);
- CMSetProperty(inst, "Direction", (CMPIValue *)&direction, CMPI_uint16);
-
- priority = convert_priority(rule->priority);
- CMSetProperty(inst, "Priority", (CMPIValue *)&priority, CMPI_uint16);
-
memset(bytes, 0, sizeof(bytes));
size = octets_from_mac(rule->var.mac.srcmacaddr,
bytes, sizeof(bytes));
@@ -260,64 +199,18 @@
if (array != NULL)
CMSetProperty(inst, "HdrDestMACMask8021", (CMPIValue *)
(CMPIValue *)&array, CMPI_uint8A);
-
- out:
- return inst;
}
-static CMPIInstance *convert_ip_rule_to_instance(
+static void convert_ip_rule_to_instance(
struct acl_rule *rule,
- const CMPIBroker *broker,
- const CMPIContext *context,
- const CMPIObjectPath *reference,
- CMPIStatus *s)
+ CMPIInstance *inst,
+ const CMPIBroker *broker)
{
- CMPIInstance *inst = NULL;
- const char *sys_name = NULL;
- const char *sys_ccname = NULL;
- int action, direction, priority = 0;
unsigned int bytes[48];
unsigned int size = 0;
unsigned int n = 0;
CMPIArray *array = NULL;
- inst = get_typed_instance(broker,
- CLASSNAME(reference),
- "IPHeadersFilter",
- NAMESPACE(reference));
- if (inst == NULL) {
- cu_statusf(broker, s,
- CMPI_RC_ERR_FAILED,
- "Unable to get ip headers filter instance");
- goto out;
- }
-
- *s = get_host_system_properties(&sys_name,
- &sys_ccname,
- reference,
- broker,
- context);
-
- if (s->rc != CMPI_RC_OK) {
- cu_statusf(broker, s,
- CMPI_RC_ERR_FAILED,
- "Unable to get host attributes");
- goto out;
- }
-
- CMSetProperty(inst, "SystemName", sys_name, CMPI_chars);
- CMSetProperty(inst, "SystemCreationClassName", sys_ccname, CMPI_chars);
- CMSetProperty(inst, "Name", (CMPIValue *)rule->name, CMPI_chars);
-
- action = convert_action(rule->action);
- CMSetProperty(inst, "Action", (CMPIValue *)&action, CMPI_uint16);
-
- direction = convert_direction(rule->direction);
- CMSetProperty(inst, "Direction", (CMPIValue *)&direction, CMPI_uint16);
-
- priority = convert_priority(rule->priority);
- CMSetProperty(inst, "Priority", (CMPIValue *)&priority, CMPI_uint16);
-
if (strstr(rule->protocol_id, "v6"))
n = 6;
else
@@ -427,8 +320,6 @@
}
}
- out:
- return inst;
}
static CMPIInstance *convert_rule_to_instance(
@@ -439,25 +330,77 @@
CMPIStatus *s)
{
CMPIInstance *instance = NULL;
+ const char *sys_name = NULL;
+ const char *sys_ccname = NULL;
+ const char *basename = NULL;
+ int action, direction, priority = 0;
+
+ void (*convert_func)(struct acl_rule*, CMPIInstance*, const CMPIBroker*);
if (rule == NULL)
return NULL;
- if(is_mac_rule(rule->type)) {
- instance = convert_mac_rule_to_instance(rule,
- broker,
- context,
- reference,
- s);
- }
- else if(is_ip_rule(rule->type)) {
- instance = convert_ip_rule_to_instance(rule,
- broker,
- context,
- reference,
- s);
+ switch (rule->type) {
+ case MAC_RULE:
+ case ARP_RULE:
+ basename = "Hdr8021Filter";
+ convert_func = convert_mac_rule_to_instance;
+ break;
+ case IP_RULE:
+ case TCP_RULE:
+ case ICMP_RULE:
+ case IGMP_RULE:
+ basename = "IPHeadersFilter";
+ convert_func = convert_ip_rule_to_instance;
+ break;
+ default:
+ basename = "FilterEntry";
+ convert_func = NULL;
+ break;
}
+ instance = get_typed_instance(broker,
+ CLASSNAME(reference),
+ basename,
+ NAMESPACE(reference));
+
+ if (instance == NULL) {
+ cu_statusf(broker, s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to get filter entry instance");
+ goto out;
+ }
+
+ *s = get_host_system_properties(&sys_name,
+ &sys_ccname,
+ reference,
+ broker,
+ context);
+
+ if (s->rc != CMPI_RC_OK) {
+ cu_statusf(broker, s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to get host attributes");
+ goto out;
+ }
+
+ CMSetProperty(instance, "SystemName", sys_name, CMPI_chars);
+ CMSetProperty(instance, "SystemCreationClassName", sys_ccname, CMPI_chars);
+ CMSetProperty(instance, "Name", (CMPIValue *)rule->name, CMPI_chars);
+
+ action = convert_action(rule->action);
+ CMSetProperty(instance, "Action", (CMPIValue *)&action, CMPI_uint16);
+
+ direction = convert_direction(rule->direction);
+ CMSetProperty(instance, "Direction", (CMPIValue *)&direction, CMPI_uint16);
+
+ priority = convert_priority(rule->priority);
+ CMSetProperty(instance, "Priority", (CMPIValue *)&priority, CMPI_uint16);
+
+ if (convert_func)
+ convert_func(rule, instance, broker);
+
+ out:
return instance;
}
@@ -475,10 +418,19 @@
CU_DEBUG("Reference = %s", REF2STR(reference));
- if (STREQC(CLASSNAME(reference), "KVM_Hdr8021Filter"))
+ if (STREQC(CLASSNAME(reference), "KVM_Hdr8021Filter")) {
class_type = MAC;
- else if (STREQC(CLASSNAME(reference), "KVM_IPHeadersFilter"))
+ } else if (STREQC(CLASSNAME(reference), "KVM_IPHeadersFilter")) {
class_type = IP;
+ } else if (STREQC(CLASSNAME(reference), "KVM_FilterEntry")) {
+ class_type = NONE;
+ } else {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unrecognized class type");
+ goto out;
+ }
+
conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s);
if (conn == NULL)
@@ -490,29 +442,12 @@
for (j = 0; j < filters[i].rule_ct; j++) {
CMPIInstance *instance = NULL;
- if (((class_type == NONE) ||
- (class_type == MAC)) &&
- is_mac_rule(filters[i].rules[j]->type)) {
- instance = convert_mac_rule_to_instance(
- filters[i].rules[j],
- broker,
- context,
- reference,
- &s);
- }
- else if (((class_type == NONE) ||
- (class_type == IP)) &&
- is_ip_rule(filters[i].rules[j]->type)) {
- instance = convert_ip_rule_to_instance(
- filters[i].rules[j],
- broker,
- context,
- reference,
- &s);
- }
- else
- CU_DEBUG("Unrecognized rule type %u",
- filters[i].rules[j]->type);
+ instance = convert_rule_to_instance(
+ filters[i].rules[j],
+ broker,
+ context,
+ reference,
+ &s);
if (instance != NULL)
inst_list_add(list, instance);
13 years, 1 month
[PATCH] [TEST] 31_unset_netrasd.py: new test for VirtualSystemManagementService
by Eduardo Lima (Etrunko)
suites/libvirt-cim/cimtest/VirtualSystemManagementService/31_unset_netrasd.py | 192 ++++++++++
1 files changed, 192 insertions(+), 0 deletions(-)
# HG changeset patch
# User Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
# Date 1317153134 10800
# Node ID 273559a7fec092be0699c486c591d3385bbf6df5
# Parent 83921669cae17a4f0a18bb440ebec01de1a3e691
[TEST] 31_unset_netrasd.py: new test for VirtualSystemManagementService
This test case covers a recent bug found in Pegasus which makes impossible for
libvirt-cim to set a property values if the value is an empty string via a
ModifyResourceSettings call.
Link to Pegasus bug follows:
http://bugzilla.openpegasus.org/show_bug.cgi?id=9053
Signed-off-by: Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/31_unset_netrasd.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/31_unset_netrasd.py
new file mode 100755
--- /dev/null
+++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/31_unset_netrasd.py
@@ -0,0 +1,192 @@
+#!/usr/bin/env python
+
+#
+# Copyright 2011 IBM Corp.
+#
+# Authors:
+# Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+#
+# ModifyResourceSettings call to set/unset NetRASD ResourceType property
+#
+
+import sys
+import pywbem
+
+from CimTest.ReturnCodes import PASS, FAIL
+from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS
+from XenKvmLib.const import do_main
+from XenKvmLib.classes import get_typed_class
+from XenKvmLib.vxml import get_class
+
+supported = ['Xen', 'KVM', 'XenFV', 'LXC']
+domain = None
+
+class CIMDomain(object):
+
+ def __init__(self, name, virt, server):
+ self.name = name
+ self.server = server
+ self._domain = get_class(virt)(name)
+ #__init__
+
+ def define(self):
+ return self._domain.cim_define(self.server)
+ # define
+
+ def undefine(self):
+ return self._domain.undefine(self.server)
+ # undefine
+
+ def destroy(self):
+ return self._domain.cim_destroy(self.server)
+ #destroy
+# CIMDomain
+
+
+def resource_settings(inst, resource_subtype):
+ return """
+instance of KVM_NetResourceAllocationSettingData {
+ InstanceID="%s";
+ ResourceType=%d;
+ Address="%s";
+ VirtualQuantityUnits="%s";
+ NetworkType="%s";
+ NetworkName="%s";
+ ResourceSubType="%s";
+};""" % (inst["InstanceID"],
+ inst["ResourceType"],
+ inst["Address"],
+ inst["VirtualQuantityUnits"],
+ inst["NetworkType"],
+ inst["NetworkName"],
+ resource_subtype)
+# resource_settings()
+
+
+@do_main(supported)
+def main():
+ # init
+ options = main.options
+ server = options.ip
+ virt = options.virt
+
+ server_url = "http://%s" % server
+ cim = pywbem.WBEMConnection(server_url, (CIM_USER, CIM_PASS), CIM_NS)
+
+ _class = get_typed_class(virt, "VirtualSystemManagementService")
+ sys_mgmt_service = cim.EnumerateInstanceNames(_class)[0]
+
+ # Create new domain
+ global domain
+ domain = CIMDomain("cimtest_unset_netrasd", virt, server)
+ if not domain.define():
+ logger.error("Error defining test domain")
+ return FAIL
+
+ # ein KVM_ComputerSystem
+ _class = get_typed_class(virt, "ComputerSystem")
+ computer_system_names = [i for i in cim.EnumerateInstanceNames(_class) if i["Name"] == dom_name]
+
+ logger.info("ComputerSystem Names\n%s", computer_system_names)
+
+ if not computer_system_names:
+ logger.info("Host has no domains defined")
+ return SKIP
+
+ # ain -ac KVM_SystemDevice -arc KVM_NetworkPort <KVM_ComputerSytem Name>
+ a_class = get_typed_class(virt, "SystemDevice")
+ r_class = get_typed_class(virt, "NetworkPort")
+ network_port_names = []
+
+ for inst_name in computer_system_names:
+ assoc_names = cim.AssociatorNames(inst_name, AssocClass=a_class, ResultClass=r_class)
+ network_port_names.extend(assoc_names)
+
+ logger.info("NetworkPort Names\n%s", network_port_names)
+
+ if not network_port_names:
+ logger.info("No NetworkPort instances returned")
+ return XFAIL
+
+ # ai -arc KVM_NetResourceAllocationSettingData <KVM_NetworkPort Name>
+ r_class = get_typed_class(virt, "NetResourceAllocationSettingData")
+ net_rasd_names = []
+
+ for inst_name in network_port_names:
+ assoc_names = cim.AssociatorNames(inst_name, ResultClass=r_class)
+ net_rasd_names.extend(assoc_names)
+
+ logger.info("NetRASD names\n%s", net_rasd_names)
+
+ if not net_rasd_names:
+ logger.info("No NetRASD instances returned")
+ return XFAIL
+
+ for subtype in ["virtio", "",]:
+ logger.info("Setting ResourceSubType to '%s'", subtype)
+
+ modified_net_rasd_names = []
+
+ for inst_name in net_rasd_names:
+ # Get current instance data
+ inst = cim.GetInstance(inst_name)
+ cur_id = inst["InstanceID"]
+ cur_subtype = inst["ResourceSubType"]
+ logger.info("Current ResourceSubType of %s: '%s'", cur_id, cur_subtype)
+
+ # Invoke ModifyResourceSettings
+ val = resource_settings(inst, subtype)
+ ret = cim.InvokeMethod("ModifyResourceSettings", sys_mgmt_service, **{"ResourceSettings": [val,],})
+
+ if ret[0]:
+ logger.error("ERROR Setting ResourceSubtype to '%s': %s", subtype, ret)
+ return FAIL
+
+ modified_net_rasd_names.extend(ret[1]["ResultingResourceSettings"])
+
+ # Get modified instance data
+ inst = cim.GetInstance(ret[1]["ResultingResourceSettings"][0])
+ new_id = inst["InstanceID"]
+ new_subtype = inst["ResourceSubType"]
+
+ logger.info("Modified ResourceSubType of %s: '%s'", new_id, new_subtype)
+
+ if cur_id != new_id:
+ logger.error("Current '%s' and new '%s' InstanceID differ", cur_id, new_id)
+ return FAIL
+
+ if new_subtype != subtype:
+ logger.error("Current '%s' and expected '%s' ResourceSubType differ", new_subtype, subtype)
+ return FAIL
+ # for inst_name...
+
+ net_rasd_names = modified_net_rasd_names
+ #for subtype...
+
+ return PASS
+#main()
+
+if __name__ == "__main__":
+ ret = main()
+
+ if domain:
+ domain.destroy()
+ domain.undefine()
+
+ sys.exit(ret)
13 years, 1 month