Skip to content

Commit

Permalink
[testing-on-gke] extract common runner code b/w fio and dlio (#2493)
Browse files Browse the repository at this point in the history
* share common code b/w fio/dlio run_tests

* fix python error

* update license headers in new files

* address review comments
  • Loading branch information
gargnitingoogle authored Sep 23, 2024
1 parent 4a628f3 commit e599fd0
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 131 deletions.
75 changes: 10 additions & 65 deletions perfmetrics/scripts/testing_on_gke/examples/dlio/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,18 @@
each valid DLIO workload.
"""

# system imports
import argparse
import os
import subprocess
import dlio_workload

import sys

def run_command(command: str):
"""Runs the given string command as a subprocess."""
result = subprocess.run(command.split(' '), capture_output=True, text=True)
print(result.stdout)
print(result.stderr)
# local imports from other directories
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'utils'))
from run_tests_common import escape_commas_in_string, parse_args, run_command


def escapeCommasInString(unescapedStr: str) -> str:
"""Returns equivalent string with ',' replaced with '\,' ."""
return unescapedStr.replace(',', '\,')
# local imports from same directory
import dlio_workload


def createHelmInstallCommands(
Expand All @@ -61,7 +58,7 @@ def createHelmInstallCommands(
f'--set instanceId={instanceId}',
(
'--set'
f' gcsfuse.mountOptions={escapeCommasInString(dlioWorkload.gcsfuseMountOptions)}'
f' gcsfuse.mountOptions={escape_commas_in_string(dlioWorkload.gcsfuseMountOptions)}'
),
f'--set nodeType={machineType}',
f'--set podName={podName}',
Expand Down Expand Up @@ -89,57 +86,5 @@ def main(args) -> None:


if __name__ == '__main__':
parser = argparse.ArgumentParser(
prog='DLIO Unet3d test runner',
description=(
'This program takes in a json test-config file, finds out valid DLIO'
' workloads from it and generates and deploys a helm chart for each'
' DLIO workload.'
),
)
parser.add_argument(
'--workload-config',
metavar='JSON workload configuration file path',
help='Runs DLIO Unet3d tests from this JSON workload configuration file.',
required=True,
)
parser.add_argument(
'--instance-id',
metavar='A unique string ID to represent the test-run',
help=(
'Set to a unique string ID for current test-run. Do not put spaces'
' in it.'
),
required=True,
)
parser.add_argument(
'--machine-type',
metavar='Machine-type of the GCE VM or GKE cluster node',
help='Machine-type of the GCE VM or GKE cluster node e.g. n2-standard-32',
required=True,
)
parser.add_argument(
'-n',
'--dry-run',
action='store_true',
help=(
'Only print out the test configurations that will run,'
' not actually run them.'
),
)

args = parser.parse_args()
for argument in ['instance_id', 'machine_type']:
value = getattr(args, argument)
if len(value) == 0 or str.isspace(value):
raise Exception(
f'Argument {argument} (value="{value}") is empty or contains only'
' spaces.'
)
if ' ' in value:
raise Exception(
f'Argument {argument} (value="{value}") contains space in it, which'
' is not supported.'
)

args = parse_args()
main(args)
77 changes: 11 additions & 66 deletions perfmetrics/scripts/testing_on_gke/examples/fio/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,18 @@
it and generates and deploys a helm chart for each valid FIO workload.
"""

# system imports
import argparse
import os
import subprocess
import fio_workload

import sys

def run_command(command: str):
"""Runs the given string command as a subprocess."""
result = subprocess.run(command.split(' '), capture_output=True, text=True)
print(result.stdout)
print(result.stderr)
# local imports from other directories
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'utils'))
from run_tests_common import escape_commas_in_string, parse_args, run_command


def escapeCommasInString(unescapedStr: str) -> str:
"""Returns equivalent string with ',' replaced with '\,' ."""
return unescapedStr.replace(',', '\,')
# local imports from same directory
import fio_workload


