Skip to content

Commit

Permalink
Merge "[fabric-ansible] role to feature mapping" into R5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vmahuli authored and opencontrail-ci-admin committed Aug 8, 2018
2 parents ba8f17f + 351a0d7 commit 9d61f18
Show file tree
Hide file tree
Showing 11 changed files with 352 additions and 61 deletions.
23 changes: 16 additions & 7 deletions src/config/fabric-ansible/ansible-playbooks/delete_fabric.yml
Expand Up @@ -13,14 +13,23 @@
set_fact:
output: "{{ job_ctx | delete_fabric }}"

- name: check failure
include_tasks: error_handler.yml
- block:
- set_fact:
op_err_message: "Failed to delete fabric due to error: {{ output.error_msg }}. Here is the deletion log: {{ output.deletion_log}}"
jl_err_message: "Failed to delete fabric due to error: {{ output.error_msg }}"

- name: Update job log with percentage
include_tasks: percentage_update.yml
vars:
current_index: 1
jl_message: "{{ jl_err_message }}"
results: {}

- pause: seconds=5

- name: handle failure
include_tasks: error_handler.yml
when: output.status == 'failure'
vars:
op_err_message: "Unable to delete fabric due to error"
jl_err_message: "Failed to delete fabric {{ playbook_input.input.fabric_fq_name }} due to error. Here is deletion log\n: {{ output.deletion_log }}"
results:
fabric_uuid: "{{ playbook_input.input.fabric_fq_name }}"

- name: Prepare to delete TFTP and DHCP config
block:
Expand Down
Expand Up @@ -16,19 +16,26 @@
set_fact:
output: "{{ job_ctx | delete_devices }}"

- debug: var=output
- block:
- set_fact:
op_err_message: "Failed to delete fabric devices due to error: {{ output.error_msg }}. Here is the deletion log: {{ output.deletion_log }}"
jl_err_message: "Failed to delete fabric devices due to error: {{ output.error_msg }}"
results: {}

- name: check failure
include_tasks: error_handler.yml
- name: Update job log with percentage
include_tasks: percentage_update.yml
vars:
current_index: 1
jl_message: "{{ jl_err_message }}"

- pause: seconds=5

- name: handle failure
include_tasks: error_handler.yml
when: output.status == 'failure'
vars:
op_err_message: "Unable to delete fabric due to error"
jl_err_message: "Failed to delete fabric {{ playbook_input.input.fabric_fq_name }} due to error. Here is deletion log\n: {{ output.deletion_log }}"
results:
fabric_uuid: "{{ playbook_input.input.fabric_fq_name }}"

- name: Update job log with percentage
include_tasks: percentage_update.yml
vars:
current_index: 2
jl_message: "Successfully deleted fabric: {{ playbook_input.input.fabric_fq_name }}"
jl_message: "Successfully deleted fabric devices"
Expand Up @@ -9,19 +9,26 @@
set_fact:
output: "{{ job_ctx | onboard_existing_fabric }}"

- debug: var=output
- block:
- set_fact:
op_err_message: "Failed to onboard existing fabric due to error: {{ output.error_msg }}. Here is the fabric onboard log: {{ output.onboard_log}}"
jl_err_message: "Failed to onboard existing fabric due to error: {{ output.error_msg }}"
results: {}

- name: check failure
include_tasks: error_handler.yml
- name: Update job log with percentage
include_tasks: percentage_update.yml
vars:
current_index: 1
jl_message: "{{ jl_err_message }}"

- pause: seconds=5

- name: handle failure
include_tasks: error_handler.yml
when: output.status == 'failure'
vars:
op_err_message: "Unable to onboard fabric due to error"
jl_err_message: "Failed to onboard fabric {{ playbook_input.input.fabric_fq_name }} due to error. Here is onboarding log\n: {{ output.onboard_log }}"
results:
fabric_uuid: "{{ output.fabric_uuid }}"

- name: Update Job log with fabric onboarding job status
job_objectlog:
job_ctx: "{{ job_ctx }}"
status: "{{ JOBLOG_STATUS.IN_PROGRESS }}"
message: "Successfully onboarded fabric: {{ playbook_input.input.fabric_fq_name }}"
jl_message: "Successfully onboarded fabric '{{ playbook_input.input.fabric_fq_name[-1] }}'"
3 changes: 3 additions & 0 deletions src/config/fabric-ansible/ansible-playbooks/fabric_config.yml
Expand Up @@ -10,9 +10,12 @@
device_name: "{{ device_info.name }}"
device_vendor: "{{ device_info.vendor_name|lower }}"
device_family: "{{ device_info.device_family|lower }}"
device_model: "{{ device_info.product_name }}"
device_username: "{{ device_info.credentials.user_name }}"
device_password: "{{ device_info.credentials.password }}"
device_mgmt_ip: "{{ device_info.management_ip }}"
device_phy_role: "{{ device_info.physical_role }}"
device_rb_roles: "{{ device_info.routing_bridging_roles if device_info.routing_bridging_roles is defined else [] }}"
output: {"status":"", "message":"", "results":""}

pre_tasks:
Expand Down
23 changes: 15 additions & 8 deletions src/config/fabric-ansible/ansible-playbooks/fabric_onboard.yml
Expand Up @@ -12,16 +12,23 @@
set_fact:
output: "{{ job_ctx | onboard_fabric }}"

- debug: var=output
- block:
- set_fact:
op_err_message: "Failed to onboard fabric due to error: {{ output.error_msg }}. Here is the fabric onboard log: {{ output.onboard_log}}"
jl_err_message: "Failed to onboard fabric due to error: {{ output.error_msg }}"
results: {}

- name: check failure
include_tasks: error_handler.yml
- name: Update job log with percentage
include_tasks: percentage_update.yml
vars:
current_index: 1
jl_message: "{{ jl_err_message }}"

- pause: seconds=5

- name: handle failure
include_tasks: error_handler.yml
when: output.status == 'failure'
vars:
op_err_message: "Unable to onboard fabric due to error"
jl_err_message: "Failed to onboard fabric {{ playbook_input.input.fabric_fq_name[-1] }} due to error. Here is onboarding log\n: {{ output.onboard_log }}"
results:
fabric_uuid: "{{ output.fabric_uuid }}"

- name: Update job log with percentage
include_tasks: percentage_update.yml
Expand Down
46 changes: 41 additions & 5 deletions src/config/fabric-ansible/ansible-playbooks/feature_config.yml
Expand Up @@ -3,11 +3,48 @@
- name: Initialize variables
set_fact:
found_template: False

- name: Calculate feature name specific to the vendor and family
set_fact:
feature_needed: True
configured_roles: []
role_list: []
feature_list: []
vf_feature: "{{ device_vendor }}_{{ device_family }}_{{ feature }}"
feature_role_dir: "./roles/cfg_{{ feature }}"
hardware: "{{ device_vendor }}-{{ device_model }}"

- name: Handle the null rb_role case
set_fact:
device_rb_roles: ['null']
when: device_rb_roles == []

- name: Get supported role list
set_fact:
supported_role_list: "{{ item.value }}"
when: item.key == hardware
with_dict: "{{ supported_roles }}"

- name: Calculate configured device role list
set_fact:
configured_roles: "{{ configured_roles }} + ['{{ item }}@{{ device_phy_role }}']"
with_items: "{{ device_rb_roles }}"

- name: Cross-check configured list with supported list
set_fact:
role_list: "{{ role_list }} + [ '{{ item }}' ]"
when: item in supported_role_list
with_items: "{{ configured_roles }}"

- name: Get the union of all features for all configured/supported roles
set_fact:
feature_list: "{{ feature_list }} + {{ item.value }}"
when: item.key is in role_list
with_dict: "{{ role_to_feature_mapping }}"

- name: Skip if feature not needed for this role
block:
- debug: msg="Feature {{ feature }} not found in role, so skipping..."
- set_fact:
feature_needed: False
when: feature not in feature_list

- name: Check whether Jinja file exists for this vendor/family/feature
stat:
Expand Down Expand Up @@ -63,5 +100,4 @@
status: "{{ JOBLOG_STATUS.IN_PROGRESS }}"
device_name: "{{ device_name }}"
- meta: end_play
when: found_template == True

when: feature_needed == True and found_template == True

0 comments on commit 9d61f18

Please sign in to comment.