Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport/2.3] Upgrade black version (#424) #446

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/action/k8s_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def get_kubeconfig(self, kubeconfig, remote_transport, new_module_args):
)

def run(self, tmp=None, task_vars=None):
""" handler for k8s options """
"""handler for k8s options"""
if task_vars is None:
task_vars = dict()

Expand Down
24 changes: 12 additions & 12 deletions plugins/connection/kubectl.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@


class Connection(ConnectionBase):
""" Local kubectl based connections """
"""Local kubectl based connections"""

transport = CONNECTION_TRANSPORT
connection_options = CONNECTION_OPTIONS
Expand Down Expand Up @@ -240,12 +240,12 @@ def _build_exec_cmd(self, cmd):
# Translate verify_ssl to skip_verify_ssl, and output as string
skip_verify_ssl = not self.get_option(key)
local_cmd.append(
u"{0}={1}".format(
"{0}={1}".format(
self.connection_options[key], str(skip_verify_ssl).lower()
)
)
censored_local_cmd.append(
u"{0}={1}".format(
"{0}={1}".format(
self.connection_options[key], str(skip_verify_ssl).lower()
)
)
Expand All @@ -262,20 +262,20 @@ def _build_exec_cmd(self, cmd):
else:
censored_local_cmd += [cmd_arg, self.get_option(key)]

extra_args_name = u"{0}_extra_args".format(self.transport)
extra_args_name = "{0}_extra_args".format(self.transport)
if self.get_option(extra_args_name):
local_cmd += self.get_option(extra_args_name).split(" ")
censored_local_cmd += self.get_option(extra_args_name).split(" ")

pod = self.get_option(u"{0}_pod".format(self.transport))
pod = self.get_option("{0}_pod".format(self.transport))
if not pod:
pod = self._play_context.remote_addr
# -i is needed to keep stdin open which allows pipelining to work
local_cmd += ["exec", "-i", pod]
censored_local_cmd += ["exec", "-i", pod]

# if the pod has more than one container, then container is required
container_arg_name = u"{0}_container".format(self.transport)
container_arg_name = "{0}_container".format(self.transport)
if self.get_option(container_arg_name):
local_cmd += ["-c", self.get_option(container_arg_name)]
censored_local_cmd += ["-c", self.get_option(container_arg_name)]
Expand All @@ -286,17 +286,17 @@ def _build_exec_cmd(self, cmd):
return local_cmd, censored_local_cmd

def _connect(self, port=None):
""" Connect to the container. Nothing to do """
"""Connect to the container. Nothing to do"""
super(Connection, self)._connect()
if not self._connected:
display.vvv(
u"ESTABLISH {0} CONNECTION".format(self.transport),
"ESTABLISH {0} CONNECTION".format(self.transport),
host=self._play_context.remote_addr,
)
self._connected = True

def exec_command(self, cmd, in_data=None, sudoable=False):
""" Run a command in the container """
"""Run a command in the container"""
super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable)

local_cmd, censored_local_cmd = self._build_exec_cmd(
Expand Down Expand Up @@ -333,7 +333,7 @@ def _prefix_login_path(self, remote_path):
return os.path.normpath(remote_path)

def put_file(self, in_path, out_path):
""" Transfer a file from local to the container """
"""Transfer a file from local to the container"""
super(Connection, self).put_file(in_path, out_path)
display.vvv(
"PUT %s TO %s" % (in_path, out_path), host=self._play_context.remote_addr
Expand Down Expand Up @@ -376,7 +376,7 @@ def put_file(self, in_path, out_path):
)

def fetch_file(self, in_path, out_path):
""" Fetch a file from container to local. """
"""Fetch a file from container to local."""
super(Connection, self).fetch_file(in_path, out_path)
display.vvv(
"FETCH %s TO %s" % (in_path, out_path), host=self._play_context.remote_addr
Expand Down Expand Up @@ -420,6 +420,6 @@ def fetch_file(self, in_path, out_path):
)

def close(self):
""" Terminate the connection. Nothing to do for kubectl"""
"""Terminate the connection. Nothing to do for kubectl"""
super(Connection, self).close()
self._connected = False
2 changes: 1 addition & 1 deletion plugins/module_utils/client/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init_cache(self, refresh=False):
self._write_cache()

def get_resources_for_api_version(self, prefix, group, version, preferred):
""" returns a dictionary of resources associated with provided (prefix, group, version)"""
"""returns a dictionary of resources associated with provided (prefix, group, version)"""

resources = defaultdict(list)
subresources = defaultdict(dict)
Expand Down
6 changes: 4 additions & 2 deletions plugins/module_utils/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,10 @@ def check_pod(k8s_ansible_mixin, module):
def _fail(exc):
arg = {}
if hasattr(exc, "body"):
msg = "Namespace={0} Kind=Pod Name={1}: Failed requested object: {2}".format(
namespace, name, exc.body
msg = (
"Namespace={0} Kind=Pod Name={1}: Failed requested object: {2}".format(
namespace, name, exc.body
)
)
else:
msg = to_native(exc)
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@


class ApplyException(Exception):
""" Could not apply patch """
"""Could not apply patch"""
12 changes: 9 additions & 3 deletions plugins/modules/helm_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,15 @@ def main():
state=dict(
type="str", default="present", choices=["present", "absent", "latest"]
),
plugin_path=dict(type="str",),
plugin_name=dict(type="str",),
plugin_version=dict(type="str",),
plugin_path=dict(
type="str",
),
plugin_name=dict(
type="str",
),
plugin_version=dict(
type="str",
),
# Helm options
context=dict(
type="str",
Expand Down
4 changes: 3 additions & 1 deletion plugins/modules/helm_plugin_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def main():
module = AnsibleModule(
argument_spec=dict(
binary_path=dict(type="path"),
plugin_name=dict(type="str",),
plugin_name=dict(
type="str",
),
# Helm options
context=dict(
type="str",
Expand Down
5 changes: 4 additions & 1 deletion plugins/modules/k8s_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ def execute_module(module, k8s_ansible_mixin):


def main():
module = AnsibleModule(argument_spec=argspec(), supports_check_mode=True,)
module = AnsibleModule(
argument_spec=argspec(),
supports_check_mode=True,
)
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
K8sAnsibleMixin,
get_api_client,
Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/k8s_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@


def execute_module(
module, k8s_ansible_mixin,
module,
k8s_ansible_mixin,
):
k8s_ansible_mixin.set_resource_definitions(module)

Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/k8s_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def merge_dicts(x, y):


def argspec():
""" argspec property builder """
"""argspec property builder"""
argument_spec = copy.deepcopy(AUTH_ARG_SPEC)
argument_spec.update(COMMON_ARG_SPEC)
argument_spec.update(RESOURCE_ARG_SPEC)
Expand All @@ -196,7 +196,7 @@ def argspec():


def execute_module(module, k8s_ansible_mixin):
""" Module execution """
"""Module execution"""
k8s_ansible_mixin.set_resource_definitions(module)

api_version = "v1"
Expand Down
5 changes: 4 additions & 1 deletion plugins/modules/k8s_taint.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,10 @@ def execute_module(self):


def main():
module = AnsibleModule(argument_spec=argspec(), supports_check_mode=True,)
module = AnsibleModule(
argument_spec=argspec(),
supports_check_mode=True,
)
k8s_taint = K8sTaintAnsible(module)
k8s_taint.execute_module()

Expand Down
3 changes: 2 additions & 1 deletion tests/integration/targets/helm/library/helm_test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
def main():
module = AnsibleModule(
argument_spec=dict(
binary_path=dict(type="path"), version=dict(type="str", default="3.7.0"),
binary_path=dict(type="path"),
version=dict(type="str", default="3.7.0"),
),
)

Expand Down
44 changes: 22 additions & 22 deletions tests/unit/module_utils/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,27 +324,27 @@
# str type and everything else was mostly unicode type (don't ask me how)
dict(
last_applied={
u"kind": u"ConfigMap",
u"data": {u"one": "1", "three": "3", "two": "2"},
u"apiVersion": u"v1",
u"metadata": {u"namespace": u"apply", u"name": u"apply-configmap"},
"kind": "ConfigMap",
"data": {"one": "1", "three": "3", "two": "2"},
"apiVersion": "v1",
"metadata": {"namespace": "apply", "name": "apply-configmap"},
},
actual={
u"kind": u"ConfigMap",
u"data": {u"one": "1", "three": "3", "two": "2"},
u"apiVersion": u"v1",
u"metadata": {
u"namespace": u"apply",
u"name": u"apply-configmap",
u"resourceVersion": "1714994",
u"creationTimestamp": u"2019-08-17T05:08:05Z",
u"annotations": {},
u"selfLink": u"/api/v1/namespaces/apply/configmaps/apply-configmap",
u"uid": u"fed45fb0-c0ac-11e9-9d95-025000000001",
"kind": "ConfigMap",
"data": {"one": "1", "three": "3", "two": "2"},
"apiVersion": "v1",
"metadata": {
"namespace": "apply",
"name": "apply-configmap",
"resourceVersion": "1714994",
"creationTimestamp": "2019-08-17T05:08:05Z",
"annotations": {},
"selfLink": "/api/v1/namespaces/apply/configmaps/apply-configmap",
"uid": "fed45fb0-c0ac-11e9-9d95-025000000001",
},
},
desired={
"kind": u"ConfigMap",
"kind": "ConfigMap",
"data": {"one": "1", "three": "3", "two": "2"},
"apiVersion": "v1",
"metadata": {"namespace": "apply", "name": "apply-configmap"},
Expand All @@ -355,7 +355,7 @@
# then apply the Deployment again. Should un-scale the Deployment
dict(
last_applied={
"kind": u"Deployment",
"kind": "Deployment",
"spec": {
"replicas": 1,
"template": {
Expand All @@ -372,10 +372,10 @@
}
},
},
"metadata": {"namespace": "apply", "name": u"apply-deployment"},
"metadata": {"namespace": "apply", "name": "apply-deployment"},
},
actual={
"kind": u"Deployment",
"kind": "Deployment",
"spec": {
"replicas": 0,
"template": {
Expand All @@ -392,10 +392,10 @@
}
},
},
"metadata": {"namespace": "apply", "name": u"apply-deployment"},
"metadata": {"namespace": "apply", "name": "apply-deployment"},
},
desired={
"kind": u"Deployment",
"kind": "Deployment",
"spec": {
"replicas": 1,
"template": {
Expand All @@ -409,7 +409,7 @@
}
},
},
"metadata": {"namespace": "apply", "name": u"apply-deployment"},
"metadata": {"namespace": "apply", "name": "apply-deployment"},
},
expected={
"spec": {
Expand Down
40 changes: 34 additions & 6 deletions tests/unit/module_utils/test_marshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,61 @@

tests = [
dict(
resource=dict(kind="ConfigMap", name="", data=dict(),),
resource=dict(
kind="ConfigMap",
name="",
data=dict(),
),
expected=b'{"data":{},"kind":"ConfigMap","name":""}',
),
dict(
resource=dict(kind="ConfigMap", name="", data=dict(one=""),),
resource=dict(
kind="ConfigMap",
name="",
data=dict(one=""),
),
expected=b'{"data":{"one":""},"kind":"ConfigMap","name":""}',
),
dict(
resource=dict(
kind="ConfigMap", name="", data=dict(two="2", one="", three="3",),
kind="ConfigMap",
name="",
data=dict(
two="2",
one="",
three="3",
),
),
expected=b'{"data":{"one":"","three":"3","two":"2"},"kind":"ConfigMap","name":""}',
),
dict(
resource=dict(kind="Secret", type="my-type", name="", data=dict(),),
resource=dict(
kind="Secret",
type="my-type",
name="",
data=dict(),
),
expected=b'{"data":{},"kind":"Secret","name":"","type":"my-type"}',
),
dict(
resource=dict(kind="Secret", type="my-type", name="", data=dict(one=""),),
resource=dict(
kind="Secret",
type="my-type",
name="",
data=dict(one=""),
),
expected=b'{"data":{"one":""},"kind":"Secret","name":"","type":"my-type"}',
),
dict(
resource=dict(
kind="Secret",
type="my-type",
name="",
data=dict(two="Mg==", one="", three="Mw==",),
data=dict(
two="Mg==",
one="",
three="Mw==",
),
),
expected=b'{"data":{"one":"","three":"Mw==","two":"Mg=="},"kind":"Secret","name":"","type":"my-type"}',
),
Expand Down
Loading