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

Should not be able to undefine hard classes

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Done
    • Priority: Higher
    • Resolution: Fixed
    • Affects Version/s: 3.17.0
    • Fix Version/s: 3.18.2, 3.15.6, 3.20.0
    • Component/s: None
    • Labels:
      None

      Description

      Today I was doing a bit of archaeology. I had memory that hard classes could not be undefined but I could not find that mentioned in the docs under the language concepts reference about classes.

      I set out to see for my self and I found indication that my memory is sound, you should not be able to undefine hard classes, but I also found that I could.

      This policy exercises extracting the tags from a known hard class, cfengine which should always be defined then attempting to undefine it if the class try_to_undefine is set.

      Pudding
      bundle agent __main__ { methods: "pudding"; }
      bundle agent pudding 
      {
        vars:
            "cfengine_class_tags" slist => getclassmetatags( "cfengine" );
      
        commands:
          try_to_undefine::
            "/bin/true"
              classes => undefine( "cfengine" );
      
        reports:
            "cfengine class tags: $(with)" with => join( ", ", cfengine_class_tags);
      }
      body classes undefine( class )
      {
            cancel_kept => { $(class) };
            cancel_repaired => { $(class) };
            cancel_notkept => { $(class) };
      }
      

      When I run it without trying to undefine cfengine it works as expected.

      # cf-agent --define dont_try_to_undefine --no-lock --log-level info --show-evaluated-classes=cfengine --file example.cf
      R: cfengine class tags: inventory, attribute_name=none, source=agent, hardclass
      Class name                                                   Meta tags                               
      cfengine                                                     inventory,attribute_name=none,source=agent,hardclass
      cfengine_3                                                   inventory,attribute_name=none,source=agent,hardclass
      cfengine_3_18                                                inventory,attribute_name=none,source=agent,hardclass
      cfengine_3_18_0a                                             inventory,attribute_name=none,source=agent,hardclass
      cfengine_3_18_0a_b248be4d0                                   inventory,attribute_name=none,source=agent,hardclass

      However, unfortunately, the pudding didn't set. When I run the policy and try to undefine cfengine I get an error telling me I can't do that, but in the end, I can see that cfengine is indeed not defined at the end of the run per the --show-evaluated-classes output.

      # cf-agent --define try_to_undefine --no-lock --log-level info --show-evaluated-classes=cfengine --file example.cf
          info: Executing 'no timeout' ... '/bin/true'
         error: You cannot cancel a reserved hard class 'cfengine' in post-condition classes
          info: Completed execution of '/bin/true'
      R: cfengine class tags: inventory, attribute_name=none, source=agent, hardclass
      Class name                                                   Meta tags                               
      cfengine_3                                                   inventory,attribute_name=none,source=agent,hardclass
      cfengine_3_18                                                inventory,attribute_name=none,source=agent,hardclass
      cfengine_3_18_0a                                             inventory,attribute_name=none,source=agent,hardclass
      cfengine_3_18_0a_b248be4d0                                   inventory,attribute_name=none,source=agent,hardclass
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              a10042 Nick Anderson
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: