From 185ceb32fea5d5c2a43d7b6ee2a40228489055f4 Mon Sep 17 00:00:00 2001 From: Ɓukasz 'sil2100' Zemczak Date: Mon, 4 Sep 2017 10:27:07 +0200 Subject: Import patches-unapplied version 2.2.16-0ubuntu1 to ubuntu/artful-proposed Imported using git-ubuntu import. Changelog parent: 43bdf9debe5377216aed0086bff2aad864f6ba82 New changelog entries: * New upstream release (LP: #1714299). --- tests/test_agent.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'tests/test_agent.py') diff --git a/tests/test_agent.py b/tests/test_agent.py index 1b35933..77be07a 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -17,12 +17,56 @@ import mock import os.path +import sys from azurelinuxagent.agent import * from azurelinuxagent.common.conf import * from tests.tools import * +EXPECTED_CONFIGURATION = \ +"""AutoUpdate.Enabled = True +AutoUpdate.GAFamily = Prod +Autoupdate.Frequency = 3600 +DVD.MountPoint = /mnt/cdrom/secure +DetectScvmmEnv = False +EnableOverProvisioning = False +Extension.LogDir = /var/log/azure +HttpProxy.Host = None +HttpProxy.Port = None +Lib.Dir = /var/lib/waagent +Logs.Verbose = False +OS.AllowHTTP = False +OS.CheckRdmaDriver = False +OS.EnableFIPS = True +OS.EnableFirewall = True +OS.EnableRDMA = False +OS.HomeDir = /home +OS.OpensslPath = /usr/bin/openssl +OS.PasswordPath = /etc/shadow +OS.RootDeviceScsiTimeout = 300 +OS.SshDir = /notareal/path +OS.SudoersDir = /etc/sudoers.d +OS.UpdateRdmaDriver = False +Pid.File = /var/run/waagent.pid +Provisioning.AllowResetSysUser = False +Provisioning.DecodeCustomData = False +Provisioning.DeleteRootPassword = True +Provisioning.Enabled = True +Provisioning.ExecuteCustomData = False +Provisioning.MonitorHostName = True +Provisioning.PasswordCryptId = 6 +Provisioning.PasswordCryptSaltLength = 10 +Provisioning.RegenerateSshHostKeyPair = True +Provisioning.SshHostKeyPairType = rsa +Provisioning.UseCloudInit = True +ResourceDisk.EnableSwap = False +ResourceDisk.Filesystem = ext4 +ResourceDisk.Format = True +ResourceDisk.MountOptions = None +ResourceDisk.MountPoint = /mnt/resource +ResourceDisk.SwapSizeMB = 0 +""".split('\n') class TestAgent(AgentTestCase): @@ -90,3 +134,36 @@ class TestAgent(AgentTestCase): mock_daemon.run.assert_called_once_with(child_args="-configuration-path:/foo/bar.conf") mock_load.assert_called_once() + + @patch("azurelinuxagent.common.conf.get_ext_log_dir") + def test_agent_ensures_extension_log_directory(self, mock_dir): + ext_log_dir = os.path.join(self.tmp_dir, "FauxLogDir") + mock_dir.return_value = ext_log_dir + + self.assertFalse(os.path.isdir(ext_log_dir)) + agent = Agent(False, + conf_file_path=os.path.join(data_dir, "test_waagent.conf")) + self.assertTrue(os.path.isdir(ext_log_dir)) + + @patch("azurelinuxagent.common.logger.error") + @patch("azurelinuxagent.common.conf.get_ext_log_dir") + def test_agent_logs_if_extension_log_directory_is_a_file(self, mock_dir, mock_log): + ext_log_dir = os.path.join(self.tmp_dir, "FauxLogDir") + mock_dir.return_value = ext_log_dir + fileutil.write_file(ext_log_dir, "Foo") + + self.assertTrue(os.path.isfile(ext_log_dir)) + self.assertFalse(os.path.isdir(ext_log_dir)) + agent = Agent(False, + conf_file_path=os.path.join(data_dir, "test_waagent.conf")) + self.assertTrue(os.path.isfile(ext_log_dir)) + self.assertFalse(os.path.isdir(ext_log_dir)) + mock_log.assert_called_once() + + def test_agent_show_configuration(self): + if not hasattr(sys.stdout, 'getvalue'): + self.fail('Test requires at least Python 2.7 with buffered output') + agent = Agent(False, + conf_file_path=os.path.join(data_dir, "test_waagent.conf")) + agent.show_configuration() + self.assertEqual(EXPECTED_CONFIGURATION, sys.stdout.getvalue().split('\n')) -- cgit v1.2.3