github.com/nginxinc/kubernetes-ingress@v1.12.5/tests/suite/test_v_s_route_status.py (about)

     1  import pytest
     2  from kubernetes.client.rest import ApiException
     3  from suite.resources_utils import wait_before_test
     4  from suite.custom_resources_utils import (
     5      read_custom_resource,
     6      patch_virtual_server_from_yaml,
     7      patch_v_s_route_from_yaml,
     8      delete_virtual_server,
     9      create_virtual_server_from_yaml,
    10  )
    11  from settings import TEST_DATA
    12  
    13  @pytest.mark.vsr
    14  @pytest.mark.parametrize(
    15      "crd_ingress_controller, v_s_route_setup",
    16      [
    17          (
    18              {"type": "complete", "extra_args": [f"-enable-custom-resources", f"-enable-leader-election=false"],},
    19              {"example": "virtual-server-route-status"},
    20          )
    21      ],
    22      indirect=True,
    23  )
    24  class TestVirtualServerRouteStatus:
    25      def patch_valid_vsr(self, kube_apis, v_s_route_setup) -> None:
    26          """
    27          Function to revert vsr deployments to valid state
    28          """
    29          patch_src_m = f"{TEST_DATA}/virtual-server-route-status/route-multiple.yaml"
    30          patch_v_s_route_from_yaml(
    31              kube_apis.custom_objects,
    32              v_s_route_setup.route_m.name,
    33              patch_src_m,
    34              v_s_route_setup.route_m.namespace,
    35          )
    36          wait_before_test()
    37          patch_src_s = f"{TEST_DATA}/virtual-server-route-status/route-single.yaml"
    38          patch_v_s_route_from_yaml(
    39              kube_apis.custom_objects,
    40              v_s_route_setup.route_s.name,
    41              patch_src_s,
    42              v_s_route_setup.route_s.namespace,
    43          )
    44          wait_before_test()
    45  
    46      def patch_valid_vs(self, kube_apis, v_s_route_setup) -> None:
    47          """
    48          Function to revert vs deployment to valid state
    49          """
    50          patch_src = f"{TEST_DATA}/virtual-server-route-status/standard/virtual-server.yaml"
    51          patch_virtual_server_from_yaml(
    52              kube_apis.custom_objects, v_s_route_setup.vs_name, patch_src, v_s_route_setup.namespace,
    53          )
    54          wait_before_test()
    55  
    56      @pytest.mark.smoke
    57      def test_status_valid(
    58          self, kube_apis, crd_ingress_controller, v_s_route_setup, v_s_route_app_setup
    59      ):
    60          """
    61          Test VirtualServerRoute status with a valid fields in yaml
    62          """
    63          response_m = read_custom_resource(
    64              kube_apis.custom_objects,
    65              v_s_route_setup.route_m.namespace,
    66              "virtualserverroutes",
    67              v_s_route_setup.route_m.name,
    68          )
    69          response_s = read_custom_resource(
    70              kube_apis.custom_objects,
    71              v_s_route_setup.route_s.namespace,
    72              "virtualserverroutes",
    73              v_s_route_setup.route_s.name,
    74          )
    75          assert (
    76              response_m["status"]
    77              and response_m["status"]["reason"] == "AddedOrUpdated"
    78              and response_m["status"]["referencedBy"]
    79              and response_m["status"]["state"] == "Valid"
    80          )
    81  
    82          assert (
    83              response_s["status"]
    84              and response_s["status"]["reason"] == "AddedOrUpdated"
    85              and response_s["status"]["referencedBy"]
    86              and response_s["status"]["state"] == "Valid"
    87          )
    88  
    89      def test_status_invalid(
    90          self, kube_apis, crd_ingress_controller, v_s_route_setup, v_s_route_app_setup
    91      ):
    92          """
    93          Test VirtualServerRoute status with a invalid paths in vsr yaml
    94          """
    95          patch_src_m = f"{TEST_DATA}/virtual-server-route-status/route-multiple-invalid.yaml"
    96          patch_v_s_route_from_yaml(
    97              kube_apis.custom_objects,
    98              v_s_route_setup.route_m.name,
    99              patch_src_m,
   100              v_s_route_setup.route_m.namespace,
   101          )
   102          wait_before_test()
   103          patch_src_s = f"{TEST_DATA}/virtual-server-route-status/route-single-invalid.yaml"
   104          patch_v_s_route_from_yaml(
   105              kube_apis.custom_objects,
   106              v_s_route_setup.route_s.name,
   107              patch_src_s,
   108              v_s_route_setup.route_s.namespace,
   109          )
   110          wait_before_test()
   111  
   112          response_m = read_custom_resource(
   113              kube_apis.custom_objects,
   114              v_s_route_setup.route_m.namespace,
   115              "virtualserverroutes",
   116              v_s_route_setup.route_m.name,
   117          )
   118          response_s = read_custom_resource(
   119              kube_apis.custom_objects,
   120              v_s_route_setup.route_s.namespace,
   121              "virtualserverroutes",
   122              v_s_route_setup.route_s.name,
   123          )
   124  
   125          self.patch_valid_vsr(kube_apis, v_s_route_setup)
   126          assert (
   127              response_m["status"]
   128              and response_m["status"]["reason"] == "Rejected"
   129              and not response_m["status"]["referencedBy"]
   130              and response_m["status"]["state"] == "Invalid"
   131          )
   132  
   133          assert (
   134              response_s["status"]
   135              and response_s["status"]["reason"] == "Rejected"
   136              and not response_s["status"]["referencedBy"]
   137              and response_s["status"]["state"] == "Invalid"
   138          )
   139      
   140      def test_status_invalid_prefix(
   141          self, kube_apis, crd_ingress_controller, v_s_route_setup, v_s_route_app_setup
   142      ):
   143          """
   144          Test VirtualServerRoute status with a invalid path /prefix in vsr yaml
   145          i.e. referring to non-existing path
   146          """
   147          patch_src_m = f"{TEST_DATA}/virtual-server-route-status/route-multiple-invalid-prefixed-path.yaml"
   148          patch_v_s_route_from_yaml(
   149              kube_apis.custom_objects,
   150              v_s_route_setup.route_m.name,
   151              patch_src_m,
   152              v_s_route_setup.route_m.namespace,
   153          )
   154          wait_before_test()
   155          patch_src_s = f"{TEST_DATA}/virtual-server-route-status/route-single-invalid-prefixed-path.yaml"
   156          patch_v_s_route_from_yaml(
   157              kube_apis.custom_objects,
   158              v_s_route_setup.route_s.name,
   159              patch_src_s,
   160              v_s_route_setup.route_s.namespace,
   161          )
   162          wait_before_test()
   163  
   164          response_m = read_custom_resource(
   165              kube_apis.custom_objects,
   166              v_s_route_setup.route_m.namespace,
   167              "virtualserverroutes",
   168              v_s_route_setup.route_m.name,
   169          )
   170          response_s = read_custom_resource(
   171              kube_apis.custom_objects,
   172              v_s_route_setup.route_s.namespace,
   173              "virtualserverroutes",
   174              v_s_route_setup.route_s.name,
   175          )
   176  
   177          self.patch_valid_vsr(kube_apis, v_s_route_setup)
   178          assert (
   179              response_m["status"]
   180              and response_m["status"]["reason"] == "AddedOrUpdated"
   181              and response_m["status"]["referencedBy"]
   182              and response_m["status"]["state"] == "Valid"
   183          )
   184  
   185          assert (
   186              response_s["status"]
   187              and response_s["status"]["reason"] == "Ignored"
   188              and not response_s["status"]["referencedBy"]
   189              and response_s["status"]["state"] == "Warning"
   190          )
   191  
   192      def test_status_invalid_vsr_in_vs(
   193          self, kube_apis, crd_ingress_controller, v_s_route_setup, v_s_route_app_setup
   194      ):
   195          """
   196          Test VirtualServerRoute status with invalid vsr reference in vs yaml
   197          """
   198  
   199          patch_src = f"{TEST_DATA}/virtual-server-route-status/virtual-server-invalid.yaml"
   200          patch_virtual_server_from_yaml(
   201              kube_apis.custom_objects, v_s_route_setup.vs_name, patch_src, v_s_route_setup.namespace,
   202          )
   203          wait_before_test()
   204  
   205          response_m = read_custom_resource(
   206              kube_apis.custom_objects,
   207              v_s_route_setup.route_m.namespace,
   208              "virtualserverroutes",
   209              v_s_route_setup.route_m.name,
   210          )
   211          response_s = read_custom_resource(
   212              kube_apis.custom_objects,
   213              v_s_route_setup.route_s.namespace,
   214              "virtualserverroutes",
   215              v_s_route_setup.route_s.name,
   216          )
   217          self.patch_valid_vs(kube_apis, v_s_route_setup)
   218          assert (
   219              response_m["status"]
   220              and response_m["status"]["reason"] == "Ignored"
   221              and not response_m["status"]["referencedBy"]
   222              and response_m["status"]["state"] == "Warning"
   223          )
   224  
   225          assert (
   226              response_s["status"]
   227              and response_s["status"]["reason"] == "Ignored"
   228              and not response_s["status"]["referencedBy"]
   229              and response_s["status"]["state"] == "Warning"
   230          )
   231  
   232      def test_status_remove_vs(
   233          self, kube_apis, crd_ingress_controller, v_s_route_setup, v_s_route_app_setup
   234      ):
   235          """
   236          Test VirtualServerRoute status after deleting referenced VirtualServer
   237          """
   238          delete_virtual_server(
   239              kube_apis.custom_objects, v_s_route_setup.vs_name, v_s_route_setup.namespace,
   240          )
   241  
   242          response_m = read_custom_resource(
   243              kube_apis.custom_objects,
   244              v_s_route_setup.route_m.namespace,
   245              "virtualserverroutes",
   246              v_s_route_setup.route_m.name,
   247          )
   248          response_s = read_custom_resource(
   249              kube_apis.custom_objects,
   250              v_s_route_setup.route_s.namespace,
   251              "virtualserverroutes",
   252              v_s_route_setup.route_s.name,
   253          )
   254  
   255          vs_src = f"{TEST_DATA}/virtual-server-route-status/standard/virtual-server.yaml"
   256          create_virtual_server_from_yaml(kube_apis.custom_objects, vs_src, v_s_route_setup.namespace)
   257  
   258          assert (
   259              response_m["status"]
   260              and response_m["status"]["reason"] == "NoVirtualServerFound"
   261              and not response_m["status"]["referencedBy"]
   262              and response_m["status"]["state"] == "Warning"
   263          )
   264  
   265          assert (
   266              response_s["status"]
   267              and response_s["status"]["reason"] == "NoVirtualServerFound"
   268              and not response_s["status"]["referencedBy"]
   269              and response_s["status"]["state"] == "Warning"
   270          )