Project

General

Profile

Actions

Bug #3293

closed

It is not possible to add a block content or at a specified location of a file using 'Enforce file content' Technique

Added by Nicolas PERRON over 11 years ago. Updated almost 9 years ago.

Status:
Released
Priority:
N/A
Assignee:
Jonathan CLARKE
Category:
Techniques
Target version:
Severity:
UX impact:
User visibility:
Effort required:
Priority:
Name check:
Fix check:
Regression:

Description

We should be able to specify where to add content in a file with the 'Enforce a file content' and to add a block.

Actually, if we have to add content like in the /etc/cups/printers.conf with group of parameters into a tag, this is not possible. Trying to add a group of parameters will not be functionnal and if one is not compliant, the line of the group of parameters will be added to the end of the file.

Actions #1

Updated by Jonathan CLARKE over 11 years ago

This sounds like a reasonable request, and would make profit of one of CFEngine's more powerful features in file editing.

What are the exact parameters you need to add to the existing Technique? I assume just "Insert this text after a line matching this regex"? Or something else. Let's discuss the spec here before attempting any implementation.

Actions #2

Updated by Nicolas PERRON over 11 years ago

  • Status changed from New to Discussion

Jonathan CLARKE wrote:

This sounds like a reasonable request, and would make profit of one of CFEngine's more powerful features in file editing.

What are the exact parameters you need to add to the existing Technique? I assume just "Insert this text after a line matching this regex"? Or something else. Let's discuss the spec here before attempting any implementation.

In my opinion, it should be two parameters to be added.
  • Insert this text after a line matching this regex to be sure to add the configuration property in the right location
  • Add as one entire block ? This could be usefull if an order is expected in the add of content.
Actions #3

Updated by Jonathan CLARKE over 11 years ago

Nicolas PERRON wrote:

Jonathan CLARKE wrote:

This sounds like a reasonable request, and would make profit of one of CFEngine's more powerful features in file editing.

What are the exact parameters you need to add to the existing Technique? I assume just "Insert this text after a line matching this regex"? Or something else. Let's discuss the spec here before attempting any implementation.

In my opinion, it should be two parameters to be added.
  • Insert this text after a line matching this regex to be sure to add the configuration property in the right location

Sounds great.

  • Add as one entire block ? This could be usefull if an order is expected in the add of content.

This sounds to me like a separate feature: you seem to be implying that lines are not inserted in order currently. If so, that's a bug and should be filed in a separate ticket. Or is that not the case? If so, please clarify.

Actions #4

Updated by Nicolas PERRON over 11 years ago

Jonathan CLARKE wrote:

Nicolas PERRON wrote:

Jonathan CLARKE wrote:

This sounds like a reasonable request, and would make profit of one of CFEngine's more powerful features in file editing.

What are the exact parameters you need to add to the existing Technique? I assume just "Insert this text after a line matching this regex"? Or something else. Let's discuss the spec here before attempting any implementation.

In my opinion, it should be two parameters to be added.
  • Insert this text after a line matching this regex to be sure to add the configuration property in the right location

Sounds great.

Ok, then is this a new feature (user story to create) or this bug answer the problem ?

  • Add as one entire block ? This could be usefull if an order is expected in the add of content.

This sounds to me like a separate feature: you seem to be implying that lines are not inserted in order currently. If so, that's a bug and should be filed in a separate ticket. Or is that not the case? If so, please clarify.

I'm not sure of this but I will test it. It seems to me that if just one line of the block defined is missing, it will be added to the end of the file which will not respect the initial order.

Actions #5

Updated by Nicolas PERRON over 11 years ago

  • Assignee set to Jonathan CLARKE

Nicolas PERRON wrote:

Jonathan CLARKE wrote:

Nicolas PERRON wrote:

Jonathan CLARKE wrote:

[...]

  • Add as one entire block ? This could be usefull if an order is expected in the add of content.

This sounds to me like a separate feature: you seem to be implying that lines are not inserted in order currently. If so, that's a bug and should be filed in a separate ticket. Or is that not the case? If so, please clarify.

