Skip to content

Commit

Permalink
Merge 49b4561 into 8c058d5
Browse files Browse the repository at this point in the history
  • Loading branch information
mks-m committed Oct 1, 2020
2 parents 8c058d5 + 49b4561 commit e518929
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 37 deletions.
22 changes: 10 additions & 12 deletions paasta_itests/steps/paasta_api_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def service_instance_status(context, app_count, job_id):
(service, instance, _, __) = decompose_job_id(job_id)
response = context.paasta_api_client.service.status_instance(
instance=instance, service=service
).result()
)

assert response["marathon"]["app_count"] == int(app_count), response
assert response.marathon.app_count == int(app_count), response


@then('instance GET should return error code "{error_code}" for "{job_id}"')
Expand All @@ -38,18 +38,18 @@ def service_instance_status_error(context, error_code, job_id):
try:
response = context.paasta_api_client.service.status_instance(
instance=instance, service=service
).result()
)
except context.paasta_api_client.api_error as exc:
assert exc.status_code == int(error_code)
assert exc.status == int(error_code)

assert not response


@then('resources GET should show "{resource}" has {used} used')
def resources_resource_used(context, resource, used):
used = float(used)
response = context.paasta_api_client.resources.resources().result()
assert response[0][resource]["used"] == used, response
response = context.paasta_api_client.resources.resources().value
assert response[0].to_dict()[resource].get("used") == used, response


@then(
Expand All @@ -61,9 +61,9 @@ def resources_groupings_filters(context, groupings, filters, num):
filters = filters.split("|")
response = context.paasta_api_client.resources.resources(
groupings=groupings, filter=filters
).result()
)

assert len(response) == num, response
assert len(response.value) == num, response


@then('resources GET with groupings "{groupings}" should return {num:d} groups')
Expand All @@ -75,14 +75,12 @@ def resources_groupings(context, groupings, num):
'marathon_dashboard GET should return "{service}.{instance}" in cluster "{cluster}" with shard {shard:d}'
)
def marathon_dashboard(context, service, instance, cluster, shard):
response = (
context.paasta_api_client.marathon_dashboard.marathon_dashboard().result()
)
response = context.paasta_api_client.marathon_dashboard.marathon_dashboard()
dashboard = response[cluster]
shard_url = context.system_paasta_config.get_dashboard_links()[cluster][
"Marathon RO"
][shard]
for marathon_dashboard_item in dashboard:
for marathon_dashboard_item in dashboard.value:
if (
marathon_dashboard_item["service"] == service
and marathon_dashboard_item["instance"] == instance
Expand Down
8 changes: 3 additions & 5 deletions paasta_itests/steps/setup_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
import json
import os
from tempfile import NamedTemporaryFile
from urllib.parse import urlparse

import yaml
from behave import given
from behave import when
from bravado.client import SwaggerClient
from itest_utils import get_service_connection_string

from paasta_tools import marathon_tools
from paasta_tools import utils
from paasta_tools.api import auth_decorator
from paasta_tools.api.client import get_paasta_oapi_client_by_url
from paasta_tools.frameworks import native_scheduler
from paasta_tools.utils import decompose_job_id

Expand Down Expand Up @@ -92,9 +92,7 @@ def get_paasta_api_url():


def setup_paasta_api_client():
return auth_decorator.AuthClientDecorator(
SwaggerClient.from_url(get_paasta_api_url()), cluster_name="itests"
)
return get_paasta_oapi_client_by_url(urlparse(get_paasta_api_url()))


def _generate_mesos_cli_config(zk_host_and_port):
Expand Down
6 changes: 6 additions & 0 deletions paasta_tools/api/api_docs/oapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,10 @@ components:
description: Mapping of reason offer was refused to the number of times
that type of refusal was seen
type: object
unused_offers:
type: array
items:
type: object
type: object
MarathonAutoscalingInfo:
properties:
Expand Down Expand Up @@ -725,6 +729,8 @@ components:
type: object
mem:
$ref: '#/components/schemas/ResourceValue'
gpus:
$ref: '#/components/schemas/ResourceValue'
type: object
ResourceValue:
properties:
Expand Down
9 changes: 9 additions & 0 deletions paasta_tools/api/api_docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,12 @@
"items": {
"$ref": "#/definitions/MarathonTask"
}
},
"unused_offers": {
"type": "array",
"items": {
"type": "object"
}
}
}
},
Expand Down Expand Up @@ -1635,6 +1641,9 @@
},
"disk": {
"$ref": "#/definitions/ResourceValue"
},
"gpus": {
"$ref": "#/definitions/ResourceValue"
}
}
},
Expand Down
55 changes: 35 additions & 20 deletions paasta_tools/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import os
from typing import Any
from typing import Mapping
from typing import Optional
from urllib.parse import ParseResult
from urllib.parse import urlparse

from dataclasses import dataclass
Expand Down Expand Up @@ -136,11 +138,37 @@ class PaastaOApiClient:
request_error: type


def get_paasta_oapi_client_by_url(
parsed_url: ParseResult,
cert_file: Optional[str] = None,
key_file: Optional[str] = None,
ssl_ca_cert: Optional[str] = None,
) -> PaastaOApiClient:
server_variables = dict(scheme=parsed_url.scheme, host=parsed_url.netloc)
config = paastaapi.Configuration(server_variables=server_variables)
config.cert_file = cert_file
config.key_file = key_file
config.ssl_ca_cert = ssl_ca_cert

client = paastaapi.ApiClient(configuration=config)
return PaastaOApiClient(
autoscaler=paastaapis.AutoscalerApi(client),
default=paastaapis.DefaultApi(client),
marathon_dashboard=paastaapis.MarathonDashboardApi(client),
resources=paastaapis.ResourcesApi(client),
service=paastaapis.ServiceApi(client),
api_error=paastaapi.ApiException,
connection_error=paastaapi.ApiException,
timeout_error=paastaapi.ApiException,
request_error=paastaapi.ApiException,
)


def get_paasta_oapi_client(
cluster: str = None,
system_paasta_config: SystemPaastaConfig = None,
http_res: bool = False,
) -> PaastaOApiClient:
) -> Optional[PaastaOApiClient]:
if not system_paasta_config:
system_paasta_config = load_system_paasta_config()

Expand All @@ -153,28 +181,15 @@ def get_paasta_oapi_client(
return None

parsed = urlparse(api_endpoints[cluster])
server_variables = dict(scheme=parsed.scheme, host=parsed.netloc)
config = paastaapi.Configuration(server_variables=server_variables)

if config.server_variables["scheme"] == "https":
cert_file = key_file = ssl_ca_cert = None
if parsed.scheme == "https":
opts = get_paasta_ssl_opts(cluster, system_paasta_config)
if opts:
config.cert_file = opts["cert"]
config.key_file = opts["key"]
config.ssl_ca_cert = opts["ca"]
cert_file = opts["cert"]
key_file = opts["key"]
ssl_ca_cert = opts["ca"]

client = paastaapi.ApiClient(configuration=config)
return PaastaOApiClient(
autoscaler=paastaapis.AutoscalerApi(client),
default=paastaapis.DefaultApi(client),
marathon_dashboard=paastaapis.MarathonDashboardApi(client),
resources=paastaapis.ResourcesApi(client),
service=paastaapis.ServiceApi(client),
api_error=paastaapi.ApiException,
connection_error=paastaapi.ApiException,
timeout_error=paastaapi.ApiException,
request_error=paastaapi.ApiException,
)
return get_paasta_oapi_client_by_url(parsed, cert_file, key_file, ssl_ca_cert)


def renew_issue_cert(system_paasta_config: SystemPaastaConfig, cluster: str) -> None:
Expand Down
3 changes: 3 additions & 0 deletions paasta_tools/paastaapi/model/marathon_app_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def openapi_types():
'tasks_staged': (int,), # noqa: E501
'tasks_total': (int,), # noqa: E501
'unused_offer_reason_counts': ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},), # noqa: E501
'unused_offers': ([{str: (bool, date, datetime, dict, float, int, list, str, none_type)}],), # noqa: E501
}

@cached_property
Expand All @@ -109,6 +110,7 @@ def discriminator():
'tasks_staged': 'tasks_staged', # noqa: E501
'tasks_total': 'tasks_total', # noqa: E501
'unused_offer_reason_counts': 'unused_offer_reason_counts', # noqa: E501
'unused_offers': 'unused_offers', # noqa: E501
}

_composed_schemas = {}
Expand Down Expand Up @@ -167,6 +169,7 @@ def __init__(self, *args, **kwargs): # noqa: E501
tasks_staged (int): Number of staged tasks for this app. [optional] # noqa: E501
tasks_total (int): Total number of tasks for this app. [optional] # noqa: E501
unused_offer_reason_counts ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}): Mapping of reason offer was refused to the number of times that type of refusal was seen. [optional] # noqa: E501
unused_offers ([{str: (bool, date, datetime, dict, float, int, list, str, none_type)}]): [optional] # noqa: E501
"""

_check_type = kwargs.pop('_check_type', True)
Expand Down
3 changes: 3 additions & 0 deletions paasta_tools/paastaapi/model/resource_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def openapi_types():
'disk': (ResourceValue,), # noqa: E501
'groupings': ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},), # noqa: E501
'mem': (ResourceValue,), # noqa: E501
'gpus': (ResourceValue,), # noqa: E501
}

@cached_property
Expand All @@ -97,6 +98,7 @@ def discriminator():
'disk': 'disk', # noqa: E501
'groupings': 'groupings', # noqa: E501
'mem': 'mem', # noqa: E501
'gpus': 'gpus', # noqa: E501
}

_composed_schemas = {}
Expand Down Expand Up @@ -149,6 +151,7 @@ def __init__(self, *args, **kwargs): # noqa: E501
disk (ResourceValue): [optional] # noqa: E501
groupings ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}): [optional] # noqa: E501
mem (ResourceValue): [optional] # noqa: E501
gpus (ResourceValue): [optional] # noqa: E501
"""

_check_type = kwargs.pop('_check_type', True)
Expand Down

0 comments on commit e518929

Please sign in to comment.