Skip to content

Commit 56afbcd

Browse files
Merge pull request #62 from spilchen/master
Move initialization of context to thread local object
2 parents 736bcf2 + c42e0d9 commit 56afbcd

File tree

4 files changed

+28
-26
lines changed

4 files changed

+28
-26
lines changed

ansible/rebuild_module.digest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4008d9385ab44dc3856603d9fb96eaef -
1+
69c12ca52d215c67dd8e93e9502d79d6 -

ansible/roles/openshift_client_python/library/openshift_client_python.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openshift/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .ansible import ansible
1313

1414
# Single source for module version
15-
__VERSION__ = '1.0.3'
15+
__VERSION__ = '1.0.4'
1616

1717
null = None # Allow scripts to specify null in object definitions
1818

packages/openshift/context.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,6 @@
99

1010
from .result import Result
1111

12-
# All threads will have a context which is
13-
# managed by a stack of Context objects. As
14-
# a thread establish additional context using
15-
# 'with' statements, the stack will push/grow. As
16-
# 'with' blocks end, the stack will pop/shrink.
17-
context = local()
18-
19-
context.stack = []
20-
context.default_oc_path = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_OC_PATH", "oc") # Assume oc is in $PATH by default
21-
context.default_kubeconfig_path = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_CONFIG_PATH", None)
22-
context.default_api_server = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_API_SERVER", None)
23-
context.default_token = None # Does not support environment variable injection to discourage this insecure practice
24-
context.default_ca_cert_path = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_CA_CERT_PATH", None)
25-
context.default_project = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_PROJECT", None)
26-
context.default_options = {}
27-
context.default_loglevel = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_OC_LOGLEVEL", None)
28-
context.default_skip_tls_verify = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_SKIP_TLS_VERIFY", None)
29-
3012
# Provides defaults for ssh_client context instantiations
3113
DEFAULT_SSH_HOSTNAME = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_SSH_HOSTNAME", None)
3214
DEFAULT_SSH_USERNAME = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_SSH_USERNAME", None)
@@ -605,9 +587,29 @@ def timeout(seconds):
605587
return c
606588

607589

608-
root_context = Context()
609-
root_context.set_timeout(MASTER_TIMEOUT)
590+
class ThreadLocalContext(local):
591+
def __init__(self):
592+
self.default_oc_path = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_OC_PATH", "oc") # Assume oc is in $PATH by default
593+
self.default_kubeconfig_path = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_CONFIG_PATH", None)
594+
self.default_api_server = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_API_SERVER", None)
595+
self.default_token = None # Does not support environment variable injection to discourage this insecure practice
596+
self.default_ca_cert_path = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_CA_CERT_PATH", None)
597+
self.default_project = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_PROJECT", None)
598+
self.default_options = {}
599+
self.default_loglevel = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_OC_LOGLEVEL", None)
600+
self.default_skip_tls_verify = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_SKIP_TLS_VERIFY", None)
601+
602+
root_context = Context()
603+
root_context.set_timeout(MASTER_TIMEOUT)
610604

611-
# Ensure stack always has at least one member to simplify getting last
612-
# with [-1]
613-
context.stack = [root_context]
605+
# Ensure stack always has at least one member to simplify getting last
606+
# with [-1]
607+
self.stack = [root_context]
608+
609+
610+
# All threads will have a context which is
611+
# managed by a stack of Context objects. As
612+
# a thread establish additional context using
613+
# 'with' statements, the stack will push/grow. As
614+
# 'with' blocks end, the stack will pop/shrink.
615+
context = ThreadLocalContext()

0 commit comments

Comments
 (0)