def test_parse_content_with_commented_lines(self):
     hostfile_content = '''
     # 7.7.7.2 first.host.com
     7.7.7.3 second.host.com
     '''
     self.assertDictEqual(hostsfile_source.parse_content(hostfile_content),
                          {'second.host.com': '7.7.7.3'})
 def test_parse_content_with_hostname_alias(self):
     hostfile_content = '7.7.7.2 my.host.com www.my.host.com'
     self.assertDictEqual(hostsfile_source.parse_content(hostfile_content),
                          {
                              'my.host.com': '7.7.7.2',
                              'www.my.host.com': '7.7.7.2'
                          })
def known_hosts(vagrant_root, name=None):
    vagrant_root = lookup_vagrant_root(vagrant_root)
    vagrant = Vagrant(vagrant_root)

    machines = list_machines(vagrant_root)
    name = name if name in machines else machines[0]

    return parse_content(vagrant._run_vagrant_command(('ssh', name, '-c', 'cat /etc/hosts')))
 def test_parse_content_with_inline_comment(self):
     hostfile_content = '''
     7.7.7.2 first.host.com # www.first.host.com
     7.7.7.3 second.host.com www.second.host.com
     '''
     self.assertDictEqual(
         hostsfile_source.parse_content(hostfile_content),
         {'first.host.com': '7.7.7.2', 'second.host.com': '7.7.7.3', 'www.second.host.com': '7.7.7.3'})
 def test_parse_content_with_commented_lines(self):
     hostfile_content = '''
     # 7.7.7.2 first.host.com
     7.7.7.3 second.host.com
     '''
     self.assertDictEqual(
         hostsfile_source.parse_content(hostfile_content),
         {'second.host.com': '7.7.7.3'})
 def test_parse_content_with_multiple_entries(self):
     hostfile_content = '''
     7.7.7.2 first.host.com
     7.7.7.3 second.host.com
     '''
     self.assertDictEqual(
         hostsfile_source.parse_content(hostfile_content),
         {'first.host.com': '7.7.7.2',
          'second.host.com': '7.7.7.3'})
def known_hosts(vagrant_root, name=None):
    vagrant_root = lookup_vagrant_root(vagrant_root)
    vagrant = Vagrant(vagrant_root)

    machines = list_machines(vagrant_root)
    name = name if name in machines else machines[0]

    return parse_content(
        vagrant._run_vagrant_command(('ssh', name, '-c', 'cat /etc/hosts')))
 def test_parse_content_ignore_localhost_addresses(self):
     hostfile_content = '''
     7.7.7.2 first.host.com
     7.7.7.3 second.host.com
     127.0.0.1 me.host.com
     127.0.1.1 here.host.com
     '''
     self.assertDictEqual(
         hostsfile_source.parse_content(hostfile_content),
         {'first.host.com': '7.7.7.2', 'second.host.com': '7.7.7.3'})
 def test_parse_content_with_multiple_entries(self):
     hostfile_content = '''
     7.7.7.2 first.host.com
     7.7.7.3 second.host.com
     '''
     self.assertDictEqual(hostsfile_source.parse_content(hostfile_content),
                          {
                              'first.host.com': '7.7.7.2',
                              'second.host.com': '7.7.7.3'
                          })
 def test_parse_content_with_inline_comment(self):
     hostfile_content = '''
     7.7.7.2 first.host.com # www.first.host.com
     7.7.7.3 second.host.com www.second.host.com
     '''
     self.assertDictEqual(
         hostsfile_source.parse_content(hostfile_content), {
             'first.host.com': '7.7.7.2',
             'second.host.com': '7.7.7.3',
             'www.second.host.com': '7.7.7.3'
         })
 def test_parse_content_ignore_localhost_addresses(self):
     hostfile_content = '''
     7.7.7.2 first.host.com
     7.7.7.3 second.host.com
     127.0.0.1 me.host.com
     127.0.1.1 here.host.com
     '''
     self.assertDictEqual(hostsfile_source.parse_content(hostfile_content),
                          {
                              'first.host.com': '7.7.7.2',
                              'second.host.com': '7.7.7.3'
                          })
 def test_parse_content_ignore_anything_but_ipv4(self):
     hostfile_content = '''
     ::1     ip6-localhost ip6-loopback
     fe00::0 ip6-localnet
     ff00::0 ip6-mcastprefix
     ff02::1 ip6-allnodes
     ff02::2 ip6-allrouters
     7.7.7.2 first.host.com
     7.7.7.3 second.host.com
     '''
     self.assertDictEqual(
         hostsfile_source.parse_content(hostfile_content),
         {'first.host.com': '7.7.7.2', 'second.host.com': '7.7.7.3'})
 def test_parse_content_ignore_anything_but_ipv4(self):
     hostfile_content = '''
     ::1     ip6-localhost ip6-loopback
     fe00::0 ip6-localnet
     ff00::0 ip6-mcastprefix
     ff02::1 ip6-allnodes
     ff02::2 ip6-allrouters
     7.7.7.2 first.host.com
     7.7.7.3 second.host.com
     '''
     self.assertDictEqual(hostsfile_source.parse_content(hostfile_content),
                          {
                              'first.host.com': '7.7.7.2',
                              'second.host.com': '7.7.7.3'
                          })
 def test_parse_content_with_hostname_alias(self):
     hostfile_content = '7.7.7.2 my.host.com www.my.host.com'
     self.assertDictEqual(
         hostsfile_source.parse_content(hostfile_content),
         {'my.host.com': '7.7.7.2','www.my.host.com': '7.7.7.2'})
 def test_parse_content_with_hostname_and_ip_multiple_spaces_and_tab_separated(self):
     hostfile_content = '7.7.7.2  \t \t  my.host.com'
     self.assertDictEqual(
         hostsfile_source.parse_content(hostfile_content),
         {'my.host.com': '7.7.7.2'})
 def test_parse_content_with_hostname_and_ip_multiple_spaces_and_tab_separated(
         self):
     hostfile_content = '7.7.7.2  \t \t  my.host.com'
     self.assertDictEqual(hostsfile_source.parse_content(hostfile_content),
                          {'my.host.com': '7.7.7.2'})