Skip to content

Commit

Permalink
Add a conditional to handle any plugins infront of oc command
Browse files Browse the repository at this point in the history
Signed-off-by: Shylesh Kumar Mohan <[email protected]>
  • Loading branch information
shylesh committed Feb 1, 2024
1 parent 2105cbd commit 6c54763
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
30 changes: 22 additions & 8 deletions ocs_ci/utility/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,15 +624,29 @@ def exec_cmd(
log.info(f"Executing command: {masked_cmd}")
if isinstance(cmd, str) and not kwargs.get("shell"):
cmd = shlex.split(cmd)
if (
cluster_config
and cmd[0] == "oc"
and "--kubeconfig" not in cmd
#and config.multicluster
):
if cluster_config and cmd[0] == "oc" and "--kubeconfig" not in cmd:
kubepath = cluster_config.RUN["kubeconfig"]
cmd = list_insert_at_position(cmd, 1, ["--kubeconfig"])
cmd = list_insert_at_position(cmd, 2, [kubepath])
kube_index = 1
# check if we have an oc plugin in the command
plugin_list = "oc plugin list"
cp = subprocess.run(
shlex.split(plugin_list),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
subcmd = cmd[1].split("-")
if len(subcmd) > 1:
subcmd = "_".join(subcmd)
log.debug(f"searching for plugin: {subcmd}")

for l in cp.stdout.decode().splitlines():
if subcmd in l:
# If oc cmdline has plugin name then we need to push the
# --kubeconfig to next index
kube_index = 2
cmd = list_insert_at_position(cmd, kube_index, ["--kubeconfig"])
cmd = list_insert_at_position(cmd, kube_index + 1, [kubepath])
log.debug(f"Modified CMD = {cmd}")
if threading_lock and cmd[0] == "oc":
threading_lock.acquire()
completed_process = subprocess.run(
Expand Down
2 changes: 1 addition & 1 deletion src/ocp-network-split
Submodule ocp-network-split updated from 9c9a94 to d5ea5d

0 comments on commit 6c54763

Please sign in to comment.