tripleo-heat-templates/deployment/ovn/ovn-dbs-pacemaker-puppet.yaml
Sofer Athlan-Guyot e7c02f9d4a Fix retaging of ovn-dbs container during update.
The variable name was wrong, and the retaging was not taking place
leading to ovn dbs being stopped on the cluster after update.

Change-Id: I9f3502be850a48f2aaf018c7cde0fea253a1513a
Closes-Bug: #1839635
2019-08-09 17:22:51 +02:00

338 lines
15 KiB
YAML

heat_template_version: rocky
description: >
OpenStack containerized OVN DBs service managed by pacemaker
parameters:
ContainerOvnDbsImage:
description: image
type: string
ContainerOvnDbsConfigImage:
description: image
type: string
EndpointMap:
default: {}
description: Mapping of service endpoint -> protocol. Typically set
via parameter_defaults in the resource registry.
type: json
ServiceData:
default: {}
description: Dictionary packing service data
type: json
ServiceNetMap:
default: {}
description: Mapping of service_name -> network name. Typically set
via parameter_defaults in the resource registry. This
mapping overrides those in ServiceNetMapDefaults.
type: json
DefaultPasswords:
default: {}
type: json
RoleName:
default: ''
description: Role name on which the service is applied
type: string
RoleParameters:
default: {}
description: Parameters specific to the role
type: json
OVNNorthboundServerPort:
description: Port of the OVN Northbound DB server
type: number
default: 6641
OVNSouthboundServerPort:
description: Port of the OVN Southbound DB server
type: number
default: 6642
ConfigDebug:
default: false
description: Whether to run config management (e.g. Puppet) in debug mode.
type: boolean
PcmkConfigRestartTimeout:
default: 600
description: Time in seconds to wait for a pcmk resource to restart when
a config change is detected and the resource is being restarted
type: number
ContainerCli:
type: string
default: 'podman'
description: CLI tool used to manage containers.
constraints:
- allowed_values: ['docker', 'podman']
DeployIdentifier:
default: ''
type: string
description: >
Setting this to a unique value will re-run any deployment tasks which
perform configuration on a Heat stack-update.
conditions:
puppet_debug_enabled: {get_param: ConfigDebug}
docker_enabled: {equals: [{get_param: ContainerCli}, 'docker']}
resources:
ContainersCommon:
type: ../containers-common.yaml
OVNDbsBase:
type: ./ovn-dbs-container-puppet.yaml
properties:
EndpointMap: {get_param: EndpointMap}
ServiceData: {get_param: ServiceData}
ServiceNetMap: {get_param: ServiceNetMap}
DefaultPasswords: {get_param: DefaultPasswords}
RoleName: {get_param: RoleName}
RoleParameters: {get_param: RoleParameters}
OVNNorthboundServerPort: {get_param: OVNNorthboundServerPort}
OVNSouthboundServerPort: {get_param: OVNSouthboundServerPort}
outputs:
role_data:
description: Role data for the OVN Dbs HA role.
value:
service_name: ovn_dbs
config_settings:
map_merge:
- get_attr: [OVNDbsBase, role_data, config_settings]
- tripleo::profile::pacemaker::ovn_dbs_bundle::ovn_dbs_docker_image: &ovn_dbs_image_pcmklatest
list_join:
- ':'
- - yaql:
data: {get_param: ContainerOvnDbsImage}
expression: $.data.rightSplit(separator => ":", maxSplits => 1)[0]
- 'pcmklatest'
- tripleo::profile::pacemaker::ovn_dbs_bundle::nb_db_port: {get_param: OVNNorthboundServerPort}
- tripleo::profile::pacemaker::ovn_dbs_bundle::sb_db_port: {get_param: OVNSouthboundServerPort}
- tripleo::profile::pacemaker::ovn_dbs_bundle::container_backend: {get_param: ContainerCli}
- tripleo::haproxy::ovn_dbs_manage_lb: false
- tripleo::ovn_dbs::firewall_rules:
'121 OVN DB server ports':
proto: 'tcp'
dport:
# Control port for pcmk remote bundle
- 3125
- {get_param: OVNNorthboundServerPort}
- {get_param: OVNSouthboundServerPort}
service_config_settings: {}
# BEGIN DOCKER SETTINGS
puppet_config:
config_volume: 'ovn_dbs'
puppet_tags: 'exec'
step_config: ''
config_image: &ovn_dbs_config_image {get_param: ContainerOvnDbsConfigImage}
kolla_config:
/var/lib/kolla/config_files/ovn_dbs.json:
command: /usr/sbin/pacemaker_remoted
config_files:
- dest: /etc/libqb/force-filesystem-sockets
source: /dev/null
owner: root
perm: '0644'
- source: "/var/lib/kolla/config_files/src/*"
dest: "/"
merge: true
preserve_properties: true
optional: true
container_config_scripts: {get_attr: [ContainersCommon, container_config_scripts]}
docker_config:
step_3:
ovn_dbs_restart_bundle:
start_order: 0
config_volume: ovn_dbs
detach: false
net: host
ipc: host
user: root
environment:
- TRIPLEO_MINOR_UPDATE
command:
- '/usr/bin/bootstrap_host_exec'
- 'ovn_dbs'
- str_replace:
template:
'if [ x"${TRIPLEO_MINOR_UPDATE,,}" != x"true" ] && /usr/sbin/pcs resource show ovn-dbs-bundle; then /usr/sbin/pcs resource restart --wait=PCMKTIMEOUT ovn-dbs-bundle; echo "ovn-dbs-bundle restart invoked"; fi'
params:
PCMKTIMEOUT: {get_param: PcmkConfigRestartTimeout}
image: {get_param: ContainerOvnDbsConfigImage}
volumes:
list_concat:
- {get_attr: [ContainersCommon, volumes]}
- if:
- docker_enabled
- - /etc/corosync/corosync.conf:/etc/corosync/corosync.conf:ro
- null
ovn_dbs_init_bundle:
start_order: 1
detach: false
net: host
ipc: host
user: root
config_volume: 'ovn_dbs_init_bundle'
command: # '/container_puppet_apply.sh "STEP" "TAGS" "CONFIG" "DEBUG"'
list_concat:
- - '/container_puppet_apply.sh'
- '3'
- 'file,file_line,concat,augeas,pacemaker::resource::bundle,pacemaker::property,pacemaker::resource::ip,pacemaker::resource::ocf,pacemaker::constraint::order,pacemaker::constraint::colocation'
- 'include ::tripleo::profile::base::pacemaker;include ::tripleo::profile::pacemaker::ovn_dbs_bundle'
- if:
- puppet_debug_enabled
- - '--debug'
- - ''
image: *ovn_dbs_config_image
volumes:
list_concat:
- {get_attr: [ContainersCommon, container_puppet_apply_volumes]}
- if:
- docker_enabled
- - /etc/corosync/corosync.conf:/etc/corosync/corosync.conf:ro
- null
environment:
# NOTE: this should force this container to re-run on each
# update (scale-out, etc.)
- list_join:
- ''
- - 'TRIPLEO_DEPLOY_IDENTIFIER='
- {get_param: DeployIdentifier}
host_prep_tasks:
- name: create persistent directories
file:
path: "{{ item.path }}"
state: directory
setype: "{{ item.setype }}"
with_items:
- { 'path': /var/log/containers/openvswitch, 'setype': svirt_sandbox_file_t }
- { 'path': /var/lib/openvswitch/ovn, 'setype': svirt_sandbox_file_t }
- { 'path': /var/log/openvswitch, 'setype': svirt_sandbox_file_t }
- name: openvswitch logs readme
copy:
dest: /var/log/openvswitch/readme.txt
content: |
Log files from openvswitch containers can be found under
/var/log/containers/openvswitch.
ignore_errors: true
deploy_steps_tasks:
- name: OVN DBS tag container image for pacemaker
when: step|int == 1
import_role:
name: tripleo-container-tag
vars:
container_image: {get_param: ContainerOvnDbsImage}
container_image_latest: *ovn_dbs_image_pcmklatest
update_tasks:
- name: Get docker ovn-dbs image
set_fact:
ovn_dbs_docker_image: {get_param: ContainerOvnDbsImage}
ovn_dbs_docker_image_latest: *ovn_dbs_image_pcmklatest
- name: set is_ovn_dbs_bootstrap_node fact
set_fact: is_ovn_dbs_bootstrap_node={{ovn_dbs_short_bootstrap_node_name|lower == ansible_hostname|lower}}
- name: ovn-dbs fetch and retag container image for pacemaker
when:
- step|int == 3
block: &ovn_dbs_fetch_retag_container_tasks
- name: Get previous ovn-dbs image id
shell: "{{container_cli}} images | awk '/ovn.* pcmklatest/{print $3}' | uniq"
register: ovn_dbs_image_id
- block:
- name: Get a list of container using ovn-dbs image
shell: "{{container_cli}} ps -a -q -f 'ancestor={{ovn_dbs_image_id.stdout}}'"
register: ovn_dbs_containers_to_destroy
# It will be recreated with the deploy step.
- name: Remove any container using the same ovn-dbs image
shell: "{{container_cli}} rm -fv {{item}}"
with_items: "{{ ovn_dbs_containers_to_destroy.stdout_lines }}"
- name: Remove previous ovn-dbs images
shell: "{{container_cli}} rmi -f {{ovn_dbs_image_id.stdout}}"
when:
- ovn_dbs_image_id.stdout != ''
- name: Pull latest ovn-dbs images
command: "{{container_cli}} pull {{ovn_dbs_docker_image}}"
- name: Retag pcmklatest to latest ovn-dbs image
import_role:
name: tripleo-container-tag
vars:
container_image: "{{ovn_dbs_docker_image}}"
container_image_latest: "{{ovn_dbs_docker_image_latest}}"
# Got to check that pacemaker_is_active is working fine with bundle.
# TODO: pacemaker_is_active resource doesn't support bundle.
# When ovn-dbs-bundle support was added, we didn't tag the ovn-dbs image
# with pcmklatest. So, when update is run for the first time we need to
# update the ovn-dbs-bundle resource to use the 'pcmklatest' tagged image.
# See https://bugzilla.redhat.com/show_bug.cgi?id=1586132.
# Step 3 (see above) takes care of tagging the image.
- name: Update ovn-dbs-bundle resource to use pcmklatest tag image if not used
when:
- step|int == 5
- is_ovn_dbs_bootstrap_node
block:
- name: Get the present image used by ovn-dbs-bundle
shell: "pcs resource show ovn-dbs-bundle | grep image | awk '{ split($2, image, \"=\"); print image[2] }'"
register: ovn_dbs_current_image
- block: &ovn_dbs_update_bundle_with_new_image
- name: Update the ovn-dbs-bundle to use the new container image name
command: "pcs resource bundle update ovn-dbs-bundle container image={{ovn_dbs_docker_image_latest}}"
when:
- ovn_dbs_current_image.stdout != ovn_dbs_docker_image_latest
upgrade_tasks:
- when: step|int == 0
block:
- name: Get docker ovn-dbs image
set_fact:
ovn_dbs_docker_image: {get_param: ContainerOvnDbsImage}
ovn_dbs_docker_image_latest: *ovn_dbs_image_pcmklatest
- name: set is_ovn_dbs_bootstrap_node fact
set_fact: is_ovn_dbs_bootstrap_node={{ovn_dbs_short_bootstrap_node_name|lower == ansible_hostname|lower}}
- name: Check ovn-dbs-bundle cluster resource status
pacemaker_resource:
resource: ovn-dbs-bundle
state: show
check_mode: false
ignore_errors: true
register: ovndbs_pcs_result
- name: Set fact ovndbs_pcs_res
set_fact:
ovndbs_pcs_res: "{{ ovndbs_pcs_result|succeeded }}"
- name: Prepare the switch to new ovn-dbs container image name in pacemaker
block:
- name: Get ovn-dbs image id currently used by pacemaker
shell: "{{container_cli}} images | awk '/ovn.* pcmklatest/{print $3}' | uniq"
register: ovn_dbs_current_pcmklatest_id
- name: Temporarily tag the current ovn-dbs pcmklatest image id with the upgraded image name
import_role:
name: tripleo-container-tag
vars:
container_image: "{{ovn_dbs_current_pcmklatest_id.stdout}}"
container_image_latest: "{{ovn_dbs_docker_image_latest}}"
pull_image: false
when: ovn_dbs_current_pcmklatest_id.stdout != ''
# If ovn-dbs image is not tagged with pcmklatest, then create a new
# tag. This could happen if the stack is upgraded without updating the stack before.
# In the next step, the block 'ovn_dbs_update_bundle_with_new_image'
# will update the ovn-dbs-bundle resource to use the tagged image.
# And in step 3, we will fetch the latest image. Ensure we run these
# steps when the resource is up and running, otherwise the tagging
# will fail.
- block:
- name: Get the present image used by ovn-dbs-bundle
shell: "pcs resource show ovn-dbs-bundle | grep image | awk '{ split($2, image, \"=\"); print image[2] }'"
register: ovn_dbs_current_image
- name: Tag the current image with pcmklatest tag
import_role:
name: tripleo-container-tag
vars:
container_image: "{{ovn_dbs_current_image.stdout}}"
container_image_latest: "{{ovn_dbs_docker_image_latest}}"
when:
- ovn_dbs_current_pcmklatest_id.stdout == ''
- ovndbs_pcs_res
- name: Update ovn-bundle pcs resource bundle for new container image
when:
- step|int == 1
- is_ovn_dbs_bootstrap_node
- ovndbs_pcs_res
block: *ovn_dbs_update_bundle_with_new_image
- name: Retag the pacemaker image if containerized
when:
- step|int == 3
block: *ovn_dbs_fetch_retag_container_tasks