Beispiel #1
0
 def test_create_limit_range(self):
     name = self.name
     limits = [{
         "type": "Container",
         "defaultRequest": {
             "cpu": "100m"
         }
     }]
     res = k8s.create_limit_range("default", limits, name=name, apiserver_url="http://127.0.0.1:8080")
     proc = Popen(["kubectl", "--namespace=default", "get", "limits", name, "-o", "json"], stdout=PIPE)
     kubectl_out = json.loads(proc.communicate()[0])
     self.assertTrue(isinstance(kubectl_out, dict))
Beispiel #2
0
 def test_create_limit_range(self):
     name = self.name
     limits = {"Container": {"defaultRequest": {"cpu": "100m"}}}
     res = k8s.create_limit_range(
         "default", limits, name=name, apiserver_url="http://127.0.0.1:8080"
     )
     proc = Popen(
         ["kubectl", "--namespace=default", "get", "limits", name, "-o", "json"],
         stdout=PIPE,
     )
     kubectl_out = salt.utils.json.loads(proc.communicate()[0])
     self.assertTrue(isinstance(kubectl_out, dict))
Beispiel #3
0
    def test_update_limit_range(self):
        name = self.name
        request = """
apiVersion: v1
kind: LimitRange
metadata:
  name: {}
spec:
  limits:
  - default:
      cpu: 200m
      memory: 512Mi
    defaultRequest:
      cpu: 100m
      memory: 256Mi
    type: Container
""".format(name)
        limits = {"Container": {"defaultRequest": {"cpu": "100m"}}}
        filename = "/tmp/{}.yaml".format(name)
        with salt.utils.files.fopen(filename, "w") as f:
            f.write(salt.utils.stringutils.to_str(request))

        create = Popen(
            ["kubectl", "--namespace=default", "create", "-f", filename],
            stdout=PIPE)
        # wee need to give kubernetes time save data in etcd
        time.sleep(0.1)
        res = k8s.create_limit_range(
            "default",
            limits,
            name=name,
            apiserver_url="http://127.0.0.1:8080",
            update=True,
        )
        proc = Popen(
            [
                "kubectl", "--namespace=default", "get", "limits", name, "-o",
                "json"
            ],
            stdout=PIPE,
        )
        kubectl_out = salt.utils.json.loads(proc.communicate()[0])
        limit = (kubectl_out.get("spec").get("limits")[0].get(
            "defaultRequest").get("cpu"))
        self.assertEqual("100m", limit)
Beispiel #4
0
    def test_update_limit_range(self):
        name = self.name
        request = """
apiVersion: v1
kind: LimitRange
metadata:
  name: {0}
spec:
  limits:
  - default:
      cpu: 200m
      memory: 512Mi
    defaultRequest:
      cpu: 100m
      memory: 256Mi
    type: Container
""".format(name)
        limits = {
            "Container": {
                "defaultRequest": {
                    "cpu": "100m"
                }
            }
        }
        filename = "/tmp/{0}.yaml".format(name)
        with open(filename, 'w') as f:
            f.write(request)

        create = Popen(["kubectl", "--namespace=default", "create", "-f", filename], stdout=PIPE)
        # wee need to give kubernetes time save data in etcd
        time.sleep(0.1)
        res = k8s.create_limit_range("default", limits, name=name, apiserver_url="http://127.0.0.1:8080", update=True)
        proc = Popen(["kubectl", "--namespace=default", "get", "limits", name, "-o", "json"], stdout=PIPE)
        kubectl_out = json.loads(proc.communicate()[0])
        limit = kubectl_out.get("spec").get("limits")[0].get("defaultRequest").get("cpu")
        self.assertEqual("100m", limit)