From 0b3e21f3bc90718ff7a18401df0d8625ff9058e1 Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Sat, 12 Aug 2017 14:34:28 -0400 Subject: [PATCH] Add --skip-dns option In the case of openstack-infra, we do not want glean to setup dns, ever. This is because we run local a unbound service on our nodes. So, even if we get the data from config-drive, we want the ability to ignore it. Change-Id: I08c9bb734c8a35cffa9a6cb864bbb3431df138ef Signed-off-by: Paul Belanger --- glean/cmd.py | 7 ++++++- glean/tests/test_glean.py | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/glean/cmd.py b/glean/cmd.py index a22cb76..f7ae065 100644 --- a/glean/cmd.py +++ b/glean/cmd.py @@ -995,7 +995,9 @@ def write_network_info_from_config_drive(args): network_info = get_network_info(args) - dns = write_dns_info(get_dns_from_config_drive(network_info)) + dns = {} + if not args.skip_dns: + dns = write_dns_info(get_dns_from_config_drive(network_info)) interfaces = get_config_drive_interfaces(network_info) sys_interfaces = get_sys_interfaces(args.interface, args) @@ -1139,6 +1141,9 @@ def main(): parser.add_argument( '--skip-network', dest='skip', action='store_true', help="Do not write network info") + parser.add_argument( + '--skip-dns', dest='skip_dns', action='store_true', + help='Do not write dns info') parser.add_argument( '--debug', dest='debug', action='store_true', help="Enable debugging output") diff --git a/glean/tests/test_glean.py b/glean/tests/test_glean.py index 8ba0ee8..6f2d959 100644 --- a/glean/tests/test_glean.py +++ b/glean/tests/test_glean.py @@ -158,13 +158,15 @@ class TestGlean(base.BaseTestCase): mock_os_unlink, mock_check_output, mock_call, - mock_platform_dist): + mock_platform_dist, + skip_dns=False): """Main test function :param distro: distro to return from "platform.dist" :param provider: we will look in fixtures/provider for mocked out files :param interface: --interface argument; None for no argument + :param skip_dns: --skip-dns argument; False for no argument """ mock_platform_dist.return_value = (distro, '', '') @@ -184,6 +186,8 @@ class TestGlean(base.BaseTestCase): if interface: sys.argv.append('--interface=%s' % interface) + if skip_dns: + sys.argv.append('--skip-dns') cmd.main() @@ -210,6 +214,10 @@ class TestGlean(base.BaseTestCase): if interface and interface not in dest: continue self.assertNotIn("eth2", dest) + # Skip check + if skip_dns and '/etc/resolv.conf' in dest: + self.assertNotIn(dest, self.file_handle_mocks) + continue self.assertIn(dest, self.file_handle_mocks) write_handle = self.file_handle_mocks[dest].write write_handle.assert_called_once_with(content) @@ -253,3 +261,8 @@ class TestGlean(base.BaseTestCase): def test_glean_systemd(self): with mock.patch('glean.systemlock.Lock'): self._assert_distro_provider(self.distro, self.style, 'eth0') + + def test_glean_skip_dns(self): + with mock.patch('glean.systemlock.Lock'): + self._assert_distro_provider( + self.distro, self.style, None, skip_dns=True)