-
Notifications
You must be signed in to change notification settings - Fork 453
/
cloudtest_application_base.py
64 lines (53 loc) · 2.06 KB
/
cloudtest_application_base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
import subprocess
from materialize import MZ_ROOT, mzbuild
from materialize.cloudtest.app.application import Application
from materialize.cloudtest.k8s.api.k8s_resource import K8sResource
class CloudtestApplicationBase(Application):
def __init__(
self,
release_mode: bool = True,
aws_region: str | None = None,
log_filter: str | None = None,
) -> None:
super().__init__()
self.release_mode = release_mode
self.aws_region = aws_region
self.mz_root = MZ_ROOT
self.resources = self.get_resources(log_filter)
self.images = self.get_images()
def create_resources_and_wait(self) -> None:
self.create_resources()
self.wait_resource_creation_completed()
def get_resources(self, log_filter: str | None) -> list[K8sResource]:
raise NotImplementedError
def get_images(self) -> list[str]:
raise NotImplementedError
def wait_resource_creation_completed(self) -> None:
raise NotImplementedError
def acquire_images(self) -> None:
repo = mzbuild.Repository(
self.mz_root, release_mode=self.release_mode, coverage=self.coverage_mode()
)
for image in self.images:
self._acquire_image(repo, image)
def _acquire_image(self, repo: mzbuild.Repository, image: str) -> None:
deps = repo.resolve_dependencies([repo.images[image]])
deps.acquire()
for dep in deps:
subprocess.check_call(
[
"kind",
"load",
"docker-image",
f"--name={self.cluster_name()}",
dep.spec(),
]
)