Factory data reset automation.

This change addresses:
    1. Factory reset the system.
    2. Restore old network settings.

Resolves openbmc/openbmc-test-automation/issues/282

Change-Id: I29e7e876eab9650c20792ba27ce7632ab063b949
Signed-off-by: Prashanth Katti <prkatti1@in.ibm.com>
diff --git a/extended/factory_reset.robot b/extended/factory_reset.robot
new file mode 100644
index 0000000..7d7fdd2
--- /dev/null
+++ b/extended/factory_reset.robot
@@ -0,0 +1,60 @@
+*** Settings ***
+Documentation   This program performs Factory data reset.
+
+Resource        ../lib/ipmi_client.robot
+Resource        ../lib/utils.robot
+Resource        ../lib/connection_client.robot
+Resource        ../lib/oem/ibm/serial_console_client.robot
+Library         OperatingSystem
+
+Suite Setup      Validate Setup
+Suite Teardown   Close All Connections
+
+*** Test Cases ***
+
+Verify Factory Reset
+    [Documentation]  Factory reset the system and verify if BMC is online.
+    [Tags]  Verify_Factory_Reset
+
+    # Factory reset erases user config settings which incldes IP, netmask
+    # gateway and route. Before running this test we are checking all these
+    # settings and checking whether ping works with BMC host.
+    # If factory reset is successful, ping to BMC host should fail as
+    # IP address is erased and comes up with zero_conf.
+
+    Erase All Settings
+    ${status}=  Run Keyword And Return Status  Ping Host  ${OPENBMC_HOST}
+    Should Be Equal  ${status}  False  msg=Factory reset failed.
+
+Revert to Initial Setup And Verify
+    [Documentation]  Revert to old setup.
+    [Tags]  Revert_to_Initial_Setup_And_Verify
+
+    # This test case restores old settings Viz IP address, netmask, gateway
+    # and route. Restoring is done through serial port console.
+    # If reverting to initial setup is successful, ping to BMC
+    # host should pass.
+
+    Configure Initial Settings
+    Ping Host  ${OPENBMC_HOST}
+
+*** Keywords ***
+
+Validate Setup
+    [Documentation]  Validate setup.
+
+    Open Connection And Log In
+
+    # Check whether gateway IP is reachable.
+    Ping Host  ${GW_IP}
+    Should Not Be Empty  ${NET_MASK}  msg=Netmask not provided.
+
+    # Check whether serial console IP is reachable and responding
+    # to telnet command.
+    Open Telnet Connection to BMC Serial Console
+
+Erase All Settings
+    [Documentation]  Factory reset the system.
+
+    Run Dbus IPMI Raw Command  0x32 0xBA 00 00
+    Run Dbus IPMI Raw Command  0x32 0x66
diff --git a/lib/utils.robot b/lib/utils.robot
index 74c8d99..a04bc58 100755
--- a/lib/utils.robot
+++ b/lib/utils.robot
@@ -792,3 +792,18 @@
 
     Open Connection  ${os_host}
     Login  ${os_username}  ${os_password}
+
+Configure Initial Settings
+    [Documentation]  Restore old IP and route.
+    ...  This keyword requires initial settings viz IP address,
+    ...  Network Mask, default gatway and serial console IP and port
+    ...  information which should be provided in command line.
+
+    [Arguments]  ${host}=${OPENBMC_HOST}  ${mask}=${NET_MASK}  ${gw_ip}=${GW_IP}
+
+    # Open telnet connection and ignore the error, in case telnet session is already
+    # opened by the program calling this keyword.
+
+    Run Keyword And Ignore Error  Open Telnet Connection to BMC Serial Console
+    Telnet.write  ifconfig eth0 ${host} netmask ${mask}
+    Telnet.write  route add default gw ${gw_ip}