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)
def findNearestAgentPackageVersion(projectVersion): if projectVersion == "": projectVersion = " " if OSCheck.is_suse_family(): Command = [ "bash", "-c", "zypper -q search -s --match-exact ambari-agent | grep '" + projectVersion + "' | cut -d '|' -f 4 | head -n1 | sed -e 's/-\w[^:]*//1' " ] elif OSCheck.is_debian_family(): if projectVersion == " ": Command = [ "bash", "-c", "apt-cache -q show ambari-agent |grep 'Version\:'|cut -d ' ' -f 2|tr -d '\\n'|sed -s 's/[-|~][A-Za-z0-9]*//'" ] else: Command = [ "bash", "-c", "apt-cache -q show ambari-agent |grep 'Version\:'|cut -d ' ' -f 2|grep '" + projectVersion + "'|tr -d '\\n'|sed -s 's/[-|~][A-Za-z\d]*//'" ] else: Command = [ "bash", "-c", "yum -q list all ambari-agent | grep '" + projectVersion + "' | sed -re 's/\s+/ /g' | cut -d ' ' -f 2 | head -n1 | sed -e 's/-\w[^:]*//1' " ] return execOsCommand(Command)
def installAgent(projectVersion): """ 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 if OSCheck.is_suse_family(): Command = ["zypper", "install", "-y", "ambari-agent-" + projectVersion] elif OSCheck.is_debian_family(): # add * to end of version in case of some test releases Command = [ "apt-get", "install", "-y", "--force-yes", "ambari-agent=" + projectVersion + "*" ] else: Command = [ "yum", "-y", "install", "--nogpgcheck", "ambari-agent-" + projectVersion ] return execOsCommand(Command)
def getAvaliableAgentPackageVersions(): if OSCheck.is_suse_family(): Command = [ "bash", "-c", "zypper -q 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-z0-9]*//g'" ] elif OSCheck.is_debian_family(): Command = [ "bash", "-c", "apt-cache -q show ambari-agent|grep 'Version\:'|cut -d ' ' -f 2| tr '\\n' ', '|sed -s 's/[-|~][A-Za-z0-9]*//g'" ] else: Command = [ "bash", "-c", "yum -q list all ambari-agent | grep -E '^ambari-agent' | sed -re 's/\s+/ /g' | cut -d ' ' -f 2 | tr '\\n' ', ' | sed -s 's/[-|~][A-Za-z0-9]*//g'" ] return execOsCommand(Command)