# HG changeset patch # User Tero Marttila # Date 1424968352 -7200 # Node ID 3b45b4fd5102a7e188eb4e37f4261d1af3785734 # Parent dafac309813ea2faec6bd86a274ed0b6dd767ca3 pvl.hosts.config: revert apply_hosts_directory to treat directory contents as a flat namespace without any parent=basname(directory) magic diff -r dafac309813e -r 3b45b4fd5102 etc/hosts/test/asdf.test --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/etc/hosts/test/asdf.test Thu Feb 26 18:32:32 2015 +0200 @@ -0,0 +1,2 @@ +[quux] + ip = 192.0.2.5 diff -r dafac309813e -r 3b45b4fd5102 etc/hosts/test/test --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/etc/hosts/test/test Thu Feb 26 18:32:32 2015 +0200 @@ -0,0 +1,1 @@ +include = test.d/ diff -r dafac309813e -r 3b45b4fd5102 etc/hosts/test/test.d/bar --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/etc/hosts/test/test.d/bar Thu Feb 26 18:32:32 2015 +0200 @@ -0,0 +1,1 @@ +ip = 192.0.2.2 diff -r dafac309813e -r 3b45b4fd5102 etc/hosts/test/test.d/foo --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/etc/hosts/test/test.d/foo Thu Feb 26 18:32:32 2015 +0200 @@ -0,0 +1,2 @@ +ip = 192.0.2.1 + diff -r dafac309813e -r 3b45b4fd5102 pvl/hosts/config.py --- a/pvl/hosts/config.py Thu Feb 26 18:22:58 2015 +0200 +++ b/pvl/hosts/config.py Thu Feb 26 18:32:32 2015 +0200 @@ -308,26 +308,25 @@ for host in apply_hosts_config(options, file, **opts): yield host -def apply_hosts_directory (options, path, parent=None, **opts): +def apply_hosts_directory (options, root, **opts): """ Load Hosts from a directory, loading each file within the directory. Skips .dotfiles. """ - if parent is None: - # use directory name - parent = os.path.basename(path.rstrip('/')) - - log.info("%s: @%s", path, parent) - - for name in os.listdir(path): - file_path = os.path.join(path, name) + for name in os.listdir(root): + path = os.path.join(root, name) if name.startswith('.'): + log.debug("%s: skip dotfile: %s", root, name) continue - for host in apply_hosts_file(options, file_path, parent=parent, **opts): + if os.path.isdir(path): + log.debug("%s: skip directory: %s", root, name) + continue + + for host in apply_hosts_file(options, path, **opts): yield host def apply_hosts_files (options, files, **opts): diff -r dafac309813e -r 3b45b4fd5102 pvl/hosts/tests.py --- a/pvl/hosts/tests.py Thu Feb 26 18:22:58 2015 +0200 +++ b/pvl/hosts/tests.py Thu Feb 26 18:32:32 2015 +0200 @@ -130,39 +130,36 @@ ]) def testApplyIncludes(self): - self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/hosts/includes.test']), [ - ('foo@includes.test', dict( + self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/hosts/test/test']), [ + ('foo@test', dict( ip = ipaddr.IPAddress('192.0.2.1'), )), - ('bar@includes.test', dict( + ('bar@test', dict( ip = ipaddr.IPAddress('192.0.2.2'), )), - ('quux@includes.test', dict( - ip = ipaddr.IPAddress('192.0.2.3'), - )), ]) def testApplyDirectory(self): - self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/hosts/included.test/']), [ - ('quux@asdf.included.test', dict( + self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/hosts/test/']), [ + ('quux@asdf.test', dict( ip = ipaddr.IPAddress('192.0.2.5'), )), - ('foo@included.test', dict( + ('foo@test', dict( ip = ipaddr.IPAddress('192.0.2.1'), )), - ('bar@included.test', dict( + ('bar@test', dict( ip = ipaddr.IPAddress('192.0.2.2'), )), ]) def testApply(self): - self.assertHostsEqual(config.apply(self.options, ['etc/hosts/test']), [ - ('foo@test', dict( - ip = ipaddr.IPAddress('127.0.0.1'), + self.assertHostsEqual(config.apply(self.options, ['etc/hosts/example.com']), [ + ('foo@example.com', dict( + ip = ipaddr.IPAddress('192.0.2.1'), ethernet = {None: '00:11:22:33:44:55'}, )), - ('bar@test', dict( - ip = ipaddr.IPAddress('127.0.0.2'), + ('bar@example.com', dict( + ip = ipaddr.IPAddress('192.0.2.2'), ethernet = {None: '01:23:45:67:89:ab'}, )), ])