Example #1
0
 def test_run_iproute_link_error(self):
     with mock.patch.object(pyroute2, "IPRoute") as iproute_mock:
         iproute_mock.side_effect = OSError(
             errno.EINVAL, "Test invalid argument exception")
         try:
             priv_lib._run_iproute_link(
                 "test_cmd", "eth0", None, test_param="test_value")
             self.fail("OSError exception not raised")
         except OSError as e:
             self.assertEqual(errno.EINVAL, e.errno)
Example #2
0
 def _test_run_iproute_link(self, namespace=None):
     ip_obj = "NetNS" if namespace else "IPRoute"
     with mock.patch.object(pyroute2, ip_obj) as ip_mock_cls:
         ip_mock = ip_mock_cls()
         ip_mock.__enter__().link_lookup.return_value = [2]
         priv_lib._run_iproute_link("test_cmd", "eth0", namespace,
                                    test_param="test_value")
         ip_mock.assert_has_calls([
             mock.call.__enter__().link_lookup(ifname="eth0"),
             mock.call.__exit__(None, None, None),
             mock.call.__enter__().link("test_cmd", index=2,
                                        test_param="test_value")])
Example #3
0
 def test_run_iproute_link_error(self):
     with mock.patch.object(pyroute2, "IPRoute") as iproute_mock:
         iproute_mock.side_effect = OSError(
             errno.EINVAL, "Test invalid argument exception")
         try:
             priv_lib._run_iproute_link("test_cmd",
                                        "eth0",
                                        None,
                                        test_param="test_value")
             self.fail("OSError exception not raised")
         except OSError as e:
             self.assertEqual(errno.EINVAL, e.errno)
Example #4
0
 def _test_run_iproute_link(self, namespace=None):
     ip_obj = "NetNS" if namespace else "IPRoute"
     with mock.patch.object(pyroute2, ip_obj) as ip_mock_cls:
         ip_mock = ip_mock_cls()
         ip_mock.__enter__().link_lookup.return_value = [2]
         priv_lib._run_iproute_link("test_cmd",
                                    "eth0",
                                    namespace,
                                    test_param="test_value")
         ip_mock.assert_has_calls([
             mock.call.__enter__().link_lookup(ifname="eth0"),
             mock.call.__exit__(None, None, None),
             mock.call.__enter__().link("test_cmd",
                                        index=2,
                                        test_param="test_value")
         ])