summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/common/osutil/test_default.py55
-rw-r--r--tests/common/test_conf.py6
-rw-r--r--tests/common/test_errorstate.py69
-rw-r--r--tests/common/test_event.py7
-rw-r--r--tests/common/test_logger.py40
-rw-r--r--tests/data/test_waagent.conf8
-rw-r--r--tests/ga/test_extension.py17
-rw-r--r--tests/ga/test_update.py37
-rw-r--r--tests/pa/test_provision.py85
-rw-r--r--tests/protocol/test_metadata.py2
-rw-r--r--tests/protocol/test_wire.py4
-rw-r--r--tests/test_agent.py23
-rw-r--r--tests/tools.py4
13 files changed, 38 insertions, 319 deletions
diff --git a/tests/common/osutil/test_default.py b/tests/common/osutil/test_default.py
index c9fa1de..a73f4b4 100644
--- a/tests/common/osutil/test_default.py
+++ b/tests/common/osutil/test_default.py
@@ -516,16 +516,6 @@ Match host 192.168.1.2\n\
self.assertEqual(-1, util.get_firewall_dropped_packets("not used"))
@patch('azurelinuxagent.common.utils.shellutil.run_get_output')
- def test_get_firewall_dropped_packets_transient_error_ignored(self, mock_output):
- osutil._enable_firewall = True
- util = osutil.DefaultOSUtil()
-
- mock_output.side_effect = [
- (0, "iptables v{0}".format(osutil.IPTABLES_LOCKING_VERSION)),
- (3, "can't initialize iptables table `security': iptables who? (do you need to insmod?)")]
- self.assertEqual(0, util.get_firewall_dropped_packets("not used"))
-
- @patch('azurelinuxagent.common.utils.shellutil.run_get_output')
def test_get_firewall_dropped_packets(self, mock_output):
osutil._enable_firewall = True
util = osutil.DefaultOSUtil()
@@ -648,34 +638,6 @@ Chain OUTPUT (policy ACCEPT 104 packets, 43628 bytes)
])
self.assertFalse(osutil._enable_firewall)
- @patch('azurelinuxagent.common.utils.shellutil.run_get_output')
- @patch('azurelinuxagent.common.utils.shellutil.run')
- def test_enable_firewall_checks_for_invalid_iptables_options(self, mock_run, mock_output):
- osutil._enable_firewall = True
- util = osutil.DefaultOSUtil()
-
- dst = '1.2.3.4'
- version = "iptables v{0}".format(osutil.IPTABLES_LOCKING_VERSION)
- wait = "-w"
-
- # iptables uses the following exit codes
- # 0 - correct function
- # 1 - other errors
- # 2 - errors which appear to be caused by invalid or abused command
- # line parameters
- mock_run.side_effect = [2]
- mock_output.return_value = (0, version)
-
- self.assertFalse(util.enable_firewall(dst_ip='1.2.3.4', uid=42))
- self.assertFalse(osutil._enable_firewall)
-
- mock_run.assert_has_calls([
- call(osutil.FIREWALL_DROP.format(wait, "C", dst), chk_err=False),
- ])
- mock_output.assert_has_calls([
- call(osutil.IPTABLES_VERSION)
- ])
-
@patch('os.getuid', return_value=42)
@patch('azurelinuxagent.common.utils.shellutil.run_get_output')
@patch('azurelinuxagent.common.utils.shellutil.run')
@@ -708,15 +670,12 @@ Chain OUTPUT (policy ACCEPT 104 packets, 43628 bytes)
version = "iptables v{0}".format(osutil.IPTABLES_LOCKING_VERSION)
wait = "-w"
- mock_run.side_effect = [0, 1, 0, 1]
+ mock_run.side_effect = [0, 0]
mock_output.side_effect = [(0, version), (0, "Output")]
- self.assertTrue(util.remove_firewall(dst, uid))
+ self.assertTrue(util.remove_firewall())
mock_run.assert_has_calls([
- call(osutil.FIREWALL_DELETE_CONNTRACK.format(wait, dst), chk_err=False),
- call(osutil.FIREWALL_DELETE_CONNTRACK.format(wait, dst), chk_err=False),
- call(osutil.FIREWALL_DELETE_OWNER.format(wait, dst, uid), chk_err=False),
- call(osutil.FIREWALL_DELETE_OWNER.format(wait, dst, uid), chk_err=False),
+ call(osutil.FIREWALL_FLUSH.format(wait), chk_err=True)
])
mock_output.assert_has_calls([
call(osutil.IPTABLES_VERSION)
@@ -730,17 +689,15 @@ Chain OUTPUT (policy ACCEPT 104 packets, 43628 bytes)
osutil._enable_firewall = True
util = osutil.DefaultOSUtil()
- dst_ip='1.2.3.4'
- uid=42
version = "iptables v{0}".format(osutil.IPTABLES_LOCKING_VERSION)
wait = "-w"
- mock_run.side_effect = [2]
+ mock_run.side_effect = [1, 0]
mock_output.side_effect = [(0, version), (1, "Output")]
- self.assertFalse(util.remove_firewall(dst_ip, uid))
+ self.assertFalse(util.remove_firewall())
mock_run.assert_has_calls([
- call(osutil.FIREWALL_DELETE_CONNTRACK.format(wait, dst_ip), chk_err=False),
+ call(osutil.FIREWALL_FLUSH.format(wait), chk_err=True)
])
mock_output.assert_has_calls([
call(osutil.IPTABLES_VERSION)
diff --git a/tests/common/test_conf.py b/tests/common/test_conf.py
index 057c83b..a2c6573 100644
--- a/tests/common/test_conf.py
+++ b/tests/common/test_conf.py
@@ -65,7 +65,7 @@ class TestConf(AgentTestCase):
"AutoUpdate.GAFamily" : "Prod",
"EnableOverProvisioning" : False,
"OS.AllowHTTP" : False,
- "OS.EnableFirewall" : False
+ "OS.EnableFirewall" : True
}
def setUp(self):
@@ -78,7 +78,6 @@ class TestConf(AgentTestCase):
def test_key_value_handling(self):
self.assertEqual("Value1", self.conf.get("FauxKey1", "Bad"))
self.assertEqual("Value2 Value2", self.conf.get("FauxKey2", "Bad"))
- 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"))
@@ -111,5 +110,4 @@ class TestConf(AgentTestCase):
for k in TestConf.EXPECTED_CONFIGURATION.keys():
self.assertEqual(
TestConf.EXPECTED_CONFIGURATION[k],
- configuration[k],
- k)
+ configuration[k])
diff --git a/tests/common/test_errorstate.py b/tests/common/test_errorstate.py
deleted file mode 100644
index 7513fe5..0000000
--- a/tests/common/test_errorstate.py
+++ /dev/null
@@ -1,69 +0,0 @@
-from datetime import timedelta
-
-from azurelinuxagent.common.errorstate import *
-from tests.tools import *
-
-
-class TestErrorState(unittest.TestCase):
- def test_errorstate00(self):
- """
- If ErrorState is never incremented, it will never trigger.
- """
- test_subject = ErrorState(timedelta(seconds=10000))
- self.assertFalse(test_subject.is_triggered())
- self.assertEqual(0, test_subject.count)
-
- def test_errorstate01(self):
- """
- If ErrorState is never incremented, and the timedelta is zero it will
- not trigger.
- """
- test_subject = ErrorState(timedelta(seconds=0))
- self.assertFalse(test_subject.is_triggered())
- self.assertEqual(0, test_subject.count)
-
- def test_errorstate02(self):
- """
- If ErrorState is triggered, and the current time is within timedelta
- of now it will trigger.
- """
- test_subject = ErrorState(timedelta(seconds=0))
- test_subject.incr()
-
-
- self.assertTrue(test_subject.is_triggered())
- self.assertEqual(1, test_subject.count)
-
- @patch('azurelinuxagent.common.errorstate.datetime')
- def test_errorstate03(self, mock_time):
- """
- ErrorState will not trigger until
- 1. ErrorState has been incr() at least once.
- 2. The timedelta from the first incr() has elapsed.
- """
- test_subject = ErrorState(timedelta(minutes=15))
-
- for x in range(1, 10):
- mock_time.utcnow = Mock(return_value=datetime.utcnow() + timedelta(minutes=x))
-
- test_subject.incr()
- self.assertFalse(test_subject.is_triggered())
-
- mock_time.utcnow = Mock(return_value=datetime.utcnow() + timedelta(minutes=30))
- test_subject.incr()
- self.assertTrue(test_subject.is_triggered())
-
- def test_errorstate04(self):
- """
- If ErrorState is reset the timestamp of the last incr() is reset to
- None.
- """
-
- test_subject = ErrorState(timedelta(minutes=15))
- self.assertTrue(test_subject.timestamp is None)
-
- test_subject.incr()
- self.assertTrue(test_subject.timestamp is not None)
-
- test_subject.reset()
- self.assertTrue(test_subject.timestamp is None)
diff --git a/tests/common/test_event.py b/tests/common/test_event.py
index 01bcd7b..d52d3e6 100644
--- a/tests/common/test_event.py
+++ b/tests/common/test_event.py
@@ -49,7 +49,8 @@ class TestEvent(AgentTestCase):
self.assertTrue(es.event_succeeded("Foo", "1.2", "FauxOperation"))
def test_event_status_records_status(self):
- es = event.EventStatus()
+ d = tempfile.mkdtemp()
+ es = event.EventStatus(tempfile.mkdtemp())
es.mark_event_status("Foo", "1.2", "FauxOperation", True)
self.assertTrue(es.event_succeeded("Foo", "1.2", "FauxOperation"))
@@ -69,7 +70,7 @@ class TestEvent(AgentTestCase):
self.assertFalse(es.event_succeeded("Foo", "1.2", "FauxOperation"))
def test_should_emit_event_ignores_unknown_operations(self):
- event.__event_status__ = event.EventStatus()
+ event.__event_status__ = event.EventStatus(tempfile.mkdtemp())
self.assertTrue(event.should_emit_event("Foo", "1.2", "FauxOperation", True))
self.assertTrue(event.should_emit_event("Foo", "1.2", "FauxOperation", False))
@@ -82,7 +83,7 @@ class TestEvent(AgentTestCase):
def test_should_emit_event_handles_known_operations(self):
- event.__event_status__ = event.EventStatus()
+ event.__event_status__ = event.EventStatus(tempfile.mkdtemp())
# Known operations always initially "fire"
for op in event.__event_status_operations__:
diff --git a/tests/common/test_logger.py b/tests/common/test_logger.py
index 005c429..9e298b3 100644
--- a/tests/common/test_logger.py
+++ b/tests/common/test_logger.py
@@ -15,20 +15,17 @@
# Requires Python 2.4+ and Openssl 1.0+
#
-import json
from datetime import datetime
import azurelinuxagent.common.logger as logger
-from azurelinuxagent.common.event import add_log_event
-from azurelinuxagent.common.version import CURRENT_AGENT, CURRENT_VERSION
from tests.tools import *
_MSG = "This is our test logging message {0} {1}"
_DATA = ["arg1", "arg2"]
-
class TestLogger(AgentTestCase):
+
@patch('azurelinuxagent.common.logger.Logger.info')
def test_periodic_emits_if_not_previously_sent(self, mock_info):
logger.reset_periodic()
@@ -67,38 +64,3 @@ class TestLogger(AgentTestCase):
logger.periodic(logger.EVERY_DAY, _MSG, *_DATA)
mock_info.assert_called_once_with(_MSG, *_DATA)
-
- def test_telemetry_logger(self):
- mock = MagicMock()
- appender = logger.TelemetryAppender(logger.LogLevel.WARNING, mock)
- appender.write(logger.LogLevel.WARNING, "--unit-test--")
-
- mock.assert_called_once_with(logger.LogLevel.WARNING, "--unit-test--")
-
- @patch('azurelinuxagent.common.event.EventLogger.save_event')
- def test_telemetry_logger1(self, mock_save):
- appender = logger.TelemetryAppender(logger.LogLevel.WARNING, add_log_event)
- appender.write(logger.LogLevel.WARNING, "--unit-test--")
-
- self.assertEqual(1, mock_save.call_count)
- telemetry_json = json.loads(mock_save.call_args[0][0])
-
- self.assertEqual('FFF0196F-EE4C-4EAF-9AA5-776F622DEB4F', telemetry_json['providerId'])
- self.assertEqual(7, telemetry_json['eventId'])
-
- self.assertEqual(5, len(telemetry_json['parameters']))
- for x in telemetry_json['parameters']:
- if x['name'] == 'EventName':
- self.assertEqual(x['value'], 'Log')
-
- elif x['name'] == 'CapabilityUsed':
- self.assertEqual(x['value'], 'WARNING')
-
- elif x['name'] == 'Context1':
- self.assertEqual(x['value'], '--unit-test--')
-
- elif x['name'] == 'Context2':
- self.assertEqual(x['value'], '')
-
- elif x['name'] == 'Context3':
- self.assertEqual(x['value'], '')
diff --git a/tests/data/test_waagent.conf b/tests/data/test_waagent.conf
index be0596a..24d05f8 100644
--- a/tests/data/test_waagent.conf
+++ b/tests/data/test_waagent.conf
@@ -6,7 +6,6 @@
=Value0
FauxKey1= Value1
FauxKey2=Value2 Value2
-FauxKey3=delalloc,rw,noatime,nobarrier,users,mode=777
# Enable instance creation
Provisioning.Enabled=y
@@ -20,8 +19,7 @@ Provisioning.DeleteRootPassword=y
# Generate fresh host key pair.
Provisioning.RegenerateSshHostKeyPair=y
-# Supported values are "rsa", "dsa", "ecdsa", "ed25519", and "auto".
-# The "auto" option is supported on OpenSSH 5.9 (2011) and later.
+# Supported values are "rsa", "dsa" and "ecdsa".
Provisioning.SshHostKeyPairType=rsa # An EOL comment that should be ignored
# Monitor host name changes and publish changes via DHCP requests.
@@ -124,5 +122,5 @@ OS.SshDir=/notareal/path
# Add firewall rules to protect access to Azure host node services
# Note:
-# - The default is false to protect the state of existing VMs
-OS.EnableFirewall=n
+# - The default is false to protect the state of exising VMs
+OS.EnableFirewall=y
diff --git a/tests/ga/test_extension.py b/tests/ga/test_extension.py
index 9a72989..9111cde 100644
--- a/tests/ga/test_extension.py
+++ b/tests/ga/test_extension.py
@@ -414,8 +414,7 @@ class TestExtension(AgentTestCase):
"<Incarnation>4<")
test_data.ext_conf = test_data.ext_conf.replace("1.0.0", "1.1.0")
exthandlers_handler.run()
- self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.0.0")
- self._assert_ext_status(protocol.report_ext_status, "success", 0)
+ self._assert_no_handler_status(protocol.report_vm_status)
#Test GUID change with hotfix
test_data.goal_state = test_data.goal_state.replace("<Incarnation>4<",
@@ -459,8 +458,7 @@ class TestExtension(AgentTestCase):
"<Incarnation>10<")
test_data.ext_conf = test_data.ext_conf.replace("1.1.0", "1.2.0")
exthandlers_handler.run()
- self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.1.1")
- self._assert_ext_status(protocol.report_ext_status, "success", 0)
+ self._assert_no_handler_status(protocol.report_vm_status)
#Test GUID change with upgrade available
test_data.goal_state = test_data.goal_state.replace("<Incarnation>10<",
@@ -579,12 +577,12 @@ class TestExtension(AgentTestCase):
decision_version = '1.0.0'
_, protocol = self._create_mock(WireProtocolData(datafile), *args)
- ext_handlers, etag = protocol.get_ext_handlers()
+ ext_handlers, _ = protocol.get_ext_handlers()
self.assertEqual(1, len(ext_handlers.extHandlers))
ext_handler = ext_handlers.extHandlers[0]
self.assertEqual('OSTCExtensions.ExampleHandlerLinux', ext_handler.name)
self.assertEqual(config_version, ext_handler.properties.version, "config version.")
- ExtHandlerInstance(ext_handler, protocol).decide_version(etag)
+ ExtHandlerInstance(ext_handler, protocol).decide_version()
self.assertEqual(decision_version, ext_handler.properties.version, "decision version.")
def test_ext_handler_version_decide_between_minor_versions(self, *args):
@@ -611,7 +609,6 @@ class TestExtension(AgentTestCase):
_, protocol = self._create_mock(WireProtocolData(DATA_FILE), *args)
version_uri = Mock()
version_uri.uri = 'http://some/Microsoft.OSTCExtensions_ExampleHandlerLinux_asiaeast_manifest.xml'
- incarnation = 1
for (installed_version, config_version, expected_version, autoupgrade_expected_version) in cases:
ext_handler = Mock()
@@ -623,9 +620,8 @@ class TestExtension(AgentTestCase):
ext_handler_instance = ExtHandlerInstance(ext_handler, protocol)
ext_handler_instance.get_installed_version = Mock(return_value=installed_version)
- ext_handler_instance.decide_version(incarnation)
+ ext_handler_instance.decide_version()
self.assertEqual(expected_version, ext_handler.properties.version)
- incarnation += 1
ext_handler.properties.version = config_version
ext_handler.properties.upgradePolicy = 'auto'
@@ -633,9 +629,8 @@ class TestExtension(AgentTestCase):
ext_handler_instance = ExtHandlerInstance(ext_handler, protocol)
ext_handler_instance.get_installed_version = Mock(return_value=installed_version)
- ext_handler_instance.decide_version(incarnation)
+ ext_handler_instance.decide_version()
self.assertEqual(autoupgrade_expected_version, ext_handler.properties.version)
- incarnation += 1
if __name__ == '__main__':
diff --git a/tests/ga/test_update.py b/tests/ga/test_update.py
index 21c81e9..88535f5 100644
--- a/tests/ga/test_update.py
+++ b/tests/ga/test_update.py
@@ -17,12 +17,17 @@
from __future__ import print_function
+from datetime import datetime
+
+import json
+import shutil
+import stat
+
from azurelinuxagent.common.event import *
from azurelinuxagent.common.protocol.hostplugin import *
from azurelinuxagent.common.protocol.metadata import *
from azurelinuxagent.common.protocol.wire import *
from azurelinuxagent.common.utils.fileutil import *
-from azurelinuxagent.common.version import AGENT_PKG_GLOB, AGENT_DIR_GLOB
from azurelinuxagent.ga.update import *
from tests.tools import *
@@ -384,30 +389,6 @@ class TestGuestAgent(UpdateTestCase):
@patch("azurelinuxagent.ga.update.GuestAgent._ensure_downloaded")
@patch("azurelinuxagent.ga.update.GuestAgent._ensure_loaded")
- def test_resource_gone_error_not_blacklisted(self, mock_loaded, mock_downloaded):
- try:
- mock_downloaded.side_effect = ResourceGoneError()
- agent = GuestAgent(path=self.agent_path)
- self.assertFalse(agent.is_blacklisted)
- except ResourceGoneError:
- pass
- except:
- self.fail("Exception was not expected!")
-
- @patch("azurelinuxagent.ga.update.GuestAgent._ensure_downloaded")
- @patch("azurelinuxagent.ga.update.GuestAgent._ensure_loaded")
- def test_ioerror_not_blacklisted(self, mock_loaded, mock_downloaded):
- try:
- mock_downloaded.side_effect = IOError()
- agent = GuestAgent(path=self.agent_path)
- self.assertFalse(agent.is_blacklisted)
- except IOError:
- pass
- except:
- self.fail("Exception was not expected!")
-
- @patch("azurelinuxagent.ga.update.GuestAgent._ensure_downloaded")
- @patch("azurelinuxagent.ga.update.GuestAgent._ensure_loaded")
def test_is_downloaded(self, mock_loaded, mock_downloaded):
agent = GuestAgent(path=self.agent_path)
self.assertFalse(agent.is_downloaded)
@@ -1018,8 +999,8 @@ class TestUpdate(UpdateTestCase):
self.assertTrue(2 < len(self.update_handler.agents))
# Purge every other agent
- purged_agents = self.update_handler.agents[1::2]
- kept_agents = self.update_handler.agents[::2]
+ kept_agents = self.update_handler.agents[1::2]
+ purged_agents = self.update_handler.agents[::2]
# Reload and assert only the kept agents remain on disk
self.update_handler.agents = kept_agents
@@ -1569,7 +1550,6 @@ class ProtocolMock(object):
self.call_counts["update_goal_state"] += 1
self.goal_state_forced = self.goal_state_forced or forced
-
class ResponseMock(Mock):
def __init__(self, status=restutil.httpclient.OK, response=None, reason=None):
Mock.__init__(self)
@@ -1599,6 +1579,5 @@ class TimeMock(Mock):
self.next_time += self.time_increment
return current_time
-
if __name__ == '__main__':
unittest.main()
diff --git a/tests/pa/test_provision.py b/tests/pa/test_provision.py
index 2c2d2c9..7045fcc 100644
--- a/tests/pa/test_provision.py
+++ b/tests/pa/test_provision.py
@@ -15,13 +15,9 @@
# Requires Python 2.4+ and Openssl 1.0+
#
-import json
-import socket
-
import azurelinuxagent.common.utils.fileutil as fileutil
-from azurelinuxagent.common.event import WALAEventOperation
-from azurelinuxagent.common.exception import ProvisionError
+from azurelinuxagent.common.exception import ProtocolError
from azurelinuxagent.common.osutil.default import DefaultOSUtil
from azurelinuxagent.common.protocol import OVF_FILE_NAME
from azurelinuxagent.pa.provision import get_provision_handler
@@ -119,85 +115,6 @@ class TestProvision(AgentTestCase):
ph.osutil.is_current_instance_id.assert_called_once()
deprovision_handler.run_changed_unique_id.assert_called_once()
- @distros()
- @patch('azurelinuxagent.common.osutil.default.DefaultOSUtil.get_instance_id',
- return_value='B9F3C233-9913-9F42-8EB3-BA656DF32502')
- def test_provision_telemetry_success(self, mock_util, distro_name, distro_version,
- distro_full_name):
- """
- Assert that the agent issues two telemetry messages as part of a
- successful provisioning.
-
- 1. Provision
- 2. GuestState
- """
- ph = get_provision_handler(distro_name, distro_version,
- distro_full_name)
- ph.report_event = MagicMock()
- ph.reg_ssh_host_key = MagicMock(return_value='--thumprint--')
-
- mock_osutil = MagicMock()
- mock_osutil.decode_customdata = Mock(return_value="")
-
- ph.osutil = mock_osutil
- ph.protocol_util.osutil = mock_osutil
- ph.protocol_util.get_protocol_by_file = MagicMock()
- ph.protocol_util.get_protocol = MagicMock()
-
- conf.get_dvd_mount_point = Mock(return_value=self.tmp_dir)
- ovfenv_file = os.path.join(self.tmp_dir, OVF_FILE_NAME)
- ovfenv_data = load_data("ovf-env.xml")
- fileutil.write_file(ovfenv_file, ovfenv_data)
-
- ph.run()
-
- call1 = call("Provisioning succeeded", duration=ANY, is_success=True)
- call2 = call(ANY, is_success=True, operation=WALAEventOperation.GuestState)
- ph.report_event.assert_has_calls([call1, call2])
-
- args, kwargs = ph.report_event.call_args_list[1]
- guest_state_json = json.loads(args[0])
- self.assertTrue(1 <= guest_state_json['cpu'])
- self.assertTrue(1 <= guest_state_json['mem'])
- self.assertEqual(socket.gethostname(), guest_state_json['hostname'])
-
- @distros()
- @patch(
- 'azurelinuxagent.common.osutil.default.DefaultOSUtil.get_instance_id',
- return_value='B9F3C233-9913-9F42-8EB3-BA656DF32502')
- def test_provision_telemetry_fail(self, mock_util, distro_name,
- distro_version,
- distro_full_name):
- """
- Assert that the agent issues one telemetry message as part of a
- failed provisioning.
-
- 1. Provision
- """
- ph = get_provision_handler(distro_name, distro_version,
- distro_full_name)
- ph.report_event = MagicMock()
- ph.reg_ssh_host_key = MagicMock(side_effect=ProvisionError(
- "--unit-test--"))
-
- mock_osutil = MagicMock()
- mock_osutil.decode_customdata = Mock(return_value="")
-
- ph.osutil = mock_osutil
- ph.protocol_util.osutil = mock_osutil
- ph.protocol_util.get_protocol_by_file = MagicMock()
- ph.protocol_util.get_protocol = MagicMock()
-
- conf.get_dvd_mount_point = Mock(return_value=self.tmp_dir)
- ovfenv_file = os.path.join(self.tmp_dir, OVF_FILE_NAME)
- ovfenv_data = load_data("ovf-env.xml")
- fileutil.write_file(ovfenv_file, ovfenv_data)
-
- ph.run()
- ph.report_event.assert_called_once_with(
- "[ProvisionError] --unit-test--")
-
-
if __name__ == '__main__':
unittest.main()
diff --git a/tests/protocol/test_metadata.py b/tests/protocol/test_metadata.py
index 5f90f12..5047b86 100644
--- a/tests/protocol/test_metadata.py
+++ b/tests/protocol/test_metadata.py
@@ -39,7 +39,7 @@ class TestMetadataProtocolGetters(AgentTestCase):
protocol.get_certs()
ext_handlers, etag = protocol.get_ext_handlers()
for ext_handler in ext_handlers.extHandlers:
- protocol.get_ext_handler_pkgs(ext_handler, etag)
+ protocol.get_ext_handler_pkgs(ext_handler)
def test_getters(self, *args):
test_data = MetadataProtocolData(DATA_FILE)
diff --git a/tests/protocol/test_wire.py b/tests/protocol/test_wire.py
index 9e475ec..77a0882 100644
--- a/tests/protocol/test_wire.py
+++ b/tests/protocol/test_wire.py
@@ -43,9 +43,8 @@ class TestWireProtocol(AgentTestCase):
protocol.get_vminfo()
protocol.get_certs()
ext_handlers, etag = protocol.get_ext_handlers()
- self.assertEqual("1", etag)
for ext_handler in ext_handlers.extHandlers:
- protocol.get_ext_handler_pkgs(ext_handler, etag)
+ protocol.get_ext_handler_pkgs(ext_handler)
crt1 = os.path.join(self.tmp_dir,
'33B0ABCE4673538650971C10F7D7397E71561F35.crt')
@@ -94,7 +93,6 @@ class TestWireProtocol(AgentTestCase):
# HostingEnvironmentConfig, will be retrieved the expected number
self.assertEqual(2, test_data.call_counts["hostingenvuri"])
-
def test_call_storage_kwargs(self,
mock_cryptutil,
mock_sleep):
diff --git a/tests/test_agent.py b/tests/test_agent.py
index 2095db0..51b157d 100644
--- a/tests/test_agent.py
+++ b/tests/test_agent.py
@@ -15,7 +15,9 @@
# Requires Python 2.4+ and Openssl 1.0+
#
+import mock
import os.path
+import sys
from azurelinuxagent.agent import *
from azurelinuxagent.common.conf import *
@@ -37,7 +39,7 @@ Logs.Verbose = False
OS.AllowHTTP = False
OS.CheckRdmaDriver = False
OS.EnableFIPS = True
-OS.EnableFirewall = False
+OS.EnableFirewall = True
OS.EnableRDMA = False
OS.HomeDir = /home
OS.OpensslPath = /usr/bin/openssl
@@ -166,22 +168,3 @@ class TestAgent(AgentTestCase):
for k in sorted(configuration.keys()):
actual_configuration.append("{0} = {1}".format(k, configuration[k]))
self.assertEqual(EXPECTED_CONFIGURATION, actual_configuration)
-
- def test_agent_usage_message(self):
- message = usage()
-
- # Python 2.6 does not have assertIn()
- self.assertTrue("-verbose" in message)
- self.assertTrue("-force" in message)
- self.assertTrue("-help" in message)
- self.assertTrue("-configuration-path" in message)
- self.assertTrue("-deprovision" in message)
- self.assertTrue("-register-service" in message)
- self.assertTrue("-version" in message)
- self.assertTrue("-daemon" in message)
- self.assertTrue("-start" in message)
- self.assertTrue("-run-exthandlers" in message)
- self.assertTrue("-show-configuration" in message)
-
- # sanity check
- self.assertFalse("-not-a-valid-option" in message)
diff --git a/tests/tools.py b/tests/tools.py
index 5c65847..73a64b6 100644
--- a/tests/tools.py
+++ b/tests/tools.py
@@ -37,9 +37,9 @@ from azurelinuxagent.common.version import PY_VERSION_MAJOR
# Import mock module for Python2 and Python3
try:
- from unittest.mock import Mock, patch, MagicMock, DEFAULT, ANY, call
+ from unittest.mock import Mock, patch, MagicMock, DEFAULT, call
except ImportError:
- from mock import Mock, patch, MagicMock, DEFAULT, ANY, call
+ from mock import Mock, patch, MagicMock, DEFAULT, call
test_dir = os.path.dirname(os.path.abspath(__file__))
data_dir = os.path.join(test_dir, "data")