Make pep8 more picky
[integration/test.git] / csit / libraries / Common.py
1 """
2 Library for the robot based system test tool of the OpenDaylight project.
3 Authors: Baohua Yang@IBM, Denghui Huang@IBM
4 Updated: 2013-11-14
5 """
6 import collections
7
8 '''
9 Common constants and functions for the robot framework.
10 '''
11
12
13 def collection_should_contain(collection, *members):
14     """
15     Fail if not every members is in the collection.
16     """
17     if not isinstance(collection, collections.Iterable):
18         return False
19     for m in members:
20         if m not in collection:
21             return False
22     else:
23         return True
24
25
26 def combine_strings(*strings):
27     """
28     Combines the given `strings` together and returns the result.
29     The given strings are not altered by this keyword.
30     """
31     result = ''
32     for s in strings:
33         if isinstance(s, str) or isinstance(s, unicode):
34             result += s
35     if result == '':
36         return None
37     else:
38         return result
39
40
41 def compare_xml(xml1, xml2):
42     """
43     compare the two XML files to see if they contain the same data
44     but could be if different order.
45     It just split the xml in to lines and just check the line is in
46     the other file
47     """
48     for line in xml1.rstrip().split('\n'):
49         if line not in xml2.rstrip().split('\n'):
50             return False
51
52     for line in xml2.rstrip().split('\n'):
53         if line not in xml1.rstrip().split('\n'):
54             return False
55
56     return True
57
58
59 def num_of_nodes(depth, fanout):
60     '''returns num of switches of a mininet with tree topology
61     with particular depth and fanout parameters
62     '''
63     result = 0
64     for i in xrange(depth):
65         result += fanout**i
66     return result
67
68
69 def num_of_links_for_node(nodeid, leaflist, fanout):
70     '''
71     If the given node is a leaf node, there will be an only one link for it
72     and nodeid will be represented 2 times in topology
73     If the given node is not a leaf node, then there will be fanout+1 links
74     for it and nodeid will be represented (fanout+1)*2 times in topology
75
76     p.s. root node is excluded.
77     '''
78     if nodeid in leaflist:
79         return 1
80     return (fanout + 1)
81
82 if __name__ == '__main__':
83     print(num_of_nodes(3, 4))