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

Clean up import statements #1900

Merged
merged 2 commits into from
Jun 3, 2020
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
20 changes: 10 additions & 10 deletions azurelinuxagent/common/osutil/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion azurelinuxagent/common/protocol/goal_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions azurelinuxagent/common/protocol/wire.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 14 additions & 15 deletions tests/common/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

import os.path

from azurelinuxagent.common.conf import *
larohra marked this conversation as resolved.
Show resolved Hide resolved
import azurelinuxagent.common.conf as conf

from azurelinuxagent.common.utils import fileutil
from tests.tools import AgentTestCase, data_dir, patch


Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -118,23 +117,23 @@ 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):
"""
Test writing disable_agent is empty
"""
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):
Expand Down
3 changes: 2 additions & 1 deletion tests/common/test_errorstate.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
4 changes: 1 addition & 3 deletions tests/daemon/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 5 additions & 4 deletions tests/distro/test_scvmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/ga/test_remoteaccess_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 25 additions & 4 deletions tests/ga/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/protocol/test_datacontract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
21 changes: 11 additions & 10 deletions tests/protocol/test_protocol_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions tests/protocol/test_wire.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = \
Expand Down