I'm not sure of this but I will test it. It seems to me that if just one line of the block defined is missing, it will be added to the end of the file which will not respect the initial order.

In fact, If I define A Directive that the file /tmp/bug_3293.txt should contain this:

This is the line 1
This is the line 2
This is the line 3
This is the line 4
This is the line 5
This is the line 6
This is the line 7

If the file does not exist, all would be fine.

If the file contains:

#This is the starting comment
This is the line 2
#Some comments there
This is the line 4
This is the line 5
#Other comments appears
This is the line 7
#This is the ending comment

The result will be:

#This is the starting comment
This is the line 2
#Some comments there
This is the line 4
This is the line 5
#Other comments appears
This is the line 7
#This is the ending comment
This is the line 1
This is the line 3
This is the line 6

The result is that lines has been added in order but still are not conform to the block defined in the Directive.

I suppose This is not really a bug but a new feature. What's your opinion, Jon ?

Actions #6

Updated by Matthieu CERDA over 11 years ago

  • Target version changed from 2.3.11 to 2.3.12
Actions #7

Updated by Matthieu CERDA over 11 years ago

  • Target version changed from 2.3.12 to 2.3.13
Actions #8

Updated by Nicolas PERRON over 11 years ago

  • Target version changed from 2.3.13 to 84
Actions #9

Updated by Nicolas PERRON over 11 years ago

  • Target version changed from 84 to 2.4.7
Actions #10

Updated by Nicolas PERRON over 11 years ago

  • Status changed from Discussion to 8
  • Assignee changed from Jonathan CLARKE to Nicolas PERRON
  • Target version changed from 2.4.7 to 2.6.3
Actions #11

Updated by Nicolas PERRON over 11 years ago

  • Target version changed from 2.6.3 to 2.6.4
Actions #12

Updated by Nicolas PERRON about 11 years ago

  • Status changed from 8 to Discussion
  • Assignee changed from Nicolas PERRON to Matthieu CERDA

I don't know how to deal with that issue:

  • There is a "bug" in all versions of this Technique:
    bundle edit_line set_arbitrary_file_content(content, enforce)
    {
    classes:
        "preserve_file_content" expression => strcmp("true", "$(enforce)");
    
    insert_lines:
      preserve_file_content::
        "$(content)" 
            insert_type => "preserve_block";
    
      !preserve_file_content::
        "$(content)";
    }
    

If the file has to be enforced, it is considered has preserved and then if the content is a block content, it will be preserve. If the file is not enforced, it will be not considered as preserved and then the content will be process for each line....

The use of preserve block will lead to a non convergent promise which will lead itself to a file containing at each run more lines

  • If I try to preserve the block content, like said above, the content will be added at each run. Then, a solution could be to remove each line before to add the content we want but this will lead to a non convergent promise and the reporting will always considered as "repaired" instead of "success".

With these informations, I don't know how to do the work. Any idea ?

Actions #13

Updated by Matthieu CERDA about 11 years ago

  • Assignee changed from Matthieu CERDA to Nicolas PERRON

I think for block edition, a template would be more adapted, but a template is unusable in this case. We are hitting the limits of what we can do here...

Maybe it would be a job to be done in another technique, a templating one ?

Actions #14

Updated by Nicolas PERRON about 11 years ago

  • Target version changed from 2.6.4 to 2.6.5
Actions #15

Updated by Nicolas PERRON about 11 years ago

  • Target version changed from 2.6.5 to 2.6.6
Actions #16

Updated by Nicolas PERRON about 11 years ago

  • Target version changed from 2.6.6 to 2.6.7
Actions #17

Updated by Nicolas PERRON about 11 years ago

  • Target version changed from 2.6.7 to 2.6.8
Actions #18

Updated by Nicolas PERRON about 11 years ago

  • Target version changed from 2.6.8 to 2.6.9
Actions #19

Updated by Nicolas PERRON almost 11 years ago

  • Target version changed from 2.6.9 to 2.6.10
Actions #20

Updated by Nicolas CHARLES almost 11 years ago

  • Status changed from Discussion to 8
  • Assignee changed from Nicolas PERRON to Nicolas CHARLES

