Skip to content

Commit

Permalink
test(perf): pathlib-ify filesystem access
Browse files Browse the repository at this point in the history
Do not leave around unclosed file descriptors from reading baseline
files, and avoid os.path.join.

Signed-off-by: Patrick Roy <[email protected]>
  • Loading branch information
roypat committed Jun 28, 2023
1 parent 6e71e49 commit 22714d2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
10 changes: 6 additions & 4 deletions tests/integration_tests/performance/test_block_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import shutil
from enum import Enum
from pathlib import Path

import pytest

Expand Down Expand Up @@ -169,11 +170,12 @@ def read_values(cons, numjobs, env_id, mode, bs, measurement, logs_path):

for job_id in range(numjobs):
file_path = (
f"{logs_path}/{env_id}/{mode}{bs}/{mode}"
f"{bs}_{measurement}.{job_id + 1}.log"
Path(logs_path)
/ env_id
/ f"{mode}{bs}"
/ f"{mode}{bs}_{measurement}.{job_id + 1}.log"
)
file = open(file_path, encoding="utf-8")
lines = file.readlines()
lines = file_path.read_text(encoding="utf-8").splitlines()

direction_count = 1
if mode.endswith("rw"):
Expand Down
6 changes: 3 additions & 3 deletions tests/integration_tests/performance/test_network_latency.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""Tests the network latency of a Firecracker guest."""

import json
import os
import re

import pytest
Expand All @@ -18,7 +17,7 @@
TEST_ID = "network_latency"
kernel_version = get_kernel_version(level=1)
CONFIG_NAME_REL = "test_{}_config_{}.json".format(TEST_ID, kernel_version)
CONFIG_NAME_ABS = os.path.join(defs.CFG_LOCATION, CONFIG_NAME_REL)
CONFIG_NAME_ABS = defs.CFG_LOCATION / CONFIG_NAME_REL

PING = "ping -c {} -i {} {}"
LATENCY = "latency"
Expand Down Expand Up @@ -132,7 +131,8 @@ def test_network_latency(
st_core.iterations = 30
st_core.custom["guest_config"] = guest_config.removesuffix(".json")

raw_baselines = json.load(open(CONFIG_NAME_ABS, encoding="utf-8"))
raw_baselines = json.loads(CONFIG_NAME_ABS.read_text("utf-8"))

env_id = f"{guest_kernel.name()}/{rootfs.name()}/{guest_config}"
cons = consumer.LambdaConsumer(
metadata_provider=DictMetadataProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""Tests the network throughput of Firecracker uVMs."""

import json
import os

import pytest

Expand All @@ -18,7 +17,7 @@
TEST_ID = "network_tcp_throughput"
kernel_version = get_kernel_version(level=1)
CONFIG_NAME_REL = "test_{}_config_{}.json".format(TEST_ID, kernel_version)
CONFIG_NAME_ABS = os.path.join(defs.CFG_LOCATION, CONFIG_NAME_REL)
CONFIG_NAME_ABS = defs.CFG_LOCATION / CONFIG_NAME_REL

BASE_PORT = 5000

Expand Down Expand Up @@ -86,7 +85,8 @@ def pipe(basevm, mode, payload_length, current_avail_cpu, host_ip, env_id):

iperf3_id = f"tcp-p{payload_length}-wsDEFAULT-{mode}"

raw_baselines = json.load(open(CONFIG_NAME_ABS, encoding="utf-8"))
raw_baselines = json.loads(CONFIG_NAME_ABS.read_text("utf-8"))

cons = consumer.LambdaConsumer(
metadata_provider=DictMetadataProvider(
measurements=raw_baselines["measurements"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""Performance benchmark for snapshot restore."""

import json
import os
import tempfile
from functools import lru_cache

Expand All @@ -21,7 +20,7 @@
TEST_ID = "snapshot_restore_performance"
WORKLOAD = "restore"
CONFIG_NAME_REL = "test_{}_config_{}.json".format(TEST_ID, get_kernel_version(level=1))
CONFIG_NAME_ABS = os.path.join(defs.CFG_LOCATION, CONFIG_NAME_REL)
CONFIG_NAME_ABS = defs.CFG_LOCATION / CONFIG_NAME_REL

BASE_VCPU_COUNT = 1
BASE_MEM_SIZE_MIB = 128
Expand Down Expand Up @@ -72,7 +71,8 @@ def get_scratch_drives():

def default_lambda_consumer(env_id, workload):
"""Create a default lambda consumer for the snapshot restore test."""
raw_baselines = json.load(open(CONFIG_NAME_ABS, encoding="utf-8"))
raw_baselines = json.loads(CONFIG_NAME_ABS.read_text("utf-8"))

return st.consumer.LambdaConsumer(
metadata_provider=DictMetadataProvider(
raw_baselines["measurements"],
Expand Down
5 changes: 3 additions & 2 deletions tests/integration_tests/performance/test_vsock_throughput.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
TEST_ID = "vsock_throughput"
kernel_version = get_kernel_version(level=1)
CONFIG_NAME_REL = "test_{}_config_{}.json".format(TEST_ID, kernel_version)
CONFIG_NAME_ABS = os.path.join(defs.CFG_LOCATION, CONFIG_NAME_REL)
CONFIG_NAME_ABS = defs.CFG_LOCATION / CONFIG_NAME_REL

BASE_PORT = 5201

Expand Down Expand Up @@ -105,7 +105,8 @@ def pipe(basevm, current_avail_cpu, env_id, mode, payload_length):

iperf3_id = f"vsock-p{payload_length}-{mode}"

raw_baselines = json.load(open(CONFIG_NAME_ABS, encoding="utf-8"))
raw_baselines = json.loads(CONFIG_NAME_ABS.read_text("utf-8"))

cons = consumer.LambdaConsumer(
metadata_provider=DictMetadataProvider(
raw_baselines["measurements"],
Expand Down

0 comments on commit 22714d2

Please sign in to comment.