bug-cfengine
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bugs and features


From: Frank Ranner
Subject: Re: Bugs and features
Date: Mon, 24 Sep 2001 23:05:25 +1000

Ronan KERYELL wrote:
> 
> >>>>> On Sat, 22 Sep 2001 20:53:36 +1000, Frank Ranner <address@hidden> said:
> 
>     Frank>      So, what is the enhancement? I would like a cross between the
>     Frank> copy action and the copy/warn action. Essentially a compare
>     Frank> between source and destination, with the ability to define a
>     Frank> class if the compare fails. The compare would be any of the
>     Frank> current modes, ie binary, checksum or date/age.
> 
> I asked for that many years ago...
> 
> The action syntax is not enough orthogonal.  It would simplify a lot
> cfengine scripts if it was possible to define classes if a file does not
> exist, etc. instead of relying on some external /bin/test processes to
> test for that...
> --
>     Ronan KERYELL              |\/
>     Labo Informatique Télécom  |/)  Tel:    (+33|0) 2.29.00.14.15
>     ENST Bretagne, BP832       K    Fax:    (+33|0) 2.29.00.12.82
>     29285 BREST CEDEX          |\   E-mail: address@hidden
>     FRANCE                     | \  http://www-info.enst-bretagne.fr/~keryell

It turned out to be quite straightforward. I have added an attachment
that is a patch against 2.0.a13 which 
implements the copy/compare action. I will submit it to the cfengine
guys when I've done some more testing. I 
also want to backport the patch to 1.6.x which is what I'm currently
using.

My test script was:

control:
actionsequence = ( copy )

copy:
   /tmp/a/version.dist 
        dest=/tmp/b/version
        action=compare
        define=timetoupdate
        type=binary

timetoupdate::
   /tmp/a
        dest=/tmp/b r=20

   /tmp/b/version.dist
        dest=/tmp/b/version
   
The compare uses the same semantics as copy. If type=binary or sum it
compares the contents against the master, 
otherwise it compares times. If the destination is missing, or
mis-compares the define triggers. I have not done 
a lot of testing, so I don't know if recursive directory compares work,
what happens if purge|ignore|include|exclude 
is set, etc. In most cases, you would use compare on a single trigger
file.

Regard, Frank Ranner
diff -r -u cfengine-2.0.a13/src/image.c cfengine-2.0.a13-patched/src/image.c
--- cfengine-2.0.a13/src/image.c        Mon Aug 13 18:29:58 2001
+++ cfengine-2.0.a13-patched/src/image.c        Sun Sep 23 17:36:38 2001
@@ -726,6 +726,16 @@
       return;
       }
 
+   if (strcmp(ip->action,"compare") == 0)
+      {
+      snprintf(OUTPUT,bufsize*2,"Compare target %s is 
non-existent\n",destfile);
+      CfLog(cfverbose,OUTPUT,"");
+      snprintf(OUTPUT,bufsize*2,"(should be copy of %s)\n",sourcefile);
+      CfLog(cfverbose,OUTPUT,"");
+      AddMultipleClasses(ip->defines);
+      return;
+      }
+
    if (S_ISREG(srcmode))
       {
       snprintf(OUTPUT,bufsize*2,"%s wasn't at destination (copying)",destfile);
@@ -859,6 +869,14 @@
                      CfLog(cferror,OUTPUT,"");
                       return;
                       }
+
+                   if (ok_to_copy && strcmp(ip->action,"compare") == 0)
+                      { 
+                      snprintf(OUTPUT,bufsize*2,"Image file %s has a wrong MD5 
checksum (should be copy of %s)\n",destfile,sourcefile);
+                     CfLog(cfverbose,OUTPUT,""); 
+                     AddMultipleClasses(ip->defines);
+                      return;
+                      }
                   break;
 
         case 'b': if (S_ISREG(deststatbuf.st_mode) && S_ISREG(srcmode))
@@ -879,6 +897,14 @@
                      CfLog(cferror,OUTPUT,"");
                       return;
                       }
+
+                   if (ok_to_copy && strcmp(ip->action,"compare") == 0)
+                      { 
+                      snprintf(OUTPUT,bufsize*2,"Image file %s has a wrong 
binary checksum (should be copy of %s)\n",destfile,sourcefile);
+                     CfLog(cfverbose,OUTPUT,""); 
+                     AddMultipleClasses(ip->defines);
+                      return;
+                      }
                   break;
 
         case 'm': ok_to_copy = (deststatbuf.st_mtime < sourcestatbuf.st_mtime);
@@ -889,6 +915,14 @@
                       CfLog(cferror,OUTPUT,"");
                       return;
                       }
+
+                   if (ok_to_copy && strcmp(ip->action,"compare") == 0)
+                      { 
+                      snprintf(OUTPUT,bufsize*2,"Image file %s out of date 
(should be copy of %s)\n",destfile,sourcefile);
+                     CfLog(cfverbose,OUTPUT,""); 
+                     AddMultipleClasses(ip->defines);
+                      return;
+                      }
                   break;
                   
          default:  ok_to_copy = (deststatbuf.st_ctime < 
sourcestatbuf.st_ctime)||(deststatbuf.st_mtime < sourcestatbuf.st_mtime);
@@ -897,6 +931,14 @@
                       { 
                       snprintf(OUTPUT,bufsize*2,"Image file %s out of date 
(should be copy of %s)\n",destfile,sourcefile);
                       CfLog(cferror,OUTPUT,"");
+                      return;
+                      }
+            
+                   if (ok_to_copy && strcmp(ip->action,"compare") == 0)
+                      { 
+                      snprintf(OUTPUT,bufsize*2,"Image file %s out of date 
(should be copy of %s)\n",destfile,sourcefile);
+                      CfLog(cfverbose,OUTPUT,"");
+                     AddMultipleClasses(ip->defines);
                       return;
                       }
                   break;
diff -r -u cfengine-2.0.a13/src/install.c cfengine-2.0.a13-patched/src/install.c
--- cfengine-2.0.a13/src/install.c      Mon Aug 27 17:49:16 2001
+++ cfengine-2.0.a13-patched/src/install.c      Sun Sep 23 17:14:08 2001
@@ -3893,7 +3893,7 @@
    strcat(action,"fix");
    }
 
-if (!(strcmp(action,"silent") == 0 || strcmp(action,"warn") == 0 || 
strcmp(action,"fix") == 0))
+if (!(strcmp(action,"silent") == 0 || strcmp(action,"warn") == 0 || 
strcmp(action,"compare") == 0 || strcmp(action,"fix") == 0))
    {
    sprintf(VBUFF,"Illegal action in image/copy item: %s",action);
    yyerror(VBUFF);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]