コード例 #1
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_create_nohash(ns_resource, subcall_cmd, monkeypatch):
    def get(*args):
        return None

    monkeypatch.setattr("kpm.kubernetes.Kubernetes.get", get)
    k = Kubernetes(body=ns_resource['body'])
    assert k.create() == "created"
コード例 #2
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_kind(svc_resource, rc_resource, ns_resource):
    ks = Kubernetes(body=svc_resource['body'])
    kr = Kubernetes(body=rc_resource['body'])
    kn = Kubernetes(body=ns_resource['body'])
    assert kr.kind == "replicationcontroller"
    assert kn.kind == "namespace"
    assert ks.kind == "service"
コード例 #3
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_create_ok_nohash(ns_resource, subcall_cmd, monkeypatch):
    def get(*args):
        r = json.loads(ns_resource['body'])
        return r

    monkeypatch.setattr("kpm.kubernetes.Kubernetes.get", get)
    k = Kubernetes(body=ns_resource['body'])
    assert k.create() == "ok"
コード例 #4
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_get_proxy_404(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1], svc_resource['name'])
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, text=response, status_code=404)
        assert k.get() is None
コード例 #5
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_create_force_protected(ns_resource, subcall_cmd, monkeypatch):
    def get(*args):
        svc2 = json.loads(ns_resource['body'])
        return svc2

    monkeypatch.setattr("kpm.kubernetes.Kubernetes.get", get)
    k = Kubernetes(body=ns_resource['body'])
    assert k.create(force=True) == "protected"
コード例 #6
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_create_ok(svc_resource, subcall_cmd, monkeypatch):
    def get(*args):
        svc2 = json.loads(svc_resource['body'])
        return svc2

    monkeypatch.setattr("kpm.kubernetes.Kubernetes.get", get)
    k = Kubernetes(body=svc_resource['body'])
    assert k.create() == "ok"
コード例 #7
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_create_ok_nohash(ns_resource, subcall_cmd, monkeypatch):
    def get(*args):
        r = json.loads(ns_resource['body'])
        return r

    monkeypatch.setattr("kpm.kubernetes.Kubernetes.get", get)
    k = Kubernetes(body=ns_resource['body'])
    assert k.create() == "ok"
コード例 #8
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_create_force_protected(ns_resource, subcall_cmd, monkeypatch):
    def get(*args):
        svc2 = json.loads(ns_resource['body'])
        return svc2

    monkeypatch.setattr("kpm.kubernetes.Kubernetes.get", get)
    k = Kubernetes(body=ns_resource['body'])
    assert k.create(force=True) == "protected"
コード例 #9
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_create_ok(svc_resource, subcall_cmd, monkeypatch):
    def get(*args):
        svc2 = json.loads(svc_resource['body'])
        return svc2

    monkeypatch.setattr("kpm.kubernetes.Kubernetes.get", get)
    k = Kubernetes(body=svc_resource['body'])
    assert k.create() == "ok"
コード例 #10
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_create_update(svc_resource, subcall_cmd, monkeypatch):
    def get(*args):
        svc2 = json.loads(svc_resource['body'])
        svc2['metadata']['annotations']['kpm.hash'] = 'dummy'
        return svc2

    monkeypatch.setattr("kpm.kubernetes.Kubernetes.get", get)
    k = Kubernetes(body=svc_resource['body'])
    assert k.create() == "updated"
コード例 #11
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_create_update(svc_resource, subcall_cmd, monkeypatch):
    def get(*args):
        svc2 = json.loads(svc_resource['body'])
        svc2['metadata']['annotations']['kpm.hash'] = 'dummy'
        return svc2

    monkeypatch.setattr("kpm.kubernetes.Kubernetes.get", get)
    k = Kubernetes(body=svc_resource['body'])
    assert k.create() == "updated"
