Skip to content

Commit

Permalink
Merge pull request #25 from 0x0I/idempotency
Browse files Browse the repository at this point in the history
activate idempotency testing and fix setup + testing bugs
  • Loading branch information
O1ahmad authored Feb 8, 2020
2 parents ddb6ba5 + 5a64113 commit a450296
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 61 deletions.
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ perform_uninstall: false
custom_unit_properties: {}
custom_miner_properties: {}

managed_services: ['service', 'miner']
managed_services: ['lotus']
19 changes: 10 additions & 9 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,70 @@
name: lotus
state: restarted
listen: Restart service
ignore_errors: true

- name: Stop lotus systemd service
become: true
service:
name: lotus
state: stopped
enabled: false
listen: Uninstall Lotus
listen: Uninstall service

- name: Remove Lotus systemd service file
become: true
file:
path: "/etc/systemd/system/lotus.service"
state: absent
listen: Uninstall Lotus
listen: Uninstall service

- name: Stop lotus storage miner systemd service
become: true
service:
name: lotus-storage-miner
state: stopped
enabled: false
listen: Uninstall Lotus
listen: Uninstall service

- name: Remove Lotus storage miner systemd service file
become: true
file:
path: "/etc/systemd/system/lotus-storage-miner.service"
state: absent
listen: Uninstall Lotus
listen: Uninstall service

- name: Remove lotus install dir
become: true
file:
path: "{{ install_dir }}"
state: absent
listen: Uninstall Lotus
listen: Uninstall service

- name: Remove lotus path dir
become: true
file:
path: "{{ lotus_path }}"
state: absent
listen: Uninstall Lotus
listen: Uninstall service

- name: Remove lotus storage path dir
become: true
file:
path: "{{ lotus_storage_path }}"
state: absent
listen: Uninstall Lotus
listen: Uninstall service

- name: Remove lotus user
become: true
user:
name: "{{ lotus_user }}"
state: absent
remove: true
listen: Uninstall Lotus
listen: Uninstall service

- name: Remove lotus group
become: true
group:
name: "{{ lotus_user }}"
state: absent
listen: Uninstall Lotus
listen: Uninstall service
10 changes: 10 additions & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ provisioner:
ansible_verbose: true
ansible_cfg_path: test/ansible.cfg
requirements_path: test/requirements-test.yml
idempotency_test: true

verifier:
name: inspec
Expand Down Expand Up @@ -89,6 +90,10 @@ suites:
- name: install_archive
provisioner:
playbook: test/integration/install/install_archive/default_playbook.yml
ansible_extra_flags: '--skip-tags=config,launch'
idempotency_skip_tags:
- config
- launch
verifier:
inspec_tests:
- path: test/integration/install/install_archive
Expand All @@ -99,6 +104,10 @@ suites:
- name: install_source
provisioner:
playbook: test/integration/install/install_source/default_playbook.yml
ansible_extra_flags: '--skip-tags=config,launch'
idempotency_skip_tags:
- config
- launch
verifier:
inspec_tests:
- path: test/integration/install/install_source
Expand Down Expand Up @@ -139,6 +148,7 @@ suites:
- name: uninstall
provisioner:
playbook: test/integration/uninstall/default_playbook.yml
idempotency_test: false
verifier:
inspec_tests:
- path: test/integration/uninstall
Expand Down
13 changes: 13 additions & 0 deletions tasks/common/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@
include_tasks: "common/install/{{ install_type }}_install.yml"
tags:
- install

- name: Create symbolic links to managed services binaries
become: true
when: install_type == "archive"
file:
src: "{{ install_dir }}/{{ item }}"
dest: "/usr/local/bin/{{ item }}"
state: link
loop: "{{ managed_services }}"
notify:
- Restart service
tags:
- install
13 changes: 0 additions & 13 deletions tasks/common/install/archive_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,3 @@
tags:
- install
- archive

- name: Create a symbolic link to /usr/local/bin/lotus
become: true
when: install_type == "archive"
file:
src: "{{ install_dir }}/lotus"
dest: /usr/local/bin/lotus
state: link
notify:
- Restart service
tags:
- install
- archive
4 changes: 4 additions & 0 deletions tasks/common/install/source_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
target: clean
environment:
PATH: /usr/local/bin:{{ ansible_env.PATH }}
changed_when: false
tags:
- install
- source
Expand All @@ -30,6 +31,7 @@
target: all
environment:
PATH: /usr/local/bin:{{ ansible_env.PATH }}
changed_when: false
tags:
- install
- source
Expand All @@ -42,6 +44,7 @@
target: install
environment:
PATH: /usr/local/bin:{{ ansible_env.PATH }}
changed_when: false
tags:
- install
- source
Expand All @@ -54,6 +57,7 @@
owner: "{{ lotus_user }}"
group: "{{ lotus_user }}"
recurse: true
changed_when: false
tags:
- install
- source
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
name: lotus-storage-miner
state: started
enabled: "yes"
changed_when: false
tags:
- launch
- miner
File renamed without changes.
44 changes: 10 additions & 34 deletions tasks/common/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,20 @@
block:
- name: Broadcast uninstall signal
command: /bin/true
notify: Uninstall Lotus
when: perform_uninstall

notify:
- Uninstall service
rescue:
- name: Ensure flush of handlers
meta: flush_handlers
always:
- name: End play following uninstallation
meta: end_play
tags:
- always

- name: Update system packages
become: true
when: go_autoinstall and ansible_os_family|lower == "redhat"
yum:
name: "*"
state: latest
tags:
- preflight

- name: Add Go-lang backports repository to sources list
become: true
when: go_autoinstall and ansible_distribution|lower == "ubuntu"
apt_repository:
repo: ppa:longsleep/golang-backports
tags:
- preflight

- name: Update apt packages
become: true
when: go_autoinstall and ansible_os_family|lower == "debian"
apt:
upgrade: 'yes'
update_cache: 'yes'
tags:
- preflight

- name: Download and extract Go-lang
become: true
when: go_autoinstall and ansible_distribution|lower != "ubuntu"
when: go_autoinstall
unarchive:
src: "{{ go_url }}"
dest: "{{ go_install_dir }}"
Expand All @@ -61,18 +38,17 @@

- name: Update system dependencies
become: true
when: ansible_distribution|lower != "ubuntu"
package:
name: "{{ system_dependencies }}"
state: present
tags:
- preflight

- name: Create a symbolic link to /usr/local/bin/go
- name: Create a symbolic link to installed go binary
become: true
when: go_autoinstall and ansible_distribution|lower != "Ubuntu"
when: go_autoinstall
file:
src: "{{ go_install_dir }}/go"
src: "{{ go_install_dir }}/go/bin/go"
dest: /usr/local/bin/go
state: link
tags:
Expand Down
2 changes: 1 addition & 1 deletion test/integration/config/default_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
title "Lotus configuration integration tests"

describe file('/home/lotus/.lotus/config.toml') do
describe file('/opt/lotus/.lotus/config.toml') do
it { should exist }
its('owner') { should eq 'lotus' }
its('group') { should eq 'lotus' }
Expand Down
2 changes: 1 addition & 1 deletion test/integration/launch/launch_miner/default_playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
- ansible-role-lotus
vars:
version: v0.1.5
managed_services: ['service', 'miner']
managed_services: ['lotus', 'lotus-storage-miner']
extra_run_args:
- '--bootstrap'
3 changes: 2 additions & 1 deletion test/integration/launch/launch_service/default_playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
- ansible-role-lotus
vars:
install_type: source
go_autoinstall: true
git_version: v0.1.5
managed_services: ['service']
managed_services: ['lotus']
extra_run_args:
- "--bootstrap"
1 change: 0 additions & 1 deletion vars/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
go_install_dir: /usr/bin
system_dependencies:
- golang-go
- gcc
- git
- bzr
Expand Down

0 comments on commit a450296

Please sign in to comment.