def createHelmInstallCommands(
Expand All @@ -62,7 +59,7 @@ def createHelmInstallCommands(
f'--set instanceId={instanceId}',
(
'--set'
f' gcsfuse.mountOptions={escapeCommasInString(fioWorkload.gcsfuseMountOptions)}'
f' gcsfuse.mountOptions={escape_commas_in_string(fioWorkload.gcsfuseMountOptions)}'
),
f'--set nodeType={machineType}',
f'--set podName={podName}',
Expand Down Expand Up @@ -90,57 +87,5 @@ def main(args) -> None:


if __name__ == '__main__':
parser = argparse.ArgumentParser(
prog='FIO test runner',
description=(
'This program takes in a json test-config file, finds out valid FIO'
' workloads from it and generates and deploys a helm chart for each'
' FIO workload.'
),
)
parser.add_argument(
'--workload-config',
metavar='JSON workload configuration file path',
help='Runs FIO tests from this JSON workload configuration file.',
required=True,
)
parser.add_argument(
'--instance-id',
metavar='A unique string ID to represent the test-run',
help=(
'Set to a unique string ID for current test-run. Do not put spaces'
' in it.'
),
required=True,
)
parser.add_argument(
'--machine-type',
metavar='Machine-type of the GCE VM or GKE cluster node',
help='Machine-type of the GCE VM or GKE cluster node e.g. n2-standard-32',
required=True,
)
parser.add_argument(
'-n',
'--dry-run',
action='store_true',
help=(
'Only print out the test configurations that will run,'
' not actually run them.'
),
)

args = parser.parse_args()
for argument in ['instance_id', 'machine_type']:
value = getattr(args, argument)
if len(value) == 0 or str.isspace(value):
raise Exception(
f'Argument {argument} (value="{value}") is empty or contains only'
' spaces.'
)
if ' ' in value:
raise Exception(
f'Argument {argument} (value="{value}") contains space in it, which'
' is not supported.'
)

main(args)
args = parse_args()
main(args)
100 changes: 100 additions & 0 deletions perfmetrics/scripts/testing_on_gke/examples/utils/run_tests_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Copyright 2018 The Kubernetes Authors.
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Common code for fio/run_tests.py and dlio/run_tests.py"""

import argparse
import subprocess
import sys


def run_command(command: str) -> int:
"""Runs the given string command as a subprocess.
Returns exit-code which would be non-zero for error.
"""
result = subprocess.run(
[word for word in command.split(' ') if (word and not str.isspace(word))],
capture_output=True,
text=True,
)
print(result.stdout)
print(result.stderr)
return result.returncode


def escape_commas_in_string(unescapedStr: str) -> str:
"""Returns equivalent string with ',' replaced with '\,' ."""
return unescapedStr.replace(',', '\,')


def parse_args():
parser = argparse.ArgumentParser(
prog='FIO test runner',
description=(
'This program takes in a json test-config file, finds out valid FIO'
' workloads from it and generates and deploys a helm chart for each'
' FIO workload.'
),
)
parser.add_argument(
'--workload-config',
metavar='JSON workload configuration file path',
help='Runs FIO tests from this JSON workload configuration file.',
required=True,
)
parser.add_argument(
'--instance-id',
metavar='A unique string ID to represent the test-run',
help=(
'Set to a unique string ID for current test-run. Do not put spaces'
' in it.'
),
required=True,
)
parser.add_argument(
'--machine-type',
metavar='Machine-type of the GCE VM or GKE cluster node',
help='Machine-type of the GCE VM or GKE cluster node e.g. n2-standard-32',
required=True,
)
parser.add_argument(
'-n',
'--dry-run',
action='store_true',
help=(
'Only print out the test configurations that will run,'
' not actually run them.'
),
)

args = parser.parse_args()
for argument in [
'instance_id',
'machine_type',
]:
value = getattr(args, argument)
if not value.strip():
raise Exception(
f'Argument {argument} (value="{value}") is empty or contains only'
' spaces.'
)
if ' ' in value:
raise Exception(
f'Argument {argument} (value="{value}") contains space in it, which'
' is not supported.'
)

return args
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2018 The Kubernetes Authors.
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
from run_tests_common import escape_commas_in_string


class RunTestsCommonTest(unittest.TestCase):

def test_escape_commas_in_string(self):
tcs = [
{"input": "a:b,c=d,", "expected_output": "a:b\,c=d\,"},
{"input": "", "expected_output": ""},
]
for tc in tcs:
self.assertEqual(
tc["expected_output"], escape_commas_in_string(tc["input"])
)


if __name__ == "__main__":
unittest.main()

0 comments on commit e599fd0

Please sign in to comment.