From: Zhongyue Luo Date: Thu, 29 Nov 2012 01:37:24 +0000 (+0800) Subject: Completes coverage of quantum.agent.netns_cleanup.py X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=099885fbb8d439d23774dbca1c84cecb55ceb9ec;p=openstack-build%2Fneutron-build.git Completes coverage of quantum.agent.netns_cleanup.py Added test cases Fixed typos Fixes bug #1084332 Change-Id: I86c2321dfe5f3f1ac4b8b570a6c76dbb1928bfb0 --- diff --git a/quantum/agent/netns_cleanup_util.py b/quantum/agent/netns_cleanup_util.py index 7271968b3..f3b0b6fc3 100644 --- a/quantum/agent/netns_cleanup_util.py +++ b/quantum/agent/netns_cleanup_util.py @@ -1,3 +1,20 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (c) 2012 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + import re import sys @@ -14,6 +31,7 @@ from quantum.openstack.common import cfg from quantum.openstack.common import importutils from quantum.openstack.common import log as logging + LOG = logging.getLogger(__name__) NS_MANGLING_PATTERN = ('(%s|%s)' % (dhcp_agent.NS_PREFIX, l3_agent.NS_PREFIX) + attributes.UUID_PATTERN) diff --git a/quantum/tests/unit/test_agent_netns_cleanup.py b/quantum/tests/unit/test_agent_netns_cleanup.py index 557b771b9..5cddbbd30 100644 --- a/quantum/tests/unit/test_agent_netns_cleanup.py +++ b/quantum/tests/unit/test_agent_netns_cleanup.py @@ -1,9 +1,32 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (c) 2012 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + import mock import unittest2 as unittest from quantum.agent import netns_cleanup_util as util +class TestNullDelegate(unittest.TestCase): + def test_getattribute(self): + null_delegate = util.NullDelegate() + self.assertIsNone(null_delegate.test()) + + class TestNetnsCleanup(unittest.TestCase): def test_setup_conf(self): with mock.patch('quantum.common.config.setup_logging'): @@ -159,15 +182,23 @@ class TestNetnsCleanup(unittest.TestCase): expected.append(mock.call().garbage_collect_namespace()) ip_wrap.assert_has_calls(expected) - def test_destory_namespace_empty(self): + def test_destroy_namespace_empty(self): self._test_destroy_namespace_helper(False, 0) - def test_destory_namespace_not_empty(self): + def test_destroy_namespace_not_empty(self): self._test_destroy_namespace_helper(False, 1) - def test_destory_namespace_not_empty_forced(self): + def test_destroy_namespace_not_empty_forced(self): self._test_destroy_namespace_helper(True, 2) + def test_destroy_namespace_exception(self): + ns = 'qrouter-6e322ac7-ab50-4f53-9cdc-d1d3c1164b6d' + conf = mock.Mock() + conf.root_helper = 'sudo' + with mock.patch('quantum.agent.linux.ip_lib.IPWrapper') as ip_wrap: + ip_wrap.side_effect = Exception() + util.destroy_namespace(conf, ns) + def test_main(self): namespaces = ['ns1', 'ns2'] with mock.patch('quantum.agent.linux.ip_lib.IPWrapper') as ip_wrap: