125
125
log.critical("Client not found on server: %r", name)
128
# Run all commands on clients
129
128
commands = commands_from_options(options)
130
130
for command in commands:
131
131
command.run(clients, bus, mandos_serv)
232
232
>>> rfc3339_duration_to_delta("")
233
233
Traceback (most recent call last):
235
ValueError: Invalid RFC 3339 duration: u''
235
ValueError: Invalid RFC 3339 duration: ""
236
236
>>> # Must start with "P":
237
237
>>> rfc3339_duration_to_delta("1D")
238
238
Traceback (most recent call last):
240
ValueError: Invalid RFC 3339 duration: u'1D'
240
ValueError: Invalid RFC 3339 duration: "1D"
241
241
>>> # Must use correct order
242
242
>>> rfc3339_duration_to_delta("PT1S2M")
243
243
Traceback (most recent call last):
245
ValueError: Invalid RFC 3339 duration: u'PT1S2M'
245
ValueError: Invalid RFC 3339 duration: "PT1S2M"
246
246
>>> # Time needs time marker
247
247
>>> rfc3339_duration_to_delta("P1H2S")
248
248
Traceback (most recent call last):
250
ValueError: Invalid RFC 3339 duration: u'P1H2S'
250
ValueError: Invalid RFC 3339 duration: "P1H2S"
251
251
>>> # Weeks can not be combined with anything else
252
252
>>> rfc3339_duration_to_delta("P1D2W")
253
253
Traceback (most recent call last):
255
ValueError: Invalid RFC 3339 duration: u'P1D2W'
255
ValueError: Invalid RFC 3339 duration: "P1D2W"
256
256
>>> rfc3339_duration_to_delta("P2W2H")
257
257
Traceback (most recent call last):
259
ValueError: Invalid RFC 3339 duration: u'P2W2H'
259
ValueError: Invalid RFC 3339 duration: "P2W2H"
262
262
# Parsing an RFC 3339 duration with regular expressions is not
930
931
@contextlib.contextmanager
931
932
def assertParseError(self):
932
933
with self.assertRaises(SystemExit) as e:
933
with self.temporarily_suppress_stderr():
934
with self.redirect_stderr_to_devnull():
935
936
# Exit code from argparse is guaranteed to be "2". Reference:
936
937
# https://docs.python.org/3/library
941
942
@contextlib.contextmanager
942
def temporarily_suppress_stderr():
943
def redirect_stderr_to_devnull():
943
944
null = os.open(os.path.devnull, os.O_RDWR)
944
945
stderrcopy = os.dup(sys.stderr.fileno())
945
946
os.dup2(null, sys.stderr.fileno())
1007
1008
options.client = ["foo"]
1008
1009
self.check_option_syntax(options)
1010
def test_actions_except_is_enabled_are_ok_with_two_clients(self):
1011
def test_one_client_with_all_actions_except_is_enabled(self):
1012
options = self.parser.parse_args()
1013
for action, value in self.actions.items():
1014
if action == "is_enabled":
1016
setattr(options, action, value)
1017
options.client = ["foo"]
1018
self.check_option_syntax(options)
1020
def test_two_clients_with_all_actions_except_is_enabled(self):
1021
options = self.parser.parse_args()
1022
for action, value in self.actions.items():
1023
if action == "is_enabled":
1025
setattr(options, action, value)
1026
options.client = ["foo", "barbar"]
1027
self.check_option_syntax(options)
1029
def test_two_clients_are_ok_with_actions_except_is_enabled(self):
1011
1030
for action, value in self.actions.items():
1012
1031
if action == "is_enabled":