i'm taking over the ticket

Actions #21

Updated by Nicolas CHARLES almost 11 years ago

Ha. Preserve block is broken in CFEngine
https://cfengine.com/dev/issues/2315

Actions #22

Updated by Nicolas CHARLES almost 11 years ago

after mch tries and tinkering, i cannot get cfengine to manage a block section, with order.
I guess the easier way would be to use a module, that would :
- check if the section is there (by header)
- if it is there, check the content (multiline regexp?)
- if it is invalid, replace it

it could look like that
http://stackoverflow.com/questions/10092328/bash-how-to-check-and-insert-a-string-within-a-block-in-a-file

Actions #23

Updated by Nicolas CHARLES almost 11 years ago

  • Category set to Techniques
  • Status changed from 8 to Pending technical review
  • Assignee changed from Nicolas CHARLES to Jonathan CLARKE
  • Target version changed from 2.6.10 to 2.4.13
  • Pull Request set to https://github.com/Normation/rudder-techniques/pull/256
Actions #24

Updated by Nicolas CHARLES almost 11 years ago

PR updated !

Actions #25

Updated by Nicolas CHARLES almost 11 years ago

  • Status changed from Pending technical review to Pending release
  • % Done changed from 0 to 100

Applied in changeset commit:6761c7297a9dc424bfea8577e5bee681d68bf3c9.

Actions #26

Updated by Nicolas CHARLES almost 11 years ago

  • Status changed from Pending release to In progress
Actions #27

Updated by Nicolas CHARLES almost 11 years ago

  • Pull Request changed from https://github.com/Normation/rudder-techniques/pull/256 to https://github.com/Normation/rudder-techniques/pull/258
Actions #28

Updated by Nicolas CHARLES almost 11 years ago

  • Status changed from In progress to Pending release

Applied in changeset commit:3b3fae6b9a7d7ce422cf156f03598e88a0259e57.

Actions #29

Updated by Vincent MEMBRÉ almost 11 years ago

  • Status changed from Pending release to Discussion

bunlde edit_line rudder_ensure_section_content has not been added in stdlib in last pull request, since this issue has not been release, I'm making another one to add it again it

Actions #30

Updated by Vincent MEMBRÉ almost 11 years ago

  • Status changed from Discussion to Pending technical review
  • Pull Request changed from https://github.com/Normation/rudder-techniques/pull/258 to https://github.com/Normation/rudder-techniques/pull/264
Actions #31

Updated by Vincent MEMBRÉ almost 11 years ago

  • Status changed from Pending technical review to Pending release

Applied in changeset commit:eaa87aa59a3d45177c1ccbab3a152d3a12eb5463.

Actions #32

Updated by Nicolas CHARLES almost 11 years ago

Applied in changeset commit:bdafec55df1a897d6b029aae5adefab3cf4ff1bc.

Actions #33

Updated by Vincent MEMBRÉ almost 11 years ago

  • Target version changed from 2.4.13 to 2.6.10

Since we will not make any more releases of 2.4 version, moving all those issues to 2.6

Actions #34

Updated by Vincent MEMBRÉ almost 11 years ago

  • Subject changed from (ex PT/ Technique) Enforce a file content: This is not possible to add a block content or at a specified location of the file. to It is not possible to add a block content or at a specified location of a file using 'Enfore file content' Technique
Actions #35

Updated by Vincent MEMBRÉ almost 11 years ago

  • Subject changed from It is not possible to add a block content or at a specified location of a file using 'Enfore file content' Technique to It is not possible to add a block content or at a specified location of a file using 'Enforce file content' Technique
Actions #36

Updated by Vincent MEMBRÉ almost 11 years ago

  • Status changed from Pending release to Released

This bug has been fixed in Rudder 2.6.10 which was released today.
Check out:

Actions #37

Updated by Benoît PECCATTE over 9 years ago

  • Project changed from 24 to Rudder
  • Category changed from Techniques to Techniques
Actions #38

Updated by Benoît PECCATTE almost 9 years ago

  • Target version changed from 2.6.10 to 2.4.12
Actions

Also available in: Atom PDF