Skip to content

Commit

Permalink
Fix rebase problems
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenprater committed Jul 16, 2019
1 parent 46a0400 commit 679653d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 39 deletions.
9 changes: 5 additions & 4 deletions app/services/tunnel.py
@@ -1,4 +1,4 @@
from typing import Tuple, cast
from typing import Tuple, List
import nomad
from dpath.util import values

Expand Down Expand Up @@ -49,6 +49,7 @@ def __init__(
def create(self) -> Tunnel:
self.check_subdomain_permissions()
job_id = None

if self.over_tunnel_limit():
raise TunnelLimitReached("Maximum number of opened tunnels reached")
try:
Expand Down Expand Up @@ -95,7 +96,7 @@ def over_tunnel_limit(self) -> bool:
return True
return False

def create_tunnel_nomad(self) -> Tuple[str, dict]:
def create_tunnel_nomad(self) -> Tuple[str, List[int]]:
"""Create a tunnel by scheduling an SSH container into the Nomad cluster"""
tcp_ports = []
for port in self.port_types:
Expand Down Expand Up @@ -153,7 +154,7 @@ def get_tcp_port(self) -> int:
try:
new_port = redis_client.spop("open_tcp_ports")
return int(new_port)
except:
except RedisError:
raise TunnelError(detail="No tcp ports available")


Expand All @@ -163,7 +164,7 @@ def __init__(self, current_user: User, tunnel: Optional[Tunnel], job_id=None):
self.tunnel = tunnel
if job_id:
self.job_id = job_id
if self.tunnel:
if tunnel:
self.subdomain = tunnel.subdomain
self.job_id = tunnel.job_id

Expand Down
6 changes: 6 additions & 0 deletions tests/conftest.py
@@ -1,6 +1,7 @@
import pytest
from dotenv import load_dotenv
from app import create_app, stripe
from app.commands import populate_redis
from app import db as _db
from sqlalchemy import event
from tests.support.client import TestClient
Expand Down Expand Up @@ -83,6 +84,11 @@ def populate_plans(app, db):
sess.expire_all()


@pytest.fixture(scope="session", autouse=True)
def populate_redis_fixture():
populate_redis()


@pytest.fixture(scope="function", autouse=True)
def session(app, db, request):
with app.app_context():
Expand Down
35 changes: 0 additions & 35 deletions tests/functional/routes/test_tunnels.py
@@ -1,9 +1,7 @@
import pytest
from dpath.util import values
from nomad.api.exceptions import BaseNomadException
from app.models import Tunnel
from app.services.tunnel import TunnelCreationService, TunnelDeletionService
from app.services.subdomain import SubdomainCreationService
from app.utils.errors import TunnelError
from tests.factories.user import UserFactory
from tests.factories import subdomain, tunnel
Expand Down Expand Up @@ -203,39 +201,6 @@ def test_tunnel_filter_by_subdomain_name(self, client, session, current_user):


class TestFailedTunnels(object):
@mock.patch.object(
TunnelCreationService, "create_tunnel_nomad", return_value=[1, []]
)
@mock.patch.object(
TunnelCreationService,
"get_tunnel_details",
side_effect=TunnelError(detail="Error"),
autospec=True,
)
@mock.patch.object(TunnelDeletionService, "delete")
def test_tunnel_delete_on_fail_deploy(
self,
mock_del_tunnel,
mock_tunnel_details,
mock_create_tunnel,
client,
current_user,
):
"""Tunnel delete is called when provisioning it fails"""
res = client.post(
"/tunnels",
json={
"data": {
"type": "tunnel",
"attributes": {"port": ["http"], "sshKey": "i-am-lousy-public-key"},
}
},
)

assert res.status_code == 500, res.get_json()
assert mock_tunnel_details.called
assert mock_del_tunnel.called

@mock.patch.object(
TunnelCreationService,
"create_tunnel_nomad",
Expand Down

0 comments on commit 679653d

Please sign in to comment.