317
317
def propname(self):
318
318
raise NotImplementedError()
320
class ValueArgumentMixIn(object):
321
"""Mixin class for commands taking a value as argument"""
320
class PropertyValueCmd(PropertyCmd):
321
"""Abstract class for PropertyCmd recieving a value as argument"""
322
322
def __init__(self, value):
323
323
self.value_to_set = value
325
class MillisecondsValueArgumentMixIn(ValueArgumentMixIn):
326
"""Mixin class for commands taking a value argument as
325
class MillisecondsPropertyValueArgumentCmd(PropertyValueCmd):
326
"""Abstract class for PropertyValueCmd taking a value argument as
327
a datetime.timedelta() but should store it as milliseconds."""
329
329
def value_to_set(self):
331
331
@value_to_set.setter
332
332
def value_to_set(self, value):
333
"""When setting, convert value to a datetime.timedelta"""
333
"""When setting, convert value from a datetime.timedelta"""
334
334
self._vts = int(round(value.total_seconds() * 1000))
336
336
# Actual (non-abstract) command classes
493
493
propname = "ApprovedByDefault"
494
494
value_to_set = dbus.Boolean(False)
496
class SetCheckerCmd(PropertyCmd, ValueArgumentMixIn):
496
class SetCheckerCmd(PropertyValueCmd):
497
497
propname = "Checker"
499
class SetHostCmd(PropertyCmd, ValueArgumentMixIn):
499
class SetHostCmd(PropertyValueCmd):
500
500
propname = "Host"
502
class SetSecretCmd(PropertyCmd, ValueArgumentMixIn):
502
class SetSecretCmd(PropertyValueCmd):
503
503
propname = "Secret"
505
505
def value_to_set(self):
510
510
self._vts = value.read()
513
class SetTimeoutCmd(PropertyCmd, MillisecondsValueArgumentMixIn):
513
class SetTimeoutCmd(MillisecondsPropertyValueArgumentCmd):
514
514
propname = "Timeout"
516
class SetExtendedTimeoutCmd(PropertyCmd,
517
MillisecondsValueArgumentMixIn):
516
class SetExtendedTimeoutCmd(MillisecondsPropertyValueArgumentCmd):
518
517
propname = "ExtendedTimeout"
520
class SetIntervalCmd(PropertyCmd, MillisecondsValueArgumentMixIn):
519
class SetIntervalCmd(MillisecondsPropertyValueArgumentCmd):
521
520
propname = "Interval"
523
class SetApprovalDelayCmd(PropertyCmd,
524
MillisecondsValueArgumentMixIn):
522
class SetApprovalDelayCmd(MillisecondsPropertyValueArgumentCmd):
525
523
propname = "ApprovalDelay"
527
class SetApprovalDurationCmd(PropertyCmd,
528
MillisecondsValueArgumentMixIn):
525
class SetApprovalDurationCmd(MillisecondsPropertyValueArgumentCmd):
529
526
propname = "ApprovalDuration"
531
528
def add_command_line_options(parser):
1130
1127
propname = "ApprovedByDefault"
1131
1128
values_to_set = [dbus.Boolean(False)]
1133
class TestValueArgumentPropertyCmd(TestPropertyCmd):
1134
"""Abstract class for tests of PropertyCmd classes using the
1135
ValueArgumentMixIn"""
1130
class TestPropertyValueCmd(TestPropertyCmd):
1131
"""Abstract class for tests of PropertyValueCmd classes"""
1136
1132
def runTest(self):
1137
if type(self) is TestValueArgumentPropertyCmd:
1133
if type(self) is TestPropertyValueCmd:
1139
return super(TestValueArgumentPropertyCmd, self).runTest()
1135
return super(TestPropertyValueCmd, self).runTest()
1140
1136
def run_command(self, value, clients):
1141
1137
self.command(value).run(clients, self.bus)
1143
class TestSetCheckerCmd(TestValueArgumentPropertyCmd):
1139
class TestSetCheckerCmd(TestPropertyValueCmd):
1144
1140
command = SetCheckerCmd
1145
1141
propname = "Checker"
1146
1142
values_to_set = ["", ":", "fping -q -- %s"]
1148
class TestSetHostCmd(TestValueArgumentPropertyCmd):
1144
class TestSetHostCmd(TestPropertyValueCmd):
1149
1145
command = SetHostCmd
1150
1146
propname = "Host"
1151
1147
values_to_set = ["192.0.2.3", "foo.example.org"]
1153
class TestSetSecretCmd(TestValueArgumentPropertyCmd):
1149
class TestSetSecretCmd(TestPropertyValueCmd):
1154
1150
command = SetSecretCmd
1155
1151
propname = "Secret"
1156
1152
values_to_set = [io.BytesIO(b""),
1157
1153
io.BytesIO(b"secret\0xyzzy\nbar")]
1158
1154
values_to_get = [b"", b"secret\0xyzzy\nbar"]
1160
class TestSetTimeoutCmd(TestValueArgumentPropertyCmd):
1156
class TestSetTimeoutCmd(TestPropertyValueCmd):
1161
1157
command = SetTimeoutCmd
1162
1158
propname = "Timeout"
1163
1159
values_to_set = [datetime.timedelta(),
1167
1163
datetime.timedelta(weeks=52)]
1168
1164
values_to_get = [0, 300000, 1000, 604800000, 31449600000]
1170
class TestSetExtendedTimeoutCmd(TestValueArgumentPropertyCmd):
1166
class TestSetExtendedTimeoutCmd(TestPropertyValueCmd):
1171
1167
command = SetExtendedTimeoutCmd
1172
1168
propname = "ExtendedTimeout"
1173
1169
values_to_set = [datetime.timedelta(),
1177
1173
datetime.timedelta(weeks=52)]
1178
1174
values_to_get = [0, 300000, 1000, 604800000, 31449600000]
1180
class TestSetIntervalCmd(TestValueArgumentPropertyCmd):
1176
class TestSetIntervalCmd(TestPropertyValueCmd):
1181
1177
command = SetIntervalCmd
1182
1178
propname = "Interval"
1183
1179
values_to_set = [datetime.timedelta(),
1187
1183
datetime.timedelta(weeks=52)]
1188
1184
values_to_get = [0, 300000, 1000, 604800000, 31449600000]
1190
class TestSetApprovalDelayCmd(TestValueArgumentPropertyCmd):
1186
class TestSetApprovalDelayCmd(TestPropertyValueCmd):
1191
1187
command = SetApprovalDelayCmd
1192
1188
propname = "ApprovalDelay"
1193
1189
values_to_set = [datetime.timedelta(),
1197
1193
datetime.timedelta(weeks=52)]
1198
1194
values_to_get = [0, 300000, 1000, 604800000, 31449600000]
1200
class TestSetApprovalDurationCmd(TestValueArgumentPropertyCmd):
1196
class TestSetApprovalDurationCmd(TestPropertyValueCmd):
1201
1197
command = SetApprovalDurationCmd
1202
1198
propname = "ApprovalDuration"
1203
1199
values_to_set = [datetime.timedelta(),