Skip to content

Commit

Permalink
Added execute_and_expect + timer edit
Browse files Browse the repository at this point in the history
Added definition of Cli_execute_and_expect_cli task
Changed "wait-for-output-timer" parameter in execute_template from 25s to 5s

Signed-off-by: Matej Matkuliak <[email protected]>
  • Loading branch information
matkuliak authored and MartinSunal committed Apr 22, 2021
1 parent 23ed7e7 commit 3b5f9d6
Showing 1 changed file with 58 additions and 2 deletions.
60 changes: 58 additions & 2 deletions workers/cli_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def execute_mount_cli(task):
"input":
{
"command": "",
"wait-for-output-timer": "25"
"wait-for-output-timer": "5"
}
}

Expand Down Expand Up @@ -313,6 +313,36 @@ def execute_cli(task):
'response_body': response_json},
'logs': ["Unable to configure device with ID %s" % device_id]}

def execute_and_expect_cli(task):
device_id = task['inputData']['device_id']
template = task['inputData']['template']
params = task['inputData']['params'] if task['inputData']['params'] else {}
params = params if isinstance(params, dict) else eval(params)
uniconfig_tx_id = task['inputData']['uniconfig_tx_id'] if 'uniconfig_tx_id' in task["inputData"] else ""

commands = Template(template).substitute(params)
exec_body = copy.deepcopy(execute_template)

exec_body["input"]["command"] = commands

id_url = Template(uniconfig_url_cli_mount_rpc).substitute({"id": device_id}) + "/yang-ext:mount/cli-unit-generic:execute-and-expect"

r = requests.post(id_url, data=json.dumps(exec_body), headers=add_uniconfig_tx_cookie(uniconfig_tx_id), **additional_uniconfig_request_params)
response_code, response_json = parse_response(r)

if response_code == requests.codes.ok:
return {'status': 'COMPLETED', 'output': {'url': id_url,
'request_body': exec_body,
'response_code': response_code,
'response_body': response_json},
'logs': ["Mountpoint with ID %s configured" % device_id]}
else:
return {'status': 'FAILED', 'output': {'url': id_url,
'request_body': exec_body,
'response_code': response_code,
'response_body': response_json},
'logs': ["Unable to configure device with ID %s" % device_id]}


def start(cc):
print('Starting CLI workers')
Expand Down Expand Up @@ -528,4 +558,30 @@ def start(cc):
"response_body"
]
})
cc.start('CLI_execute_cli', execute_cli, False)
cc.start('CLI_execute_cli', execute_cli, False)


cc.register('CLI_execute_and_expect_cli', {
"name": "CLI_execute_and_expect_cli",
"description": "{\"description\": \"execute commands for a CLI device\", \"labels\": [\"BASICS\",\"CLI\"]}",
"retryCount": 0,
"ownerEmail":"[email protected]",
"timeoutSeconds": 60,
"timeoutPolicy": "TIME_OUT_WF",
"retryLogic": "FIXED",
"retryDelaySeconds": 0,
"responseTimeoutSeconds": 30,
"inputKeys": [
"device_id",
"template",
"params",
"uniconfig_tx_id"
],
"outputKeys": [
"url",
"request_body",
"response_code",
"response_body"
]
})
cc.start('CLI_execute_and_expect_cli', execute_and_expect_cli, False)

0 comments on commit 3b5f9d6

Please sign in to comment.