Repository: Azure/WALinuxAgent (python)

Issue:
Ensure events only contain VM info from the agent
Extensions may write events and, in some case, may include VM information values (such as ContainerID) they should not. This can result in events containing duplicate PARAMs which may confuse off-board telemetry collectors.

`monitor.py#collect_and_send_events` should, after parsing the event, should purge from the event any fields it intends to add from its `sysinfo` object.

Pull request description:
Instead of adding values in sysinfo directly to event, if a value
already exist in the event, overwrite it to prevent duplicates.

This fixes #520.

Patch:
diff --git a/azurelinuxagent/common/conf.py b/azurelinuxagent/common/conf.py
index 79116995..9c79d10e 100644
--- a/azurelinuxagent/common/conf.py
+++ b/azurelinuxagent/common/conf.py
@@ -98,10 +98,6 @@ def get_lib_dir(conf=__conf__):
     return conf.get("Lib.Dir", "/var/lib/waagent")
 
 
-def get_published_hostname(conf=__conf__):
-    return os.path.join(get_lib_dir(conf), 'published_hostname')
-
-
 def get_dvd_mount_point(conf=__conf__):
     return conf.get("DVD.MountPoint", "/mnt/cdrom/secure")
 
diff --git a/azurelinuxagent/common/osutil/default.py b/azurelinuxagent/common/osutil/default.py
index 6eccc913..dc73379c 100644
--- a/azurelinuxagent/common/osutil/default.py
+++ b/azurelinuxagent/common/osutil/default.py
@@ -675,7 +675,6 @@ class DefaultOSUtil(object):
 
     def publish_hostname(self, hostname):
         self.set_dhcp_hostname(hostname)
-        self.set_hostname_record(hostname)
         ifname = self.get_if_name()
         self.restart_if(ifname)
 
@@ -742,15 +741,6 @@ class DefaultOSUtil(object):
                 break
         return device
 
-    def set_hostname_record(self, hostname):
-        fileutil.write_file(conf.get_published_hostname(), contents=hostname)
-
-    def get_hostname_record(self):
-        record = None
-        if os.path.exists(conf.get_published_hostname()):
-            record = fileutil.read_file(conf.get_published_hostname())
-        return record
-
     def del_account(self, username):
         if self.is_sys_user(username):
             logger.error("{0} is a system user. Will not delete it.", username)
diff --git a/azurelinuxagent/common/osutil/redhat.py b/azurelinuxagent/common/osutil/redhat.py
index fef9e152..8e86f6ec 100644
--- a/azurelinuxagent/common/osutil/redhat.py
+++ b/azurelinuxagent/common/osutil/redhat.py
@@ -84,8 +84,7 @@ class Redhat6xOSUtil(DefaultOSUtil):
     def set_dhcp_hostname(self, hostname):
         ifname = self.get_if_name()
         filepath = "/etc/sysconfig/network-scripts/ifcfg-{0}".format(ifname)
-        fileutil.update_conf_file(filepath,
-                                  'DHCP_HOSTNAME',
+        fileutil.update_conf_file(filepath, 'DHCP_HOSTNAME',
                                   'DHCP_HOSTNAME={0}'.format(hostname))
 
     def get_dhcp_lease_endpoint(self):
@@ -118,11 +117,5 @@ class RedhatOSUtil(Redhat6xOSUtil):
         DefaultOSUtil.openssl_to_openssh(self, input_file, output_file)
 
     def get_dhcp_lease_endpoint(self):
-        # dhclient
-        endpoint = self.get_endpoint_from_leases_path('/var/lib/dhclient/dhclient-*.lease')
-
-        if endpoint is None:
-            # NetworkManager
-            endpoint = self.get_endpoint_from_leases_path('/var/lib/NetworkManager/dhclient-*.lease')
-
-        return endpoint
+        # centos7 has this weird naming with double hyphen like /var/lib/dhclient/dhclient--eth0.lease
+        return self.get_endpoint_from_leases_path('/var/lib/dhclient/dhclient-*.lease')
diff --git a/azurelinuxagent/common/protocol/wire.py b/azurelinuxagent/common/protocol/wire.py
index b375f23a..9f634e9a 100644
--- a/azurelinuxagent/common/protocol/wire.py
+++ b/azurelinuxagent/common/protocol/wire.py
@@ -823,7 +823,7 @@ class WireClient(object):
             logger.info("Wire protocol version:{0}", PROTOCOL_VERSION)
         elif PROTOCOL_VERSION in version_info.get_supported():
             logger.info("Wire protocol version:{0}", PROTOCOL_VERSION)
-            logger.warn("Server preferred version:{0}", preferred)
+            logger.warn("Server prefered version:{0}", preferred)
         else:
             error = ("Agent supported wire protocol version: {0} was not "
                      "advised by Fabric.").format(PROTOCOL_VERSION)
diff --git a/azurelinuxagent/common/utils/fileutil.py b/azurelinuxagent/common/utils/fileutil.py
index 8713d0c6..b0b6fb75 100644
--- a/azurelinuxagent/common/utils/fileutil.py
+++ b/azurelinuxagent/common/utils/fileutil.py
@@ -140,9 +140,9 @@ def update_conf_file(path, line_start, val, chk_err=False):
     if not os.path.isfile(path) and chk_err:
         raise IOError("Can't find config file:{0}".format(path))
     conf = read_file(path).split('\n')
-    conf = [x for x in conf if x is not None and len(x) > 0 and not x.startswith(line_start)]
+    conf = [x for x in conf if not x.startswith(line_start)]
     conf.append(val)
-    write_file(path, '\n'.join(conf) + '\n')
+    write_file(path, '\n'.join(conf))
 
 def search_file(target_dir_name, target_file_name):
     for root, dirs, files in os.walk(target_dir_name):
diff --git a/azurelinuxagent/common/utils/textutil.py b/azurelinuxagent/common/utils/textutil.py
index 2d99f6f6..59b8fe75 100644
--- a/azurelinuxagent/common/utils/textutil.py
+++ b/azurelinuxagent/common/utils/textutil.py
@@ -221,24 +221,15 @@ def hexstr_to_bytearray(a):
 
 
 def set_ssh_config(config, name, val):
-    found = False
-    no_match = -1
-
-    match_start = no_match
+    notfound = True
     for i in range(0, len(config)):
-        if config[i].startswith(name) and match_start == no_match:
+        if config[i].startswith(name):
             config[i] = "{0} {1}".format(name, val)
-            found = True
-        elif config[i].lower().startswith("match"):
-            if config[i].lower().startswith("match all"):
-                # outside match block
-                match_start = no_match
-            elif match_start == no_match:
-                # inside match block
-                match_start = i
-    if not found:
-        if match_start != no_match:
-            i = match_start
+            notfound = False
+        elif config[i].startswith("Match"):
+            # Match block must be put in the end of sshd config
+            break
+    if notfound:
         config.insert(i, "{0} {1}".format(name, val))
     return config
 
@@ -276,9 +267,6 @@ def gen_password_hash(password, crypt_id, salt_len):
     collection = string.ascii_letters + string.digits
     salt = ''.join(random.choice(collection) for _ in range(salt_len))
     salt = "${0}${1}".format(crypt_id, salt)
-    if sys.version_info[0] == 2:
-        # if python 2.*, encode to type 'str' to prevent Unicode Encode Error from crypt.crypt
-        password = password.encode('utf-8')
     return crypt.crypt(password, salt)
 
 
diff --git a/azurelinuxagent/common/version.py b/azurelinuxagent/common/version.py
index 1e505bdb..1099e252 100644
--- a/azurelinuxagent/common/version.py
+++ b/azurelinuxagent/common/version.py
@@ -112,13 +112,12 @@ def set_current_agent():
     lib_dir = conf.get_lib_dir()
     if lib_dir[-1] != os.path.sep:
         lib_dir += os.path.sep
-    agent = path[len(lib_dir):].split(os.path.sep)[0]
-    match = AGENT_NAME_PATTERN.match(agent)
-    if match:
-        version = match.group(1)
-    else:
+    if path[:len(lib_dir)] != lib_dir:
         agent = AGENT_LONG_VERSION
         version = AGENT_VERSION
+    else:
+        agent = path[len(lib_dir):].split(os.path.sep)[0]
+        version = AGENT_NAME_PATTERN.match(agent).group(1)
     return agent, FlexibleVersion(version)
 CURRENT_AGENT, CURRENT_VERSION = set_current_agent()
 
diff --git a/azurelinuxagent/ga/env.py b/azurelinuxagent/ga/env.py
index c0545694..5d8da5c0 100644
--- a/azurelinuxagent/ga/env.py
+++ b/azurelinuxagent/ga/env.py
@@ -56,9 +56,9 @@ class EnvHandler(object):
         self.stopped = False
         logger.info("Start env monitor service.")
         self.dhcp_handler.conf_routes()
-        self.hostname = self.osutil.get_hostname_record()
+        self.hostname = socket.gethostname()
         self.dhcpid = self.osutil.get_dhcp_pid()
-        self.server_thread = threading.Thread(target=self.monitor)
+        self.server_thread = threading.Thread(target = self.monitor)
         self.server_thread.setDaemon(True)
         self.server_thread.start()
 
@@ -81,8 +81,7 @@ class EnvHandler(object):
         curr_hostname = socket.gethostname()
         if curr_hostname != self.hostname:
             logger.info("EnvMonitor: Detected host name change: {0} -> {1}",
-                        self.hostname,
-                        curr_hostname)
+                        self.hostname, curr_hostname)
             self.osutil.set_hostname(curr_hostname)
             self.osutil.publish_hostname(curr_hostname)
             self.hostname = curr_hostname
