Change 'rke' role testing strategy 30/117430/1
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>
Wed, 3 Feb 2021 14:01:34 +0000 (15:01 +0100)
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>
Wed, 3 Feb 2021 14:01:34 +0000 (15:01 +0100)
So far Molecule framework setup allowed full rke cluster deployment
in testing env but since rke cluster often fails to deploy in resource
constrained CI environment this change switches testing strategy to
only simulate 'rke up' operation.

Change-Id: Ia221da6666d558e086cd24155f5bd81237d82388
Issue-ID: OOM-2665
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
12 files changed:
ansible/roles/rke/molecule/default/molecule.yml
ansible/roles/rke/molecule/default/prepare.yml
ansible/roles/rke/molecule/default/tests/test_controlplane.py [deleted file]
ansible/roles/rke/molecule/default/tests/test_etcd.py [deleted file]
ansible/roles/rke/molecule/default/tests/test_infrastructure.py
ansible/roles/rke/molecule/default/tests/test_nodes.py [deleted file]
ansible/roles/rke/molecule/etcd_storage/molecule.yml
ansible/test/play-rke/molecule/default/prepare.yml
ansible/test/play-rke/molecule/default/vars.yml
ansible/test/roles/prepare-rke/tasks/all.yml
ansible/test/roles/prepare-rke/tasks/infra.yml
ansible/test/roles/prepare-rke/templates/rke.j2 [new file with mode: 0644]

index 3078c11..6da9e83 100644 (file)
@@ -49,6 +49,10 @@ provisioner:
   env:
     ANSIBLE_ROLES_PATH: ../../../../test/roles
     ANSIBLE_LIBRARY: ../../../../library
+  inventory:
+    group_vars:
+      all:
+        cluster_config_dir: /opt/onap/cluster
   options:
     e: "app_data_path=/opt/onap"
   lint:
index b012790..d20f196 100644 (file)
@@ -5,7 +5,6 @@
     - role: prepare-rke
       vars:
         mode: all
-    - prepare-docker-dind
 
 - name: "Infra specific preparations"
   hosts: infrastructure
diff --git a/ansible/roles/rke/molecule/default/tests/test_controlplane.py b/ansible/roles/rke/molecule/default/tests/test_controlplane.py
deleted file mode 100644 (file)
index 0bfbca2..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-import os
-import pytest
-
-import testinfra.utils.ansible_runner
-
-testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
-    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(
-      'kubernetes-control-plane')
-
-
-@pytest.mark.parametrize('container_name', [
-  'kube-apiserver', 'kube-controller-manager', 'kube-scheduler', 'kubelet'])
-def test_container_running(host, container_name):
-    assert host.docker(container_name).is_running
diff --git a/ansible/roles/rke/molecule/default/tests/test_etcd.py b/ansible/roles/rke/molecule/default/tests/test_etcd.py
deleted file mode 100644 (file)
index 0f4b6f1..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-import os
-import pytest
-
-import testinfra.utils.ansible_runner
-
-testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
-    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('kubernetes-etcd')
-
-
-@pytest.mark.parametrize('container_name', [
-  'etcd'])
-def test_container_running(host, container_name):
-    assert host.docker(container_name).is_running
index 731f38b..81f90d1 100644 (file)
@@ -1,6 +1,5 @@
 import os
 import pytest
-import json
 
 import testinfra.utils.ansible_runner
 
@@ -11,7 +10,9 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 @pytest.mark.parametrize('filename', [
   '/root/.kube/config',
   '/opt/onap/cluster/cluster.yml',
-  '/opt/onap/cluster/cluster.rkestate'])
+  '/opt/onap/cluster/kubernetes-dashboard.yml',
+  '/opt/onap/cluster/k8s-dashboard-user.yml',
+  '/opt/onap/cluster/kube_config_cluster.yml'])
 def test_file_existence(host, filename):
     assert host.file(filename).exists
 
@@ -22,35 +23,4 @@ def test_rke_in_path(host):
 
 def test_rke_version_works(host):
     # Note that we need to cd to the cluster data dir first, really.
