Example #1
0
 def validate_host_console_output(self, exp_string, wait_time=500):
     '''Procedure to verify the expected string on host console output during boot'''
     logger.info('Looking for the console output {}'.format(exp_string))
     try:
         out = self.host_conn_handle.read_until(exp_string, wait_time)
         logger.info('Host console output:')
         logger.info(out)
         found_string = False
         for line in out.splitlines():
             logger.info(line)
             if exp_string in line:
                 logger.info('Found expected string')
                 found_string = True
                 break
         if exp_string in out:
             found_string = True
         if found_string is True:
             logger.info(
                 'Successfully validated the expected string {} found \
                 in console output'.format(exp_string))
             return True
         else:
             logger.error(
                 'Failed to validate that expected string {} found \
                 in console output'.format(exp_string))
             return False
     except:
         dump_error_in_lib()
         logger.error(
             'Failed to validate console output with expected string {}'.
             format(exp_string))
         return False
 def copy_file_to_share(self, file_name, path_to_copy):
     '''
     copies the file to share path
     returns - True if successfull
     returns - False if unscessfull
     '''
     try:
         if not os.path.exists(path_to_copy):
             logger.info(
                 path_to_copy +
                 " Directory doesnt exists .Hence creating directory")
             os.makedirs(path_to_copy)
             os.chmod(path_to_copy, stat.S_IRWXO)
         copy_command = "cp -rf " + file_name + " " + path_to_copy
         copy_output = subprocess.check_output(copy_command,
                                               shell=True,
                                               stderr=subprocess.STDOUT)
         logger.info(str(copy_output))
         file_path = path_to_copy + file_name
         if os.path.exists(file_path):
             logger.info("Successfull copied the file to the path :" +
                         file_path)
             return True
         else:
             logger.error("Error in copying the file: " + file_name +
                          "to directory:" + path_to_copy)
             return False
     except:
         dump_error_in_lib()
         logger.error("Expection obtained in Copying the file" + file_name +
                      "to directory:" + path_to_copy)
         return False
Example #3
0
 def delete_vnic(self, slot_no, dev_name):
     '''
     Procedure to delete vnic interface
     Parameter:
         slot_no: slot number on interface device is created
         dev_name: name of device e.g: eth2
     Return:
         True  : Success
         False : Failure
     '''
     try:
         logger.info('Deleting the vnic interface')
         out = self.handle.execute_cmd_list('top',
                                            'scope chassis',
                                            'scope adapter ' + str(slot_no),
                                            wait_time=6)
         if 'Error: Managed object does not exist' in out:
             logger.error(
                 'vnic interface {} does not exists'.format(dev_name))
             return False
         self.handle.execute_cmd('delete  host-eth-if ' + dev_name,
                                 wait_time=12)
         out = self.handle.execute_cmd('commit', wait_time=10)
         if 'Deleted host-eth-if' in out:
             logger.info('Successfully deleted vnic interface ' + dev_name)
             return True
         else:
             logger.error('Failed to delete vnic interface ' + dev_name)
             return False
     except:
         dump_error_in_lib()
         return False
Example #4
0
 def start_tech_support(self):
     '''
     Procedure to start tech-support
     Parameter:
         handle: connection handle of cimc
     Return:
         True  : Success
         False : Failure
     '''
     try:
         self.handle.execute_cmd_list('top', 'scope cimc',
                                      'scope tech-support')
         out = self.handle.execute_cmd('start', wait_time=8)
         logger.info(out)
         if "Tech Support upload started" in out:
             logger.info(
                 'Tech Support Upload start command was issued successfully'
             )
             return True
         match = re.search(
             'invalid command detected|Already an upload is in \
                            progress|Hostname/IP Address|is not reachable',
             out, re.I)
         if match is not None:
             logger.error('Can not issue tech-support start command')
             return False
     except:
         dump_error_in_lib()
         return False
Example #5
0
    def get_cpu_info_host(self, host_handle, token=None):
        '''
            Collect proccesor information like threads and core from
            host

            Parameter :
                host handle
                token : passing this token will send
                        only the specific tokens(thread,cores)

            Return :
                Returns dictionary with host details
                if token parameter is none else it will
                return the token value : Success
                False : Failure
        '''
        try:
            cpu_info_host = {}
            out = host_handle.execute_cmd("cat /proc/cpuinfo", buffer_size=100000, wait_time=20)
            cpu_info_host['thread'] = len(re.findall(r'processor\s*\:\s*(\d+)', out))
            cpu_info_host['cores'] = re.search(r'cpu\s*cores\s*\:\s*(\d+)', out).group(1)
            if token is None:
                return cpu_info_host
            else:
                return cpu_info_host[token]
        except:
            dump_error_in_lib()
            return False
