122
136
help="Select all clients")
123
137
parser.add_argument("-v", "--verbose", action="store_true",
124
138
help="Print all fields")
125
parser.add_argument("-j", "--dump-json", action="store_true",
139
parser.add_argument("-j", "--dump-json", dest="commands",
140
action="append_const", default=[],
141
const=command.DumpJSON(),
126
142
help="Dump client data in JSON format")
127
143
enable_disable = parser.add_mutually_exclusive_group()
128
enable_disable.add_argument("-e", "--enable", action="store_true",
144
enable_disable.add_argument("-e", "--enable", dest="commands",
145
action="append_const", default=[],
146
const=command.Enable(),
129
147
help="Enable client")
130
enable_disable.add_argument("-d", "--disable",
148
enable_disable.add_argument("-d", "--disable", dest="commands",
149
action="append_const", default=[],
150
const=command.Disable(),
132
151
help="disable client")
133
parser.add_argument("-b", "--bump-timeout", action="store_true",
152
parser.add_argument("-b", "--bump-timeout", dest="commands",
153
action="append_const", default=[],
154
const=command.BumpTimeout(),
134
155
help="Bump timeout for client")
135
156
start_stop_checker = parser.add_mutually_exclusive_group()
136
157
start_stop_checker.add_argument("--start-checker",
159
action="append_const", default=[],
160
const=command.StartChecker(),
138
161
help="Start checker for client")
139
start_stop_checker.add_argument("--stop-checker",
162
start_stop_checker.add_argument("--stop-checker", dest="commands",
163
action="append_const", default=[],
164
const=command.StopChecker(),
141
165
help="Stop checker for client")
142
parser.add_argument("-V", "--is-enabled", action="store_true",
166
parser.add_argument("-V", "--is-enabled", dest="commands",
167
action="append_const", default=[],
168
const=command.IsEnabled(),
143
169
help="Check if client is enabled")
144
parser.add_argument("-r", "--remove", action="store_true",
170
parser.add_argument("-r", "--remove", dest="commands",
171
action="append_const", default=[],
172
const=command.Remove(),
145
173
help="Remove client")
146
parser.add_argument("-c", "--checker",
174
parser.add_argument("-c", "--checker", dest="commands",
175
action="append", default=[],
176
metavar="COMMAND", type=command.SetChecker,
147
177
help="Set checker command for client")
148
parser.add_argument("-t", "--timeout", type=string_to_delta,
149
help="Set timeout for client")
150
parser.add_argument("--extended-timeout", type=string_to_delta,
151
help="Set extended timeout for client")
152
parser.add_argument("-i", "--interval", type=string_to_delta,
153
help="Set checker interval for client")
179
"-t", "--timeout", dest="commands", action="append",
180
default=[], metavar="TIME",
181
type=command.SetTimeout.argparse(string_to_delta),
182
help="Set timeout for client")
184
"--extended-timeout", dest="commands", action="append",
185
default=[], metavar="TIME",
186
type=command.SetExtendedTimeout.argparse(string_to_delta),
187
help="Set extended timeout for client")
189
"-i", "--interval", dest="commands", action="append",
190
default=[], metavar="TIME",
191
type=command.SetInterval.argparse(string_to_delta),
192
help="Set checker interval for client")
154
193
approve_deny_default = parser.add_mutually_exclusive_group()
155
194
approve_deny_default.add_argument(
156
"--approve-by-default", action="store_true",
157
default=None, dest="approved_by_default",
195
"--approve-by-default", dest="commands",
196
action="append_const", default=[],
197
const=command.ApproveByDefault(),
158
198
help="Set client to be approved by default")
159
199
approve_deny_default.add_argument(
160
"--deny-by-default", action="store_false",
161
dest="approved_by_default",
200
"--deny-by-default", dest="commands",
201
action="append_const", default=[],
202
const=command.DenyByDefault(),
162
203
help="Set client to be denied by default")
163
parser.add_argument("--approval-delay", type=string_to_delta,
164
help="Set delay before client approve/deny")
165
parser.add_argument("--approval-duration", type=string_to_delta,
166
help="Set duration of one client approval")
167
parser.add_argument("-H", "--host", help="Set host for client")
168
parser.add_argument("-s", "--secret",
169
type=argparse.FileType(mode="rb"),
170
help="Set password blob (file) for client")
205
"--approval-delay", dest="commands", action="append",
206
default=[], metavar="TIME",
207
type=command.SetApprovalDelay.argparse(string_to_delta),
208
help="Set delay before client approve/deny")
210
"--approval-duration", dest="commands", action="append",
211
default=[], metavar="TIME",
212
type=command.SetApprovalDuration.argparse(string_to_delta),
213
help="Set duration of one client approval")
214
parser.add_argument("-H", "--host", dest="commands",
215
action="append", default=[], metavar="STRING",
216
type=command.SetHost,
217
help="Set host for client")
219
"-s", "--secret", dest="commands", action="append",
220
default=[], metavar="FILENAME",
221
type=command.SetSecret.argparse(argparse.FileType(mode="rb")),
222
help="Set password blob (file) for client")
171
223
approve_deny = parser.add_mutually_exclusive_group()
172
224
approve_deny.add_argument(
173
"-A", "--approve", action="store_true",
225
"-A", "--approve", dest="commands", action="append_const",
226
default=[], const=command.Approve(),
174
227
help="Approve any current client request")
175
approve_deny.add_argument("-D", "--deny", action="store_true",
228
approve_deny.add_argument("-D", "--deny", dest="commands",
229
action="append_const", default=[],
230
const=command.Deny(),
176
231
help="Deny any current client request")
177
232
parser.add_argument("--debug", action="store_true",
178
233
help="Debug mode (show D-Bus commands)")
369
425
"""Apply additional restrictions on options, not expressible in
372
def has_actions(options):
373
return any((options.enable,
375
options.bump_timeout,
376
options.start_checker,
377
options.stop_checker,
380
options.checker is not None,
381
options.timeout is not None,
382
options.extended_timeout is not None,
383
options.interval is not None,
384
options.approved_by_default is not None,
385
options.approval_delay is not None,
386
options.approval_duration is not None,
387
options.host is not None,
388
options.secret is not None,
428
def has_commands(options, commands=None):
430
commands = (command.Enable,
433
command.StartChecker,
439
command.SetExtendedTimeout,
441
command.ApproveByDefault,
442
command.DenyByDefault,
443
command.SetApprovalDelay,
444
command.SetApprovalDuration,
449
return any(isinstance(cmd, commands)
450
for cmd in options.commands)
392
if has_actions(options) and not (options.client or options.all):
452
if has_commands(options) and not (options.client or options.all):
393
453
parser.error("Options require clients names or --all.")
394
if options.verbose and has_actions(options):
454
if options.verbose and has_commands(options):
395
455
parser.error("--verbose can only be used alone.")
396
if options.dump_json and (options.verbose
397
or has_actions(options)):
456
if (has_commands(options, (command.DumpJSON,))
457
and (options.verbose or len(options.commands) > 1)):
398
458
parser.error("--dump-json can only be used alone.")
399
if options.all and not has_actions(options):
459
if options.all and not has_commands(options):
400
460
parser.error("--all requires an action.")
401
if options.is_enabled and len(options.client) > 1:
461
if (has_commands(options, (command.IsEnabled,))
462
and len(options.client) > 1):
402
463
parser.error("--is-enabled requires exactly one client")
404
options.remove = False
405
if has_actions(options) and not options.deny:
406
parser.error("--remove can only be combined with --deny")
407
options.remove = True
464
if (len(options.commands) > 1
465
and has_commands(options, (command.Remove,))
466
and not has_commands(options, (command.Deny,))):
467
parser.error("--remove can only be combined with --deny")
411
470
class dbus(object):
549
616
return new_object
619
class pydbus_adapter(object):
620
class SystemBus(dbus.MandosBus):
621
def __init__(self, module=pydbus):
623
self.bus = self.pydbus.SystemBus()
625
@contextlib.contextmanager
626
def convert_exception(self, exception_class=dbus.Error):
629
except gi.repository.GLib.Error as e:
630
# This does what "raise from" would do
631
exc = exception_class(*e.args)
635
def call_method(self, methodname, busname, objectpath,
637
proxy_object = self.get(busname, objectpath)
638
log.debug("D-Bus: %s:%s:%s.%s(%s)", busname, objectpath,
639
interface, methodname,
640
", ".join(repr(a) for a in args))
641
method = getattr(proxy_object[interface], methodname)
642
with self.convert_exception():
645
def get(self, busname, objectpath):
646
log.debug("D-Bus: Connect to: (busname=%r, path=%r)",
648
with self.convert_exception(dbus.ConnectFailed):
649
if sys.version_info.major <= 2:
650
with warnings.catch_warnings():
651
warnings.filterwarnings(
652
"ignore", "", DeprecationWarning,
653
r"^xml\.etree\.ElementTree$")
654
return self.bus.get(busname, objectpath)
656
return self.bus.get(busname, objectpath)
658
def set_property(self, busname, objectpath, interface, key,
660
proxy_object = self.get(busname, objectpath)
661
log.debug("D-Bus: %s:%s:%s.Set(%r, %r, %r)", busname,
662
objectpath, self.properties_iface, interface,
664
setattr(proxy_object[interface], key, value)
666
class CachingBus(SystemBus):
667
"""A caching layer for pydbus_adapter.SystemBus"""
668
def __init__(self, *args, **kwargs):
669
self.object_cache = {}
670
super(pydbus_adapter.CachingBus,
671
self).__init__(*args, **kwargs)
672
def get(self, busname, objectpath):
674
return self.object_cache[(busname, objectpath)]
676
new_object = (super(pydbus_adapter.CachingBus, self)
677
.get(busname, objectpath))
678
self.object_cache[(busname, objectpath)] = new_object
552
682
def commands_from_options(options):
556
if options.is_enabled:
557
commands.append(command.IsEnabled())
560
commands.append(command.Approve())
563
commands.append(command.Deny())
566
commands.append(command.Remove())
568
if options.dump_json:
569
commands.append(command.DumpJSON())
572
commands.append(command.Enable())
575
commands.append(command.Disable())
577
if options.bump_timeout:
578
commands.append(command.BumpTimeout())
580
if options.start_checker:
581
commands.append(command.StartChecker())
583
if options.stop_checker:
584
commands.append(command.StopChecker())
586
if options.approved_by_default is not None:
587
if options.approved_by_default:
588
commands.append(command.ApproveByDefault())
684
commands = list(options.commands)
686
def find_cmd(cmd, commands):
688
for i, c in enumerate(commands):
689
if isinstance(c, cmd):
693
# If command.Remove is present, move any instances of command.Deny
694
# to occur ahead of command.Remove.
695
index_of_remove = find_cmd(command.Remove, commands)
696
before_remove = commands[:index_of_remove]
697
after_remove = commands[index_of_remove:]
699
for cmd in after_remove:
700
if isinstance(cmd, command.Deny):
701
before_remove.append(cmd)
590
commands.append(command.DenyByDefault())
592
if options.checker is not None:
593
commands.append(command.SetChecker(options.checker))
595
if options.host is not None:
596
commands.append(command.SetHost(options.host))
598
if options.secret is not None:
599
commands.append(command.SetSecret(options.secret))
601
if options.timeout is not None:
602
commands.append(command.SetTimeout(options.timeout))
604
if options.extended_timeout:
606
command.SetExtendedTimeout(options.extended_timeout))
608
if options.interval is not None:
609
commands.append(command.SetInterval(options.interval))
611
if options.approval_delay is not None:
613
command.SetApprovalDelay(options.approval_delay))
615
if options.approval_duration is not None:
617
command.SetApprovalDuration(options.approval_duration))
703
cleaned_after.append(cmd)
704
if cleaned_after != after_remove:
705
commands = before_remove + cleaned_after
619
707
# If no command option has been given, show table of clients,
620
708
# optionally verbosely
967
1060
def test_actions_requires_client_or_all(self):
968
1061
for action, value in self.actions.items():
969
options = self.parser.parse_args()
970
setattr(options, action, value)
1062
args = self.actionargs(action, value)
971
1063
with self.assertParseError():
972
self.check_option_syntax(options)
1064
self.parse_args(args)
974
# This mostly corresponds to the definition from has_actions() in
1066
# This mostly corresponds to the definition from has_commands() in
975
1067
# check_option_syntax()
977
# The actual values set here are not that important, but we do
978
# at least stick to the correct types, even though they are
982
"bump_timeout": True,
983
"start_checker": True,
984
"stop_checker": True,
988
"timeout": datetime.timedelta(),
989
"extended_timeout": datetime.timedelta(),
990
"interval": datetime.timedelta(),
991
"approved_by_default": True,
992
"approval_delay": datetime.timedelta(),
993
"approval_duration": datetime.timedelta(),
995
"secret": io.BytesIO(b"x"),
1071
"--bump-timeout": None,
1072
"--start-checker": None,
1073
"--stop-checker": None,
1074
"--is-enabled": None,
1077
"--timeout": "PT0S",
1078
"--extended-timeout": "PT0S",
1079
"--interval": "PT0S",
1080
"--approve-by-default": None,
1081
"--deny-by-default": None,
1082
"--approval-delay": "PT0S",
1083
"--approval-duration": "PT0S",
1084
"--host": "hostname",
1085
"--secret": "/dev/null",
1091
def actionargs(action, value, *args):
1092
if value is not None:
1093
return [action, value] + list(args)
1095
return [action] + list(args)
1000
1097
@contextlib.contextmanager
1001
1098
def assertParseError(self):
1002
1099
with self.assertRaises(SystemExit) as e:
1024
1125
def test_actions_all_conflicts_with_verbose(self):
1025
1126
for action, value in self.actions.items():
1026
options = self.parser.parse_args()
1027
setattr(options, action, value)
1029
options.verbose = True
1127
args = self.actionargs(action, value, "--all",
1030
1129
with self.assertParseError():
1031
self.check_option_syntax(options)
1130
self.parse_args(args)
1033
1132
def test_actions_with_client_conflicts_with_verbose(self):
1034
1133
for action, value in self.actions.items():
1035
options = self.parser.parse_args()
1036
setattr(options, action, value)
1037
options.verbose = True
1038
options.client = ["client"]
1134
args = self.actionargs(action, value, "--verbose",
1039
1136
with self.assertParseError():
1040
self.check_option_syntax(options)
1137
self.parse_args(args)
1042
1139
def test_dump_json_conflicts_with_verbose(self):
1043
options = self.parser.parse_args()
1044
options.dump_json = True
1045
options.verbose = True
1140
args = ["--dump-json", "--verbose"]
1046
1141
with self.assertParseError():
1047
self.check_option_syntax(options)
1142
self.parse_args(args)
1049
1144
def test_dump_json_conflicts_with_action(self):
1050
1145
for action, value in self.actions.items():
1051
options = self.parser.parse_args()
1052
setattr(options, action, value)
1053
options.dump_json = True
1146
args = self.actionargs(action, value, "--dump-json")
1054
1147
with self.assertParseError():
1055
self.check_option_syntax(options)
1148
self.parse_args(args)
1057
1150
def test_all_can_not_be_alone(self):
1058
options = self.parser.parse_args()
1060
1152
with self.assertParseError():
1061
self.check_option_syntax(options)
1153
self.parse_args(args)
1063
1155
def test_all_is_ok_with_any_action(self):
1064
1156
for action, value in self.actions.items():
1065
options = self.parser.parse_args()
1066
setattr(options, action, value)
1068
self.check_option_syntax(options)
1157
args = self.actionargs(action, value, "--all")
1158
self.parse_args(args)
1070
1160
def test_any_action_is_ok_with_one_client(self):
1071
1161
for action, value in self.actions.items():
1072
options = self.parser.parse_args()
1073
setattr(options, action, value)
1074
options.client = ["client"]
1075
self.check_option_syntax(options)
1162
args = self.actionargs(action, value, "client")
1163
self.parse_args(args)
1077
1165
def test_one_client_with_all_actions_except_is_enabled(self):
1078
options = self.parser.parse_args()
1079
1166
for action, value in self.actions.items():
1080
if action == "is_enabled":
1167
if action == "--is-enabled":
1082
setattr(options, action, value)
1083
options.client = ["client"]
1084
self.check_option_syntax(options)
1169
args = self.actionargs(action, value, "client")
1170
self.parse_args(args)
1086
1172
def test_two_clients_with_all_actions_except_is_enabled(self):
1087
options = self.parser.parse_args()
1088
1173
for action, value in self.actions.items():
1089
if action == "is_enabled":
1174
if action == "--is-enabled":
1091
setattr(options, action, value)
1092
options.client = ["client1", "client2"]
1093
self.check_option_syntax(options)
1176
args = self.actionargs(action, value, "client1",
1178
self.parse_args(args)
1095
1180
def test_two_clients_are_ok_with_actions_except_is_enabled(self):
1096
1181
for action, value in self.actions.items():
1097
if action == "is_enabled":
1182
if action == "--is-enabled":
1099
options = self.parser.parse_args()
1100
setattr(options, action, value)
1101
options.client = ["client1", "client2"]
1102
self.check_option_syntax(options)
1184
args = self.actionargs(action, value, "client1",
1186
self.parse_args(args)
1104
1188
def test_is_enabled_fails_without_client(self):
1105
options = self.parser.parse_args()
1106
options.is_enabled = True
1189
args = ["--is-enabled"]
1107
1190
with self.assertParseError():
1108
self.check_option_syntax(options)
1191
self.parse_args(args)
1110
1193
def test_is_enabled_fails_with_two_clients(self):
1111
options = self.parser.parse_args()
1112
options.is_enabled = True
1113
options.client = ["client1", "client2"]
1194
args = ["--is-enabled", "client1", "client2"]
1114
1195
with self.assertParseError():
1115
self.check_option_syntax(options)
1196
self.parse_args(args)
1117
1198
def test_remove_can_only_be_combined_with_action_deny(self):
1118
1199
for action, value in self.actions.items():
1119
if action in {"remove", "deny"}:
1200
if action in {"--remove", "--deny"}:
1121
options = self.parser.parse_args()
1122
setattr(options, action, value)
1124
options.remove = True
1202
args = self.actionargs(action, value, "--all",
1125
1204
with self.assertParseError():
1126
self.check_option_syntax(options)
1205
self.parse_args(args)
1129
1208
class Test_dbus_exceptions(unittest.TestCase):
1516
1622
self.assertIs(obj1, obj1b)
1625
class Test_pydbus_adapter_SystemBus(TestCaseWithAssertLogs):
1627
def Stub_pydbus_func(self, func):
1628
class stub_pydbus(object):
1629
"""stub pydbus module"""
1630
class SystemBus(object):
1632
def get(busname, objectpath):
1633
DBusObject = collections.namedtuple(
1634
"DBusObject", ("methodname",))
1635
return {"interface":
1636
DBusObject(methodname=func)}
1639
def call_method(self, bus, methodname, busname, objectpath,
1641
with self.assertLogs(log, logging.DEBUG):
1642
return bus.call_method(methodname, busname, objectpath,
1645
def test_call_method_returns(self):
1646
expected_method_return = Unique()
1647
method_args = (Unique(), Unique())
1649
self.assertEqual(len(method_args), len(args))
1650
for marg, arg in zip(method_args, args):
1651
self.assertIs(marg, arg)
1652
return expected_method_return
1653
stub_pydbus = self.Stub_pydbus_func(func)
1654
bus = pydbus_adapter.SystemBus(stub_pydbus)
1655
ret = self.call_method(bus, "methodname", "busname",
1656
"objectpath", "interface",
1658
self.assertIs(ret, expected_method_return)
1660
def test_call_method_handles_exception(self):
1661
dbus_logger = logging.getLogger("dbus.proxies")
1664
raise gi.repository.GLib.Error()
1666
stub_pydbus = self.Stub_pydbus_func(func)
1667
bus = pydbus_adapter.SystemBus(stub_pydbus)
1669
with self.assertRaises(dbus.Error) as e:
1670
self.call_method(bus, "methodname", "busname",
1671
"objectpath", "interface")
1673
self.assertNotIsInstance(e, dbus.ConnectFailed)
1675
def test_get_converts_to_correct_exception(self):
1676
bus = pydbus_adapter.SystemBus(
1677
self.fake_pydbus_raises_exception_on_connect)
1678
with self.assertRaises(dbus.ConnectFailed):
1679
self.call_method(bus, "methodname", "busname",
1680
"objectpath", "interface")
1682
class fake_pydbus_raises_exception_on_connect(object):
1683
"""fake dbus-python module"""
1686
def get(busname, objectpath):
1687
raise gi.repository.GLib.Error()
1688
Bus = collections.namedtuple("Bus", ["get"])
1691
def test_set_property_uses_setattr(self):
1692
class Object(object):
1695
class pydbus_spy(object):
1696
class SystemBus(object):
1698
def get(busname, objectpath):
1699
return {"interface": obj}
1700
bus = pydbus_adapter.SystemBus(pydbus_spy)
1702
bus.set_property("busname", "objectpath", "interface", "key",
1704
self.assertIs(value, obj.key)
1706
def test_get_suppresses_xml_deprecation_warning(self):
1707
if sys.version_info.major >= 3:
1709
class stub_pydbus_get(object):
1710
class SystemBus(object):
1712
def get(busname, objectpath):
1713
warnings.warn_explicit(
1714
"deprecated", DeprecationWarning,
1715
"xml.etree.ElementTree", 0)
1716
bus = pydbus_adapter.SystemBus(stub_pydbus_get)
1717
with warnings.catch_warnings(record=True) as w:
1718
warnings.simplefilter("always")
1719
bus.get("busname", "objectpath")
1720
self.assertEqual(0, len(w))
1723
class Test_pydbus_adapter_CachingBus(unittest.TestCase):
1724
class stub_pydbus(object):
1725
"""stub pydbus module"""
1726
class SystemBus(object):
1728
def get(busname, objectpath):
1732
self.bus = pydbus_adapter.CachingBus(self.stub_pydbus)
1734
def test_returns_distinct_objectpaths(self):
1735
obj1 = self.bus.get("busname", "objectpath1")
1736
self.assertIsInstance(obj1, Unique)
1737
obj2 = self.bus.get("busname", "objectpath2")
1738
self.assertIsInstance(obj2, Unique)
1739
self.assertIsNot(obj1, obj2)
1741
def test_returns_distinct_busnames(self):
1742
obj1 = self.bus.get("busname1", "objectpath")
1743
self.assertIsInstance(obj1, Unique)
1744
obj2 = self.bus.get("busname2", "objectpath")
1745
self.assertIsInstance(obj2, Unique)
1746
self.assertIsNot(obj1, obj2)
1748
def test_returns_distinct_both(self):
1749
obj1 = self.bus.get("busname1", "objectpath")
1750
self.assertIsInstance(obj1, Unique)
1751
obj2 = self.bus.get("busname2", "objectpath")
1752
self.assertIsInstance(obj2, Unique)
1753
self.assertIsNot(obj1, obj2)
1755
def test_returns_same(self):
1756
obj1 = self.bus.get("busname", "objectpath")
1757
self.assertIsInstance(obj1, Unique)
1758
obj2 = self.bus.get("busname", "objectpath")
1759
self.assertIsInstance(obj2, Unique)
1760
self.assertIs(obj1, obj2)
1762
def test_returns_same_old(self):
1763
obj1 = self.bus.get("busname1", "objectpath1")
1764
self.assertIsInstance(obj1, Unique)
1765
obj2 = self.bus.get("busname2", "objectpath2")
1766
self.assertIsInstance(obj2, Unique)
1767
obj1b = self.bus.get("busname1", "objectpath1")
1768
self.assertIsInstance(obj1b, Unique)
1769
self.assertIsNot(obj1, obj2)
1770
self.assertIsNot(obj2, obj1b)
1771
self.assertIs(obj1, obj1b)
1519
1774
class Test_commands_from_options(unittest.TestCase):
1521
1776
def setUp(self):
2070
2367
def runTest(self):
2071
2368
if not hasattr(self, "command"):
2072
2369
return # Abstract TestCase class
2073
values_to_get = getattr(self, "values_to_get",
2075
for value_to_set, value_to_get in zip(self.values_to_set,
2077
for clientpath in self.bus.clients:
2078
self.bus.clients[clientpath][self.propname] = Unique()
2079
self.run_command(value_to_set, self.bus.clients)
2080
for clientpath in self.bus.clients:
2081
value = self.bus.clients[clientpath][self.propname]
2371
if hasattr(self, "values_to_set"):
2372
cmd_args = [(value,) for value in self.values_to_set]
2373
values_to_get = getattr(self, "values_to_get",
2376
cmd_args = [() for x in range(len(self.values_to_get))]
2377
values_to_get = self.values_to_get
2378
for value_to_get, cmd_arg in zip(values_to_get, cmd_args):
2379
for clientpath in self.bus.clients:
2380
self.bus.clients[clientpath][self.propname] = (
2382
self.command(*cmd_arg).run(self.bus.clients, self.bus)
2383
for clientpath in self.bus.clients:
2384
value = (self.bus.clients[clientpath]
2082
2386
self.assertNotIsInstance(value, Unique)
2083
2387
self.assertEqual(value_to_get, value)
2085
def run_command(self, value, clients):
2086
self.command().run(clients, self.bus)
2089
2390
class TestEnableCmd(TestPropertySetterCmd):
2090
2391
command = command.Enable
2091
2392
propname = "Enabled"
2092
values_to_set = [True]
2393
values_to_get = [True]
2095
2396
class TestDisableCmd(TestPropertySetterCmd):
2096
2397
command = command.Disable
2097
2398
propname = "Enabled"
2098
values_to_set = [False]
2399
values_to_get = [False]
2101
2402
class TestBumpTimeoutCmd(TestPropertySetterCmd):
2102
2403
command = command.BumpTimeout
2103
2404
propname = "LastCheckedOK"
2104
values_to_set = [""]
2405
values_to_get = [""]
2107
2408
class TestStartCheckerCmd(TestPropertySetterCmd):
2108
2409
command = command.StartChecker
2109
2410
propname = "CheckerRunning"
2110
values_to_set = [True]
2411
values_to_get = [True]
2113
2414
class TestStopCheckerCmd(TestPropertySetterCmd):
2114
2415
command = command.StopChecker
2115
2416
propname = "CheckerRunning"
2116
values_to_set = [False]
2417
values_to_get = [False]
2119
2420
class TestApproveByDefaultCmd(TestPropertySetterCmd):
2120
2421
command = command.ApproveByDefault
2121
2422
propname = "ApprovedByDefault"
2122
values_to_set = [True]
2423
values_to_get = [True]
2125
2426
class TestDenyByDefaultCmd(TestPropertySetterCmd):
2126
2427
command = command.DenyByDefault
2127
2428
propname = "ApprovedByDefault"
2128
values_to_set = [False]
2131
class TestPropertySetterValueCmd(TestPropertySetterCmd):
2132
"""Abstract class for tests of PropertySetterValueCmd classes"""
2134
def run_command(self, value, clients):
2135
self.command(value).run(clients, self.bus)
2138
class TestSetCheckerCmd(TestPropertySetterValueCmd):
2429
values_to_get = [False]
2432
class TestSetCheckerCmd(TestPropertySetterCmd):
2139
2433
command = command.SetChecker
2140
2434
propname = "Checker"
2141
2435
values_to_set = ["", ":", "fping -q -- %s"]
2144
class TestSetHostCmd(TestPropertySetterValueCmd):
2438
class TestSetHostCmd(TestPropertySetterCmd):
2145
2439
command = command.SetHost
2146
2440
propname = "Host"
2147
2441
values_to_set = ["192.0.2.3", "client.example.org"]
2150
class TestSetSecretCmd(TestPropertySetterValueCmd):
2444
class TestSetSecretCmd(TestPropertySetterCmd):
2151
2445
command = command.SetSecret
2152
2446
propname = "Secret"
2153
2447
values_to_set = [io.BytesIO(b""),