def test_ManagerFilePathConfiguration(self):
        mock_logger = MagicMock()
        mock_client = MagicMock()
        mock_load_and_set = MagicMock()
        mock_loader = MagicMock()
        mock_loader.load_and_set = mock_load_and_set
        mock_get_kube_config_loader_from_file = MagicMock(
            return_value=mock_loader)

        instance = ManagerFilePathConfiguration(
            mock_logger, {'manager_file_path': 'kubernetes.conf'})

        mock_isfile = MagicMock(return_value=True)

        with patch('os.path.isfile', mock_isfile):
            with patch(
                    'cloudify_kubernetes.k8s.config.'
                    'KubernetesApiConfiguration.'
                    'get_kube_config_loader_from_file',
                    mock_get_kube_config_loader_from_file):
                with patch('kubernetes.client', mock_client):
                    self.assertEqual(instance.prepare_api(), mock_client)

        mock_isfile.assert_called_with('kubernetes.conf')
        mock_load_and_set.assert_called_with()
        mock_get_kube_config_loader_from_file.assert_called_with(
            config_file='kubernetes.conf')
    def test_ManagerFilePathConfiguration_Error(self):
        mock_logger = MagicMock()

        instance = ManagerFilePathConfiguration(
            mock_logger, {'manager_file_path': 'kubernetes.conf'})

        with self.assertRaises(KuberentesApiInitializationFailedError):
            instance.prepare_api()
Пример #3
0
    def test_ManagerFilePathConfiguration_Error(self):
        ctx_mock = MagicMock()

        ctx_mock.download_resource = MagicMock(side_effect=Exception())

        instance = ManagerFilePathConfiguration(
            ctx_mock, {'manager_file_path': 'kubernetes.conf'})

        with self.assertRaises(KuberentesApiInitializationFailedError):
            instance.prepare_api()
Пример #4
0
    def test_ManagerFilePathConfiguration(self):
        ctx_mock = MagicMock()
        mock_config = MagicMock()
        mock_client = MagicMock()

        instance = ManagerFilePathConfiguration(
            ctx_mock, {'manager_file_path': 'kubernetes.conf'})

        mock_isfile = MagicMock(return_value=True)

        with patch('os.path.isfile', mock_isfile):
            with patch('kubernetes.config.load_kube_config', mock_config):
                with patch('kubernetes.client', mock_client):
                    self.assertEqual(instance.prepare_api(), mock_client)

        mock_isfile.assert_called_with('kubernetes.conf')
        mock_config.assert_called_with(config_file='kubernetes.conf')