Example #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)
Example #2
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)