diff --git a/azurelinuxagent/ga/monitor.py b/azurelinuxagent/ga/monitor.py
index 478a7a3f..9e47d753 100644
--- a/azurelinuxagent/ga/monitor.py
+++ b/azurelinuxagent/ga/monitor.py
@@ -162,7 +162,7 @@ class MonitorHandler(object):
 
             try:
                 event = parse_event(data_str)
-                event.parameters.extend(self.sysinfo)
+                self.add_sysinfo(event)
                 event_list.events.append(event)
             except (ValueError, ProtocolError) as e:
                 logger.warn("Failed to decode event file: {0}", e)
@@ -193,3 +193,11 @@ class MonitorHandler(object):
             except Exception as e:
                 logger.warn("Failed to send events: {0}", e)
             time.sleep(60)
+
+    def add_sysinfo(self, event):
+        sysinfo_names = [v.name for v in self.sysinfo]
+        for param in event.parameters:
+            if param.name in sysinfo_names:
+                logger.verbose("Remove existing event parameter: [{0}:{1}]", param.name, param.value)
+                event.parameters.remove(param)
+        event.parameters.extend(self.sysinfo)
\ No newline at end of file
diff --git a/azurelinuxagent/pa/deprovision/default.py b/azurelinuxagent/pa/deprovision/default.py
index ced87eef..74f38544 100644
--- a/azurelinuxagent/pa/deprovision/default.py
+++ b/azurelinuxagent/pa/deprovision/default.py
@@ -88,9 +88,8 @@ class DeprovisionHandler(object):
         dirs_to_del = ["/var/lib/dhclient", "/var/lib/dhcpcd", "/var/lib/dhcp"]
         actions.append(DeprovisionAction(fileutil.rm_dirs, dirs_to_del))
 
