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)
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 test_dc_dns_modify(ensure_synced, scenario): """ Update DNS servers on central region and check it is propagated to subclouds Args: ensure_synced: test fixture scenario: DNS change scenario Setups: - Ensure primary subcloud is managed and DNS config is valid and synced Test Steps: - Un-manage primary subcloud - Configure DNS servers on central region to new value based on given scenario - Wait for new DNS config to sync over to managed online subclouds - Ensure DNS config is not updated on unmanaged primary subcloud - Re-manage primary subcloud and ensure DNS config syncs over - Verify nslookup works in Central Region and primary subcloud Teardown: - Reset DNS servers to original value (module) """ primary_subcloud, managed_subclouds, prev_dns_servers = ensure_synced new_dns_servers = compose_new_dns_servers( scenario=scenario, prev_dns_servers=prev_dns_servers) LOG.tc_step("Unmanage {}".format(primary_subcloud)) dc_helper.unmanage_subcloud(subcloud=primary_subcloud, check_first=True) LOG.tc_step( "Reconfigure DNS servers on central region from {} to {}".format( prev_dns_servers, new_dns_servers)) system_helper.set_dns_servers(new_dns_servers, auth_info=Tenant.get('admin_platform', dc_region='RegionOne')) LOG.tc_step( "Wait for new DNS config to sync over to managed online subclouds") for managed_sub in managed_subclouds: dc_helper.wait_for_subcloud_dns_config(subcloud=managed_sub, expected_dns=new_dns_servers) LOG.tc_step( "Ensure DNS config is not updated on unmanaged subcloud: {}".format( primary_subcloud)) code = dc_helper.wait_for_subcloud_dns_config(subcloud=primary_subcloud, expected_dns=new_dns_servers, timeout=60, fail_ok=True)[0] assert 1 == code, "Actual return code: {}".format(code) LOG.tc_step('Re-manage {} and ensure DNS config syncs over'.format( primary_subcloud)) dc_helper.manage_subcloud(subcloud=primary_subcloud, check_first=False) dc_helper.wait_for_subcloud_dns_config(subcloud=primary_subcloud, expected_dns=new_dns_servers) LOG.tc_step('Verify nslookup works in Central Region and {}'.format( primary_subcloud)) verify_dns_on_central_and_subcloud(primary_subcloud)
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))
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)
def test_dc_dns_override_local_change(ensure_synced): """ Verify DNS modification on subcloud will be overridden by central region config Args: ensure_synced: test fixture Setups: - Ensure primary subcloud is managed and DNS config is valid and synced Test Steps: - Un-manage primary subcloud - Configure DNS servers on primary subcloud to a unreachable ip address (8.4.4.4) - Wait for sync log for any managed subcloud with best effort - Ensure DNS config is not updated on unmanaged primary subcloud - Verify nslookup passes on central region and fails on primary subcloud - Re-manage primary subcloud and ensure DNS config syncs over - Verify nslookup in Central Region and primary subcloud are working as expected Teardown: - Manage primary subcloud if not managed (module) - Reset DNS servers to original value on central region (module) """ primary_subcloud, managed_subclouds, sc_dns = ensure_synced new_dns_servers = compose_new_dns_servers(scenario='unreachable_server', prev_dns_servers=sc_dns) LOG.tc_step("Unmanage {}".format(primary_subcloud)) dc_helper.unmanage_subcloud(subcloud=primary_subcloud, check_first=True) LOG.tc_step("Reconfigure DNS on {} from {} to {}".format( primary_subcloud, sc_dns, new_dns_servers)) system_helper.set_dns_servers(new_dns_servers, auth_info=Tenant.get( 'admin_platform', dc_region=primary_subcloud)) managed_cloud = managed_subclouds[0] if managed_subclouds else '' LOG.tc_step( "Wait for sync update log for managed subcloud {} with best effort". format(managed_cloud)) dc_helper.wait_for_sync_audit(subclouds=managed_cloud, fail_ok=True, timeout=660) LOG.tc_step( "Ensure DNS config is not updated on unmanaged subcloud: {}".format( primary_subcloud)) code = dc_helper.wait_for_subcloud_dns_config(subcloud=primary_subcloud, expected_dns=sc_dns, fail_ok=True, timeout=60)[0] assert 1 == code, "Actual return code: {}".format(code) LOG.tc_step("Verify nslookup fails on {}".format(primary_subcloud)) central_res, local_res = verify_dns_on_central_and_subcloud( primary_subcloud, fail_ok=True, sc_dns=sc_dns) assert 0 == central_res, "nslookup failed on central region" assert 1 == local_res, "nslookup succeeded on {} with unreachable DNS servers configured".\ format(primary_subcloud) central_auth = Tenant.get('admin_platform', dc_region='RegionOne') if system_helper.get_standby_controller_name(auth_info=central_auth): LOG.tc_step("Swact in central region") host_helper.swact_host(auth_info=central_auth) LOG.tc_step( 'Re-manage {} and ensure local DNS config is overridden by central config' .format(primary_subcloud)) dc_helper.manage_subcloud(subcloud=primary_subcloud, check_first=False) dc_helper.wait_for_subcloud_dns_config(subcloud=primary_subcloud, expected_dns=sc_dns) LOG.tc_step('Verify nslookup works in Central Region and {}'.format( primary_subcloud)) verify_dns_on_central_and_subcloud(primary_subcloud, sc_dns=sc_dns)