Skip to content

Commit

Permalink
Run pre-commit hooks to fix python test imports (#3221)
Browse files Browse the repository at this point in the history
* Run pre-commit hooks to fix python test imports

* Add context.minimum_version
  • Loading branch information
lucacome committed Nov 8, 2022
1 parent 20934ae commit 1396149
Show file tree
Hide file tree
Showing 108 changed files with 385 additions and 497 deletions.
20 changes: 10 additions & 10 deletions internal/certmanager/cm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ func (c *CmController) processItem(ctx context.Context, key string) error {
// example, the following Certificate "cert-1" is controlled by the VirtualServer
// "vs-1":
//
// kind: Certificate
// metadata: Note that the owner
// namespace: cert-1 reference does not
// ownerReferences: have a namespace,
// - controller: true since owner refs
// apiVersion: networking.x-k8s.io/v1alpha1 only work inside
// kind: VirtualServer the same namespace.
// name: vs-1
// blockOwnerDeletion: true
// uid: 7d3897c2-ce27-4144-883a-e1b5f89bd65a
// kind: Certificate
// metadata: Note that the owner
// namespace: cert-1 reference does not
// ownerReferences: have a namespace,
// - controller: true since owner refs
// apiVersion: networking.x-k8s.io/v1alpha1 only work inside
// kind: VirtualServer the same namespace.
// name: vs-1
// blockOwnerDeletion: true
// uid: 7d3897c2-ce27-4144-883a-e1b5f89bd65a
func certificateHandler(queue workqueue.RateLimitingInterface) func(obj interface{}) {
return func(obj interface{}) {
crt, ok := obj.(*cmapi.Certificate)
Expand Down
33 changes: 17 additions & 16 deletions internal/certmanager/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,26 @@ var (
// apiVersion: k8s.nginx.org/v1
// kind: VirtualServer
// spec:
// <...>
// tls:
// <...>
// cert-manager:
// common-name: example.com
// duration: 2160h
// renew-before: 1440h
// usages: "digital signature,key encipherment"
//
// <...>
// tls:
// <...>
// cert-manager:
// common-name: example.com
// duration: 2160h
// renew-before: 1440h
// usages: "digital signature,key encipherment"
//
// is mapped to the following Certificate:
//
// kind: Certificate
// spec:
// commonName: example.com
// duration: 2160h
// renewBefore: 1440h
// usages:
// - digital signature
// - key encipherment
// kind: Certificate
// spec:
// commonName: example.com
// duration: 2160h
// renewBefore: 1440h
// usages:
// - digital signature
// - key encipherment
func translateVsSpec(crt *cmapi.Certificate, vsCmSpec *vsapi.CertManager) error {
var errs []string
if crt == nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/certmanager/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ func certNeedsUpdate(a, b *cmapi.Certificate) bool {
// Certificate created for the given VirtualServer resource. We look up the following
// VS TLS Cert-Manager fields:
//
// cluster-issuer
// issuer
// issuer-kind
// issuer-group
// cluster-issuer
// issuer
// issuer-kind
// issuer-group
func issuerForVirtualServer(vs *vsapi.VirtualServer) (name, kind, group string, err error) {
var errs []string
vsCmSpec := vs.Spec.TLS.CertManager
Expand Down
2 changes: 1 addition & 1 deletion internal/configs/version1/nginx.ingress.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ server {

{{range $location := $server.Locations}}
location {{$location.Path}} {
set $service "{{$location.ServiceName}}";
set $service "{{$location.ServiceName}}";
{{with $location.MinionIngress}}
# location for minion {{$location.MinionIngress.Namespace}}/{{$location.MinionIngress.Name}}
set $resource_name "{{$location.MinionIngress.Name}}";
Expand Down
2 changes: 1 addition & 1 deletion internal/configs/version2/nginx.transportserver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ server {
proxy_next_upstream_timeout {{ $s.ProxyNextUpstreamTimeout }};
proxy_next_upstream_tries {{ $s.ProxyNextUpstreamTries }};
{{ end }}
}
}
12 changes: 6 additions & 6 deletions perf-tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
PyYAML==6.0
requests==2.28.1
certifi==2022.9.24
cffi==1.15.1
kubernetes==25.3.0
locust==2.13.0
pytest==7.2.0
cffi==1.15.1
certifi==2022.9.24
urllib3==1.26.12
pytest-html==3.2.0
pytest-repeat==0.9.1
locust==2.13.0
PyYAML==6.0
requests==2.28.1
urllib3==1.26.12
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pythonpath = [
".",
"tests/suite",
"tests/suite/grpc",
"tests/suite/fixtures",
"tests/suite/utils",
]
addopts = "--tb=native -ra --disable-warnings -x -l --profile -v"
log_cli = true
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
NS_COUNT,
NUM_REPLICAS,
)
from suite.resources_utils import get_first_pod_name
from suite.utils.resources_utils import get_first_pod_name


def pytest_addoption(parser) -> None:
Expand Down Expand Up @@ -111,7 +111,7 @@ def pytest_addoption(parser) -> None:


# import fixtures into pytest global namespace
pytest_plugins = ["suite.fixtures", "suite.ic_fixtures", "suite.custom_resource_fixtures"]
pytest_plugins = ["suite.fixtures.fixtures", "suite.fixtures.ic_fixtures", "suite.fixtures.custom_resource_fixtures"]


def pytest_collection_modifyitems(config, items) -> None:
Expand Down
7 changes: 0 additions & 7 deletions tests/kind/kind-config-template.yaml

This file was deleted.

22 changes: 11 additions & 11 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
PyYAML==6.0
requests==2.28.1
certifi==2022.9.24
cffi==1.15.1
flaky==3.7.0
forcediphttpsadapter==1.0.2
grpcio==1.50.0
grpcio-tools==1.50.0
kubernetes==25.3.0
pytest==7.2.0
cffi==1.15.1
mock==4.0.3
more-itertools==9.0.0
pyOpenSSL==22.1.0
certifi==2022.9.24
urllib3==1.26.12
pytest==7.2.0
pytest-html==3.2.0
pytest-profiling==1.7.0
more-itertools==9.0.0
mock==4.0.3
grpcio==1.50.0
grpcio-tools==1.50.0
flaky==3.7.0
PyYAML==6.0
requests==2.28.1
urllib3==1.26.12
1 change: 0 additions & 1 deletion tests/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Describe project settings"""
import os

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Describe project shared pytest fixtures related to setup of custom resources and apps."""

import pytest
import yaml
from settings import TEST_DATA
from suite.custom_resources_utils import create_gc_from_yaml, create_ts_from_yaml, delete_gc, delete_ts
from suite.fixtures import PublicEndpoint
from suite.resources_utils import (
from suite.fixtures.fixtures import PublicEndpoint
from suite.utils.custom_resources_utils import create_gc_from_yaml, create_ts_from_yaml, delete_gc, delete_ts
from suite.utils.resources_utils import (
create_deployment_with_name,
create_example_app,
create_items_from_yaml,
Expand All @@ -19,13 +18,13 @@
get_first_pod_name,
wait_until_all_pods_are_ready,
)
from suite.vs_vsr_resources_utils import (
from suite.utils.vs_vsr_resources_utils import (
create_v_s_route_from_yaml,
create_virtual_server_from_yaml,
delete_v_s_route,
delete_virtual_server,
)
from suite.yaml_utils import (
from suite.utils.yaml_utils import (
get_first_host_from_yaml,
get_paths_from_vs_yaml,
get_paths_from_vsr_yaml,
Expand Down
8 changes: 4 additions & 4 deletions tests/suite/fixtures.py → tests/suite/fixtures/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
)
from kubernetes.client.rest import ApiException
from settings import ALLOWED_DEPLOYMENT_TYPES, ALLOWED_IC_TYPES, ALLOWED_SERVICE_TYPES, DEPLOYMENTS, TEST_DATA
from suite.custom_resources_utils import create_crd_from_yaml, delete_crd
from suite.kube_config_utils import ensure_context_in_config, get_current_context_name
from suite.resources_utils import (
from suite.utils.custom_resources_utils import create_crd_from_yaml, delete_crd
from suite.utils.kube_config_utils import ensure_context_in_config, get_current_context_name
from suite.utils.resources_utils import (
cleanup_rbac,
configure_rbac,
create_configmap_from_yaml,
Expand All @@ -34,7 +34,7 @@
wait_before_test,
wait_for_public_ip,
)
from suite.yaml_utils import get_name_from_yaml
from suite.utils.yaml_utils import get_name_from_yaml


class KubeApis:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import time

import pytest
import yaml
from kubernetes.client.rest import ApiException
from settings import DEPLOYMENTS, TEST_DATA
from suite.custom_resources_utils import create_crd_from_yaml, delete_crd
from suite.resources_utils import (
from suite.utils.custom_resources_utils import create_crd_from_yaml, delete_crd
from suite.utils.resources_utils import (
cleanup_rbac,
configure_rbac_with_ap,
configure_rbac_with_dos,
Expand All @@ -22,7 +21,7 @@
replace_configmap_from_yaml,
wait_until_all_pods_are_ready,
)
from suite.yaml_utils import get_name_from_yaml
from suite.utils.yaml_utils import get_name_from_yaml


@pytest.fixture(scope="class")
Expand Down
11 changes: 4 additions & 7 deletions tests/suite/test_ac_policies.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import json

import pytest
import requests
from kubernetes.client.rest import ApiException
from settings import DEPLOYMENTS, TEST_DATA
from suite.custom_resources_utils import read_custom_resource
from suite.policy_resources_utils import create_policy_from_yaml, delete_policy, read_policy
from suite.resources_utils import (
from suite.utils.custom_resources_utils import read_custom_resource
from suite.utils.policy_resources_utils import create_policy_from_yaml, delete_policy
from suite.utils.resources_utils import (
get_last_reload_time,
get_test_file_name,
replace_configmap_from_yaml,
wait_before_test,
write_to_json,
)
from suite.vs_vsr_resources_utils import (
from suite.utils.vs_vsr_resources_utils import (
create_virtual_server_from_yaml,
delete_virtual_server,
patch_virtual_server_from_yaml,
Expand Down
14 changes: 4 additions & 10 deletions tests/suite/test_ac_policies_vsr.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import pytest
import requests
from kubernetes.client.rest import ApiException
from settings import DEPLOYMENTS, TEST_DATA
from suite.custom_resources_utils import read_custom_resource
from suite.policy_resources_utils import create_policy_from_yaml, delete_policy, read_policy
from suite.resources_utils import replace_configmap_from_yaml, wait_before_test
from suite.vs_vsr_resources_utils import (
create_virtual_server_from_yaml,
delete_virtual_server,
patch_v_s_route_from_yaml,
patch_virtual_server_from_yaml,
)
from suite.utils.custom_resources_utils import read_custom_resource
from suite.utils.policy_resources_utils import create_policy_from_yaml, delete_policy
from suite.utils.resources_utils import replace_configmap_from_yaml, wait_before_test
from suite.utils.vs_vsr_resources_utils import patch_v_s_route_from_yaml, patch_virtual_server_from_yaml

std_cm_src = f"{DEPLOYMENTS}/common/nginx-config.yaml"
test_cm_src = f"{TEST_DATA}/access-control/configmap/nginx-config.yaml"
Expand Down
8 changes: 4 additions & 4 deletions tests/suite/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import yaml
from kubernetes.client import NetworkingV1Api
from settings import DEPLOYMENTS, TEST_DATA
from suite.custom_assertions import assert_event_count_increased
from suite.fixtures import PublicEndpoint
from suite.resources_utils import (
from suite.fixtures.fixtures import PublicEndpoint
from suite.utils.custom_assertions import assert_event_count_increased
from suite.utils.resources_utils import (
create_example_app,
create_items_from_yaml,
delete_common_app,
Expand All @@ -19,7 +19,7 @@
wait_before_test,
wait_until_all_pods_are_ready,
)
from suite.yaml_utils import get_first_ingress_host_from_yaml, get_name_from_yaml
from suite.utils.yaml_utils import get_first_ingress_host_from_yaml, get_name_from_yaml


def get_event_count(event_text, events_list) -> int:
Expand Down
10 changes: 4 additions & 6 deletions tests/suite/test_app_protect.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import json

import pytest
import requests
from settings import DEPLOYMENTS, TEST_DATA
from suite.ap_resources_utils import (
from settings import TEST_DATA
from suite.utils.ap_resources_utils import (
create_ap_logconf_from_yaml,
create_ap_policy_from_yaml,
delete_ap_logconf,
delete_ap_policy,
)
from suite.resources_utils import (
from suite.utils.resources_utils import (
create_example_app,
create_ingress_with_ap_annotations,
create_items_from_yaml,
Expand All @@ -23,7 +21,7 @@
wait_until_all_pods_are_ready,
write_to_json,
)
from suite.yaml_utils import get_first_ingress_host_from_yaml
from suite.utils.yaml_utils import get_first_ingress_host_from_yaml

ap_policies_under_test = ["dataguard-alarm", "file-block", "malformed-block"]
valid_resp_addr = "Server address:"
Expand Down
13 changes: 6 additions & 7 deletions tests/suite/test_app_protect_grpc.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import grpc
import pytest
from settings import DEPLOYMENTS, TEST_DATA
from suite.ap_resources_utils import (
from suite.grpc.helloworld_pb2 import HelloRequest
from suite.grpc.helloworld_pb2_grpc import GreeterStub
from suite.utils.ap_resources_utils import (
create_ap_logconf_from_yaml,
create_ap_policy_from_yaml,
delete_ap_logconf,
delete_ap_policy,
)
from suite.grpc.helloworld_pb2 import HelloRequest
from suite.grpc.helloworld_pb2_grpc import GreeterStub
from suite.resources_utils import (
from suite.utils.resources_utils import (
create_example_app,
create_ingress_with_ap_annotations,
create_items_from_yaml,
delete_common_app,
delete_items_from_yaml,
get_file_contents,
get_service_endpoint,
replace_configmap_from_yaml,
wait_before_test,
wait_until_all_pods_are_ready,
)
from suite.ssl_utils import get_certificate
from suite.yaml_utils import get_first_ingress_host_from_yaml
from suite.utils.ssl_utils import get_certificate
from suite.utils.yaml_utils import get_first_ingress_host_from_yaml

log_loc = f"/var/log/messages"
valid_resp_txt = "Hello"
Expand Down

0 comments on commit 1396149

Please sign in to comment.