<s> import unittest <EOL> import random <EOL> from testlib import get_fixture <EOL> import pyeapi . client <EOL> class DutSystemTest ( unittest . TestCase ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( DutSystemTest , self ) . __init__ ( * args , ** kwargs ) <EOL> self . longMessage = True <EOL> def setUp ( self ) : <EOL> pyeapi . client . load_config ( filename = get_fixture ( '<STR_LIT>' ) ) <EOL> config = pyeapi . client . config <EOL> self . duts = list ( ) <EOL> for name in config . sections ( ) : <EOL> if name . startswith ( '<STR_LIT>' ) and '<STR_LIT:localhost>' not in name : <EOL> name = name . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] <EOL> self . duts . append ( pyeapi . client . connect_to ( name ) ) <EOL> def sort_dict_by_keys ( self , d ) : <EOL> keys = sorted ( d . keys ( ) ) <EOL> return dict ( [ ( k , d [ k ] ) for k in keys ] ) <EOL> def random_interface ( dut , exclude = None ) : <EOL> exclude = [ ] if exclude is None else exclude <EOL> interfaces = dut . api ( '<STR_LIT>' ) <EOL> names = [ name for name in list ( interfaces . keys ( ) ) if name . startswith ( '<STR_LIT>' ) ] <EOL> exclude_interfaces = dut . settings . get ( '<STR_LIT>' , [ ] ) <EOL> if exclude_interfaces : <EOL> exclude_interfaces = exclude_interfaces . split ( '<STR_LIT:U+002C>' ) <EOL> exclude_interfaces . extend ( exclude ) <EOL> if sorted ( exclude_interfaces ) == sorted ( names ) : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> choices = set ( names ) . difference ( exclude ) <EOL> return random . choice ( list ( choices ) ) </s>
