diff --git a/azurelinuxagent/common/osutil/factory.py b/azurelinuxagent/common/osutil/factory.py index 5baa9ebb89..69f8430052 100644 --- a/azurelinuxagent/common/osutil/factory.py +++ b/azurelinuxagent/common/osutil/factory.py @@ -16,27 +16,27 @@ # +from distutils.version import LooseVersion as Version + import azurelinuxagent.common.logger as logger -from azurelinuxagent.common.version import * -from .default import DefaultOSUtil +from azurelinuxagent.common.version import DISTRO_NAME, DISTRO_CODE_NAME, DISTRO_VERSION, DISTRO_FULL_NAME +from .alpine import AlpineOSUtil from .arch import ArchUtil +from .bigip import BigIpOSUtil from .clearlinux import ClearLinuxUtil from .coreos import CoreOSUtil from .debian import DebianOSBaseUtil, DebianOSModernUtil +from .default import DefaultOSUtil from .freebsd import FreeBSDOSUtil +from .gaia import GaiaOSUtil +from .iosxe import IosxeOSUtil +from .nsbsd import NSBSDOSUtil from .openbsd import OpenBSDOSUtil +from .openwrt import OpenWRTOSUtil from .redhat import RedhatOSUtil, Redhat6xOSUtil from .suse import SUSEOSUtil, SUSE11OSUtil from .ubuntu import UbuntuOSUtil, Ubuntu12OSUtil, Ubuntu14OSUtil, \ UbuntuSnappyOSUtil, Ubuntu16OSUtil, Ubuntu18OSUtil -from .alpine import AlpineOSUtil -from .bigip import BigIpOSUtil -from .gaia import GaiaOSUtil -from .iosxe import IosxeOSUtil -from .nsbsd import NSBSDOSUtil -from .openwrt import OpenWRTOSUtil - -from distutils.version import LooseVersion as Version def get_osutil(distro_name=DISTRO_NAME, diff --git a/azurelinuxagent/common/protocol/goal_state.py b/azurelinuxagent/common/protocol/goal_state.py index 5624360058..de0124c236 100644 --- a/azurelinuxagent/common/protocol/goal_state.py +++ b/azurelinuxagent/common/protocol/goal_state.py @@ -25,7 +25,10 @@ from azurelinuxagent.common.AgentGlobals import AgentGlobals from azurelinuxagent.common.datacontract import set_properties from azurelinuxagent.common.event import add_event, WALAEventOperation -from azurelinuxagent.common.protocol.restapi import * +from azurelinuxagent.common.future import ustr +from azurelinuxagent.common.protocol.restapi import Cert, CertList, Extension, ExtHandler, ExtHandlerList, \ + ExtHandlerVersionUri, RemoteAccessUser, RemoteAccessUsersList, \ + VMAgentManifest, VMAgentManifestList, VMAgentManifestUri from azurelinuxagent.common.utils import fileutil from azurelinuxagent.common.utils.cryptutil import CryptUtil from azurelinuxagent.common.utils.textutil import parse_doc, findall, find, findtext, getattrib, gettext diff --git a/azurelinuxagent/common/protocol/wire.py b/azurelinuxagent/common/protocol/wire.py index 5ab5de3c58..ff07268999 100644 --- a/azurelinuxagent/common/protocol/wire.py +++ b/azurelinuxagent/common/protocol/wire.py @@ -32,10 +32,11 @@ from azurelinuxagent.common.event import add_event, add_periodic, WALAEventOperation, EVENTS_DIRECTORY from azurelinuxagent.common.exception import ProtocolNotFoundError, \ ResourceGoneError, ExtensionDownloadError, InvalidContainerError, ProtocolError, HttpError -from azurelinuxagent.common.future import httpclient, bytebuffer +from azurelinuxagent.common.future import httpclient, bytebuffer, ustr from azurelinuxagent.common.protocol.goal_state import GoalState, TRANSPORT_CERT_FILE_NAME, TRANSPORT_PRV_FILE_NAME from azurelinuxagent.common.protocol.hostplugin import HostPluginProtocol -from azurelinuxagent.common.protocol.restapi import * +from azurelinuxagent.common.protocol.restapi import DataContract, ExtensionStatus, ExtHandlerPackage, \ + ExtHandlerPackageList, ExtHandlerVersionUri, ProvisionStatus, VMInfo, VMStatus from azurelinuxagent.common.telemetryevent import TelemetryEventList from azurelinuxagent.common.utils import fileutil, restutil from azurelinuxagent.common.utils.archive import StateFlusher diff --git a/tests/common/test_conf.py b/tests/common/test_conf.py index 725f7e5748..ef5bc810bd 100644 --- a/tests/common/test_conf.py +++ b/tests/common/test_conf.py @@ -17,9 +17,8 @@ import os.path -from azurelinuxagent.common.conf import * import azurelinuxagent.common.conf as conf - +from azurelinuxagent.common.utils import fileutil from tests.tools import AgentTestCase, data_dir, patch @@ -73,8 +72,8 @@ class TestConf(AgentTestCase): def setUp(self): AgentTestCase.setUp(self) - self.conf = ConfigurationProvider() - load_conf_from_file( + self.conf = conf.ConfigurationProvider() + conf.load_conf_from_file( os.path.join(data_dir, "test_waagent.conf"), self.conf) @@ -84,29 +83,29 @@ def test_key_value_handling(self): self.assertEqual("delalloc,rw,noatime,nobarrier,users,mode=777", self.conf.get("FauxKey3", "Bad")) def test_get_ssh_dir(self): - self.assertTrue(get_ssh_dir(self.conf).startswith("/notareal/path")) + self.assertTrue(conf.get_ssh_dir(self.conf).startswith("/notareal/path")) def test_get_sshd_conf_file_path(self): - self.assertTrue(get_sshd_conf_file_path( + self.assertTrue(conf.get_sshd_conf_file_path( self.conf).startswith("/notareal/path")) def test_get_ssh_key_glob(self): - self.assertTrue(get_ssh_key_glob( + self.assertTrue(conf.get_ssh_key_glob( self.conf).startswith("/notareal/path")) def test_get_ssh_key_private_path(self): - self.assertTrue(get_ssh_key_private_path( + self.assertTrue(conf.get_ssh_key_private_path( self.conf).startswith("/notareal/path")) def test_get_ssh_key_public_path(self): - self.assertTrue(get_ssh_key_public_path( + self.assertTrue(conf.get_ssh_key_public_path( self.conf).startswith("/notareal/path")) def test_get_fips_enabled(self): - self.assertTrue(get_fips_enabled(self.conf)) + self.assertTrue(conf.get_fips_enabled(self.conf)) def test_get_provision_agent(self): - self.assertTrue(get_provisioning_agent(self.conf) == 'auto') + self.assertTrue(conf.get_provisioning_agent(self.conf) == 'auto') def test_get_configuration(self): configuration = conf.get_configuration(self.conf) @@ -118,8 +117,8 @@ def test_get_configuration(self): k) def test_get_agent_disabled_file_path(self): - self.assertEqual(get_disable_agent_file_path(self.conf), - os.path.join(self.tmp_dir, DISABLE_AGENT_FILE)) + self.assertEqual(conf.get_disable_agent_file_path(self.conf), + os.path.join(self.tmp_dir, conf.DISABLE_AGENT_FILE)) def test_write_agent_disabled(self): """ @@ -127,14 +126,14 @@ def test_write_agent_disabled(self): """ from azurelinuxagent.pa.provision.default import ProvisionHandler - disable_file_path = get_disable_agent_file_path(self.conf) + disable_file_path = conf.get_disable_agent_file_path(self.conf) self.assertFalse(os.path.exists(disable_file_path)) ProvisionHandler.write_agent_disabled() self.assertTrue(os.path.exists(disable_file_path)) self.assertEqual('', fileutil.read_file(disable_file_path)) def test_get_extensions_enabled(self): - self.assertTrue(get_extensions_enabled(self.conf)) + self.assertTrue(conf.get_extensions_enabled(self.conf)) @patch('azurelinuxagent.common.conf.ConfigurationProvider.get') def assert_get_cgroups_excluded(self, patch_get, config, expected_value): diff --git a/tests/common/test_errorstate.py b/tests/common/test_errorstate.py index d578bdd95f..263d95ed7d 100644 --- a/tests/common/test_errorstate.py +++ b/tests/common/test_errorstate.py @@ -1,6 +1,7 @@ import unittest +from datetime import timedelta, datetime -from azurelinuxagent.common.errorstate import * +from azurelinuxagent.common.errorstate import ErrorState from tests.tools import Mock, patch diff --git a/tests/daemon/test_daemon.py b/tests/daemon/test_daemon.py index e17dd7f459..5b412e4cb3 100644 --- a/tests/daemon/test_daemon.py +++ b/tests/daemon/test_daemon.py @@ -17,12 +17,10 @@ import os import unittest - from multiprocessing import Process import azurelinuxagent.common.conf as conf -from azurelinuxagent.daemon import * -from azurelinuxagent.daemon.main import OPENSSL_FIPS_ENVIRONMENT +from azurelinuxagent.daemon.main import OPENSSL_FIPS_ENVIRONMENT, get_daemon_handler from azurelinuxagent.pa.provision.default import ProvisionHandler from tests.tools import AgentTestCase, Mock, patch diff --git a/tests/distro/test_scvmm.py b/tests/distro/test_scvmm.py index a07435961d..abc9b5d70b 100644 --- a/tests/distro/test_scvmm.py +++ b/tests/distro/test_scvmm.py @@ -17,14 +17,16 @@ # Implements parts of RFC 2131, 1541, 1497 and # http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx # http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx +import os +import unittest import mock -from tests.tools import AgentTestCase, Mock, patch -import unittest import azurelinuxagent.daemon.scvmm as scvmm -from azurelinuxagent.daemon.main import * +from azurelinuxagent.common import conf from azurelinuxagent.common.osutil.default import DefaultOSUtil +from azurelinuxagent.common.utils import fileutil +from tests.tools import AgentTestCase, Mock, patch class TestSCVMM(AgentTestCase): @@ -50,7 +52,6 @@ def test_scvmm_detection_with_file(self): # cleanup os.remove(scvmm_file) - def test_scvmm_detection_with_multiple_cdroms(self): # setup conf.get_dvd_mount_point = Mock(return_value=self.tmp_dir) diff --git a/tests/ga/test_remoteaccess_handler.py b/tests/ga/test_remoteaccess_handler.py index b67b87d6ac..ea2f0d0cde 100644 --- a/tests/ga/test_remoteaccess_handler.py +++ b/tests/ga/test_remoteaccess_handler.py @@ -15,14 +15,14 @@ # Requires Python 2.6+ and Openssl 1.0+ # -from datetime import timedelta +from datetime import timedelta, datetime from mock import Mock, MagicMock -from azurelinuxagent.common.protocol.util import ProtocolUtil from azurelinuxagent.common.exception import RemoteAccessError from azurelinuxagent.common.protocol.goal_state import RemoteAccess -from azurelinuxagent.common.protocol.wire import * +from azurelinuxagent.common.protocol.util import ProtocolUtil +from azurelinuxagent.common.protocol.wire import WireProtocol from azurelinuxagent.ga.remoteaccess import RemoteAccessHandler from tests.common.osutil.mock_osutil import MockOSUtil from tests.tools import AgentTestCase, load_data, patch, clear_singleton_instances diff --git a/tests/ga/test_update.py b/tests/ga/test_update.py index f9f4d2ac8a..209b05242f 100644 --- a/tests/ga/test_update.py +++ b/tests/ga/test_update.py @@ -3,16 +3,36 @@ from __future__ import print_function +import glob +import json +import os +import shutil +import stat +import sys import tempfile +import time import unittest +import zipfile +from datetime import datetime, timedelta from threading import currentThread +from azurelinuxagent.common import conf +from azurelinuxagent.common.exception import ProtocolError, UpdateError, ResourceGoneError +from azurelinuxagent.common.future import ustr from azurelinuxagent.common.protocol.goal_state import ExtensionsConfig -from azurelinuxagent.common.protocol.hostplugin import * +from azurelinuxagent.common.protocol.hostplugin import URI_FORMAT_GET_API_VERSIONS, HOST_PLUGIN_PORT, \ + URI_FORMAT_GET_EXTENSION_ARTIFACT, HostPluginProtocol +from azurelinuxagent.common.protocol.restapi import ExtHandlerPackageUri, VMAgentManifest, VMAgentManifestUri, \ + VMAgentManifestList, ExtHandlerPackage, ExtHandlerPackageList from azurelinuxagent.common.protocol.util import ProtocolUtil -from azurelinuxagent.common.protocol.wire import * -from azurelinuxagent.common.version import AGENT_PKG_GLOB, AGENT_DIR_GLOB -from azurelinuxagent.ga.update import * +from azurelinuxagent.common.protocol.wire import WireProtocol +from azurelinuxagent.common.utils import fileutil, restutil, textutil +from azurelinuxagent.common.utils.flexible_version import FlexibleVersion +from azurelinuxagent.common.version import AGENT_PKG_GLOB, AGENT_DIR_GLOB, AGENT_NAME, AGENT_DIR_PATTERN, \ + AGENT_VERSION, CURRENT_AGENT, CURRENT_VERSION +from azurelinuxagent.ga.update import GuestAgent, GuestAgentError, MAX_FAILURE, AGENT_MANIFEST_FILE, \ + get_update_handler, ORPHAN_POLL_INTERVAL, AGENT_PARTITION_FILE, AGENT_ERROR_FILE, ORPHAN_WAIT_INTERVAL, \ + CHILD_LAUNCH_RESTART_MAX, get_python_cmd, CHILD_HEALTH_INTERVAL, UpdateHandler from tests.tools import AgentTestCase, call, data_dir, DEFAULT, patch, load_bin_data, load_data, Mock, MagicMock, \ clear_singleton_instances @@ -1461,6 +1481,7 @@ def test_telemetry_heartbeat_creates_event(self, patch_add_event, patch_info, *_ "The heartbeat was not written to the agent's log" ) + class MonitorThreadTest(AgentTestCase): def setUp(self): AgentTestCase.setUp(self) diff --git a/tests/protocol/test_datacontract.py b/tests/protocol/test_datacontract.py index 7813eb7ca6..342e84918e 100644 --- a/tests/protocol/test_datacontract.py +++ b/tests/protocol/test_datacontract.py @@ -16,8 +16,8 @@ # import unittest -from azurelinuxagent.common.datacontract import get_properties, set_properties -from azurelinuxagent.common.protocol.restapi import * + +from azurelinuxagent.common.datacontract import get_properties, set_properties, DataContract, DataContractList class SampleDataContract(DataContract): diff --git a/tests/protocol/test_protocol_util.py b/tests/protocol/test_protocol_util.py index 740d5aa183..eedd8a172f 100644 --- a/tests/protocol/test_protocol_util.py +++ b/tests/protocol/test_protocol_util.py @@ -15,22 +15,23 @@ # Requires Python 2.6+ and Openssl 1.0+ # -import unittest import os import tempfile -from multiprocessing import Queue +import unittest +from errno import ENOENT from threading import Thread -from tests.tools import AgentTestCase, MagicMock, Mock, patch, clear_singleton_instances -from azurelinuxagent.common.exception import * -from azurelinuxagent.common.protocol.metadata_server_migration_util import _METADATA_PROTOCOL_NAME, \ - _LEGACY_METADATA_SERVER_TRANSPORT_PRV_FILE_NAME, \ - _LEGACY_METADATA_SERVER_TRANSPORT_CERT_FILE_NAME, \ - _LEGACY_METADATA_SERVER_P7B_FILE_NAME +from azurelinuxagent.common.exception import ProtocolError, DhcpError, OSUtilError from azurelinuxagent.common.protocol.goal_state import TRANSPORT_CERT_FILE_NAME, TRANSPORT_PRV_FILE_NAME -from azurelinuxagent.common.protocol.util import get_protocol_util, ProtocolUtil, PROTOCOL_FILE_NAME, WIRE_PROTOCOL_NAME, ENDPOINT_FILE_NAME +from azurelinuxagent.common.protocol.metadata_server_migration_util import _METADATA_PROTOCOL_NAME, \ + _LEGACY_METADATA_SERVER_TRANSPORT_PRV_FILE_NAME, \ + _LEGACY_METADATA_SERVER_TRANSPORT_CERT_FILE_NAME, \ + _LEGACY_METADATA_SERVER_P7B_FILE_NAME +from azurelinuxagent.common.protocol.util import get_protocol_util, ProtocolUtil, PROTOCOL_FILE_NAME, \ + WIRE_PROTOCOL_NAME, ENDPOINT_FILE_NAME from azurelinuxagent.common.utils.restutil import KNOWN_WIRESERVER_IP -from errno import ENOENT +from tests.tools import AgentTestCase, MagicMock, Mock, patch, clear_singleton_instances + @patch("time.sleep") class TestProtocolUtil(AgentTestCase): diff --git a/tests/protocol/test_wire.py b/tests/protocol/test_wire.py index c5004dc80e..9cd8ddcd8d 100644 --- a/tests/protocol/test_wire.py +++ b/tests/protocol/test_wire.py @@ -20,17 +20,18 @@ import json import os import re +import socket import time import unittest import uuid from azurelinuxagent.common.exception import InvalidContainerError, ResourceGoneError, ProtocolError, \ ExtensionDownloadError, HttpError -from azurelinuxagent.common.future import httpclient -from azurelinuxagent.common.protocol.hostplugin import HostPluginProtocol from azurelinuxagent.common.protocol.goal_state import ExtensionsConfig +from azurelinuxagent.common.protocol.hostplugin import HostPluginProtocol +from azurelinuxagent.common.protocol.restapi import VMAgentManifestUri from azurelinuxagent.common.protocol.wire import WireProtocol, WireClient, \ - InVMArtifactsProfile, VMAgentManifestUri, StatusBlob, VMStatus, ExtHandlerVersionUri, DataContractList, socket + InVMArtifactsProfile, StatusBlob, VMStatus from azurelinuxagent.common.telemetryevent import TelemetryEvent, TelemetryEventParam, TelemetryEventList from azurelinuxagent.common.utils import restutil from azurelinuxagent.common.version import CURRENT_VERSION, DISTRO_NAME, DISTRO_VERSION @@ -39,7 +40,7 @@ from tests.protocol.mocks import mock_wire_protocol, HttpRequestPredicates from tests.protocol.mockwiredata import DATA_FILE_NO_EXT from tests.protocol.mockwiredata import WireProtocolData -from tests.tools import MagicMock, Mock, patch, AgentTestCase +from tests.tools import Mock, patch, AgentTestCase data_with_bom = b'\xef\xbb\xbfhehe' testurl = 'http://foo' diff --git a/tests/test_agent.py b/tests/test_agent.py index 2e89bc90b7..42fe842492 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -17,9 +17,9 @@ import os.path -from azurelinuxagent.agent import * -from azurelinuxagent.common.conf import * - +from azurelinuxagent.agent import parse_args, Agent, usage +from azurelinuxagent.common import conf +from azurelinuxagent.common.utils import fileutil from tests.tools import AgentTestCase, data_dir, Mock, patch EXPECTED_CONFIGURATION = \