コード例 #12
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_get_proxy_500_raise(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1], svc_resource['name'])
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, text=response, status_code=500)
        with pytest.raises(requests.exceptions.HTTPError):
            k.get()
コード例 #13
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_get_proxy(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1], svc_resource['name'])
    url2 = "%s/%s/%s" % (k.proxy.geturl(), k.endpoint, k.name)
    assert url == url2
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, text=response)
        assert json.dumps(k.get()) == json.dumps(json.loads(response))
コード例 #14
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_create_proxy(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s" % (proxy, svc_resource['endpoint'][1:-1])
    url2 = "%s/%s" % (k.proxy.geturl(), k.endpoint)
    assert url == url2
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.post(url, text=response)
        m.get(url + "/" + svc_resource['name'], status_code=404)
        assert k.create() == "created"
コード例 #15
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_get_proxy_404(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'],
                   proxy=proxy,
                   endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1],
                        svc_resource['name'])
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, text=response, status_code=404)
        assert k.get() is None
コード例 #16
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_get_proxy_500_raise(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'],
                   proxy=proxy,
                   endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1],
                        svc_resource['name'])
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, text=response, status_code=500)
        with pytest.raises(requests.exceptions.HTTPError):
            k.get()
コード例 #17
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_wait(svc_resource, monkeypatch):
    import time
    monkeypatch.setattr(time, 'sleep', lambda s: None)
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1], svc_resource['name'])
    url2 = "%s/%s/%s" % (k.proxy.geturl(), k.endpoint, k.name)
    assert url == url2
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, [{'status_code': 404}, {'text': response, 'status_code': 200}])
        assert json.dumps(k.wait()) == json.dumps(json.loads(response))
        assert m.call_count == 2
コード例 #18
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_create_proxy(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'],
                   proxy=proxy,
                   endpoint=svc_resource['endpoint'])
    url = "%s/%s" % (proxy, svc_resource['endpoint'][1:-1])
    url2 = "%s/%s" % (k.proxy.geturl(), k.endpoint)
    assert url == url2
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.post(url, text=response)
        m.get(url + "/" + svc_resource['name'], status_code=404)
        assert k.create() == "created"
コード例 #19
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_get_proxy(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'],
                   proxy=proxy,
                   endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1],
                        svc_resource['name'])
    url2 = "%s/%s/%s" % (k.proxy.geturl(), k.endpoint, k.name)
    assert url == url2
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, text=response)
        assert json.dumps(k.get()) == json.dumps(json.loads(response))
コード例 #20
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_wait(svc_resource, monkeypatch):
    import time
    monkeypatch.setattr(time, 'sleep', lambda s: None)
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'],
                   proxy=proxy,
                   endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1],
                        svc_resource['name'])
    url2 = "%s/%s/%s" % (k.proxy.geturl(), k.endpoint, k.name)
    assert url == url2
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, [{
            'status_code': 404
        }, {
            'text': response,
            'status_code': 200
        }])
        assert json.dumps(k.wait()) == json.dumps(json.loads(response))
        assert m.call_count == 2
コード例 #21
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_create_nohash(ns_resource, subcall_cmd, monkeypatch):
    def get(*args):
        return None
    monkeypatch.setattr("kpm.kubernetes.Kubernetes.get", get)
    k = Kubernetes(body=ns_resource['body'])
    assert k.create() == "created"
コード例 #22
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test__namespace(ns_resource):
    k = Kubernetes(body=ns_resource['body'])
    assert k._namespace() == "default"
コード例 #23
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test__namespace_params(svc_resource):
    k = Kubernetes(namespace="test", body=svc_resource['body'])
    assert k._namespace(k.namespace) == "test"
コード例 #24
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_delete_existing_resource(subcall_delete, svc_resource):
    k = Kubernetes(body=svc_resource['body'])
    assert k.delete() == "deleted"
コード例 #25
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_protected_is_true_when_annoted(ns_resource):
    k = Kubernetes(body=ns_resource['body'])
    assert k.protected is True