Example #6
0
 def start_and_wait_for_ts_to_finish(self):
     '''
     Wrapper procedure to start and wait for tech-support to complete
     Parameter:
         handle: connection handle of cimc
     Return:
         True  : Success
         False : Failure
     '''
     try:
         if self.start_tech_support() is False:
             logger.error('Tech-support start command failed')
             return False
         if self.has_techsupport_started() is False:
             logger.error(
                 'The tech-support status not started after start command was issued'
             )
             return False
         if self.wait_for_techsupport_to_finish() is False:
             logger.error(
                 "Tech support upload did not finish in max timeout seconds"
             )
             return False
         return True
     except:
         dump_error_in_lib()
         return False
Example #7
0
    def get_led_status(self, led="LED_HLTH_STATUS"):
        '''
        Procedure to get led state of server
        Parameter:
        led: Default - LED_HLTH_STATUS
             or
             Pass the appropriate led name to get the status
        Return:
            Led status: Success
            False : Failure

        Author: Suren kumar Moorthy
        '''
        logger.info('Getting the LED status')

        try:
            out = self.handle.execute_cmd_list(
                ['top', 'scope chassis', 'show led detail'], wait_time=10)
            logger.info(out)
            regex = r'name\:\s*' + led + \
                r'\s*state\s*\:\s*\w+\s*color\:\s*(\w+)'
            return re.search(regex, out).group(1)
        except:
            dump_error_in_lib()
            return False
Example #8
0
    def load_cpu_obj(self):
        '''
            To Load CPU object from config
            Return:
                Object populated with processor details : SUCCESS
                False : FAILURE

            Authhor : Suren Kumar Moorthy
        '''
        try:
            logger.info("Loading CPU object from Config")
            self.handle.execute_cmd_list("top", "scope chassis")
            out = self.handle.execute_cmd("show cpu detail")
            regex = r'(?:(?:Xeon\(R\)\s*CPU\s+([a-zA-Z0-9\s\-]+)(?:\s+)?\@)|(?:Xeon\(R\)\s*([a-zA-Z0-9\s\-]+)\s+CPU))'
            model_reg_out = re.search(regex, out)
            model = str(model_reg_out.group(2)) if model_reg_out.group(1) is None else str(model_reg_out.group(1))
            rep = re.compile(r'\s+$')
            model = rep.sub('', model)
            rep = re.compile(r'\s+')
            model = rep.sub('-', model)
            logger.info('Model selected: ' +model)
            con = ConfigParser()
            proccessor_config = con.load_processor_config(model).proceesor_details
            return proccessor_config
        except:
            dump_error_in_lib()
            return False
 def file_compare(self, file_path_1, file_path_2):
     '''
     Compares two files and returns True if there is no difference
     '''
     try:
         file1 = open(file_path_1, "r")
         file2 = open(file_path_2, 'r')
         file_diff = difflib.context_diff(file1.readlines(),
                                          file2.readlines())
         delta = ''.join(file_diff)
         if not delta:
             logger.info(
                 " There is not differece between the STD and Lstest data" +
                 str(delta))
             return True
         else:
             logger.error(
                 " There is difference between STD and latest data" +
                 str(delta))
             return False
     except:
         dump_error_in_lib()
         logger.info(
             " Exception obtained while comparing the STD and laetst config files"
         )
         return False
Example #10
0
 def has_techsupport_started(self):
     '''
     Procedure to check whether tech-support has started collecting data
     Parameter:
         handle: connection handle of cimc
     Return:
         True  : Success
         False : Failure
     '''
     try:
         self.handle.execute_cmd_list('top', 'scope cimc',
                                      'scope tech-support')
         out = self.handle.execute_cmd('show detail', wait_time=6)
         logger.info(out)
         out = re.search('remote-status: ([^\r\n]+)', out).group(1)
         if out == "COLLECTING":
             logger.info('The Update is in progress')
             return True
         elif out == "COMPLETED":
             logger.error(
                 'The tech-support status not started after start command was issued'
             )
             return False
     except:
         dump_error_in_lib()
         return False
