Merge "Completes coverage of quantum.agent.netns_cleanup.py"
This commit is contained in:
commit
d2ba190173
@ -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 re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -14,6 +31,7 @@ from quantum.openstack.common import cfg
|
|||||||
from quantum.openstack.common import importutils
|
from quantum.openstack.common import importutils
|
||||||
from quantum.openstack.common import log as logging
|
from quantum.openstack.common import log as logging
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
NS_MANGLING_PATTERN = ('(%s|%s)' % (dhcp_agent.NS_PREFIX, l3_agent.NS_PREFIX) +
|
NS_MANGLING_PATTERN = ('(%s|%s)' % (dhcp_agent.NS_PREFIX, l3_agent.NS_PREFIX) +
|
||||||
attributes.UUID_PATTERN)
|
attributes.UUID_PATTERN)
|
||||||
|
@ -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 mock
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
|
|
||||||
from quantum.agent import netns_cleanup_util as util
|
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):
|
class TestNetnsCleanup(unittest.TestCase):
|
||||||
def test_setup_conf(self):
|
def test_setup_conf(self):
|
||||||
with mock.patch('quantum.common.config.setup_logging'):
|
with mock.patch('quantum.common.config.setup_logging'):
|
||||||
@ -159,15 +182,23 @@ class TestNetnsCleanup(unittest.TestCase):
|
|||||||
expected.append(mock.call().garbage_collect_namespace())
|
expected.append(mock.call().garbage_collect_namespace())
|
||||||
ip_wrap.assert_has_calls(expected)
|
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)
|
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)
|
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)
|
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):
|
def test_main(self):
|
||||||
namespaces = ['ns1', 'ns2']
|
namespaces = ['ns1', 'ns2']
|
||||||
with mock.patch('quantum.agent.linux.ip_lib.IPWrapper') as ip_wrap:
|
with mock.patch('quantum.agent.linux.ip_lib.IPWrapper') as ip_wrap:
|
||||||
|
Loading…
Reference in New Issue
Block a user