[Autotest] Adding a check/warn to external storage check
There is some flake with the external storage check. Adding a warn to
help catch where this could be happening
TEST=this
BUG=None
Change-Id: I0c6983f2d6c67d78ec6bfe56694f80a460824118
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/1980929
Reviewed-by: Derek Beckett <dbeckett@chromium.org>
Commit-Queue: Derek Beckett <dbeckett@chromium.org>
Tested-by: Derek Beckett <dbeckett@chromium.org>
diff --git a/client/site_tests/policy_ExternalStorageReadOnly/policy_ExternalStorageReadOnly.py b/client/site_tests/policy_ExternalStorageReadOnly/policy_ExternalStorageReadOnly.py
index 727901e..9256baf 100644
--- a/client/site_tests/policy_ExternalStorageReadOnly/policy_ExternalStorageReadOnly.py
+++ b/client/site_tests/policy_ExternalStorageReadOnly/policy_ExternalStorageReadOnly.py
@@ -33,7 +33,6 @@
super(policy_ExternalStorageReadOnly, self).cleanup()
-
def _test_external_storage(self, policy_value):
"""
Verify the behavior of the ExternalStorageReadOnly policy.
@@ -48,17 +47,15 @@
"""
# Attempt to modify the external storage by creating a file.
- try:
- return_code = utils.run('touch %s' % self.TEST_FILE)
- except error.CmdError:
- if not policy_value:
- raise error.TestFail('External storage not readonly but '
- 'unable to write to storage')
- else:
- if policy_value:
- raise error.TestFail('External storage was readonly but '
- 'external storage was modified')
-
+ if os.path.isfile(self.TEST_FILE):
+ raise error.TestWarn('Test file existed prior to test.')
+ utils.run('touch %s' % self.TEST_FILE, ignore_status=True)
+ if policy_value and os.path.isfile(self.TEST_FILE):
+ raise error.TestFail('External storage set to read-only but '
+ 'was able to write to storage.')
+ elif not policy_value and not os.path.isfile(self.TEST_FILE):
+ raise error.TestFail('External storage not read-only but '
+ 'unable to write to storage.')
def run_once(self, case):
"""