Factory class for creating auth keys with unique conf key ID
| 110 | |
| 111 | |
| 112 | class AuthKeyFactory(object): |
| 113 | """Factory class for creating auth keys with unique conf key ID""" |
| 114 | |
| 115 | def __init__(self): |
| 116 | self._conf_key_ids = {} |
| 117 | |
| 118 | def create_random_key(self, test, auth_type=BFDAuthType.keyed_sha1): |
| 119 | """create a random key with unique conf key id""" |
| 120 | conf_key_id = randint(0, 0xFFFFFFFF) |
| 121 | while conf_key_id in self._conf_key_ids: |
| 122 | conf_key_id = randint(0, 0xFFFFFFFF) |
| 123 | self._conf_key_ids[conf_key_id] = 1 |
| 124 | key = scapy.compat.raw( |
| 125 | bytearray([randint(0, 255) for _ in range(randint(1, 20))]) |
| 126 | ) |
| 127 | return VppBFDAuthKey( |
| 128 | test=test, auth_type=auth_type, conf_key_id=conf_key_id, key=key |
| 129 | ) |
| 130 | |
| 131 | |
| 132 | @parameterized_class( |