コード例 #26
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_exists_false(subcall_cmd_error, svc_resource):
    k = Kubernetes(body=svc_resource['body'])
    assert k.exists() is False
コード例 #27
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_check_cmd(svc_resource, subcall_cmd):
    k = Kubernetes(body=svc_resource['body'])
    assert k._call(["get", "svc",
                    "kube-ui"]) == "kubectl get svc kube-ui --namespace testns"
コード例 #28
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_get_hash(svc_resource):
    ks = Kubernetes(body=svc_resource['body'])
    kbody = json.loads(svc_resource['body'])
    assert ks.kpmhash == ks._get_kpmhash(kbody)
    assert ks.kpmhash == kbody['metadata']['annotations']['kpm.hash']
コード例 #29
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_load_obj(svc_resource):
    k = Kubernetes(namespace="test", body=svc_resource['body'])
    assert json.dumps(k.obj) == json.dumps(json.loads(svc_resource['body']))
コード例 #30
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test__namespace_annotate(svc_resource):
    k = Kubernetes(body=svc_resource['body'])
    assert k._namespace() == "testns"
コード例 #31
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_force_namespace(ns_resource):
    k = Kubernetes(namespace="test", body=ns_resource['body'])
    assert k.namespace == "test"
コード例 #32
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_call_dry(svc_resource):
    k = Kubernetes(body=svc_resource['body'])
    assert k._call(["get", "rc", "kube-ui"], dry=True)
コード例 #33
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_get_svc(subcall_get_assert, svc_resource):
    k = Kubernetes(body=svc_resource['body'])
    assert json.dumps(k.get()) == json.dumps(
        json.loads(get_response(k.name, k.kind)))
コード例 #34
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_call_dry(svc_resource):
    k = Kubernetes(body=svc_resource['body'])
    assert k._call(["get", "rc", "kube-ui"], dry=True)
コード例 #35
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_delete_ns_protected(subcall_delete, ns_resource):
    k = Kubernetes(body=ns_resource['body'])
    assert k.delete() == "protected"
コード例 #36
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_exists_true(subcall_get_assert, svc_resource):
    k = Kubernetes(body=svc_resource['body'])
    assert k.exists() is True
コード例 #37
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_exists_true(subcall_get_assert, svc_resource):
    k = Kubernetes(body=svc_resource['body'])
    assert k.exists() is True
コード例 #38
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_delete_non_existing_resource(subcall_cmd_error, svc_resource):
    k = Kubernetes(body=svc_resource['body'])
    assert k.delete() == "absent"
コード例 #39
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_exists_false(subcall_cmd_error, svc_resource):
    k = Kubernetes(body=svc_resource['body'])
    assert k.exists() is False
コード例 #40
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_get_hash(svc_resource):
    ks = Kubernetes(body=svc_resource['body'])
    kbody = json.loads(svc_resource['body'])
    assert ks.kpmhash == ks._get_kpmhash(kbody)
    assert ks.kpmhash == kbody['metadata']['annotations']['kpm.hash']
コード例 #41
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test__namespace_annotate(svc_resource):
    k = Kubernetes(body=svc_resource['body'])
    assert k._namespace() == "testns"
コード例 #42
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_protected_is_false(svc_resource):
    k = Kubernetes(body=svc_resource['body'])
    assert k.protected is False
コード例 #43
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_check_cmd(svc_resource, subcall_cmd):
    k = Kubernetes(body=svc_resource['body'])
    assert k._call(["get", "svc", "kube-ui"]) == "kubectl get svc kube-ui --namespace testns"
コード例 #44
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test__namespace(ns_resource):
    k = Kubernetes(body=ns_resource['body'])
    assert k._namespace() == "default"
コード例 #45
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_get_cmd_error(svc_resource, subcall_cmd_error):
    k = Kubernetes(body=svc_resource['body'])
    assert k.get() is None
