mirror of
https://bitbucket.org/atlassian/dc-deployments-automation.git
synced 2025-12-13 08:23:06 -06:00
ITOPSENG-101 add the locking logic for storing in shared_home
This commit is contained in:
@@ -11,15 +11,15 @@ def test_version_is_correct(host):
|
||||
verfile = host.file('/media/atl/jira/shared/jira-core.version')
|
||||
assert verfile.exists
|
||||
|
||||
assert verfile.content.decode("UTF-8").strip() == "7.9.0"
|
||||
assert verfile.content.decode("UTF-8").strip() == "7.13.1"
|
||||
|
||||
def test_is_downloaded(host):
|
||||
installer = host.file('/media/atl/jira/shared/downloads/jira-core.7.9.0-x64.bin')
|
||||
installer = host.file('/media/atl/jira/shared/downloads/jira-core.7.13.1-x64.bin')
|
||||
assert installer.exists
|
||||
assert installer.user == 'root'
|
||||
|
||||
def test_completed_lockfile(host):
|
||||
lockfile = host.file('/media/atl/jira/shared/downloads/jira-core.7.9.0-x64.bin_completed')
|
||||
lockfile = host.file('/media/atl/jira/shared/downloads/jira-core.7.13.1-x64.bin_completed')
|
||||
assert lockfile.exists
|
||||
assert lockfile.user == 'root'
|
||||
|
||||
|
||||
@@ -21,21 +21,132 @@
|
||||
debug:
|
||||
msg="obr_ref={{ atl_jsd_build_info.json._embedded.artifact._links.binary.href }}"
|
||||
|
||||
- name: Fetch the jsd obr
|
||||
get_url:
|
||||
url: "{{ atl_jsd_build_info.json._embedded.artifact._links.binary.href }}"
|
||||
dest: "{{ atl_installer_temp }}"
|
||||
register: jsdobr
|
||||
|
||||
- name: check the name of the downloaded file
|
||||
- name: how about getting the obr filename
|
||||
debug:
|
||||
msg="{{ jsdobr.dest }}"
|
||||
msg="obr_name=jira-servicedesk-application-{{ atl_jsd_build_info.json.name }}.obr"
|
||||
|
||||
- name: Copy the obr to shared_home
|
||||
copy:
|
||||
src: "{{ jsdobr.dest }}"
|
||||
dest: "{{ atl_product_version_cache_dir }}"
|
||||
remote_src: true
|
||||
- name: is shared_home set ?
|
||||
debug:
|
||||
msg="atl_product_home_shared_download_dir={{ atl_product_home_shared_download_dir }}"
|
||||
# For the first run a temp obr should be downloaded but moved to
|
||||
# shared home to ensure all subsequent nodes have access
|
||||
# to the same specific version binary.
|
||||
# To prevent a race condition with multiple downloads at the same time
|
||||
# a directory is used as a lockfile (atomic operation) when moving obr.
|
||||
|
||||
- name: Set assumptions to avoid race condition
|
||||
set_fact:
|
||||
download_obr: true
|
||||
move_obr: false
|
||||
atl_obr_download_href: "{{ atl_jsd_build_info.json._embedded.artifact._links.binary.href }}"
|
||||
atl_obr_filename: "jira-servicedesk-application-{{ atl_jsd_build_info.json.name }}.obr"
|
||||
atl_obr_temp_download: "{{ atl_installer_temp }}/{{ atl_obr_filename }}"
|
||||
atl_obr_shared_download: "{{ atl_product_home_shared_download_dir }}/{{ atl_obr_filename }}"
|
||||
atl_obr_moving_lock: "{{{ atl_product_home_shared_download_dir }}/{{ atl_obr_filename }}_moving"
|
||||
atl_obr_completed_lock: "{{ atl_product_home_shared_download_dir }}/{{ atl_obr_filename }}_completed"
|
||||
|
||||
# Check for pre-downloaded obr on shared_home and completed lock dir.
|
||||
- name: Check for completed lock directory
|
||||
stat:
|
||||
path: "{{ atl_obr_completed_lock }}"
|
||||
register: completed_lock
|
||||
|
||||
- name: Check for obr in home_shared
|
||||
stat:
|
||||
path: "{{ atl_obr_shared_download }}"
|
||||
register: home_shared_download
|
||||
|
||||
# If obr exists and lockdir exists use this obr instead
|
||||
- name: Check lock directory and obr exists on shared_home
|
||||
set_fact:
|
||||
download_obr: false
|
||||
atl_obr_download: "{{ atl_obr_shared_download }}"
|
||||
when:
|
||||
- home_shared_download.stat.exists
|
||||
- completed_lock.stat.isdir is defined
|
||||
- completed_lock.stat.isdir
|
||||
|
||||
# Fetch obr if required
|
||||
- name: download_obr is true so fetch and do all the things
|
||||
block:
|
||||
|
||||
# Fetch obr and copy to temp
|
||||
- name: Fetch obr
|
||||
get_url:
|
||||
url: "{{ atl_obr_download_href }}"
|
||||
dest: "{{ atl_obr_temp_download }}"
|
||||
mode: 0755
|
||||
force: false
|
||||
register: atl_obr_completed
|
||||
|
||||
# If obr was fetched make the lock directory
|
||||
- name: Create moving_lock.
|
||||
file:
|
||||
path: "{{ atl_obr_moving_lock }}"
|
||||
state: directory
|
||||
when:
|
||||
- atl_obr_completed is succeeded
|
||||
register: moving_lock_created
|
||||
|
||||
# Directory lock was created by this run?
|
||||
# If so, then set a fact intending to move obr
|
||||
- name: Move obr Scenario - lock created by this run
|
||||
set_fact:
|
||||
move_obr: true
|
||||
when:
|
||||
- moving_lock_created is succeeded
|
||||
- moving_lock_created.changed
|
||||
# Otherwise directory lock was either already created or
|
||||
# could not be created. Fall back is to continue and install from temp
|
||||
|
||||
when: download_obr
|
||||
|
||||
# If the intention is to move obr to home_shared
|
||||
- name: Move obr to home_shared
|
||||
block:
|
||||
|
||||
- name: Copy temp installer to home_shared
|
||||
copy:
|
||||
src: "{{ atl_obr_temp_download }}"
|
||||
dest: "{{ atl_obr_shared_download }}"
|
||||
remote_src: true
|
||||
when:
|
||||
- moving_lock_created is succeeded
|
||||
- moving_lock_created.changed
|
||||
register: copied
|
||||
|
||||
- name: Create completed_lock once obr downloaded and copied
|
||||
file:
|
||||
path: "{{ atl_obr_shared_completed_lock }}"
|
||||
state: directory
|
||||
when: copied is succeeded
|
||||
register: completed_lock_created
|
||||
|
||||
- name: Remove moving_lock to show that obr is completed
|
||||
file:
|
||||
path: "{{ atl_obr_shared_moving_lock }}"
|
||||
state: absent
|
||||
when:
|
||||
- completed_lock_created is succeeded
|
||||
- copied is succeeded
|
||||
register: moving_lock_removed
|
||||
|
||||
- name: Delete old temp installer
|
||||
file:
|
||||
path: "{{ atl_obr_temp_download }}"
|
||||
state: absent
|
||||
when: moving_lock_removed is succeeded
|
||||
register: temp_deleted
|
||||
|
||||
- name: Set install to home_shared location
|
||||
set_fact:
|
||||
atl_obr_download: "{{ atl_obr_home_shared_download }}"
|
||||
when: temp_deleted is succeeded
|
||||
|
||||
when: move_obr
|
||||
|
||||
# At this point the binary is in {{ atl_obr_download }}
|
||||
# (which is either on home_shared or temp)
|
||||
|
||||
- name: Ensure instaled-plugins dir exists
|
||||
file:
|
||||
@@ -48,7 +159,7 @@
|
||||
- name: Unpack the obr into the installed-plugins dir
|
||||
unarchive:
|
||||
remote_src: true
|
||||
src: "{{ jsdobr.dest }}"
|
||||
src: "{{ atl_obr_download }}"
|
||||
dest: "{{ atl_product_version_cache_dir }}/plugins/installed-plugins"
|
||||
owner: "{{ atl_product_user }}"
|
||||
group: "{{ atl_product_user }}"
|
||||
|
||||
Reference in New Issue
Block a user