-        # For Freebsd, NM controlled
-        actions.append(DeprovisionAction(fileutil.rm_files, ["/var/db/dhclient.leases.hn0",
-                                                             "/var/lib/NetworkManager/dhclient-*.lease"]))
+        # For Freebsd
+        actions.append(DeprovisionAction(fileutil.rm_files, ["/var/db/dhclient.leases.hn0"]))
 
     def del_lib_dir(self, warnings, actions):
         dirs_to_del = [conf.get_lib_dir()]


Test patch:
diff --git a/tests/common/osutil/test_default.py b/tests/common/osutil/test_default.py
index 933787ba..d982b7e2 100644
--- a/tests/common/osutil/test_default.py
+++ b/tests/common/osutil/test_default.py
@@ -21,7 +21,6 @@ import mock
 import azurelinuxagent.common.osutil.default as osutil
 import azurelinuxagent.common.utils.shellutil as shellutil
 from azurelinuxagent.common.osutil import get_osutil
-from azurelinuxagent.common.utils import fileutil
 from tests.tools import *
 
 
@@ -165,155 +164,5 @@ class TestOSUtil(AgentTestCase):
         else:
             self.fail("Cannot retrieve number of process cores using shell command.")
 
-    def test_conf_sshd(self):
-        new_file = "\
-Port 22\n\
-Protocol 2\n\
-ChallengeResponseAuthentication yes\n\
-#PasswordAuthentication yes\n\
-UsePAM yes\n\
-"
-        expected_output = "\
-Port 22\n\
-Protocol 2\n\
-ChallengeResponseAuthentication no\n\
-#PasswordAuthentication yes\n\
-UsePAM yes\n\
-PasswordAuthentication no\n\
-ClientAliveInterval 180\n\
-"
-
-        with patch.object(fileutil, 'write_file') as patch_write:
-            with patch.object(fileutil, 'read_file', return_value=new_file):
-                osutil.DefaultOSUtil().conf_sshd(disable_password=True)
-                patch_write.assert_called_once_with(
-                    conf.get_sshd_conf_file_path(),
-                    expected_output)
-
-    def test_conf_sshd_with_match(self):
-        new_file = "\
-Port 22\n\
-ChallengeResponseAuthentication yes\n\
-Match host 192.168.1.1\n\
-  ChallengeResponseAuthentication yes\n\
-"
-        expected_output = "\
-Port 22\n\
-ChallengeResponseAuthentication no\n\
-PasswordAuthentication no\n\
-ClientAliveInterval 180\n\
-Match host 192.168.1.1\n\
-  ChallengeResponseAuthentication yes\n\
-"
-
-        with patch.object(fileutil, 'write_file') as patch_write:
-            with patch.object(fileutil, 'read_file', return_value=new_file):
-                osutil.DefaultOSUtil().conf_sshd(disable_password=True)
-                patch_write.assert_called_once_with(
-                    conf.get_sshd_conf_file_path(),
-                    expected_output)
-
-    def test_conf_sshd_with_match_last(self):
-        new_file = "\
-Port 22\n\
-Match host 192.168.1.1\n\
-  ChallengeResponseAuthentication yes\n\
-"
-        expected_output = "\
-Port 22\n\
-PasswordAuthentication no\n\
-ChallengeResponseAuthentication no\n\
-ClientAliveInterval 180\n\
-Match host 192.168.1.1\n\
-  ChallengeResponseAuthentication yes\n\
-"
-
-        with patch.object(fileutil, 'write_file') as patch_write:
-            with patch.object(fileutil, 'read_file', return_value=new_file):
-                osutil.DefaultOSUtil().conf_sshd(disable_password=True)
-                patch_write.assert_called_once_with(
-                    conf.get_sshd_conf_file_path(),
-                    expected_output)
-
-    def test_conf_sshd_with_match_middle(self):
-        new_file = "\
-Port 22\n\
-match host 192.168.1.1\n\
-  ChallengeResponseAuthentication yes\n\
-match all\n\
-#Other config\n\
-"
-        expected_output = "\
-Port 22\n\
-match host 192.168.1.1\n\
-  ChallengeResponseAuthentication yes\n\
-match all\n\
-#Other config\n\
-PasswordAuthentication no\n\
-ChallengeResponseAuthentication no\n\
-ClientAliveInterval 180\n\
-"
-
-        with patch.object(fileutil, 'write_file') as patch_write:
-            with patch.object(fileutil, 'read_file', return_value=new_file):
-                osutil.DefaultOSUtil().conf_sshd(disable_password=True)
-                patch_write.assert_called_once_with(
-                    conf.get_sshd_conf_file_path(),
-                    expected_output)
-
-    def test_conf_sshd_with_match_multiple(self):
-        new_file = "\
-Port 22\n\
-Match host 192.168.1.1\n\
-  ChallengeResponseAuthentication yes\n\
-Match host 192.168.1.2\n\
-  ChallengeResponseAuthentication yes\n\
-Match all\n\
-#Other config\n\
-"
-        expected_output = "\
-Port 22\n\
-Match host 192.168.1.1\n\
-  ChallengeResponseAuthentication yes\n\
-Match host 192.168.1.2\n\
-  ChallengeResponseAuthentication yes\n\
-Match all\n\
-#Other config\n\
-PasswordAuthentication no\n\
-ChallengeResponseAuthentication no\n\
-ClientAliveInterval 180\n\
-"
-
-        with patch.object(fileutil, 'write_file') as patch_write:
-            with patch.object(fileutil, 'read_file', return_value=new_file):
-                osutil.DefaultOSUtil().conf_sshd(disable_password=True)
-                patch_write.assert_called_once_with(
-                    conf.get_sshd_conf_file_path(),
-                    expected_output)
-
-    def test_conf_sshd_with_match_multiple_first_last(self):
-        new_file = "\
-Match host 192.168.1.1\n\
-  ChallengeResponseAuthentication yes\n\
-Match host 192.168.1.2\n\
-  ChallengeResponseAuthentication yes\n\
-"
-        expected_output = "\
-PasswordAuthentication no\n\
-ChallengeResponseAuthentication no\n\
-ClientAliveInterval 180\n\
-Match host 192.168.1.1\n\
-  ChallengeResponseAuthentication yes\n\
-Match host 192.168.1.2\n\
-  ChallengeResponseAuthentication yes\n\
-"
-
-        with patch.object(fileutil, 'write_file') as patch_write:
-            with patch.object(fileutil, 'read_file', return_value=new_file):
-                osutil.DefaultOSUtil().conf_sshd(disable_password=True)
-                patch_write.assert_called_once_with(
-                    conf.get_sshd_conf_file_path(),
-                    expected_output)
-
 if __name__ == '__main__':
     unittest.main()
