Start host watchdog after magic sequence

The magic sequence triggers the host to boot, so start the
host watchdog timer (which monitors for the host hanging)
right after that.
There's no need to port the check for debug flag because
it's checked as part of the magic sequence.
Resolves openbmc/skeleton#127

Change-Id: Ibad7b73c795c6cc8971bb99b755c8fce2c859f97
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/op-hostctl/control_host_obj.c b/op-hostctl/control_host_obj.c
index 94b5134..6202044 100644
--- a/op-hostctl/control_host_obj.c
+++ b/op-hostctl/control_host_obj.c
@@ -83,6 +83,11 @@
 		gpointer user_data)
 {
 	int rc = GPIO_OK;
+	GDBusProxy *proxy;
+	GError *error = NULL;
+	GVariant *result = NULL;
+	GDBusConnection *connection =
+		g_dbus_object_manager_server_get_connection(manager);
 
 	if(control_host_get_debug_mode(host)==1)
 	{
@@ -174,7 +179,57 @@
 	gpio_close(&Throttle);
 	gpio_close(&idbtn);
 
+	// Start watchdog with 30s timeout per the OpenPower Host IPMI Spec.
+	// Once the host starts booting, it'll reset and refresh the timer.
+	error = NULL;
+	// TODO Use the object mapper to lookup the bus name when this is
+	// refactored to use sdbus.
+	proxy = g_dbus_proxy_new_sync(connection,
+		G_DBUS_PROXY_FLAGS_NONE,
+		NULL, /* GDBusInterfaceInfo* */
+		"org.openbmc.watchdog.Host", /* name */
+		"/org/openbmc/watchdog/host0", /* object path */
+		"org.openbmc.Watchdog", /* interface name */
+		NULL, /* GCancellable */
+		&error);
+	g_assert_no_error(error);
+	if(error)
+		goto exit;
+
+	// Set watchdog timer to 30s
+	error = NULL;
+	result = g_dbus_proxy_call_sync(proxy,
+		"set",
+		g_variant_new("(i)", 30000),
+		G_DBUS_CALL_FLAGS_NONE,
+		-1,
+		NULL,
+		&error);
+	g_assert_no_error(error);
+	if (error)
+		goto exit;
+	if (result)
+		g_variant_unref(result);
+
+	// Start watchdog timer
+	error = NULL;
+	result = g_dbus_proxy_call_sync(proxy,
+		"start",
+		NULL,
+		G_DBUS_CALL_FLAGS_NONE,
+		-1,
+		NULL,
+		&error);
+	g_assert_no_error(error);
+	if (error)
+		goto exit;
+
 	control_host_emit_booted(host);
+
+exit:
+	if (result)
+		g_variant_unref(result);
+
 	return TRUE;
 }
 
diff --git a/pychassisctl/chassis_control.py b/pychassisctl/chassis_control.py
index 7f14195..6c5ad09 100755
--- a/pychassisctl/chassis_control.py
+++ b/pychassisctl/chassis_control.py
@@ -133,22 +133,6 @@
         if (self.getPowerState() == 0):
             intf = self.getInterface('power_control')
             intf.setPowerState(POWER_ON)
-
-            # Determine if debug_mode is set.  If it is then we don't
-            # want to start the watchdog since debug mode
-            intfcontrol = self.getInterface('host_control')
-            intfproperties = dbus.Interface(intfcontrol,
-                                            "org.freedesktop.DBus.Properties")
-            debug_mode = intfproperties.Get('org.openbmc.control.Host',
-                                            'debug_mode')
-            if(not debug_mode):
-                intfwatchdog = self.getInterface('watchdog')
-                # Start watchdog with 30s timeout per the OpenPower Host IPMI Spec
-                #Once the host starts booting, it'll reset and refresh the timer
-                intfwatchdog.set(30000)
-                intfwatchdog.start()
-            else:
-                print "Debug mode is on, no watchdog"
         return None
 
     @dbus.service.method(DBUS_NAME,