Ejemplo n.º 1
0
    def test_get_one_resource_quota(self):
        name = self.name
        namespace = self.name
        create_namespace = Popen(["kubectl", "create", "namespace", namespace], stdout=PIPE)
        request = """
apiVersion: v1
kind: ResourceQuota
metadata:
  name: {0}
spec:
  hard:
    cpu: "20"
    memory: 1Gi
    persistentvolumeclaims: "10"
    pods: "10"
    replicationcontrollers: "20"
    resourcequotas: "1"
    secrets: "10"
    services: "5"
""".format(name)
        filename = "/tmp/{0}.yaml".format(name)
        with salt.utils.files.fopen(filename, 'w') as f:
            f.write(request)

        create = Popen(["kubectl", "--namespace={0}".format(namespace), "create", "-f", filename], stdout=PIPE)
        # wee need to give kubernetes time save data in etcd
        time.sleep(0.2)
        res = k8s.get_resource_quotas(namespace, name, apiserver_url="http://127.0.0.1:8080")
        a = res.get("metadata", {}).get("name", "a")
        proc = Popen(["kubectl", "--namespace={0}".format(namespace), "get", "quota", name, "-o", "json"], stdout=PIPE)
        kubectl_out = salt.utils.json.loads(proc.communicate()[0])
        b = kubectl_out.get("metadata", {}).get("name", "b")
        self.assertEqual(a, b)
Ejemplo n.º 2
0
    def test_get_one_resource_quota(self):
        name = self.name
        namespace = self.name
        create_namespace = Popen(["kubectl", "create", "namespace", namespace], stdout=PIPE)
        request = """
apiVersion: v1
kind: ResourceQuota
metadata:
  name: {0}
spec:
  hard:
    cpu: "20"
    memory: 1Gi
    persistentvolumeclaims: "10"
    pods: "10"
    replicationcontrollers: "20"
    resourcequotas: "1"
    secrets: "10"
    services: "5"
""".format(name)
        filename = "/tmp/{0}.yaml".format(name)
        with open(filename, 'w') as f:
            f.write(request)

        create = Popen(["kubectl", "--namespace={0}".format(namespace), "create", "-f", filename], stdout=PIPE)
        # wee need to give kubernetes time save data in etcd
        time.sleep(0.2)
        res = k8s.get_resource_quotas(namespace, name, apiserver_url="http://127.0.0.1:8080")
        a = res.get("metadata", {}).get("name", "a")
        proc = Popen(["kubectl", "--namespace={0}".format(namespace), "get", "quota", name, "-o", "json"], stdout=PIPE)
        kubectl_out = json.loads(proc.communicate()[0])
        b = kubectl_out.get("metadata", {}).get("name", "b")
        self.assertEqual(a, b)