Skip to content

Commit

Permalink
Fixes #57 #58 #59 #60 #61
Browse files Browse the repository at this point in the history
  • Loading branch information
haxorof committed Oct 31, 2018
1 parent d944da6 commit a94f9ce
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 116 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/.project
.vagrant
*.retry
.vscode/
*.retry
*.vdi
/.project
*.log
tests/yaml.sh
tests/yamlparser.sh.inc
tests/test-dbg.sh
Expand Down
19 changes: 15 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased](../../releases/tag/X.Y.Z)

### Fixed

- Docker startup fails in Fedora 28 because it cannot find pvcreate ([#58](../../issues/58))
- LVM2 package is required to be installed when devicemapper is used ([#61](../../issues/61))

### Internal

- Testing: Snapshotting used during testing by `test.sh` to speed up by avoiding unnecessary installs of Ansible and guest additions
- Add Fedora distributions to test suite ([#57](../../issues/57))
- Fails to install VirtualBox guest additions on Fedora 29 beta ([#59](../../issues/59))
- Replace currently used Vagrant boxes during testing with more official boxes ([#60](../../issues/60))

## [1.9.0](../../releases/tag/1.9.0) - 2018-10-24

### Added
Expand All @@ -25,11 +37,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Add support to install Docker Ansible module dependencies ([#48](../../issues/48))
- Add support to install packages after install via PiP or OS package manager ([#49](../../issues/49))

### Changed
### Itnernal

- Testing:
- Improved structure in `vagrant_config.yml` for `test.sh`
- Improved `test.sh` with better limit functionality
- Testing: Improved structure in `vagrant_config.yml` for `test.sh`
- Testing: Improved `test.sh` with better limit functionality

### Fixed

Expand Down
11 changes: 10 additions & 1 deletion tasks/configure-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@
append: true
with_items: "{{ docker_users }}"

- name: Ensure thin-provisioning-tools is installed when devicemapper is used (Ubuntu)
- name: Ensure lvm2 is installed when devicemapper is used (Fedora/Debian)
become: true
package:
name: lvm2
state: present
when: (_docker_os_dist == "Fedora" or _docker_os_dist == "Debian") and
docker_daemon_config['storage-driver'] is defined and
docker_daemon_config['storage-driver'] == 'devicemapper'

- name: Ensure thin-provisioning-tools is installed when devicemapper is used (Ubuntu/Debian)
become: true
package:
name: thin-provisioning-tools
Expand Down
6 changes: 6 additions & 0 deletions tasks/lvm-thinpool.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
- name: Ensure lvm2 is installed
become: true
package:
name: lvm2
state: present

- name: Create LVM volume group
become: true
lvg:
Expand Down
36 changes: 22 additions & 14 deletions tests/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ unless File.exist?(testcase_file)
exit 1
end
vagrant_config = YAML.load_file("#{testcase_file}")
vagrant_devs = ["/dev/sda", "/dev/sdb", "/dev/sdc"]

Vagrant.configure("2") do |config|
config.vm.box = vagrant_config['box']
Expand All @@ -27,13 +28,8 @@ Vagrant.configure("2") do |config|
unless File.exist?(docker_disk)
vb.customize ['createhd', '--filename', docker_disk, '--size', 5 * 1024]
end
vb.customize ['storageattach', :id, '--storagectl', vagrant_config['ide_ctl_name'], '--port', 1, '--device', 0, '--type', 'hdd', '--medium', docker_disk]
vb.customize ['storageattach', :id, '--storagectl', vagrant_config['storage_ctl'], '--port', vagrant_config['storage_port'], '--device', 0, '--type', 'hdd', '--medium', docker_disk]
end

# Print test ID
config.vm.provision "shell",
inline: "echo '--> Test: " + vagrant_config['id'] + "'"

# Prepare Ansible roles directory
config.vm.provision "shell",
inline: "test -d /etc/ansible/roles/haxorof.docker-ce || \
Expand All @@ -42,18 +38,30 @@ Vagrant.configure("2") do |config|

# Prepare box
config.vm.provision "ansible_local" do |ansible|
ansible.verbose = false
ansible.playbook = vagrant_config['prep_yml']
ansible.limit = "test-host"
ansible.verbose = false
ansible.install_mode = "pip"
ansible.compatibility_mode = "2.0"
ansible.version = "latest"
ansible.playbook = vagrant_config['prep_yml']
ansible.limit = "test-host"
ansible.inventory_path = "hosts"
ansible.config_file = "/vagrant/ansible.cfg"
ansible.config_file = "/vagrant/ansible.cfg"
ansible.extra_vars = {
lvm_device: "#{vagrant_devs[vagrant_config['storage_port']]}"
}
end
# Test storage config
config.vm.provision "ansible_local" do |ansible|
ansible.verbose = false
ansible.playbook = vagrant_config['test_yml']
ansible.limit = "test-host"
ansible.verbose = false
ansible.install_mode = "pip"
ansible.compatibility_mode = "2.0"
ansible.version = "latest"
ansible.playbook = vagrant_config['test_yml']
ansible.limit = "test-host"
ansible.inventory_path = "hosts"
ansible.config_file = "/vagrant/ansible.cfg"
ansible.config_file = "/vagrant/ansible.cfg"
ansible.extra_vars = {
lvm_device: "#{vagrant_devs[vagrant_config['storage_port']]}"
}
end
end
24 changes: 12 additions & 12 deletions tests/prepare.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
- hosts: test-host
tasks:
- name: Ensure git is installed
package:
name: git
state: present
become: true
- name: Ensure Docker Bench Security is cloned
git:
repo: 'https://github.com/docker/docker-bench-security.git'
dest: /home/vagrant/docker-bench-security
version: master
when: docker_bench_security is defined
tasks: []
# - name: Ensure git is installed
# package:
# name: git
# state: present
# become: true
# - name: Ensure Docker Bench Security is cloned
# git:
# repo: 'https://github.com/docker/docker-bench-security.git'
# dest: /home/vagrant/docker-bench-security
# version: master
# when: docker_bench_security is defined
30 changes: 15 additions & 15 deletions tests/prepare_storage.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
---
- hosts: test-host
tasks:
- name: Ensure git and parted is installed
- name: Ensure dependencies are installed
package:
name: "{{ item }}"
state: present
become: true
with_items:
- git
- parted
#- git

- name: Ensure Docker Bench Security is cloned
git:
repo: 'https://github.com/docker/docker-bench-security.git'
dest: /home/vagrant/docker-bench-security
version: master
when: docker_bench_security is defined
# - name: Ensure Docker Bench Security is cloned
# git:
# repo: 'https://github.com/docker/docker-bench-security.git'
# dest: /home/vagrant/docker-bench-security
# version: master
# when: docker_bench_security is defined

- name: Create partition sdb1
- name: Create partition {{ lvm_device }}1
parted:
device: /dev/sdb
device: "{{ lvm_device }}"
number: 1
flags: [ lvm ]
part_end: 1GiB
state: present
become: true
- name: Create partition sdb2
- name: Create partition {{ lvm_device }}2
parted:
device: /dev/sdb
device: "{{ lvm_device }}"
number: 2
flags: [ lvm ]
part_start: 1GiB
state: present
become: true
- name: Ensure file system is EXT4 for /dev/sdb1
- name: Ensure file system is EXT4 for {{ lvm_device }}1
filesystem:
fstype: ext4
dev: /dev/sdb1
dev: "{{ lvm_device }}1"
become: true
- name: Ensure /var/lib/docker directory exists
file:
Expand All @@ -46,7 +46,7 @@
- name: Ensure /var/lib/docker is mounted
mount:
path: /var/lib/docker
src: /dev/sdb1
src: "{{ lvm_device }}1"
fstype: ext4
state: mounted
become: true
63 changes: 41 additions & 22 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ VirtualBox() {
exit 2
fi
$VIRTUALBOX_CMD $@ 2>&1
_exitCode=$?
local _exitCode=$?
return $_exitCode
}

LogVirtualBoxVersion() {
_output=$(VirtualBox --version)
_exitCode=$?
local _output=$(VirtualBox --version)
local _exitCode=$?
if [[ $_exitCode -eq 0 ]]; then
Info "VirtualBox $_output"
else
Expand All @@ -82,13 +82,13 @@ Vagrant() {
exit 2
fi
$VAGRANT_CMD $@ 2>&1
_exitCode=$?
local _exitCode=$?
return $_exitCode
}

LogVagrantVersion() {
_output=$(Vagrant --version)
_exitCode=$?
local _output=$(Vagrant --version)
local _exitCode=$?
if [[ $_exitCode -eq 0 ]]; then
Info "$_output"
else
Expand All @@ -114,16 +114,16 @@ VagrantProvision() {

VagrantDestroy() {
Vagrant destroy -f
_exitCode=$?
local _exitCode=$?
if [[ -f $VAGRANT_TESTCASE_FILE ]]; then
rm $VAGRANT_TESTCASE_FILE
fi
return $_exitCode
}

VagrantBoxAdd() {
cmdOutput=$(Vagrant box add --provider=virtualbox $1)
exitCode=$?
local cmdOutput=$(Vagrant box add --provider=virtualbox $1)
local exitCode=$?
if [[ "$cmdOutput" == *force* ]]; then
return 0
else
Expand All @@ -135,11 +135,12 @@ VagrantBoxAdd() {
}

GenerateDoNothingConfig() {
_box_index=$1
_test_index=$2
cat << EOF > $VAGRANT_TESTCASE_FILE
local _box_index=$1
local _test_index=$2
cat << EOF > $VAGRANT_TESTCASE_FILE
box: ${boxes__box[$_box_index]}
ide_ctl_name: ${boxes__ide_ctl_name[$_box_index]}
storage_ctl: ${boxes__storage_ctl[$_box_index]}
storage_port: ${boxes__storage_port[$_box_index]}
vbguest_update: ${boxes__vbguest_update[$_box_index]}
id: snapshot
prep_yml: test_nothing.yml
Expand All @@ -149,10 +150,21 @@ EOF

VagrantSaveSnapshot() {
GenerateDoNothingConfig $1
local _exitCode=0
Vagrant up
let "_exitCode += $?"
Vagrant halt
Vagrant snapshot save default base
return $?
let "_exitCode += $?"
Vagrant snapshot save default base -f
let "_exitCode += $?"
if [[ "$_exitCode" != "0" ]]; then
if [[ "$ON_FAILURE_KEEP" == "1" ]]; then
Info "VM is kept for debugging"
else
VagrantDestroy
fi
fi
return $_exitCode
}

VagrantRestoreSnapShot() {
Expand All @@ -167,7 +179,7 @@ VagrantDeleteSnapshot() {

DownloadBoxes() {
Info "Downloading boxes..."
exitCode=0
local exitCode=0
for box in ${boxes__box[*]}; do
if [[ "$box" != *"$LIMIT_BOX"* ]]; then
Skip "Download $box"
Expand All @@ -185,11 +197,12 @@ DownloadBoxes() {
}

GenerateTestCaseConfig() {
_box_index=$1
_test_index=$2
local _box_index=$1
local _test_index=$2
cat << EOF > $VAGRANT_TESTCASE_FILE
box: ${boxes__box[$_box_index]}
ide_ctl_name: ${boxes__ide_ctl_name[$_box_index]}
storage_ctl: ${boxes__storage_ctl[$_box_index]}
storage_port: ${boxes__storage_port[$_box_index]}
vbguest_update: ${boxes__vbguest_update[$_box_index]}
id: ${tests__id[$_test_index]}
prep_yml: ${tests__prep_yml[$_test_index]}
Expand All @@ -199,16 +212,22 @@ EOF

ExecuteTests() {
Info "Starting tests..."
exitCode=0
local exitCode=0
local do_skip=0
for box_index in $(seq 0 `expr ${#boxes__box[@]} - 1`); do
box=${boxes__box[$box_index]}
local box=${boxes__box[$box_index]}
if [[ "$box" != *"$LIMIT_BOX"* ]]; then
Skip "(code:1) Test: Skipping box [$box]"
continue
fi
VagrantSaveSnapshot $box_index
exitCode=$?
if [[ "$exitCode" != "0" ]]; then
Fail "Error when trying to create snapshot for box $box"
break
fi
for index in $(seq 0 `expr ${#tests__name[@]} - 1`); do
test_name=${tests__name[$index]}
local test_name=${tests__name[$index]}
if [[ "${tests__id[$index]}" != *"$LIMIT_TEST"* ]]; then
Skip "(code:2) Test: $test_name [$box]"
continue
Expand Down
8 changes: 8 additions & 0 deletions tests/test_config_nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- hosts: test-host
vars:
docker_channel: nightly
docker_users:
- vagrant
roles:
- haxorof.docker-ce
2 changes: 1 addition & 1 deletion tests/test_config_storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
docker_daemon_config:
storage-driver: devicemapper
storage-opts:
- "dm.directlvm_device=/dev/sdb2"
- "dm.directlvm_device={{ lvm_device }}2"
roles:
- haxorof.docker-ce
Loading

0 comments on commit a94f9ce

Please sign in to comment.