Exemple #1
0
    def test_command_deps_fail(self, m_check_output, m_check_call,
                                m_exists):
        futils.check_command_deps()
        num_check_calls = m_check_call.call_count
        self.assertEqual(num_check_calls, 2,
                         msg="Calls to check_call: %s" %
                             m_check_call.mock_calls)
        num_check_outputs = m_check_output.call_count
        self.assertEqual(num_check_outputs, 3,
                         msg="Calls to check_output: %s" %
                             m_check_output.mock_calls)
        m_check_output.return_value = "v1.2.3"

        # Run through all the check_call invocations raising an error from
        # each.
        for exc in [futils.FailedSystemCall(), OSError()]:
            for ii in xrange(num_check_calls):
                # Raise from the ii'th check_call.
                log.info("Raising %s from the %s check_call",
                         exc, ii)
                m_check_call.reset_mock()
                m_check_call.side_effect = iter(([None] * ii) + [exc])
                self.assertRaises(SystemExit, futils.check_command_deps)
                self.assertEqual(ii+1, m_check_call.call_count)

        # Run through all the check_output invocations raising an error from
        # each.
        m_check_call.side_effect = None
        for exc in [CalledProcessError(1, "foo"), OSError()]:
            for ii in xrange(num_check_outputs):
                # Raise from the ii'th check_output.
                m_check_output.reset_mock()
                m_check_output.side_effect = iter(([None] * ii) + [exc])
                self.assertRaises(SystemExit, futils.check_command_deps)
                self.assertEqual(ii+1, m_check_output.call_count)
Exemple #2
0
    def test_interface_exists(self):
        tap = "tap" + str(uuid.uuid4())[:11]

        args = []
        retcode = 1
        stdout = ""
        stderr = "Device \"%s\" does not exist." % tap
        err = futils.FailedSystemCall("From test", args, retcode, stdout,
                                      stderr)

        with mock.patch('calico.felix.futils.check_call', side_effect=err):
            self.assertFalse(devices.interface_exists(tap))
            futils.check_call.assert_called_with(["ip", "link", "list", tap])

        with mock.patch('calico.felix.futils.check_call'):
            self.assertTrue(devices.interface_exists(tap))
            futils.check_call.assert_called_with(["ip", "link", "list", tap])

        stderr = "Another error."
        err = futils.FailedSystemCall("From test", args, retcode, stdout,
                                      stderr)
        with mock.patch('calico.felix.futils.check_call', side_effect=err):
            with self.assertRaises(futils.FailedSystemCall):
                devices.interface_exists(tap)
Exemple #3
0
 def test_remove_conntrack_error(self, m_check_call):
     m_check_call.side_effect = futils.FailedSystemCall(
         "message",
         [],
         1,
         "",
         "unexpected error"
     )
     devices.remove_conntrack_flows(set(["10.0.0.1"]), 4)
     # Each call is retried 3 times.
     self.assertEqual(m_check_call.mock_calls,
         [mock.call(["conntrack", "--family", "ipv4", "--delete",
                     "--orig-src", "10.0.0.1"])] * 3 +
         [mock.call(["conntrack", "--family", "ipv4", "--delete",
                     "--orig-dst", "10.0.0.1"])] * 3 +
         [mock.call(["conntrack", "--family", "ipv4", "--delete",
                     "--reply-src", "10.0.0.1"])] * 3 +
         [mock.call(["conntrack", "--family", "ipv4", "--delete",
                     "--reply-dst", "10.0.0.1"])] * 3)
Exemple #4
0
 def test_remove_conntrack_missing(self, m_check_call):
     m_check_call.side_effect = futils.FailedSystemCall(
         "message",
         [],
         1,
         "",
         "0 flow entries"
     )
     devices.remove_conntrack_flows(set(["10.0.0.1"]), 4)
     self.assertEqual(m_check_call.mock_calls, [
         mock.call(["conntrack", "--family", "ipv4", "--delete",
                    "--orig-src", "10.0.0.1"]),
         mock.call(["conntrack", "--family", "ipv4", "--delete",
                    "--orig-dst", "10.0.0.1"]),
         mock.call(["conntrack", "--family", "ipv4", "--delete",
                    "--reply-src", "10.0.0.1"]),
         mock.call(["conntrack", "--family", "ipv4", "--delete",
                    "--reply-dst", "10.0.0.1"]),
     ])
Exemple #5
0
 def test_ipv6_missing_ip6tables(self, m_popen, m_check_call, m_exists):
     m_popen.return_value.communicate.return_value = "", ""
     m_exists.return_value = True
     m_check_call.side_effect = futils.FailedSystemCall()
     self.assertEqual(futils.ipv6_supported(), (False, mock.ANY))
Exemple #6
0
 def test_ipv6_missing_nat_table(self, m_check_call, m_exists):
     m_exists.return_value = True
     m_check_call.side_effect = iter([None, futils.FailedSystemCall()])
     self.assertEqual(futils.detect_ipv6_supported(), (False, mock.ANY))