diff --git a/tests/common/test_version.py b/tests/common/test_version.py
index 57b2e9a1..306ea16f 100644
--- a/tests/common/test_version.py
+++ b/tests/common/test_version.py
@@ -54,22 +54,6 @@ class TestCurrentAgentName(AgentTestCase):
         self.assertEqual(AGENT_VERSION, str(current_version))
         return
 
-    @patch("os.getcwd", return_value="/")
-    def test_extract_name_root_finds_installed(self, mock_cwd):
-        current_agent, current_version = set_current_agent()
-        self.assertEqual(AGENT_LONG_VERSION, current_agent)
-        self.assertEqual(AGENT_VERSION, str(current_version))
-        return
-
-    @patch("os.getcwd")
-    def test_extract_name_in_path_finds_installed(self, mock_cwd):
-        path = os.path.join(conf.get_lib_dir(), "events")
-        mock_cwd.return_value = path
-        current_agent, current_version = set_current_agent()
-        self.assertEqual(AGENT_LONG_VERSION, current_agent)
-        self.assertEqual(AGENT_VERSION, str(current_version))
-        return
-
     @patch("os.getcwd")
     def test_extract_name_finds_latest_agent(self, mock_cwd):
         path = os.path.join(conf.get_lib_dir(), "{0}-{1}".format(
diff --git a/tests/ga/test_monitor.py b/tests/ga/test_monitor.py
index 838d037a..c646cef9 100644
--- a/tests/ga/test_monitor.py
+++ b/tests/ga/test_monitor.py
@@ -16,7 +16,6 @@
 #
 
 from tests.tools import *
-from azurelinuxagent.common.exception import *
 from azurelinuxagent.ga.monitor import *
 
 class TestMonitor(AgentTestCase):
@@ -27,3 +26,52 @@ class TestMonitor(AgentTestCase):
         self.assertNotEquals(0, event.parameters)
         self.assertNotEquals(None, event.parameters[0])
 
+    @patch('azurelinuxagent.common.osutil.get_osutil')
+    @patch('azurelinuxagent.common.protocol.get_protocol_util')
+    def test_add_sysinfo(self, _, __):
+        data_str = load_data('ext/event.xml')
+        event = parse_xml_event(data_str)
+        monitor_handler = get_monitor_handler()
+
+        vm_name = 'dummy_vm'
+        tenant_name = 'dummy_tenant'
+        role_name = 'dummy_role'
+        role_instance_name = 'dummy_role_instance'
+        container_id = 'dummy_container_id'
+
+        vm_name_param = "VMName"
+        tenant_name_param = "TenantName"
+        role_name_param = "RoleName"
+        role_instance_name_param = "RoleInstanceName"
+        container_id_param = "ContainerId"
+
+        sysinfo = [TelemetryEventParam(vm_name_param, vm_name),
+                   TelemetryEventParam(tenant_name_param, tenant_name),
+                   TelemetryEventParam(role_name_param, role_name),
+                   TelemetryEventParam(role_instance_name_param, role_instance_name),
+                   TelemetryEventParam(container_id_param, container_id)]
+        monitor_handler.sysinfo = sysinfo
+        monitor_handler.add_sysinfo(event)
+
+        self.assertNotEquals(None, event)
+        self.assertNotEquals(0, event.parameters)
+        self.assertNotEquals(None, event.parameters[0])
+        counter = 0
+        for p in event.parameters:
+            if p.name == vm_name_param:
+                self.assertEquals(vm_name, p.value)
+                counter += 1
+            elif p.name == tenant_name_param:
+                self.assertEquals(tenant_name, p.value)
+                counter += 1
+            elif p.name == role_name_param:
+                self.assertEquals(role_name, p.value)
+                counter += 1
+            elif p.name == role_instance_name_param:
+                self.assertEquals(role_instance_name, p.value)
+                counter += 1
+            elif p.name == container_id_param:
+                self.assertEquals(container_id, p.value)
+                counter += 1
+
+        self.assertEquals(5, counter)
diff --git a/tests/utils/test_file_util.py b/tests/utils/test_file_util.py
index 76fb15ba..f16f4099 100644
--- a/tests/utils/test_file_util.py
+++ b/tests/utils/test_file_util.py
@@ -15,12 +15,13 @@
 # Requires Python 2.4+ and Openssl 1.0+
 #
 
+from tests.tools import *
 import uuid
-
-import azurelinuxagent.common.utils.fileutil as fileutil
+import unittest
+import os
+import sys
 from azurelinuxagent.common.future import ustr
-from tests.tools import *
-
+import azurelinuxagent.common.utils.fileutil as fileutil
 
 class TestFileOperations(AgentTestCase):
 
@@ -116,66 +117,5 @@ class TestFileOperations(AgentTestCase):
 
         self.assertEqual(set(expected_files), set(actual_files))
 
-    @patch('os.path.isfile')
-    def test_update_conf_file(self, _):
-        new_file = "\
-DEVICE=eth0\n\
-ONBOOT=yes\n\
-BOOTPROTO=dhcp\n\
-TYPE=Ethernet\n\
-USERCTL=no\n\
-PEERDNS=yes\n\
-IPV6INIT=no\n\
-NM_CONTROLLED=yes\n"
-
-        existing_file = "\
-DEVICE=eth0\n\
-ONBOOT=yes\n\
-BOOTPROTO=dhcp\n\
-TYPE=Ethernet\n\
-DHCP_HOSTNAME=existing\n\
-USERCTL=no\n\
-PEERDNS=yes\n\
-IPV6INIT=no\n\
-NM_CONTROLLED=yes\n"
-
-        bad_file = "\
-DEVICE=eth0\n\
-ONBOOT=yes\n\
-BOOTPROTO=dhcp\n\
-TYPE=Ethernet\n\
-USERCTL=no\n\
-PEERDNS=yes\n\
-IPV6INIT=no\n\
-NM_CONTROLLED=yes\n\
-DHCP_HOSTNAME=no_new_line"
-
-        updated_file = "\
-DEVICE=eth0\n\
-ONBOOT=yes\n\
-BOOTPROTO=dhcp\n\
-TYPE=Ethernet\n\
-USERCTL=no\n\
-PEERDNS=yes\n\
-IPV6INIT=no\n\
-NM_CONTROLLED=yes\n\
-DHCP_HOSTNAME=test\n"
-
-        path = 'path'
-        with patch.object(fileutil, 'write_file') as patch_write:
-            with patch.object(fileutil, 'read_file', return_value=new_file):
-                fileutil.update_conf_file(path, 'DHCP_HOSTNAME', 'DHCP_HOSTNAME=test')
-                patch_write.assert_called_once_with(path, updated_file)
-
-        with patch.object(fileutil, 'write_file') as patch_write:
-            with patch.object(fileutil, 'read_file', return_value=existing_file):
-                fileutil.update_conf_file(path, 'DHCP_HOSTNAME', 'DHCP_HOSTNAME=test')
-                patch_write.assert_called_once_with(path, updated_file)
-
-        with patch.object(fileutil, 'write_file') as patch_write:
-            with patch.object(fileutil, 'read_file', return_value=bad_file):
-                fileutil.update_conf_file(path, 'DHCP_HOSTNAME', 'DHCP_HOSTNAME=test')
-                patch_write.assert_called_once_with(path, updated_file)
-
 if __name__ == '__main__':
     unittest.main()
diff --git a/tests/utils/test_passwords.txt b/tests/utils/test_passwords.txt
deleted file mode 100644
index 0d995eff..00000000
--- a/tests/utils/test_passwords.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-김치
-करी
-hamburger
-café
\ No newline at end of file
diff --git a/tests/utils/test_text_util.py b/tests/utils/test_text_util.py
index 6f204c78..dc3de85d 100644
--- a/tests/utils/test_text_util.py
+++ b/tests/utils/test_text_util.py
@@ -23,16 +23,12 @@ from azurelinuxagent.common.future import ustr
 import azurelinuxagent.common.utils.textutil as textutil
 from azurelinuxagent.common.utils.textutil import Version
 
-
 class TestTextUtil(AgentTestCase):
     def test_get_password_hash(self):
-        with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_passwords.txt'), 'rb') as in_file:
-            for data in in_file:
-                # Remove bom on bytes data before it is converted into string.
-                data = textutil.remove_bom(data)
-                data = ustr(data, encoding='utf-8')
-                password_hash = textutil.gen_password_hash(data, 6, 10)
-                self.assertNotEquals(None, password_hash)
+        password_hash = textutil.gen_password_hash("asdf", 6, 10)
+        self.assertNotEquals(None, password_hash)
+        password_hash = textutil.gen_password_hash("asdf", 6, 0)
+        self.assertNotEquals(None, password_hash)
 
     def test_remove_bom(self):
         #Test bom could be removed