Improve dns format validation

Currently, if variable dns-nameserver is a list which
contains extra spaces, e.g., ',', then
validate_dns will fail and API will throw 400 Bad request.

This patch strips extra spaces before the dns format validation.

Change-Id: I8d7c94f42e9ea70009157c5de3dce75620ff5fe8
Story: 2006407
Task: 36291
Xingchao Yu 2019-08-16 00:44:18 +12:00
parent 04fd0470ad
commit 893e2cdf60
1 changed files with 1 additions and 1 deletions

View File

@ -127,7 +127,7 @@ def validate_dns(dns_list):
dns_nameservers = dns_list.split(',')
for dns in dns_nameservers:
netaddr.IPAddress(dns, version=4, flags=netaddr.INET_PTON)
netaddr.IPAddress(dns.strip(), version=4, flags=netaddr.INET_PTON)
except netaddr.AddrFormatError:
raise exception.InvalidDNS(dns=dns_list)