Esempio n. 1
0
 def _initiate_python_log(self):
     python_logger.write('Dumping ENV:'+ '\n')
     for env in os.environ:
         python_logger.write(' '*8 +env + '= ' + os.environ[env] + '\n')
     python_logger.write('Start time: ' + TIMESTAMP + '\n')
     python_logger.write('Command line: ' + self.cmd_line+ '\n')
     python_logger.write('Test log dir: ' + LOG_DIR+ '\n')
     if re.search(r'Linux', platform.system(), re.I):
         python_logger.write('Route table:' + str(subprocess.Popen(['route'] + ['-n'], stdout=subprocess.PIPE).communicate()[0],encoding="utf8")+ '\n')
         python_logger.write('DNS setting:' + str(subprocess.Popen(['cat'] + ['/etc/resolv.conf'], stdout=subprocess.PIPE).communicate()[0],encoding="utf8")+ '\n')
     elif re.search(r'cygwin|mswin32', platform.system(), re.I):
         python_logger.write('Route table:' + str(subprocess.Popen(['/cygdrive/c/WINDOWS/system32/route'] + ['print'], stdout=subprocess.PIPE).communicate()[0],encoding="utf8")+ '\n')
         python_logger.write('DNS setting:' + str(subprocess.Popen(['/cygdrive/c/WINDOWS/system32/ipconfig'] + ['/all'], stdout=subprocess.PIPE).communicate()[0],encoding="utf8")+ '\n')
     if Params.sonicos_ver:
         sys.path.append(os.environ["PYTHON_COMMON_HOME"])
         from util.openstack import Openstack
         try:
             if Params.testbed and Params.openstack and int(Params.openstack) == 1:
                 ostack = Openstack(Params.testbed)
                 nodes = ostack.get_nodes()
                 python_logger.write('OpenStack Topology Definition: \n')
             for node in nodes:
                 python_logger.write(' '*4 + '{\n')
                 for node_key in node:
                     python_logger.write(' '*8 + node_key + '=> ' + str(node[node_key]) + '\n')
                 python_logger.write(' '*4 + '}\n\n')
         except Exception as e:
             logger.error(e.args)
Esempio n. 2
0
 def assert_equal(cls, actual_output, expected_output, msg):
     logger.info("actual output is:")
     logger.info(actual_output)
     logger.info("expected output is:")
     logger.info(expected_output)
     try:
         assert actual_output == expected_output, msg
     except AssertionError as e:
         logger.error(traceback.format_exc(), "error")
         raise e
Esempio n. 3
0
 def assert_equal_multiple_value(cls, actual_output, expected_output, msg):
     logger.info("actual output is : " + str(actual_output))
     logger.info("expected output is any from : ")
     logger.info(expected_output)
     try:
         assert any(expected_input == actual_output
                    for expected_input in expected_output), msg
     except AssertionError as e:
         logger.error(traceback.format_exc())
         raise e
Esempio n. 4
0
 def assert_not_regular(cls, actual_output, expected_output, msg):
     logger.info("actual output is:")
     logger.info(actual_output)
     logger.info("expected output is:")
     logger.info(expected_output)
     try:
         assert not re.search(r'' + expected_output + '', actual_output,
                              re.I), msg
     except AssertionError as e:
         logger.error(traceback.format_exc(), "error")
         raise e
Esempio n. 5
0
    def finish_mail(self, res_summary, exec_summary, logs, test_details):
        msg = MIMEMultipart('alternative')

        try:
            # generate subject line
            suite_name = exec_summary['Testsuite Display Name']
            test_bed = exec_summary['Test Bed']
            product = exec_summary['Product']
            scmlabel = exec_summary['Software Version']
            rgname = exec_summary['rgname']
            result = 'PASSED: ' + res_summary[0][
                'Pass'] + ', FAILED: ' + res_summary[0][
                    'Fail'] + ', SKIPPED: ' + res_summary[0]['Skip']
            if int(res_summary[0]['Fail']) > 0:
                color = 'PASSCODE:RED'
            elif int(res_summary[0]['Skip']) > 0:
                color = 'PASSCODE:YELLOW'
            else:
                color = 'PASSCODE:GREEN'

            subject = 'SonicTest: ' + rgname[
                rgname.find('['):rgname.find(']') +
                1] + suite_name + ': ' + test_bed + ' - Completed (' + color + ') for ' + product
            subject = subject + ': ' + result
            exec_summary.pop('rgname')

            msg['Subject'] = subject
            msg['From'] = self.from_user
            msg['To'] = self.to_users
            msg['Cc'] = self.cc_users
            full_html = TEST_COMPLETED_TEMPLATE.render(
                suite_name=suite_name,
                user=msg['To'],
                test_bed=test_bed,
                res_summary=res_summary,
                exec_summary=exec_summary,
                logs=logs,
                test_details=test_details)
            html_display = MIMEText(full_html.encode('utf-16'), 'html',
                                    'utf-16')
            msg.attach(html_display)
            send = smtplib.SMTP(self.mail_srv)
            # send.set_debuglevel(1)
            receiver = [self.to_users]
            if self.cc_users is not None:
                for i in self.cc_users.split(','):
                    receiver.append(i)
            send.sendmail(self.from_user, receiver, msg.as_string())
        except Exception as e:
            logger.error(e.args)
Esempio n. 6
0
 def get_dut_log(self):
     data = {
         'Name': 'DUT Console Logs',
         'Link': '',
         'Display': '',           
     }
     try:
         my_log = log(Params.resource, Params.product, Params.scmlabel, Params.testbed, Params.user)
         console_url = my_log.get_dut_console_log_link()
          
         data['Link'] = console_url[0]
         data['Display'] = console_url[0].split('/')[-1]
     except:
         logger.error("Unable to get DUT console info.")
     return data
Esempio n. 7
0
    def set_console_index(self, link):
        result = re.search(r'\/([\w-]+)$', link)
        console = result.group(1)

        try:
            response = requests.get(link)
            content = response.content.decode('ASCII')
            logfile = content.split('\n')

            self.logfile[console] = logfile
            self.index[console] = len(logfile)
        except:
            logger.error("ERROR: Unable to retrieve console logfile")
            return 1

        return self
Esempio n. 8
0
    def populate_console(self):
        testbed = self.testbed
        product = self.product
        product = re.sub(r'pro|nsa|octeon', '', product.lower())

        tbdefcsl = ''
        if self.openstack != '1':
            tbdefcsl = testbed.lower() + '-' + product

            tqtest_resource = self.resource
            tqtest_resources = tqtest_resource.split(',')
            for element in tqtest_resources:
                element = re.sub(r':\d+$', '', element)
                logger.info("RESOURCE ELEMENT: " + element)

                if re.match(r'^(SHA|CLUSTER)$', element):
                    console = tbdefcsl
                    tbdefcsl = console + '-pri'
                    self.consoles.append(tbdefcsl)
                    tbdefcsl = console + '-sec'
        elif not self.testbed in self.openstack_setup:
            try:
                xml = self.testbed + '.xml'
                xml_path = 'http://osservices-sj.eng.sonicwall.com/topologies/' + xml

                content = self.log_path + '/' + xml
                cmd = ['/bin/rm', '-Rf', content]
                retval = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]

                params = ['-P', self.log_path, xml_path]
                retval = subprocess.Popen(['wget'] + params, stdout=subprocess.PIPE).communicate()[0]

                doc = minidom.parse(content)
                rec = doc.getElementsByTagNameNS('*', 'topology')[0]
                console = rec.getElementsByTagName('node')[0]
                tbdefcsl = console.getElementsByTagName('topology-resource-name')[0].firstChild.data
            except:
                logger.error("Unable to retrieve xml file from osservices")
                return 1

        self.consoles.append(tbdefcsl)

        return self
Esempio n. 9
0
 def subTestTearDown(self, outcome, test_case_id, uuid):
     if outcome is not None:
         logger.error(test_case_id + ": FAILED")
         self.test_case_result = "FAILED"
     else:
         logger.info(test_case_id + ": PASSED")
         self.test_case_result = "PASSED"
     self.end_time = str(datetime.datetime.now().replace(microsecond=0))
     output_file = open(SUITE_RES_FILE_WITH_PATH, 'a', newline='')
     a = csv.writer(output_file, delimiter=',')
     a.writerow([
         test_case_id, self.test_case_result, self.start_time,
         self.end_time, uuid
     ])
     output_file.close()
     logger.info("########## SubTest Case: " + test_case_id + ' ' * 3 +
                 self.test_case_result + "  ##########" + '\n' * 3)
     python_logger.write('Exting Sub-Testcase: ' + test_case_id + ' at ' +
                         time.asctime(time.localtime(time.time())) +
                         ' ... Result: ' + self.test_case_result + '\n')
Esempio n. 10
0
    def create_dut_console_textfile(self, file_name):
        result = re.search(r'\/([\w-]+)\.\w+$', file_name)
        console = result.group(1)

        link = self.console_links[console]

        try:
            response = requests.get(link)
            content = response.content.decode('ASCII')
            logfile = content.split('\n')

            current_content = logfile[self.index[console]:]

            with open(file_name, "w", newline="") as file_handle:
                file_handle.writelines(current_content)
                file_handle.close()
        except:
            logger.error("Unable to write console textfile")
            return 1

        return 0
Esempio n. 11
0
    def copy_file_to_log_server(self, file_name):
        uploaddir = self.uploaddir
        dst = uploaddir
        src = file_name

        params = ['-avz']
        params.extend((src, dst))
        python_logger.write('Entering utils::log::copy_file_to_log_server...'+ '\n' )
        python_logger.write(''*4 + 'Rsyncing logs rsync: '+ ' '.join(['rsync'] + params)+ '\n')

        try:
            if not os.path.exists(dst):
                os.makedirs(dst)
            rsync_result_string = subprocess.Popen(['rsync'] + params, stdout=subprocess.PIPE).communicate()[0]

            #mtab_params = ['/etc/mtab']
            python_logger.flush()
        except:
            logger.error("Unable to rsync files or /logs nfs mount cannot be determined from /etc/mtab")
            return 1
        return uploaddir
Esempio n. 12
0
    def start_mail(self, start_summary, dut_log, user):
        msg = MIMEMultipart('alternative')
        try:
            suite_name = start_summary['Testsuite Display Name']
            test_bed = start_summary['Test Bed']
            product = start_summary['Product']
            scmlabel = start_summary['Software Version']
            rgname = start_summary['rgname']
            subject = 'SonicTest: ' + rgname[
                rgname.find('['):rgname.find(']') +
                1] + suite_name + ': ' + test_bed + '- Test Started on Test Bed ' + test_bed
            start_summary.pop('rgname')

            msg['Subject'] = subject
            msg['From'] = self.from_user
            msg['To'] = self.to_users
            msg['Cc'] = self.cc_users

            full_html = START_TEST_COMPLETED_TEMPLATE.render(
                suite_name=suite_name,
                test_bed=test_bed,
                user=user,
                start_summary=start_summary,
                dut_log=dut_log,
            )
            html_display = MIMEText(full_html.encode('iso-8859-1'), 'html',
                                    'iso-8859-1')
            msg.attach(html_display)
            send = smtplib.SMTP(self.mail_srv)
            # send.set_debuglevel(1)
            receiver = [self.to_users]
            if self.cc_users is not None:
                for i in self.cc_users.split(','):
                    receiver.append(i)
            send.sendmail(self.from_user, receiver, msg.as_string())
        except Exception as e:
            logger.info(e.args)
            logger.error('Fail to get ' + e.args)
Esempio n. 13
0
 def fail(cls, msg):
     logger.error(str(msg))
     raise AssertionError(msg)
Esempio n. 14
0
    def assert_raises(cls, methodToRun, expected_exception, msg):
        try:
            with Assertion.assertRaises(
                    cls, expected_exception=expected_exception) as cm:
                methodToRun()
        except Exception as e:
            logger.error("actual exception is:")
            logger.error(e)
            logger.error("expected exception is:")
            logger.error(expected_exception)
            logger.error(msg)
            logger.error(traceback.format_exc(), "error")
            raise e

        logger.info("actual exception is:")
        logger.info(cm.exception)
        logger.info("expected exception is:")
        logger.info(expected_exception)