Ejemplo n.º 1
0
    def test_check_system_bad_state_do_not_quit(
        self,
        kernel_status,
        docker_version_status,
        m_check_etcd_version,
        m_check_docker_version,
        m_check_kernel_modules,
        m_enforce_root,
    ):
        """
        Test for check_system when one of the system checks fails

        This test does not quit if there is an error -
        Assert that the function returns False

        :param kernel_status: return_value for _check_modules
        :param docker_version_status: return_value for _check_docker_version
        """
        # Set up mock objects
        m_check_kernel_modules.return_value = kernel_status
        m_check_docker_version.return_value = docker_version_status

        # Call method under test without exiting if error detected
        test_return = check_system(quit_if_error=False)

        # Assert
        self.assertIn(False, test_return)
Ejemplo n.º 2
0
    def test_check_system_bad_state_do_not_quit(
            self, kernel_status, ip_forwarding_status, docker_version_status):
        """
        Test for check_system when one of the system checks fails

        This test does not quit if there is an error -
        Assert that the function returns False

        :param kernel_status: return_value for _check_kernel_modules
        :param ip_forwarding_status: return_value for _check_ip_forwarding
        :param docker_version_status: return_value for _check_docker_version
        """
        with patch('calico_ctl.checksystem.enforce_root', autospec=True) \
                     as m_enforce_root, \
             patch('calico_ctl.checksystem._check_kernel_modules', autospec=True) \
                     as m_check_kernel_modules, \
             patch('calico_ctl.checksystem._check_ip_forwarding', autospec=True) \
                     as m_check_ip_forwarding, \
             patch('calico_ctl.checksystem._check_docker_version', autospec=True) \
                        as m_check_docker_version:
            # Set up mock objects
            m_check_kernel_modules.return_value = kernel_status
            m_check_ip_forwarding.return_value = ip_forwarding_status
            m_check_docker_version.return_value = docker_version_status

            # Call method under test without exiting if error detected
            test_return = check_system(fix=False, quit_if_error=False)

            # Assert
            m_enforce_root.assert_called_once_with()
            self.assertFalse(test_return)
    def test_check_system(self, m_check_docker_version,
                          m_check_kernel_modules, m_enforce_root):
        """
        Test for check_system when all checks pass

        Assert that the function returns True
        """
        # Call method under test
        test_return = check_system(quit_if_error=True)

        # Assert
        m_enforce_root.assert_called_once_with()
        m_check_kernel_modules.assert_called_once_with()
        m_check_docker_version.assert_called_once_with(False)
        self.assertTrue(test_return)
    def test_check_system(self, m_check_docker_version, m_check_kernel_modules,
                          m_enforce_root):
        """
        Test for check_system when all checks pass

        Assert that the function returns True
        """
        # Call method under test
        test_return = check_system(quit_if_error=True)

        # Assert
        m_enforce_root.assert_called_once_with()
        m_check_kernel_modules.assert_called_once_with()
        m_check_docker_version.assert_called_once_with(False)
        self.assertTrue(test_return)
Ejemplo n.º 5
0
    def test_check_system_bad_state_do_not_quit(
            self, kernel_status, docker_version_status, m_check_etcd_version,
            m_check_docker_version, m_check_kernel_modules, m_enforce_root):
        """
        Test for check_system when one of the system checks fails

        This test does not quit if there is an error -
        Assert that the function returns False

        :param kernel_status: return_value for _check_modules
        :param docker_version_status: return_value for _check_docker_version
        """
        # Set up mock objects
        m_check_kernel_modules.return_value = kernel_status
        m_check_docker_version.return_value = docker_version_status

        # Call method under test without exiting if error detected
        test_return = check_system(quit_if_error=False)

        # Assert
        self.assertIn(False, test_return)