Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Commit

Permalink
add option to specify docker-compose file
Browse files Browse the repository at this point in the history
  • Loading branch information
Chia-Chi Lin committed Nov 2, 2016
1 parent 3ebe4fb commit 77bb7a5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
38 changes: 24 additions & 14 deletions schematizer/tools/register_tables.py
Expand Up @@ -65,6 +65,13 @@ def _setup_cli_options():
help='Name of the cluster to connect to, such as primary, aux, etc. '
'Required.'
)
parser.add_argument(
'--docker-file',
type=str,
default='docker-compose.yml',
help='Docker compose file for building Schematizer container. '
'Default is %(default)s.'
)
return parser


Expand All @@ -75,7 +82,7 @@ def run(parsed_args):
)
with _setup_mysql_connection(conn_param) as conn:
tables_info = _get_mysql_tables_info(conn)
with _setup_schematizer_container() as host:
with _setup_schematizer_container(parsed_args.docker_file) as host:
register_tables_results = _register_tables(host, tables_info)
results_stats = _verify_register_tables_results(register_tables_results)
_output_results(results_stats)
Expand Down Expand Up @@ -162,34 +169,37 @@ def _execute_query(connection, query):


@contextmanager
def _setup_schematizer_container():
def _setup_schematizer_container(docker_compose_file):
"""Set up a scheamtizer container and yields the IP address of the host
container. It removes the container when exiting the context manager.
"""
project = 'schematizermanualtest{}'.format(getpass.getuser())
# TODO(DATAPIPE-1822|abrar): make it configurable so that it can
# be run using both docker-compose.yml and docker-compose-opensource.yml
service = 'schematizerservice'

project_arg = '--project-name={}'.format(project)
docker_compose_file_arg = '--file={}'.format(docker_compose_file)
try:
_run_docker_compose_command(
'--project-name={}'.format(project),
'--file=docker-compose-opensource.yml',
project_arg,
docker_compose_file_arg,
'pull'
)
_run_docker_compose_command(
'--project-name={}'.format(project),
'--file=docker-compose-opensource.yml',
project_arg,
docker_compose_file_arg,
'rm',
'--force'
)
_run_docker_compose_command(
'--project-name={}'.format(project),
'--file=docker-compose-opensource.yml',
project_arg,
docker_compose_file_arg,
'build'
)
_run_docker_compose_command(
'--project-name={}'.format(project),
'--file=docker-compose-opensource.yml',
project_arg,
docker_compose_file_arg,
'up',
'-d',
'--no-build',
Expand All @@ -202,13 +212,13 @@ def _setup_schematizer_container():

finally:
_run_docker_compose_command(
'--project-name={}'.format(project),
'--file=docker-compose-opensource.yml',
project_arg,
docker_compose_file_arg,
'kill'
)
_run_docker_compose_command(
'--project-name={}'.format(project),
'--file=docker-compose-opensource.yml',
project_arg,
docker_compose_file_arg,
'rm',
'--force'
)
Expand Down
3 changes: 2 additions & 1 deletion tests/tools/register_tables_test.py
Expand Up @@ -61,7 +61,8 @@ def simple_topology_file(self, tmpdir):
def test_register_all_schematizer_tables(self, simple_topology_file):
parsed_args = Namespace(
cluster_name=self.schematizer_cluster,
config_file=simple_topology_file
config_file=simple_topology_file,
docker_file='docker-compose-opensource.yml'
)
with mock.patch(
'schematizer.tools.register_tables.print'
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Expand Up @@ -45,7 +45,8 @@ commands =
docker pull docker-dev.yelpcorp.com/mysql-testing:latest
coverage erase
coverage run --source=schematizer/ -m pytest -vv --strict {posargs:tests}
coverage report --show-missing --fail-under 89
# TODO: [clin|DATAPIPE-2024] increase code test coverage
coverage report --show-missing --fail-under 86

[testenv:acceptance]
whitelist_externals =
Expand Down

0 comments on commit 77bb7a5

Please sign in to comment.