Skip to content

Commit 14f1db3

Browse files
committed
test runs
1 parent 4fbf61a commit 14f1db3

6 files changed

Lines changed: 44 additions & 27 deletions

File tree

localstack_utils/__init__.py

Whitespace-only changes.

localstack_utils/container.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import docker
44
from time import sleep
55

6-
LOCALSTACK_NAME = "localstack/localstack"
7-
LOCALSTACK_TAG = "latest"
6+
LOCALSTACK_COMMUNITY_IMAGE_NAME = "localstack/localstack"
7+
LOCALSTACK_PRO_IMAGE_NAME = "localstack/localstack-pro"
8+
LATEST_TAG = "latest"
89

910
MAX_PORT_CONNECTION_ATTEMPTS = 10
1011
MAX_LOG_COLLECTION_ATTEMPTS = 120
@@ -24,16 +25,19 @@ class Container:
2425
@staticmethod
2526
def create_localstack_container(
2627
pull_new_image: bool,
27-
image_name: str,
28-
image_tag: str,
29-
gateway_listen: str,
30-
environment_variables: dict,
31-
bind_ports: dict,
28+
image_name: str = None,
29+
image_tag: str = LATEST_TAG,
30+
gateway_listen: str = "0.0.0.0:4566",
31+
environment_variables: dict = None,
32+
bind_ports: dict = None,
33+
pro: bool = False,
3234
):
3335
environment_variables = environment_variables or {}
3436
environment_variables["GATEWAY_LISTEN"] = gateway_listen
3537

36-
image_name_or_default = LOCALSTACK_NAME if image_name is None else image_name
38+
image_name_or_default = image_name or (
39+
LOCALSTACK_PRO_IMAGE_NAME if pro else LOCALSTACK_COMMUNITY_IMAGE_NAME
40+
)
3741
image_exists = (
3842
True
3943
if len(DOCKER_CLIENT.images.list(name=image_name_or_default))
Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,21 @@ def startup(self, docker_configuration):
3838
if self.locked:
3939
raise Exception("A docker instance is starting or already started.")
4040
self.locked = True
41-
self.external_hostname = docker_configuration.external_hostname
4241

4342
try:
4443
self.localstack_container = Container.create_localstack_container(
45-
docker_configuration.external_hostname,
4644
docker_configuration.pull_new_image,
47-
docker_configuration.randomize_ports,
4845
docker_configuration.image_name,
4946
docker_configuration.image_tag,
50-
docker_configuration.port_edge,
51-
docker_configuration.port_elastic_search,
47+
docker_configuration.gateway_listen,
5248
docker_configuration.environment_variables,
5349
docker_configuration.port_mappings,
54-
docker_configuration.bind_mounts,
55-
docker_configuration.platform,
50+
docker_configuration.pro,
5651
)
5752

5853
self.setup_logger()
5954

60-
Container.waitForReady(self.localstack_container, READY_TOKEN)
55+
Container.wait_for_ready(self.localstack_container, READY_TOKEN)
6156

6257
except docker.errors.APIError:
6358
if not docker_configuration.ignore_docker_runerrors:
@@ -74,16 +69,37 @@ def setup_logger(self):
7469
localstack_logger.start()
7570

7671

77-
def startup_localstack(port=4566, services=[], ignore_docker_errors=False):
72+
def startup_localstack(
73+
image_name="",
74+
tag="",
75+
pro=False,
76+
ports=None,
77+
env_variables=None,
78+
gateway_listen="",
79+
ignore_docker_errors=False,
80+
):
7881
global localstack_instance
7982
localstack_instance = Localstack.INSTANCE()
8083
config = LocalstackDockerConfiguration()
8184

82-
if len(services):
83-
config.envirement_variables.update({"SERVICES": ",".join(services)})
84-
if port != 4566:
85-
config.port_edge = str(port)
8685
config.ignore_docker_runerrors = ignore_docker_errors
86+
if image_name:
87+
config.image_name = image_name
88+
89+
if tag:
90+
config.image_tag = tag
91+
92+
if ports:
93+
config.port_mappings = ports
94+
95+
if pro:
96+
config.pro = pro
97+
98+
if env_variables:
99+
config.environment_variables = env_variables
100+
101+
if gateway_listen:
102+
config.gateway_listen = gateway_listen
87103

88104
localstack_instance.startup(config)
89105

localstack_utils/localstack_docker_configuration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ class LocalstackDockerConfiguration:
1313
initialization_token = None
1414
use_dingle_docker_container = False
1515
ignore_docker_runerrors = False
16+
pro = False

setug.cfg

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,3 @@ exclude =
4747
exclude =
4848
tests
4949
tests.*
50-
51-
[options.entry_points]
52-
localstack_utils =
53-
localstack_utils = localstack_utils

tests/test_kinesis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import time
22
import boto3
33
import unittest
4-
from localstack_utils import startup_localstack, stop_localstack
4+
from localstack_utils.localstack import startup_localstack, stop_localstack
55

66

77
class TestKinesis(unittest.TestCase):
@@ -21,7 +21,7 @@ def test_create_stream(self):
2121
)
2222

2323
kinesis.create_stream(StreamName="test", ShardCount=1)
24-
time.sleep(5)
24+
time.sleep(1)
2525

2626
response = kinesis.list_streams()
2727
self.assertGreater(len(response.get("StreamNames", [])), 0)

0 commit comments

Comments
 (0)