Skip to content

Commit

Permalink
Cleanup common directory (Azure#2902)
Browse files Browse the repository at this point in the history
Co-authored-by: narrieta <narrieta>
  • Loading branch information
narrieta authored and nagworld9 committed Aug 30, 2023
1 parent 3294044 commit 9630724
Show file tree
Hide file tree
Showing 40 changed files with 172 additions and 171 deletions.
6 changes: 3 additions & 3 deletions azurelinuxagent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
import subprocess
import sys
import threading
from azurelinuxagent.common import cgroupconfigurator, logcollector
from azurelinuxagent.common.cgroupapi import SystemdCgroupsApi
from azurelinuxagent.ga import logcollector, cgroupconfigurator
from azurelinuxagent.ga.cgroupapi import SystemdCgroupsApi

import azurelinuxagent.common.conf as conf
import azurelinuxagent.common.event as event
import azurelinuxagent.common.logger as logger
from azurelinuxagent.common.future import ustr
from azurelinuxagent.common.logcollector import LogCollector, OUTPUT_RESULTS_FILE_PATH
from azurelinuxagent.ga.logcollector import LogCollector, OUTPUT_RESULTS_FILE_PATH
from azurelinuxagent.common.osutil import get_osutil
from azurelinuxagent.common.utils import fileutil, textutil
from azurelinuxagent.common.utils.flexible_version import FlexibleVersion
Expand Down
2 changes: 1 addition & 1 deletion azurelinuxagent/daemon/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from azurelinuxagent.common.osutil import get_osutil
from azurelinuxagent.common.protocol.goal_state import GoalState, GoalStateProperties
from azurelinuxagent.common.protocol.util import get_protocol_util
from azurelinuxagent.common.rdma import setup_rdma_device
from azurelinuxagent.pa.rdma.rdma import setup_rdma_device
from azurelinuxagent.common.utils import textutil
from azurelinuxagent.common.version import AGENT_NAME, AGENT_LONG_NAME, \
AGENT_VERSION, \
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
import uuid

from azurelinuxagent.common import logger
from azurelinuxagent.common.cgroup import CpuCgroup, MemoryCgroup
from azurelinuxagent.common.cgroupstelemetry import CGroupsTelemetry
from azurelinuxagent.ga.cgroup import CpuCgroup, MemoryCgroup
from azurelinuxagent.ga.cgroupstelemetry import CGroupsTelemetry
from azurelinuxagent.common.conf import get_agent_pid_file_path
from azurelinuxagent.common.exception import CGroupsException, ExtensionErrorCodes, ExtensionError, \
ExtensionOperationError
from azurelinuxagent.common.future import ustr
from azurelinuxagent.common.osutil import systemd
from azurelinuxagent.common.utils import fileutil, shellutil
from azurelinuxagent.common.utils.extensionprocessutil import handle_process_completion, read_output, \
from azurelinuxagent.ga.extensionprocessutil import handle_process_completion, read_output, \
TELEMETRY_MESSAGE_MAX_LEN
from azurelinuxagent.common.utils.flexible_version import FlexibleVersion
from azurelinuxagent.common.version import get_distro
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@

from azurelinuxagent.common import conf
from azurelinuxagent.common import logger
from azurelinuxagent.common.cgroup import CpuCgroup, AGENT_NAME_TELEMETRY, MetricsCounter, MemoryCgroup
from azurelinuxagent.common.cgroupapi import CGroupsApi, SystemdCgroupsApi, SystemdRunError, EXTENSION_SLICE_PREFIX
from azurelinuxagent.common.cgroupstelemetry import CGroupsTelemetry
from azurelinuxagent.ga.cgroup import CpuCgroup, AGENT_NAME_TELEMETRY, MetricsCounter, MemoryCgroup
from azurelinuxagent.ga.cgroupapi import CGroupsApi, SystemdCgroupsApi, SystemdRunError, EXTENSION_SLICE_PREFIX
from azurelinuxagent.ga.cgroupstelemetry import CGroupsTelemetry
from azurelinuxagent.common.exception import ExtensionErrorCodes, CGroupsException, AgentMemoryExceededException
from azurelinuxagent.common.future import ustr
from azurelinuxagent.common.osutil import get_osutil, systemd
from azurelinuxagent.common.version import get_distro
from azurelinuxagent.common.utils import shellutil, fileutil
from azurelinuxagent.common.utils.extensionprocessutil import handle_process_completion
from azurelinuxagent.ga.extensionprocessutil import handle_process_completion
from azurelinuxagent.common.event import add_event, WALAEventOperation

AZURE_SLICE = "azure.slice"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import threading

from azurelinuxagent.common import logger
from azurelinuxagent.common.cgroup import CpuCgroup
from azurelinuxagent.ga.cgroup import CpuCgroup
from azurelinuxagent.common.future import ustr


Expand Down
10 changes: 5 additions & 5 deletions azurelinuxagent/ga/collect_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
import sys
import threading
import time
from azurelinuxagent.common import cgroupconfigurator, logcollector
from azurelinuxagent.ga import logcollector, cgroupconfigurator

import azurelinuxagent.common.conf as conf
from azurelinuxagent.common import logger
from azurelinuxagent.common.cgroup import MetricsCounter
from azurelinuxagent.ga.cgroup import MetricsCounter
from azurelinuxagent.common.event import elapsed_milliseconds, add_event, WALAEventOperation, report_metric
from azurelinuxagent.common.future import ustr
from azurelinuxagent.common.interfaces import ThreadHandlerInterface
from azurelinuxagent.common.logcollector import COMPRESSED_ARCHIVE_PATH, GRACEFUL_KILL_ERRCODE
from azurelinuxagent.common.cgroupconfigurator import CGroupConfigurator, LOGCOLLECTOR_MEMORY_LIMIT
from azurelinuxagent.ga.interfaces import ThreadHandlerInterface
from azurelinuxagent.ga.logcollector import COMPRESSED_ARCHIVE_PATH, GRACEFUL_KILL_ERRCODE
from azurelinuxagent.ga.cgroupconfigurator import CGroupConfigurator, LOGCOLLECTOR_MEMORY_LIMIT
from azurelinuxagent.common.protocol.util import get_protocol_util
from azurelinuxagent.common.utils import shellutil
from azurelinuxagent.common.utils.shellutil import CommandError
Expand Down
2 changes: 1 addition & 1 deletion azurelinuxagent/ga/collect_telemetry_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
CollectOrReportEventDebugInfo, EVENT_FILE_REGEX, parse_event
from azurelinuxagent.common.exception import InvalidExtensionEventError, ServiceStoppedError
from azurelinuxagent.common.future import ustr
from azurelinuxagent.common.interfaces import ThreadHandlerInterface
from azurelinuxagent.ga.interfaces import ThreadHandlerInterface
from azurelinuxagent.common.telemetryevent import TelemetryEvent, TelemetryEventParam, \
GuestAgentGenericLogsSchema, GuestAgentExtensionEventsSchema
from azurelinuxagent.common.utils import textutil
Expand Down
2 changes: 1 addition & 1 deletion azurelinuxagent/ga/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from azurelinuxagent.common.dhcp import get_dhcp_handler
from azurelinuxagent.common.event import add_periodic, WALAEventOperation, add_event
from azurelinuxagent.common.future import ustr
from azurelinuxagent.common.interfaces import ThreadHandlerInterface
from azurelinuxagent.ga.interfaces import ThreadHandlerInterface
from azurelinuxagent.common.osutil import get_osutil
from azurelinuxagent.common.protocol.util import get_protocol_util
from azurelinuxagent.common.version import AGENT_NAME, CURRENT_VERSION
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion azurelinuxagent/ga/exthandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from azurelinuxagent.common import version
from azurelinuxagent.common.agent_supported_feature import get_agent_supported_features_list_for_extensions, \
SupportedFeatureNames, get_supported_feature_by_name, get_agent_supported_features_list_for_crp
from azurelinuxagent.common.cgroupconfigurator import CGroupConfigurator
from azurelinuxagent.ga.cgroupconfigurator import CGroupConfigurator
from azurelinuxagent.common.datacontract import get_properties, set_properties
from azurelinuxagent.common.errorstate import ErrorState
from azurelinuxagent.common.event import add_event, elapsed_milliseconds, WALAEventOperation, \
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
from datetime import datetime
from heapq import heappush, heappop

from azurelinuxagent.common.cgroup import CpuCgroup, AGENT_LOG_COLLECTOR, MemoryCgroup
from azurelinuxagent.ga.cgroup import CpuCgroup, AGENT_LOG_COLLECTOR, MemoryCgroup
from azurelinuxagent.common.conf import get_lib_dir, get_ext_log_dir, get_agent_log_file
from azurelinuxagent.common.event import initialize_event_logger_vminfo_common_parameters
from azurelinuxagent.common.future import ustr
from azurelinuxagent.common.logcollector_manifests import MANIFEST_NORMAL, MANIFEST_FULL
from azurelinuxagent.ga.logcollector_manifests import MANIFEST_NORMAL, MANIFEST_FULL

# Please note: be careful when adding agent dependencies in this module.
# This module uses its own logger and logs to its own file, not to the agent log.
Expand Down
8 changes: 4 additions & 4 deletions azurelinuxagent/ga/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import azurelinuxagent.common.conf as conf
import azurelinuxagent.common.logger as logger
import azurelinuxagent.common.utils.networkutil as networkutil
from azurelinuxagent.common.cgroup import MetricValue, MetricsCategory, MetricsCounter
from azurelinuxagent.common.cgroupconfigurator import CGroupConfigurator
from azurelinuxagent.common.cgroupstelemetry import CGroupsTelemetry
from azurelinuxagent.ga.cgroup import MetricValue, MetricsCategory, MetricsCounter
from azurelinuxagent.ga.cgroupconfigurator import CGroupConfigurator
from azurelinuxagent.ga.cgroupstelemetry import CGroupsTelemetry
from azurelinuxagent.common.errorstate import ErrorState
from azurelinuxagent.common.event import add_event, WALAEventOperation, report_metric
from azurelinuxagent.common.future import ustr
from azurelinuxagent.common.interfaces import ThreadHandlerInterface
from azurelinuxagent.ga.interfaces import ThreadHandlerInterface
from azurelinuxagent.common.osutil import get_osutil
from azurelinuxagent.common.protocol.healthservice import HealthService
from azurelinuxagent.common.protocol.imds import get_imds_client
Expand Down
2 changes: 1 addition & 1 deletion azurelinuxagent/ga/send_telemetry_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from azurelinuxagent.common.event import add_event, WALAEventOperation
from azurelinuxagent.common.exception import ServiceStoppedError
from azurelinuxagent.common.future import ustr, Queue, Empty
from azurelinuxagent.common.interfaces import ThreadHandlerInterface
from azurelinuxagent.ga.interfaces import ThreadHandlerInterface
from azurelinuxagent.common.utils import textutil


Expand Down
4 changes: 2 additions & 2 deletions azurelinuxagent/ga/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
from azurelinuxagent.common.utils import fileutil, textutil
from azurelinuxagent.common.agent_supported_feature import get_supported_feature_by_name, SupportedFeatureNames, \
get_agent_supported_features_list_for_crp
from azurelinuxagent.common.cgroupconfigurator import CGroupConfigurator
from azurelinuxagent.ga.cgroupconfigurator import CGroupConfigurator
from azurelinuxagent.common.event import add_event, initialize_event_logger_vminfo_common_parameters, \
WALAEventOperation, EVENTS_DIRECTORY
from azurelinuxagent.common.exception import ExitException, AgentUpgradeExitException, AgentMemoryExceededException
from azurelinuxagent.common.future import ustr
from azurelinuxagent.common.osutil import get_osutil, systemd
from azurelinuxagent.common.persist_firewall_rules import PersistFirewallRulesHandler
from azurelinuxagent.ga.persist_firewall_rules import PersistFirewallRulesHandler
from azurelinuxagent.common.protocol.hostplugin import HostPluginProtocol, VmSettingsNotSupported
from azurelinuxagent.common.protocol.restapi import VERSION_0
from azurelinuxagent.common.protocol.util import get_protocol_util
Expand Down
4 changes: 2 additions & 2 deletions azurelinuxagent/pa/deprovision/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import azurelinuxagent.common.conf as conf
import azurelinuxagent.common.utils.fileutil as fileutil
from azurelinuxagent.common import version
from azurelinuxagent.common.cgroupconfigurator import _AGENT_DROP_IN_FILE_SLICE, _DROP_IN_FILE_CPU_ACCOUNTING, \
from azurelinuxagent.ga.cgroupconfigurator import _AGENT_DROP_IN_FILE_SLICE, _DROP_IN_FILE_CPU_ACCOUNTING, \
_DROP_IN_FILE_CPU_QUOTA, _DROP_IN_FILE_MEMORY_ACCOUNTING, LOGCOLLECTOR_SLICE
from azurelinuxagent.common.exception import ProtocolError
from azurelinuxagent.common.osutil import get_osutil, systemd
from azurelinuxagent.common.persist_firewall_rules import PersistFirewallRulesHandler
from azurelinuxagent.ga.persist_firewall_rules import PersistFirewallRulesHandler
from azurelinuxagent.common.protocol.util import get_protocol_util
from azurelinuxagent.ga.exthandlers import HANDLER_COMPLETE_NAME_PATTERN

Expand Down
2 changes: 1 addition & 1 deletion azurelinuxagent/pa/rdma/centos.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import time
import azurelinuxagent.common.logger as logger
import azurelinuxagent.common.utils.shellutil as shellutil
from azurelinuxagent.common.rdma import RDMAHandler
from azurelinuxagent.pa.rdma.rdma import RDMAHandler


class CentOSRDMAHandler(RDMAHandler):
Expand Down
2 changes: 1 addition & 1 deletion azurelinuxagent/pa/rdma/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from distutils.version import LooseVersion as Version # pylint: disable=no-name-in-module, import-error

import azurelinuxagent.common.logger as logger
from azurelinuxagent.common.rdma import RDMAHandler
from azurelinuxagent.pa.rdma.rdma import RDMAHandler
from azurelinuxagent.common.version import DISTRO_FULL_NAME, DISTRO_VERSION
from .centos import CentOSRDMAHandler
from .suse import SUSERDMAHandler
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion azurelinuxagent/pa/rdma/suse.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import azurelinuxagent.common.logger as logger
import azurelinuxagent.common.utils.shellutil as shellutil

from azurelinuxagent.common.rdma import RDMAHandler
from azurelinuxagent.pa.rdma.rdma import RDMAHandler
from azurelinuxagent.common.version import DISTRO_VERSION

from distutils.version import LooseVersion as Version
Expand Down
2 changes: 1 addition & 1 deletion azurelinuxagent/pa/rdma/ubuntu.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import azurelinuxagent.common.conf as conf
import azurelinuxagent.common.logger as logger
import azurelinuxagent.common.utils.shellutil as shellutil
from azurelinuxagent.common.rdma import RDMAHandler
from azurelinuxagent.pa.rdma.rdma import RDMAHandler


class UbuntuRDMAHandler(RDMAHandler):
Expand Down
4 changes: 2 additions & 2 deletions tests/common/osutil/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ def mock_popen(command, *args, **kwargs):
return mock_popen.original(command, *args, **kwargs)
mock_popen.original = subprocess.Popen

with patch("azurelinuxagent.common.cgroupapi.subprocess.Popen", side_effect=mock_popen) as popen_patcher:
with patch("azurelinuxagent.ga.cgroupapi.subprocess.Popen", side_effect=mock_popen) as popen_patcher:
with patch('os.getuid', return_value=uid):
popen_patcher.wait = wait
popen_patcher.destination = destination
Expand Down Expand Up @@ -910,7 +910,7 @@ def mock_popen(command, *args, **kwargs):
return mock_popen.original(command, *args, **kwargs)
mock_popen.original = subprocess.Popen

with patch("azurelinuxagent.common.cgroupapi.subprocess.Popen", side_effect=mock_popen):
with patch("azurelinuxagent.ga.cgroupapi.subprocess.Popen", side_effect=mock_popen):
success = osutil.DefaultOSUtil().remove_firewall(mock_iptables.destination, mock_iptables.uid, mock_iptables.wait)

delete_conntrack_accept_command = TestOSUtil._command_to_string(osutil.get_firewall_delete_conntrack_accept_command(mock_iptables.wait, mock_iptables.destination))
Expand Down
24 changes: 12 additions & 12 deletions tests/common/utils/test_extension_process_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import subprocess
import tempfile

from azurelinuxagent.common.cgroup import CpuCgroup
from azurelinuxagent.ga.cgroup import CpuCgroup
from azurelinuxagent.common.exception import ExtensionError, ExtensionErrorCodes
from azurelinuxagent.common.future import ustr
from azurelinuxagent.common.utils.extensionprocessutil import format_stdout_stderr, read_output, \
from azurelinuxagent.ga.extensionprocessutil import format_stdout_stderr, read_output, \
wait_for_process_completion_or_timeout, handle_process_completion
from tests.lib.tools import AgentTestCase, patch, data_dir

Expand Down Expand Up @@ -68,7 +68,7 @@ def test_wait_for_process_completion_or_timeout_should_kill_process_on_timeout(s
preexec_fn=os.setsid)

# We don't actually mock the kill, just wrap it so we can assert its call count
with patch('azurelinuxagent.common.utils.extensionprocessutil.os.killpg', wraps=os.killpg) as patch_kill:
with patch('azurelinuxagent.ga.extensionprocessutil.os.killpg', wraps=os.killpg) as patch_kill:
with patch('time.sleep') as mock_sleep:
timed_out, ret, _ = wait_for_process_completion_or_timeout(process=process, timeout=timeout, cpu_cgroup=None)

Expand Down Expand Up @@ -211,20 +211,20 @@ def test_handle_process_completion_should_raise_on_nonzero_exit_code(self):
self.assertIn("Non-zero exit code:", ustr(context_manager.exception))

def test_read_output_should_return_no_content(self):
with patch('azurelinuxagent.common.utils.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 0):
with patch('azurelinuxagent.ga.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 0):
expected = ""
actual = read_output(self.stdout, self.stderr)
self.assertEqual(expected, actual)

def test_read_output_should_truncate_the_content(self):
with patch('azurelinuxagent.common.utils.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 50):
with patch('azurelinuxagent.ga.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 50):
expected = "[stdout]\nr the lazy dog.\n\n" \
"[stderr]\ns jump quickly."
actual = read_output(self.stdout, self.stderr)
self.assertEqual(expected, actual)

def test_read_output_should_not_truncate_the_content(self):
with patch('azurelinuxagent.common.utils.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 90):
with patch('azurelinuxagent.ga.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 90):
expected = "[stdout]\nThe quick brown fox jumps over the lazy dog.\n\n" \
"[stderr]\nThe five boxing wizards jump quickly."
actual = read_output(self.stdout, self.stderr)
Expand All @@ -240,7 +240,7 @@ def test_format_stdout_stderr00(self):
stderr = "The five boxing wizards jump quickly."

expected = "[stdout]\n{0}\n\n[stderr]\n{1}".format(stdout, stderr)
with patch('azurelinuxagent.common.utils.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 1000):
with patch('azurelinuxagent.ga.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 1000):
actual = format_stdout_stderr(stdout, stderr)
self.assertEqual(expected, actual)

Expand All @@ -254,7 +254,7 @@ def test_format_stdout_stderr01(self):

# noinspection SpellCheckingInspection
expected = '[stdout]\ns over the lazy dog.\n\n[stderr]\nizards jump quickly.'
with patch('azurelinuxagent.common.utils.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 60):
with patch('azurelinuxagent.ga.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 60):
actual = format_stdout_stderr(stdout, stderr)
self.assertEqual(expected, actual)
self.assertEqual(60, len(actual))
Expand All @@ -268,7 +268,7 @@ def test_format_stdout_stderr02(self):
stderr = "The five boxing wizards jump quickly."

expected = '[stdout]\nempty\n\n[stderr]\ns jump quickly.'
with patch('azurelinuxagent.common.utils.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 40):
with patch('azurelinuxagent.ga.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 40):
actual = format_stdout_stderr(stdout, stderr)
self.assertEqual(expected, actual)
self.assertEqual(40, len(actual))
Expand All @@ -282,7 +282,7 @@ def test_format_stdout_stderr03(self):
stderr = "empty"

expected = '[stdout]\nr the lazy dog.\n\n[stderr]\nempty'
with patch('azurelinuxagent.common.utils.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 40):
with patch('azurelinuxagent.ga.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 40):
actual = format_stdout_stderr(stdout, stderr)
self.assertEqual(expected, actual)
self.assertEqual(40, len(actual))
Expand All @@ -296,7 +296,7 @@ def test_format_stdout_stderr04(self):
stderr = "The five boxing wizards jump quickly."

expected = ''
with patch('azurelinuxagent.common.utils.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 4):
with patch('azurelinuxagent.ga.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 4):
actual = format_stdout_stderr(stdout, stderr)
self.assertEqual(expected, actual)
self.assertEqual(0, len(actual))
Expand All @@ -307,6 +307,6 @@ def test_format_stdout_stderr05(self):
"""

expected = '[stdout]\n\n\n[stderr]\n'
with patch('azurelinuxagent.common.utils.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 1000):
with patch('azurelinuxagent.ga.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN', 1000):
actual = format_stdout_stderr('', '')
self.assertEqual(expected, actual)
Loading

0 comments on commit 9630724

Please sign in to comment.