summaryrefslogtreecommitdiffstats
path: root/k8s
diff options
context:
space:
mode:
authorMiroslav Los <miroslav.los@pantheon.tech>2019-11-26 14:20:36 +0100
committerMiroslav Los <miroslav.los@pantheon.tech>2019-11-26 19:24:24 +0100
commit01a60ff23b979eb676658713748598ba4892163a (patch)
tree1fb1b260c3723ddc42f047796db6b1928171b48c /k8s
parent77e27adeab5ff155b690f2e058c06f0a7812e225 (diff)
Support python3 in all plugins
Unify tox/requirements/setup.py requirement specifications. Do not set upper version limits if possible. Drop uuid as dependency included with standard library. Drop import of unmaintained cloudify_importer without python3 version. Use PEP 508 URLs in requirements for non-PyPI (github) releases. Use cloudify-common 5 release; pre-release package for python3. Rewrite uses of map with loops/comprehensions. Signed-off-by: Miroslav Los <miroslav.los@pantheon.tech> Issue-ID: DCAEGEN2-1956 Change-Id: I7b3ceb97a628e3af5bda3178d182f4207069e86d
Diffstat (limited to 'k8s')
-rw-r--r--k8s/configure/configure.py8
-rw-r--r--k8s/k8sclient/k8sclient.py11
-rw-r--r--k8s/k8splugin/discovery.py9
-rw-r--r--k8s/k8splugin/tasks.py40
-rw-r--r--k8s/k8splugin/utils.py3
-rw-r--r--k8s/requirements.txt10
-rw-r--r--k8s/setup.py11
-rw-r--r--k8s/tests/test_k8sclient.py7
-rw-r--r--k8s/tox.ini8
9 files changed, 51 insertions, 56 deletions
diff --git a/k8s/configure/configure.py b/k8s/configure/configure.py
index 9f7929e..959c215 100644
--- a/k8s/configure/configure.py
+++ b/k8s/configure/configure.py
@@ -2,6 +2,7 @@
# org.onap.dcae
# ================================================================================
# Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -75,13 +76,16 @@ def configure(config_path=_CONFIG_PATH, key = _CONSUL_KEY):
"""
from cloudify.exceptions import NonRecoverableError
- import ConfigParser
+ try:
+ import configparser
+ except ImportError:
+ import ConfigParser as configparser
from k8splugin import discovery
config = _set_defaults()
try:
# Get Consul address from a config file
- c = ConfigParser.ConfigParser()
+ c = configparser.ConfigParser()
c.read(config_path)
config["consul_host"] = c.get('consul','address')
diff --git a/k8s/k8sclient/k8sclient.py b/k8s/k8sclient/k8sclient.py
index 9a01536..323a208 100644
--- a/k8s/k8sclient/k8sclient.py
+++ b/k8s/k8sclient/k8sclient.py
@@ -2,6 +2,7 @@
# org.onap.dcae
# ================================================================================
# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -136,7 +137,7 @@ def _create_resources(resources=None):
def _create_container_object(name, image, always_pull, env={}, container_ports=[], volume_mounts = [], resources = None, readiness = None, liveness = None):
# Set up environment variables
# Copy any passed in environment variables
- env_vars = [client.V1EnvVar(name=k, value=env[k]) for k in env.keys()]
+ env_vars = [client.V1EnvVar(name=k, value=env[k]) for k in env]
# Add POD_IP with the IP address of the pod running the container
pod_ip = client.V1EnvVarSource(field_ref = client.V1ObjectFieldSelector(field_path="status.podIP"))
env_vars.append(client.V1EnvVar(name="POD_IP",value_from=pod_ip))
@@ -517,7 +518,7 @@ def deploy(namespace, component_name, image, replicas, always_pull, k8sconfig, r
if port_map:
service_ports = [] # Ports exposed internally on the k8s network
exposed_ports = [] # Ports to be mapped to ports on the k8s nodes via NodePort
- for (cport, proto), hport in port_map.iteritems():
+ for (cport, proto), hport in port_map.items():
service_ports.append(client.V1ServicePort(port=int(cport),protocol=proto,name="port-{0}-{1}".format(proto[0].lower(), cport)))
if int(hport) != 0:
exposed_ports.append(client.V1ServicePort(port=int(cport),protocol=proto,node_port=int(hport),name="xport-{0}-{1}".format(proto[0].lower(),cport)))
@@ -660,8 +661,6 @@ def execute_command_in_deployment(deployment_description, command):
field_selector = "status.phase=Running"
).items]
- def do_execute(pod_name):
- return _execute_command_in_pod(location, namespace, pod_name, command)
-
# Execute command in the running pods
- return map(do_execute, pod_names)
+ return [_execute_command_in_pod(location, namespace, pod_name, command)
+ for pod_name in pod_names]
diff --git a/k8s/k8splugin/discovery.py b/k8s/k8splugin/discovery.py
index 56f8260..76c160a 100644
--- a/k8s/k8splugin/discovery.py
+++ b/k8s/k8splugin/discovery.py
@@ -2,6 +2,7 @@
# org.onap.dcae
# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -233,12 +234,10 @@ def add_to_entry(conn, key, add_name, add_value):
def _find_matching_services(services, name_search, tags):
"""Find matching services given search criteria"""
- def is_match(service):
- srv_name, srv_tags = service
- return name_search in srv_name and \
- all(map(lambda tag: tag in srv_tags, tags))
+ tags = set(tags)
+ return [srv_name for srv_name in services
+ if name_search in srv_name and tags <= set(services[srv_name])]
- return [ srv[0] for srv in services.items() if is_match(srv) ]
def search_services(conn, name_search, tags):
"""Search for services that match criteria
diff --git a/k8s/k8splugin/tasks.py b/k8s/k8splugin/tasks.py
index 108cf31..956fff2 100644
--- a/k8s/k8splugin/tasks.py
+++ b/k8s/k8splugin/tasks.py
@@ -2,6 +2,7 @@
# org.onap.dcae
# ================================================================================
# Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -20,9 +21,6 @@
# Lifecycle interface calls for containerized components
-# Needed by Cloudify Manager to load google.auth for the Kubernetes python client
-import cloudify_importer
-
import time, copy
import json
from cloudify import ctx
@@ -138,16 +136,14 @@ def _parse_streams(**kwargs):
"""Parse streams and setup for DMaaP plugin"""
# The DMaaP plugin requires this plugin to set the runtime properties
# keyed by the node name.
- def setup_publishes(s):
- kwargs[s["name"]] = s
-
- map(setup_publishes, kwargs["streams_publishes"])
+ for stream in kwargs["streams_publishes"]:
+ kwargs[stream["name"]] = stream
- def setup_subscribes(s):
- if s["type"] == "data_router":
+ for stream in kwargs["streams_subscribes"]:
+ if stream["type"] == "data_router":
# Don't want to mutate the source
- s = copy.deepcopy(s)
+ stream = copy.deepcopy(stream)
# Set up the delivery URL
# Using service_component_name as the host name in the subscriber URL
@@ -156,29 +152,27 @@ def _parse_streams(**kwargs):
# more remote ("edge") locations depends on how networking and DNS is set
# up in a multi-cluster deployment
service_component_name = kwargs["name"]
- ports,_ = k8sclient.parse_ports(kwargs["ports"])
- (dport, _) = ports[0]
+ ports, _ = k8sclient.parse_ports(kwargs["ports"])
+ dport, _ = ports[0]
subscriber_host = "{host}:{port}".format(host=service_component_name, port=dport)
- scheme = s["scheme"] if "scheme" in s else DEFAULT_SCHEME
- if "route" not in s:
+ scheme = stream.get("scheme", DEFAULT_SCHEME)
+ if "route" not in stream:
raise NonRecoverableError("'route' key missing from data router subscriber")
- path = s["route"]
- s["delivery_url"] = "{scheme}://{host}/{path}".format(
+ path = stream["route"]
+ stream["delivery_url"] = "{scheme}://{host}/{path}".format(
scheme=scheme, host=subscriber_host, path=path)
# If username and password has not been provided then generate it. The
# DMaaP plugin doesn't generate for subscribers. The generation code
# and length of username password has been lifted from the DMaaP
# plugin.
- if not s.get("username", None):
- s["username"] = utils.random_string(8)
- if not s.get("password", None):
- s["password"] = utils.random_string(10)
-
- kwargs[s["name"]] = s
+ if not stream.get("username", None):
+ stream["username"] = utils.random_string(8)
+ if not stream.get("password", None):
+ stream["password"] = utils.random_string(10)
- map(setup_subscribes, kwargs["streams_subscribes"])
+ kwargs[stream["name"]] = stream
return kwargs
diff --git a/k8s/k8splugin/utils.py b/k8s/k8splugin/utils.py
index c45af68..6475aaa 100644
--- a/k8s/k8splugin/utils.py
+++ b/k8s/k8splugin/utils.py
@@ -2,6 +2,7 @@
# org.onap.dcae
# ================================================================================
# Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -34,7 +35,7 @@ def update_dict(d, u):
Update dict d with dict u
"""
- for k, v in u.iteritems():
+ for k, v in u.items():
if isinstance(v, collections.Mapping):
r = update_dict(d.get(k, {}), v)
d[k] = r
diff --git a/k8s/requirements.txt b/k8s/requirements.txt
index b2c0986..2a94ae6 100644
--- a/k8s/requirements.txt
+++ b/k8s/requirements.txt
@@ -1,5 +1,5 @@
-python-consul>=0.6.0,<1.0.0
-uuid==1.30
-onap-dcae-dcaepolicy-lib>=2.4.1,<3.0.0
-kubernetes==9.0.0
-cloudify-plugins-common==3.4
+python-consul>=0.6.0
+onap-dcae-dcaepolicy-lib>=2.4.1
+kubernetes>=9.0.0
+cloudify-common>=5.0.0; python_version<"3"
+cloudify-common @ git+https://github.com/cloudify-cosmo/cloudify-common@cy-1374-python3#egg=cloudify-common==5.0.0; python_version>="3"
diff --git a/k8s/setup.py b/k8s/setup.py
index b0e43f6..386dde8 100644
--- a/k8s/setup.py
+++ b/k8s/setup.py
@@ -2,6 +2,7 @@
# org.onap.dcae
# ================================================================================
# Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -28,11 +29,9 @@ setup(
packages=['k8splugin','k8sclient','msb','configure'],
zip_safe=False,
install_requires=[
- "python-consul>=0.6.0,<1.0.0",
- "uuid==1.30",
- "onap-dcae-dcaepolicy-lib>=2.4.1,<3.0.0",
- "cloudify-plugins-common==3.4",
- "cloudify-python-importer==0.1.0",
- "kubernetes==9.0.0"
+ 'python-consul>=0.6.0',
+ 'onap-dcae-dcaepolicy-lib>=2.4.1',
+ 'kubernetes>=9.0.0',
+ 'cloudify-common>=5.0.0',
]
)
diff --git a/k8s/tests/test_k8sclient.py b/k8s/tests/test_k8sclient.py
index 079748c..fcc6b95 100644
--- a/k8s/tests/test_k8sclient.py
+++ b/k8s/tests/test_k8sclient.py
@@ -2,6 +2,7 @@
# org.onap.dcae
# ================================================================================
# Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -34,9 +35,9 @@ def test_parse_interval():
(354123, 354123),
("354123", 354123),
("354123s", 354123),
- (1234567890123456789012345678901234567890L,1234567890123456789012345678901234567890L),
- ("1234567890123456789012345678901234567890",1234567890123456789012345678901234567890L),
- ("1234567890123456789012345678901234567890s",1234567890123456789012345678901234567890L),
+ (1234567890123456789012345678901234567890,1234567890123456789012345678901234567890),
+ ("1234567890123456789012345678901234567890",1234567890123456789012345678901234567890),
+ ("1234567890123456789012345678901234567890s",1234567890123456789012345678901234567890),
("05s", 5),
("00000000000000000000000000000000005m", 5 * 60)
]
diff --git a/k8s/tox.ini b/k8s/tox.ini
index b6b2b54..3bea42d 100644
--- a/k8s/tox.ini
+++ b/k8s/tox.ini
@@ -1,6 +1,6 @@
# content of: tox.ini , put in same dir as setup.py
[tox]
-envlist = py27
+envlist = py27,py36
[testenv]
deps=
@@ -8,8 +8,6 @@ deps=
pytest
coverage
pytest-cov
-setenv=
- PYTHONPATH={toxinidir}
commands=
- pytest --junitxml xunit-results.xml --cov configure --cov k8sclient --cov k8splugin --cov msb --cov-report xml
- coverage xml
+ pytest --junitxml xunit-results.xml --cov configure --cov k8sclient --cov k8splugin --cov msb --cov-report xml
+ coverage xml