Exemplo n.º 1
0
    def test_prepare_storage_directory_exception(self, tmpdir):
        """Verify that we can create a storage directory."""
        p = tmpdir.mkdir("test")
        newdir = "{0}/subdir/subdir/subdir".format(str(p))

        with raises(OSError):
            osa_differ.prepare_storage_dir(newdir)
Exemplo n.º 2
0
def run_rpc_differ():
    """The script starts here."""
    args = parse_arguments()

    # 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)

    # Assemble some variables for the RPC repository.
    rpc_old_commit = args.old_commit[0]
    rpc_new_commit = args.new_commit[0]
    rpc_repo_dir = "{0}/rpc-openstack".format(storage_directory)

    # 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.
    role_yaml = osa_differ.get_roles(rpc_repo_dir, rpc_old_commit)
    role_yaml_latest = osa_differ.get_roles(rpc_repo_dir, rpc_new_commit)

    # Generate the role report.
    report_rst += ("RPC-OpenStack Roles\n"
                   "-------------------")
    report_rst += osa_differ.make_report(storage_directory,
                                         role_yaml,
                                         role_yaml_latest,
                                         args.update)

    report_rst += "\n"

    # Generate OpenStack-Ansible report.
    osa_old_commit, osa_new_commit = get_osa_commits(rpc_repo_dir,
                                                     rpc_old_commit,
                                                     rpc_new_commit)

    osa_repo_dir = "{0}/openstack-ansible".format(storage_directory)
    report_rst += osa_differ.make_osa_report(osa_repo_dir,
                                             osa_old_commit,
                                             osa_new_commit,
                                             args)

    # Get the list of OpenStack-Ansible roles from the newer and older commits.
    role_yaml = osa_differ.get_roles(osa_repo_dir, osa_old_commit)
    role_yaml_latest = osa_differ.get_roles(osa_repo_dir, osa_new_commit)

    # Generate the role report.
    report_rst += ("OpenStack-Ansible Roles\n"
                   "-----------------------")
    report_rst += osa_differ.make_report(storage_directory,
                                         role_yaml,
                                         role_yaml_latest,
                                         args.update)

    # Get the list of OpenStack projects from newer commit and older commit.
    yaml_files = [
        'playbooks/defaults/repo_packages/openstack_services.yml',
        'playbooks/defaults/repo_packages/openstack_other.yml'
    ]
    project_yaml = osa_differ.get_projects(osa_repo_dir,
                                           yaml_files,
                                           osa_old_commit)
    project_yaml_latest = osa_differ.get_projects(osa_repo_dir,
                                                  yaml_files,
                                                  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)

    # Publish report according to the user's request.
    output = publish_report(report_rst,
                            args,
                            rpc_old_commit,
                            rpc_new_commit)
    print(output)
Exemplo n.º 3
0
 def test_prepare_storage_directory_exists(self, tmpdir):
     """Verify that we can create a storage directory."""
     p = tmpdir.mkdir("test")
     storagedir = osa_differ.prepare_storage_dir(str(p))
     assert storagedir == p
Exemplo n.º 4
0
 def test_prepare_storage_directory_create(self, tmpdir):
     """Verify that we can create a storage directory."""
     p = tmpdir.mkdir("test")
     newdir = "{0}/subdir".format(str(p))
     storagedir = osa_differ.prepare_storage_dir(newdir)
     assert storagedir == newdir
Exemplo n.º 5
0
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)

    # Assemble some variables for the RPC repository.
    rpc_old_commit = args.old_commit[0]
    rpc_new_commit = args.new_commit[0]
    rpc_repo_dir = "{0}/rpc-openstack".format(storage_directory)

    # 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.
    role_yaml = osa_differ.get_roles(rpc_repo_dir, rpc_old_commit)
    role_yaml_latest = osa_differ.get_roles(rpc_repo_dir, rpc_new_commit)

    # 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)

    report_rst += "\n"

    # Generate OpenStack-Ansible report.
    repo = Repo(rpc_repo_dir)
    osa_old_commit = get_osa_commit(repo, rpc_old_commit)
    osa_new_commit = get_osa_commit(repo, rpc_new_commit)
    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.
    role_yaml = osa_differ.get_roles(osa_repo_dir, osa_old_commit)
    role_yaml_latest = osa_differ.get_roles(osa_repo_dir, osa_new_commit)

    # 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)

    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)

    # Publish report according to the user's request.
    output = publish_report(report_rst, args, rpc_old_commit, rpc_new_commit)
    print(output)