github.com/SUSE/skuba@v1.4.17/ci/infra/testrunner/tests/test_cpi_openstack.py (about)

     1  import pytest
     2  import os
     3  import platforms
     4  from skuba import Skuba
     5  from utils import BaseConfig
     6  from tests.utils import (check_pods_ready, wait)
     7  
     8  CINDER_YAML = '''
     9  apiVersion: storage.k8s.io/v1
    10  kind: StorageClass
    11  metadata:
    12    name: gold
    13  provisioner: kubernetes.io/cinder
    14  parameters:
    15    availability: nova
    16  ---
    17  apiVersion: v1
    18  kind: PersistentVolumeClaim
    19  metadata:
    20    name: cinder-claim
    21    annotations:
    22      volume.beta.kubernetes.io/storage-class: gold
    23  spec:
    24    accessModes:
    25      - ReadWriteOnce
    26    resources:
    27      requests:
    28        storage: 1Gi
    29    storageClassName: gold
    30  '''
    31  
    32  TEST_READ_POD = '''
    33  apiVersion: v1
    34  kind: Pod
    35  metadata:
    36    name: read-pod
    37  spec:
    38    containers:
    39    - name: read-pod
    40      image: gcr.io/google_containers/busybox:1.24
    41      command:
    42        - "/bin/sh"
    43      args:
    44        - "-c"
    45        - "test -f /mnt/SUCCESS && exit 0 || exit 1"
    46      volumeMounts:
    47        - name: cinder
    48          mountPath: "/mnt"
    49    restartPolicy: "Never"
    50    volumes:
    51      - name: cinder
    52        persistentVolumeClaim:
    53          claimName: cinder-claim
    54  '''
    55  
    56  TEST_WRITE_POD = '''
    57  apiVersion: v1
    58  kind: Pod
    59  metadata:
    60    name: write-pod
    61  spec:
    62    containers:
    63    - name: write-pod
    64      image: gcr.io/google_containers/busybox:1.24
    65      command:
    66        - "/bin/sh"
    67      args:
    68        - "-c"
    69        - "touch /mnt/SUCCESS && exit 0 || exit 1"
    70      volumeMounts:
    71        - name: cinder
    72          mountPath: "/mnt"
    73    restartPolicy: "Never"
    74    volumes:
    75      - name: cinder
    76        persistentVolumeClaim:
    77          claimName: cinder-claim
    78  '''
    79  
    80  
    81  @pytest.fixture(autouse=True, scope='module')
    82  def conf(request):
    83      """Builds a conf object from a yaml file"""
    84      path = request.config.getoption("vars")
    85      return BaseConfig(path)
    86  
    87  
    88  @pytest.fixture(autouse=True, scope='module')
    89  def target(request):
    90      """Returns the target platform"""
    91      platform = request.config.getoption("platform")
    92      return platform
    93  
    94  
    95  @pytest.fixture(autouse=True, scope='module')
    96  def platform(conf, target):
    97      platform = platforms.get_platform(conf, target)
    98      return platform
    99  
   100  
   101  @pytest.fixture(autouse=True, scope='module')
   102  def skuba(conf, target):
   103      return Skuba(conf, target)
   104  
   105  
   106  @pytest.fixture(autouse=True, scope='module')
   107  def setup(request, platform, skuba, conf):
   108      def cleanup():
   109          platform.cleanup()
   110          skuba.cleanup(conf)
   111  
   112      request.addfinalizer(cleanup)
   113      platform.provision(num_master=1, num_worker=3)
   114  
   115  
   116  @pytest.mark.disruptive
   117  @pytest.mark.openstack
   118  @pytest.mark.run(order=1)
   119  def test_init_cpi_openstack_cluster(skuba, kubernetes_version=None):
   120      """
   121      Initialize the cluster with the openstack cpi
   122      """
   123      skuba.cluster_init(kubernetes_version, cloud_provider="openstack")
   124  
   125  @pytest.mark.disruptive
   126  @pytest.mark.openstack
   127  @pytest.mark.run(order=2)
   128  def test_bootstrap_cpi_openstack_cluster(skuba):
   129      """
   130      Bootstrap the cluster with the openstack cpi
   131      """
   132      skuba.node_bootstrap(cloud_provider="openstack")
   133  
   134  
   135  @pytest.mark.disruptive
   136  @pytest.mark.openstack
   137  @pytest.mark.run(order=3)
   138  def test_node_join_cpi_openstack_cluster(skuba, kubectl):
   139      """
   140      Join nodes to the cluster with the openstack cpi enabled
   141      """
   142      skuba.join_nodes(masters=1, workers=3)
   143  
   144      wait(check_pods_ready,
   145           kubectl,
   146           namespace="kube-system",
   147           wait_delay=60,
   148           wait_timeout=10,
   149           wait_backoff=30,
   150           wait_elapsed=300,
   151           wait_allow=(AssertionError))
   152  
   153  
   154  @pytest.mark.disruptive
   155  @pytest.mark.openstack
   156  @pytest.mark.run(order=4)
   157  def test_create_cinder_storage(kubectl, skuba):
   158          # TODO: result of action is successful  
   159          kubectl.run_kubectl(" apply -f -", stdin=CINDER_YAML.encode())
   160  
   161  
   162  @pytest.mark.disruptive
   163  @pytest.mark.openstack
   164  @pytest.mark.run(order=5)
   165  def test_wrtite_cinder_storage(kubectl, skuba):
   166      kubectl.run_kubectl("apply -f -", stdin=TEST_WRITE_POD.encode())
   167  
   168      wait(
   169          check_pods_ready,
   170          kubectl,
   171          pods=["write-pod"],
   172          statuses=["Succeeded"],
   173          wait_delay=60,
   174          wait_retries=1,
   175          wait_allow=(AssertionError))
   176  
   177  @pytest.mark.disruptive
   178  @pytest.mark.openstack
   179  @pytest.mark.run(order=6)
   180  def test_read_cinder_storage(kubectl, skuba):
   181      kubectl.run_kubectl(" apply -f -", stdin=TEST_READ_POD.encode())
   182  
   183      wait(
   184          check_pods_ready,
   185          kubectl,
   186          pods=["read-pod"],
   187          statuses=["Succeeded"],
   188          wait_delay=60,
   189          wait_retries=1,
   190          wait_allow=(AssertionError))