def make_rpc_report(repo_dir, old_commit, new_commit, args): """Create initial RST report header for OpenStack-Ansible.""" rpc_repo_url = "https://github.com/rcbops/rpc-openstack" osa_differ.update_repo(repo_dir, rpc_repo_url, args.update) # Are these commits valid? osa_differ.validate_commits(repo_dir, [old_commit, new_commit]) # Do we have a valid commit range? osa_differ.validate_commit_range(repo_dir, old_commit, new_commit) # Get the commits in the range commits = osa_differ.get_commits(repo_dir, old_commit, new_commit) # Start off our report with a header and our OpenStack-Ansible commits. template_vars = { 'args': args, 'repo': 'rpc-openstack', 'commits': commits, 'commit_base_url': osa_differ.get_commit_url(rpc_repo_url), 'old_sha': old_commit, 'new_sha': new_commit } return render_template('offline-header.j2', template_vars)
def test_repo_update_update(self, tmpdir): """Verify that update_repo tries to update the repo.""" p = tmpdir.mkdir('test') path = str(p) repo = Repo.init(path) file = p / 'test.txt' file.write_text(u'Testing', encoding='utf-8') repo.index.add(['test.txt']) repo.index.commit('Testing') result = osa_differ.update_repo(path, path) assert result.active_branch.name == 'master' assert not result.is_dirty()
def make_rpc_report(repo_dir, old_commit, new_commit, args): """Create initial RST report header for OpenStack-Ansible.""" rpc_repo_url = args.rpc_repo_url osa_differ.update_repo(repo_dir, rpc_repo_url, args.update) # Are these commits valid? osa_differ.validate_commits(repo_dir, [old_commit, new_commit]) # Do we have a valid commit range? # NOTE: # An exception is thrown by osa_differ if these two commits # are the the same, but it is sometimes necessary to compare # two RPC tags that have the same OSA SHA. For example, # comparing two tags that only have differences between the # two RPCO commit, but no differences between the OSA SHAs # that correspond to those two commits. # To handle this case, the exception will be caught and flow # of execution will continue normally. try: osa_differ.validate_commit_range(repo_dir, old_commit, new_commit) except exceptions.InvalidCommitRangeException: pass # Get the commits in the range commits = osa_differ.get_commits(repo_dir, old_commit, new_commit) # Start off our report with a header and our OpenStack-Ansible commits. template_vars = { 'args': args, 'repo': 'rpc-openstack', 'commits': commits, 'commit_base_url': osa_differ.get_commit_url(rpc_repo_url), 'old_sha': old_commit, 'new_sha': new_commit } return render_template('offline-header.j2', template_vars)
def test_repo_clone_update(self, tmpdir): """Verify that we can clone a repo.""" p = tmpdir.mkdir('test') path = str(p) repo = Repo.init(path) file = p / 'test.txt' file.write_text(u'Testing', encoding='utf-8') repo.index.add(['test.txt']) repo.index.commit('Testing') p = tmpdir.mkdir("test2") path_clonefrom = "{0}/testrepodoesntexist".format(str(p)) result = osa_differ.update_repo(path_clonefrom, path) assert result.active_branch.name == 'master' assert not result.is_dirty()
def run_rpc_differ(): """The script starts here.""" args = parse_arguments() # Set up DEBUG logging if needed if args.debug: log.setLevel(logging.DEBUG) elif args.verbose: log.setLevel(logging.INFO) # Create the storage directory if it doesn't exist already. try: storage_directory = osa_differ.prepare_storage_dir(args.directory) except OSError: print("ERROR: Couldn't create the storage directory {0}. " "Please create it manually.".format(args.directory)) sys.exit(1) # Prepare the rpc-openstack repository. rpc_repo_url = args.rpc_repo_url rpc_repo_dir = "{0}/rpc-openstack".format(storage_directory) osa_differ.update_repo(rpc_repo_dir, rpc_repo_url, args.update) # Validate/update the commits. rpc_old_commit = validate_rpc_sha(rpc_repo_dir, args.old_commit[0]) rpc_new_commit = validate_rpc_sha(rpc_repo_dir, args.new_commit[0]) # Generate RPC report header. report_rst = make_rpc_report(rpc_repo_dir, rpc_old_commit, rpc_new_commit, args) # Get the list of RPC roles from the newer and older commits. try: role_yaml = osa_differ.get_roles(rpc_repo_dir, rpc_old_commit, args.role_requirements) except IOError: role_yaml = osa_differ.get_roles(rpc_repo_dir, rpc_old_commit, ROLE_REQ_FILE) try: role_yaml_latest = osa_differ.get_roles(rpc_repo_dir, rpc_old_commit, args.role_requirements) except IOError: role_yaml_latest = osa_differ.get_roles(rpc_repo_dir, rpc_old_commit, ROLE_REQ_FILE) # Generate the role report. report_rst += ("\nRPC-OpenStack Roles\n" "-------------------") report_rst += osa_differ.make_report(storage_directory, role_yaml, role_yaml_latest, args.update, args.version_mappings) report_rst += "\n" # Generate OpenStack-Ansible report. repo = Repo(rpc_repo_dir) osa_old_commit = get_osa_commit(repo, rpc_old_commit, rpc_product=args.rpc_product) osa_new_commit = get_osa_commit(repo, rpc_new_commit, rpc_product=args.rpc_product) log.debug("OSA Commits old:{old} new:{new}".format(old=osa_old_commit, new=osa_new_commit)) osa_repo_dir = "{0}/openstack-ansible".format(storage_directory) # NOTE: # An exception is thrown by osa_differ if these two commits # are the the same, but it is sometimes necessary to compare # two RPC tags that have the same OSA SHA. For example, # comparing two tags that only have differences between the # two RPCO commit, but no differences between the OSA SHAs # that correspond to those two commits. # To handle this case, the exception will be caught and flow # of execution will continue normally. try: report_rst += osa_differ.make_osa_report(osa_repo_dir, osa_old_commit, osa_new_commit, args) except exceptions.InvalidCommitRangeException: pass # Get the list of OpenStack-Ansible roles from the newer and older commits. try: role_yaml = osa_differ.get_roles(osa_repo_dir, osa_old_commit, args.role_requirements) except IOError: role_yaml = osa_differ.get_roles(osa_repo_dir, osa_old_commit, ROLE_REQ_FILE) try: role_yaml_latest = osa_differ.get_roles(osa_repo_dir, osa_new_commit, args.role_requirements) except IOError: role_yaml_latest = osa_differ.get_roles(osa_repo_dir, osa_new_commit, ROLE_REQ_FILE) # Generate the role report. report_rst += ("\nOpenStack-Ansible Roles\n" "-----------------------") report_rst += osa_differ.make_report(storage_directory, role_yaml, role_yaml_latest, args.update, args.version_mappings) project_yaml = osa_differ.get_projects(osa_repo_dir, osa_old_commit) project_yaml_latest = osa_differ.get_projects(osa_repo_dir, osa_new_commit) # Generate the project report. report_rst += ("OpenStack-Ansible Projects\n" "--------------------------") report_rst += osa_differ.make_report(storage_directory, project_yaml, project_yaml_latest, args.update, args.version_mappings) # Publish report according to the user's request. output = publish_report(report_rst, args, rpc_old_commit, rpc_new_commit) print(output)