Add netdevice value type
While it is just a copy of the netaddress regexp, they may diverge later and users should be able to continue using the appropriate one. Change-Id: Ib6d96113f16fc5f4dc4b8918d2409d08e317a47d Closes-Bug: #1262786
This commit is contained in:
@@ -200,7 +200,8 @@ def parse_opts(argv):
|
|||||||
parser.add_argument('--type', default='default',
|
parser.add_argument('--type', default='default',
|
||||||
help='exit with error if the specified --key does not'
|
help='exit with error if the specified --key does not'
|
||||||
' match type. Valid types are'
|
' match type. Valid types are'
|
||||||
' <int|default|netaddress|dsn|swiftdevices|raw>')
|
' <int|default|netaddress|netdevice|dsn|'
|
||||||
|
'swiftdevices|raw>')
|
||||||
parser.add_argument('--key-default',
|
parser.add_argument('--key-default',
|
||||||
help='This option only affects running with --key.'
|
help='This option only affects running with --key.'
|
||||||
' Print this if key is not found. This value is'
|
' Print this if key is not found. This value is'
|
||||||
|
|||||||
@@ -71,6 +71,23 @@ class ValueTypeTestCase(testtools.TestCase):
|
|||||||
self.assertRaises(config_exception.ConfigException,
|
self.assertRaises(config_exception.ConfigException,
|
||||||
value_types.ensure_type, "192.0.2.1;DROP TABLE foo")
|
value_types.ensure_type, "192.0.2.1;DROP TABLE foo")
|
||||||
|
|
||||||
|
def test_netdevice(self):
|
||||||
|
self.assertEqual('eth0',
|
||||||
|
value_types.ensure_type('eth0', 'netdevice'))
|
||||||
|
|
||||||
|
def test_netdevice_dash(self):
|
||||||
|
self.assertEqual('br-ctlplane',
|
||||||
|
value_types.ensure_type('br-ctlplane', 'netdevice'))
|
||||||
|
|
||||||
|
def test_netdevice_alias(self):
|
||||||
|
self.assertEqual('eth0:1',
|
||||||
|
value_types.ensure_type('eth0:1', 'netdevice'))
|
||||||
|
|
||||||
|
def test_netdevice_bad(self):
|
||||||
|
self.assertRaises(config_exception.ConfigException,
|
||||||
|
value_types.ensure_type, "br-tun; DROP TABLE bar",
|
||||||
|
'netdevice')
|
||||||
|
|
||||||
def test_dsn_nopass(self):
|
def test_dsn_nopass(self):
|
||||||
test_dsn = 'mysql://user@host/db'
|
test_dsn = 'mysql://user@host/db'
|
||||||
self.assertEqual(test_dsn, value_types.ensure_type(test_dsn, 'dsn'))
|
self.assertEqual(test_dsn, value_types.ensure_type(test_dsn, 'dsn'))
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ TYPES = {
|
|||||||
"int": "^[0-9]+$",
|
"int": "^[0-9]+$",
|
||||||
"default": "^[A-Za-z0-9_]*$",
|
"default": "^[A-Za-z0-9_]*$",
|
||||||
"netaddress": "^[A-Za-z0-9/.:-]*$",
|
"netaddress": "^[A-Za-z0-9/.:-]*$",
|
||||||
|
"netdevice": "^[A-Za-z0-9/.:-]*$",
|
||||||
"dsn": "(?#driver)^[a-zA-Z0-9]+://"
|
"dsn": "(?#driver)^[a-zA-Z0-9]+://"
|
||||||
"(?#username[:password])([a-zA-Z0-9+_-]+(:[^@]+)?)?"
|
"(?#username[:password])([a-zA-Z0-9+_-]+(:[^@]+)?)?"
|
||||||
"(?#@host or file)(@?[a-zA-Z0-9/_.-]+)?"
|
"(?#@host or file)(@?[a-zA-Z0-9/_.-]+)?"
|
||||||
|
|||||||
Reference in New Issue
Block a user