Molecule tests for resource-data role

Initial molecule tests. Tests now ssh transfer but
test files fully supports also testing nfs transfer.
Creating nfs transfer as separate scenario later when
find out better ways to share common code.

Issue-ID: OOM-1754

Change-Id: Ia728ecfed4378c01f7e305d5a4446b0172fe42d9
Signed-off-by: Samuli Silvius <s.silvius@partner.samsung.com>
diff --git a/ansible/roles/resource-data/molecule/default/group_vars/all.yml b/ansible/roles/resource-data/molecule/default/group_vars/all.yml
new file mode 100644
index 0000000..558eacb
--- /dev/null
+++ b/ansible/roles/resource-data/molecule/default/group_vars/all.yml
@@ -0,0 +1,7 @@
+---
+app_data_path: /opt/myleculeapp
+aux_data_path: "{{ app_data_path }}/runtime_images_source_dir"
+resources_dir: /data
+resources_filename: resources_package.tar
+aux_resources_filename: aux_resources_package.tar
+ansible_ssh_private_key_file: ~/.ssh/offline_ssh_key
diff --git a/ansible/roles/resource-data/molecule/default/molecule.yml b/ansible/roles/resource-data/molecule/default/molecule.yml
new file mode 100644
index 0000000..03f40cb
--- /dev/null
+++ b/ansible/roles/resource-data/molecule/default/molecule.yml
@@ -0,0 +1,47 @@
+---
+dependency:
+  name: galaxy
+driver:
+  name: docker
+lint:
+  name: yamllint
+platforms:
+
+  - name: resource-host
+    image: molecule-${PREBUILD_PLATFORM_DISTRO:-centos}:${PREBUILD_DISTRO_VERSION:-centos7.6}
+    pre_build_image: true
+    privileged: true
+    command: ${MOLECULE_DOCKER_COMMAND:-""}
+    groups:
+      - resources
+    networks:
+      - name: resource-data
+    volumes:
+      - /sys/fs/cgroup:/sys/fs/cgroup:ro
+      #  - ${HOME}/resource-data:/data:rw  # mount fs from host to get nfs exportfs task working
+
+  - name: infrastructure-server
+    image: molecule-${PREBUILD_PLATFORM_DISTRO:-centos}:${PREBUILD_DISTRO_VERSION:-centos7.6}
+    pre_build_image: true
+    privileged: true
+    command: ${MOLECULE_DOCKER_COMMAND:-""}
+    groups:
+      - infrastructure
+    networks:
+      - name: resource-data
+    volumes:
+      - /sys/fs/cgroup:/sys/fs/cgroup:ro
+
+provisioner:
+  name: ansible
+  log: true
+  lint:
+    name: ansible-lint
+  env:
+    ANSIBLE_ROLES_PATH: ../../../../test/roles/
+scenario:
+  name: default
+verifier:
+  name: testinfra
+  lint:
+    name: flake8
diff --git a/ansible/roles/resource-data/molecule/default/playbook.yml b/ansible/roles/resource-data/molecule/default/playbook.yml
new file mode 100644
index 0000000..cdd9820
--- /dev/null
+++ b/ansible/roles/resource-data/molecule/default/playbook.yml
@@ -0,0 +1,6 @@
+---
+- name: Converge
+  hosts: all
+  roles:
+    - setup
+    - resource-data
diff --git a/ansible/roles/resource-data/molecule/default/prepare.yml b/ansible/roles/resource-data/molecule/default/prepare.yml
new file mode 100644
index 0000000..a443600
--- /dev/null
+++ b/ansible/roles/resource-data/molecule/default/prepare.yml
@@ -0,0 +1,5 @@
+---
+- name: Prepare resource-data
+  hosts: all
+  roles:
+    - prepare-resource-data
diff --git a/ansible/roles/resource-data/molecule/default/tests/test_default.py b/ansible/roles/resource-data/molecule/default/tests/test_default.py
new file mode 100644
index 0000000..7cff76a
--- /dev/null
+++ b/ansible/roles/resource-data/molecule/default/tests/test_default.py
@@ -0,0 +1,56 @@
+import os
+import pytest
+
+import testinfra.utils.ansible_runner
+
+testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
+    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('infrastructure-server')
+
+
+@pytest.fixture
+def group_vars(host):
+    all_file = "file=group_vars/all.yml name=all"
+    return host.ansible("include_vars", all_file)["ansible_facts"]["all"]
+
+
+@pytest.mark.parametrize('dir', [
+  'app_data_path',
+  'aux_data_path'
+])
+def test_data_target_dirs(host, dir, group_vars):
+    tested_dir = host.file(group_vars[dir])
+    assert tested_dir.exists
+    assert tested_dir.is_directory
+
+
+@pytest.mark.parametrize('target_file', [
+  'resource1.txt',
+  'resource2.txt',
+  'resource3.txt',
+  'somedir/resource4.txt'
+])
+def test_transferred_resources_files(host, target_file, group_vars):
+    tested_file = host.file(group_vars["app_data_path"] + "/" + target_file)
+    assert tested_file.exists
+    assert tested_file.is_file
+
+    flag_file = \
+        host.file(group_vars["app_data_path"] + "/" +
+                  group_vars["resources_filename"] + "-uploaded")
+    assert flag_file.exists
+    assert flag_file.is_file
+
+
+@pytest.mark.parametrize('target_file', [
+  'auxdata'
+])
+def test_transferred_aux_resources_files(host, target_file, group_vars):
+    tested_file = host.file(group_vars["aux_data_path"] + "/" + target_file)
+    assert tested_file.exists
+    assert tested_file.is_file
+
+    flag_file = \
+        host.file(group_vars["aux_data_path"] + "/" +
+                  group_vars["aux_resources_filename"] + "-uploaded")
+    assert flag_file.exists
+    assert flag_file.is_file