Skip to content

Commit 9ba7b4d

Browse files
committed
salt: Remove cri.execute salt module function
This salt execution module is not used so let's remove it
1 parent 96407f5 commit 9ba7b4d

File tree

2 files changed

+0
-76
lines changed

2 files changed

+0
-76
lines changed

salt/_modules/cri.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -99,48 +99,6 @@ def pull_image(image):
9999
return ret
100100

101101

102-
def execute(name, command, *args):
103-
"""
104-
Run a command in a container.
105-
106-
.. note::
107-
108-
This uses the :command:`crictl` command, which should be configured
109-
correctly on the system, e.g. in :file:`/etc/crictl.yaml`.
110-
111-
name
112-
Name of the target container
113-
command
114-
Command to run
115-
args
116-
Command parameters
117-
"""
118-
log.info('Retrieving ID of container "%s"', name)
119-
out = __salt__["cmd.run_all"](
120-
f'crictl ps -q --label io.kubernetes.container.name="{name}"'
121-
)
122-
123-
if out["retcode"] != 0:
124-
log.error('Failed to find container "%s"', name)
125-
return None
126-
127-
container_id = out["stdout"]
128-
if not container_id:
129-
log.error('Container "%s" does not exists', name)
130-
return None
131-
132-
cmd_opts = f"{command} {' '.join(args)}"
133-
134-
log.info('Executing command "%s"', cmd_opts)
135-
out = __salt__["cmd.run_all"](f"crictl exec {container_id} {cmd_opts}")
136-
137-
if out["retcode"] != 0:
138-
log.error('Failed run command "%s"', cmd_opts)
139-
return None
140-
141-
return out["stdout"]
142-
143-
144102
def wait_container(name, state, timeout=60, delay=5):
145103
"""
146104
Wait for a container to be in given state.

salt/tests/unit/modules/test_cri.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -157,40 +157,6 @@ def test_pull_image(self, retcode, stdout, result):
157157
self.assertEqual(cri.pull_image("my-images"), result)
158158
mock_cmd.assert_called_once_with('crictl pull "my-images"')
159159

160-
@parameterized.expand(
161-
[
162-
(0, "292c3b07b", 0, "All ok", "All ok"),
163-
(1, "292c3b07b", 0, "All ok", None),
164-
(0, "", 0, "All ok", None),
165-
(0, "292c3b07b", 1, "All not ok", None),
166-
(0, "292c3b07b", 0, "", ""),
167-
]
168-
)
169-
def test_execute(self, ret_ps, stdout_ps, ret_exec, stdout_exec, result):
170-
"""
171-
Tests the return of `execute` function
172-
"""
173-
cmd_ps = utils.cmd_output(retcode=ret_ps, stdout=stdout_ps)
174-
cmd_exec = utils.cmd_output(retcode=ret_exec, stdout=stdout_exec)
175-
176-
def _cmd_run_all_mock(cmd):
177-
if "crictl ps" in cmd:
178-
return cmd_ps
179-
elif "crictl exec" in cmd:
180-
return cmd_exec
181-
return None
182-
183-
mock_cmd = MagicMock(side_effect=_cmd_run_all_mock)
184-
with patch.dict(cri.__salt__, {"cmd.run_all": mock_cmd}):
185-
self.assertEqual(cri.execute("my_cont", "my command"), result)
186-
mock_cmd.assert_any_call(
187-
'crictl ps -q --label io.kubernetes.container.name="my_cont"'
188-
)
189-
if ret_ps == 0 and stdout_ps:
190-
mock_cmd.assert_called_with(
191-
"crictl exec {} my command ".format(stdout_ps)
192-
)
193-
194160
@parameterized.expand(
195161
[
196162
# Success: Found one container

0 commit comments

Comments
 (0)