From 1f860f939dcbd90a7a3b6cd88d21066e306dfd98 Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Wed, 9 Oct 2019 20:28:52 -0700 Subject: [PATCH] Fix sql migrate repo prefix check Without this patch, the test_migrate_repos_file_names_have_prefix test may not necessarily check the latest migration in the repo but could be checking a __pycache__ file or a .pyc bytecode file, which would cause the test to pass even if the latest migration did not contain the required expand/migrate/contract prefix[1]. This patch corrects the issue by using the glob module to filter only valid python files to check. This issue was noticed when the test correctly caught an error in the py27 unit test job[1] but erroneously let slide the issue in the py3 tests[2]. [1] https://aca43ed1a01d95dea0ee-dcdb6cbb330bdac08ffee1284f86c919.ssl.cf2.rackcdn.com/687753/2/check/openstack-tox-py27/f602c1f/testr_results.html.gz [2] https://openstack.fortnebula.com:13808/v1/AUTH_e8fd161dc34c421a979a9e6421f823e9/zuul_opendev_logs_832/687753/2/check/openstack-tox-py37/8322cff/testr_results.html.gz Change-Id: I636f420e8a0c274131281af1d5aae931c164d91d --- keystone/tests/unit/test_sql_upgrade.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/keystone/tests/unit/test_sql_upgrade.py b/keystone/tests/unit/test_sql_upgrade.py index c048fe516a..cd03fbf011 100644 --- a/keystone/tests/unit/test_sql_upgrade.py +++ b/keystone/tests/unit/test_sql_upgrade.py @@ -39,6 +39,7 @@ WARNING:: """ import datetime +import glob import json import os import uuid @@ -1674,22 +1675,22 @@ class VersionTests(SqlMigrateBase): """ versions_path = '/versions' # test for expand prefix, e.g. 001_expand_new_fk_constraint.py - expand_list = os.listdir( - self.repos[EXPAND_REPO].repo_path + versions_path) + expand_list = glob.glob( + self.repos[EXPAND_REPO].repo_path + versions_path + '/*.py') self.assertRepoFileNamePrefix(expand_list, 'expand') # test for migrate prefix, e.g. 001_migrate_new_fk_constraint.py - migrate_list = os.listdir( - self.repos[DATA_MIGRATION_REPO].repo_path + versions_path) + migrate_list = glob.glob( + self.repos[DATA_MIGRATION_REPO].repo_path + versions_path + '/*.py') self.assertRepoFileNamePrefix(migrate_list, 'migrate') # test for contract prefix, e.g. 001_contract_new_fk_constraint.py - contract_list = os.listdir( - self.repos[CONTRACT_REPO].repo_path + versions_path) + contract_list = glob.glob( + self.repos[CONTRACT_REPO].repo_path + versions_path + '/*.py') self.assertRepoFileNamePrefix(contract_list, 'contract') def assertRepoFileNamePrefix(self, repo_list, prefix): if len(repo_list) > 1: # grab the file name for the max version - file_name = sorted(repo_list)[-2] + file_name = os.path.basename(sorted(repo_list)[-2]) # pattern for the prefix standard, ignoring placeholder, init files pattern = ( '^[0-9]{3,}_PREFIX_|^[0-9]{3,}_placeholder.py|^__init__.py')