示例#1
0
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
示例#2
0
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
示例#3
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
示例#4
0
def _process(package_name,
             version=None,
             dest="/tmp",
             namespace=None,
             force=False,
             dry=False,
             endpoint=None,
             action="create",
             fmt="text",
             proxy=None,
             variables=None,
             shards=None):

    registry = Registry(endpoint=endpoint)
    packages = registry.generate(package_name,
                                 namespace=namespace,
                                 version=version,
                                 variables=variables,
                                 shards=shards)

    dest = os.path.join(dest, package_name)

    if version:
        dest = os.path.join(dest, version)
    mkdir_p(dest)
    table = []
    results = []
    if fmt == "text":
        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 == "text":
            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,
                        "%s-%s" % (resource['name'], resource['file'].replace(
                            "/", "_"))), '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 == "text":
                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 == "text":
                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 == "text":
        print_deploy_result(table)
    return results