Fix DOS test case false pass and add Teardown

The test case 'Verify User Cannot Login After 5 Non-Logged In Sessions'
is designed to verify that a type of Denial-Of-Service attack is prevented.
Specifically, it verifies that the root user cannot log in if
5 other SSH sessions are running but login has not been authenticated.
However, the test case does not first verify that the attempted
login method would otherwise succeed. If the attempted login method
is faulty, then the test case will falsely report a pass, as I have seen.

To address this, I added a Setup that skips the test if the login
does not succeed.

I also added a Teardown method that terminates the processes and
sessions. This makes manual testing more convenient - I was
experiencing pop-up messages from the SSHLibrary connections
before they automatically timed out.

Signed-off-by: Gene Ratzlaff <generatz@gmail.com>
Change-Id: Id10b15e09e1ae24a809c593f291c5dd9f025f364
diff --git a/security/test_bmc_connections.robot b/security/test_bmc_connections.robot
index 0c458b1..f75e73b 100644
--- a/security/test_bmc_connections.robot
+++ b/security/test_bmc_connections.robot
@@ -76,6 +76,9 @@
     [Documentation]  User should not be able to login when there
     ...  are 5 non-logged in sessions.
     [Tags]  Verify_User_Cannot_Login_After_5_Non-Logged_In_Sessions
+    [Setup]  Confirm Ability to Connect Then Close All Connections
+    [Teardown]  Run Keywords  Process.Terminate All Processes  AND
+    ...  SSHLibrary.Close All Connections  AND  FFDC On Test Case Fail
 
     FOR  ${iter}  IN RANGE  ${0}  ${MAX_UNAUTH_PER_IP}
        SSHLibrary.Open Connection  ${OPENBMC_HOST}
@@ -334,3 +337,15 @@
     Log  ${failed_iter_list}
     ${fail_count}=  Get Length  ${failed_iter_list}
     Run Keyword If  ${fail_count} > ${0}  FAIL  Could not Login to Redfish ${fail_count} times
+
+
+Confirm Ability to Connect Then Close All Connections
+    [Documentation]  Confirm that SSH login works, otherwise, skip this test.
+    ...  If login succeeds, close all SSH connections to BMC to prepare for test.
+
+    SSHLibrary.Close All Connections
+    SSHLibrary.Open Connection  ${OPENBMC_HOST}
+    ${status}=   Run Keyword And Return Status
+    ...  SSHLibrary.Login  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
+    Skip If  ${status} == ${False}  msg= SSH Login failed: test will be skipped
+    SSHLibrary.Close All Connections