[PATCH] [TEST] Update FilterList tests and helper
by Eduardo Lima (Etrunko)
From: "Eduardo Lima (Etrunko)" <eblima(a)br.ibm.com>
According to recent changes in FilterList and FilterEntry providers.
03_create.py:
- Creation and deletion of AppliedFilterList instance
- Deletion of NestedFilterList instance
- Deletion of FilterList instance
helper.py:
- Removed warning about Deprecated use of lxml functionality
- New filter rule actions
- Match protocol id
Signed-off-by: Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
---
suites/libvirt-cim/cimtest/FilterList/03_create.py | 35 +++++++++++++---
suites/libvirt-cim/cimtest/FilterList/helper.py | 42 +++++++++++++++++---
2 files changed, 64 insertions(+), 13 deletions(-)
diff --git a/suites/libvirt-cim/cimtest/FilterList/03_create.py b/suites/libvirt-cim/cimtest/FilterList/03_create.py
index e828e92..551a01f 100644
--- a/suites/libvirt-cim/cimtest/FilterList/03_create.py
+++ b/suites/libvirt-cim/cimtest/FilterList/03_create.py
@@ -38,6 +38,9 @@ from VirtLib.utils import run_remote
sup_types = ["KVM",]
domain = None
+flist_name = None
+nested_name = None
+applied_name = None
def get_filter_inst_and_inst_name(name):
try:
@@ -89,6 +92,7 @@ def create_filter_list(name):
# A NestedFilterList instance will add the "clean-traffic" filter
# as an entry of the newly created FilterList
+ global nested_name
logger.info("Creating NestedFilterList instance")
nested_name = test.CreateFilterListInstance(None, "KVM_NestedFilterList",
{"Antecedent":flist_name,
@@ -125,8 +129,11 @@ def get_nwport_inst_and_inst_name(domain_name):
def cleanup():
try:
- # Destroy filter list
- test.wbem.DeleteInstance(flist_name)
+ # Destroy filter list instances
+ for n in [applied_name, nested_name, flist_name]:
+ if n is not None:
+ logger.info("Deleting instance %s", n)
+ test.wbem.DeleteInstance(n)
except Exception, e:
logger.error("Error deleting filter list: %s", e)
@@ -165,15 +172,29 @@ def main():
# An AppliedFilterList Instance will apply the filter to the network
# port of the defined domain
- test.CreateFilterListInstance(None, "KVM_AppliedFilterList",
- {"Antecedent":nwport_name,
- "Dependent":flist_name})
+ global applied_name
+ logger.info ("Creating AppliedFilterList instance")
+ applied_name = test.CreateFilterListInstance(None, "KVM_AppliedFilterList",
+ {"Antecedent":nwport_name,
+ "Dependent":flist_name})
+ logger.info("Got AppliedFilterList name '%s'", applied_name)
+ #applied = test.GetInstance(applied_name)
+ #logger.info("Got AppliedFilterList '%s'", applied)
+
+ # Check results
+ filterref = test.libvirt_applied_filter_lists(domain_name)[0]
+ rule = helper.FilterRule(filterref)
+ if rule.filter != test_flist:
+ raise Exception("AppliedFilterList name '%s' does not match expected '%s'",
+ rule.filter, test_flist)
+
+ test.cim_applied_filter_lists(domain_name)
+ logger.info("AppliedFilterList created succesfully")
+ result = PASS
except Exception, e:
logger.error("Caught exception: %s", e)
result = FAIL
- # Check results
-
# Cleanup
cleanup()
diff --git a/suites/libvirt-cim/cimtest/FilterList/helper.py b/suites/libvirt-cim/cimtest/FilterList/helper.py
index 9ae2f62..5202fa6 100644
--- a/suites/libvirt-cim/cimtest/FilterList/helper.py
+++ b/suites/libvirt-cim/cimtest/FilterList/helper.py
@@ -252,7 +252,7 @@ class FilterListTest(BaseTestObject):
d = {}
for f in filters:
root = self.libvirt_filter_dumpxml(f[0])
- if not root:
+ if root is None:
return None
d[f] = root
@@ -307,6 +307,22 @@ class FilterListTest(BaseTestObject):
return self.Associators(_inst_name, result_class="CIM_FilterEntryBase")
# cim_entries_in_filter_list
+
+ def libvirt_applied_filter_lists(self, dom_name):
+ cmd = "virsh -q -c %s dumpxml %s 2>/dev/null" % (self.uri, dom_name)
+ ret, dom_xml = run_remote(self.server, cmd)
+ if ret:
+ logger.error("Error retrieving domain xml for %s", dom_name)
+ return None
+
+ xdoc = etree.fromstring(dom_xml)
+ filter_list = xdoc.xpath("/domain/devices/interface/filterref")
+ return filter_list
+ # libvirt_applied_filter_lists
+
+ def cim_applied_filter_lists(self, dom_name):
+ pass
+ # cim_applied_filter_lists
# FilterListTest
@@ -319,9 +335,17 @@ class FilterRule(object):
__versions = {"ip" : "4",
"ipv6": "6",}
- __actions = {"accept" : "1",
- "deny" : "2",
- "drop" : "2",}
+ __actions = {"accept" : "1",
+ "deny" : "2",
+ "drop" : "2",
+ "reject" : "3",
+ "return" : "4",
+ "continue" : "5",}
+
+ __protocolids = {"ipv4": "2048",
+ "arp" : "2054",
+ "rarp": "32821",
+ "ipv6": "34525",}
__baserule_map = {"action" : "Action",
"direction" : "Direction",
@@ -394,7 +418,7 @@ class FilterRule(object):
for e in element:
self.__dict = dict(self.__dict, **e.attrib)
- if not self.__type:
+ if self.__type is None:
self.__type = e.tag
try:
@@ -415,6 +439,12 @@ class FilterRule(object):
return self.__actions[self.__dict[key]]
elif key == "type":
return self.__type
+ elif key == "protocolid":
+ value = self.__dict[key]
+ try:
+ return self.__protocolids[value]
+ except KeyError:
+ return value
try:
return self.__dict[key]
@@ -470,7 +500,7 @@ class FilterRule(object):
# convert the property value to string
prop = instance.properties[inst_key]
val = self.__getattr__(key)
- if val.startswith("0x"):
+ if isinstance(val, str) and val.startswith("0x"):
inst_val = hex(int(prop.value))
else:
inst_val = str(prop.value)
--
1.7.7.6
12 years, 7 months
[PATCH 0/4] Update Filter{Entry,List} providers
by Eduardo Lima (Etrunko)
From: "Eduardo Lima (Etrunko)" <eblima(a)br.ibm.com>
These changes are necessary due to recent changes in the libvirt network
filters specification. Cimtests were also updated to match these changes.
http://libvirt.org/formatnwfilter.html
Eduardo Lima (Etrunko) (4):
FilterEntry: Change 'Priority' property type
FilterList: Add 'Priority' property
FilterEntry: Update action property
FilterEntry: Accept protocol id string values
libxkutil/acl_parsing.c | 2 +
libxkutil/acl_parsing.h | 1 +
schema/FilterEntry.mof | 26 ++++++++++++------------
schema/FilterList.mof | 9 ++++++++
src/Makefile.am | 4 +-
src/Virt_FilterEntry.c | 49 +++++++++++++++++++++++++++++++++++-----------
src/Virt_FilterEntry.h | 6 +++++
src/Virt_FilterList.c | 5 +++-
8 files changed, 74 insertions(+), 28 deletions(-)
--
1.7.7.6
12 years, 7 months