Skip to content

Commit 70f77a5

Browse files
committed
update logger implementation and change imports
1 parent 638d765 commit 70f77a5

File tree

8 files changed

+150
-124
lines changed

8 files changed

+150
-124
lines changed

.infra/test/ec2/setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
22
from invoke.context import Context
3-
from test.test_utils import LOGGER
3+
from .test_infra_utils import create_logger
44
from codebuild_environment import get_cloned_folder_path
55

6+
LOGGER = create_logger(__name__)
7+
68

79
class EC2Platform:
810
def __init__(self):
@@ -56,4 +58,4 @@ def _standard_ec2_setup(self, params):
5658
LOGGER.info(f"Standard EC2 setup: {instance_type}, {node_count} nodes, {region}")
5759

5860
# TODO: Implement generic EC2 provisioning
59-
raise NotImplementedError("Standard EC2 setup not yet implemented")
61+
raise NotImplementedError("Standard EC2 setup not yet implemented")

.infra/test/eks/setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
22
from invoke.context import Context
3-
from test.test_utils import LOGGER
3+
from .test_infra_utils import create_logger
44
from codebuild_environment import get_cloned_folder_path
55

6+
LOGGER = create_logger(__name__)
7+
68

79
class EKSPlatform:
810
def __init__(self):

.infra/test/entrypoint.py

Lines changed: 10 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,17 @@
11
import os
2-
import yaml
3-
from typing import Dict, List
42
from src.config import is_new_test_structure_enabled
5-
from src.buildspec import Buildspec
6-
from .infra.test.ec2.setup import EC2Platform
7-
from .infra.test.eks.setup import EKSPlatform
8-
from .infra.test.validators.platform_validator_utils import get_platform_validator
9-
from test.test_utils import LOGGER, get_dlc_images, get_buildspec_path
3+
from .ec2.setup import EC2Platform
4+
from .eks.setup import EKSPlatform
5+
from .test_infra_utils import (
6+
create_logger,
7+
parse_buildspec,
8+
validate_and_filter_tests,
9+
execute_platform_tests,
10+
)
11+
from test.test_utils import get_dlc_images
1012
from codebuild_environment import get_cloned_folder_path
1113

12-
def resolve_buildspec_variables(config):
13-
"""
14-
Resolve environment variables in buildspec
15-
"""
16-
region = os.getenv("REGION", "us-west-2")
17-
account_id = os.getenv("ACCOUNT_ID", "")
18-
19-
config_str = yaml.dump(config)
20-
config_str = config_str.replace("<set-$REGION-in-environment>", region)
21-
config_str = config_str.replace("<set-$ACCOUNT_ID-in-environment>", account_id)
22-
23-
return yaml.safe_load(config_str)
24-
25-
26-
def parse_buildspec(image_uri):
27-
"""
28-
Parse buildspec for test configurations
29-
"""
30-
repo_root = get_cloned_folder_path()
31-
buildspec_path = get_buildspec_path(repo_root)
32-
33-
if not os.path.exists(buildspec_path):
34-
raise FileNotFoundError(f"Buildspec file not found: {buildspec_path}")
35-
36-
BUILDSPEC = Buildspec()
37-
BUILDSPEC.load(buildspec_path)
38-
39-
# Extract test configs
40-
images = BUILDSPEC.get("images", {})
41-
image_key = list(images.keys())[0]
42-
LOGGER.info(f"Using image config: {image_key}")
43-
image_config = images[image_key]
44-
45-
tests = image_config.get("tests", [])
46-
47-
globals_data = {
48-
"region": BUILDSPEC.get("region"),
49-
"arch_type": BUILDSPEC.get("arch_type"),
50-
"framework": BUILDSPEC.get("framework"),
51-
}
52-
53-
return {
54-
"tests": tests,
55-
"globals": globals_data,
56-
}
57-
58-
59-
def validate_and_filter_tests(buildspec_data: Dict, test_type: str, base_path: str) -> List[Dict]:
60-
applicable_tests = []
61-
validation_errors = []
62-
63-
# Filter for applicable tests
64-
all_tests = buildspec_data.get("tests", [])
65-
LOGGER.info(f"Found {len(all_tests)} total test configurations")
66-
67-
platform_tests = [test for test in all_tests if test["platform"].startswith(test_type)]
68-
LOGGER.info(f"Found {len(platform_tests)} applicable test configurations for {test_type}")
69-
70-
# Validate each applicable test
71-
for test in platform_tests:
72-
try:
73-
validator = get_platform_validator(test["platform"], base_path)
74-
test_config = {**test, "globals": buildspec_data.get("globals", {})}
75-
errors = validator.validate(test_config)
76-
77-
if errors:
78-
validation_errors.extend(
79-
[f"Test {test['platform']}:", *[f" {error}" for error in errors], ""]
80-
)
81-
else:
82-
applicable_tests.append(test)
83-
84-
except ValueError as e:
85-
validation_errors.append(f"Test {test['platform']}: {str(e)}")
86-
87-
if validation_errors:
88-
error_msg = "\n".join(validation_errors)
89-
LOGGER.error("Test validation failed:")
90-
LOGGER.error(error_msg)
91-
raise ValueError("Test validation failed. See errors above.")
92-
93-
LOGGER.info(f"Validated {len(applicable_tests)} test configurations successfully")
94-
return applicable_tests
95-
96-
97-
def execute_platform_tests(platform, test_config, buildspec_data, image_uri):
98-
"""
99-
Helper function to execute tests for a platform
100-
"""
101-
try:
102-
setup_params = {
103-
**test_config["params"],
104-
**buildspec_data["globals"],
105-
"image_uri": image_uri,
106-
}
107-
108-
platform.setup(setup_params)
109-
LOGGER.info(f"{platform.__class__.__name__} setup completed")
110-
111-
LOGGER.info(f"Executing {len(test_config['run'])} commands:")
112-
for cmd in test_config["run"]:
113-
LOGGER.info(f" - {cmd}")
114-
platform.execute_command(cmd)
115-
except Exception as e:
116-
LOGGER.error(f"Test failed: {e}")
117-
raise
14+
LOGGER = create_logger(__name__)
11815

11916

12017
def main():

.infra/test/test_infra_utils.py

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import logging
2+
import sys
3+
import datetime
4+
import os
5+
import yaml
6+
from typing import Dict, List
7+
from src.buildspec import Buildspec
8+
from test.test_utils import get_buildspec_path
9+
from codebuild_environment import get_cloned_folder_path
10+
from .validators.platform_validator_utils import get_platform_validator
11+
12+
13+
def create_logger(name, level=logging.INFO):
14+
logger = logging.getLogger(name)
15+
if logger.handlers:
16+
return logger
17+
18+
logger.setLevel(level)
19+
formatter = logging.Formatter(
20+
"[%(asctime)s PST %(levelname)s %(name)s %(filename)s:%(lineno)d] %(message)s",
21+
datefmt="%Y-%m-%d %H:%M:%S",
22+
)
23+
formatter.converter = lambda *args: datetime.datetime.now(
24+
datetime.timezone(datetime.timedelta(hours=-8))
25+
).timetuple()
26+
27+
handler = logging.StreamHandler(sys.stdout)
28+
handler.setFormatter(formatter)
29+
logger.addHandler(handler)
30+
logger.propagate = False
31+
return logger
32+
33+
34+
LOGGER = create_logger(__name__)
35+
36+
37+
def resolve_buildspec_variables(config):
38+
"""Resolve environment variables in buildspec"""
39+
region = os.getenv("REGION", "us-west-2")
40+
account_id = os.getenv("ACCOUNT_ID", "")
41+
config_str = yaml.dump(config)
42+
config_str = config_str.replace("<set-$REGION-in-environment>", region)
43+
config_str = config_str.replace("<set-$ACCOUNT_ID-in-environment>", account_id)
44+
return yaml.safe_load(config_str)
45+
46+
47+
def parse_buildspec(image_uri):
48+
"""Parse buildspec for test configurations"""
49+
repo_root = get_cloned_folder_path()
50+
buildspec_path = get_buildspec_path(repo_root)
51+
52+
if not os.path.exists(buildspec_path):
53+
raise FileNotFoundError(f"Buildspec file not found: {buildspec_path}")
54+
55+
BUILDSPEC = Buildspec()
56+
BUILDSPEC.load(buildspec_path)
57+
58+
images = BUILDSPEC.get("images", {})
59+
image_key = list(images.keys())[0]
60+
LOGGER.info(f"Using image config: {image_key}")
61+
image_config = images[image_key]
62+
63+
tests = image_config.get("tests", [])
64+
globals_data = {
65+
"region": BUILDSPEC.get("region"),
66+
"arch_type": BUILDSPEC.get("arch_type"),
67+
"framework": BUILDSPEC.get("framework"),
68+
}
69+
70+
return {"tests": tests, "globals": globals_data}
71+
72+
73+
def validate_and_filter_tests(buildspec_data: Dict, test_type: str, base_path: str) -> List[Dict]:
74+
"""Validate and filter tests for the given test type"""
75+
applicable_tests = []
76+
validation_errors = []
77+
78+
all_tests = buildspec_data.get("tests", [])
79+
LOGGER.info(f"Found {len(all_tests)} total test configurations")
80+
81+
platform_tests = [test for test in all_tests if test["platform"].startswith(test_type)]
82+
LOGGER.info(f"Found {len(platform_tests)} applicable test configurations for {test_type}")
83+
84+
for test in platform_tests:
85+
try:
86+
validator = get_platform_validator(test["platform"], base_path)
87+
test_config = {**test, "globals": buildspec_data.get("globals", {})}
88+
errors = validator.validate(test_config)
89+
90+
if errors:
91+
validation_errors.extend(
92+
[f"Test {test['platform']}:", *[f" {error}" for error in errors], ""]
93+
)
94+
else:
95+
applicable_tests.append(test)
96+
except ValueError as e:
97+
validation_errors.append(f"Test {test['platform']}: {str(e)}")
98+
99+
if validation_errors:
100+
error_msg = "\n".join(validation_errors)
101+
LOGGER.error("Test validation failed:")
102+
LOGGER.error(error_msg)
103+
raise ValueError("Test validation failed. See errors above.")
104+
105+
LOGGER.info(f"Validated {len(applicable_tests)} test configurations successfully")
106+
return applicable_tests
107+
108+
109+
def execute_platform_tests(platform, test_config, buildspec_data, image_uri):
110+
"""Execute tests for a platform"""
111+
try:
112+
setup_params = {
113+
**test_config["params"],
114+
**buildspec_data["globals"],
115+
"image_uri": image_uri,
116+
}
117+
118+
platform.setup(setup_params)
119+
LOGGER.info(f"{platform.__class__.__name__} setup completed")
120+
121+
LOGGER.info(f"Executing {len(test_config['run'])} commands:")
122+
for cmd in test_config["run"]:
123+
LOGGER.info(f" - {cmd}")
124+
platform.execute_command(cmd)
125+
except Exception as e:
126+
LOGGER.error(f"Test failed: {e}")
127+
raise