-    assert host.run('cd /opt/onap/cluster && rke version').rc == 0
-
-
-def test_nodes_ready(host):
-    # Retrieve all node names.
-    nodecmdres = host.run('kubectl get nodes -o name')
-    assert nodecmdres.rc == 0
-    nodes = nodecmdres.stdout.split('\n')
-    for node in nodes:
-        assert host.run(
-          'kubectl wait --timeout=0 --for=condition=ready ' + node).rc == 0
-
-
-def test_pods_ready(host):
-    # Retrieve all pods from all namespaces.
-    # Because we need pod and namespace name, we get full json representation.
-    podcmdres = host.run('kubectl get pods --all-namespaces -o json')
-    assert podcmdres.rc == 0
-    pods = json.loads(podcmdres.stdout)['items']
-    for pod in pods:
-        # Each pod may be either created by a job or not.
-        # In job case they should already be completed
-        # when we are here so we ignore them.
-        namespace = pod['metadata']['namespace']
-        podname = pod['metadata']['name']
-        condition = 'Ready'
-        if len(pod['metadata']['ownerReferences']) == 1 and pod[
-          'metadata']['ownerReferences'][0]['kind'] == 'Job':
-            continue
-        assert host.run(
-          'kubectl wait --timeout=240s --for=condition=' + condition + ' -n ' +
-          namespace + ' pods/' + podname).rc == 0
+    assert host.run('cd /opt/onap/cluster && rke').rc == 0
diff --git a/ansible/roles/rke/molecule/default/tests/test_nodes.py b/ansible/roles/rke/molecule/default/tests/test_nodes.py
deleted file mode 100644 (file)
index 6041301..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-import os
-import pytest
-
-import testinfra.utils.ansible_runner
-
-testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
-    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('kubernetes-node')
-
-
-@pytest.mark.parametrize('container_name', [
-  'kubelet', 'kube-proxy'])
-def test_container_running(host, container_name):
-    assert host.docker(container_name).is_running
index 3c91528..a68ceb9 100644 (file)
@@ -52,18 +52,19 @@ provisioner:
   inventory:
     group_vars:
       all:
+        cluster_config_dir: /opt/onap/cluster
         rke_etcd:
           enabled_custom_etcd_storage: false
           storage_path: /var/lib/etcd-custom
           storage_mountpoint: /var/lib/rancher/etcd-custom
           enabled_unsafe_volatile_storage: true
           tmpfs_size: 5G
+  options:
+    e: "app_data_path=/opt/onap"
   playbooks:
     prepare: ../default/prepare.yml
     converge: ../default/playbook.yml
     destroy: ../default/destroy.yml
-  options:
-    e: "app_data_path=/opt/onap"
   lint:
     name: ansible-lint
 scenario:
index 9f254c0..6d81005 100644 (file)
@@ -2,7 +2,6 @@
 - name: Prepare for all
   hosts: all
   roles:
-    - prepare-docker-dind
     - role: prepare-rke
       vars:
         mode: all
index fa5b60e..739dc95 100644 (file)
@@ -1,3 +1,4 @@
 ---
 app_name: moleculeapp
 app_data_path: "/opt/{{ app_name }}"
+cluster_config_dir: "/opt/{{ app_name }}/cluster"
index d4b67c1..7f876ff 100644 (file)
@@ -4,3 +4,6 @@
     name: systemd-user-sessions
     state: started
 
+- name: "Add docker group"
+  group:
+    name: docker
index 8aa93ca..0a0b927 100644 (file)
@@ -4,11 +4,22 @@
     path: "{{ app_data_path }}/downloads"
     state: directory
 
+- name: "Create rke binary wrapper"
+  template:
+    src: rke.j2
+    dest: "{{ app_data_path }}/downloads/rke_linux-amd64"
+    mode: 0755
+
 - name: "Install rke-{{ rke_version }}"
-  command: "curl --connect-timeout 10 -L https://github.com/rancher/rke/releases/download/v{{ rke_version }}/rke_linux-amd64 -o {{ app_data_path }}/downloads/rke_linux-amd64"
+  command: "curl --connect-timeout 10 -L https://github.com/rancher/rke/releases/download/v{{ rke_version }}/rke_linux-amd64 -o {{ app_data_path }}/downloads/rke_linux-amd64_real"
   register: result
   retries: 10
   delay: 1
   until: not result.failed
   args:
     warn: false
+
+- name: "Ensure downloaded rke binary has correct file mode"
+  file:
+    path: "{{ app_data_path }}/downloads/rke_linux-amd64_real"
+    mode: 0755
diff --git a/ansible/test/roles/prepare-rke/templates/rke.j2 b/ansible/test/roles/prepare-rke/templates/rke.j2
new file mode 100644 (file)
index 0000000..ea1267e
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+if [[ $@ =~ 'up' ]];
+then
+  # If the operation is 'rke up' then simulate rke up operation
+  echo $@
+  touch {{ cluster_config_dir }}/kube_config_cluster.yml
+elif [[ $@ =~ 'version' ]];
+then
+  {{ app_data_path }}/downloads/rke_linux-amd64_real version
+  exit 0
+else
+  {{ app_data_path }}/downloads/rke_linux-amd64_real $@
+fi