Skip to content

use puts instead of write to output the YAML.trim_lines array #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

scoates
Copy link

@scoates scoates commented Oct 31, 2014

.write attempts to output it as a string representation of an array
whereas .puts just concatenates the array elements together

the latter is what we need, as each element of the array is a line of YAML

(trim_lines outputs an array)

The setup:

sarcasm:~/tmp$ zonify r53 testzone.example > testzone.example.yaml
sarcasm:~/tmp$ cat testzone.example.yaml
suffix: .testzone.example.
records:
  testzone.example.:
    NS:
      :ttl: '172800'
      :value:
      - ns-462.awsdns-57.com.
      - ns-1387.awsdns-45.org.
      - ns-536.awsdns-03.net.
      - ns-1779.awsdns-30.co.uk.
    SOA:
      :ttl: '900'
      :value:
      - ns-462.awsdns-57.com. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400
sarcasm:~/tmp$ cat testzone.changed.yaml
suffix: .testzone.example.
records:
  testzone.example.:
    NS:
      :ttl: '172800'
      :value:
      - ns-462.awsdns-57.com.
      - ns-1387.awsdns-45.org.
      - ns-536.awsdns-03.net.
      - ns-1779.awsdns-30.co.uk.
    SOA:
      :ttl: '900'
      :value:
      - ns-462.awsdns-57.com. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400
    A:
      :ttl: '300'
      :value:
      - 127.0.0.1

Without this patch, the output of zonify diff is:

sarcasm:~/tmp$ zonify diff testzone.changed.yaml testzone.example.yaml 2>/dev/null
["- :ttl: '300'\n", "  :value:\n", "  - 127.0.0.1\n", "  :name: testzone.example.\n", "  :type: A\n", "  :action: DELETE\n"]

This is not valid YAML, and causes trouble when piped into zonify apply:

sarcasm:~/tmp$ zonify diff testzone.changed.yaml testzone.example.yaml | zonify apply
There are 1 changes.
testzone.example. A  --->  delete
/Users/sean/.gem/ruby/1.9.1/gems/zonify-0.4.3/bin/zonify:75:in `[]': can't convert Symbol into Integer (TypeError)
    from /Users/sean/.gem/ruby/1.9.1/gems/zonify-0.4.3/bin/zonify:75:in `block in display'
    from /Users/sean/.gem/ruby/1.9.1/gems/zonify-0.4.3/bin/zonify:74:in `each'
    from /Users/sean/.gem/ruby/1.9.1/gems/zonify-0.4.3/bin/zonify:74:in `inject'
    from /Users/sean/.gem/ruby/1.9.1/gems/zonify-0.4.3/bin/zonify:74:in `display'
    from /Users/sean/.gem/ruby/1.9.1/gems/zonify-0.4.3/bin/zonify:226:in `main'
    from /Users/sean/.gem/ruby/1.9.1/gems/zonify-0.4.3/bin/zonify:253:in `<top (required)>'
    from /Users/sean/.gem/ruby/1.9.1/bin/zonify:23:in `load'
    from /Users/sean/.gem/ruby/1.9.1/bin/zonify:23:in `<main>'

With this patch, the output of zonify diff is well-formed YAML:

sarcasm:~/tmp$ zonify diff testzone.changed.yaml testzone.example.yaml 2>/dev/null
- :ttl: '300'
  :value:
  - 127.0.0.1
  :name: testzone.example.
  :type: A
  :action: DELETE

This, then, allows the normal zonify diff … | zonify apply workflow:

sarcasm:~/tmp$ zonify diff testzone.example.yaml testzone.changed.yaml | zonify apply
There are 1 changes.
testzone.example. A  --->  create
There are 1 changes.
testzone.example. A  --->  create

Note: I've also applied the same change to ec2/r53; it may additionally be required in eips. I don't use either of these, though, so I can't effectively test.

Also of note: this worked just fine for me before an OS reinstall. I tried tracking down a change in the way STDOUT.write works, but didn't have much luck. My guess is that something changed, somewhere in the YAML parser, in the past couple years.

Occurs on Ruby 2.0 and 1.9.1.

.write attempts to output it as a string representation of an array
whereas .puts just concatenates the array elements together

the latter is what we need, as each element of the array is a line of
YAML
@scoates
Copy link
Author

scoates commented Oct 31, 2014

I see now that this is a duplicate of #18
Leaving it open so it's noticed, though. Please feel free to close without merging if #18 is merged.

@solidsnack
Copy link
Collaborator

Merged @boivie's fix: solidsnack@4bbd696

@scoates
Copy link
Author

scoates commented Oct 31, 2014

Great. Thanks.
Any idea when we'll see this gem packaged and available?

@solidsnack
Copy link
Collaborator

@solidsnack solidsnack closed this Oct 31, 2014
@scoates
Copy link
Author

scoates commented Oct 31, 2014

Thanks!

@scoates scoates deleted the fix-array-concat-as-yaml branch October 31, 2014 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants