def test_get_os_major_version(self, mock_linux_distribution): # 1 mock_linux_distribution.return_value = ('', '123.45.67', '') result = OSCheck.get_os_major_version() self.assertEquals(result, '123') # 2 mock_linux_distribution.return_value = ('Suse', '11', '') result = OSCheck.get_os_major_version() self.assertEquals(result, '11')
def test_get_os_major_version(self, mock_linux_distribution): # 1 mock_linux_distribution.return_value = ("", "123.45.67", "") result = OSCheck.get_os_major_version() self.assertEquals(result, "123") # 2 mock_linux_distribution.return_value = ("Suse", "11", "") result = OSCheck.get_os_major_version() self.assertEquals(result, "11")
def test_get_os_major_version(self, mock_linux_distribution): # 1 mock_linux_distribution.return_value = ('', '123.45.67', '') result = OSCheck.get_os_major_version() self.assertEquals(result, '123') # 2 mock_linux_distribution.return_value = ('Suse', '11', '') result = OSCheck.get_os_major_version() self.assertEquals(result, '11')
def get_postgre_hba_dir(OS_FAMILY): """Return postgre hba dir location depends on OS. Also depends on version of postgres creates symlink like postgresql-->postgresql-9.3 1) /etc/rc.d/init.d/postgresql --> /etc/rc.d/init.d/postgresql-9.3 2) /etc/init.d/postgresql --> /etc/init.d/postgresql-9.1 """ if OSCheck.is_ubuntu_family(): # Like: /etc/postgresql/9.1/main/ return os.path.join(get_pg_hba_init_files(), get_ubuntu_pg_version(), "main") elif OSCheck.is_redhat_family() and int(OSCheck.get_os_major_version()) >= 7: return PG_HBA_ROOT_DEFAULT else: if not os.path.isfile(get_pg_hba_init_files()): # Link: /etc/init.d/postgresql --> /etc/init.d/postgresql-9.1 os.symlink(glob.glob(get_pg_hba_init_files() + '*')[0], get_pg_hba_init_files()) # Get postgres_data location (default: /var/lib/pgsql/data) cmd = "alias exit=return; source " + get_pg_hba_init_files() + " status &>/dev/null; echo $PGDATA" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) (PG_HBA_ROOT, err) = p.communicate() if PG_HBA_ROOT and len(PG_HBA_ROOT.strip()) > 0: return PG_HBA_ROOT.strip() else: return PG_HBA_ROOT_DEFAULT
def get_ntp_service(): if OSCheck.is_redhat_family() and int(OSCheck.get_os_major_version()) >= 7: return ("chronyd", "ntpd",) elif OSCheck.is_redhat_family(): return ("ntpd",) elif OSCheck.is_suse_family() or OSCheck.is_ubuntu_family(): return ("ntp",)
def get_postgre_hba_dir(OS_FAMILY): """Return postgre hba dir location depends on OS. Also depends on version of postgres creates symlink like postgresql-->postgresql-9.3 1) /etc/rc.d/init.d/postgresql --> /etc/rc.d/init.d/postgresql-9.3 2) /etc/init.d/postgresql --> /etc/init.d/postgresql-9.1 """ if OSCheck.is_ubuntu_family(): # Like: /etc/postgresql/9.1/main/ return os.path.join(get_pg_hba_init_files(), get_ubuntu_pg_version(), "main") elif OSCheck.is_redhat_family() and int( OSCheck.get_os_major_version()) >= 7: return PG_HBA_ROOT_DEFAULT else: if not os.path.isfile(get_pg_hba_init_files()): # Link: /etc/init.d/postgresql --> /etc/init.d/postgresql-9.1 os.symlink( glob.glob(get_pg_hba_init_files() + '*')[0], get_pg_hba_init_files()) # Get postgres_data location (default: /var/lib/pgsql/data) cmd = "alias exit=return; source " + get_pg_hba_init_files( ) + " status &>/dev/null; echo $PGDATA" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) (PG_HBA_ROOT, err) = p.communicate() if PG_HBA_ROOT and len(PG_HBA_ROOT.strip()) > 0: return PG_HBA_ROOT.strip() else: return PG_HBA_ROOT_DEFAULT
def os_major_version(self): """ Example return value: "6" for "Centos 6.3" In case cannot detect --> Fail """ return OSCheck.get_os_major_version()
def os_major_version(self): """ Example return value: "6" for "Centos 6.3" In case cannot detect --> Fail """ return OSCheck.get_os_major_version()
def test_aliases(self, mock_linux_distribution): OSConst.OS_TYPE_ALIASES['qwerty_os123'] = 'aliased_os5' OSConst.OS_FAMILY_COLLECTION.append({ 'name': 'aliased_os_family', 'os_list': ["aliased_os"] }) mock_linux_distribution.return_value = ('qwerty_os', '123.45.67', '') self.assertEquals(OSCheck.get_os_type(), 'aliased_os') self.assertEquals(OSCheck.get_os_major_version(), '5') self.assertEquals(OSCheck.get_os_version(), '5.45.67') self.assertEquals(OSCheck.get_os_family(), 'aliased_os_family')
def test_aliases(self, mock_linux_distribution): OSConst.OS_TYPE_ALIASES['qwerty_os123'] = 'aliased_os5' OSConst.OS_FAMILY_COLLECTION.append({ 'name': 'aliased_os_family', 'os_list': ["aliased_os"] }) mock_linux_distribution.return_value = ('qwerty_os', '123.45.67', '') self.assertEquals(OSCheck.get_os_type(), 'aliased_os') self.assertEquals(OSCheck.get_os_major_version(), '5') self.assertEquals(OSCheck.get_os_version(), '5.45.67') self.assertEquals(OSCheck.get_os_family(), 'aliased_os_family')
def configure_kernel_parameters(): """Configure correct kernel parameters.""" import params if not params.set_kernel_parameters: return if System.get_instance().os_family == "redhat" and int( OSCheck.get_os_major_version()) >= 6: utilities.set_kernel_parameters( utilities.get_configuration_file('system-variables-redhat6')) else: utilities.set_kernel_parameters( utilities.get_configuration_file('system-variables'))
def main(argv=None): # Same logic that was in "os_type_check.sh" if len(sys.argv) != 2: print "Usage: <cluster_os>" raise Exception("Error in number of arguments. Usage: <cluster_os>") pass cluster_os = sys.argv[1] current_os = OSCheck.get_os_family() + OSCheck.get_os_major_version() # If agent/server have the same {"family","main_version"} - then ok. print "Cluster primary/cluster OS type is %s and local/current OS type is %s" % ( cluster_os, current_os) if current_os == cluster_os: sys.exit(0) else: raise Exception("Local OS is not compatible with cluster primary OS. Please perform manual bootstrap on this host.")
def main(argv=None): # Same logic that was in "os_type_check.sh" if len(sys.argv) != 2: print "Usage: <cluster_os>" raise Exception("Error in number of arguments. Usage: <cluster_os>") pass cluster_os = sys.argv[1] current_os = OSCheck.get_os_family() + OSCheck.get_os_major_version() # If agent/server have the same {"family","main_version"} - then ok. print "Cluster primary/cluster OS family is %s and local/current OS family is %s" % ( cluster_os, current_os) if current_os == cluster_os: sys.exit(0) else: raise Exception( "Local OS is not compatible with cluster primary OS family. Please perform manual bootstrap on this host." )
def checkLiveServices(self, services, result): is_redhat7_or_higher = False is_redhat = False if OSCheck.is_redhat_family(): is_redhat = True if int(OSCheck.get_os_major_version()) >= 7: is_redhat7_or_higher = True for service in services: svcCheckResult = {} if "ntpd" in service and is_redhat7_or_higher: svcCheckResult['name'] = "chronyd" elif "chronyd" in service and is_redhat: svcCheckResult['name'] = "ntpd" else: svcCheckResult['name'] = " or ".join(service) svcCheckResult['status'] = "UNKNOWN" svcCheckResult['desc'] = "" try: out = "" err = "" for serviceName in service: sys_out, sys_err, code = self.getServiceStatus(serviceName) if code == 0: break out += sys_out if len(out) == 0 else os.linesep + sys_out err += sys_err if len(err) == 0 else os.linesep + sys_err if 0 != code: svcCheckResult['status'] = "Unhealthy" svcCheckResult['desc'] = out if len(out) == 0: svcCheckResult['desc'] = err else: svcCheckResult['status'] = "Healthy" except Exception, e: svcCheckResult['status'] = "Unhealthy" svcCheckResult['desc'] = repr(e) result.append(svcCheckResult)
webhcat_server_win_service_name = "templeton" else: hive_pid_dir = config['configurations']['hive-env']['hive_pid_dir'] hive_pid = 'hive-server.pid' hive_metastore_pid = 'hive.pid' hcat_pid_dir = config['configurations']['hive-env'][ 'hcat_pid_dir'] #hcat_pid_dir webhcat_pid_file = format('{hcat_pid_dir}/webhcat.pid') process_name = 'mysqld' if OSCheck.is_suse_family() or OSCheck.is_ubuntu_family(): daemon_name = 'mysql' else: if OSCheck.is_redhat_family() and OSCheck.get_os_major_version( ) == "7": daemon_name = 'mariadb' else: daemon_name = 'mysqld' # Security related/required params hostname = config['hostname'] security_enabled = config['configurations']['cluster-env'][ 'security_enabled'] kinit_path_local = get_kinit_path( default('/configurations/kerberos-env/executable_search_paths', None)) tmp_dir = Script.get_tmp_dir() hdfs_user = config['configurations']['hadoop-env']['hdfs_user'] hive_user = config['configurations']['hive-env']['hive_user'] webhcat_user = config['configurations']['hive-env']['webhcat_user']
config = Script.get_config() hive_pid_dir = config['configurations']['hive-env']['hive_pid_dir'] hive_pid = 'hive-server.pid' hive_metastore_pid = 'hive.pid' hcat_pid_dir = config['configurations']['hive-env'][ 'hcat_pid_dir'] #hcat_pid_dir webhcat_pid_file = format('{hcat_pid_dir}/webhcat.pid') process_name = 'mysqld' if OSCheck.is_suse_family() or OSCheck.is_ubuntu_family(): daemon_name = 'mysql' elif OSCheck.is_redhat_family() and int(OSCheck.get_os_major_version()) >= 7: daemon_name = 'mariadb' else: daemon_name = 'mysqld' # Security related/required params hostname = config['hostname'] security_enabled = config['configurations']['cluster-env']['security_enabled'] kinit_path_local = get_kinit_path( default('/configurations/kerberos-env/executable_search_paths', None)) tmp_dir = Script.get_tmp_dir() hdfs_user = config['configurations']['hadoop-env']['hdfs_user'] hive_user = config['configurations']['hive-env']['hive_user'] webhcat_user = config['configurations']['hive-env']['webhcat_user'] # default configuration directories
hive_pid = 'hive-server.pid' hive_interactive_pid = 'hive-interactive.pid' hive_metastore_pid = 'hive.pid' hcat_pid_dir = config['configurations']['hive-env'][ 'hcat_pid_dir'] #hcat_pid_dir webhcat_pid_file = format('{hcat_pid_dir}/webhcat.pid') mariadb_redhat_support = default( "/configurations/hive-env/mariadb_redhat_support", "false") mariadb_redhat_support = str(mariadb_redhat_support) Logger.info('MariaDB RedHat Support: %s' % mariadb_redhat_support) process_name = 'mysqld' if OSCheck.is_suse_family() or OSCheck.is_ubuntu_family(): daemon_name = 'mysql' elif OSCheck.is_redhat_family() and int(OSCheck.get_os_major_version( )) >= 7 and mariadb_redhat_support.lower() == "true": daemon_name = 'mariadb' else: daemon_name = 'mysqld' # Security related/required params hostname = config['hostname'] security_enabled = config['configurations']['cluster-env'][ 'security_enabled'] kinit_path_local = get_kinit_path( default('/configurations/kerberos-env/executable_search_paths', None)) tmp_dir = Script.get_tmp_dir() hdfs_user = config['configurations']['hadoop-env']['hdfs_user'] hive_user = config['configurations']['hive-env']['hive_user'] webhcat_user = config['configurations']['hive-env']['webhcat_user']