def verify_dns_on_central_and_subcloud(primary_subcloud, fail_ok=False, sc_dns=None): res = [] for region in ('RegionOne', primary_subcloud): # take snapshot orig_dns_servers = system_helper.get_dns_servers( auth_info=Tenant.get('admin_platform', dc_region=region)) if not sc_dns or set(sc_dns) <= set(orig_dns_servers): LOG.info("Modify dns server to public dns") system_helper.set_dns_servers(nameservers=['8.8.8.8'], auth_info=Tenant.get( 'admin_platform', dc_region=region)) LOG.info("Check dns on {}".format(region)) con_ssh = ControllerClient.get_active_controller(name=region) code, out = con_ssh.exec_cmd('nslookup -timeout=1 www.google.com', fail_ok=fail_ok, expect_timeout=30) res.append(code) # revert system_helper.set_dns_servers(nameservers=orig_dns_servers, auth_info=Tenant.get('admin_platform', dc_region=region)) return res
def subclouds_to_test(request): LOG.info("Gather DNS config and subcloud management info") sc_auth = Tenant.get('admin_platform', dc_region='SystemController') dns_servers = system_helper.get_dns_servers(auth_info=sc_auth) subcloud = ProjVar.get_var('PRIMARY_SUBCLOUD') def revert(): LOG.fixture_step("Manage {} if unmanaged".format(subcloud)) dc_helper.manage_subcloud(subcloud) LOG.fixture_step("Revert DNS config if changed") system_helper.set_dns_servers(nameservers=dns_servers, auth_info=sc_auth) request.addfinalizer(revert) managed_subclouds = dc_helper.get_subclouds(mgmt='managed', avail='online') if subcloud in managed_subclouds: managed_subclouds.remove(subcloud) ssh_map = ControllerClient.get_active_controllers_map() managed_subclouds = [ subcloud for subcloud in managed_subclouds if subcloud in ssh_map ] return subcloud, managed_subclouds
def test_horizon_sysconfig_dns_cancel_edit(sys_config_pg): """ Test dns edit and display: Setups: - Login as Admin - Go to Admin > Platform > System Configuration Teardown: - Back to System Configuration Page - Logout Test Steps: - Check DNS display - Edit DNS but not submit """ LOG.tc_step('check DNS display') sys_config_pg.go_to_dns_tab() dns_list = system_helper.get_dns_servers() for i in range(len(dns_list)): cli_dns = dns_list[i] horizon_dns = sys_config_pg.get_dns_info( ip=dns_list[0], header='DNS Server {} IP'.format(i + 1)) assert cli_dns == horizon_dns, 'DNS Server {} IP display incorrectly' LOG.tc_step('Edit DNS but not submit') sys_config_pg.edit_dns(cancel=True) horizon.test_result = True
def ensure_synced(subclouds_to_test, check_central_alarms): primary_subcloud, managed_subclouds = subclouds_to_test LOG.fixture_step( "Ensure {} is managed and DNS config is valid and synced".format( primary_subcloud)) subcloud_auth = Tenant.get('admin_platform', dc_region=primary_subcloud) subcloud_dns = system_helper.get_dns_servers(con_ssh=None, auth_info=subcloud_auth) sc_dns = system_helper.get_dns_servers(con_ssh=None, auth_info=Tenant.get( 'admin_platform', dc_region='SystemController')) if subcloud_dns != sc_dns: dc_helper.manage_subcloud(subcloud=primary_subcloud, check_first=True) dc_helper.wait_for_subcloud_dns_config(subcloud=primary_subcloud, expected_dns=sc_dns) verify_dns_on_central_and_subcloud(primary_subcloud) return primary_subcloud, managed_subclouds, sc_dns
def backup_restore_dns_settings(self, request): """ Fixture to save the current DNS servers and restore them after test Args: request: request passed in by py.test system """ if ProjVar.get_var('IS_DC'): skip("Distributed Cloud has different procedure for " "DNS configuration.") self.dns_servers = system_helper.get_dns_servers(con_ssh=None) LOG.info('Save current DNS-servers:{}'.format(self.dns_servers)) def restore_dns_settings(): LOG.info('Restore the DNS-servers to the ' 'original:{}'.format(self.dns_servers)) system_helper.set_dns_servers(nameservers=self.dns_servers) request.addfinalizer(restore_dns_settings)
def test_change_dns_settings(self, new_dns_servers, with_action_option): """ Test changing the DNS servers of the system under test Args: - new_dns_servers(list): IP addresses of new DNS servers to change to. Both IPv4 and IPv6 are supported. Test Setups: - Do nothing, and delegate to the class-scope fixture to save the currently in-use DNS servers Test Steps: - Set the new DNS servers via CLI - Verify the DNS settings are successfully changed - Check the changes are saved to persistent storage Test Teardown: - Do nothing, and delegate to the class-scope fixture to restore the original DNS servers Notes: - This TC covers SysInv 5) Change the DNS server IP addresses using CLI """ LOG.tc_step('Validate the input IPs') ip_addr_list = [] expect_fail = False for server in new_dns_servers: ip_addr = network_helper.get_ip_address_str(server) if not ip_addr: # we know it will fail, for invalid IPs will be rejected LOG.info('Found invalid IP:{}'.format(server)) ip_addr_list.append(server) expect_fail = True continue ip_addr_list.append(ip_addr) if not ip_addr_list: skip('No valid IPs input for DNS servers, skip the test') return LOG.tc_step('\nSave the current DNS servers') old_dns_servers = system_helper.get_dns_servers() LOG.info('OK, current DNS servers: "{}" are saved\n'.format( old_dns_servers)) if with_action_option is not None and with_action_option.upper( ) == 'RANDOM': with_action_option = ''.join( random.choice(string.ascii_lowercase) for _ in range(6)) if with_action_option.upper() != 'APPLY': LOG.info('with_action_option.upper: "%s", expecting to fail', with_action_option.upper()) expect_fail = True LOG.tc_step( '\nAttempt to change the DNS servers to: {}'.format(ip_addr_list)) code, msg = system_helper.set_dns_servers( fail_ok=expect_fail, nameservers=ip_addr_list, with_action_option=with_action_option) if code == -1 and ip_addr_list == old_dns_servers: LOG.info( 'New DNS servers are the same as current DNS servers, PASS the test.\n%s, %s, %s, %s', 'attempting change to:', ip_addr_list, 'current:', old_dns_servers) elif expect_fail: assert code != 0, 'Request to change DNS servers should be rejected but not: new Servers: "{}", msg: "{}"'.\ format(ip_addr_list, msg) LOG.info( 'OK, attempt was rejected as expected to change DNS to: "{}"\n' .format(ip_addr_list)) LOG.tc_step( 'Verify DNS servers remain UNCHANGED as old: "{}"'.format( old_dns_servers)) code, output = self.wait_for_dns_changed(old_dns_servers) assert code == 0, \ 'In configuration DNS servers should remain unchanged:\nbefore: "{}"\nnow: "{}"'.format( old_dns_servers, output) else: assert 0 == code, 'Failed to change DNS servers to: "{}", msg: "{}"'.format( msg, ip_addr_list) LOG.tc_step( 'Verify in DB changed to new servers: {}'.format(ip_addr_list)) acutal_dns_servers = system_helper.get_dns_servers() assert list(acutal_dns_servers) == list(ip_addr_list), \ 'DNS servers were not changed, \nexpected:"{}"\nactual:"{}"\n'.format(ip_addr_list, acutal_dns_servers) LOG.info( 'OK, in DB, DNS servers changed to new IPs: "{}"\n'.format( ip_addr_list)) LOG.tc_step( 'Verify in configuration, DNS should change after wait {} seconds' .format(SysInvTimeout.DNS_SERVERS_SAVED)) LOG.info('Check if DNS changed or not in configuration\n') if with_action_option is None or with_action_option == 'apply': LOG.info( 'In this case, configuration should be updated with new DNS:{}' .format(ip_addr_list)) code, output = self.wait_for_dns_changed(ip_addr_list) assert code == 0, \ 'DNS in configuration is different from requested:\ninput:"{}"\n"in config: {}"'.format( ip_addr_list, output) else: LOG.info( 'In this case, configuration should remain UNCHANGED as old: "{}"' .format(old_dns_servers)) code, output = self.wait_for_dns_changed(old_dns_servers) assert code == 0, \ 'Saved DNS servers should remain unchanged:\nbefore: "{}"\nnow: "{}"'.format( old_dns_servers, output) LOG.info('OK, test setting DNS to "{}" passed'.format(ip_addr_list))