mirror of
https://github.com/linux-system-roles/network.git
synced 2026-01-23 10:25:28 +00:00
Support compatibility values for 'state' setting
This commit is contained in:
parent
e1bb399311
commit
09258d84e3
2 changed files with 39 additions and 2 deletions
|
|
@ -610,8 +610,8 @@ class ArgValidator_DictMacvlan(ArgValidatorDict):
|
|||
|
||||
class ArgValidator_DictConnection(ArgValidatorDict):
|
||||
|
||||
VALID_STATES = ["up", "down"]
|
||||
VALID_PERSISTENT_STATES = ["absent", "present"]
|
||||
VALID_STATES = VALID_PERSISTENT_STATES + ["up", "down"]
|
||||
VALID_TYPES = [
|
||||
"ethernet",
|
||||
"infiniband",
|
||||
|
|
@ -701,7 +701,14 @@ class ArgValidator_DictConnection(ArgValidatorDict):
|
|||
"""
|
||||
actions = []
|
||||
state = result.get("state")
|
||||
persistent_state = result.get("persistent_state")
|
||||
if state in self.VALID_PERSISTENT_STATES:
|
||||
del result["state"]
|
||||
persistent_state_default = state
|
||||
state = None
|
||||
else:
|
||||
persistent_state_default = None
|
||||
|
||||
persistent_state = result.get("persistent_state", persistent_state_default)
|
||||
|
||||
# default persistent_state to present (not done via default_value in the
|
||||
# ArgValidatorStr, the value will only be set at the end of
|
||||
|
|
|
|||
|
|
@ -1908,6 +1908,24 @@ class TestValidator(unittest.TestCase):
|
|||
{"actions": ["present"], "persistent_state": "present", "state": None},
|
||||
)
|
||||
|
||||
def test_invalid_persistent_state_up(self):
|
||||
network_connections = [{"name": "internal", "persistent_state": "up"}]
|
||||
self.assertRaises(
|
||||
n.ValidationError, ARGS_CONNECTIONS.validate, network_connections
|
||||
)
|
||||
|
||||
def test_invalid_persistent_state_down(self):
|
||||
network_connections = [{"name": "internal", "persistent_state": "down"}]
|
||||
self.assertRaises(
|
||||
n.ValidationError, ARGS_CONNECTIONS.validate, network_connections
|
||||
)
|
||||
|
||||
def test_invalid_state_test(self):
|
||||
network_connections = [{"name": "internal", "state": "test"}]
|
||||
self.assertRaises(
|
||||
n.ValidationError, ARGS_CONNECTIONS.validate, network_connections
|
||||
)
|
||||
|
||||
def test_default_states_type(self):
|
||||
self.check_partial_connection_zero(
|
||||
{"name": "eth0", "type": "ethernet"},
|
||||
|
|
@ -1920,6 +1938,18 @@ class TestValidator(unittest.TestCase):
|
|||
{"actions": ["present"], "persistent_state": "present", "state": None},
|
||||
)
|
||||
|
||||
def test_state_present(self):
|
||||
self.check_partial_connection_zero(
|
||||
{"name": "eth0", "state": "present", "type": "ethernet"},
|
||||
{"actions": ["present"], "persistent_state": "present", "state": None},
|
||||
)
|
||||
|
||||
def test_state_absent(self):
|
||||
self.check_partial_connection_zero(
|
||||
{"name": "eth0", "state": "absent"},
|
||||
{"actions": ["absent"], "persistent_state": "absent", "state": None},
|
||||
)
|
||||
|
||||
def test_persistent_state_absent(self):
|
||||
self.check_partial_connection_zero(
|
||||
{"name": "eth0", "persistent_state": "absent"},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue