From: Naoki Kambe Date: Fri, 17 Aug 2012 05:42:29 +0000 (+0900) Subject: [2158] added the lettuce step methods for statistics X-Git-Tag: trac2351_base~65^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b18cb62ebeea655fcc277a2478a9ee560a33408b;p=thirdparty%2Fkea.git [2158] added the lettuce step methods for statistics - added the two step methods and a helper method That is intended for querying statistics counters via bindctl and for checking whether the returned values of the counters are exactly expected ones. --- diff --git a/tests/lettuce/features/terrain/bind10_control.py b/tests/lettuce/features/terrain/bind10_control.py index b661657bce..b1c8aced7a 100644 --- a/tests/lettuce/features/terrain/bind10_control.py +++ b/tests/lettuce/features/terrain/bind10_control.py @@ -362,3 +362,64 @@ def configure_ddns_off(step): config commit \"\"\" """) + +@step('query statistics(?: (\S+))? of bind10 module (\S+)(?: with cmdctl port (\d+))?') +def query_statistics(step, statistics, name, cmdctl_port): + """ + query statistics data via bindctl. + Parameters: + statistics ('statistics ', optional) : The queried statistics name. + name ('module '): The name of the module (case sensitive!) + cmdctl_port ('with cmdctl port ', optional): cmdctl port to send + the command to. + """ + port_str = ' with cmdctl port %s' % cmdctl_port \ + if cmdctl_port else '' + step.given('send bind10%s the command Stats show owner=%s%s'\ + % (port_str, name,\ + ' name=%s' % statistics if statistics else '')) + +def find_value(dictionary, key): + """A helper method. Recursively find a value corresponding to the + key of the dictionary and returns it. Returns None if the + dictionary is not dict type.""" + if type(dictionary) is not dict: + return + if key in dictionary: + return dictionary[key] + else: + for v in dictionary.values(): + return find_value(v, key) + +@step('The counter (\S+)(?: for the zone (\S+))? should be' + \ + '(?:( greater than| less than))? (\d+)') +def check_statistics(step, counter, zone, gtlt, number): + """ + check the output of bindctl for statistics of specified counter + and zone. + Parameters: + counter ('counter '): The counter name of statistics. + zone ('zone ', optional): The zone name. + gtlt (' greater than'|' less than', optional): greater than + or less than . + number ('): The expect counter number. is assumed + to be an unsigned integer. + """ + output = parse_bindctl_output_as_data_structure() + found = None + zone_str = "" + if zone: + found = find_value(find_value(output, zone), counter) + zone_str = " for zone %s" % zone + else: + found = find_value(output, counter) + assert found is not None, \ + 'Not found statistics counter %s%s' % (counter, zone_str) + msg = "Got %s, expected%s %s as counter %s%s" % \ + (found, gtlt, number, counter, zone_str) + if gtlt and 'greater' in gtlt: + assert int(found) > int(number), msg + elif gtlt and 'less' in gtlt: + assert int(found) < int(number), msg + else: + assert int(found) == int(number), msg