Skip to content

Commit

Permalink
change behaviour of ProxyPromote object and mapping rules availabilit…
Browse files Browse the repository at this point in the history
…y in promoted proxies
  • Loading branch information
mkudlej committed Feb 19, 2024
1 parent d350ecb commit 0949d23
Show file tree
Hide file tree
Showing 15 changed files with 271 additions and 109 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
flake8 = "*"
mypy = "*"
pylint = "*"
pytest = "*"
pytest = "<8.0.0"
python-dotenv = "*"
backoff = "*"
responses = "*"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ see https://github.com/3scale/3scale-operator/blob/master/doc/backend-reference.
Command to run integration unit tests: `pipenv run pytest --log-cli-level=10 -vvvv -s ./tests/integration/ |& tee x`

### TODO
- do https://github.com/3scale/3scale-operator/pull/813
- do not simulate app plan id
- create unit integration tests for:
- ProductDeploymentSpec
Expand Down
2 changes: 2 additions & 0 deletions get_exports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ACCESS_TOKEN="$(curl -X POST "${DOMAIN}/admin/api/personal/access_tokens.json" -
echo "Create secret with ${DOMAIN} ${ACCESS_TOKEN}"

oc create secret --namespace=${NAMESPACE} generic ${SEC_NAME} --from-literal="adminURL=${DOMAIN}" --from-literal="token=${ACCESS_TOKEN}"
oc label secret/${SEC_NAME} capabilities=''

echo "export THREESCALE_PROVIDER_URL=\"${DOMAIN}\"" >> gen_exports.sh
echo "export THREESCALE_PROVIDER_TOKEN=\"${ACCESS_TOKEN}\"" >> gen_exports.sh
Expand All @@ -44,6 +45,7 @@ ACCESS_TOKEN="$(curl -X POST "${DOMAIN}/admin/api/personal/access_tokens.json" -
echo "Create master secret with ${DOMAIN} ${ACCESS_TOKEN}"

oc create secret --namespace=${NAMESPACE} generic ${SEC_NAME} --from-literal="MASTER_ACCESS_TOKEN=${ACCESS_TOKEN}"
oc label secret/${SEC_NAME} capabilities=''

echo "export THREESCALE_MASTER_URL=\"${DOMAIN}\"" >> gen_exports.sh
echo "export THREESCALE_MASTER_TOKEN=\"${ACCESS_TOKEN}\"" >> gen_exports.sh
13 changes: 9 additions & 4 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def backend_updated_usage_params(backend_usage_params):

@pytest.fixture(scope='module')
def backend_usage(service, backend, backend_usage_params) -> BackendUsage:
service = service.read()
resource = service.backend_usages.create(params=backend_usage_params)
yield resource
cleanup(resource)
Expand Down Expand Up @@ -258,6 +259,7 @@ def method(hits_metric, method_params):
resource = hits_metric.methods.create(params=method_params)
yield resource
cleanup(resource)
#service.proxy.deploy()


@pytest.fixture(scope='module')
Expand Down Expand Up @@ -314,23 +316,26 @@ def updated_backend_mapping_rules_params(backend_mapping_rule_params):


@pytest.fixture(scope='module')
def mapping_rule(service, mapping_rule_params) -> MappingRule:
def mapping_rule(service, mapping_rule_params, proxy) -> MappingRule:
"""
Fixture for getting mapping rule for product/service.
"""
resource = service.mapping_rules.create(params=mapping_rule_params)
yield resource
cleanup(resource)
proxy.deploy()


@pytest.fixture(scope='module')
def backend_mapping_rule(backend, backend_metric, backend_mapping_rule_params) -> BackendMappingRule:
def backend_mapping_rule(backend, backend_metric, backend_mapping_rule_params, service, proxy, backend_usage) -> BackendMappingRule:
"""
Fixture for getting mapping rule for backend.
"""
backend = backend.read()
resource = backend.mapping_rules.create(params=backend_mapping_rule_params)
yield resource
cleanup(resource)
proxy.deploy()