.infra/test/validators/platform_validator_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from .infra.test.validators.base_platform_validator import BasePlatformValidator
2-
from .infra.test.validators.platform_validators import EC2MultiNodeValidator, EKSValidator
1+
from .base_platform_validator import BasePlatformValidator
2+
from .platform_validators import EC2MultiNodeValidator, EKSValidator
33

44

55
_VALIDATORS = {"ec2-multi-node": EC2MultiNodeValidator, "eks": EKSValidator}

.infra/test/validators/platform_validators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import List, Dict
2-
from .infra.test.validators.base_platform_validator import BasePlatformValidator
3-
from .infra.test.validators.base_platform_validator import EC2Config, EKSConfig
2+
from .base_platform_validator import BasePlatformValidator
3+
from .base_platform_validator import EC2Config, EKSConfig
44

55

66
class EC2MultiNodeValidator(BasePlatformValidator):

test/testrunner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from test_utils import KEYS_TO_DESTROY_FILE
3434
from test_utils.pytest_cache import PytestCache
3535
from test.vllm.trigger_test import test as test_vllm
36-
from .infra.test.entrypoint import main as run_new_tests
36+
from ...infra.test.entrypoint import main as run_new_tests
3737

3838
from src.codebuild_environment import get_codebuild_project_name
3939

test/v2/eks/vllm/vllm_eks_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
VLLM_NAMESPACE = os.getenv("NAMESPACE")
2727

2828
REPO_ROOT = get_cloned_folder_path()
29-
LWS_YAML = os.path.join(
30-
REPO_ROOT, "test", "v2", "eks", "vllm", "vllm-deepseek-32b-lws.yaml"
31-
)
29+
LWS_YAML = os.path.join(REPO_ROOT, "test", "v2", "eks", "vllm", "vllm-deepseek-32b-lws.yaml")
3230
LWS_INGRESS_YAML = os.path.join(
3331
REPO_ROOT, "test", "v2", "eks", "vllm", "vllm-deepseek-32b-lws-ingress.yaml"
3432
)

0 commit comments

Comments
 (0)