From 2786a6cafa6edaf5438a3dacf54b160d8a733e7b Mon Sep 17 00:00:00 2001 From: armando-migliaccio Date: Wed, 14 Aug 2013 12:05:43 -0700 Subject: [PATCH] Mock os.makdirs to avoid directory creation in unit tests The directory 'dhcp' under neutron state path should not be created during unit tests. This patch mocks up calls to os.makedirs and ensures that methods that rely on it, like _populate_network_cache, are mocked as well. Fixes bug #1211952 Change-Id: I83998d4e631b1ebeab90b4c3c0276aa2ffe22c50 --- neutron/tests/unit/test_dhcp_agent.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/neutron/tests/unit/test_dhcp_agent.py b/neutron/tests/unit/test_dhcp_agent.py index 728f7fba5..56c20be27 100644 --- a/neutron/tests/unit/test_dhcp_agent.py +++ b/neutron/tests/unit/test_dhcp_agent.py @@ -138,9 +138,12 @@ class TestDhcpAgent(base.BaseTestCase): self.driver.existing_dhcp_networks.return_value = [] self.driver_cls = self.driver_cls_p.start() self.driver_cls.return_value = self.driver + self.mock_makedirs_p = mock.patch("os.makedirs") + self.mock_makedirs = self.mock_makedirs_p.start() def tearDown(self): self.driver_cls_p.stop() + self.mock_makedirs_p.stop() cfg.CONF.reset() super(TestDhcpAgent, self).tearDown() @@ -407,6 +410,11 @@ class TestDhcpAgentEventHandler(base.BaseTestCase): cache_cls = self.cache_p.start() self.cache = mock.Mock() cache_cls.return_value = self.cache + self.mock_makedirs_p = mock.patch("os.makedirs") + self.mock_makedirs = self.mock_makedirs_p.start() + self.mock_init_p = mock.patch('neutron.agent.dhcp_agent.' + 'DhcpAgent._populate_networks_cache') + self.mock_init = self.mock_init_p.start() with mock.patch.object(dhcp.Dnsmasq, 'check_version') as check_v: @@ -425,6 +433,8 @@ class TestDhcpAgentEventHandler(base.BaseTestCase): self.call_driver_p.stop() self.cache_p.stop() self.plugin_p.stop() + self.mock_makedirs_p.stop() + self.mock_init_p.stop() cfg.CONF.reset() super(TestDhcpAgentEventHandler, self).tearDown() -- 2.45.2