Example #11
0
 def wait_for_techsupport_to_finish(self, wait_time=1200):
     '''
     Procedure to wait until tech-support is completed
     Parameter:
         handle: connection handle of cimc
         Optional Param:
             wait_time: Maximum time to wait for tech-support to complete
     Return:
         True  : Success
         False : Failure
     '''
     try:
         max_wait_time = time.time() + wait_time
         while time.time() < max_wait_time:
             out = self.get_techsupport_param_value('progress')
             if out == "100":
                 logger.info('Successfully uploaded tech-support data')
                 return True
             elif 'Remote_Upload_Error' in out:
                 logger.error('Upload error happened, will exit')
                 return False
             time.sleep(10)
             logger.info('Will continue to wait')
         logger.info('Exceeded max wait time ' + str(max_wait_time) +
                     ' seconds')
         return False
     except:
         dump_error_in_lib()
         return False
Example #12
0
    def reboot_bmc_and_connect(self, config):
        '''
        Procedure to reboot BMC and reconnects the BMC
        Parameter:
            None
        Return:
            True: Success
            False : Failure
        '''
        try:
            logger.info('Rebooting CIMC')
            self.handle.execute_cmd_list('top', 'scope cimc', 'reboot', 'y')
            mgmt_detail_obj = config.mgmtdetail
            bmc_ip = mgmt_detail_obj.bmc_mgmt_ip
            bmc_login = mgmt_detail_obj.bmc_login
            bmc_passwd = mgmt_detail_obj.bmc_password
            logger.info('Successfully rebooted BMC, Wait for BMC to come up')

            res = self.verify_host_up(bmc_ip, wait_time=500)
            if res is not True:
                logger.error('After BMC reboot, failed to ping BMC mgmt IP')
                return False
            else:
                logger.info(
                    'Successfully rebooted BMC, connecting back to BMC')

            self.handle = LinuxUtils(bmc_ip, bmc_login, bmc_passwd)
            self.handle.connect()

            return True
        except:
            dump_error_in_lib()
            return False
Example #13
0
    def get_common_token_value(self, token, scope, sub_scope=None):
        '''
        Procedure to get bios values by passing its token name
        Parameter:
        param: Default - None
                  or
               Pass the appropriate name of the token to get the value
               (Pass sub scope name to get token values inside sub scopes
                like advance,server-management,main,bios-profile,boot-device)

        Return:
            Token value: Success
            False : Failure

        Author: Suren kumar Moorthy
       '''
        logger.info('Getting bios token value')
        try:
            if sub_scope is None:
                out = self.handle.execute_cmd_list('top',
                                                   'scope ' + scope,
                                                   'show detail',
                                                   wait_time=8)
            else:
                out = self.handle.execute_cmd_list('top',
                                                   'scope ' + scope,
                                                   'scope ' + sub_scope,
                                                   'show detail',
                                                   wait_time=8)
            logger.info(out)
            regex = token + r'\s*\:\s+([^\r\n]+)'
            return re.search(regex, out).group(1)
        except:
            dump_error_in_lib()
            return False
Example #14
0
    def is_msr_bitSet(self, operand, mask_string, flag, bit_position):
        '''
        Bit Manipulator
        Procedure to masks the bits of the msr value per core to get
        the value of the required bit
        Parameter:
        param: operant - Corevalue from EFI
               mask_string - Mask value
               flag - "and" or "or"
               bit_position - bit position to check
        Return:
            Bit value: Success
            False : Failure

        Author: Suren kumar Moorthy
        '''
        try:
            per_core_value = int("0x" + operand, 16)
            mask_value = int("0x" + mask_string, 16)
            if flag == "and":
                res = per_core_value & mask_value
                if res > 0:
                    bit_array = list("{0:b}".format(res))
                    bit_array.reverse()
                    return bit_array[int(bit_position)]
                else:
                    return res
            elif flag == "or":
                return per_core_value | mask_value
            else:
                return False
        except:
            dump_error_in_lib()
            return False
Example #15
0
    def connect(self):
        '''
           Connects to the host with given credentials and saves the handle in
           the current object

        '''
        try:
            remote_conn_pre = paramiko.SSHClient()
            # Automatically add untrusted hosts (make sure okay for security
            # policy in your environment)
            remote_conn_pre.set_missing_host_key_policy(
                paramiko.AutoAddPolicy())
            # initiate SSH connection
            remote_conn_pre.connect(self.ip,
                                    username=self.username,
                                    password=self.password,
                                    look_for_keys=False,
                                    allow_agent=False)
            self.handle = remote_conn_pre.invoke_shell()
            self.handle.keepthis = remote_conn_pre
            logger.info("Successfully connected to the host with IP:" +
                        self.ip + " username:"******" password:"******"set cli output yaml")
            self.handle.settimeout(10)
        except:
            dump_error_in_lib()
            return False
Example #16
0
    def change_default_password(self):
        logger.info("Changing the default password")

        original_password = '******'
        mgmnt_password = '******'

        try:
            self.mgmnt_conn_handle.read_until(b'Enter current password: '******'Entering current password:'******'ascii') + b'\n')

            self.mgmnt_conn_handle.read_until(b'Enter new password: '******'Entering new password:'******'ascii') + b'\n')

            self.mgmnt_conn_handle.read_until(b'Re-enter new password: '******'Re-Entering new password:'******'ascii') + b'\n')

            self.mgmnt_conn_handle.read_until(b'Updating password...', 5)
            self.mgmnt_conn_handle.read_until(
                b'Password updated successfully.', 5)
            logger.info('Password Successfully Changed')

            return True

        except:
            dump_error_in_lib()
            return False
Example #17
0
    def get_cpu_info(self):
        '''
        Get Cpu info from CimcUtils
        Procedure loads the cpu info in processor object

        Return:
            Object populated with processor details : SUCCESS
            False : FAILURE

        Authhor : Suren Kumar Moorthy
        '''
        try:

            self.handle.execute_cmd_list("top", "scope chassis")
            out = self.handle.execute_cmd("show cpu detail")
            token_list = ["name", "manufacturer", "family", "thread-count", 'core-count',
                          "version", "current-speed", "signature", 'cpu-status']
            main_param_list = []
            out_list = out.split("---")
            for out_bloc in out_list[1:]:
                param_list = []
                for token in token_list:
                    regex = re.escape(token) + r'\s*\:\s+([^\r\n]+)'
                    value = re.search(regex, out_bloc).group(1)
                    param_list.append(value)
                    if token == 'version':                        
                        model_regex = r'(?:(?:Xeon\(R\)\s*CPU\s+([a-zA-Z0-9\s\-]+)\s+\@)|(?:Xeon\(R\)\s*([a-zA-Z0-9\s\-]+)\s+CPU))'
                        model_reg_out = re.search(model_regex, value)
                        model = str(model_reg_out.group(2)) if model_reg_out.group(1) is None else str(model_reg_out.group(1))                        
                        print('=========*****========****====')
                        print(model)
                        print('=========*****========****====')
                        rep1 = re.compile(r'\s$')
                        model = rep1.sub('', model)
                        rep2 = re.compile(r'\s+')
                        model = rep2.sub('-', model)
                param_list.append(model)
                main_param_list.append(param_list)
            self.handle.execute_cmd_list("top", "scope chassis")
            pid_out = self.handle.execute_cmd("show cpu-pid detail", wait_time=20)
            token_list_pid = ["Description", "PID"]
            pid_out_list = pid_out.split("---")
            i = 0
            for pid_out_bloc in pid_out_list[1:]:
                for token_pid in token_list_pid:
                    regex_pid = re.escape(token_pid) + r'\s*\:\s+([^\r\n]+)'
                    value_pid = re.search(regex_pid, pid_out_bloc).group(1)
                    main_param_list[i].append(value_pid)
                self.cpu_details.append(Processor(main_param_list[i][0], main_param_list[i][1],
                                                  main_param_list[i][2], main_param_list[i][3],
                                                  main_param_list[i][4], main_param_list[i][5],
                                                  main_param_list[i][6], main_param_list[i][7],
                                                  main_param_list[i][8], main_param_list[i][9],
                                                  main_param_list[i][10], main_param_list[i][11]))
                i += 1
            return self.cpu_details
        except:
            dump_error_in_lib()
            return False
Example #18
0
    def connect_to_mgmnt(self):
        try:
            logger.info('Console IP {} and Port {}'.format(
                self.ip, self.mgmnt_port))
            telnet_handle = telnetlib.Telnet(self.ip.encode('ascii'),
                                             self.mgmnt_port)
            telnet_handle.set_debuglevel(10)
            self.mgmnt_conn_handle = telnet_handle
            self.mgmnt_conn_handle.write(b'\n')
            self.mgmnt_conn_handle.write(b'\n')
            time.sleep(3)
            cur_mode = self.get_cimc_serial_mode()
            if cur_mode == None:
                # send cntr+C signal to return to sldp or help prompt
                self.mgmnt_conn_handle.write(b'\x03')
                self.connect_debug_shell_serial(connectShell='None',
                                                sldp_enabled='yes')
            elif cur_mode == 'responseKeyMode':
                self.connect_debug_shell_serial(connectShell='None')
            elif cur_mode == 'sldpMode' or cur_mode == 'helpMode':
                self.connect_debug_shell_serial(connectShell='None',
                                                sldp_enabled='yes')
            return self.mgmnt_conn_handle
        except:
            logger.warning('Entering exception block in: connect_to_mgmnt')

            dump_error_in_lib()

            tem_handle = self.connect_to_terminal_srvr()
            # Have to handle the server_Type here
            if self.server_type == None or 'cisco' in self.server_type:
                i = 0
                while i < 4:
                    tem_handle.write(b'clear line ' +
                                     str(self.mgmnt_port)[2:].encode('ascii') +
                                     b'\n')
                    tem_handle.read_until(b'[confirm]', 5).decode('ascii')
                    tem_handle.write(b'\n')
                    i += 1
                    time.sleep(3)
                    logger.info('in while with loop count' + str(i))

            try:
                telnet_handle = telnetlib.Telnet(self.ip.encode('ascii'),
                                                 self.mgmnt_port)
                telnet_handle.set_debuglevel(10)
                self.mgmnt_conn_handle = telnet_handle
                self.mgmnt_conn_handle.write(b'\n')
                self.mgmnt_conn_handle.write(b'\n')
                time.sleep(3)
                if self.get_cimc_serial_mode() == 'responseKeyMode':
                    self.connect_debug_shell_serial(connectShell='None',
                                                    sldp_enabled='yes')

                return self.mgmnt_conn_handle
            except:
                dump_error_in_lib()
                logger.error('Connection issue check terminal ')
                return None
Example #19
0
 def execute_cmd(self, cmd):
     result = None
     try:
         result = self.connection.run_cmd(cmd)
         logger.info("output of the execute command in windows is" + result.__str__())
     except: 
         dump_error_in_lib()
     return result.std_out
Example #20
0
 def verify_keys_values(self, smbios_dict, config_file_dict, verify_list=None):
     try:
         smbios_dict_efi = smbios_dict
         smbios_dict_file = config_file_dict
         result = 0
         for key in smbios_dict_file:
             logger.info("key..." + key)
             if verify_list is not None:
                 if key in verify_list:
                     logger.info("key= " + key + "found in the dynamic list")
                     logger.info(
                         "key=....." + key + "..value...=" + smbios_dict_file[key])
                     EFI_shell_value = smbios_dict_efi[
                         key].replace(" ", "").strip().lower()
                     Config_file_value = smbios_dict_file[
                         key].replace(" ", "").strip().lower()
                     out = re.match(
                         Config_file_value, EFI_shell_value, re.IGNORECASE)
                     if out is not None:
                         logger.info(
                             "Server obtained value for" + key + "...=" + smbios_dict_efi[key])
                         logger.info(
                             "SMBIOS CONFIG FILE  obtained value for" + key + "...=" + smbios_dict_file[key])
                         logger.info("Values matched")
                     else:
                         logger.error(
                             "server obtained value for " + key + "...=" + smbios_dict_efi[key])
                         logger.error(
                             " CONFIG FILE  obtained value for " + key + "...=" + smbios_dict_file[key])
                         logger.error(
                             "server obtained value and CONFIG File values mismatch")
                         result = 1
             else:
                 # logger.info("key=....."+key+"..value...="+smbios_dict_file[key])
                 EFI_shell_value = smbios_dict_efi[key].replace(
                     " ", "").strip().lower().replace(')', '').replace('(', '')
                 Config_file_value = smbios_dict_file[key].replace(
                     " ", "").strip().lower().replace(')', '').replace('(', '')
                 out = re.match(
                     Config_file_value, EFI_shell_value, re.IGNORECASE)
                 if out is not None:
                     logger.info(
                         "Server obtained value for" + key + "...=" + EFI_shell_value)
                     logger.info(
                         "SMBIOS CONFIG FILE  obtained value for" + key + "...=" + Config_file_value)
                     logger.info("Values matched")
                 else:
                     logger.error(
                         "server obtained value for " + key + "...=" + EFI_shell_value)
                     logger.error(
                         " CONFIG FILE  obtained value for " + key + "...=" + Config_file_value)
                     logger.error(
                         "server obtained value and CONFIG File values mismatch")
                     result = 1
         return result
     except:
         dump_error_in_lib()
         return 1
Example #21
0
 def __init__(self, ip_address=None, user_name=None, password=None):
     self.ip_addr = ip_address
     self.user = user_name
     self.password = password
     try:
         self.connection = winrm.Session(self.ip_addr,
                                         auth=(self.user, self.password))
     except: 
         dump_error_in_lib()
Example #22
0
 def power_cycle_host(self, wait_time=60):
     '''
     Procedure to power cycle the host
     Parameter:
         handle : connection handle of cimc
         waitForPingFail : If true, will wait for ping to fail and then back up
                     If False, will return True in case host is responding
         wait_time : Max time attempted to check host's availability
     Return:
         True  : Success
         False : Failure
     '''
     power_off = 0
     power_on = 0
     try:
         power_state = self.get_power_state()
         if power_state == 'off':
             logger.info('Host is already powered off, powering on')
             power_off = 1
             self.set_host_power('on')
         else:
             self.handle.execute_cmd_list('top',
                                          'scope chassis',
                                          'power cycle',
                                          wait_time=6)
             time.sleep(1)
             self.handle.execute_cmd('y')
         # have to add validation
         max_wait_time = time.time() + wait_time  # wait for 60 sec
         while True:
             power_state = self.get_power_state()
             if power_state == 'off':
                 logger.info('Host is powered off')
                 power_off = 1
             elif power_state == 'on':
                 logger.info('Host is powered on')
                 power_on = 1
             if power_on == 1 and power_off == 1:
                 break
             if time.time() > max_wait_time:
                 logger.info('Maximum timeout reached')
                 break
             else:
                 logger.info('Will continue to wait')
                 time.sleep(2)
         if power_off == 1 and power_on == 1:
             logger.info('Successfully power cycled the host')
             return True
         else:
             logger.info('Failed to power cycled the host')
             return False
     except:
         dump_error_in_lib()
         return False
Example #23
0
 def remove_vic_config(self):
     '''
     Procedure to remove the VIC exported file
     Returns:
         True: on success
         False: on failure
     '''
     try:
         logger.info('Deleting vic export config file: ' + self.export_path)
         self.tftp_handle.connect()
         self.tftp_handle.execute_cmd('rm -f ' + self.export_path)
         self.tftp_handle.disconnect()
     except:
         dump_error_in_lib()
Example #24
0
    def verify_msr_mode(self, mode, mask_id, bit, verify_bit, out=None):
        '''
            To verify the mode
            Parameter :
                mode : MSR value
                mask_id : Mask id for the msr value
                bit : which bit to check(Ex : 18 th bit)
                verify_bit : Bit to verify (1 or 0)
            Return:
                True or false

            Author : Suren Kumar Moorthy
        '''
        try:
            if out is None:
                host_serial_handle = self.bios_util_obj.cimc_obj.telnet_handle
                efi_out = self.boot_order_obj.boot_to_efi_shell()
                if efi_out is False:
                    return False
                msr_input = 'MSR ' + self.msr[mode]
                out = host_serial_handle.execute_cmd_serial_host(msr_input, wait_time=40)
                logger.info(out)
                host_serial_handle.disconnect()
                time.sleep(60)
            match = re.search(r'\d+\s+\d+\s+\d+\s+([0-9A-Z]{8})\s+([0-9A-Z]{8})', out)
            if match is None:
                logger.error('Unknown MSR Output')
                return False
            core = 1
            fail_flag = 0
            pattern = re.compile(r'\d+\s+\d+\s+\d+\s+([0-9A-Z]{8})\s+([0-9A-Z]{8})')
            for (data1, msr_bit) in re.findall(pattern, out):
                msr_val = data1 + msr_bit
                logger.info("Verify BIT value" + msr_val)
                bit_val = self.is_msr_bitSet(msr_val, mask_id, "and", bit)
                logger.info("Bit Value got is %s" % bit_val)
                logger.info("verify Value got is %s" % verify_bit)
                if int(bit_val) == int(verify_bit):
                    logger.info("Bit value for core " + str(core) + " passed")
                else:
                    fail_flag = 1
                core += 1
            if fail_flag == 1:
                return False
            else:
                return out
        except:
            dump_error_in_lib()
            return False
