summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Zegan <m.zegan@samsung.com>2019-04-09 15:21:52 +0200
committerSamuli Silvius <s.silvius@partner.samsung.com>2019-04-17 08:18:00 +0000
commit1266d180911300c4236a6e1411b1f1782884dafb (patch)
tree90488bd4aa1bde844a1d14a74bf817bd9591734b
parentbb3bef83ca562b9aadc288b3ec46264d73ec73ac (diff)
Improve nfs role
This commit improves the nfs role by using cluster_ip variable instead of ansible_host for getting nfs client/server address, and using /etc/exports.d instead of /etc/exports for exporting nfs filesystem. Also, this commit fixes other issues in molecule found along the way. Change-Id: Ibd4ea5d4fd937116e2dc9e1b6f85c3e019f62e17 Issue-ID: OOM-1770 Signed-off-by: Michal Zegan <m.zegan@samsung.com>
-rw-r--r--ansible/roles/nfs/molecule/default/cleanup.yml6
-rw-r--r--ansible/roles/nfs/molecule/default/host_vars/kubernetes-node-1.yml2
-rw-r--r--ansible/roles/nfs/molecule/default/host_vars/kubernetes-node-2.yml2
-rw-r--r--ansible/roles/nfs/molecule/default/molecule.yml7
-rw-r--r--ansible/roles/nfs/molecule/default/tests/test_kubernetes-server.py9
-rw-r--r--ansible/roles/nfs/molecule/default/tests/test_nfs-server.py7
-rw-r--r--ansible/roles/nfs/tasks/main.yml4
-rw-r--r--ansible/roles/nfs/templates/exports.j22
-rw-r--r--ansible/test/roles/cleanup-nfs/tasks/main.yml5
9 files changed, 36 insertions, 8 deletions
diff --git a/ansible/roles/nfs/molecule/default/cleanup.yml b/ansible/roles/nfs/molecule/default/cleanup.yml
new file mode 100644
index 00000000..a085bd5a
--- /dev/null
+++ b/ansible/roles/nfs/molecule/default/cleanup.yml
@@ -0,0 +1,6 @@
+---
+- name: Cleanup
+ hosts: all
+ ignore_unreachable: true
+ roles:
+ - cleanup-nfs
diff --git a/ansible/roles/nfs/molecule/default/host_vars/kubernetes-node-1.yml b/ansible/roles/nfs/molecule/default/host_vars/kubernetes-node-1.yml
new file mode 100644
index 00000000..27a521b7
--- /dev/null
+++ b/ansible/roles/nfs/molecule/default/host_vars/kubernetes-node-1.yml
@@ -0,0 +1,2 @@
+---
+cluster_ip: "{{ ansible_default_ipv4.address }}"
diff --git a/ansible/roles/nfs/molecule/default/host_vars/kubernetes-node-2.yml b/ansible/roles/nfs/molecule/default/host_vars/kubernetes-node-2.yml
new file mode 100644
index 00000000..27a521b7
--- /dev/null
+++ b/ansible/roles/nfs/molecule/default/host_vars/kubernetes-node-2.yml
@@ -0,0 +1,2 @@
+---
+cluster_ip: "{{ ansible_default_ipv4.address }}"
diff --git a/ansible/roles/nfs/molecule/default/molecule.yml b/ansible/roles/nfs/molecule/default/molecule.yml
index 71e08d03..f6610ece 100644
--- a/ansible/roles/nfs/molecule/default/molecule.yml
+++ b/ansible/roles/nfs/molecule/default/molecule.yml
@@ -14,6 +14,7 @@ platforms:
groups:
- kubernetes
- nfs-server
+ purge_networks: true
networks:
- name: nfs-net
volumes:
@@ -27,15 +28,21 @@ platforms:
command: ${MOLECULE_DOCKER_COMMAND:-""}
groups:
- kubernetes
+ purge_networks: true
networks:
- name: nfs-net
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
provisioner:
name: ansible
+ playbooks:
+ cleanup: cleanup.yml
+ env:
+ ANSIBLE_ROLES_PATH: "../../../../test/roles"
inventory:
links:
group_vars: ../../../../group_vars
+ host_vars: host_vars
lint:
name: ansible-lint
verifier:
diff --git a/ansible/roles/nfs/molecule/default/tests/test_kubernetes-server.py b/ansible/roles/nfs/molecule/default/tests/test_kubernetes-server.py
index b702a73d..0e3710cf 100644
--- a/ansible/roles/nfs/molecule/default/tests/test_kubernetes-server.py
+++ b/ansible/roles/nfs/molecule/default/tests/test_kubernetes-server.py
@@ -1,5 +1,6 @@
import os
+import testinfra
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
@@ -7,9 +8,11 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
def test_nfs_mount(host):
+ node1_ip = testinfra.get_host("docker://kubernetes-node-1").interface(
+ "eth0").addresses[0]
mp = host.mount_point("/dockerdata-nfs")
assert mp.exists
- assert mp.filesystem == "nfs"
- assert mp.device == "kubernetes-node-1:/dockerdata-nfs"
+ assert mp.filesystem == "nfs" or mp.filesystem == "nfs4"
+ assert mp.device == node1_ip + ":/dockerdata-nfs"
assert host.file("/etc/fstab").\
- contains("kubernetes-node-1:/dockerdata-nfs /dockerdata-nfs nfs")
+ contains(node1_ip + ":/dockerdata-nfs /dockerdata-nfs nfs")
diff --git a/ansible/roles/nfs/molecule/default/tests/test_nfs-server.py b/ansible/roles/nfs/molecule/default/tests/test_nfs-server.py
index 078c653e..88ba0a61 100644
--- a/ansible/roles/nfs/molecule/default/tests/test_nfs-server.py
+++ b/ansible/roles/nfs/molecule/default/tests/test_nfs-server.py
@@ -1,6 +1,7 @@
import os
import pytest
+import testinfra
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
@@ -19,7 +20,9 @@ def test_svc(host, svc):
def test_exports(host):
- f = host.file("/etc/exports")
+ node2_ip = testinfra.get_host("docker://kubernetes-node-2").interface(
+ "eth0").addresses[0]
+ f = host.file("/etc/exports.d/dockerdata-nfs.exports")
assert f.exists
assert f.content_string == \
- """/dockerdata-nfs kubernetes-node-2(rw,sync,no_root_squash,no_subtree_check)""" # noqa: E501
+ """/dockerdata-nfs """ + node2_ip + """(rw,sync,no_root_squash,no_subtree_check)""" # noqa: E501
diff --git a/ansible/roles/nfs/tasks/main.yml b/ansible/roles/nfs/tasks/main.yml
index e7580b66..1d848876 100644
--- a/ansible/roles/nfs/tasks/main.yml
+++ b/ansible/roles/nfs/tasks/main.yml
@@ -23,7 +23,7 @@
- name: Add hosts to exports
template:
src: exports.j2
- dest: /etc/exports
+ dest: /etc/exports.d/dockerdata-nfs.exports
notify:
- reload nfs
when:
@@ -35,7 +35,7 @@
- name: Mount dockerdata-nfs
mount:
path: "{{ nfs_mount_path }}"
- src: "{{ hostvars[groups['nfs-server'].0].ansible_host | default(hostvars[groups['nfs-server'].0].inventory_hostname) }}:{{ nfs_mount_path }}"
+ src: "{{ hostvars[groups['nfs-server'].0].cluster_ip }}:{{ nfs_mount_path }}"
fstype: nfs
state: mounted
when:
diff --git a/ansible/roles/nfs/templates/exports.j2 b/ansible/roles/nfs/templates/exports.j2
index 465c9d21..f49c4999 100644
--- a/ansible/roles/nfs/templates/exports.j2
+++ b/ansible/roles/nfs/templates/exports.j2
@@ -1,3 +1,3 @@
{% for host in groups.kubernetes | difference(groups['nfs-server']) -%}
- {{ nfs_mount_path }} {{ hostvars[host].ansible_host | default(hostvars[host].inventory_hostname) }}(rw,sync,no_root_squash,no_subtree_check)
+ {{ nfs_mount_path }} {{ hostvars[host].cluster_ip }}(rw,sync,no_root_squash,no_subtree_check)
{% endfor %}
diff --git a/ansible/test/roles/cleanup-nfs/tasks/main.yml b/ansible/test/roles/cleanup-nfs/tasks/main.yml
new file mode 100644
index 00000000..e0ca4a41
--- /dev/null
+++ b/ansible/test/roles/cleanup-nfs/tasks/main.yml
@@ -0,0 +1,5 @@
+- name: "Unmount /dockerdata-nfs if mounted"
+ ignore_errors: true
+ mount:
+ path: /dockerdata-nfs
+ state: unmounted