fixes typo in ensure_namespace
bug 1035425 There was an uncheck branch in ensure_namespace that used the wrong class name. This fixes that bug and adds better tests. Change-Id: I0c22e70938305e180084de4bf9a700aebf512645
This commit is contained in:
parent
a9829daa6b
commit
d66f85ac02
@ -90,7 +90,7 @@ class IPWrapper(SubProcessBase):
|
|||||||
lo = ip.device('lo')
|
lo = ip.device('lo')
|
||||||
lo.link.set_up()
|
lo.link.set_up()
|
||||||
else:
|
else:
|
||||||
ip = IP(self.root_helper, name)
|
ip = IPWrapper(self.root_helper, name)
|
||||||
return ip
|
return ip
|
||||||
|
|
||||||
def add_device_to_namespace(self, device):
|
def add_device_to_namespace(self, device):
|
||||||
|
@ -15,9 +15,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
import unittest2 as unittest
|
||||||
|
|
||||||
from quantum.agent.linux import ip_lib
|
from quantum.agent.linux import ip_lib
|
||||||
from quantum.agent.linux import utils
|
from quantum.agent.linux import utils
|
||||||
@ -174,12 +173,22 @@ class TestIpWrapper(unittest.TestCase):
|
|||||||
|
|
||||||
def test_ensure_namespace(self):
|
def test_ensure_namespace(self):
|
||||||
with mock.patch.object(ip_lib, 'IPDevice') as ip_dev:
|
with mock.patch.object(ip_lib, 'IPDevice') as ip_dev:
|
||||||
ns = ip_lib.IPWrapper('sudo').ensure_namespace('ns')
|
ip = ip_lib.IPWrapper('sudo')
|
||||||
self.execute.assert_has_calls([mock.call('o', 'netns', ('list',),
|
with mock.patch.object(ip.netns, 'exists') as ns_exists:
|
||||||
'sudo', None)])
|
ns_exists.return_value = False
|
||||||
|
ns = ip.ensure_namespace('ns')
|
||||||
|
self.execute.assert_has_calls(
|
||||||
|
[mock.call([], 'netns', ('add', 'ns'), 'sudo', None)])
|
||||||
ip_dev.assert_has_calls([mock.call('lo', 'sudo', 'ns'),
|
ip_dev.assert_has_calls([mock.call('lo', 'sudo', 'ns'),
|
||||||
mock.call().link.set_up()])
|
mock.call().link.set_up()])
|
||||||
|
|
||||||
|
def test_ensure_namespace_existing(self):
|
||||||
|
with mock.patch.object(ip_lib, 'IpNetnsCommand') as ip_ns_cmd:
|
||||||
|
ip_ns_cmd.exists.return_value = True
|
||||||
|
ns = ip_lib.IPWrapper('sudo').ensure_namespace('ns')
|
||||||
|
self.assertFalse(self.execute.called)
|
||||||
|
self.assertEqual(ns.namespace, 'ns')
|
||||||
|
|
||||||
def test_add_device_to_namespace(self):
|
def test_add_device_to_namespace(self):
|
||||||
dev = mock.Mock()
|
dev = mock.Mock()
|
||||||
ip_lib.IPWrapper('sudo', 'ns').add_device_to_namespace(dev)
|
ip_lib.IPWrapper('sudo', 'ns').add_device_to_namespace(dev)
|
||||||
|
Loading…
Reference in New Issue
Block a user