Merge "Validate the fixed ip address passed with --nic"
This commit is contained in:
commit
60997a5997
@ -561,6 +561,16 @@ class ShellTest(utils.TestCase):
|
||||
'--nic port-id=some=port,net-id=some=net some-server')
|
||||
self.assertRaises(exceptions.CommandError, self.run_command, cmd)
|
||||
|
||||
def test_boot_nics_invalid_ipv4(self):
|
||||
cmd = ('boot --image 1 --flavor 1 '
|
||||
'--nic net-id=a=c,v4-fixed-ip=2001:db9:0:1::10 some-server')
|
||||
self.assertRaises(exceptions.CommandError, self.run_command, cmd)
|
||||
|
||||
def test_boot_nics_invalid_ipv6(self):
|
||||
cmd = ('boot --image 1 --flavor 1 '
|
||||
'--nic net-id=a=c,v6-fixed-ip=10.0.0.1 some-server')
|
||||
self.assertRaises(exceptions.CommandError, self.run_command, cmd)
|
||||
|
||||
def test_boot_files(self):
|
||||
testfile = os.path.join(os.path.dirname(__file__), 'testfile.txt')
|
||||
with open(testfile) as testfile_fd:
|
||||
|
@ -30,6 +30,7 @@ import time
|
||||
import warnings
|
||||
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import netutils
|
||||
from oslo_utils import strutils
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
@ -288,6 +289,14 @@ def _boot(cs, args):
|
||||
else:
|
||||
raise exceptions.CommandError(err_msg)
|
||||
|
||||
if nic_info['v4-fixed-ip'] and not netutils.is_valid_ipv4(
|
||||
nic_info['v4-fixed-ip']):
|
||||
raise exceptions.CommandError(_("Invalid ipv4 address."))
|
||||
|
||||
if nic_info['v6-fixed-ip'] and not netutils.is_valid_ipv6(
|
||||
nic_info['v6-fixed-ip']):
|
||||
raise exceptions.CommandError(_("Invalid ipv6 address."))
|
||||
|
||||
if bool(nic_info['net-id']) == bool(nic_info['port-id']):
|
||||
raise exceptions.CommandError(err_msg)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user