diff --git a/os_apply_config/apply_config.py b/os_apply_config/apply_config.py index 279d26b..754b9a2 100755 --- a/os_apply_config/apply_config.py +++ b/os_apply_config/apply_config.py @@ -200,7 +200,8 @@ def parse_opts(argv): parser.add_argument('--type', default='default', help='exit with error if the specified --key does not' ' match type. Valid types are' - ' ') + ' ') parser.add_argument('--key-default', help='This option only affects running with --key.' ' Print this if key is not found. This value is' diff --git a/os_apply_config/tests/test_value_type.py b/os_apply_config/tests/test_value_type.py index 3e52e96..90ac64d 100644 --- a/os_apply_config/tests/test_value_type.py +++ b/os_apply_config/tests/test_value_type.py @@ -71,6 +71,23 @@ class ValueTypeTestCase(testtools.TestCase): self.assertRaises(config_exception.ConfigException, 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): test_dsn = 'mysql://user@host/db' self.assertEqual(test_dsn, value_types.ensure_type(test_dsn, 'dsn')) diff --git a/os_apply_config/value_types.py b/os_apply_config/value_types.py index bf90bd5..7efd921 100644 --- a/os_apply_config/value_types.py +++ b/os_apply_config/value_types.py @@ -21,6 +21,7 @@ TYPES = { "int": "^[0-9]+$", "default": "^[A-Za-z0-9_]*$", "netaddress": "^[A-Za-z0-9/.:-]*$", + "netdevice": "^[A-Za-z0-9/.:-]*$", "dsn": "(?#driver)^[a-zA-Z0-9]+://" "(?#username[:password])([a-zA-Z0-9+_-]+(:[^@]+)?)?" "(?#@host or file)(@?[a-zA-Z0-9/_.-]+)?"