@pytest.fixture(scope='module')
Expand Down Expand Up @@ -428,7 +433,7 @@ def tenant_params():
"""
return dict(name=f"tenant{get_suffix()}",
admin_password="123456",
email="email@invalid.invalid",
email=f"e{get_suffix()}@invalid.invalid",
org_name="org")


Expand Down Expand Up @@ -467,7 +472,7 @@ def openapi_params(active_docs_body):
name=name,
productionPublicBaseURL='http://productionPublicBaseURL',
stagingPublicBaseURL='http://stagingPublicBaseURL',
productSystemName='productsystemname', # https://issues.redhat.com/browse/THREESCALE-8128
productSystemName='PrOdUcTsYsTeMnAmE',
privateBaseURL='http://privateBaseURL',
prefixMatching=True,
privateAPIHostHeader='privateAPIHostHeader',
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_integration_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_application_update(update_application_params, application):
# changing application state tests

def test_application_set_state(application):
application.set_state('suspend')
application = application.set_state('suspend')
assert application['state'] == 'suspended'
application.set_state('resume')
application = application.set_state('resume')
assert application['state'] == 'live'
4 changes: 2 additions & 2 deletions tests/integration/test_integration_backend_mapping_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ def test_should_update_mapping_rule(service, backend, backend_usage, backend_map
response = apicast_http_client.get(path=resource['pattern'])
asserts.assert_http_ok(response)
resource.delete()
service.proxy.deploy()

# end of tests important for CRD - CRU + list


def test_should_mapping_rule_endpoint_return_ok(service, backend,
backend_usage, backend_mapping_rule, application, apicast_http_client):
backend_mapping_rule.update()
service.proxy.deploy()
response = apicast_http_client.get(path=f"{backend_mapping_rule['pattern']}")
asserts.assert_http_ok(response)

Expand All @@ -67,3 +66,4 @@ def test_stop_processing_mapping_rules_once_first_one_is_met(service,

resource_first.delete()
resource_second.delete()
service.proxy.deploy()
2 changes: 2 additions & 0 deletions tests/integration/test_integration_backend_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def test_should_apicast_return_403_when_metric_is_disabled(
assert response.status_code == 403
back_lim.delete()
back_mapping.delete()
proxy.deploy()
back_metric.delete()


Expand Down Expand Up @@ -102,6 +103,7 @@ def test_should_apicast_return_429_when_limits_exceeded(
assert response.status_code == 429
back_lim.delete()
back_mapping.delete()
proxy.deploy()
back_metric.delete()


Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_integration_backend_usages.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def test_should_list_backend_usages(backend, service, backend_usage):
assert len(service.backend_usages.list()) > 0
assert len(backend.usages.list()) > 0
assert len(backend.usages()) > 0

def test_should_create_backend_usage(backend_usage, backend_usage_params):
asserts.assert_resource(backend_usage)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_integration_openapis.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_openapi_can_be_read(api, openapi_params, openapi):
def test_openapi_can_be_updated(api, openapi):
des_changed = (openapi['productSystemName'] or '') + '_changed'
openapi['productSystemName'] = des_changed
gg = openapi.update()
openapi.update()
assert openapi['productSystemName'] == des_changed
updated = openapi.read()
assert updated['productSystemName'] == des_changed
Expand Down
10 changes: 7 additions & 3 deletions tests/integration/test_integration_promotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@

# tests important for CRD - CRU + list

# these tests should run in sequence because operator client checks if there are any changes in the product

@pytest.mark.order(1)
def test_promote_list(api, promote):
promotes = api.promotes.list()
assert len(promotes) >= 1


@pytest.mark.order(2)
def test_promote_can_be_created(promote_params, promote):
asserts.assert_resource(promote)
asserts.assert_resource_params(promote, promote_params)


@pytest.mark.order(3)
def test_promote_can_be_read(api, promote, promote_params):
read = api.promotes.read(promote.entity_id)
asserts.assert_resource(read)
asserts.assert_resource_params(read, promote_params)


@pytest.mark.order(4)
def test_promote_can_be_updated(api, promote):
lcount = api.promotes.list()
promote['deleteCR'] = False
Expand All @@ -33,8 +38,7 @@ def test_promote_can_be_updated(api, promote):

# end of tests important for CRD - CRU + list

# these tests should run in sequence
@pytest.mark.order(1)
@pytest.mark.order(5)
def test_promote_to_production(api, mapping_rule, proxy, backend_usage):
"""
Promotes to production. This promotion actually promotes to staging first and then to production.
Expand All @@ -43,7 +47,7 @@ def test_promote_to_production(api, mapping_rule, proxy, backend_usage):
mapping_rule.update()
proxy.promote()

@pytest.mark.order(2)
@pytest.mark.order(6)
def test_promote_only_to_staging(api, mapping_rule, proxy, backend_usage):
"""
Promotes to staging only.
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/test_integration_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def test_service_list_configs(service, proxy, backend_usage):


def test_service_proxy_configs_version(service, proxy, backend_usage):
service.proxy.list().deploy()
config = service.proxy.list().configs.version(version=1)
assert config
assert config['environment'] == "sandbox"
Expand All @@ -107,7 +106,6 @@ def test_service_proxy_configs_version(service, proxy, backend_usage):


def test_service_proxy_configs_latest(service, proxy, backend_usage):
service.proxy.list().deploy()
config = service.proxy.list().configs.latest()
assert config
assert config['environment'] == "sandbox"
Expand Down
2 changes: 1 addition & 1 deletion threescale_api_crd/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module with ThreeScaleClient for CRD.
"""

import openshift as ocp
import openshift_client as ocp
import threescale_api
from threescale_api_crd import resources

Expand Down
17 changes: 16 additions & 1 deletion threescale_api_crd/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@
}
}



SPEC_TENANT = {
'apiVersion': 'capabilities.3scale.net/v1alpha1',
'kind': 'Tenant',
Expand Down Expand Up @@ -536,7 +538,20 @@
'privateBaseURL': 'privateBaseURL',
'prefixMatching': 'prefixMatching',
'privateAPIHostHeader': 'privateAPIHostHeader',
'privateAPISecretToken': 'privateAPISecretToken'
'privateAPISecretToken': 'privateAPISecretToken',
'oidc': 'oidc'
}

KEYS_OPEN_API_OIDC = {
'issuerEndpoint': 'issuerEndpoint',
'issuerEndpointRef': 'issuerEndpointRef',
'issuerType': 'issuerType',
'authenticationFlow': 'authenticationFlow',
'jwtClaimWithClientID': 'jwtClaimWithClientID',
'jwtClaimWithClientIDType': 'jwtClaimWithClientIDType',
'credentials': 'credentials',
'security': 'security',
'gatewayResponse': 'gatewayResponse',
}

KEYS_TENANT = {
Expand Down
Loading

0 comments on commit 0949d23

Please sign in to comment.