Adding Ubuntu support in Ansible - nfs role 74/101474/9
authorJan Benedikt <j.benedikt@partner.samsung.com>
Mon, 10 Feb 2020 15:06:37 +0000 (16:06 +0100)
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>
Tue, 21 Apr 2020 11:56:44 +0000 (11:56 +0000)
Extending ansible playbooks of ubuntu support.
Creating new test with Ubuntu image for Molecule in nfs role.

Issue-ID: OOM-1671
Signed-off-by: Jan Benedikt <j.benedikt@partner.samsung.com>
Change-Id: Ib1c85e4df7ec2ba547a20684ed5e23e097351df2

ansible/roles/nfs/defaults/main.yml
ansible/roles/nfs/molecule/default/molecule.yml
ansible/roles/nfs/molecule/default/tests/test_default.py
ansible/roles/nfs/molecule/default/tests/test_nfs-server.py
ansible/roles/nfs/molecule/ubuntu/molecule.yml [new file with mode: 0644]
ansible/roles/nfs/tasks/main.yml

index bce98da..adeaf91 100644 (file)
@@ -2,7 +2,18 @@
 nfs_packages:
   RedHat:
     - nfs-utils
+  Debian:
+    - nfs-common
+    - nfs-kernel-server
 nfs_services:
   RedHat:
     - rpcbind
     - nfs-server
+  Debian:
+    - rpcbind
+    - nfs-kernel-server
+nfs_destination:
+  RedHat:
+    - "/etc/exports.d/dockerdata-nfs.exports"
+  Debian:
+    - "/etc/exports"
index a8ca6a3..9af3236 100644 (file)
@@ -43,6 +43,8 @@ provisioner:
       host_vars: host_vars
   lint:
     name: ansible-lint
+scenario:
+  name: default
 verifier:
   name: testinfra
   lint:
index 4813989..dc80875 100644 (file)
@@ -7,10 +7,13 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
     os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
 
 
-@pytest.mark.parametrize('pkg', [
-  'nfs-utils'
+@pytest.mark.parametrize('distro,pkg', [
+  ('centos', 'nfs-utils'),
+  ('ubuntu', 'nfs-common'),
+  ('ubuntu', 'nfs-kernel-server')
 ])
-def test_pkg(host, pkg):
-    package = host.package(pkg)
-
-    assert package.is_installed
+def test_pkg(host, distro, pkg):
+    os = host.system_info.distribution
+    if distro == os:
+        package = host.package(pkg)
+        assert package.is_installed
index 88ba0a6..e35e21c 100644 (file)
@@ -20,9 +20,14 @@ def test_svc(host, svc):
 
 
 def test_exports(host):
+    os = host.system_info.distribution
+    if (os == "centos"):
+        host_file = "/etc/exports.d/dockerdata-nfs.exports"
+    elif (os == "ubuntu"):
+        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")
+    f = host.file(host_file)
     assert f.exists
     assert f.content_string == \
         """/dockerdata-nfs  """ + node2_ip + """(rw,sync,no_root_squash,no_subtree_check)"""  # noqa: E501
diff --git a/ansible/roles/nfs/molecule/ubuntu/molecule.yml b/ansible/roles/nfs/molecule/ubuntu/molecule.yml
new file mode 100644 (file)
index 0000000..3fe393f
--- /dev/null
@@ -0,0 +1,54 @@
+---
+dependency:
+  name: galaxy
+driver:
+  name: docker
+lint:
+  name: yamllint
+platforms:
+  - name: kubernetes-node-1
+    image: molecule-${PREBUILD_PLATFORM_DISTRO:-ubuntu}:${PREBUILD_DISTRO_VERSION:-18.04}
+    pre_build_image: true
+    privileged: true
+    command: ${MOLECULE_DOCKER_COMMAND:-""}
+    groups:
+      - kubernetes
+      - nfs-server
+    purge_networks: true
+    networks:
+      - name: nfs-net
+    volumes:
+      - /sys/fs/cgroup:/sys/fs/cgroup:ro
+      - /dockerdata-nfs
+  - name: kubernetes-node-2
+    image: molecule-${PREBUILD_PLATFORM_DISTRO:-ubuntu}:${PREBUILD_DISTRO_VERSION:-18.04}
+    pre_build_image: true
+    privileged: true
+    command: ${MOLECULE_DOCKER_COMMAND:-""}
+    groups:
+      - kubernetes
+    purge_networks: true
+    networks:
+      - name: nfs-net
+    volumes:
+      - /sys/fs/cgroup:/sys/fs/cgroup:ro
+provisioner:
+  name: ansible
+  env:
+    ANSIBLE_ROLES_PATH: "../../../../test/roles"
+  inventory:
+    links:
+      group_vars: ../../../../group_vars
+      host_vars: ../default/host_vars
+  lint:
+    name: ansible-lint
+  playbooks:
+    prepare: ../default/prepare.yml
+    converge: ../default/playbook.yml
+scenario:
+  name: ubuntu
+verifier:
+  name: testinfra
+  lint:
+    name: flake8
+  directory: ../default/tests
index 1d84887..cc5290d 100644 (file)
@@ -23,7 +23,8 @@
     - name: Add hosts to exports
       template:
         src: exports.j2
-        dest: /etc/exports.d/dockerdata-nfs.exports
+        dest: "{{ item }}"
+      loop: "{{ nfs_destination[ansible_os_family] }}"
       notify:
         - reload nfs
   when: