Parcourir la source

AMBARI-5689. In some cases automated agent setup doesn't work (dlysnichenko)

Lisnichenko Dmitro il y a 11 ans
Parent
commit
00cc0cf501

+ 41 - 0
ambari-common/src/main/python/common_functions/os_check.py

@@ -124,5 +124,46 @@ class OSCheck:
     else:
     else:
       raise Exception("Cannot detect os release name. Exiting...")
       raise Exception("Cannot detect os release name. Exiting...")
 
 
+  #  Exception safe family check functions
 
 
+  @staticmethod
+  def is_debian_family():
+    """
+     Return true if it is so or false if not
+
+     This is safe check for debian family, doesn't generate exception
+    """
+    try:
+      if OSCheck.get_os_family() == "debian":
+        return True
+    except Exception:
+      pass
+    return False
+
+  @staticmethod
+  def is_suse_family():
+    """
+     Return true if it is so or false if not
 
 
+     This is safe check for suse family, doesn't generate exception
+    """
+    try:
+      if OSCheck.get_os_family() == "suse":
+        return True
+    except Exception:
+      pass
+    return False
+
+  @staticmethod
+  def is_redhat_family():
+    """
+     Return true if it is so or false if not
+
+     This is safe check for redhat family, doesn't generate exception
+    """
+    try:
+      if OSCheck.get_os_family() == "redhat":
+        return True
+    except Exception:
+      pass
+    return False

+ 2 - 2
ambari-server/src/main/python/bootstrap.py

@@ -417,9 +417,9 @@ class Bootstrap(threading.Thread):
     self.host_log.write("Checking 'sudo' package on remote host...")
     self.host_log.write("Checking 'sudo' package on remote host...")
     params = self.shared_state
     params = self.shared_state
     if self.getServerFamily()[0] == "debian":
     if self.getServerFamily()[0] == "debian":
-      command = "dpkg --get-selections|grep -e ^sudo"
+      command = "dpkg --get-selections|grep -e '^sudo\s*install'"
     else:
     else:
-      command = "rpm -qa | grep -e ^sudo"
+      command = "rpm -qa | grep -e '^sudo\-'"
     ssh = SSH(params.user, params.sshkey_file, self.host, command,
     ssh = SSH(params.user, params.sshkey_file, self.host, command,
               params.bootdir, self.host_log,
               params.bootdir, self.host_log,
               errorMessage="Error: Sudo command is not available. " \
               errorMessage="Error: Sudo command is not available. " \

+ 59 - 50
ambari-server/src/main/python/setupAgent.py

@@ -29,6 +29,7 @@ import threading
 import traceback
 import traceback
 import stat
 import stat
 from pprint import pformat
 from pprint import pformat
+from common_functions import OSCheck
 
 
 AMBARI_PASSPHRASE_VAR = "AMBARI_PASSPHRASE"
 AMBARI_PASSPHRASE_VAR = "AMBARI_PASSPHRASE"
 
 
@@ -40,26 +41,12 @@ def execOsCommand(osCommand):
   return ret
   return ret
 
 
 
 
-def is_suse():
-  if os.path.isfile("/etc/issue"):
-    if "suse" in open("/etc/issue").read().lower():
-      return True
-  return False
-
-
-def is_ubuntu():
-  if os.path.isfile("/etc/issue"):
-    if "ubuntu" in open("/etc/issue").read().lower():
-      return True
-  return False
-
-
 def installAgent(projectVersion):
 def installAgent(projectVersion):
   """ Run install and make sure the agent install alright """
   """ Run install and make sure the agent install alright """
   # The command doesn't work with file mask ambari-agent*.rpm, so rename it on agent host
   # The command doesn't work with file mask ambari-agent*.rpm, so rename it on agent host
-  if is_suse():
+  if OSCheck.is_suse_family():
     Command = ["zypper", "install", "-y", "ambari-agent-" + projectVersion]
     Command = ["zypper", "install", "-y", "ambari-agent-" + projectVersion]
-  elif is_ubuntu():
+  elif OSCheck.is_debian_family():
     # add * to end of version in case of some test releases
     # add * to end of version in case of some test releases
     Command = ["apt-get", "install", "-y", "--force-yes", "ambari-agent=" + projectVersion + "*"]
     Command = ["apt-get", "install", "-y", "--force-yes", "ambari-agent=" + projectVersion + "*"]
   else:
   else:
@@ -69,7 +56,7 @@ def installAgent(projectVersion):
 
 
 def configureAgent(server_hostname):
 def configureAgent(server_hostname):
   """ Configure the agent so that it has all the configs knobs properly installed """
   """ Configure the agent so that it has all the configs knobs properly installed """
-  osCommand = ["sed", "-i.bak", "s/hostname=localhost/hostname=" + server_hostname +\
+  osCommand = ["sed", "-i.bak", "s/hostname=localhost/hostname=" + server_hostname +
                                 "/g", "/etc/ambari-agent/conf/ambari-agent.ini"]
                                 "/g", "/etc/ambari-agent/conf/ambari-agent.ini"]
   execOsCommand(osCommand)
   execOsCommand(osCommand)
   return
   return
@@ -77,7 +64,7 @@ def configureAgent(server_hostname):
 
 
 def runAgent(passPhrase, expected_hostname):
 def runAgent(passPhrase, expected_hostname):
   os.environ[AMBARI_PASSPHRASE_VAR] = passPhrase
   os.environ[AMBARI_PASSPHRASE_VAR] = passPhrase
-  agent_retcode = subprocess.call("/usr/sbin/ambari-agent restart --expected-hostname=" +\
+  agent_retcode = subprocess.call("/usr/sbin/ambari-agent restart --expected-hostname=" +
                                   expected_hostname, shell=True)
                                   expected_hostname, shell=True)
   # need this, because, very rarely,
   # need this, because, very rarely,
   # main.py(ambari-agent) starts a bit later then it should be started
   # main.py(ambari-agent) starts a bit later then it should be started
@@ -101,7 +88,8 @@ def getOptimalVersion(initialProjectVersion):
   optimalVersion = initialProjectVersion
   optimalVersion = initialProjectVersion
   ret = findNearestAgentPackageVersion(optimalVersion)
   ret = findNearestAgentPackageVersion(optimalVersion)
 
 
-  if ret["exitstatus"] == 0 and ret["log"][0].strip() != "" and ret["log"][0].strip() == initialProjectVersion:
+  if ret["exitstatus"] == 0 and ret["log"][0].strip() != "" \
+     and ret["log"][0].strip() == initialProjectVersion:
     optimalVersion = ret["log"][0].strip()
     optimalVersion = ret["log"][0].strip()
     retcode = 0
     retcode = 0
   else:
   else:
@@ -115,24 +103,24 @@ def getOptimalVersion(initialProjectVersion):
 def findNearestAgentPackageVersion(projectVersion):
 def findNearestAgentPackageVersion(projectVersion):
   if projectVersion == "":
   if projectVersion == "":
     projectVersion = "  "
     projectVersion = "  "
-  if is_suse():
-    Command = ["bash", "-c", "zypper search -s --match-exact ambari-agent | grep '" + projectVersion +\
+  if OSCheck.is_suse_family():
+    Command = ["bash", "-c", "zypper search -s --match-exact ambari-agent | grep '" + projectVersion +
                                  "' | cut -d '|' -f 4 | head -n1 | sed -e 's/-\w[^:]*//1' "]
                                  "' | cut -d '|' -f 4 | head -n1 | sed -e 's/-\w[^:]*//1' "]
-  elif is_ubuntu():
+  elif OSCheck.is_debian_family():
     if projectVersion == "  ":
     if projectVersion == "  ":
-      Command = ["bash", "-c", "apt-cache show ambari-agent |grep Version|cut -d ' ' -f 2|tr -d '\\n'|sed -s 's/[-|~][A-Za-z\d]*//g'"]
+      Command = ["bash", "-c", "apt-cache show ambari-agent |grep 'Version\:'|cut -d ' ' -f 2|tr -d '\\n'|sed -s 's/[-|~][A-Za-z\d]*//'"]
     else:
     else:
-      Command = ["bash", "-c", "apt-cache show ambari-agent |grep Version|cut -d ' ' -f 2|grep '" +
-               projectVersion + "'|tr -d '\\n'|sed -s 's/[-|~][A-Za-z\d]*//g'"]
+      Command = ["bash", "-c", "apt-cache show ambari-agent |grep 'Version\:'|cut -d ' ' -f 2|grep '" +
+               projectVersion + "'|tr -d '\\n'|sed -s 's/[-|~][A-Za-z\d]*//'"]
   else:
   else:
-    Command = ["bash", "-c", "yum list all ambari-agent | grep '" + projectVersion +\
+    Command = ["bash", "-c", "yum list all ambari-agent | grep '" + projectVersion +
                               "' | sed -re 's/\s+/ /g' | cut -d ' ' -f 2 | head -n1 | sed -e 's/-\w[^:]*//1' "]
                               "' | sed -re 's/\s+/ /g' | cut -d ' ' -f 2 | head -n1 | sed -e 's/-\w[^:]*//1' "]
   return execOsCommand(Command)
   return execOsCommand(Command)
 
 
 
 
 def isAgentPackageAlreadyInstalled(projectVersion):
 def isAgentPackageAlreadyInstalled(projectVersion):
-    if is_ubuntu():
-      Command = ["bash", "-c", "dpkg -s ambari-agent  2>&1|grep Version|grep " + projectVersion]
+    if OSCheck.is_debian_family():
+      Command = ["bash", "-c", "dpkg -s ambari-agent  2>&1|grep 'Version\:'|grep " + projectVersion]
     else:
     else:
       Command = ["bash", "-c", "rpm -qa | grep ambari-agent-"+projectVersion]
       Command = ["bash", "-c", "rpm -qa | grep ambari-agent-"+projectVersion]
     ret = execOsCommand(Command)
     ret = execOsCommand(Command)
@@ -143,15 +131,15 @@ def isAgentPackageAlreadyInstalled(projectVersion):
 
 
 
 
 def getAvaliableAgentPackageVersions():
 def getAvaliableAgentPackageVersions():
-  if is_suse():
+  if OSCheck.is_suse_family():
     Command = ["bash", "-c",
     Command = ["bash", "-c",
-        """zypper search -s --match-exact ambari-agent | grep ambari-agent | sed -re 's/\s+/ /g' | cut -d '|' -f 4 | tr '\\n' ', ' | sed -e 's/-\w[^:]*//1' """]
-  elif is_ubuntu():
+        "zypper search -s --match-exact ambari-agent | grep ambari-agent | sed -re 's/\s+/ /g' | cut -d '|' -f 4 | tr '\\n' ', ' | sed -s 's/[-|~][A-Za-z\d]*//g'"]
+  elif OSCheck.is_debian_family():
     Command = ["bash", "-c",
     Command = ["bash", "-c",
-        """apt-cache show ambari-agent|grep Version|cut -d ' ' -f 2| tr '\\n' ', '|sed -s 's/[-|~][A-Za-z\d]*//g'"""]
+        "apt-cache show ambari-agent|grep 'Version\:'|cut -d ' ' -f 2| tr '\\n' ', '|sed -s 's/[-|~][A-Za-z\d]*//g'"]
   else:
   else:
     Command = ["bash", "-c",
     Command = ["bash", "-c",
-        """yum list all ambari-agent | grep -E '^ambari-agent' | sed -re 's/\s+/ /g' | cut -d ' ' -f 2 | tr '\\n' ', ' | sed -e 's/-\w[^:]*//1' """]
+        "yum list all ambari-agent | grep -E '^ambari-agent' | sed -re 's/\s+/ /g' | cut -d ' ' -f 2 | tr '\\n' ', ' | sed -s 's/[-|~][A-Za-z\d]*//g'"]
   return execOsCommand(Command)
   return execOsCommand(Command)
 
 
 
 
@@ -170,27 +158,48 @@ def checkServerReachability(host, port):
   pass
   pass
 
 
 
 
-def main(argv=None):
-  # Parse the input
-  onlyargs = argv[1:]
-  expected_hostname = onlyargs[0]
-  passPhrase = onlyargs[1]
-  hostname = onlyargs[2]
-  projectVersion = None
+#  Command line syntax help
+# IsOptional  Index     Description
+#               0        Expected host name
+#               1        Password
+#               2        Host name
+#      X        3        Project Version (Ambari)
+#      X        4        Server port
+
+
+def parseArguments(argv=None):
+  if argv is None:  # make sure that arguments was passed
+     sys.exit(1)
+  args = argv[1:]  # shift path to script
+  if len(args) < 3:
+    sys.exit({"exitstatus": 1, "log": "Was passed not all required arguments"})
+
+  expected_hostname = args[0]
+  passPhrase = args[1]
+  hostname = args[2]
+  projectVersion = ""
   server_port = 8080
   server_port = 8080
-  if len(onlyargs) > 3:
-    projectVersion = onlyargs[3]
-  if len(onlyargs) > 4:
-    server_port = onlyargs[4]
-  try:
-    server_port = int(server_port)
-  except (Exception):
-    server_port = 8080
+
+  if len(args) > 3:
+    projectVersion = args[3]
+
+  if len(args) > 4:
+    try:
+      server_port = int(args[4])
+    except (Exception):
+      server_port = 8080
+
+  return expected_hostname, passPhrase, hostname, projectVersion, server_port
+
+
+def main(argv=None):
+  # Parse passed arguments
+  expected_hostname, passPhrase, hostname,\
+  projectVersion, server_port = parseArguments(argv)
 
 
   checkServerReachability(hostname, server_port)
   checkServerReachability(hostname, server_port)
 
 
-  if projectVersion is None or projectVersion == "null" or projectVersion == "{ambariVersion}" or projectVersion == "":
-    projectVersion = ""  # fix error in error output, if projectVersion leaves None
+  if projectVersion == "null" or projectVersion == "{ambariVersion}" or projectVersion == "":
     retcode = getOptimalVersion("")
     retcode = getOptimalVersion("")
   else:
   else:
     retcode = getOptimalVersion(projectVersion)
     retcode = getOptimalVersion(projectVersion)

+ 2 - 2
ambari-server/src/test/python/TestBootstrap.py

@@ -536,7 +536,7 @@ class TestBootstrap(TestCase):
     res = bootstrap_obj.checkSudoPackage()
     res = bootstrap_obj.checkSudoPackage()
     self.assertEquals(res, expected)
     self.assertEquals(res, expected)
     command = str(init_mock.call_args[0][3])
     command = str(init_mock.call_args[0][3])
-    self.assertEqual(command, "rpm -qa | grep -e ^sudo")
+    self.assertEqual(command, "rpm -qa | grep -e '^sudo\-'")
 
 
   @patch.object(Bootstrap, "getServerFamily")
   @patch.object(Bootstrap, "getServerFamily")
   @patch.object(SSH, "__init__")
   @patch.object(SSH, "__init__")
@@ -554,7 +554,7 @@ class TestBootstrap(TestCase):
     res = bootstrap_obj.checkSudoPackage()
     res = bootstrap_obj.checkSudoPackage()
     self.assertEquals(res, expected)
     self.assertEquals(res, expected)
     command = str(init_mock.call_args[0][3])
     command = str(init_mock.call_args[0][3])
-    self.assertEqual(command, "dpkg --get-selections|grep -e ^sudo")
+    self.assertEqual(command, "dpkg --get-selections|grep -e '^sudo\s*install'")
 
 
 
 
   @patch.object(SSH, "__init__")
   @patch.object(SSH, "__init__")

+ 27 - 0
ambari-server/src/test/python/TestOSCheck.py

@@ -239,3 +239,30 @@ class TestOSCheck(TestCase):
         "Local OS is not compatible with cluster primary OS. Please perform manual bootstrap on this host.",
         "Local OS is not compatible with cluster primary OS. Please perform manual bootstrap on this host.",
         str(e))
         str(e))
       pass
       pass