Example #25
0
    def restore_tokens_to_defaults(self, restore_type):
        '''
        Procedure to set bios tokens to default values
        Parameter:
            None
        Return:
            True  : Success
            False : Failure
        Author: jchanda
        '''
        try:
            logger.info('Performing bios restore operation: %s' %
                        (restore_type))
            self.handle.execute_cmd_list('top', 'scope bios')

            if restore_type == 'bios-setup-default':
                out = self.handle.execute_cmd('bios-setup-default')
            elif restore_type == 'clear-cmos':
                # Power off the system to run clear-cmos command
                self.cimc_obj.set_host_power('off')
                out = self.handle.execute_cmd_list('top', 'scope bios',
                                                   'clear-cmos')
            elif restore_type == 'restore-mfg-defaults':
                # Power off the system to run restore-mfg-defaults command
                self.cimc_obj.set_host_power('off')
                out = self.handle.execute_cmd_list('top', 'scope bios',
                                                   'restore-mfg-defaults')
            else:
                logger.warning('Invalid bios token restore option: %s' %
                               (restore_type))
                return False

            if 'Continue' in out:
                out = self.handle.execute_cmd('y')
                if re.search('Error', out):
                    logger.error(
                        'Failed to perform %s operation. Got Error Msg: %s ' %
                        (restore_type, out))
                    return False
                logger.info("Waiting for host to come up")
                res = self.cimc_obj.verify_host_up(hostname=self.host_ip,
                                                   wait_for_ping_fail=False)
                if res is False:
                    logger.warning('Failed to ping the host')
        except:
            dump_error_in_lib()
            return False
        logger.info('Successfully performed operation %s' % (restore_type))
        return True
Example #26
0
    def get_host_eth_int_details(self, adapter_slot):
        '''
        Get Host Ethernet interface Details
        Procedure to load the Ethernet intf detail in HostEthInt object

        Return:
            Object populated with host eth interface details : SUCCESS
            False : FAILURE

        Author : jchanda
        '''
        try:
            self.handle.execute_cmd_list('top', 'scope chassis',
                                         'scope adapter ' + adapter_slot)
            output = self.handle.execute_cmd('show host-eth-if detail',
                                             wait_time=15)
            attr_list = [
                'name', 'mtu', 'uplink', 'mac-addr', 'cos', 'trust-host-cos',
                'pci-link', 'order', 'vlan', 'rate-limit', 'boot',
                'iscsi-boot', 'usnic-count', 'channel-number', 'port-profile',
                'uplink-failover', 'uplink-failback-timeout', 'arfs', 'vmq',
                'nvgre', 'vxlan', 'CDN', 'rdma_qp', 'rdma_mr', 'rdma_resgrp'
            ]
            out_list = output.split("---")
            for out_block in out_list[1:]:
                intf_tmp_list = []
                for attr in attr_list:
                    value = re.search(attr + ': ([^\r\n.$]+)', out_block)
                    if value != None:
                        value = value.group(1)
                    intf_tmp_list.append(value)
                self.eth_int_details.append(
                    HostEthInt(
                        intf_tmp_list[0], intf_tmp_list[1], intf_tmp_list[2],
                        intf_tmp_list[3], intf_tmp_list[4], intf_tmp_list[5],
                        intf_tmp_list[6], intf_tmp_list[7], intf_tmp_list[8],
                        intf_tmp_list[9], intf_tmp_list[10], intf_tmp_list[11],
                        intf_tmp_list[12], intf_tmp_list[13],
                        intf_tmp_list[14], intf_tmp_list[15],
                        intf_tmp_list[16], intf_tmp_list[17],
                        intf_tmp_list[18], intf_tmp_list[19],
                        intf_tmp_list[20], intf_tmp_list[21],
                        intf_tmp_list[22], intf_tmp_list[23],
                        intf_tmp_list[24]))
            return self.eth_int_details
        except:
            dump_error_in_lib()
            return False
Example #27
0
 def create_dict_from_output(self, EFI_output):
     try:
         lines = EFI_output.split("\n")
         generate_dict_efi = {}
         smbios_dict_file = {}
         logger.info("..... Server Obtained EFI SMBIOS values......")
         for line in lines:
             if line.find(':') != -1:
                 key1 = line.split(':')[0].replace(' ', '').strip().lower()
                 value1 = line.split(':')[1].replace(' ', '').strip().lower()
                 logger.info(key1 + "....." + value1)
                 generate_dict_efi[key1] = value1
         return generate_dict_efi
     except:
         dump_error_in_lib()
         return False
Example #28
0
    def get_cimc_serial_mode(self):
        """
        Procedure to return current cimc serial mode

        Return Value: On Success it will returns either of one 'linuxMode' 'cliMode' 'debugMode'
                      None in case of failure
        """
        logger.info('Calling get_cimc_serial_mode method')
        try:
            time.sleep(1)
            out = self.execute_cmd_serial('\n')
            time.sleep(2)

            linux_prompt = ':~]$'
            cli_prompt1 = 'bmc#'
            cli_prompt2 = ' #'
            cli_prompt3 = '# '
            cli_prompt4 = '--More--'
            help_prompt = '[ help ]#'
            response_key_prompt = 'ResponseKey#>'
            mode = None
            change_passwd_prompt = 'Enter current password: '******'[ sldp ]#'

            if linux_prompt in out:
                mode = 'linuxMode'
            elif help_prompt in out:
                mode = 'helpMode'
            elif sldp_prompt in out:
                mode = 'sldpMode'
            elif response_key_prompt in out:
                mode = 'responseKeyMode'
            elif change_passwd_prompt in out:
                mode = 'changePasswdMode'
            elif cli_prompt1 in out or cli_prompt2 in out or \
                    cli_prompt3 in out or cli_prompt4 in out:
                mode = 'cliMode'
            else:
                mode = None
            logger.info('CIMC serial in: ' + str(mode))
            return mode

        except:
            logger.warning('Exception in def get_cimc_serial_mode')
            dump_error_in_lib()
Example #29
0
 def get_release_note_content(self, config):
     try:
         mgmt_detail_obj = config.mgmtdetail
         plat = mgmt_detail_obj.platform
         platform = self.get_platform_name(plat)
         build = os.environ["BUILD"]
         huu_image = os.environ["HUU_IMAGE"]
         if not build:
             logger.error("Build is not set in environment variable")
             return False
         if not huu_image:
             logger.error("HUU IMAGE is not set in environment variable")
             return False
         huu_iso_file = "/var/www/html/HUU_Sanity/systemupgrade/isos/" + \
             platform + "/" + build + "/" + huu_image
         logger.info("HUU FILe: " + huu_iso_file)
         host = LinuxUtils('10.127.45.20', 'root', 'HuuWelcome123')
         host.connect()
         if "No such file or directory" in host.execute_cmd("ls " +
                                                            huu_iso_file):
             logger.error("HUU file not found in filer")
             return False
         # Mouting ISO
         logger.info("Mouting ISO" + huu_iso_file)
         mount_folder = "/mnt/" + \
             re.search(r'(.*?)\.iso', huu_image).group(1)
         logger.info("Mount Foleder" + mount_folder)
         host.execute_cmd("mkdir " + mount_folder)
         # Check mount folder
         if "No such file or directory" in host.execute_cmd("ls " +
                                                            mount_folder):
             logger.error("mount folder is not found in filer")
             return False
         host.execute_cmd("mount -o loop " + huu_iso_file + " " +
                          mount_folder)
         if "No such file or directory" in host.execute_cmd("ls " +
                                                            mount_folder +
                                                            "/TOC*.xml"):
             logger.error("TOC file not found")
             return False
         toc_out = host.execute_cmd("cat " + mount_folder + "/TOC*.xml")
         host.disconnect()
         return toc_out
     except:
         dump_error_in_lib()
Example #30
0
 def reboot_bmc(self, handle):
     '''
     Procedure to get current power state of host
     Parameter:
         handle : connection handle of cimc
     Return:
         True: Success
         False : Failure
     '''
     logger.info('Rebooting CIMC')
     try:
         logger.info(handle.execute_cmd('scope cimc'))
         logger.info(handle.execute_cmd('reboot'))
         logger.info(handle.execute_cmd('y'))
         return True
     except:
         dump_error_in_lib()
         return False