xref: /openbmc/openbmc-test-automation/bin/event_notification_util.py (revision 20f38712b324e61a94e174017c487a0af4b373e1)
1e7e9171eSGeorge Keishing#!/usr/bin/env python3
21cd34b52SAnusha Dathatri
31cd34b52SAnusha Dathatrir"""
41cd34b52SAnusha DathatriSee help text for details.
51cd34b52SAnusha Dathatri"""
61cd34b52SAnusha Dathatri
71cd34b52SAnusha Dathatriimport sys
81cd34b52SAnusha Dathatri
91cd34b52SAnusha Dathatrisave_dir_path = sys.path.pop(0)
101cd34b52SAnusha Dathatri
11*20f38712SPatrick Williamsmodules = ["gen_arg", "gen_print", "gen_valid", "event_notification"]
121cd34b52SAnusha Dathatrifor module in modules:
131cd34b52SAnusha Dathatri    exec("from " + module + " import *")
141cd34b52SAnusha Dathatri
151cd34b52SAnusha Dathatrisys.path.insert(0, save_dir_path)
161cd34b52SAnusha Dathatri
171cd34b52SAnusha Dathatriparser = argparse.ArgumentParser(
18*20f38712SPatrick Williams    usage="%(prog)s [OPTIONS]",
191cd34b52SAnusha Dathatri    description="%(prog)s will subscribe and receive event notifications when "
201cd34b52SAnusha Dathatri    + "properties change for the given dbus path.",
211cd34b52SAnusha Dathatri    formatter_class=argparse.ArgumentDefaultsHelpFormatter,
22*20f38712SPatrick Williams    prefix_chars="-+",
23*20f38712SPatrick Williams)
241cd34b52SAnusha Dathatriparser.add_argument(
25*20f38712SPatrick Williams    "--host",
26*20f38712SPatrick Williams    default="",
27*20f38712SPatrick Williams    help="The host name or IP of the system to subscribe to.",
28*20f38712SPatrick Williams)
291cd34b52SAnusha Dathatriparser.add_argument(
30*20f38712SPatrick Williams    "--username", default="root", help="The username for the host system."
31*20f38712SPatrick Williams)
321cd34b52SAnusha Dathatriparser.add_argument(
33*20f38712SPatrick Williams    "--password", default="", help="The password for the host system."
34*20f38712SPatrick Williams)
351cd34b52SAnusha Dathatriparser.add_argument(
36*20f38712SPatrick Williams    "--dbus_path",
37*20f38712SPatrick Williams    default="",
38*20f38712SPatrick Williams    help='The path to be monitored (e.g. "/xyz/openbmc_project/sensors").',
39*20f38712SPatrick Williams)
401cd34b52SAnusha Dathatriparser.add_argument(
41*20f38712SPatrick Williams    "--enable_trace",
421cd34b52SAnusha Dathatri    choices=[0, 1],
431cd34b52SAnusha Dathatri    default=0,
44*20f38712SPatrick Williams    help="Indicates that trace needs to be enabled.",
45*20f38712SPatrick Williams)
461cd34b52SAnusha Dathatri
471cd34b52SAnusha Dathatri
481cd34b52SAnusha Dathatri# Populate stock_list with options we want.
491cd34b52SAnusha Dathatristock_list = [("test_mode", 0), ("quiet", 0), ("debug", 0)]
501cd34b52SAnusha Dathatri
511cd34b52SAnusha Dathatri
521cd34b52SAnusha Dathatridef main():
531cd34b52SAnusha Dathatri    gen_setup()
541cd34b52SAnusha Dathatri    my_event = event_notification(host, username, password)
551cd34b52SAnusha Dathatri    event_notifications = my_event.subscribe(dbus_path, enable_trace)
561cd34b52SAnusha Dathatri    print_var(event_notifications, fmt=[no_header(), strip_brackets()])
571cd34b52SAnusha Dathatri
581cd34b52SAnusha Dathatri
591cd34b52SAnusha Dathatrimain()
60