+
+  @patch.object(OSCheck, "get_os_family")
+  def test_is_debian_family(self, get_os_family_mock):
+
+    get_os_family_mock.return_value = "debian"
+    self.assertEqual(OSCheck.is_debian_family(), True)
+
+    get_os_family_mock.return_value = "troll_os"
+    self.assertEqual(OSCheck.is_debian_family(), False)
+
+  @patch.object(OSCheck, "get_os_family")
+  def test_is_suse_family(self, get_os_family_mock):
+
+    get_os_family_mock.return_value = "suse"
+    self.assertEqual(OSCheck.is_suse_family(), True)
+
+    get_os_family_mock.return_value = "troll_os"
+    self.assertEqual(OSCheck.is_suse_family(), False)
+
+  @patch.object(OSCheck, "get_os_family")
+  def test_is_redhat_family(self, get_os_family_mock):
+
+    get_os_family_mock.return_value = "redhat"
+    self.assertEqual(OSCheck.is_redhat_family(), True)
+
+    get_os_family_mock.return_value = "troll_os"
+    self.assertEqual(OSCheck.is_redhat_family(), False)

+ 65 - 84
ambari-server/src/test/python/TestSetupAgent.py

@@ -80,16 +80,15 @@ class TestSetupAgent(TestCase):
     self.assertTrue(expected_hostname in cmdStr)
     self.assertTrue(expected_hostname in cmdStr)
     self.assertEqual(ret, 2)
     self.assertEqual(ret, 2)
 
 
-
   @patch.object(setup_agent, 'getAvaliableAgentPackageVersions')
   @patch.object(setup_agent, 'getAvaliableAgentPackageVersions')
-  @patch.object(setup_agent, 'is_suse')
-  @patch.object(setup_agent, 'is_ubuntu')
+  @patch('common_functions.OSCheck.is_suse_family')
+  @patch('common_functions.OSCheck.is_debian_family')
   @patch.object(setup_agent, 'findNearestAgentPackageVersion')
   @patch.object(setup_agent, 'findNearestAgentPackageVersion')
-  def test_returned_optimal_version_is_initial_on_suse(self, findNearestAgentPackageVersion_method, is_ubuntu_mock,
-                                                       is_suse_method, getAvaliableAgentPackageVersions_method):
+  def test_returned_optimal_version_is_initial_on_suse(self, findNearestAgentPackageVersion_method, is_debian_family_method,
+                                                       is_suse_family_method, getAvaliableAgentPackageVersions_method):
     getAvaliableAgentPackageVersions_method.return_value = {"exitstatus": 0, "log": "1.1.1"}
     getAvaliableAgentPackageVersions_method.return_value = {"exitstatus": 0, "log": "1.1.1"}
-    is_suse_method.return_value = True
-    is_ubuntu_mock.return_value = False
+    is_suse_family_method.return_value = True
+    is_debian_family_method.return_value = False
 
 
     projectVersion = "1.1.1"
     projectVersion = "1.1.1"
     result_version = setup_agent.getOptimalVersion(projectVersion)
     result_version = setup_agent.getOptimalVersion(projectVersion)
@@ -98,14 +97,14 @@ class TestSetupAgent(TestCase):
     pass
     pass
 
 
   @patch.object(setup_agent, 'getAvaliableAgentPackageVersions')
   @patch.object(setup_agent, 'getAvaliableAgentPackageVersions')
-  @patch.object(setup_agent, 'is_suse')
-  @patch.object(setup_agent, 'is_ubuntu')
+  @patch('common_functions.OSCheck.is_suse_family')
+  @patch('common_functions.OSCheck.is_debian_family')
   @patch.object(setup_agent, 'findNearestAgentPackageVersion')
   @patch.object(setup_agent, 'findNearestAgentPackageVersion')
-  def test_returned_optimal_version_is_initial_on_ubuntu(self, findNearestAgentPackageVersion_method, is_ubuntu_mock,
-                                                       is_suse_method, getAvaliableAgentPackageVersions_method):
+  def test_returned_optimal_version_is_initial_on_debian(self, findNearestAgentPackageVersion_method, is_debian_family_method,
+                                                       is_suse_family_method, getAvaliableAgentPackageVersions_method):
     getAvaliableAgentPackageVersions_method.return_value = {"exitstatus": 0, "log": "1.1.1"}
     getAvaliableAgentPackageVersions_method.return_value = {"exitstatus": 0, "log": "1.1.1"}
-    is_suse_method.return_value = False
-    is_ubuntu_mock.return_value = True
+    is_suse_family_method.return_value = False
+    is_debian_family_method.return_value = True
 
 
     projectVersion = "1.1.1"
     projectVersion = "1.1.1"
     result_version = setup_agent.getOptimalVersion(projectVersion)
     result_version = setup_agent.getOptimalVersion(projectVersion)
@@ -113,19 +112,19 @@ class TestSetupAgent(TestCase):
     self.assertTrue(result_version["exitstatus"] == 1)
     self.assertTrue(result_version["exitstatus"] == 1)
     pass
     pass
 
 
-  @patch.object(setup_agent, 'is_suse')
-  @patch.object(setup_agent, 'is_ubuntu')
+  @patch('common_functions.OSCheck.is_suse_family')
+  @patch('common_functions.OSCheck.is_debian_family')
   @patch.object(setup_agent, 'findNearestAgentPackageVersion')
   @patch.object(setup_agent, 'findNearestAgentPackageVersion')
   def test_returned_optimal_version_is_nearest_on_suse(self, findNearestAgentPackageVersion_method,
   def test_returned_optimal_version_is_nearest_on_suse(self, findNearestAgentPackageVersion_method,
-                                                       is_ubuntu_method,
-                                                       is_suse_method):
-    is_suse_method.return_value = True
-    is_ubuntu_method.return_value = False
+                                                       is_debian_family_method,
+                                                       is_suse_family_method):
+    is_suse_family_method.return_value = True
+    is_debian_family_method.return_value = False
 
 
     projectVersion = ""
     projectVersion = ""
     nearest_version = projectVersion + "1.1.1"
     nearest_version = projectVersion + "1.1.1"
     findNearestAgentPackageVersion_method.return_value = {
     findNearestAgentPackageVersion_method.return_value = {
-      "exitstatus" : 0,
+      "exitstatus": 0,
       "log": [nearest_version, ""]
       "log": [nearest_version, ""]
     }
     }
 
 
@@ -134,19 +133,19 @@ class TestSetupAgent(TestCase):
     self.assertTrue(result_version["exitstatus"] == 1)
     self.assertTrue(result_version["exitstatus"] == 1)
     pass
     pass
 
 
-  @patch.object(setup_agent, 'is_suse')
-  @patch.object(setup_agent, 'is_ubuntu')
+  @patch('common_functions.OSCheck.is_suse_family')
+  @patch('common_functions.OSCheck.is_debian_family')
   @patch.object(setup_agent, 'findNearestAgentPackageVersion')
   @patch.object(setup_agent, 'findNearestAgentPackageVersion')
-  def test_returned_optimal_version_is_nearest_on_ubuntu(self, findNearestAgentPackageVersion_method,
-                                                       is_ubuntu_method,
-                                                       is_suse_method):
-    is_suse_method.return_value = False
-    is_ubuntu_method.return_value = True
+  def test_returned_optimal_version_is_nearest_on_debian(self, findNearestAgentPackageVersion_method,
+                                                       is_debian_family_method,
+                                                       is_suse_family_method):
+    is_suse_family_method.return_value = False
+    is_debian_family_method.return_value = True
 
 
     projectVersion = ""
     projectVersion = ""
     nearest_version = projectVersion + "1.1.1"
     nearest_version = projectVersion + "1.1.1"
     findNearestAgentPackageVersion_method.return_value = {
     findNearestAgentPackageVersion_method.return_value = {
-      "exitstatus" : 0,
+      "exitstatus": 0,
       "log": [nearest_version, ""]
       "log": [nearest_version, ""]
     }
     }
 
 
@@ -156,15 +155,15 @@ class TestSetupAgent(TestCase):
     pass
     pass
 
 
   @patch.object(setup_agent, 'getAvaliableAgentPackageVersions')
   @patch.object(setup_agent, 'getAvaliableAgentPackageVersions')
-  @patch.object(setup_agent, 'is_suse')
-  @patch.object(setup_agent, 'is_ubuntu')
+  @patch('common_functions.OSCheck.is_suse_family')
+  @patch('common_functions.OSCheck.is_debian_family')
   @patch.object(setup_agent, 'findNearestAgentPackageVersion')
   @patch.object(setup_agent, 'findNearestAgentPackageVersion')
   def test_returned_optimal_version_is_initial(self, findNearestAgentPackageVersion_method,
   def test_returned_optimal_version_is_initial(self, findNearestAgentPackageVersion_method,
-                                               is_ubuntu_method,
-                                               is_suse_method, getAvaliableAgentPackageVersions_method):
+                                               is_debian_family_method,
+                                               is_suse_family_method, getAvaliableAgentPackageVersions_method):
     getAvaliableAgentPackageVersions_method.return_value = {"exitstatus": 0, "log": "1.1.1"}
     getAvaliableAgentPackageVersions_method.return_value = {"exitstatus": 0, "log": "1.1.1"}
-    is_suse_method.return_value = False
-    is_ubuntu_method.return_value = False
+    is_suse_family_method.return_value = False
+    is_debian_family_method.return_value = False
 
 
     projectVersion = "1.1.1"
     projectVersion = "1.1.1"
     result_version = setup_agent.getOptimalVersion(projectVersion)
     result_version = setup_agent.getOptimalVersion(projectVersion)
@@ -172,19 +171,18 @@ class TestSetupAgent(TestCase):
     self.assertTrue(result_version["log"] == projectVersion)
     self.assertTrue(result_version["log"] == projectVersion)
     pass
     pass
 
 
-
   @patch.object(setup_agent, 'getAvaliableAgentPackageVersions')
   @patch.object(setup_agent, 'getAvaliableAgentPackageVersions')
-  @patch.object(setup_agent, 'is_suse')
-  @patch.object(setup_agent, 'is_ubuntu')
+  @patch('common_functions.OSCheck.is_suse_family')
+  @patch('common_functions.OSCheck.is_debian_family')
   @patch.object(setup_agent, 'findNearestAgentPackageVersion')
   @patch.object(setup_agent, 'findNearestAgentPackageVersion')
   def test_returned_optimal_version_is_default(self, findNearestAgentPackageVersion_method,
   def test_returned_optimal_version_is_default(self, findNearestAgentPackageVersion_method,
-                                               is_ubuntu_method,
-                                               is_suse_method, getAvaliableAgentPackageVersions_method):
+                                               is_debian_family_method,
+                                               is_suse_family_method, getAvaliableAgentPackageVersions_method):
     getAvaliableAgentPackageVersions_method.return_value = {"exitstatus": 0, "log": "1.1.1"}
     getAvaliableAgentPackageVersions_method.return_value = {"exitstatus": 0, "log": "1.1.1"}
-    is_suse_method.return_value = False
-    is_ubuntu_method.return_value = False
+    is_suse_family_method.return_value = False
+    is_debian_family_method.return_value = False
     findNearestAgentPackageVersion_method.return_value = {
     findNearestAgentPackageVersion_method.return_value = {
-      "exitstatus" : 0,
+      "exitstatus": 0,
       "log": ["1.1.1.1", ""]
       "log": ["1.1.1.1", ""]
     }
     }
 
 
@@ -198,36 +196,19 @@ class TestSetupAgent(TestCase):
   def test_execOsCommand(self, Popen_mock):
   def test_execOsCommand(self, Popen_mock):
     self.assertFalse(setup_agent.execOsCommand("hostname -f") == None)
     self.assertFalse(setup_agent.execOsCommand("hostname -f") == None)
 
 
-  @patch("os.path.isfile")
-  @patch("__builtin__.open")
-  def test_is_suse(self, open_mock, isfile_mock):
-    self.assertFalse(setup_agent.is_suse())
-    isfile_mock.return_value = True
-    f = open_mock.return_value
-    f.read.return_value = " suse "
-    self.assertTrue(setup_agent.is_suse())
-
-  @patch("os.path.isfile")
-  @patch("__builtin__.open")
-  def test_is_ubuntu(self, open_mock, isfile_mock):
-    isfile_mock.return_value = True
-    f = open_mock.return_value
-    f.read.return_value = " ubuntu "
-    self.assertTrue(setup_agent.is_ubuntu())
-
   @patch.object(setup_agent, 'isAgentPackageAlreadyInstalled')
   @patch.object(setup_agent, 'isAgentPackageAlreadyInstalled')
   @patch.object(setup_agent, 'runAgent')
   @patch.object(setup_agent, 'runAgent')
   @patch.object(setup_agent, 'configureAgent')
   @patch.object(setup_agent, 'configureAgent')
   @patch.object(setup_agent, 'installAgent')
   @patch.object(setup_agent, 'installAgent')
-  @patch.object(setup_agent, 'is_suse')
-  @patch.object(setup_agent, 'is_ubuntu')
+  @patch('common_functions.OSCheck.is_suse_family')
+  @patch('common_functions.OSCheck.is_debian_family')
   @patch.object(setup_agent, 'getOptimalVersion')
   @patch.object(setup_agent, 'getOptimalVersion')
   @patch.object(setup_agent, 'checkServerReachability')
   @patch.object(setup_agent, 'checkServerReachability')
   @patch("sys.exit")
   @patch("sys.exit")
   @patch("os.path.dirname")
   @patch("os.path.dirname")
   @patch("os.path.realpath")
   @patch("os.path.realpath")
   def test_setup_agent_main(self, dirname_mock, realpath_mock, exit_mock, checkServerReachability_mock,
   def test_setup_agent_main(self, dirname_mock, realpath_mock, exit_mock, checkServerReachability_mock,
-                            getOptimalVersion_mock, is_ubuntu_mock, is_suse_mock,
+                            getOptimalVersion_mock, is_debian_family_mock, is_suse_family_mock,
                             installAgent_mock, configureAgent_mock, runAgent_mock,
                             installAgent_mock, configureAgent_mock, runAgent_mock,
                             isAgentPackageAlreadyInstalled_mock):
                             isAgentPackageAlreadyInstalled_mock):
     installAgent_mock.return_value = {'log': 'log', 'exitstatus': 0}
     installAgent_mock.return_value = {'log': 'log', 'exitstatus': 0}
@@ -241,20 +222,20 @@ class TestSetupAgent(TestCase):
 
 
     getOptimalVersion_mock.return_value = {'log': '1.1.1', 'exitstatus': 0}
     getOptimalVersion_mock.return_value = {'log': '1.1.1', 'exitstatus': 0}
     isAgentPackageAlreadyInstalled_mock.return_value = False
     isAgentPackageAlreadyInstalled_mock.return_value = False
-    is_suse_mock.return_value = True
-    is_ubuntu_mock.return_value = False
+    is_suse_family_mock.return_value = True
+    is_debian_family_mock.return_value = False
     setup_agent.main(("setupAgent.py","agents_host","password", "server_hostname","1.1.1","8080"))
     setup_agent.main(("setupAgent.py","agents_host","password", "server_hostname","1.1.1","8080"))
     self.assertTrue(exit_mock.called)
     self.assertTrue(exit_mock.called)
     self.assertTrue(getOptimalVersion_mock.called)
     self.assertTrue(getOptimalVersion_mock.called)
     self.assertTrue(isAgentPackageAlreadyInstalled_mock.called)
     self.assertTrue(isAgentPackageAlreadyInstalled_mock.called)
     self.assertTrue(installAgent_mock.called)
     self.assertTrue(installAgent_mock.called)
-    self.assertFalse(is_suse_mock.called)
-    self.assertFalse(is_ubuntu_mock.called)
+    self.assertFalse(is_suse_family_mock.called)
+    self.assertFalse(is_debian_family_mock.called)
     exit_mock.reset_mock()
     exit_mock.reset_mock()
     getOptimalVersion_mock.reset_mock()
     getOptimalVersion_mock.reset_mock()
     isAgentPackageAlreadyInstalled_mock.reset_mock()
     isAgentPackageAlreadyInstalled_mock.reset_mock()
-    is_suse_mock.reset_mock()
-    is_ubuntu_mock.reset_mock()
+    is_suse_family_mock.reset_mock()
+    is_debian_family_mock.reset_mock()
     installAgent_mock.reset_mock()
     installAgent_mock.reset_mock()
 
 
     getOptimalVersion_mock.return_value = {'log': '', 'exitstatus': 0}
     getOptimalVersion_mock.return_value = {'log': '', 'exitstatus': 0}
@@ -262,34 +243,34 @@ class TestSetupAgent(TestCase):
     self.assertTrue(exit_mock.called)
     self.assertTrue(exit_mock.called)
     self.assertTrue(getOptimalVersion_mock.called)
     self.assertTrue(getOptimalVersion_mock.called)
     self.assertFalse(isAgentPackageAlreadyInstalled_mock.called)
     self.assertFalse(isAgentPackageAlreadyInstalled_mock.called)
-    self.assertFalse(is_suse_mock.called)
-    self.assertFalse(is_ubuntu_mock.called)
+    self.assertFalse(is_suse_family_mock.called)
+    self.assertFalse(is_debian_family_mock.called)
 
 
     exit_mock.reset_mock()
     exit_mock.reset_mock()
     getOptimalVersion_mock.reset_mock()
     getOptimalVersion_mock.reset_mock()
     isAgentPackageAlreadyInstalled_mock.reset_mock()
     isAgentPackageAlreadyInstalled_mock.reset_mock()
-    is_suse_mock.reset_mock()
-    is_ubuntu_mock.reset_mock()
+    is_suse_family_mock.reset_mock()
+    is_debian_family_mock.reset_mock()
     installAgent_mock.reset_mock()
     installAgent_mock.reset_mock()
 
 
-    is_suse_mock.return_value = False
-    is_ubuntu_mock.return_value = False
+    is_suse_family_mock.return_value = False
+    is_debian_family_mock.return_value = False
     getOptimalVersion_mock.return_value = {'log': '1.1.1', 'exitstatus': 0}
     getOptimalVersion_mock.return_value = {'log': '1.1.1', 'exitstatus': 0}
     setup_agent.main(("setupAgent.py","agents_host","password", "server_hostname","1.1.1","8080"))
     setup_agent.main(("setupAgent.py","agents_host","password", "server_hostname","1.1.1","8080"))
     self.assertTrue(exit_mock.called)
     self.assertTrue(exit_mock.called)
     self.assertTrue(getOptimalVersion_mock.called)
     self.assertTrue(getOptimalVersion_mock.called)
     self.assertTrue(isAgentPackageAlreadyInstalled_mock.called)
     self.assertTrue(isAgentPackageAlreadyInstalled_mock.called)
     self.assertTrue(installAgent_mock.called)
     self.assertTrue(installAgent_mock.called)
-    self.assertFalse(is_suse_mock.called)
-    self.assertFalse(is_ubuntu_mock.called)
+    self.assertFalse(is_suse_family_mock.called)
+    self.assertFalse(is_debian_family_mock.called)
     exit_mock.reset_mock()
     exit_mock.reset_mock()
     getOptimalVersion_mock.reset_mock()
     getOptimalVersion_mock.reset_mock()
     isAgentPackageAlreadyInstalled_mock.reset_mock()
     isAgentPackageAlreadyInstalled_mock.reset_mock()
     exit_mock.reset_mock()
     exit_mock.reset_mock()
     getOptimalVersion_mock.reset_mock()
     getOptimalVersion_mock.reset_mock()
     isAgentPackageAlreadyInstalled_mock.reset_mock()
     isAgentPackageAlreadyInstalled_mock.reset_mock()
-    is_suse_mock.reset_mock()
-    is_ubuntu_mock.reset_mock()
+    is_suse_family_mock.reset_mock()
+    is_debian_family_mock.reset_mock()
     installAgent_mock.reset_mock()
     installAgent_mock.reset_mock()
 
 
     setup_agent.main(("setupAgent.py","agents_host","password", "server_hostname","{ambariVersion}","8080"))
     setup_agent.main(("setupAgent.py","agents_host","password", "server_hostname","{ambariVersion}","8080"))
@@ -301,8 +282,8 @@ class TestSetupAgent(TestCase):
     self.assertTrue(exit_mock.called)
     self.assertTrue(exit_mock.called)
     self.assertTrue(getOptimalVersion_mock.called)
     self.assertTrue(getOptimalVersion_mock.called)
     exit_mock.reset_mock()
     exit_mock.reset_mock()
-    is_suse_mock.return_value = False
-    is_ubuntu_mock.return_value = False
+    is_suse_family_mock.return_value = False
+    is_debian_family_mock.return_value = False
     setup_agent.main(("setupAgent.py","agents_host","password", "server_hostname","null","null"))
     setup_agent.main(("setupAgent.py","agents_host","password", "server_hostname","null","null"))
     self.assertTrue(exit_mock.called)
     self.assertTrue(exit_mock.called)
     exit_mock.reset_mock()
     exit_mock.reset_mock()
@@ -321,8 +302,8 @@ class TestSetupAgent(TestCase):
     installAgent_mock.reset_mock()
     installAgent_mock.reset_mock()
     exit_mock.reset_mock()
     exit_mock.reset_mock()
     #if suse
     #if suse
-    is_suse_mock.return_value = True
-    is_ubuntu_mock.return_value = False
+    is_suse_family_mock.return_value = True
+    is_debian_family_mock.return_value = False
     #if "zypper install -y ambari-agent" return not 0 result
     #if "zypper install -y ambari-agent" return not 0 result
     installAgent_mock.return_value = {'log': 'log', 'exitstatus': 1}
     installAgent_mock.return_value = {'log': 'log', 'exitstatus': 1}
     try:
     try:
@@ -334,8 +315,8 @@ class TestSetupAgent(TestCase):
     self.assertTrue(exit_mock.called)
     self.assertTrue(exit_mock.called)
     exit_mock.reset_mock()
     exit_mock.reset_mock()
     #if ubuntu
     #if ubuntu
-    is_suse_mock.return_value = False
-    is_ubuntu_mock.return_value = True
+    is_suse_family_mock.return_value = False
+    is_debian_family_mock.return_value = True
 
 
     installAgent_mock.return_value = {'log': 'log', 'exitstatus': 1}
     installAgent_mock.return_value = {'log': 'log', 'exitstatus': 1}
     try:
     try: