1 # Copyright (c) 2016 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """Robot framework variable file.
16 Create dictionary variable nodes_ipv6_addr with IPv6 adresses from available
20 from IPv6Setup import IPv6Networks
21 from topology import Topology
23 # Default list of available IPv6 networks
24 IPV6_NETWORKS = ['db01::/64', 'db02::/64', 'db03::/64']
27 def get_variables(nodes, networks=IPV6_NETWORKS):
28 """Special robot framework method that returns dictionary nodes_ipv6_addr,
29 mapping of node and interface name to IPv6 adddress.
31 :param nodes: Nodes of the test topology.
32 :param networks: list of available IPv6 networks
37 Robot framework calls it automatically.
40 links = topo.get_links(nodes)
42 if len(links) > len(networks):
43 raise Exception('Not enough available IPv6 networks for topology.')
45 ip6_n = IPv6Networks(networks)
50 ip6_net = ip6_n.next_network()
51 net_hosts = ip6_net.hosts()
54 for node in nodes.values():
55 if_name = topo.get_interface_by_link_name(node, link)
56 if if_name is not None:
57 port = {'addr': str(next(net_hosts)),
61 port_id = 'port{0}'.format(port_idx)
62 ports.update({port_id: port})
63 nets.update({link: {'net_addr': str(ip6_net.network_address),
64 'prefix': ip6_net.prefixlen,
67 return {'DICT__nodes_ipv6_addr': nets}