network_VPNConnect: ping check fails when _expect_success is False

If self._expect_success is False, it means that the VPN client is
intentionally using incorrect credentials, therefore the VPN connection
should not be established.  Skip the ping check if the VPN isn't up.

BUG=chromium:804524
TEST=`test_that -b eve IP network_VPNConnect.l2tpipsec_psk \
                          network_VPNConnect.l2tpipsec_cert \
                          network_VPNConnect.l2tpipsec_xauth \
                          network_VPNConnect.openvpn_user_pass \
                          network_VPNConnect.openvpn`

Change-Id: I526f83600613ebc9c90b51af311e32df85d0b993
Reviewed-on: https://chromium-review.googlesource.com/924763
Commit-Ready: Kevin Cernekee <cernekee@chromium.org>
Tested-by: Kevin Cernekee <cernekee@chromium.org>
Reviewed-by: Harpreet Grewal <harpreet@chromium.org>
(cherry picked from commit 2008ad60659ed9114f519a094a5068e54a1ed916)
Reviewed-on: https://chromium-review.googlesource.com/959182
Reviewed-by: Kevin Cernekee <cernekee@chromium.org>
Commit-Queue: Kevin Cernekee <cernekee@chromium.org>
diff --git a/client/site_tests/network_VPNConnect/network_VPNConnect.py b/client/site_tests/network_VPNConnect/network_VPNConnect.py
index 1731fdc..b9bc64a 100644
--- a/client/site_tests/network_VPNConnect/network_VPNConnect.py
+++ b/client/site_tests/network_VPNConnect/network_VPNConnect.py
@@ -207,6 +207,7 @@
         if successful and not self._expect_success:
             raise error.TestFail('VPN connection suceeded '
                                  'when it should have failed')
+        return successful
 
 
     def run_once(self, vpn_types=[]):
@@ -249,13 +250,15 @@
                                          self.NETWORK_PREFIX)
 
                 with self.get_vpn_server() as server:
-                    self.connect_vpn()
-                    res = utils.ping(server.SERVER_IP_ADDRESS, tries=3,
-                                     user='chronos')
-                    if res != 0:
-                        raise error.TestFail('Error pinging server IP')
+                    if self.connect_vpn():
+                        res = utils.ping(server.SERVER_IP_ADDRESS, tries=3,
+                                         user='chronos')
+                        if res != 0:
+                            raise error.TestFail('Error pinging server IP')
 
-                    # IPv6 should be blackholed, so ping returns "other error"
-                    res = utils.ping("2001:db8::1", tries=1, user='chronos')
-                    if res != 2:
-                        raise error.TestFail('IPv6 ping should have aborted')
+                        # IPv6 should be blackholed, so ping returns
+                        # "other error"
+                        res = utils.ping("2001:db8::1", tries=1, user='chronos')
+                        if res != 2:
+                            raise error.TestFail('IPv6 ping should '
+                                                 'have aborted')