Skip to content

Commit

Permalink
fixed local run 'no tty message' not appearing with --build (#916)
Browse files Browse the repository at this point in the history
* fixed local run notyy message not appearing with --build

* mocked stdin instead of stdin.isatty
  • Loading branch information
mjksmith committed Dec 3, 2016
1 parent b9067d1 commit b41f314
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
19 changes: 13 additions & 6 deletions paasta_tools/cli/cmds/local_run.py
Expand Up @@ -632,18 +632,25 @@ def configure_and_run_docker_container(
Function prints the output of run command in stdout.
"""

soa_dir = args.yelpsoa_config_root
if instance is None and args.healthcheck:
paasta_print(
"With --healthcheck, --instance must be provided!",
file=sys.stderr,
)
sys.exit(1)
if instance is None and not sys.stdin.isatty():
paasta_print(
"--instance and --cluster must be specified when using paasta local-run without a tty!",
file=sys.stderr,
)
sys.exit(1)

soa_dir = args.yelpsoa_config_root
volumes = list()

load_deployments = docker_hash is None or pull_image

interactive = args.interactive

try:
if instance is None and args.healthcheck:
paasta_print("With --healthcheck, --instance must be provided!", file=sys.stderr)
sys.exit(1)
if instance is None:
instance_type = 'adhoc'
instance = 'interactive'
Expand Down
3 changes: 3 additions & 0 deletions tests/cli/test_cmds_local_run.py
Expand Up @@ -479,16 +479,19 @@ def test_configure_and_run_pulls_image_when_asked(

def test_configure_and_run_docker_container_defaults_to_interactive_instance():
with contextlib.nested(
mock.patch('paasta_tools.cli.cmds.local_run.sys.stdin', autospec=True),
mock.patch('paasta_tools.cli.cmds.local_run.validate_service_instance', autospec=True),
mock.patch('paasta_tools.cli.cmds.local_run.socket.getfqdn', autospec=True),
mock.patch('paasta_tools.cli.cmds.local_run.run_docker_container', autospec=True),
mock.patch('paasta_tools.cli.cmds.local_run.get_default_interactive_config', autospec=True),
) as (
mock_stdin,
mock_validate_service_instance,
mock_socket_get_fqdn,
mock_run_docker_container,
mock_get_default_interactive_config,
):
mock_stdin.isatty.return_value = True
mock_validate_service_instance.side_effect = NoConfigurationForServiceError
mock_docker_client = mock.MagicMock(spec_set=docker.Client)
mock_socket_get_fqdn.return_value = 'fake_hostname'
Expand Down

0 comments on commit b41f314

Please sign in to comment.