Skip to content

Commit

Permalink
Fix bastion behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
ezh committed Dec 17, 2019
1 parent 6e0960c commit 3d2760f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cloudselect/pathfinder/bastion.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def run(self, instance, instances):
raise ValueError("instance must be something, not None")
arguments = Container.options("pathfinder", instance.metadata)
if arguments:
jumphost = {}
jumphost = None
if "host" in arguments:
jumphost["host"] = Instance(
jumphost = Instance(
-1,
arguments["host"],
arguments.get("key"),
Expand All @@ -40,7 +40,7 @@ def run(self, instance, instances):
{},
[],
)
if "metadata" in arguments and ":" in arguments["metadata"]:
elif "metadata" in arguments and ":" in arguments["metadata"]:
key, pattern = arguments["metadata"].split(":", 1)
for i in instances:
point = self.find_jumphost(key, pattern, i)
Expand Down
44 changes: 44 additions & 0 deletions test/pathfinder/test_bastion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2019 Alexey Aksenov and individual contributors
# See the LICENSE.txt file at the top-level directory of this distribution.
#
# Licensed under the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>
# This file may not be copied, modified, or distributed
# except according to those terms.
"""This module is used for testing Stub pathfinder plugin."""
from cloudselect import Container, Instance
from cloudselect.cloudselect import CloudSelect
from cloudselect.pathfinder.bastion import Bastion

instance = Instance(1, "127.0.0.1", "key", "user", 22, None, {}, [])


def test_bastion_initialization(mocker):
"""Assert plugin initialization."""
cloud = CloudSelect()
configuration = cloud.configuration_read()
args = cloud.parse_args([])
configuration["pathfinder"] = {"type": "bastion"}
cloud.fabric(configuration, args)

assert type(Container.pathfinder()) == Bastion

result = Container.pathfinder().run(instance, [instance])
assert result.jumphost is None


def test_bastion_behaviour(mocker):
"""Assert bastion returning correct result."""
cloud = CloudSelect()
configuration = cloud.configuration_read()
args = cloud.parse_args([])
configuration["pathfinder"] = {"type": "bastion", "host": "my-bastion-hostname"}
cloud.fabric(configuration, args)

assert type(Container.pathfinder()) == Bastion

result = Container.pathfinder().run(instance, [instance])

assert type(result.jumphost) == Instance
assert result.jumphost.host == "my-bastion-hostname"
# assert result.jumphost is None

0 comments on commit 3d2760f

Please sign in to comment.