library: cleanup handling of 'wait' argument

- extend the maxiumum wait time to 3600 seconds

 - disallow -1 values for 'wait'. It was used to mark
   the default value, but that marker should not be
   a valid value for user configuration. Instead, internally
   mark the missing value with None.

 - don't coerce a missing 'wait' parameter to 90 in _validate_post().
   Instead, track it as None so we can later decide between an explicitly
   set paramter and a default value. Also, the default for the states
   'up', 'down', and 'wait' differ.
   This also allows us to slience the warning about 'wait' not
   being implemented -- in case the user didn't configure it.

 - However, still allow zero.

   For

     - state: wait
       wait: 0

   allow it for convinience, so a user can disable the statement by
   setting the wait value to zero.

   For

     - name: MyProfile
       state: up
       wait: 0

   'wait' zero makes sense. It is what we currently do -- not wait
   at all. Later, when we implement waiting for complete activation, the
   default of wait will change (to 90 in this case).
This commit is contained in:
Thomas Haller 2017-05-09 13:48:34 +02:00
parent 47f1a3adc9
commit 530788a9dc
2 changed files with 25 additions and 19 deletions

View file

@ -642,7 +642,7 @@ class ArgValidator_DictConnection(ArgValidatorDict):
nested = [
ArgValidatorStr ('name'),
ArgValidatorStr ('state', enum_values = ArgValidator_DictConnection.VALID_STATES),
ArgValidatorInt ('wait', val_min = -1, val_max = 1200),
ArgValidatorInt ('wait', val_min = 0, val_max = 3600),
ArgValidatorStr ('type', enum_values = ArgValidator_DictConnection.VALID_TYPES),
ArgValidatorBool('autoconnect', default_value = True),
ArgValidatorStr ('slave_type', enum_values = ArgValidator_DictConnection.VALID_SLAVE_TYPES),
@ -694,14 +694,9 @@ class ArgValidator_DictConnection(ArgValidatorDict):
if 'name' not in result:
raise ValidationError(name, 'missing "name"')
if result['state'] == 'wait':
if result.get('wait', -1) == -1:
result['wait'] = 10
elif result['wait'] == 0:
raise ValidationError(name + '.wait', 'the "wait" value for state "wait" must be positive')
elif result['state'] in ['up', 'down']:
if result.get('wait', -1) == -1:
result['wait'] = 90
if result['state'] in [ 'wait', 'up', 'down' ]:
if 'wait' not in result:
result['wait'] = None
else:
if 'wait' in result:
raise ValidationError(name + '.wait', '"wait" is not allowed for state "%s"' % (result['state']))
@ -1571,10 +1566,13 @@ class Cmd:
try:
state = connection['state']
if state == 'wait':
AnsibleUtil.log_info(idx, 'wait for %s seconds' % (connection['wait']))
w = connection['wait']
if w is None:
w = 10
AnsibleUtil.log_info(idx, 'wait for %s seconds' % (w))
if AnsibleUtil.check_mode == CheckMode.REAL_RUN:
import time
time.sleep(connection['wait'])
time.sleep(w)
elif state == 'absent':
self.run_state_absent(idx)
elif state == 'present':
@ -1729,7 +1727,11 @@ class Cmd_nm(Cmd):
def run_state_up(self, idx):
connection = AnsibleUtil.connections[idx]
if connection['wait'] != 0:
w = connection['wait']
if w is None:
w = 90
else:
# TODO
AnsibleUtil.log_warn(idx, 'wait for activation is not yet implemented')
con = Util.first(self.nmutil.connection_list(name = connection['name'], uuid = connection['nm.uuid']))
@ -1751,7 +1753,11 @@ class Cmd_nm(Cmd):
def run_state_down(self, idx):
connection = AnsibleUtil.connections[idx]
if connection['wait'] != 0:
w = connection['wait']
if w is None:
w = 10
else:
# TODO
AnsibleUtil.log_warn(idx, 'wait for activation is not yet implemented')
cons = self.nmutil.connection_list(name = connection['name'])
@ -1863,7 +1869,7 @@ class Cmd_initscripts(Cmd):
connection = AnsibleUtil.connections[idx]
name = connection['name']
if connection['wait'] != 0:
if connection['wait'] is not None:
# initscripts don't support wait, they always block until the ifup/ifdown
# command completes. Silently ignore the argument.
pass

View file

@ -134,7 +134,7 @@ class TestValidator(unittest.TestCase):
{
'name': '5',
'state': 'up',
'wait': 90,
'wait': None,
'ignore_errors': None,
}
],
@ -173,7 +173,7 @@ class TestValidator(unittest.TestCase):
'interface_name': None,
'check_iface_exists': True,
'slave_type': None,
'wait': 90,
'wait': None,
},
],
n.AnsibleUtil.ARGS_CONNECTIONS.validate([
@ -275,7 +275,7 @@ class TestValidator(unittest.TestCase):
'interface_name': None,
'check_iface_exists': True,
'slave_type': None,
'wait': 90,
'wait': None,
},
],
n.AnsibleUtil.ARGS_CONNECTIONS.validate([
@ -314,7 +314,7 @@ class TestValidator(unittest.TestCase):
'interface_name': None,
'check_iface_exists': True,
'slave_type': None,
'wait': 90,
'wait': None,
},
],
n.AnsibleUtil.ARGS_CONNECTIONS.validate([
@ -355,7 +355,7 @@ class TestValidator(unittest.TestCase):
'interface_name': None,
'check_iface_exists': True,
'slave_type': None,
'wait': 90,
'wait': None,
},
],
n.AnsibleUtil.ARGS_CONNECTIONS.validate([