2 Python invocation of several parallel publish-notifications RPCs.
4 from robot.api import logger
14 def _send_http_request_thread_impl(rqueue, url, data, http_timeout):
15 """Start either publish or write transactions rpc based on input.
17 :param rqueue: result queue
18 :type rqueue: Queue.Queue
21 :param data: http request content
23 :param http_timeout: http response timeout
24 :type http_timeout: int
26 logger.info('rpc indoked with details: {}'.format(data))
28 resp = requests.post(url=url, headers={'Content-Type': 'application/xml'},
29 data=data, auth=('admin', 'admin'), timeout=http_timeout)
30 except Exception as exc:
36 def _initiate_rpcs(host_list, prefix_list, url_templ, data_templ, subst_dict):
37 """Initiate rpc on given hosts.
39 :param host_list: list of ip address of odl nodes
40 :type host_list: list of strings
41 :param id_prefix: list of node indexes which coresponds to the ip addresses
42 :type id_prefix: string
43 :param url_templ: url template
44 :type url_templ: string.Template object
45 :param data_templ: http request data
46 :type data_templ: string.Template object
47 :param subst_dict: dictionary with key value pairs to be used with template
48 :type subst_dict: dict
50 resqueue = _globals.pop('result_queue', Queue.Queue())
51 lthreads = _globals.pop('threads', [])
52 for i, host in enumerate(host_list):
53 subst_dict.update({'ID': '{}{}'.format(subst_dict['ID_PREFIX'], prefix_list[i])})
54 url = url_templ.substitute({'HOST': host})
55 data = data_templ.substitute(subst_dict)
56 timeout = int(subst_dict['DURATION'])+60
57 logger.info('url: {}, data: {}, timeout: {}'.format(url, data, timeout))
58 t = threading.Thread(target=_send_http_request_thread_impl,
59 args=(resqueue, url, data, timeout))
64 _globals.update({'threads': lthreads, 'result_queue': resqueue})
67 def start_write_transactions_on_nodes(host_list, prefix_list, id_prefix, duration, rate, chained_flag=False):
68 """Invoke write-transactions rpc on given nodes.
70 :param host_list: list of ip address of odl nodes
71 :type host_list: list of strings
72 :param prefix_list: list of node indexes which coresponds to the ip addresses
73 :type prefix_list: list
74 :param id_prefix: identifier prefix
75 :type id_prefix: string
76 :param duration: time in seconds
78 :param rate: writing transactions rate in transactions per second
80 :param chained_flag: specify chained vs. simple transactions
81 :type chained_flag: bool
84 "Input parameters: host_list:{}, prefix_list:{}, id_prefix:{}, duration:{}, rate:{}, chained_flag:{}".format(
85 host_list, prefix_list, id_prefix, duration, rate, chained_flag))
86 datat = string.Template('''<input xmlns="tag:opendaylight.org,2017:controller:yang:lowlevel:control">
88 <seconds>$DURATION</seconds>
89 <transactions-per-second>$RATE</transactions-per-second>
90 <chained-transactions>$CHAINED_FLAG</chained-transactions>
92 subst_dict = {'ID_PREFIX': id_prefix, 'DURATION': duration, 'RATE': rate, 'CHAINED_FLAG': chained_flag}
93 urlt = string.Template('''http://$HOST:8181/restconf/operations/odl-mdsal-lowlevel-control:write-transactions''')
94 _initiate_rpcs(host_list, prefix_list, urlt, datat, subst_dict)
97 def start_produce_transactions_on_nodes(host_list, prefix_list, id_prefix,
98 duration, rate, isolated_transactions_flag=True):
99 """Invoke produce-transactions rpcs on given nodes.
101 :param host_list: list of ip address of odl nodes
102 :type host_list: list of strings
103 :param prefix_list: list of node indexes which coresponds to the ip addresses
104 :type prefix_list: list
105 :param id_prefix: identifier prefix
106 :type id_prefix: string
107 :param duration: time in seconds
109 :param rate: produce transactions rate in transactions per second
111 :param isolated_transactions_flag: isolated transactions flag
112 :type isolated_transactions_flag: bool
114 msg = "host_list:{}, prefix_list:{} ,id_prefix:{}, duration:{}, rate:{}, isolated_transactions:{}".format(
115 host_list, prefix_list, id_prefix, duration, rate, isolated_transactions_flag)
116 msg = "Input parameters: " + msg
118 datat = string.Template('''<input xmlns="tag:opendaylight.org,2017:controller:yang:lowlevel:control">
120 <seconds>$DURATION</seconds>
121 <transactions-per-second>$RATE</transactions-per-second>
122 <isolated-transactions>$ISOLATED_TRANSACTIONS</isolated-transactions>
124 subst_dict = {'ID_PREFIX': id_prefix, 'DURATION': duration, 'RATE': rate,
125 'ISOLATED_TRANSACTIONS': isolated_transactions_flag}
126 urlt = string.Template('''http://$HOST:8181/restconf/operations/odl-mdsal-lowlevel-control:produce-transactions''')
127 _initiate_rpcs(host_list, prefix_list, urlt, datat, subst_dict)
130 def wait_for_transactions():
131 """Blocking call, waitig for responses from all threads."""
132 lthreads = _globals.pop('threads')
133 resqueue = _globals.pop('result_queue')
139 while not resqueue.empty():
140 results.append(resqueue.get())
145 def get_next_transactions_response():
146 """Get http response from write-transactions rpc if available."""
147 resqueue = _globals.get('result_queue')
149 if not resqueue.empty():
150 return resqueue.get()