コード例 #46
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test__namespace_params(svc_resource):
    k = Kubernetes(namespace="test", body=svc_resource['body'])
    assert k._namespace(k.namespace) == "test"
コード例 #47
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_get_svc(subcall_get_assert, svc_resource):
    k = Kubernetes(body=svc_resource['body'])
    assert json.dumps(k.get()) == json.dumps(json.loads(get_response(k.name, k.kind)))
コード例 #48
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_get_ns(subcall_get_assert, ns_resource):
    k = Kubernetes(body=ns_resource['body'], namespace="testns")
    assert json.dumps(k.get()) == json.dumps(
        json.loads(get_response(k.name, k.kind)))
コード例 #49
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_delete_ns_protected(subcall_delete, ns_resource):
    k = Kubernetes(body=ns_resource['body'])
    assert k.delete() == "protected"
コード例 #50
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_get_empty(ns_resource):
    k = Kubernetes(body=ns_resource['body'])
    assert k.kpmhash is None
コード例 #51
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_delete_existing_resource(subcall_delete, svc_resource):
    k = Kubernetes(body=svc_resource['body'])
    assert k.delete() == "deleted"
コード例 #52
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_get_cmd_error(svc_resource, subcall_cmd_error):
    k = Kubernetes(body=svc_resource['body'])
    assert k.get() is None
コード例 #53
0
ファイル: test_kubernetes.py プロジェクト: ryanj/kpm
def test_delete_non_existing_resource(subcall_cmd_error, svc_resource):
    k = Kubernetes(body=svc_resource['body'])
    assert k.delete() == "absent"
コード例 #54
0
ファイル: deploy.py プロジェクト: jonboulle/kpm
def _process(package_name,
             version=None,
             dest="/tmp",
             namespace=None,
             force=False,
             dry=False,
             endpoint=None,
             action="create",
             fmt="stdout",
             proxy=None,
             variables=None):

    registry = Registry(endpoint=endpoint)
    packages = registry.generate(package_name, namespace=namespace, version=version, variables=variables)
    dest = os.path.join(dest, package_name)

    if version:
        dest = os.path.join(dest, version)
    mkdir_p(dest)
    table = []
    results = []
    if fmt == "stdout":
        print "%s %s " % (action, package_name)
    i = 0
    for package in packages["deploy"]:
        i += 1
        pname = package["package"]
        version = package["version"]
        namespace = package["namespace"]
        if fmt == "stdout":
            print "\n %02d - %s:" % (i, package["package"])
        for resource in package["resources"]:
            body = resource["body"]
            endpoint = resource["endpoint"]
            # Use API instead of kubectl
            with open(os.path.join(dest, resource['file']), 'wb') as f:
                f.write(body)
            kubresource = Kubernetes(namespace=namespace, body=body, endpoint=endpoint, proxy=proxy)
            status = getattr(kubresource, action)(force=force, dry=dry)
            if fmt == "stdout":
                output_progress(kubresource, status)
            result_line = OrderedDict([("package", pname),
                                       ("version", version),
                                       ("kind", kubresource.kind),
                                       ("dry", dry),
                                       ("name", kubresource.name),
                                       ("namespace", kubresource.namespace),
                                       ("status", status)])

            if status != 'ok' and action == 'create':
                kubresource.wait(3)
            results.append(result_line)
            if fmt == "stdout":
                header = ["package", "version", "kind", "name",  "namespace", "status"]
                display_line = []
                for k in header:
                    display_line.append(result_line[k])
                table.append(display_line)
    if fmt == "stdout":
        print_deploy_result(table)
    return results
コード例 #55
0
ファイル: test_kubernetes.py プロジェクト: jonboulle/kpm
def test_get_ns(subcall_get_assert, ns_resource):
    k = Kubernetes(body=ns_resource['body'], namespace="testns")
    assert json.dumps(k.get()) == json.dumps(json.loads(get_response(k.name, k.kind)))