Skip to content

Commit

Permalink
Merge "[DM] Concurrent execution of multi-device playbooks"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul v3 CI authored and opencontrail-ci-admin committed Jul 13, 2018
2 parents a70fd60 + 9f5ca47 commit 0ec0b6d
Show file tree
Hide file tree
Showing 15 changed files with 348 additions and 55 deletions.
Expand Up @@ -24,7 +24,10 @@
status: "{{ JOBLOG_STATUS.IN_PROGRESS }}"
message: "Successfully deleted fabric: {{ playbook_input.input.fabric_fq_name }}"

- name: print marked output
debug:
msg: "{{PB_OUTPUT_MARKER}}{{output}}{{PB_OUTPUT_MARKER}}"
verbosity: 0
- name: insert/update in /tmp/<exec-id> file
set_fact:
write_resp: "{{job_ctx | report_pb_output(output)}}"

- name: insert/update in /tmp/<exec-id> file
set_fact:
write_resp: "{{job_ctx | report_end_of_playbook()}}"
Expand Up @@ -30,4 +30,6 @@
status: "{{ JOBLOG_STATUS.IN_PROGRESS }}"
message: "Import Device: {{prouter_name}} succeeded importing {{bulk_create_phy_int_resp_set|length}} PhysicalInterfaces and {{bulk_create_log_int_resp_set|length}} Logical Interfaces"


- name: insert/update in /tmp/<exec-id> file
set_fact:
write_resp: "{{job_ctx | report_end_of_playbook()}}"
Expand Up @@ -37,3 +37,7 @@

- name: print output
debug: var=output verbosity=1

- name: insert/update in /tmp/<exec-id> file
set_fact:
write_resp: "{{job_ctx | report_end_of_playbook()}}"
Expand Up @@ -17,4 +17,8 @@
include_tasks: percentage_update.yml
vars:
current_index: 2
jl_message: "Role Discovery succeeded discovering roles for the prouter {{prouter_name}} in the fabric"
jl_message: "Role Discovery succeeded discovering roles for the prouter {{prouter_name}} in the fabric"

- name: insert/update in /tmp/<exec-id> file
set_fact:
write_resp: "{{job_ctx | report_end_of_playbook()}}"
Expand Up @@ -30,7 +30,10 @@
pb_output:
fabric_uuid: "{{output.fabric_uuid}}"

- name: print marked output
debug:
msg: "{{PB_OUTPUT_MARKER}}{{pb_output}}{{PB_OUTPUT_MARKER}}"
verbosity: 0
- name: insert/update in /tmp/<exec-id> file
set_fact:
write_resp: "{{job_ctx | report_pb_output(pb_output)}}"

- name: insert/update in /tmp/<exec-id> file
set_fact:
write_resp: "{{job_ctx | report_end_of_playbook()}}"
11 changes: 7 additions & 4 deletions src/config/fabric-ansible/ansible-playbooks/fabric_onboard.yml
Expand Up @@ -30,7 +30,10 @@
pb_output:
fabric_uuid: "{{output.fabric_uuid}}"

- name: print marked output
debug:
msg: "{{PB_OUTPUT_MARKER}}{{pb_output}}{{PB_OUTPUT_MARKER}}"
verbosity: 0
- name: insert/update in /tmp/<exec-id> file
set_fact:
write_resp: "{{job_ctx | report_pb_output(pb_output)}}"

- name: insert/update in /tmp/<exec-id> file
set_fact:
write_resp: "{{job_ctx | report_end_of_playbook()}}"
@@ -0,0 +1,188 @@
#!/usr/bin/python
import logging
import argparse
import traceback
import sys
import json


class FilterModule(object):
@staticmethod
def _init_logging():
logger = logging.getLogger('WriteToFileFilter')
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)

formatter = logging.Formatter(
'%(asctime)s %(levelname)-8s %(message)s',
datefmt='%Y/%m/%d %H:%M:%S'
)
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)

return logger
# end _init_logging

def __init__(self):
self._logger = FilterModule._init_logging()
# end __init__

def filters(self):
return {
'report_percentage_completion': self.report_percentage_completion,
'report_device_info': self.report_device_info,
'report_pb_output': self.report_pb_output,
'report_end_of_playbook': self.report_end_of_playbook,
}

def get_job_ctx_details(self, job_ctx):
return job_ctx.get('job_execution_id'),job_ctx.get('unique_pb_id')

