Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions rootfs/scheduler/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import uuid
from zlib import adler32

from . import KubeHTTPClient, KubeHTTPException
import scheduler
from scheduler import KubeHTTPClient, KubeHTTPException

from django.conf import settings
from django.core.cache import cache
Expand Down Expand Up @@ -738,7 +739,7 @@ def remove_cache_item(url, resource_type):
cache.set(cache_url, items, None)


def mock(request, context):
def mock_kubernetes(request, context):
# always cleanup pods
cleanup_pods()
# always transition pods
Expand All @@ -760,20 +761,23 @@ def mock(request, context):
logger.critical(request.method)


class MockSchedulerClient(KubeHTTPClient):
def __init__(self):
self.url = settings.SCHEDULER_URL
self.registry = settings.REGISTRY_URL
def session():
adapter = requests_mock.Adapter()
session = requests.Session()
session.mount(settings.SCHEDULER_URL, adapter)

# Lets just listen to everything and sort it out ourselves
adapter.register_uri(
requests_mock.ANY, requests_mock.ANY,
json=mock_kubernetes
)

adapter = requests_mock.Adapter()
self.session = requests.Session()
self.session.mount(self.url, adapter)
return session

# Lets just listen to everything and sort it out ourselves
adapter.register_uri(
requests_mock.ANY, requests_mock.ANY,
json=mock
)

class MockSchedulerClient(KubeHTTPClient):
def __init__(self):
super().__init__()

# Pre-seed data that is assumed to otherwise be there
try:
Expand Down Expand Up @@ -888,6 +892,7 @@ def __init__(self):
except Exception as e:
logger.critical(e)

scheduler.session = session()
SchedulerClient = MockSchedulerClient


Expand Down