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

Update deploy-agent future deps #1681

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion deploy-agent/deployd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
# 2: puppet applied successfully with changes
PUPPET_SUCCESS_EXIT_CODES = [0, 2]

__version__ = '1.2.63'
__version__ = '1.2.64'
13 changes: 6 additions & 7 deletions deploy-agent/deployd/client/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,29 @@
# 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
#
#
# http://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.

from abc import ABCMeta, abstractmethod
from future.utils import with_metaclass
from abc import ABC, abstractmethod


class BaseClient(with_metaclass(ABCMeta, object)):
class BaseClient(ABC):
"""This class plays a role as an interface defining methods for agent to
communicate with teletraan service.
"""

@abstractmethod
def send_reports(self, env_reports=None):
"""Args:
env_reports: a dict with env name as key and DeployStatus as value.

Returns:
PingResponse describing next action for deploy agent.
PingResponse describing next action for deploy agent.
"""
pass
16 changes: 5 additions & 11 deletions deploy-agent/deployd/common/caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# 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
#
#
# http://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.
Expand All @@ -15,11 +15,9 @@
import subprocess
import traceback
import logging
import time
import time
from typing import Optional, Tuple

from future.utils import PY3

log = logging.getLogger(__name__)


Expand All @@ -32,12 +30,8 @@ def call_and_log(cmd, **kwargs) -> Tuple[Optional[str], str, Optional[int]]:
output = ""
start = time.time()
try:
if PY3:
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, encoding='utf-8', **kwargs)
else:
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, **kwargs)
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, encoding='utf-8', **kwargs)
while process.poll() is None:
line = process.stdout.readline()
if line:
Expand Down
1 change: 0 additions & 1 deletion deploy-agent/deployd/common/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
# Copyright 2016 Pinterest, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
28 changes: 8 additions & 20 deletions deploy-agent/deployd/common/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# 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
#
#
# http://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.
Expand All @@ -22,8 +22,6 @@
import traceback
from typing import Tuple

from future.utils import PY3

from deployd.common.types import DeployReport, PingStatus, PRE_STAGE_STEPS, AgentStatus

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -111,14 +109,11 @@ def run_cmd(self, cmd, **kw) -> DeployReport:

# sleep some seconds before next poll
sleep_time = self._get_sleep_interval(start, self.PROCESS_POLL_INTERVAL)
if PY3:
# Wait up to sleep_time for the process to terminate (new in Python 3.3)
try:
process.wait(sleep_time)
except subprocess.TimeoutExpired:
pass
else:
time.sleep(sleep_time)
# Wait up to sleep_time for the process to terminate (new in Python 3.3)
try:
process.wait(sleep_time)
except subprocess.TimeoutExpired:
pass

# finish executing sub process
deploy_report.error_code = process.returncode
Expand Down Expand Up @@ -202,14 +197,7 @@ def _graceful_shutdown(self, process) -> None:
try:
log.info('Gracefully shutdown currently running process with timeout {}'.format(self.TERMINATE_TIMEOUT))
os.killpg(process.pid, signal.SIGTERM)
if PY3:
process.wait(self.TERMINATE_TIMEOUT)
else:
start_time = datetime.datetime.now()
while process.poll() is None:
if (datetime.datetime.now() - start_time).seconds > self.TERMINATE_TIMEOUT:
raise Exception('Timed out while waiting for the process to shutdown')
time.sleep(min(self.PROCESS_POLL_INTERVAL, self.TERMINATE_TIMEOUT))
process.wait(self.TERMINATE_TIMEOUT)
except Exception as e:
log.debug('Failed to gracefully shutdown: {}'.format(e))
Executor._kill_process(process)
Expand Down
20 changes: 4 additions & 16 deletions deploy-agent/deployd/common/single_instance.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function
from __future__ import absolute_import
# Copyright 2016 Pinterest, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,10 +15,8 @@
import logging
import os
import stat
import errno
import fcntl
from . import utils
from future.utils import PY3
import tempfile
log = logging.getLogger(__name__)
LOCKFILE_DIR = '/var/lock'
Expand All @@ -32,12 +28,12 @@ def __init__(self) -> None:
appname = 'deploy-agent'
lockfile_name = '.{}.lock'.format(appname)
self._create_lock_dir()
# Backward compatibility as old deploy agent versions use lock file in /tmp.
# Use the old lock file if it exists
# Backward compatibility as old deploy agent versions use lock file in /tmp.
# Use the old lock file if it exists
tmp_lockfile_path = os.path.join(tempfile.gettempdir(), lockfile_name)
if os.path.exists(tmp_lockfile_path):
lockfile_path = tmp_lockfile_path
else:
else:
lockfile_path = os.path.join(LOCKFILE_DIR, lockfile_name)
lockfile_flags = os.O_WRONLY | os.O_CREAT
# This is 0o222, i.e. 146, --w--w--w-
Expand All @@ -61,12 +57,4 @@ def __init__(self) -> None:
utils.exit_abruptly(1)

def _create_lock_dir(self) -> None:
if PY3:
os.makedirs(LOCKFILE_DIR, exist_ok=True)
else:
# Need to handle the case when lock dir exists in py2
try:
os.makedirs(LOCKFILE_DIR) # py2
except OSError as e:
if e.errno != errno.EEXIST:
raise
os.makedirs(LOCKFILE_DIR, exist_ok=True)
1 change: 0 additions & 1 deletion deploy-agent/deployd/common/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
# Copyright 2016 Pinterest, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion deploy-agent/deployd/download/download_helper_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing import Optional

import boto3
from future.moves.urllib.parse import urlparse
from urllib.parse import urlparse

from deployd.download.download_helper import DownloadHelper
from deployd.download.s3_download_helper import S3DownloadHelper
Expand Down
3 changes: 1 addition & 2 deletions deploy-agent/deployd/download/http_download_helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
# Copyright 2016 Pinterest, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -98,4 +97,4 @@ def validate_source(self) -> bool:
return True
else:
log.error(f"{domain} is not in the allow list: {allow_list}.")
return False
return False
1 change: 0 additions & 1 deletion deploy-agent/deployd/staging/stager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
# Copyright 2016 Pinterest, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 1 addition & 2 deletions deploy-agent/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
"gevent==24.2.1; python_version >= '3.12'",
"lockfile==0.10.2",
"boto3==1.34.134",
"python-daemon==2.0.6",
"future==0.18.2"
"python-daemon==2.0.6"
]

setup(
Expand Down
5 changes: 2 additions & 3 deletions deploy-agent/tests/unit/deploy/client/test_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# limitations under the License.

import unittest
from abc import ABCMeta, abstractmethod
from future.utils import with_metaclass
from abc import ABC, abstractmethod
from tests import TestCase

from deployd.client.base_client import BaseClient
Expand All @@ -34,7 +33,7 @@ def test_abc_equivalent_to_old(self):
"""
Make sure that new changes to base client extend the original class
"""
class OldBaseClient(with_metaclass(ABCMeta, object)):
class OldBaseClient(ABC):
@abstractmethod
def send_reports(self, env_reports=None):
pass
Expand Down
Loading