Menu

push_errata function suggestion

2011-04-13
2013-02-14
  • Jason Nielsen

    Jason Nielsen - 2011-04-13

    This can be cleaned up and likely done far better. Ive never written any perl and Im very new to SW. Anyhow this will only submit packages to channels they are found in bypassing the "bug" in which submission to all channels results in cross posting of packages. See the comment "###use a config…" as this works for me. I was thinking a config file that maps what archs you want and to which they belong. This is not needed but it speeds the process up dramatically otherwise you have ALL archs being searched.

    sub push_errata {
        our @bugs = @bugs;
        our %errata_info = %errata_info;
        our $rhn_client;
        our $rhn_session;
        our $spwk_client;
        our $spwk_session;
        my @packages;
        my @keywords;
        my @channels;
        my @errata_packages = $rhn_client->call('errata.listPackages',$rhn_session,$errata_info{advisory_name});
        my @swchannels = $spwk_client->call('channel.listAllChannels',$spwk_session);
        my $arch_match = 0;
        my $submit_errata = 0;
        my @chk_pkg;
        my %swchannel;
        my $lucene_query;
        foreach(@errata_packages) {
            foreach (@$_) {
                my %errata_package = %{ $_ };
                $lucene_query = "name:$errata_package{package_name} AND version:$errata_package{package_version} AND release:$errata_package{package_release} AND arch:$errata_package{package_arch_label}";
                foreach (@swchannels) {
                    foreach (@$_) {
                        %swchannel = %{ $_ };
    ###use a config file, pass as parameter etc?
                        if($swchannel{arch_name} eq "IA-32" &&  $errata_package{package_arch_label} eq "i386") { $arch_match = 1};
                        if($swchannel{arch_name} eq "x86_64" &&  $errata_package{package_arch_label} eq "x86_64") { $arch_match = 1};
                        if($arch_match == 1) { 
                            $arch_match = 0; 
                            @chk_pkg = $spwk_client->call('packages.search.advancedWithChannel',$spwk_session,$lucene_query,$swchannel{label});
                            if($chk_pkg[0][0]{id}) {
                                push(@packages, $chk_pkg[0][0]{id});
                                push(@channels, $swchannel{label});
                                push(@keywords, $errata_package{package_name});
                                $submit_errata = 1;
                                print "$swchannel{label}: $errata_package{package_name}.$errata_package{package_version}.$errata_package{package_release}.$errata_package{package_arch_label}\n";
                            }
                        }
                    }
                }
            }
        }
        if($submit_errata) {
            @keywords = uniq(@keywords);
            @packages = uniq(@packages);
            @channels = uniq(@channels);
            eval {$spwk_client->call('errata.create',$spwk_session,\%errata_info,\@bugs,\@keywords,\@packages,1,\@channels) };                  
            $submit_errata = 0;
        }
    }
    
     
  • Jason Nielsen

    Jason Nielsen - 2011-04-25

    The above code still suffers the same problem as the submission needs to take place within the inner loop upon package discovery. The problem is once you have submitted an errata once you cant do it again. This leads me to think that not only is this impossible to perform manually but the entire methodology of spacewalk's errata submission and package to channel association is either wrong or broken. The simple fact of pushing a package into a channel it does not exist within simply because the errata for that package was associated with a channel is wrong. Other than hacking up spacewalks code Im not seeing a way this can be resolved through the api.

     
  • Jason Nielsen

    Jason Nielsen - 2011-05-04

    An update to the code. So this will only publish to the channels in which the rpm exists although I dont publish so the code doing that part matters not. This solves nothing though as the ability to prevent cross posting of packages does not exist via the API. Its going to need a change in the java backend. Im guessing perhaps some where around SyncErrataPackagesAction.class. Anyhow, this wont publish as I tried publishing during creation and publishing after the fact and they both cross post. Oddly enough the later only cross posts some packages. No idea why. I am merely posting this with the remote chance it might provide some help/insight.

    sub push_errata {
        our @bugs = @bugs;
        our %errata_info = %errata_info;
        our $rhn_client;
        our $rhn_session;
        our $spwk_client;
        our $spwk_session;
        my @packages;
        my @keywords;
        my @channels;
        my @errata_packages = $rhn_client->call('errata.listPackages',$rhn_session,$errata_info{advisory_name});
        my @swchannels = $spwk_client->call('channel.listAllChannels',$spwk_session);
        my $arch_match = 0;
        my @chk_pkg;
        my %swchannel;
        my $lucene_query;
    #Name-Version-Release.ARCH
        foreach(@errata_packages) {
            foreach (@$_) {
                my %errata_package = %{ $_ };
                $lucene_query = "name:$errata_package{package_name} AND version:$errata_package{package_version} AND release:$errata_package{package_release} AND arch:$errata_package{package_arch_label}";
                foreach (@swchannels) {
                    foreach (@$_) {
                        %swchannel = %{ $_ };
    ###use a config file, pass as parameter etc?
                        if($swchannel{arch_name} eq "IA-32" &&  $errata_package{package_arch_label} eq "i386") { $arch_match = 1};
                        if($swchannel{arch_name} eq "x86_64" &&  $errata_package{package_arch_label} eq "x86_64") { $arch_match = 1};
                        if($arch_match == 1) { 
                            $arch_match = 0; 
                            @chk_pkg = $spwk_client->call('packages.search.advancedWithChannel',$spwk_session,$lucene_query,$swchannel{label});
                            #print "Searching for: $swchannel{label}: $errata_package{package_name}.$errata_package{package_version}.$errata_package{package_release}.$errata_package{package_arch_label}\n";
                            if($chk_pkg[0][0]{id}) {
                                push(@packages, $chk_pkg[0][0]{id});
                                push(@channels, $swchannel{label});
                                push(@keywords, $errata_package{package_name});
                                @keywords = uniq(@keywords);
                                @packages = uniq(@packages);
                                @channels = uniq(@channels);
                                eval{ $spwk_client->call('errata.getDetails',$spwk_session,$errata_info{advisory_name}) };
                                #print "EVAL is: $@\n";
                                if ( $@ ) {
                                    print "Creating errata $errata_info{advisory_name}.\n";
                                    eval {$spwk_client->call('errata.create',$spwk_session,\%errata_info,\@bugs,\@keywords,\@packages,0,\@channels) };
                                }
                                else {
                                    print "Adding the package $errata_package{package_name}.$errata_package{package_version}.$errata_package{package_release}.$errata_package{package_arch_label}.\n";
                                    eval {$spwk_client->call('errata.addPackages',$spwk_session,$errata_info{advisory_name},\@packages) };
                                }
                                @packages=();
                            }
                        }
                    }
                }
            }
        }
        my %errata_updates = ("keywords" => \@keywords);
        eval {$spwk_client->call('errata.setDetails',$spwk_session,$errata_info{advisory_name},\%errata_updates) };
        @keywords=();
        @channels=();
    }
    
     
  • zan

    zan - 2011-06-07

    That looks incredibly complicated.

     
  • Angel

    Angel - 2012-03-30

    I really feel the same, I have 6 channels of red hat and each time I run "get_errata.pl" I increased the number of packets on each channel producing the updates fail.

     

Log in to post a comment.