|
| 1 | +############################################################ |
| 2 | +# CFE-2216: Files converted to directories should be changed |
| 3 | +# back on recursive copy |
| 4 | +############################################################ |
| 5 | + |
| 6 | +body common control |
| 7 | +{ |
| 8 | + inputs => { "../default.cf.sub" }; |
| 9 | + bundlesequence => { default("$(this.promise_filename)") }; |
| 10 | + version => "1.0"; |
| 11 | +} |
| 12 | + |
| 13 | +############################################################ |
| 14 | + |
| 15 | +bundle agent init |
| 16 | +{ |
| 17 | + files: |
| 18 | + "$(G.testdir)/src/." |
| 19 | + create => "true"; |
| 20 | + "$(G.testdir)/src/foo" |
| 21 | + content => "Hello CFEngine!"; |
| 22 | + "$(G.testdir)/src/bar/." |
| 23 | + create => "true"; |
| 24 | + |
| 25 | + # The .sub file needs to know the value of $(G.testdir). We can use a |
| 26 | + # template in order to hardcode it in before execution. |
| 27 | + "$(this.promise_filename).sub" |
| 28 | + create => "true", |
| 29 | + edit_template => "$(this.promise_filename).template", |
| 30 | + template_method => "mustache", |
| 31 | + template_data => parsejson('{ "testdir": "$(G.testdir)" }'); |
| 32 | +} |
| 33 | + |
| 34 | +############################################################ |
| 35 | + |
| 36 | +bundle agent test |
| 37 | +{ |
| 38 | + meta: |
| 39 | + "description" -> { "CFE-2216" } |
| 40 | + string => "Files converted to directories should be changed back on recursive copy"; |
| 41 | + |
| 42 | + # This bug is not yet fixed, so we need to soft fail it |
| 43 | + "test_soft_fail" |
| 44 | + string => "any", |
| 45 | + meta => { "CFE-2216" }; |
| 46 | + |
| 47 | + commands: |
| 48 | + # Sync files between source and destination dir |
| 49 | + "$(sys.cf_agent) -Kf $(this.promise_filename).sub"; |
| 50 | + |
| 51 | + # Change foo from a file to a directory |
| 52 | + "rm $(G.testdir)/dst/foo && mkdir $(G.testdir)/dst/foo" |
| 53 | + contain => dcs_useshell; |
| 54 | + |
| 55 | + # Change bar from a directory to a file |
| 56 | + "rmdir $(G.testdir)/dst/bar && touch $(G.testdir)/dst/bar" |
| 57 | + contain => dcs_useshell; |
| 58 | + |
| 59 | + # Sync the files again. We append -- at the end to make sure the promise |
| 60 | + # hash is different |
| 61 | + "$(sys.cf_agent) -Kf $(this.promise_filename).sub --"; |
| 62 | +} |
| 63 | + |
| 64 | +############################################################ |
| 65 | + |
| 66 | +bundle agent check |
| 67 | +{ |
| 68 | + classes: |
| 69 | + # Check that foo is converted back to a file and that bar is converted |
| 70 | + # back to a directory |
| 71 | + "ok" |
| 72 | + expression => and( |
| 73 | + not(isdir("$(G.testdir)/dst/foo")), |
| 74 | + isdir("$(G.testdir)/dst/bar") |
| 75 | + ); |
| 76 | + |
| 77 | + methods: |
| 78 | + "" |
| 79 | + usebundle => dcs_passif("ok", "$(this.promise_filename)"), |
| 80 | + inherit => "true"; |
| 81 | +} |
| 82 | + |
| 83 | +############################################################ |
| 84 | + |
| 85 | +bundle agent clean |
| 86 | +{ |
| 87 | + # Clean up the files generated from the template |
| 88 | + files: |
| 89 | + "$(this.promise_filename).sub" |
| 90 | + delete => tidy; |
| 91 | + "$(this.promise_filename).sub.cf-before-edit" |
| 92 | + delete => tidy; |
| 93 | +} |
0 commit comments