customink-webops/hostsfile — pull request #27 by satiani (2013-08-13 16:00:06+00:00)
Title: Better /etc/hosts flattening, fixed bugs, and fixed tests

This includes several improvements and bug fixes:

1. Some host files include separate lines for the same IP with different hosts, I added functionality to flatten the host file by merging these lines into one line with a list of aliases.

2. The method "remove_existing_hostnames" makes some false assumptions, so I removed it:
* It says: "it doesn't make sense to allow multiple IPs to have the same host name or aliases". AFAIK, this is not true, since you can have the same host with multiple network interfaces (different IPs) and you can also have an IPv4 and IPv6 addresses for the same host. For example, vanilla Debian 7 installation includes these two lines in the /etc/hosts: `127.0.0.1 localhost` and `::1 localhost ip6-localhost ip6-loopback` out of the box. Currently this chef recipe causes one of these lines to be removed, breaking the loopback interface.
* It assumes that the `changed_entry` is always the first item in the `@entries` instance variable. This is only true when `add(entry)` is invoked, and is not true for `append(entry)` and `update(entry)`.

3. Previously, if an entry was added with the same host name, `append` would result in an entry that has the same host name in `hostname` and `aliases` attribute, resulting in an /etc/hosts line that has the same host twice. I fixed this behavior and updated the test to reflect this.