Пример #1
0
 def test_create_secret(self):
     name = self.name
     names = []
     expected_data = {}
     for i in range(2):
         names.append("/tmp/{}-{}".format(name, i))
         with salt.utils.files.fopen("/tmp/{}-{}".format(name, i),
                                     "w") as f:
             expected_data["{}-{}".format(name, i)] = base64.b64encode(
                 "{}{}".format(name, i))
             f.write(salt.utils.stringutils.to_str("{}{}".format(name, i)))
     res = k8s.create_secret("default",
                             name,
                             names,
                             apiserver_url="http://127.0.0.1:8080")
     proc = Popen(
         [
             "kubectl", "--namespace=default", "get", "secrets", name, "-o",
             "json"
         ],
         stdout=PIPE,
     )
     kubectl_out = salt.utils.json.loads(proc.communicate()[0])
     # if creation is failed, kubernetes return non json error message
     b = kubectl_out.get("data", {})
     self.assertTrue(isinstance(kubectl_out, dict))
     self.assertEqual(expected_data, b)
Пример #2
0
 def test_create_secret(self):
     name = self.name
     names = []
     expected_data = {}
     for i in range(2):
         names.append("/tmp/{0}-{1}".format(name, i))
         with open("/tmp/{0}-{1}".format(name, i), 'w') as f:
             expected_data["{0}-{1}".format(name, i)] = base64.b64encode("{0}{1}".format(name, i))
             f.write("{0}{1}".format(name, i))
     res = k8s.create_secret("default", name, names, apiserver_url="http://127.0.0.1:8080")
     proc = Popen(["kubectl", "--namespace=default", "get", "secrets", name, "-o", "json"], stdout=PIPE)
     kubectl_out = json.loads(proc.communicate()[0])
     # if creation is failed, kubernetes return non json error message
     b = kubectl_out.get("data", {})
     self.assertTrue(isinstance(kubectl_out, dict))
     self.assertEqual(expected_data, b)