Merge "Completes coverage of quantum.agent.netns_cleanup.py"

This commit is contained in:
Jenkins 2012-11-29 08:25:58 +00:00 committed by Gerrit Code Review
commit d2ba190173
2 changed files with 52 additions and 3 deletions

View File

@ -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)

View File

@ -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: