Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-3568

Freebsd pkg module fixups (promise outcome on package upgrade, fix repsoitory option )

    XMLWordPrintable

    Details

    • Story Points:
      0

      Description

      From: https://github.com/cfengine/masterfiles/pull/1886 submitted by Gian Piero Carrubba.

      cfengine properly reports that a packages promise has been correctly repaired in case of package upgrade or if the architecture has been explicitly declared in the promise

      the repository option is not ignored anymore

      Summary of fixes in PR:

      • Fixed promise status from package upgrade when architecture specified in promise
      • Removed unused variable in pkg module
      • Fixed pkg module parsing input when values include equals (=)
      • Fixed parsing of options attribute in pkg module
      • Added repo alias for repository option
      • Added support for option option

      Example Policy

      Example Policy (/tmp/CFE-3568.cf)
      bundle agent main
      {
        vars:
            'pkg'     string => 'bash';
            'oldver'  string => '5.0.17';
            'repo'    string => 'CFE-3568';
      
        methods:
          !cleanup::
            '' usebundle => install_architecture($(pkg));
            '' usebundle => update($(pkg), $(oldver));
      
            '' usebundle => create_repository($(repo));
            '' usebundle => install_repository($(repo), $(pkg));
      
          cleanup::
            '' usebundle => remove_repository($(repo));
            '' usebundle => install($(pkg));
      }
      
      bundle agent install(pkg)
      {
        packages:
            '$(pkg)'
                policy => 'absent';
            '$(pkg)'
                policy  => 'present',
                classes => lresults;
      
        reports:
            '* bundle   : $(this.bundle)';
            '  results  : $(with)'
                with => join(' ', classesmatching('_.*'));
            '  installed: $(with)'
                with => join(' ', mapdata('none', '$(this.v)', packagesmatching('$(pkg)', '.*', '.*', '.*')));
      }
      
      bundle agent install_architecture(pkg)
      {
        vars:
            'arch' string => execresult('/usr/bin/uname -m', noshell);
      
        packages:
            '$(pkg)'
                policy => 'absent';
            '$(pkg)'
                policy        => 'present',
                architecture  => $(arch),
                classes       => lresults;
      
        reports:
            '* bundle   : $(this.bundle)';
            '  results  : $(with)'
                with => join(' ', classesmatching('_.*'));
            '  installed: $(with)'
                with => join(' ', mapdata('none', '$(this.v)', packagesmatching('$(pkg)', '.*', '.*', '.*')));
      }
      
      bundle agent update(pkg, oldver)
      {
        packages:
            '$(pkg)'
                handle => '$(this.namespace)_$(this.bundle)_step_1',
                policy => 'absent';
            '/var/cache/pkg/$(pkg)-$(oldver).txz'
                policy      => 'present';
            '$(pkg)'
                policy      => 'present',
                version     => 'latest',
                classes     => lresults;
      
        reports:
            '* bundle   : $(this.bundle)';
            '  results  : $(with)'
                with => join(' ', classesmatching('_.*'));
            '  installed: $(with)'
                with => join(' ', mapdata('none', '$(this.v)', packagesmatching('$(pkg)', '.*', '.*', '.*')));
      }
      
      bundle agent install_repository(repo, pkg)
      {
        packages:
            '$(pkg)'
                policy => 'absent';
            '$(pkg)'
                comment => 'This promise should fail as the package is not present in the referred repo.',
                policy  => 'present',
                options => { 'repository=$(repo)' },
                classes => lresults;
      
        reports:
            '* bundle   : $(this.bundle)';
            '  results  : $(with)'
                with => join(' ', classesmatching('_.*'));
            '  installed: $(with)'
                with => join(' ', mapdata('none', '$(this.v)', packagesmatching('$(pkg)', '.*', '.*', '.*')));
      }
      
      bundle agent create_repository(repo)
      {
        vars:
            'path'      string => '/tmp/$(repo)-repo';
            'repoconf'  string => '
      $(repo): {
        url: "file://$(path)",
        enabled: true,
        mirror_type: "none"
      }
      ';
      
        files:
            '/usr/local/etc/pkg/repos/.'
                create  => 'true';
            '/usr/local/etc/pkg/repos/$(repo).conf'
                create                => 'true',
                template_method       => 'inline_mustache',
                edit_template_string  => '$(repoconf)';
            '$(path)/.'
                create  => 'true';
            '$(path)/fake.txz'
                create  => 'true';
      
        commands:
            '/usr/sbin/pkg repo -q $(path)'
                contain => silent;
            '/usr/sbin/pkg update -fqr $(repo)';
      }
      
      bundle agent remove_repository(repo)
      {
        vars:
            'path' string => '/tmp/$(repo)-repo';
      
        files:
            '/usr/local/etc/pkg/repos/$(repo).conf'
                delete => rm;
      
        commands:
            '/bin/rm -rf $(path)';
            '/usr/sbin/pkg update -q';
      }
      
      body contain silent
      {
        no_output => 'true';
      }
      
      body delete rm
      {
        dirlinks  => 'delete';
        rmdirs    => 'false' ;
      }
      
      body classes lresults
      {
        scope => 'bundle';
        promise_kept      => { '_reached', '_ok', '_kept' };
        promise_repaired  => { '_reached', '_ok', '_repaired' };
        repair_failed     => { '_reached', '_error', '_not_kept', '_failed' };
        repair_denied     => { '_reached', '_error', '_not_kept', '_denied' };
        repair_timeout    => { '_reached', '_error', '_not_kept', '_timeout' };
      }
      
      body package_module pkg
      {
        query_installed_ifelapsed => "0";
        query_updates_ifelapsed   => "0";
      }
      
      body common control
      {
        package_module    => 'pkg';
        package_inventory => {'pkg'};
      }
      
      

      Before changes

      # cf-agent -K /tmp/CFE-3568.cf 
         error: Error installing package 'bash'
      R: * bundle   : install_architecture
      R:   results  : _failed _not_kept _error _reached
      R:   installed: bash 5.1.4 FreeBSD:12:i386 pkg
         error: Method 'install_architecture' failed in some repairs
         error: Error installing package 'bash'
      R: * bundle   : update
      R:   results  : _failed _not_kept _error _reached
      R:   installed: bash 5.1.4 FreeBSD:12:i386 pkg
         error: Method 'update' failed in some repairs
      R: * bundle   : install_repository
      R:   results  : _repaired _ok _reached
      R:   installed: bash 5.1.4 FreeBSD:12:i386 pkg
      

      After changes

      In the first 2 tests (install_architecture and update) CFEngine could not recognize the promise was repaired despite the package had been correctly installed

      in the 3rd test (install_repository) the package had been installed despite not existing in the referred repository (the repository option was ignored)

      # cf-agent -K /tmp/CFE-3568.cf 
      R: * bundle   : install_architecture
      R:   results  : _repaired _ok _reached
      R:   installed: bash 5.1.4 i386 pkg
      R: * bundle   : update
      R:   results  : _repaired _ok _reached
      R:   installed: bash 5.1.4 i386 pkg
         error: Error installing package 'bash'
      R: * bundle   : install_repository
      R:   results  : _failed _not_kept _error _reached
      R:   installed: 
         error: Method 'install_repository' failed in some repairs
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              a10042 Nick Anderson
              Reporter:
              gpiero Gian Piero Carrubba
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: