Disable avahi daemon and next reboot discover BMC

Change-Id: I8c163d4fba5ba55d02f1582f9a0eb591f2f5dd14
Signed-off-by: Sushil Singh <susilsi7@in.ibm.com>
diff --git a/lib/external_intf/management_console_utils.py b/lib/external_intf/management_console_utils.py
index b6ac2bc..2cc62a9 100644
--- a/lib/external_intf/management_console_utils.py
+++ b/lib/external_intf/management_console_utils.py
@@ -19,6 +19,26 @@
         return repr(self.exc_value)
 
 
+def Check_bmc_record_exists(bmc_records, bmc_ip):
+    r"""
+    Parse the BMC records to check for passed input.
+
+    Description of arguments:
+    bmc_records            Contains the list of discoverd BMC records.
+    bmc_ip                 BMC ip address.
+    """
+
+    try:
+        for bmc_key, bmc_val in bmc_records.items():
+            temp_ip = bmc_val.get('address', None)
+            if bmc_ip.strip() == temp_ip.strip():
+                return True
+        else:
+            return False
+    except Exception as exc_obj:
+        return exc_obj
+
+
 def validate_bmc_properties(bmc_prop_pattern, bmc_prop, bmc_value,
                             bmc_rec_valid):
     r"""
@@ -117,7 +137,7 @@
 
     Description of arguments:
     service_type     Service type (e.g. RESTService, RedfishService).
-    bmc_records      Contains the lis of discoverd BMC records.
+    bmc_records      Contains the list of discoverd BMC records.
 
     This function will return this variable i.e.
     bmc_inv_list in dictionary form as mention below.
diff --git a/lib/external_intf/management_console_utils.robot b/lib/external_intf/management_console_utils.robot
new file mode 100644
index 0000000..b9c0462
--- /dev/null
+++ b/lib/external_intf/management_console_utils.robot
@@ -0,0 +1,40 @@
+*** Settings ***
+Documentation    Management console utilities keywords.
+
+Library          ../../lib/gen_robot_valid.py
+Library          Collections
+Library          ../../lib/bmc_ssh_utils.py
+Library          SSHLibrary
+
+*** Variables ***
+&{daemon_command}  start=systemctl start avahi-daemon
+                  ...  stop=systemctl stop avahi-daemon
+                  ...  status=systemctl status avahi-daemon -l
+&{daemon_message}  start=Active: active (running)
+                  ...  stop=Active: inactive (dead)
+
+*** Keywords ***
+
+Set AvahiDaemon Service
+    [Documentation]  To enable or disable avahi service.
+    [Arguments]  ${command}
+
+    # Description of argument(s):
+    # command  Get command from dictionay.
+
+    ${service_command}=  Get From Dictionary  ${daemon_command}  ${command}
+    ${resp}  ${stderr}  ${rc}=  BMC Execute Command  ${service_command}  print_out=1
+    Should Be Equal As Integers  ${rc}  0
+
+
+Verify AvahiDaemon Service Status
+    [Documentation]  To check for avahi service.
+    [Arguments]  ${message}
+
+    # Description of argument(s):
+    # message  Get status message from dictionay.
+
+    ${service_command}=  Get From Dictionary  ${daemon_command}  status
+    ${service_message}=  Get From Dictionary  ${daemon_message}  ${message}
+    ${resp}  ${stderr}  ${rc}=  BMC Execute Command  ${service_command}  print_out=1
+    Should Contain  ${resp}  ${service_message}
diff --git a/openpower/ext_interfaces/test_discovery.robot b/openpower/ext_interfaces/test_discovery.robot
index 20410f8..b8ff2fc 100644
--- a/openpower/ext_interfaces/test_discovery.robot
+++ b/openpower/ext_interfaces/test_discovery.robot
@@ -1,11 +1,15 @@
 *** Settings ***
-Documentation        Test to discover the BMC.
+Documentation        Test to discover the BMC. Before running suit,
+...                  check BMC and Avahi browse machine should be in same subnet.
 
 Variables            ../../data/variables.py
 Library              SSHLibrary
 Library              ../../lib/external_intf/management_console_utils.py
 Library              ../../lib/gen_robot_print.py
 Library              ../../lib/gen_print.py
+Library              ../../lib/gen_misc.py
+Resource             ../../lib/external_intf/management_console_utils.robot
+Resource             ../../lib/boot_utils.robot
 Resource             ../../syslib/utils_os.robot
 
 Suite Setup          Suite Setup Execution
@@ -22,6 +26,16 @@
     _obmc_redfish._tcp
 
 
+Disable AvahiDaemon And Discover BMC After Reboot
+    [Documentation]  Check the input BMC is discoverd and then disable the avahi daemon,
+    ...  in next reboot same input BMC should discoverable.
+    [Tags]  Disable_AvahiDaemon_And_Discover_BMC_After_Reboot
+    [Template]  Disable Daemon And Discover BMC After Reboot
+
+    # Service type
+    _obmc_rest._tcp
+    _obmc_redfish._tcp
+
 *** Keywords ***
 
 Suite Setup Execution
@@ -51,8 +65,8 @@
     [Arguments]  ${service_type}
 
     # Description of argument(s):
-    # service_type    BMC service type e.g.
-    #                 (REST Service = _obmc_rest._tcp, Redfish Service = _obmc_redfish._tcp).
+    # service_type  BMC service type e.g.
+    #               (REST Service = _obmc_rest._tcp, Redfish Service = _obmc_redfish._tcp).
 
     # bmc_list:
     # [1]:
@@ -73,3 +87,34 @@
     Print Timen  Exception message is ${exc_msg}
     Should Not Be Empty  ${bmc_list}
     Rprint Vars  bmc_list
+    [Return]  ${bmc_list}
+
+
+Verify Existence Of BMC Record From List
+    [Documentation]  Verify the existence of BMC record from list of BMC records.
+    [Arguments]  ${service_type}
+
+    # Description of argument(s):
+    # service_type  BMC service type e.g.
+    #               (REST Service = _obmc_rest._tcp, Redfish Service = _obmc_redfish._tcp).
+
+    ${bmc_list}=  Discover BMC With Service Type  ${service_type}
+    ${openbmc_host_name}  ${openbmc_ip}=  Get Host Name IP  host=${OPENBMC_HOST}
+    ${resp}=  Check BMC Record Exists  ${bmc_list}  ${openbmc_ip}
+    Should Be True  'True' == '${resp}'
+
+
+Disable Daemon And Discover BMC After Reboot
+    [Documentation]  Discover BMC After reboot.
+    [Arguments]  ${service_type}
+
+    # Description of argument(s):
+    # service_type  BMC service type e.g.
+    #               (REST Service = _obmc_rest._tcp, Redfish Service = _obmc_redfish._tcp).
+
+    Set AvahiDaemon Service  command=stop
+    Redfish OBMC Reboot (off)
+    Verify AvahiDaemon Service Status  message=start
+    Login To OS  ${AVAHI_CLIENT}  ${AVAHI_CLIENT_USERNAME}  ${AVAHI_CLIENT_PASSWORD}
+    Wait Until Keyword Succeeds  2 min  30 sec
+    ...  Verify Existence Of BMC Record From List  ${service_type}