Skip to content
This repository was archived by the owner on Jun 27, 2018. It is now read-only.

Commit a84f519

Browse files
committed
testwise checks in automated bucket testing
1 parent 1cba74f commit a84f519

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

pyretic/examples/bucket.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ def static_fwding_cycle_3_3():
6767

6868
class QueryTest(CountBucket):
6969

70-
def __init__(self):
70+
def __init__(self, test_num=None):
7171
super(QueryTest, self).__init__()
7272
self.register_callback(self.query_callback)
73+
self.test_num = test_num if test_num else id(self)
7374
import threading
7475
self.query_thread = threading.Thread(target=self.query_thread)
7576
self.query_thread.daemon = True
@@ -84,14 +85,14 @@ def query_thread(self):
8485
output += self.get_matches()
8586
# print output
8687
self.pull_stats()
87-
print ">>>", str(datetime.now()), ('issued query %d, sleeping for %f' %
88-
(id(self), interval))
88+
print ">>>", str(datetime.now()), ('issued query %s, sleeping for %f' %
89+
(str(self.test_num), interval))
8990
time.sleep(interval)
9091

9192
def query_callback(self, counts):
9293
print "***", str(datetime.now()), "| In user callback for bucket",
93-
print id(self)
94-
print "Bucket", id(self), "(packet, byte) counts:", counts
94+
print self.test_num
95+
print "Bucket", self.test_num, "(packet, byte) counts:", counts
9596
print "-----------------------------------"
9697

9798
def test0():
@@ -112,7 +113,7 @@ def test0():
112113
number of packets/bytes displayed by wireshark or tshark with these
113114
filters. They are designed to work under topology and policy updates.
114115
"""
115-
test_bucket = QueryTest()
116+
test_bucket = QueryTest(0)
116117
return test_bucket
117118

118119
def test1():
@@ -127,7 +128,7 @@ def test1():
127128
arp.dst.proto_ipv4 == 10.0.2.0/24) ) or ipv6 ) ) and ( ip.src ==
128129
10.0.0.1 || (arp && arp.src.proto_ipv4 == 10.0.0.1) )
129130
"""
130-
test_bucket = QueryTest()
131+
test_bucket = QueryTest(1)
131132
return (match(srcip=ip1) >> test_bucket)
132133

133134
def test2():
@@ -153,7 +154,7 @@ def test2():
153154
"""
154155
b = [] # counting buckets
155156
for i in range(0,2):
156-
b.append(QueryTest())
157+
b.append(QueryTest('2.b%d' % i))
157158
time.sleep(0.2)
158159

159160
pol1 = (match(ethtype=IP_TYPE) & match(srcip=ip1)) >> b[0]
@@ -186,7 +187,7 @@ def test3():
186187
"""
187188
b = [] # counting buckets
188189
for i in range(0,2):
189-
b.append(QueryTest())
190+
b.append(QueryTest('3.b%d' % i))
190191
time.sleep(0.2)
191192

192193
pol1 = match(srcip=ip1) >> b[0]
@@ -221,7 +222,7 @@ def test4():
221222
"""
222223
b = [] # counting buckets
223224
for i in range(0,3):
224-
b.append(QueryTest())
225+
b.append(QueryTest('4.b%d' % i))
225226
time.sleep(0.2)
226227

227228
query1 = match(srcip=ip1) >> match(dstip=ip2) >> b[0]
@@ -245,7 +246,7 @@ def test5():
245246
(arp.dst.proto_ipv4 == 10.0.0.1 || arp.dst.proto_ipv4 == 10.0.0.2 ||
246247
arp.dst.proto_ipv4 == 10.0.0.3) ) )
247248
"""
248-
test_bucket = QueryTest()
249+
test_bucket = QueryTest(5)
249250
matched_traffic = ( (~match(srcip=ip1) & match(dstip=ip2)) +
250251
(~match(srcip=ip1) & match(dstip=ip3)) +
251252
(~match(srcip=ip1) & match(dstip=ip1)) )
@@ -264,7 +265,7 @@ def test6():
264265
( (ip && ip.src == 10.0.0.1 ) or (arp && arp.src.proto_ipv4 == 10.0.0.1) or
265266
ipv6))
266267
"""
267-
test_bucket = QueryTest()
268+
test_bucket = QueryTest(6)
268269
matched_traffic = ~match(srcip=ip1)
269270
return (matched_traffic >> test_bucket)
270271

@@ -280,7 +281,7 @@ def test7():
280281
arp.dst.proto_ipv4 == 10.0.2.0/24) ) or ipv6 ) ) and (ip.dst == 10.0.0.1 ||
281282
(arp && (arp.dst.proto_ipv4 == 10.0.0.1 ) ) )
282283
"""
283-
return ( (match(dstip=ip1) >> QueryTest()) +
284+
return ( (match(dstip=ip1) >> QueryTest(7)) +
284285
(match(dstip=ip1) >> Controller) )
285286

286287
def parse_args(kwargs, defaults):

pyretic/tests/test_bucket.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,22 @@ def write_passfail_info(success_file, tshark_counts, buckets_counts, ctlr):
327327
def bucket_write_passfail_info(success_file, tshark_counts, buckets_counts):
328328
passfail = open(success_file, 'w')
329329
output_str = ''
330-
if set(tshark_counts.values()) == set(buckets_counts.values()):
331-
output_str += "PASS\n"
332-
else:
330+
if set(tshark_counts.keys()) != set(buckets_counts.keys()):
333331
output_str += "FAIL\n"
334-
output_str += "TShark: %s\n" % str(tshark_counts)
335-
output_str += "Bucket: %s\n" % str(buckets_counts)
332+
output_str += "Query references mismatch:\n"
333+
output_str += "TShark: %s\n" % str(tshark_counts.keys())
334+
output_str += "Bucket: %s\n" % str(buckets_counts.keys())
335+
elif True:
336+
for q in tshark_counts.keys():
337+
tc = tshark_counts[q]
338+
bc = buckets_counts[q]
339+
if tc != bc:
340+
output_str += "FAIL\n"
341+
output_str += "Query: %s\n" % q
342+
output_str += "TShark: %s\n" % str(tc)
343+
output_str += "Bucket: %s\n" % str(bc)
344+
if output_str == '':
345+
output_str += "PASS\n"
336346
print output_str
337347
passfail.write(output_str)
338348
passfail.close()

0 commit comments

Comments
 (0)