Commit 63f04832 authored by Naoki Kambe's avatar Naoki Kambe
Browse files

[917] show the statistics data or the statistics spec with the module_name and the item_name

even if module_name is specified or module_name and item_name are specified in arguments
parent de07e6a0
......@@ -246,12 +246,12 @@ class Stats:
self.update_statistics_data()
if owner and name:
try:
return self.statistics_data[owner][name]
return {owner:{name:self.statistics_data[owner][name]}}
except KeyError:
pass
elif owner:
try:
return self.statistics_data[owner]
return {owner: self.statistics_data[owner]}
except KeyError:
pass
elif name:
......@@ -360,9 +360,9 @@ class Stats:
if owner:
try:
if name:
return isc.config.create_answer(0, schema_byname[owner][name])
return isc.config.create_answer(0, {owner:[schema_byname[owner][name]]})
else:
return isc.config.create_answer(0, schema[owner])
return isc.config.create_answer(0, {owner:schema[owner]})
except KeyError:
pass
else:
......
......@@ -778,9 +778,7 @@ class StatsHttpd:
xsd_root = xml.etree.ElementTree.Element( # started with xml:template tag
"xsl:template",
attrib={'match': "bind10:statistics"})
if module_name is not None and item_name is not None:
stats_spec2xsl([ stats_spec ], xsd_root, XML_URL_PATH + '/' + module_name)
elif module_name is not None:
if module_name is not None:
stats_spec2xsl(stats_spec, xsd_root, XML_URL_PATH + '/' + module_name)
else:
stats_spec2xsl(stats_spec, xsd_root)
......
......@@ -182,8 +182,9 @@ class TestHttpHandler(unittest.TestCase):
+ stats_httpd.XSL_URL_PATH + '/' + mod
+ '"?>'))
for k in DUMMY_DATA[mod].keys():
self.assertIsNotNone(root.find(k))
itm = root.find(k)
self.assertIsNotNone(root.find(mod + '/' + k))
itm = root.find(mod + '/' + k)
self.assertIsNotNone(itm)
if type(DUMMY_DATA[mod][k]) is list:
for v in DUMMY_DATA[mod][k]:
for i in v:
......@@ -198,7 +199,7 @@ class TestHttpHandler(unittest.TestCase):
'<?xml-stylesheet type="text/xsl" href="'
+ stats_httpd.XSL_URL_PATH + '/' + mod + '/' + item
+ '"?>'))
self.assertIsNotNone(root.find(item))
self.assertIsNotNone(root.find(mod + '/' + item))
# URL is '/bind10/statistics/xml'
check_XML_URL_PATH(mod=None, item=None)
......@@ -247,9 +248,12 @@ class TestHttpHandler(unittest.TestCase):
self.assertTrue(
k in [ elm.attrib['name'] for elm in itm_elm2['zones'].findall(xsdpath) ])
elif item is None:
xsdpath = '/'.join([ url_xmlschema + t for t in [ 'element', 'complexType', 'all', 'element' ] ])
mod_elm = dict([ (elm.attrib['name'], elm) for elm in root.findall(xsdpath) ])
self.assertTrue(mod in mod_elm)
for (it, val) in DUMMY_DATA[mod].items():
xsdpath = '/'.join([ url_xmlschema + t for t in [ 'element', 'complexType', 'all', 'element' ] ])
itm_elm = dict([ (elm.attrib['name'], elm) for elm in root.findall(xsdpath) ])
xsdpath = '/'.join([ url_xmlschema + t for t in [ 'complexType', 'all', 'element' ] ])
itm_elm = dict([ (elm.attrib['name'], elm) for elm in mod_elm[mod].findall(xsdpath) ])
self.assertTrue(it in itm_elm)
if type(val) is list:
xsdpath = '/'.join([ url_xmlschema + t for t in [ 'complexType', 'sequence', 'element' ] ])
......@@ -262,7 +266,10 @@ class TestHttpHandler(unittest.TestCase):
k in [ elm.attrib['name'] for elm in itm_elm2['zones'].findall(xsdpath) ])
else:
xsdpath = '/'.join([ url_xmlschema + t for t in [ 'element', 'complexType', 'all', 'element' ] ])
itm_elm = dict([ (elm.attrib['name'], elm) for elm in root.findall(xsdpath) ])
mod_elm = dict([ (elm.attrib['name'], elm) for elm in root.findall(xsdpath) ])
self.assertTrue(mod in mod_elm)
xsdpath = '/'.join([ url_xmlschema + t for t in [ 'complexType', 'all', 'element' ] ])
itm_elm = dict([ (elm.attrib['name'], elm) for elm in mod_elm[mod].findall(xsdpath) ])
self.assertTrue(item in itm_elm)
if type(DUMMY_DATA[mod][item]) is list:
xsdpath = '/'.join([ url_xmlschema + t for t in [ 'complexType', 'sequence', 'element' ] ])
......@@ -328,11 +335,14 @@ class TestHttpHandler(unittest.TestCase):
itm_vo = [ x.attrib['select'] for x in mod_fe[mod].findall(xslpath) ]
self.assertTrue(k in itm_vo)
elif item is None:
xslpath = url_trans + 'template/' + url_xhtml + 'table/' + url_trans + 'for-each'
mod_fe = dict([ (x.attrib['select'], x) for x in root.findall(xslpath) ])
self.assertTrue(mod in mod_fe)
for (k, v) in DUMMY_DATA[mod].items():
if type(v) is list:
xslpath = url_trans + 'template/' + url_xhtml + 'table/' \
+ url_trans + 'for-each'
itm_fe = dict([ (x.attrib['select'], x) for x in root.findall(xslpath) ])
xslpath = url_xhtml + 'tr/' + url_xhtml + 'td/' \
+ url_xhtml + 'table/' + url_trans + 'for-each'
itm_fe = dict([ (x.attrib['select'], x) for x in mod_fe[mod].findall(xslpath) ])
self.assertTrue(k in itm_fe)
for itms in v:
xslpath = url_xhtml + 'tr/' + url_xhtml + 'td/' \
......@@ -346,21 +356,24 @@ class TestHttpHandler(unittest.TestCase):
itm_vo = [ x.attrib['select'] for x in itm_fe['zones'].findall(xslpath) ]
self.assertTrue(k in itm_vo)
else:
xslpath = url_trans + 'template/' + url_xhtml + 'table/' \
+ url_xhtml + 'tr/' + url_xhtml + 'td/' + url_trans + 'value-of'
itm_vo = dict([ (x.attrib['select'], x) for x in root.findall(xslpath) ])
xslpath = url_xhtml + 'tr/' + url_xhtml + 'td/' \
+ url_xhtml + 'table/' + url_xhtml + 'tr/' \
+ url_xhtml + 'td/' + url_trans + 'value-of'
itm_vo = [ x.attrib['select'] for x in mod_fe[mod].findall(xslpath) ]
self.assertTrue(k in itm_vo)
else:
(k, v) = (item, DUMMY_DATA[mod][item])
if type(v) is list:
xslpath = url_trans + 'template/' + url_xhtml + 'table/' \
+ url_trans + 'for-each'
itm_fe = dict([ (x.attrib['select'], x) for x in root.findall(xslpath) ])
self.assertTrue(k in itm_fe)
for itms in v:
xslpath = url_trans + 'template/' + url_xhtml + 'table/' + url_trans + 'for-each'
mod_fe = dict([ (x.attrib['select'], x) for x in root.findall(xslpath) ])
self.assertTrue(mod in mod_fe)
if type(DUMMY_DATA[mod][item]) is list:
xslpath = url_xhtml + 'tr/' + url_xhtml + 'td/' \
+ url_xhtml + 'table/' + url_trans + 'for-each'
itm_fe = dict([ (x.attrib['select'], x) for x in mod_fe[mod].findall(xslpath) ])
self.assertTrue(item in itm_fe)
for itms in DUMMY_DATA[mod][item]:
xslpath = url_xhtml + 'tr/' + url_xhtml + 'td/' \
+ url_xhtml + 'table/' + url_trans + 'for-each'
itm_fe = dict([ (x.attrib['select'], x) for x in itm_fe[k].findall(xslpath) ])
itm_fe = dict([ (x.attrib['select'], x) for x in itm_fe[item].findall(xslpath) ])
self.assertTrue('zones' in itm_fe)
for (k, v) in itms.items():
xslpath = url_xhtml + 'tr/' + url_xhtml + 'td/' \
......@@ -369,10 +382,11 @@ class TestHttpHandler(unittest.TestCase):
itm_vo = [ x.attrib['select'] for x in itm_fe['zones'].findall(xslpath) ]
self.assertTrue(k in itm_vo)
else:
xslpath = url_trans + 'template/' + url_xhtml + 'table/' \
+ url_xhtml + 'tr/' + url_xhtml + 'td/' + url_trans + 'value-of'
itm_vo = dict([ (x.attrib['select'], x) for x in root.findall(xslpath) ])
self.assertTrue(k in itm_vo)
xslpath = url_xhtml + 'tr/' + url_xhtml + 'td/' \
+ url_xhtml + 'table/' + url_xhtml + 'tr/' \
+ url_xhtml + 'td/' + url_trans + 'value-of'
itm_vo = [ x.attrib['select'] for x in mod_fe[mod].findall(xslpath) ]
self.assertTrue(item in itm_vo)
# URL is '/bind10/statistics/xsl'
check_XSL_URL_PATH(mod=None, item=None)
......
......@@ -226,7 +226,7 @@ class TestStats(unittest.TestCase):
'show', 'Stats',
params={ 'owner' : 'Boss',
'name' : 'boot_time' }),
(0, self.const_datetime))
(0, {'Boss': {'boot_time': self.const_datetime}}))
self.assertEqual(
send_command(
'set', 'Stats',
......@@ -238,7 +238,7 @@ class TestStats(unittest.TestCase):
'show', 'Stats',
params={ 'owner' : 'Boss',
'name' : 'boot_time' }),
(0, self.const_datetime))
(0, {'Boss': {'boot_time': self.const_datetime}}))
self.assertEqual(
send_command('status', 'Stats'),
(0, "Stats is up. (PID " + str(os.getpid()) + ")"))
......@@ -321,25 +321,25 @@ class TestStats(unittest.TestCase):
my_statistics_data = self.stats.get_statistics_data()
self.assertTrue('Stats' in my_statistics_data)
self.assertTrue('Boss' in my_statistics_data)
self.assertTrue('boot_time' in my_statistics_data['Boss'])
my_statistics_data = self.stats.get_statistics_data(owner='Stats')
self.assertTrue('report_time' in my_statistics_data)
self.assertTrue('boot_time' in my_statistics_data)
self.assertTrue('last_update_time' in my_statistics_data)
self.assertTrue('timestamp' in my_statistics_data)
self.assertTrue('lname' in my_statistics_data)
self.assertTrue('Stats' in my_statistics_data)
self.assertTrue('report_time' in my_statistics_data['Stats'])
self.assertTrue('boot_time' in my_statistics_data['Stats'])
self.assertTrue('last_update_time' in my_statistics_data['Stats'])
self.assertTrue('timestamp' in my_statistics_data['Stats'])
self.assertTrue('lname' in my_statistics_data['Stats'])
self.assertRaises(stats.StatsError, self.stats.get_statistics_data, owner='Foo')
my_statistics_data = self.stats.get_statistics_data(owner='Stats')
self.assertTrue('boot_time' in my_statistics_data)
my_statistics_data = self.stats.get_statistics_data(owner='Stats', name='report_time')
self.assertEqual(my_statistics_data, self.const_default_datetime)
self.assertEqual(my_statistics_data['Stats']['report_time'], self.const_default_datetime)
my_statistics_data = self.stats.get_statistics_data(owner='Stats', name='boot_time')
self.assertEqual(my_statistics_data, self.const_default_datetime)
self.assertEqual(my_statistics_data['Stats']['boot_time'], self.const_default_datetime)
my_statistics_data = self.stats.get_statistics_data(owner='Stats', name='last_update_time')
self.assertEqual(my_statistics_data, self.const_default_datetime)
self.assertEqual(my_statistics_data['Stats']['last_update_time'], self.const_default_datetime)
my_statistics_data = self.stats.get_statistics_data(owner='Stats', name='timestamp')
self.assertEqual(my_statistics_data, 0.0)
self.assertEqual(my_statistics_data['Stats']['timestamp'], 0.0)
my_statistics_data = self.stats.get_statistics_data(owner='Stats', name='lname')
self.assertEqual(my_statistics_data, '')
self.assertEqual(my_statistics_data, {'Stats': {'lname':''}})
self.assertRaises(stats.StatsError, self.stats.get_statistics_data,
owner='Stats', name='Bar')
self.assertRaises(stats.StatsError, self.stats.get_statistics_data,
......@@ -385,25 +385,25 @@ class TestStats(unittest.TestCase):
1, "specified arguments are incorrect: owner: Foo, name: bar"))
self.assertEqual(self.stats.command_show(owner='Auth'),
isc.config.create_answer(
0, { 'queries.udp': 0,
0, {'Auth':{ 'queries.udp': 0,
'queries.tcp': 0,
'queries.perzone': [{ 'zonename': 'test1.example',
'queries.udp': 1,
'queries.tcp': 2 },
{ 'zonename': 'test2.example',
'queries.udp': 3,
'queries.tcp': 4 }] }))
'queries.tcp': 4 }] }}))
self.assertEqual(self.stats.command_show(owner='Auth', name='queries.udp'),
isc.config.create_answer(
0, 0))
0, {'Auth': {'queries.udp':0}}))
self.assertEqual(self.stats.command_show(owner='Auth', name='queries.perzone'),
isc.config.create_answer(
0, [{ 'zonename': 'test1.example',
0, {'Auth': {'queries.perzone': [{ 'zonename': 'test1.example',
'queries.udp': 1,
'queries.tcp': 2 },
{ 'zonename': 'test2.example',
'queries.udp': 3,
'queries.tcp': 4 }]))
'queries.tcp': 4 }]}}))
orig_get_timestamp = stats.get_timestamp
orig_get_datetime = stats.get_datetime
stats.get_timestamp = lambda : self.const_timestamp
......@@ -411,7 +411,7 @@ class TestStats(unittest.TestCase):
self.assertEqual(stats.get_timestamp(), self.const_timestamp)
self.assertEqual(stats.get_datetime(), self.const_datetime)
self.assertEqual(self.stats.command_show(owner='Stats', name='report_time'), \
isc.config.create_answer(0, self.const_datetime))
isc.config.create_answer(0, {'Stats': {'report_time':self.const_datetime}}))
self.assertEqual(self.stats.statistics_data['Stats']['timestamp'], self.const_timestamp)
self.assertEqual(self.stats.statistics_data['Stats']['boot_time'], self.const_default_datetime)
stats.get_timestamp = orig_get_timestamp
......@@ -473,10 +473,10 @@ class TestStats(unittest.TestCase):
(rcode, value) = isc.config.ccsession.parse_answer(
self.stats.command_showschema(owner='Stats'))
self.assertEqual(rcode, 0)
self.assertFalse('Stats' in value)
self.assertTrue('Stats' in value)
self.assertFalse('Boss' in value)
self.assertFalse('Auth' in value)
for item in value:
for item in value['Stats']:
self.assertTrue(len(item) == 6 or len(item) == 7)
self.assertTrue('item_name' in item)
self.assertTrue('item_type' in item)
......@@ -490,19 +490,19 @@ class TestStats(unittest.TestCase):
(rcode, value) = isc.config.ccsession.parse_answer(
self.stats.command_showschema(owner='Stats', name='report_time'))
self.assertEqual(rcode, 0)
self.assertFalse('Stats' in value)
self.assertTrue('Stats' in value)
self.assertFalse('Boss' in value)
self.assertFalse('Auth' in value)
self.assertTrue(len(value) == 7)
self.assertTrue('item_name' in value)
self.assertTrue('item_type' in value)
self.assertTrue('item_optional' in value)
self.assertTrue('item_default' in value)
self.assertTrue('item_title' in value)
self.assertTrue('item_description' in value)
self.assertTrue('item_format' in value)
self.assertEqual(value['item_name'], 'report_time')
self.assertEqual(value['item_format'], 'date-time')
self.assertEqual(len(value['Stats'][0]), 7)
self.assertTrue('item_name' in value['Stats'][0])
self.assertTrue('item_type' in value['Stats'][0])
self.assertTrue('item_optional' in value['Stats'][0])
self.assertTrue('item_default' in value['Stats'][0])
self.assertTrue('item_title' in value['Stats'][0])
self.assertTrue('item_description' in value['Stats'][0])
self.assertTrue('item_format' in value['Stats'][0])
self.assertEqual(value['Stats'][0]['item_name'], 'report_time')
self.assertEqual(value['Stats'][0]['item_format'], 'date-time')
self.assertEqual(self.stats.command_showschema(owner='Foo'),
isc.config.create_answer(
......@@ -512,7 +512,7 @@ class TestStats(unittest.TestCase):
1, "specified arguments are incorrect: owner: Foo, name: bar"))
self.assertEqual(self.stats.command_showschema(owner='Auth'),
isc.config.create_answer(
0, [{
0, {'Auth': [{
"item_default": 0,
"item_description": "A number of total query counts which all auth servers receive over TCP since they started initially",
"item_name": "queries.tcp",
......@@ -578,20 +578,20 @@ class TestStats(unittest.TestCase):
}
]
}
}]))
}]}))
self.assertEqual(self.stats.command_showschema(owner='Auth', name='queries.tcp'),
isc.config.create_answer(
0, {
0, {'Auth': [{
"item_default": 0,
"item_description": "A number of total query counts which all auth servers receive over TCP since they started initially",
"item_name": "queries.tcp",
"item_optional": False,
"item_title": "Queries TCP",
"item_type": "integer"
}))
}]}))
self.assertEqual(self.stats.command_showschema(owner='Auth', name='queries.perzone'),
isc.config.create_answer(
0, {
0, {'Auth':[{
"item_name": "queries.perzone",
"item_type": "list",
"item_optional": False,
......@@ -641,7 +641,7 @@ class TestStats(unittest.TestCase):
}
]
}
}))
}]}))
self.assertEqual(self.stats.command_showschema(owner='Stats', name='bar'),
isc.config.create_answer(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment