3 from robot.libraries.BuiltIn import BuiltIn
4 from robot.api import logger
6 from test_constants import *
8 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '../libraries/common'))
10 ex = BuiltIn().get_library_instance('execute_command')
11 crf_nodes = BuiltIn().get_library_instance('stack_infos').get_crf_nodes()
14 def tc_005_ssh_dns_server_check():
15 steps = ['step1_check_dns_server_replica_num_within_limits',
16 'step2_dns_server_port_check',
17 'step3_check_address_resolution']
18 common_utils.keyword_runner(steps)
21 def step1_check_dns_server_replica_num_within_limits():
22 command = "kubectl get daemonset kube-dns --namespace=kube-system | grep kube-dns | awk {'print $5'}"
23 available_dns_replica_num = int(ex.execute_unix_command(command))
24 if available_dns_replica_num < min_dns_replica:
25 raise Exception(available_dns_replica_num + "DNS server is running! Minimum should be " + min_dns_replica + ".")
26 if available_dns_replica_num > max_dns_replica:
27 raise Exception(available_dns_replica_num + "DNS server is running! Maximum should be " + max_dns_replica + ".")
30 def step2_dns_server_port_check():
31 nodes = get_nodes_containing_dns_servers()
32 check_program_listening_on_given_port_protocol_on_remote(nodes, 'dnsmasq', 'tcp', dns_masq_port)
33 check_program_listening_on_given_port_protocol_on_remote(nodes, 'kube-dns', 'tcp6', kube_dns_port)
36 def step3_check_address_resolution():
37 ex.execute_unix_command("getent hosts " + test_address1)
38 ex.execute_unix_command("getent hosts " + test_address2)
39 logger.console("Addresses are resolved successfully")
42 def get_nodes_containing_dns_servers():
45 for name, ip in crf_nodes.items():
46 command = 'docker ps | grep dnsmasq | wc -l'
47 stdout = int(ex.execute_unix_command_on_remote_as_user(command, ip))
49 logger.console('DNS server running on ' + name + ':' + ip)
52 raise Exception('Instead of one, ' + str(stdout) + ' DNS server running on node: ' + name + '!')
56 def check_program_listening_on_given_port_protocol_on_remote(nodes, pname, proto, port):
57 command = 'netstat -lopna | grep --color=no -P "' + proto + ' .*:' + port + '.*LISTEN.*"' + pname
58 for name, ip in nodes.items():
59 stdout = ex.execute_unix_command_on_remote_as_root(command, ip)
60 logger.console(name + ':' + stdout)