* Revert "nxos_command:run_commands results failure when commands array size >1 (#52670)"
This reverts commit 0df5b92af37d43da20125dc418f1cb92390a8a25.
* Revert "added timestamps to nxos_command module (#50261)"
This reverts commit e1509433144572e5010d0ced72a2129600dd8bd4.
* Revert "added timestamps to ios_command module (#50323)"
This reverts commit 2a432a093b392e3f8babea6b760df6a5c8716b03.
* Revert "added response_timestamps to iosxr_command module (#50095)"
This reverts commit 2a0c356da9d18a98399f2802ea8a52eb421f87ac.
(cherry picked from commit 2e8a3efccb8f90ae03e61e3b08d238790fb50658)
... | ... |
@@ -129,10 +129,10 @@ def get_config(module, flags=None): |
129 | 129 |
return cfg |
130 | 130 |
|
131 | 131 |
|
132 |
-def run_commands(module, commands, check_rc=True, return_timestamps=False): |
|
132 |
+def run_commands(module, commands, check_rc=True): |
|
133 | 133 |
connection = get_connection(module) |
134 | 134 |
try: |
135 |
- return connection.run_commands(commands=commands, check_rc=check_rc, return_timestamps=return_timestamps) |
|
135 |
+ return connection.run_commands(commands=commands, check_rc=check_rc) |
|
136 | 136 |
except ConnectionError as exc: |
137 | 137 |
module.fail_json(msg=to_text(exc)) |
138 | 138 |
|
... | ... |
@@ -477,10 +477,10 @@ def load_config(module, command_filter, commit=False, replace=False, |
477 | 477 |
return diff |
478 | 478 |
|
479 | 479 |
|
480 |
-def run_commands(module, commands, check_rc=True, return_timestamps=False): |
|
480 |
+def run_commands(module, commands, check_rc=True): |
|
481 | 481 |
connection = get_connection(module) |
482 | 482 |
try: |
483 |
- return connection.run_commands(commands=commands, check_rc=check_rc, return_timestamps=return_timestamps) |
|
483 |
+ return connection.run_commands(commands=commands, check_rc=check_rc) |
|
484 | 484 |
except ConnectionError as exc: |
485 | 485 |
module.fail_json(msg=to_text(exc)) |
486 | 486 |
|
... | ... |
@@ -33,7 +33,7 @@ import json |
33 | 33 |
import re |
34 | 34 |
|
35 | 35 |
from ansible.module_utils._text import to_text |
36 |
-from ansible.module_utils.basic import env_fallback, get_timestamp |
|
36 |
+from ansible.module_utils.basic import env_fallback |
|
37 | 37 |
from ansible.module_utils.network.common.utils import to_list, ComplexList |
38 | 38 |
from ansible.module_utils.connection import Connection, ConnectionError |
39 | 39 |
from ansible.module_utils.common._collections_compat import Mapping |
... | ... |
@@ -154,13 +154,13 @@ class Cli: |
154 | 154 |
self._device_configs[cmd] = cfg |
155 | 155 |
return cfg |
156 | 156 |
|
157 |
- def run_commands(self, commands, check_rc=True, return_timestamps=False): |
|
157 |
+ def run_commands(self, commands, check_rc=True): |
|
158 | 158 |
"""Run list of commands on remote device and return results |
159 | 159 |
""" |
160 | 160 |
connection = self._get_connection() |
161 | 161 |
|
162 | 162 |
try: |
163 |
- out, timestamps = connection.run_commands(commands, check_rc) |
|
163 |
+ out = connection.run_commands(commands, check_rc) |
|
164 | 164 |
if check_rc == 'retry_json': |
165 | 165 |
capabilities = self.get_capabilities() |
166 | 166 |
network_api = capabilities.get('network_api') |
... | ... |
@@ -170,11 +170,8 @@ class Cli: |
170 | 170 |
if ('Invalid command at' in resp or 'Ambiguous command at' in resp) and 'json' in resp: |
171 | 171 |
if commands[index]['output'] == 'json': |
172 | 172 |
commands[index]['output'] = 'text' |
173 |
- out, timestamps = connection.run_commands(commands, check_rc) |
|
174 |
- if return_timestamps: |
|
175 |
- return out, timestamps |
|
176 |
- else: |
|
177 |
- return out |
|
173 |
+ out = connection.run_commands(commands, check_rc) |
|
174 |
+ return out |
|
178 | 175 |
except ConnectionError as exc: |
179 | 176 |
self._module.fail_json(msg=to_text(exc)) |
180 | 177 |
|
... | ... |
@@ -344,7 +341,6 @@ class LocalNxapi: |
344 | 344 |
|
345 | 345 |
headers = {'Content-Type': 'application/json'} |
346 | 346 |
result = list() |
347 |
- timestamps = list() |
|
348 | 347 |
timeout = self._module.params['timeout'] |
349 | 348 |
use_proxy = self._module.params['provider']['use_proxy'] |
350 | 349 |
|
... | ... |
@@ -352,7 +348,6 @@ class LocalNxapi: |
352 | 352 |
if self._nxapi_auth: |
353 | 353 |
headers['Cookie'] = self._nxapi_auth |
354 | 354 |
|
355 |
- timestamp = get_timestamp() |
|
356 | 355 |
response, headers = fetch_url( |
357 | 356 |
self._module, self._url, data=req, headers=headers, |
358 | 357 |
timeout=timeout, method='POST', use_proxy=use_proxy |
... | ... |
@@ -380,13 +375,12 @@ class LocalNxapi: |
380 | 380 |
self._error(output=output, **item) |
381 | 381 |
elif 'body' in item: |
382 | 382 |
result.append(item['body']) |
383 |
- timestamps.append(timestamp) |
|
384 | 383 |
# else: |
385 | 384 |
# error in command but since check_status is disabled |
386 | 385 |
# silently drop it. |
387 | 386 |
# result.append(item['msg']) |
388 | 387 |
|
389 |
- return result, timestamps |
|
388 |
+ return result |
|
390 | 389 |
|
391 | 390 |
def get_config(self, flags=None): |
392 | 391 |
"""Retrieves the current config from the device or cache |
... | ... |
@@ -400,18 +394,17 @@ class LocalNxapi: |
400 | 400 |
try: |
401 | 401 |
return self._device_configs[cmd] |
402 | 402 |
except KeyError: |
403 |
- out, out_timestamps = self.send_request(cmd) |
|
403 |
+ out = self.send_request(cmd) |
|
404 | 404 |
cfg = str(out[0]).strip() |
405 | 405 |
self._device_configs[cmd] = cfg |
406 | 406 |
return cfg |
407 | 407 |
|
408 |
- def run_commands(self, commands, check_rc=True, return_timestamps=False): |
|
408 |
+ def run_commands(self, commands, check_rc=True): |
|
409 | 409 |
"""Run list of commands on remote device and return results |
410 | 410 |
""" |
411 | 411 |
output = None |
412 | 412 |
queue = list() |
413 | 413 |
responses = list() |
414 |
- timestamps = list() |
|
415 | 414 |
|
416 | 415 |
def _send(commands, output): |
417 | 416 |
return self.send_request(commands, output, check_status=check_rc) |
... | ... |
@@ -422,23 +415,16 @@ class LocalNxapi: |
422 | 422 |
item['output'] = 'json' |
423 | 423 |
|
424 | 424 |
if all((output == 'json', item['output'] == 'text')) or all((output == 'text', item['output'] == 'json')): |
425 |
- out, out_timestamps = _send(queue, output) |
|
426 |
- responses.extend(out) |
|
427 |
- timestamps.extend(out_timestamps) |
|
425 |
+ responses.extend(_send(queue, output)) |
|
428 | 426 |
queue = list() |
429 | 427 |
|
430 | 428 |
output = item['output'] or 'json' |
431 | 429 |
queue.append(item['command']) |
432 | 430 |
|
433 | 431 |
if queue: |
434 |
- out, out_timestamps = _send(queue, output) |
|
435 |
- responses.extend(out) |
|
436 |
- timestamps.extend(out_timestamps) |
|
432 |
+ responses.extend(_send(queue, output)) |
|
437 | 433 |
|
438 |
- if return_timestamps: |
|
439 |
- return responses, timestamps |
|
440 |
- else: |
|
441 |
- return responses |
|
434 |
+ return responses |
|
442 | 435 |
|
443 | 436 |
def load_config(self, commands, return_error=False, opts=None, replace=None): |
444 | 437 |
"""Sends the ordered set of commands to the device |
... | ... |
@@ -450,8 +436,8 @@ class LocalNxapi: |
450 | 450 |
commands = 'config replace {0}'.format(replace) |
451 | 451 |
|
452 | 452 |
commands = to_list(commands) |
453 |
- msg, msg_timestamps = self.send_request(commands, output='config', check_status=True, |
|
454 |
- return_error=return_error, opts=opts) |
|
453 |
+ msg = self.send_request(commands, output='config', check_status=True, |
|
454 |
+ return_error=return_error, opts=opts) |
|
455 | 455 |
if return_error: |
456 | 456 |
return msg |
457 | 457 |
else: |
... | ... |
@@ -530,7 +516,7 @@ class HttpApi: |
530 | 530 |
|
531 | 531 |
return self._connection_obj |
532 | 532 |
|
533 |
- def run_commands(self, commands, check_rc=True, return_timestamps=False): |
|
533 |
+ def run_commands(self, commands, check_rc=True): |
|
534 | 534 |
"""Runs list of commands on remote device and returns results |
535 | 535 |
""" |
536 | 536 |
try: |
... | ... |
@@ -548,11 +534,7 @@ class HttpApi: |
548 | 548 |
if response[0] == '{': |
549 | 549 |
out[index] = json.loads(response) |
550 | 550 |
|
551 |
- if return_timestamps: |
|
552 |
- # workaround until timestamps are implemented |
|
553 |
- return out, list() |
|
554 |
- else: |
|
555 |
- return out |
|
551 |
+ return out |
|
556 | 552 |
|
557 | 553 |
def get_config(self, flags=None): |
558 | 554 |
"""Retrieves the current config from the device or cache |
... | ... |
@@ -726,9 +708,9 @@ def get_config(module, flags=None): |
726 | 726 |
return conn.get_config(flags=flags) |
727 | 727 |
|
728 | 728 |
|
729 |
-def run_commands(module, commands, check_rc=True, return_timestamps=False): |
|
729 |
+def run_commands(module, commands, check_rc=True): |
|
730 | 730 |
conn = get_connection(module) |
731 |
- return conn.run_commands(to_command(module, commands), check_rc, return_timestamps) |
|
731 |
+ return conn.run_commands(to_command(module, commands), check_rc) |
|
732 | 732 |
|
733 | 733 |
|
734 | 734 |
def load_config(module, config, return_error=False, opts=None, replace=None): |
... | ... |
@@ -198,7 +198,7 @@ def main(): |
198 | 198 |
match = module.params['match'] |
199 | 199 |
|
200 | 200 |
while retries > 0: |
201 |
- responses, timestamps = run_commands(module, commands, return_timestamps=True) |
|
201 |
+ responses = run_commands(module, commands) |
|
202 | 202 |
|
203 | 203 |
for item in list(conditionals): |
204 | 204 |
if item(responses): |
... | ... |
@@ -221,7 +221,6 @@ def main(): |
221 | 221 |
result.update({ |
222 | 222 |
'stdout': responses, |
223 | 223 |
'stdout_lines': list(to_lines(responses)), |
224 |
- 'timestamps': timestamps |
|
225 | 224 |
}) |
226 | 225 |
|
227 | 226 |
module.exit_json(**result) |
... | ... |
@@ -178,7 +178,7 @@ def main(): |
178 | 178 |
match = module.params['match'] |
179 | 179 |
|
180 | 180 |
while retries > 0: |
181 |
- responses, timestamps = run_commands(module, commands, return_timestamps=True) |
|
181 |
+ responses = run_commands(module, commands) |
|
182 | 182 |
|
183 | 183 |
for item in list(conditionals): |
184 | 184 |
if item(responses): |
... | ... |
@@ -201,7 +201,6 @@ def main(): |
201 | 201 |
result.update({ |
202 | 202 |
'stdout': responses, |
203 | 203 |
'stdout_lines': list(to_lines(responses)), |
204 |
- 'timestamps': timestamps |
|
205 | 204 |
}) |
206 | 205 |
|
207 | 206 |
module.exit_json(**result) |
... | ... |
@@ -188,7 +188,8 @@ def main(): |
188 | 188 |
match = module.params['match'] |
189 | 189 |
|
190 | 190 |
while retries > 0: |
191 |
- responses, timestamps = run_commands(module, commands, return_timestamps=True) |
|
191 |
+ responses = run_commands(module, commands) |
|
192 |
+ |
|
192 | 193 |
for item in list(conditionals): |
193 | 194 |
try: |
194 | 195 |
if item(responses): |
... | ... |
@@ -213,7 +214,6 @@ def main(): |
213 | 213 |
result.update({ |
214 | 214 |
'stdout': responses, |
215 | 215 |
'stdout_lines': list(to_lines(responses)), |
216 |
- 'timestamps': timestamps |
|
217 | 216 |
}) |
218 | 217 |
|
219 | 218 |
module.exit_json(**result) |
... | ... |
@@ -38,7 +38,6 @@ from itertools import chain |
38 | 38 |
|
39 | 39 |
from ansible.errors import AnsibleConnectionFailure |
40 | 40 |
from ansible.module_utils._text import to_text |
41 |
-from ansible.module_utils.basic import get_timestamp |
|
42 | 41 |
from ansible.module_utils.common._collections_compat import Mapping |
43 | 42 |
from ansible.module_utils.six import iteritems |
44 | 43 |
from ansible.module_utils.network.common.config import NetworkConfig, dumps |
... | ... |
@@ -287,12 +286,11 @@ class Cliconf(CliconfBase): |
287 | 287 |
|
288 | 288 |
return resp |
289 | 289 |
|
290 |
- def run_commands(self, commands=None, check_rc=True, return_timestamps=False): |
|
290 |
+ def run_commands(self, commands=None, check_rc=True): |
|
291 | 291 |
if commands is None: |
292 | 292 |
raise ValueError("'commands' value is required") |
293 | 293 |
|
294 | 294 |
responses = list() |
295 |
- timestamps = list() |
|
296 | 295 |
for cmd in to_list(commands): |
297 | 296 |
if not isinstance(cmd, Mapping): |
298 | 297 |
cmd = {'command': cmd} |
... | ... |
@@ -303,19 +301,14 @@ class Cliconf(CliconfBase): |
303 | 303 |
|
304 | 304 |
try: |
305 | 305 |
out = self.send_command(**cmd) |
306 |
- timestamp = get_timestamp() |
|
307 | 306 |
except AnsibleConnectionFailure as e: |
308 | 307 |
if check_rc: |
309 | 308 |
raise |
310 | 309 |
out = getattr(e, 'err', to_text(e)) |
311 | 310 |
|
312 | 311 |
responses.append(out) |
313 |
- timestamps.append(timestamp) |
|
314 | 312 |
|
315 |
- if return_timestamps: |
|
316 |
- return responses, timestamps |
|
317 |
- else: |
|
318 |
- return responses |
|
313 |
+ return responses |
|
319 | 314 |
|
320 | 315 |
def get_defaults_flag(self): |
321 | 316 |
""" |
... | ... |
@@ -35,7 +35,6 @@ import json |
35 | 35 |
|
36 | 36 |
from ansible.errors import AnsibleConnectionFailure |
37 | 37 |
from ansible.module_utils._text import to_text |
38 |
-from ansible.module_utils.basic import get_timestamp |
|
39 | 38 |
from ansible.module_utils.common._collections_compat import Mapping |
40 | 39 |
from ansible.module_utils.connection import ConnectionError |
41 | 40 |
from ansible.module_utils.network.common.config import NetworkConfig, dumps |
... | ... |
@@ -184,11 +183,10 @@ class Cliconf(CliconfBase): |
184 | 184 |
|
185 | 185 |
self.send_command(**cmd_obj) |
186 | 186 |
|
187 |
- def run_commands(self, commands=None, check_rc=True, return_timestamps=False): |
|
187 |
+ def run_commands(self, commands=None, check_rc=True): |
|
188 | 188 |
if commands is None: |
189 | 189 |
raise ValueError("'commands' value is required") |
190 | 190 |
responses = list() |
191 |
- timestamps = list() |
|
192 | 191 |
for cmd in to_list(commands): |
193 | 192 |
if not isinstance(cmd, Mapping): |
194 | 193 |
cmd = {'command': cmd} |
... | ... |
@@ -198,7 +196,6 @@ class Cliconf(CliconfBase): |
198 | 198 |
raise ValueError("'output' value %s is not supported for run_commands" % output) |
199 | 199 |
|
200 | 200 |
try: |
201 |
- timestamp = get_timestamp() |
|
202 | 201 |
out = self.send_command(**cmd) |
203 | 202 |
except AnsibleConnectionFailure as e: |
204 | 203 |
if check_rc: |
... | ... |
@@ -217,11 +214,7 @@ class Cliconf(CliconfBase): |
217 | 217 |
pass |
218 | 218 |
|
219 | 219 |
responses.append(out) |
220 |
- timestamps.append(timestamp) |
|
221 |
- if return_timestamps: |
|
222 |
- return responses, timestamps |
|
223 |
- else: |
|
224 |
- return responses |
|
220 |
+ return responses |
|
225 | 221 |
|
226 | 222 |
def discard_changes(self): |
227 | 223 |
self.send_command('abort') |
... | ... |
@@ -34,7 +34,6 @@ import json |
34 | 34 |
import re |
35 | 35 |
|
36 | 36 |
from ansible.errors import AnsibleConnectionFailure |
37 |
-from ansible.module_utils.basic import get_timestamp |
|
38 | 37 |
from ansible.module_utils._text import to_bytes, to_text |
39 | 38 |
from ansible.module_utils.common._collections_compat import Mapping |
40 | 39 |
from ansible.module_utils.connection import ConnectionError |
... | ... |
@@ -199,7 +198,6 @@ class Cliconf(CliconfBase): |
199 | 199 |
raise ValueError("'commands' value is required") |
200 | 200 |
|
201 | 201 |
responses = list() |
202 |
- timestamps = list() |
|
203 | 202 |
for cmd in to_list(commands): |
204 | 203 |
if not isinstance(cmd, Mapping): |
205 | 204 |
cmd = {'command': cmd} |
... | ... |
@@ -209,7 +207,6 @@ class Cliconf(CliconfBase): |
209 | 209 |
cmd['command'] = self._get_command_with_output(cmd['command'], output) |
210 | 210 |
|
211 | 211 |
try: |
212 |
- timestamp = get_timestamp() |
|
213 | 212 |
out = self.send_command(**cmd) |
214 | 213 |
except AnsibleConnectionFailure as e: |
215 | 214 |
if check_rc is True: |
... | ... |
@@ -228,8 +225,7 @@ class Cliconf(CliconfBase): |
228 | 228 |
pass |
229 | 229 |
|
230 | 230 |
responses.append(out) |
231 |
- timestamps.append(timestamp) |
|
232 |
- return responses, timestamps |
|
231 |
+ return responses |
|
233 | 232 |
|
234 | 233 |
def get_device_operations(self): |
235 | 234 |
return { |
... | ... |
@@ -22,7 +22,6 @@ __metaclass__ = type |
22 | 22 |
import json |
23 | 23 |
|
24 | 24 |
from units.compat.mock import patch |
25 |
-from ansible.module_utils.basic import get_timestamp |
|
26 | 25 |
from ansible.modules.network.ios import ios_command |
27 | 26 |
from units.modules.utils import set_module_args |
28 | 27 |
from .ios_module import TestIosModule, load_fixture |
... | ... |
@@ -47,7 +46,6 @@ class TestIosCommandModule(TestIosModule): |
47 | 47 |
def load_from_file(*args, **kwargs): |
48 | 48 |
module, commands = args |
49 | 49 |
output = list() |
50 |
- timestamps = list() |
|
51 | 50 |
|
52 | 51 |
for item in commands: |
53 | 52 |
try: |
... | ... |
@@ -57,8 +55,7 @@ class TestIosCommandModule(TestIosModule): |
57 | 57 |
command = item['command'] |
58 | 58 |
filename = str(command).replace(' ', '_') |
59 | 59 |
output.append(load_fixture(filename)) |
60 |
- timestamps.append(get_timestamp()) |
|
61 |
- return output, timestamps |
|
60 |
+ return output |
|
62 | 61 |
|
63 | 62 |
self.run_commands.side_effect = load_from_file |
64 | 63 |
|
... | ... |
@@ -20,7 +20,6 @@ from __future__ import (absolute_import, division, print_function) |
20 | 20 |
__metaclass__ = type |
21 | 21 |
|
22 | 22 |
from units.compat.mock import patch |
23 |
-from ansible.module_utils.basic import get_timestamp |
|
24 | 23 |
from ansible.modules.network.iosxr import iosxr_command |
25 | 24 |
from units.modules.utils import set_module_args |
26 | 25 |
from .iosxr_module import TestIosxrModule, load_fixture |
... | ... |
@@ -46,7 +45,6 @@ class TestIosxrCommandModule(TestIosxrModule): |
46 | 46 |
def load_from_file(*args, **kwargs): |
47 | 47 |
module, commands = args |
48 | 48 |
output = list() |
49 |
- timestamps = list() |
|
50 | 49 |
|
51 | 50 |
for item in commands: |
52 | 51 |
try: |
... | ... |
@@ -55,8 +53,7 @@ class TestIosxrCommandModule(TestIosxrModule): |
55 | 55 |
command = item |
56 | 56 |
filename = str(command).replace(' ', '_') |
57 | 57 |
output.append(load_fixture(filename)) |
58 |
- timestamps.append(get_timestamp()) |
|
59 |
- return output, timestamps |
|
58 |
+ return output |
|
60 | 59 |
|
61 | 60 |
self.run_commands.side_effect = load_from_file |
62 | 61 |
|
... | ... |
@@ -22,7 +22,6 @@ __metaclass__ = type |
22 | 22 |
import json |
23 | 23 |
|
24 | 24 |
from units.compat.mock import patch |
25 |
-from ansible.module_utils.basic import get_timestamp |
|
26 | 25 |
from ansible.modules.network.nxos import nxos_command |
27 | 26 |
from .nxos_module import TestNxosModule, load_fixture, set_module_args |
28 | 27 |
|
... | ... |
@@ -45,7 +44,6 @@ class TestNxosCommandModule(TestNxosModule): |
45 | 45 |
def load_from_file(*args, **kwargs): |
46 | 46 |
module, commands = args |
47 | 47 |
output = list() |
48 |
- timestamps = list() |
|
49 | 48 |
|
50 | 49 |
for item in commands: |
51 | 50 |
try: |
... | ... |
@@ -55,8 +53,7 @@ class TestNxosCommandModule(TestNxosModule): |
55 | 55 |
command = item['command'] |
56 | 56 |
filename = '%s.txt' % str(command).replace(' ', '_') |
57 | 57 |
output.append(load_fixture('nxos_command', filename)) |
58 |
- timestamps.append(get_timestamp()) |
|
59 |
- return output, timestamps |
|
58 |
+ return output |
|
60 | 59 |
|
61 | 60 |
self.run_commands.side_effect = load_from_file |
62 | 61 |
|