Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse maintenance window check for formplayer deploys #6192

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions src/commcare_cloud/commands/deploy/commcare.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import shlex
from datetime import datetime, timedelta

import pytz
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pytz is already imported in deploy/utils.py if you happen to notice that there isn't a diff adding it to the file.


from commcare_cloud.alias import commcare_cloud
from commcare_cloud.cli_utils import ask
from commcare_cloud.colors import color_error, color_notice, color_summary
Expand All @@ -19,7 +17,7 @@
record_deploy_start,
announce_deploy_success,
create_release_tag,
within_maintenance_window,
confirm_environment_time,
DeployContext,
record_deploy_failed,
)
Expand Down Expand Up @@ -115,7 +113,7 @@ def confirm_deploy(environment, deploy_revs, rev_diffs, args):

if not (
_confirm_translated(environment, quiet=args.quiet)
and _confirm_environment_time(environment, quiet=args.quiet)
and confirm_environment_time(environment, quiet=args.quiet)
):
return False

Expand Down Expand Up @@ -178,19 +176,6 @@ def _confirm_translated(environment, quiet=False):
)


def _confirm_environment_time(environment, quiet=False):
if within_maintenance_window(environment):
return True
window = environment.fab_settings_config.acceptable_maintenance_window
d = datetime.now(pytz.timezone(window['timezone']))
message = (
"Whoa there bud! You're deploying '%s' outside the configured maintenance window. "
"The current local time is %s.\n"
"ARE YOU DOING SOMETHING EXCEPTIONAL THAT WARRANTS THIS?"
) % (environment.name, d.strftime("%-I:%M%p on %h. %d %Z"))
return ask(message, quiet=quiet)


def _print_same_code_warning(code_branch):
if code_branch == 'master':
branch_specific_msg = "Perhaps you meant to merge a PR or specify a --set code_branch=<branch> ?"
Expand Down
14 changes: 12 additions & 2 deletions src/commcare_cloud/commands/deploy/formplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
from commcare_cloud.commands.ansible.helpers import AnsibleContext
from commcare_cloud.commands.deploy.deploy_diff import DeployDiff
from commcare_cloud.commands.deploy.sentry import update_sentry_post_deploy
from commcare_cloud.commands.deploy.utils import record_deploy_start, record_deploy_failed, \
announce_deploy_success, create_release_tag, DeployContext
from commcare_cloud.commands.deploy.utils import (
announce_deploy_success,
confirm_environment_time,
create_release_tag,
record_deploy_start,
record_deploy_failed,
DeployContext
)
from commcare_cloud.user_utils import get_default_username
from commcare_cloud.commands.utils import timeago
from commcare_cloud.events import publish_deploy_event
Expand Down Expand Up @@ -47,6 +53,10 @@ def _format_time_ago(time):


def deploy_formplayer(environment, args):
if not confirm_environment_time(environment, quiet=args.quiet):
print(color_notice("Aborted by user"))
return 1

print(color_notice("\nPreparing to deploy Formplayer to: "), end="")
print(f"{environment.name}\n")

Expand Down
15 changes: 15 additions & 0 deletions src/commcare_cloud/commands/deploy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from memoized import memoized

from commcare_cloud.alias import commcare_cloud
from commcare_cloud.cli_utils import ask
from commcare_cloud.colors import color_summary, color_error
from commcare_cloud.commands.deploy.slack import notify_slack_deploy_start, notify_slack_deploy_end
from commcare_cloud.user_utils import get_default_username
Expand Down Expand Up @@ -55,7 +56,7 @@
def send_deploy_start_email(environment, context):
is_nonstandard_deploy_time = not within_maintenance_window(environment)
is_non_default_branch = (
context.revision != environment.fab_settings_config.default_branch and

Check failure on line 59 in src/commcare_cloud/commands/deploy/utils.py

View workflow job for this annotation

GitHub Actions / Flake8

src/commcare_cloud/commands/deploy/utils.py#L59

Line break after binary operator (W504)
context.revision is not None
)
env_name = environment.meta_config.deploy_env
Expand Down Expand Up @@ -126,6 +127,20 @@
show_command=False
)


def confirm_environment_time(environment, quiet=False):
if within_maintenance_window(environment):
return True
window = environment.fab_settings_config.acceptable_maintenance_window
d = datetime.now(pytz.timezone(window['timezone']))
message = (
"Whoa there bud! You're deploying '%s' outside the configured maintenance window. "
"The current local time is %s.\n"
"ARE YOU DOING SOMETHING EXCEPTIONAL THAT WARRANTS THIS?"
) % (environment.name, d.strftime("%-I:%M%p on %h. %d %Z"))
return ask(message, quiet=quiet)


def within_maintenance_window(environment):
window = environment.fab_settings_config.acceptable_maintenance_window
if window:
Expand Down
Loading