Remove pre-check for test accounts file in credential factory

This commit removes a check for a valid accounts.yaml file before
we use the preprov cred provider. This masks real configuration issues
and makes it very confusing for users to see when something doesn't
work because it defaults to trying to use the legacy provider. Since
we'll actually fail to load a missing accounts.yaml file now this also
adds a check for IOError and raises an InvalidConfiguration exception
with a descriptive message instead.

Change-Id: I9c02b406746af799f8939e0b9d06c14b48302a7e
diff --git a/tempest/common/credentials_factory.py b/tempest/common/credentials_factory.py
index 95dcafc..5d290d4 100644
--- a/tempest/common/credentials_factory.py
+++ b/tempest/common/credentials_factory.py
@@ -11,8 +11,6 @@
 #    See the License for the specific language governing permissions and
 #    limitations under the License.
 
-import os
-
 from oslo_concurrency import lockutils
 from oslo_log import log as logging
 from tempest_lib import auth
@@ -170,8 +168,7 @@
             admin_creds=admin_creds,
             **_get_dynamic_provider_params())
     else:
-        if (CONF.auth.test_accounts_file and
-                os.path.isfile(CONF.auth.test_accounts_file)):
+        if CONF.auth.test_accounts_file:
             # Most params are not relevant for pre-created accounts
             return preprov_creds.PreProvisionedCredentialProvider(
                 name=name, identity_version=identity_version,
@@ -193,8 +190,7 @@
     if CONF.auth.use_dynamic_credentials:
         return is_admin
     # Check whether test accounts file has the admin specified or not
-    elif (CONF.auth.test_accounts_file and
-            os.path.isfile(CONF.auth.test_accounts_file)):
+    elif CONF.auth.test_accounts_file:
         check_accounts = preprov_creds.PreProvisionedCredentialProvider(
             identity_version=identity_version, name='check_admin',
             **_get_preprov_provider_params())
@@ -219,8 +215,7 @@
     if CONF.auth.use_dynamic_credentials:
         return True
     # Check whether test accounts file has the admin specified or not
-    if (CONF.auth.test_accounts_file and
-            os.path.isfile(CONF.auth.test_accounts_file)):
+    if CONF.auth.test_accounts_file:
         check_accounts = preprov_creds.PreProvisionedCredentialProvider(
             identity_version=identity_version, name='check_alt',
             **_get_preprov_provider_params())
diff --git a/tempest/common/preprov_creds.py b/tempest/common/preprov_creds.py
index 74cc3f0..34af31e 100644
--- a/tempest/common/preprov_creds.py
+++ b/tempest/common/preprov_creds.py
@@ -31,8 +31,13 @@
 
 
 def read_accounts_yaml(path):
-    with open(path, 'r') as yaml_file:
-        accounts = yaml.load(yaml_file)
+    try:
+        with open(path, 'r') as yaml_file:
+            accounts = yaml.load(yaml_file)
+    except IOError:
+        raise exceptions.InvalidConfiguration(
+            'The path for the test accounts file: %s '
+            'could not be found' % path)
     return accounts
 
 
@@ -74,7 +79,7 @@
             identity_version=identity_version, name=name,
             admin_role=admin_role, credentials_domain=credentials_domain)
         self.test_accounts_file = test_accounts_file
-        if test_accounts_file and os.path.isfile(test_accounts_file):
+        if test_accounts_file:
             accounts = read_accounts_yaml(self.test_accounts_file)
             self.use_default_creds = False
         else: