3666N/A#!/usr/bin/python
3666N/A
3666N/A# CDDL HEADER START
3666N/A#
3666N/A# The contents of this file are subject to the terms of the
3666N/A# Common Development and Distribution License, Version 1.0 only
3666N/A# (the "License"). You may not use this file except in compliance
3666N/A# with the License.
3666N/A#
6982N/A# You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
6982N/A# or http://forgerock.org/license/CDDLv1.0.html.
3666N/A# See the License for the specific language governing permissions
3666N/A# and limitations under the License.
3666N/A#
3666N/A# When distributing Covered Code, include this CDDL HEADER in each
6982N/A# file and include the License file at legal-notices/CDDLv1_0.txt.
6982N/A# If applicable, add the following below this CDDL HEADER, with the
6982N/A# fields enclosed by brackets "[]" replaced with your own identifying
3666N/A# information:
3666N/A# Portions Copyright [yyyy] [name of copyright owner]
3666N/A#
3666N/A# CDDL HEADER END
3666N/A#
3666N/A#
3666N/A# Copyright 2008 Sun Microsystems, Inc.
3666N/A
3666N/A__version__ = "$Revision$"
3666N/A# $Source$
3666N/A
3666N/A# public symbols
3666N/A__all__ = [ "create_table_fromoutput",
3666N/A "compare_snmp_values",
3666N/A "get_handler_count",
3666N/A "get_handler_index" ]
3666N/A
3666N/Adef create_table_fromoutput(output):
3666N/A table = {}
3666N/A separator = '='
3666N/A start= 'ds'
3666N/A
3666N/A for line in output.splitlines():
3666N/A if line.startswith('ds'):
4723N/A key = line.split(separator,1)[0].strip()
3666N/A try:
4723N/A value = line.split(separator,1)[1].strip()
3666N/A except IndexError:
3666N/A value = '-'
3666N/A table[key] = value
3666N/A
3666N/A return table
3666N/A
3671N/Adef compare_snmp_values(refTable, newTable, index):
3666N/A import re
3666N/A
3666N/A result = ''
3666N/A
3666N/A refKeys=newTable.keys()
3666N/A for refKey in refKeys:
3666N/A if not refTable.has_key(refKey):
3666N/A result = result + 'ERROR: Entry ' + refKey + ' does not exists'
3666N/A result = result + ' in the reference table.\n'
3666N/A
3666N/A refKeys=refTable.keys()
3666N/A for refKey in refKeys:
3666N/A if not newTable.has_key(refKey):
3666N/A result = result + 'ERROR: Entry ' + refKey + ' does not exists'
3666N/A result = result + ' in the new table.\n'
3666N/A else:
3671N/A result = result + refKey + '=> expected: ' + refTable[refKey]
3666N/A result = result + ' , result: ' + newTable[refKey] + '\n'
3666N/A
3671N/A pattern1 = 'dsApplIfOutBytes.%s' % index
3671N/A pattern2 = 'dsApplIfInBytes.%s' % index
3671N/A if refKey == pattern1 or refKey == pattern2:
3671N/A if int(newTable[refKey]) <= int(refTable[refKey]):
3671N/A result = result + 'ERROR: Value for ' + refKey
3666N/A result = result + ' should be greater.\n'
3666N/A else:
3666N/A if refTable[refKey] != newTable[refKey]:
3671N/A result = result + 'ERROR: Value for ' + refKey
3666N/A result = result + ' should be the same.\n'
3666N/A
3666N/A return result
3666N/A
3666N/Adef get_handler_count(table):
3666N/A import re
3666N/A
3666N/A count = 0
3666N/A
3666N/A keys=table.keys()
3666N/A for key in keys:
3666N/A pattern = re.compile('dsApplIfProtocol\..*')
3666N/A if pattern.search(key) != None:
3666N/A count = count + 1
3666N/A
3666N/A return count
3666N/A
3666N/Adef get_handler_index(table, handler):
3666N/A import re
3666N/A
3666N/A index = 0
3666N/A
3666N/A keys=table.keys()
3666N/A for key in keys:
3666N/A pattern = re.compile('dsApplIfProtocol\..*')
3666N/A if pattern.search(key) != None:
3666N/A if table[key] == handler:
3666N/A regexp = re.compile('^.*\.')
3666N/A index = re.sub(regexp, '', key)
3666N/A break
3666N/A
3666N/A return index