Пример #1
0
 def test_setup_kubeconfig_data_overwrite(self):
     '''
     Test that provided `kubernetes.kubeconfig` configuration is overwritten
     by provided kubeconfig_data in the command
     :return:
     '''
     with mock_kubernetes_library() as mock_kubernetes_lib:
         with patch.dict(
                 kubernetes.__salt__,
             {'config.option': Mock(side_effect=self.settings)}):
             mock_kubernetes_lib.config.load_kube_config = Mock()
             config = kubernetes._setup_conn(
                 kubeconfig_data='MTIzNDU2Nzg5MAo=', context='newcontext')
             check_path = os.path.join('/tmp', 'salt-kubeconfig-')
             if salt.utils.platform.is_windows():
                 check_path = os.path.join(os.environ.get('TMP'),
                                           'salt-kubeconfig-')
             elif salt.utils.platform.is_darwin():
                 check_path = os.path.join(os.environ.get('TMPDIR', '/tmp'),
                                           'salt-kubeconfig-')
             self.assertTrue(config['kubeconfig'].lower().startswith(
                 check_path.lower()))
             self.assertTrue(os.path.exists(config['kubeconfig']))
             with salt.utils.files.fopen(config['kubeconfig'], 'r') as kcfg:
                 self.assertEqual('1234567890\n', kcfg.read())
             kubernetes._cleanup(**config)
Пример #2
0
 def test_setup_kubeconfig_file(self):
     '''
     Test that the `kubernetes.kubeconfig` configuration isn't overwritten
     :return:
     '''
     with mock_kubernetes_library() as mock_kubernetes_lib:
         with patch.dict(
                 kubernetes.__salt__,
             {'config.option': Mock(side_effect=self.settings)}):
             mock_kubernetes_lib.config.load_kube_config = Mock()
             config = kubernetes._setup_conn()
             self.assertEqual(
                 self.settings('kubernetes.kubeconfig'),
                 config['kubeconfig'],
             )
Пример #3
0
    def test_setup_client_key_file(self):
        '''
        Test that the `kubernetes.client-key-file` configuration isn't overwritten
        :return:
        '''
        def settings(name, value=None):
            data = {
                'kubernetes.client-key-file':
                '/home/testuser/.minikube/client.key',
            }
            return data.get(name, value)

        with patch.dict(kubernetes.__salt__,
                        {'config.option': Mock(side_effect=settings)}):
            config = kubernetes._setup_conn()
            self.assertEqual(
                settings('kubernetes.client-key-file'),
                config['key_file'],
            )
Пример #4
0
 def test_setup_kubeconfig_data_overwrite(self):
     '''
     Test that provided `kubernetes.kubeconfig` configuration is overwritten
     by provided kubeconfig_data in the command
     :return:
     '''
     with mock_kubernetes_library() as mock_kubernetes_lib:
         with patch.dict(
                 kubernetes.__salt__,
             {'config.option': Mock(side_effect=self.settings)}):
             mock_kubernetes_lib.config.load_kube_config = Mock()
             config = kubernetes._setup_conn(
                 kubeconfig_data='MTIzNDU2Nzg5MAo=', context='newcontext')
             self.assertTrue(
                 config['kubeconfig'].startswith('/tmp/salt-kubeconfig-'))
             self.assertTrue(os.path.exists(config['kubeconfig']))
             with salt.utils.files.fopen(config['kubeconfig'], 'r') as kcfg:
                 self.assertEqual('1234567890\n', kcfg.read())
             kubernetes._cleanup(**config)