def run(self): pkg_name = self.context.package_name if pkg_name in self.package_dependency_dict: logging.info("Running regression test for {}".format(pkg_name)) self.whl_path = os.path.join( self.context.whl_directory, find_whl(pkg_name, self.context.pkg_version, self.context.whl_directory)) if find_packages_missing_on_pypi(self.whl_path): logging.error( "Required packages are not available on PyPI. Skipping regression test" ) exit(0) dep_packages = self.package_dependency_dict[pkg_name] logging.info("Dependent packages for [{0}]: {1}".format( pkg_name, dep_packages)) for dep_pkg_path in dep_packages: dep_pkg_name, _, _, _ = parse_setup(dep_pkg_path) logging.info( "Starting regression test of {0} against released {1}". format(pkg_name, dep_pkg_name)) self._run_test(dep_pkg_path) logging.info( "Completed regression test of {0} against released {1}". format(pkg_name, dep_pkg_name)) logging.info("Completed regression test for {}".format(pkg_name)) else: logging.info( "Package {} is not added as required by any package".format( pkg_name))
def _run_test(self, dep_pkg_path): self.context.initialize(dep_pkg_path) # find GA released tags for package and run test using that code base dep_pkg_name, version, _, _ = parse_setup(dep_pkg_path) release_tag = get_release_tag(dep_pkg_name, self.context.is_latest_depend_test) if not release_tag: logging.error( "Release tag is not available. Skipping package {} from test". format(dep_pkg_name)) return test_branch_name = "{0}_tests".format(release_tag) try: git_checkout_branch(test_branch_name, dep_pkg_path) except: # If git checkout failed for "tests" branch then checkout branch with release tag logging.info( "Failed to checkout branch {}. Checking out release tagged git repo" .format(test_branch_name)) git_checkout_tag(release_tag, dep_pkg_path) try: # install packages required to run tests run_check_call([ self.context.venv.python_executable, "-m", "pip", "install", "-r", test_tools_req_file, ], dep_pkg_path) # Install pre-built whl for current package. install_package_from_whl( self.whl_path, self.context.temp_path, self.context.venv.python_executable, ) # install dependent package from source self._install_packages(dep_pkg_path, self.context.package_name) # try install of pre-built whl for current package again. if unnecessary, pip does nothing. # we do this to ensure that the correct development version is installed. on non-dev builds # this step will just skip through. install_package_from_whl( self.whl_path, self.context.temp_path, self.context.venv.python_executable, ) self._execute_test(dep_pkg_path) finally: self.context.deinitialize(dep_pkg_path)
def find_package_dependency(glob_string, repo_root_dir): package_paths = process_glob_string(glob_string, repo_root_dir, "", "Regression") dependency_map = {} for pkg_root in package_paths: _, _, _, requires = parse_setup(pkg_root) # Get a list of package names from install requires required_pkgs = [parse_require(r)[0] for r in requires] required_pkgs = [p for p in required_pkgs if p.startswith("azure")] for req_pkg in required_pkgs: if req_pkg not in dependency_map: dependency_map[req_pkg] = [] dependency_map[req_pkg].append(pkg_root) logging.info("Package dependency: {}".format(dependency_map)) return dependency_map
def build_whl_for_req(req, package_path): if ".." in req: # Create temp path if it doesn't exist temp_dir = os.path.join(package_path, ".tmp_whl_dir") if not os.path.exists(temp_dir): os.mkdir(temp_dir) req_pkg_path = os.path.abspath(os.path.join(package_path, req.replace("\n", ""))) pkg_name, version, _, _ = parse_setup(req_pkg_path) logging.info("Building wheel for package {}".format(pkg_name)) run_check_call([sys.executable, "setup.py", "bdist_wheel", "-d", temp_dir], req_pkg_path) whl_path = find_whl(pkg_name, version, temp_dir) logging.info("Wheel for package {0} is {1}".format(pkg_name, whl_path)) logging.info("Replacing dev requirement. Old requirement:{0}, New requirement:{1}".format(req, whl_path)) return whl_path else: return req
def _run_test(self, dep_pkg_path): self.context.initialize(dep_pkg_path) # find GA released tags for package and run test using that code base dep_pkg_name, version, _, _ = parse_setup(dep_pkg_path) release_tag = get_release_tag(dep_pkg_name, self.context.is_latest_depend_test) if not release_tag: logging.error( "Release tag is not available. Skipping package {} from test". format(dep_pkg_name)) return test_branch_name = "{0}_tests".format(release_tag) try: git_checkout_branch(test_branch_name, dep_pkg_path) except: # If git checkout failed for "tests" branch then checkout branch with release tag logging.info( "Failed to checkout branch {}. Checking out release tagged git repo" .format(test_branch_name)) git_checkout_tag(release_tag, dep_pkg_path) try: # install packages required to run tests run_check_call([ self.context.venv.python_executable, "-m", "pip", "install", "-r", test_tools_req_file, ], dep_pkg_path) # Install pre-built whl for current package install_package_from_whl( self.whl_path, self.context.temp_path, self.context.venv.python_executable, ) # install package to be tested and run pytest self._execute_test(dep_pkg_path) finally: self.context.deinitialize(dep_pkg_path)
def verify_packages(targeted_packages): # run the build and distribution change_log_missing = {} for package in targeted_packages: # Parse setup.py using common helper method to get version and package name pkg_name, version, _ = parse_setup(package) # Skip management packages if "-mgmt" in pkg_name or pkg_name in excluded_packages: continue if not find_change_log(package, version): logging.error( "Change log is not updated for package {0}, version {1}". format(pkg_name, version)) change_log_missing[pkg_name] = version return change_log_missing
def find_package_dependency(glob_string, repo_root_dir, dependent_service): package_paths = process_glob_string(glob_string, repo_root_dir, "", "Regression") dependent_service_filter = os.path.join('sdk', dependent_service.lower()) dependency_map = {} for pkg_root in package_paths: if dependent_service_filter in pkg_root: _, _, _, requires = parse_setup(pkg_root) # Get a list of package names from install requires required_pkgs = [parse_require(r)[0] for r in requires] required_pkgs = [p for p in required_pkgs if p.startswith("azure")] for req_pkg in required_pkgs: if req_pkg not in dependency_map: dependency_map[req_pkg] = [] dependency_map[req_pkg].append(pkg_root) return dependency_map
def _run_test(self, dep_pkg_path): self.context.initialize(dep_pkg_path) # find GA released tags for package and run test using that code base dep_pkg_name, _, _, _ = parse_setup(dep_pkg_path) release_tag = get_release_tag(dep_pkg_name, self.context.is_latest_depend_test) if not release_tag: logging.error( "Release tag is not avaiable. Skipping package {} from test". format(dep_pkg_name)) return # Get code repo with released tag of dependent package checkout_code_repo(release_tag, dep_pkg_path) try: # install packages required to run tests run_check_call( [ self.context.venv.python_executable, "-m", "pip", "install", "-r", test_tools_req_file, ], self.context.package_root_path, ) # Install pre-built whl for current package install_package_from_whl( self.context.package_name, self.context.pkg_version, self.context.whl_directory, self.context.temp_path, self.context.venv.python_executable, ) # install package to be tested and run pytest self._execute_test(dep_pkg_path) finally: self.context.deinitialize(dep_pkg_path)
def verify_packages(targeted_packages): # run the build and distribution change_log_missing = {} for package in targeted_packages: # Parse setup.py using common helper method to get version and package name pkg_name, version, _, _ = parse_setup(package) # Skip management packages and any explicitly excluded packages if "-mgmt" in pkg_name or pkg_name in NON_STANDARD_CHANGE_LOG_PACKAGES: logging.info( "Skipping {} due to known exclusion in change log verification" .format(pkg_name)) continue if not find_change_log(package, version): logging.error( "Change log is not updated for package {0}, version {1}". format(pkg_name, version)) change_log_missing[pkg_name] = version return change_log_missing
def run(self): pkg_name = self.context.package_name if pkg_name in self.package_dependency_dict: dep_packages = self.package_dependency_dict[pkg_name] logging.info("Running regression test for {}".format(pkg_name)) logging.info("Dependent packages for [{0}]: {1}".format( pkg_name, dep_packages)) for dep_pkg_path in dep_packages: dep_pkg_name, _, _, _ = parse_setup(dep_pkg_path) logging.info( "Starting regression test of {0} against released {1}". format(pkg_name, dep_pkg_name)) self._run_test(dep_pkg_path) logging.info( "Completed regression test of {0} against released {1}". format(pkg_name, dep_pkg_name)) logging.info("Completed regression test for {}".format(pkg_name)) else: logging.info( "Package {} is not added as required by any package".format( pkg_name))
def init_for_pkg(self, pkg_root): # This method is called each time context is switched to test regression for new package self.package_root_path = pkg_root self.package_name, self.pkg_version, _, _ = parse_setup( self.package_root_path)
help="The set of packages that we shouldn't be able to import.", ) parser.add_argument( "-p", "--path-to-setup", dest="target_setup", help= "The path to the setup.py (not including the file) for the package that we are running try_import alongside. The key here is that if a package on our 'check' list actually requires something, we will not fail the check.", ) args = parser.parse_args() acceptable_to_import = [] if args.target_setup: _, _, _, reqs = parse_setup(args.target_setup) acceptable_to_import = [ get_name_from_specifier(req).strip() for req in reqs ] importable_packages = [] for ns in [ ns for ns in list(args.imports) if ns not in acceptable_to_import ]: try: logging.info( "Ensuring that namespace {} is not importable.".format(ns)) exec("import {}".format(ns)) importable_packages.append(ns) except ImportError: