def _is_ascs_installed(processes): """ Check if ASCS instance is installed """ msg_server = shell.find_pattern(r'msg_server, MessageServer,.*', processes.output) enserver_ensa1 = shell.find_pattern(r'enserver, EnqueueServer,.*', processes.output) enq_server_ensa2 = shell.find_pattern(r'enq_server, Enqueue Server 2,.*', processes.output) return bool(msg_server and (enserver_ensa1 or enq_server_ensa2))
def _get_ers_ensa_version(processes): """ Get ERS ENSA version """ if shell.find_pattern(r'enrepserver, EnqueueReplicator,.*', processes.output): return 1 elif shell.find_pattern(r'enq_replicator, Enqueue Replicator 2,.*', processes.output): return 2 raise ValueError('ERS not installed or found')
def _get_ascs_ensa_version(processes): """ Get ASCS ENSA version """ if shell.find_pattern(r'enserver, EnqueueServer,.*', processes.output): return 1 elif shell.find_pattern(r'enq_server, Enqueue Server 2,.*', processes.output): return 2 raise ValueError('ASCS not installed or found')
def _is_app_server_installed(processes): """ Check if an application server (PAS or AAS) instance is installed """ disp = shell.find_pattern(r'disp\+work, Dispatcher,.*', processes.output) igswd = shell.find_pattern(r'igswd_mt, IGS Watchdog,.*', processes.output) gwrd = shell.find_pattern(r'gwrd, Gateway,.*', processes.output) icman = shell.find_pattern(r'icman, ICM,.*', processes.output) return bool(disp and igswd and gwrd and icman)
def _is_ers_installed(processes): """ Check if ERS instance is installed """ enrepserver_ensa1 = shell.find_pattern( r'enrepserver, EnqueueReplicator,.*', processes.output) enq_replicator_ensa2 = shell.find_pattern( r'enq_replicator, Enqueue Replicator 2,.*', processes.output) return bool(enrepserver_ensa1 or enq_replicator_ensa2)
def _restart_ascs(cls, conf_file, ers_pass, ascs_pass, remote_host=None): """ Restart ascs from the ERS host. Args: conf_file (str): Path to the configuration file ascs_pass (str): ASCS instance password remote_host (str, optional): Remote host where the command will be executed """ # Get sid and instance number from configuration file sid = cls.get_attribute_from_file( conf_file, 'NW_readProfileDir.profileDir += +.*/(.*)/profile').group(1).lower() instance_number = cls.get_attribute_from_file( conf_file, 'nw_instance_ers.ersInstanceNumber += +(.*)').group(1) ers = cls(sid, instance_number, ers_pass, remote_host=remote_host) result = ers.get_system_instances(exception=False) ascs_data = shell.find_pattern( '(.*), (.*), (.*), (.*), (.*), MESSAGESERVER|ENQUE, GREEN', result.output) ascs_user = '******'.format(sid).lower() ascs_hostname = ascs_data.group(1) ascs_instance_number = ascs_data.group(2) ers.stop(host=ascs_hostname, inst=ascs_instance_number, user=ascs_user, password=ascs_pass) ers.start(host=ascs_hostname, inst=ascs_instance_number, user=ascs_user, password=ascs_pass)
def get_attribute_from_file(conf_file, attribute_pattern): """ Get attribute from file using a pattern """ with open(conf_file, 'r') as file_content: attribute_data = shell.find_pattern(attribute_pattern, file_content.read()) return attribute_data
def _is_ers_installed(processes): """ Check if ERS instance is installed """ msg_server = shell.find_pattern(r'enrepserver, EnqueueReplicator.*', processes.output) return bool(msg_server)
def get_version(self): """ Get SAP HANA version """ cmd = 'HDB version' result = self._run_hana_command(cmd) version_pattern = shell.find_pattern(r'\s+version:\s+(\d+.\d+.\d+).*', result.output) if version_pattern is None: raise HanaError('Version pattern not found in command output') return version_pattern.group(1)
def get_sr_state(self): """ Get system replication state for the current node. Note: The command reads the state from the configuration files and so the reported state may not match the actual state. Returns: str: String between PRIMARY, SECONDARY and DISABLED INFO: In previous versions this was done using an enum. enum usage was removed to avoid dependencies """ cmd = 'hdbnsutil -sr_state' result = self._run_hana_command(cmd) if shell.find_pattern('.*mode: primary.*', result.output) is not None: return 'PRIMARY' if shell.find_pattern('.*mode: ({})'.format('|'.join(self.SYNCMODES)), result.output) is not None: return 'SECONDARY' return 'DISABLED'
def _ascs_restart_needed(cls, installation_result): """ Check the ERS installation return code and output to see if the ASCS instance restart is needed Args: installation_result (shell.ProcessResult): ERS installation result Returns: True if ASCS restart is needed, False otherwise """ expected_msg = \ '<html><p>Error when stopping instance.</p><p>Cannot stop instance <i>(.*)'\ '</i> on host <i>(.*)</i>.</p><p>Stop the instance manually and choose <i>OK</i> to '\ 'continue.</html>' if installation_result.returncode == cls.UNSPECIFIED_ERROR: if shell.find_pattern(expected_msg, installation_result.output): return True return False
def test_find_pattern_fail(self): out = ("Output text\n" " line1 \n" "line2") result = shell.find_pattern('.*line3.*', out) self.assertIsNone(result)