def report_percentage_completion(self, job_ctx, percentage):
exec_id, unique_pb_id = self.get_job_ctx_details(job_ctx)
write_to_file_log = "\n"
try:
write_to_file_log = "Attempting to create or open file.. \n"
with open("/tmp/"+exec_id, "a") as f:
write_to_file_log += "Opened file in /tmp ... \n"
percentage_data = {'percent_complete': percentage}
line_in_file = unique_pb_id + 'JOB_PROGRESS##' +\
json.dumps(percentage_data) + 'JOB_PROGRESS##'
f.write(line_in_file + '\n')
write_to_file_log += "Written line %s to the /tmp/exec-id" \
" file \n" % line_in_file
return {
'status': 'success',
'write_to_file_log': write_to_file_log
}
except Exception as ex:
self._logger.info(write_to_file_log)
self._logger.error(str(ex))
traceback.print_exc(file=sys.stdout)
return {
'status': 'failure',
'error_msg': str(ex),
'write_to_file_log': write_to_file_log
}

def report_pb_output(self, job_ctx, pb_output):
exec_id, unique_pb_id = self.get_job_ctx_details(job_ctx)
write_to_file_log = "\n"
try:
write_to_file_log = "Attempting to create or open file.. \n"
with open("/tmp/"+exec_id, "a") as f:
write_to_file_log += "Opened file in /tmp ... \n"
line_in_file = unique_pb_id + 'PLAYBOOK_OUTPUT##' +\
json.dumps(pb_output) + 'PLAYBOOK_OUTPUT##'
f.write(line_in_file + '\n')
write_to_file_log += "Written line %s to the /tmp/exec-id" \
" file \n" % line_in_file
return {
'status': 'success',
'write_to_file_log': write_to_file_log
}
except Exception as ex:
self._logger.info(write_to_file_log)
self._logger.error(str(ex))
traceback.print_exc(file=sys.stdout)
return {
'status': 'failure',
'error_msg': str(ex),
'write_to_file_log': write_to_file_log
}

def report_end_of_playbook(self, job_ctx):
exec_id, unique_pb_id = self.get_job_ctx_details(job_ctx)
write_to_file_log = "\n"
try:
write_to_file_log = "Attempting to create or open file.. \n"
with open("/tmp/"+exec_id, "a") as f:
write_to_file_log += "Opened file in /tmp ... \n"
line_in_file = unique_pb_id + 'END'
f.write(line_in_file + '\n')
write_to_file_log += "Written line %s to the /tmp/exec-id" \
" file \n" % line_in_file
return {
'status': 'success',
'write_to_file_log': write_to_file_log
}
except Exception as ex:
self._logger.info(write_to_file_log)
self._logger.error(str(ex))
traceback.print_exc(file=sys.stdout)
return {
'status': 'failure',
'error_msg': str(ex),
'write_to_file_log': write_to_file_log
}

def report_device_info(self, job_ctx, device_data):
exec_id, unique_pb_id = self.get_job_ctx_details(job_ctx)
write_to_file_log = "\n"
try:
write_to_file_log = "Attempting to create or open file.. \n"
with open("/tmp/"+exec_id, "a") as f:
write_to_file_log += "Opened file in /tmp ... \n"
line_in_file = unique_pb_id + 'DEVICEDATA##' +\
json.dumps(device_data) + 'DEVICEDATA##'
f.write(line_in_file + '\n')
write_to_file_log += "Written line %s to the /tmp/exec-id" \
" file \n" % line_in_file
return {
'status': 'success',
'write_to_file_log': write_to_file_log
}
except Exception as ex:
self._logger.info(write_to_file_log)
self._logger.error(str(ex))
traceback.print_exc(file=sys.stdout)
return {
'status': 'failure',
'error_msg': str(ex),
'write_to_file_log': write_to_file_log
}


def _parse_args():
parser = argparse.ArgumentParser(description='fabric filters tests')
parser.add_argument('-pc', '--percentage_complete',
action='store_true',
help='write percentage completion to file')
parser.add_argument('-po', '--playbook_output',
action='store_true',
help='write playbook_output to file')
parser.add_argument('-e', '--mark_end',
action='store_true',
help='write playbook end to file')
parser.add_argument('-dd', '--device_data',
action='store_true',
help='write device info to file')
return parser.parse_args()
# end _parse_args


if __name__ == '__main__':

results = None
fabric_filter = FilterModule()
parser = _parse_args()
if parser.percentage_complete:
results = fabric_filter.report_percentage_completion(
"sample_exec_id_filename",
"sample_unique_pb_id",
10)
elif parser.playbook_output:
results = fabric_filter.report_pb_output(
"sample_exec_id_filename",
"sample_unique_pb_id",
{"pb_op": "sample pb_op"})
elif parser.mark_end:
results = fabric_filter.report_end_of_playbook(
"sample_exec_id_filename",
"sample_unique_pb_id")
elif parser.device_data:
results = fabric_filter.report_device_info(
"sample_exec_id_filename",
"sample_unique_pb_id",
{"dd": "sample device_info"})
print results
Expand Up @@ -22,6 +22,9 @@ job_ctx:
job_input: "{{ playbook_input.input }}"
auth_token: "{{ playbook_input.auth_token }}"
playbook_job_percentage: "{{ playbook_input.playbook_job_percentage}}"
# This is used to demarcate the marked outputs from playbooks to the common
# file
unique_pb_id: "{{ playbook_input.unique_pb_id }}"
# This is used in the job percentage calculations. Dataype is an int
# Example: For the first task in image upgrade - dowloading the image
# the current_task_index will be 1. Note: The first task index always needs
Expand Down Expand Up @@ -85,8 +88,3 @@ TFTP_BOOT_PATH: "/var/lib/docker/volumes/ironic_pxe/_data"
# DHCP and TFTP servers
DHCP_SERVER: "localhost"
TFTP_SERVER: "localhost"

# MARKERS
JOB_PROGRESS_MARKER: "JOB_PROGRESS##"
DEVICE_DATA_MARKER: "DEVICEDATA##"
PB_OUTPUT_MARKER: "PLAYBOOK_OUTPUT##"
Expand Up @@ -8,7 +8,6 @@
message: "{{ jl_message }}"
register: jl_output

- name: print percentage data
debug:
msg: "{{JOB_PROGRESS_MARKER}}{{jl_output.percentage_completed}}{{JOB_PROGRESS_MARKER}}"
verbosity: 0
- name: insert/update in /tmp/<exec-id> file
set_fact:
write_resp: "{{job_ctx | report_percentage_completion(jl_output.percentage_completed)}}"
11 changes: 7 additions & 4 deletions src/config/fabric-ansible/ansible-playbooks/role_assignment.yml
Expand Up @@ -23,7 +23,10 @@
status: "{{ JOBLOG_STATUS.IN_PROGRESS }}"
message: "Successfully assigned roles to devices"

- name: print marked output
debug:
msg: "{{PB_OUTPUT_MARKER}}{{output}}{{PB_OUTPUT_MARKER}}"
verbosity: 0
- name: insert/update in /tmp/<exec-id> file
set_fact:
write_resp: "{{job_ctx | report_pb_output(output)}}"

- name: insert/update in /tmp/<exec-id> file
set_fact:
write_resp: "{{job_ctx | report_end_of_playbook()}}"
Expand Up @@ -12,7 +12,6 @@
total_retry_timeout: 0
register: discovery_results

- name: print marked output
debug:
msg: "{{DEVICE_DATA_MARKER}}{{discovery_results.device_info}}{{DEVICE_DATA_MARKER}}"
verbosity: 0
- name: insert/update in /tmp/<exec-id> file
set_fact:
write_resp: "{{job_ctx | report_device_info(discovery_results.device_info)}}"
Expand Up @@ -11,7 +11,6 @@
total_retry_timeout: "{{ TOTAL_RETRY_TIMEOUT }}"
register: discovery_results

- name: print marked output
debug:
msg: "{{DEVICE_DATA_MARKER}}{{discovery_results.device_info}}{{DEVICE_DATA_MARKER}}"
verbosity: 0
- name: insert/update in /tmp/<exec-id> file
set_fact:
write_resp: "{{job_ctx | report_device_info(discovery_results.device_info)}}"
Expand Up @@ -18,3 +18,7 @@
vars:
current_index: 4
jl_message: "Topology Discovery: {{prouter_name}} succeeded discovering topology"

- name: insert/update in /tmp/<exec-id> file
set_fact:
write_resp: "{{job_ctx | report_end_of_playbook()}}"
11 changes: 7 additions & 4 deletions src/config/fabric-ansible/ansible-playbooks/ztp.yml
Expand Up @@ -90,7 +90,10 @@
status: "{{ JOBLOG_STATUS.IN_PROGRESS }}"
message: "{{ output.results.jl_message if output.status == 'Failure' else 'Finished ZTP'}}"

- name: print marked output
debug:
msg: "{{PB_OUTPUT_MARKER}}{{output}}{{PB_OUTPUT_MARKER}}"
verbosity: 0
- name: insert/update in /tmp/<exec-id> file
set_fact:
write_resp: "{{job_ctx | report_pb_output(output)}}"

- name: insert/update in /tmp/<exec-id> file
set_fact:
write_resp: "{{job_ctx | report_end_of_playbook()}}"

0 comments on commit 0ec0b6d

Please sign in to comment.