def validate_config(value, lineno=None):
    """
    Check if the config file is yaml or not.

    - **parameters**, **types**, **return** and **return types**::

      :param value: config.yaml info from argfile
      :type value: string
      :param lineno: line no of the config.yaml info from argfile
      :type lineno: int
      :return: Returns errormsg
      :rtype: string

    """
    global errormsg
    if value != "None" and ".yaml" not in value:
        if lineno:
            msg = ("In Argfile at line number %s "
                   "config file is not yaml file." % lineno)
        else:
            msg = "Please provide '.YAML' file for -c option."
        notify.message(msg)
        errormsg = errormsg + "\n\n" + msg
    if not lineno:
        return errormsg
    def update_hitcount(self, obj, issue, att, namemap, log_msg):
        """
        Increments value of Hit count field and updates
            - **parameters**, **types**, **return** and **return types**::

                :param obj: Jiralib object
                :param issue: issue where HitCount field needs to be updated
                :param att: attachment to be added in the issue
                :param namemap: dictionary of customfields and its values in jira project
                :param log_msg: Message to be updated in the log
                :type obj: object
                :type issue: string
                :type att: string
                :type namemap: dictionary
                :type log_msg: string

        """
        logger.warn(log_msg)
        try:
            value = \
                issue.raw['fields'][namemap['HitCount']] + 1
            issue.update(fields={namemap['HitCount']: value})
            text = '\n\nHitCount increased to {}'.format(int(value)) + '\n'
            notify.message(text)

        except (KeyError, TypeError):
            logger.warn("\nHitCount field not found.")
        comment = "updated Hitcount and attached latest log"
        if not att is None:
            self.add_attachment_and_comment(obj, issue, att, comment)
示例#3
0
    def connectSwitch(self, host_ip, u_name, p_word, tc_name):
        """
        Connects to Linux host and checks for software existence

            - **parameters**, **types**, **return** and **return types**::

                :param host_ip: Linux host IP
                :param u_name: Linux host username
                :param p_word: Linux host Password
                :param softwares: List of software to be checked
                :type host_ip: string
                :type u_name: string
                :type p_word: string
                :type softwares: list
        """
        port = 22
        client = paramiko.SSHClient()
        try:
            client.load_system_host_keys()
            client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            logger.info('*** Connecting to Switch...')
            client.connect(host_ip, port, u_name, p_word)
            stdin, stdout, stderr = client.exec_command('version')
            client.close()
        except Exception:
            msg = "Unable to connect Switch..Hardware requirement failed" \
                  "Hence skipping test case {}".format(tc_name)
            logger.error(msg)
            notify.message(msg)
            raise Exception(msg)
示例#4
0
    def validate_hitachi_software(self, ip, u_name, pwd, model, serial_number,
                                  port, licenses, tcname):
        """
        Connects to Hitachi host and checks for License existence

        - **parameters**, **types**, **return** and **return types**::

            :param host_ip: Hitachi array IP
            :param u_name:  Hitachi array username
            :param p_word:  Hitachi array Password
            :param softwares: List of software to be checked
            :type host_ip: string
            :type u_name: string
            :type p_word: string
            :type softwares: List
            :return: Returns None
        """
        base_URL = "https://"+ip+":"+str(port)+"/ConfigurationManager"+\
                   "/v1/objects/storages/"
        try:
            logger.info('*** Connecting to Hitachi Array...')
            resp = requests.get(base_URL, auth=(u_name, pwd), verify=False)
            data = resp.json()
            for array in data['data']:
                if array['model'] == model and \
                   array['serialNumber'] == int(serial_number):
                    sdid = array['storageDeviceId']
                    logger.info('connection  to Hitachi successfull,'
                                'Hence starting test case execution.')
                    url = base_URL + sdid + '/' + 'licenses'
                    resp = requests.get(url, auth=(u_name, pwd), verify=False)
                    out = resp.json()
                    for dev in out['data']:
                        for pro in licenses:
                            if dev['programProductName'] == pro:
                                if dev['status'] == 'Installed':
                                    msg = "Required Software {} is installed".format(
                                        pro)
                                    logger.info(msg)
                                else:
                                    msg = (
                                        'Required software {} is {}.Hence Skipping the '
                                        'Test case {}...'.format(
                                            pro, dev['status'], tcname))
                                    raise Exception(msg)
                else:
                    msg = "Provided Hitachi model is not registered with "\
                          "rest server / Management server"
                    logger.error(msg)
                    raise Exception(msg)

        except Exception as err:
            notify.message(str(err))
            logger.error(err)
            raise Exception(err)
    def validate_error(self, msg, tc_name):
        """
            Validates error for not raising a defect incase of invalid user inputs"

            - **parameters**, **types**, **return** and **return types**::

                :param msg: error msg of failed test case from output xml file.
                :param tc_name: name of the failed testcase
                :type msg: string
                :type tc_name: string

        """
        msg1 = "hardware requirement failed"
        msg2 = "software requirement failed"
        msg3 = "dependency tests failed"
        msg4 = "hence skipping the test case"
        msg_lower = msg.lower()
        if "No keyword with name".lower() in msg_lower:
            log_msg = "Not raising defect for tc '%s' since it is an import error.\n" % tc_name
            logger.warn(log_msg)
            notify.message(log_msg)
            return False
        elif msg_lower in [
                'connectionerror:', 'max retries exceeded with url'
        ]:
            log_msg = "Not raising defect for tc %s since it is a connection error.\n" % tc_name
            logger.warn(log_msg)
            notify.message(log_msg)
            return False
        elif re.search(r"expected\s\d\sarguments, \sgot\s\d", msg):
            key_word = re.search(r"\'(.*)\'", msg).group(1)
            log_msg = "Not raising defect for tc '%s' since user did not \
                provide required arguments for keyword %s.\n" % (tc_name,
                                                                 key_word)
            logger.warn(log_msg)
            notify.message(log_msg)
            return False
        elif "Already_Exist" in msg:
            log_msg = "Not raising defect for tc '%s' since user tried to \
                create already existing configurarion.\n" % tc_name
            logger.warn(log_msg)
            notify.message(log_msg)
            return False
        elif "Invalid_Argument" in msg:
            log_msg = "Not raising defect for tc '%s' since user provided \
                invalid arguments.\n" % tc_name
            logger.warn(log_msg)
            notify.message(log_msg)
            return False
        elif (msg1 in msg_lower) or (msg2 in msg_lower) or \
            (msg3 in msg_lower) or (msg4 in msg_lower):
            return False
        return True
示例#6
0
    def connectWin(self, host_ip, u_name, p_word, softwares, tc_name):
        """
        Connects to Windows Host and checks for software existence

            - **parameters**, **types**, **return** and **return types**::

            :param host_ip: windows host ip
            :param u_name: windows host username
            :param p_word: windows host password
            :param softwares: list of softwares to be checked
            :type host_ip: string
            :type u_name: string
            :type p_word: string
            :type softwares: list
        """
        hostIP = "http://" + host_ip + ":5985/wsman"
        try:
            pro = Protocol(endpoint=hostIP,
                           transport='ntlm',
                           username=u_name,
                           password=p_word,
                           server_cert_validation='ignore')
            logger.info("\n***Connecting  to Windows Host...")
            shell_id = pro.open_shell()
            for software in softwares:
                logger.info("Checking for software {} in "\
                            "windows" .format(software))
                command_id = pro.run_command(
                    shell_id, self.getSoftwareCmd(software, "Windows"))
                std_out, std_err, status_code = pro.get_command_output(
                    shell_id, command_id)
                msg = "Software {} does not exist in the C drive.."\
                    "Hence Skipping"\
                      "the test case {}..." .format(software, tc_name)
                if std_out == "":
                    notify.message(msg)
                    raise Exception(msg)
                msg = 'Found software on host %s at ' % host_ip + std_out
                logger.info(msg)
                pro.cleanup_command(shell_id, command_id)
            pro.close_shell(shell_id)
        except Exception as e:
            text = "Requirements pre check failed.. "\
                "Hence Skipping the test case "\
               "{} ..." .format(tc_name)
            logger.error(text)
            notify.message(text)
            raise Exception(text)
 def parse(self, suit_name, tc_name, kw_name, msg, att, raise_bugs):
     """
     Parse output xml file generated by SUTAS framework
     """
     msg = msg.replace('\n', ' ')
     summ = tc_name + " failed with error " + msg
     summ = summ[0:250]
     desc = "Test suite name: %s \nTest case name"\
                 ": %s \nTest case failed while "\
                    "executing Keyword: %s \n Error msg"\
                    ": %s \n Please check attached log "\
                    "file for more informantion."\
                    % (suit_name, tc_name, kw_name, msg)
     if raise_bugs.lower() == 'yes':
         obj = Jiralib(self.url, self.username, self.password)
         issue = self.validate_duplicate_issue(msg, obj, att, tc_name)
         new_issue = issue
         if issue != True:
             issue = False
         if self.validate_error(msg, tc_name) and issue:
             try:
                 component, label = obj.get_fields_from_subtasks(\
                     self.project, tc_name, self.tsid)
                 new_issue = obj.raise_issue(self.project, self.affects_version, \
                                             self.env, summ, desc, self.watcher, \
                                             component, label, attachments=att)
                 text = str(new_issue.key) + \
                 "created for the test case " + tc_name
                 notify.message(text)
                 return new_issue
             except:
                 new_issue = obj.raise_issue(\
                     self.project, self.affects_version, \
                     self.env, summ, desc, self.watcher, attachments=att)
                 text = str(new_issue.key) + \
                 "created for the test case " + tc_name
                 notify.message(text)
                 return new_issue
         else:
             if not isinstance(new_issue, jira.resources.Issue):
                 new_issue = None
         return new_issue
示例#8
0
    def connectLinux(self, host_ip, u_name, p_word, softwares, tcname):
        """
        Connects to Linux host and checks for software existence

        - **parameters**, **types**, **return** and **return types**::

            :param host_ip: Linux host IP
            :param u_name: Linux host username
            :param p_word: Linux host Password
            :param softwares: List of software to be checked
            :type host_ip: string
            :type u_name: string
            :type p_word: string
            :type softwares: list

        """
        try:
            logger.info('*** Connecting to linux box...')
            conn = SSH(host_ip, u_name, p_word)
            conn.connect()
        except Exception:
            text = 'Unable to connect Linux Host...'\
                      'Hardware requirement failed.'\
                      'Hence Skipping the Test case {}...' .format(tcname)
            logger.error(text)
            notify.message(text)
            raise Exception(text)
        try:
            for software in softwares:
                logger.info('Checking for software {} ...'.format(software))
                returncode, stdout, stderr = conn.command_exec(
                    self.getSoftwareCmd(software, "Linux"))
                if not stdout:
                    msg = "Software {} does not exist. " \
                      "Hence Skipping the test case {}..." .format(software,
                                                                   tcname)
                    notify.message(msg)
                    raise Exception(msg)
                msg = 'Found software on host %s at ' % host_ip + stdout
                logger.info(msg)

        except Exception:
            text = '{} not found on Linux Host...'\
                  'software requirement failed.'\
                  'Hence Skipping the Test case {}...' .format(software, tcname)
            logger.error(text)
            notify.message(text)
            raise Exception(text)
        conn.close()
def validate_duration(value, lineno=None):
    """
    Check if the duration value is provided in correct format.

    - **parameters**, **types**, **return** and **return types**::

      :param value: duration value from argfile
      :type value: string
      :param lineno: line no of the duration value from argfile
      :type lineno: int
      :return: Returns errormsg
      :rtype: string

    """
    global errormsg
    if value != "None" and "c" not in value.lower() and "m" not in value.lower(
    ):
        if lineno:
            msg = ("In Argfile at line number %s "
                   "duration must be mentioned in Cycles or "
                   "Minutes i.e 5C or 5M" % lineno)
        else:
            msg = "duration must be mentioned in Cycles or Minutes i.e 5C or 5M"
        notify.message(msg)
        errormsg = errormsg + "\n\n" + msg
    num = value[:-1]
    if not num.isdigit():
        if lineno:
            msg = ("In Argfile at line %s provided duration is not in "
                   "correct format. it has to be like 5C or 12M" % lineno)
        else:
            msg = ("provided duration is not in correct format. "
                   "It has to be like 5C or 12M")
        notify.message(msg)
        errormsg = errormsg + "\n\n" + msg
        if not lineno:
            return errormsg
        else:
            return
    num = int(num)
    if "c" in value.lower():
        if num <= 0:
            if lineno:
                msg = ("In Argfile at line %s "
                       "Number of cycles cannot be 0 or less than 0." % lineno)
            else:
                msg = "Number of cycles cannot be 0 or less than 0"
            notify.message(msg)
            errormsg = errormsg + "\n\n" + msg
        if num > 500:
            if lineno:
                msg = ("In Argfile at line %s "
                       "Number of cycles cannot be more than 500" % lineno)
            else:
                msg = "Number of cycles cannot be more than 500"
            notify.message(msg)
            errormsg = errormsg + "\n\n" + msg
    else:
        if num <= 0:
            if lineno:
                msg = ("In Argfile at line %s "
                       "Number of minutes cannot be 0 or less than 0." %
                       lineno)
            else:
                msg = "Number of minutes cannot be 0 or less than 0."
            notify.message(msg)
            errormsg = errormsg + "\n\n" + msg
        if num > 10080:
            if lineno:
                msg = ("In Argfile at line %s "
                       "Number of minutes cannot be more than a week." %
                       lineno)
            else:
                msg = ("Number of minutes cannot be more than a week.")
            notify.message(msg)
            errormsg = errormsg + "\n\n" + msg
    if not lineno:
        return errormsg
示例#10
0
def validateandparseargfile(testsfile):
    """
    Check if data in argfile is in correct format.

    - **parameters**, **types**, **return** and **return types**::

      :param testsfile: path of argfile
      :type testsfile: string
      :return: Returns errormsg and list of sutas commands
      :rtype: tuple

    """
    global errormsg
    os.environ['argfile'] = testsfile
    try:
        with open(testsfile, "r") as argfile:
            tests = argfile.read().strip().splitlines()
    except IOError:
        if not '.txt' in testsfile:
            msg = ("Provide the file {} with .txt extension or "
                   "checkwhether the file exists or not".format(testsfile))
        else:
            msg = "Check whether the file exists or not."
        raise Exception(msg)
    argv = []
    cmd = None
    for line in tests:
        lineno = tests.index(line) + 1
        line = line.split('\t')
        line = [word for word in line if word != '']
        if len(line) != 5:
            msg = (
                "In Arg file at line %s "
                "extra argument is provided."
                "It must be in below format.\n"
                "Each line must contain <robot file path> "
                "<config.yaml file> <Jira testid>   <Duration>    <testtype>\n"
                "ts1.robot    ts1.yaml    TM-121    5C     MPTC\n"
                "ts2.robot    ts2.yaml    None      60M    Regression\n"
                "ts3.robot    None        None      None   None\n"
                "ts4.robot    ts4.yaml    TM-124    None   None\n"
                "config file, jira id, duration and testtype are optional "
                "i.e you have to replace it with None if not used.\nAll must be seperated with tab space"
                % lineno)
            notify.message(msg)
            errormsg = errormsg + "\n\n" + msg
            raise Exception(errormsg)
        if line[1] != 'None':
            validate_config(line[1], lineno)
        if line[3] != 'None':
            validate_duration(line[3], lineno)
        if len(line) == 5:
            if line[3] != 'None' and "-p" in sys.argv:
                if sys.argv[sys.argv.index("-p") + 1].lower() == "true":
                    msg = ("SUTAS cannot run tests in parallel when duration "
                           "is mentioned in argfile")
                    notify.message(msg)
                    errormsg = errormsg + "\n\n" + msg
                    break
            cmd = [
                sys.argv[0],
                "execute",
            ]
            if not line[0]:
                msg = ("Argfile doesn't contain testsuite "
                       "in one of the lines.")
                notify.message(msg)
                errormsg = errormsg + "\n\n" + msg
            else:
                cmd.extend(["-s", line[0]])
            if line[1] != 'None':
                cmd.extend(["-c", line[1]])
            if line[2] != 'None':
                cmd.extend(["-j", line[2]])
            if line[3] != 'None':
                cmd.extend(["-d", line[3]])
            if line[4].lower() == 'none':
                raise Exception(
                    "TestBuildType must be specified in the argfile for the line {}"
                    .format(line))
            if line[4] != 'None':
                line[4] = line[4].replace('"', '')
                line[4] = line[4].replace("'", '')
                TBTypes = fetch_data_from_testenvdata('TestBuildTypes')
                try:
                    if line[4] not in TBTypes:
                        raise TestBuildTypeException
                except TestBuildTypeException as err:
                    mailobj = EmailNotification().emailobj()
                    body = "TestBuildType must be specified from one of the following {}".format(
                        TBTypes)
                    mailobj.send_mail_when_failed(body)
                    print(TestBuildTypeException(body))
                    sys.exit(1)
                cmd.extend(["-l", line[4]])
        argv.append(cmd)
    return (errormsg, argv)
    def validate_duplicate_issue(self, msg, obj, att, tc_name):
        """
            Find Duplicate issues based on Summaries comparison with error msg

                - **parameters**, **types**, **return** and **return types**::

                    :param msg: error msg of failed test case from the output xml file
                    :param obj: jira connection object
                    :param att: log file to be attached for the duplicate issue
        """

        summaries, issue_keys, issues = obj.get_summary(self.project)
        msg = msg.split()

        match = 0
        allfields = obj.conn.fields()
        namemap = {field['name']: field['id'] for field in allfields}

        def addwatchersforduplicateissue(obj, watcher):
            if watcher:
                users = self.watcher.split(",")
                for user in users:
                    try:
                        obj.conn.add_watcher(issue, user)
                    except Exception as err:
                        msg = '{} cannot be added as watcher'.format(user)
                        logger.warn(msg)

        for index, jira_msg in enumerate(summaries):
            no_match = []
            jira_msg = jira_msg.encode('utf-8').split()
            if len(jira_msg) == len(msg):
                for j in range(len(msg)):
                    if msg[j] != jira_msg[j]:
                        no_match.append([msg[j], jira_msg[j]])
                if len(no_match) == 0:
                    match += 1
                    issue_status = issues[index].fields.status.name.lower()
                    completed_statuses = [
                        "done", "resolved", "completed", "qa-done",
                        "merge-done", "passed", "merge-ready", "closed",
                        "testing", "in review", "blocked"
                    ]
                    if issue_status not in completed_statuses:
                        issue = issues[index]
                        issue_status = issue.fields.status.name
                        Hitcount = issue.raw['fields'][namemap['HitCount']]
                        Hitcount = int(Hitcount) + 1
                        log_msg = "\n\nSimilar issue already exists with "\
                                  "id {} with status {} and error msg is "\
                                  "{}. So, Updating the Hit count to {}"\
                                  ".\n".format(issue_keys[index], issue_status, " ".join(msg), Hitcount)
                        issue = issues[index]
                        notify.message(log_msg)
                        self.update_hitcount(obj, issue, att, namemap, log_msg)
                        addwatchersforduplicateissue(obj, self.watcher)

                    else:
                        try:
                            issue = issues[index]
                            fixed_versions = issues[index].raw['fields'][
                                namemap['Fix Version/s']]
                            version = fixed_versions[0]
                            fix_version = version["name"]
                            if fix_version <= self.affects_version:
                                self.reopen_issue(obj, issue,
                                                  issue_keys[index], att)
                                log_msg = "\n\nreopening the issue {} for the {}\n".format(
                                    issue_keys[index], tc_name)
                                self.update_hitcount(obj, issue, att, namemap,
                                                     log_msg)
                                notify.message(log_msg)
                            else:
                                Hitcount = issue.raw['fields'][
                                    namemap['HitCount']]
                                Hitcount = int(Hitcount) + 1
                                log_msg = "\n\nSimilar issue already exists with "\
                                    " id {} with status {} and "\
                                    "your msg is "\
                                    "{}. So, Updating the Hit count to {}"\
                                    ".\n".format(issue_keys[index], issue_status, " ".join(msg), Hitcount)
                                notify.message(log_msg)
                                self.update_hitcount(obj, issue, att, namemap,
                                                     log_msg)
                                addwatchersforduplicateissue(obj, self.watcher)
                        except KeyError:
                            logger.warn(
                                "Fix version is Unknown in the defect\n")
                            issue = issues[index]
                        except IndexError:
                            logger.info('Fix version is None.')
                            issue = issues[index]
                            self.reopen_issue(obj, issue, issue_keys[index],
                                              att)
                            text = "\n\nreopening the issue {} for the {}\n".format(
                                issue_keys[index], tc_name)
                            logger.warn(text)
                            notify.message(text)

                    break
        if match:
            return issue
        else:
            return True
示例#12
0
    def get_rqmt(self, kwargs):
        """
        Get the requirements dictionary from each test case

        - **parameters**, **types**, **return** and **return types**::

            :param kwargs: Dictionary with devices as keys and softwares as values
            :type kwargs: Dict
        """
        self.tcname = BuiltIn().get_variable_value("${TEST NAME}")
        msg = ("\n\nValidating Software/Hardware requirements (%s) for "
               "test case %s\n " % (kwargs, self.tcname))
        logger.info(msg)
        notify.message(msg)
        sw_dict = kwargs
        configfile = os.environ['Configfile']
        data = get_data_from_yaml(configfile)
        for device in sw_dict:
            try:
                softwares = sw_dict[device].split(",")
                check = [
                    True for i in
                    ["RHEL".lower(), "Windows".lower(), "Switch".lower()]
                    if i in device.lower()
                ]
                if check:
                    device_ip = data[str(device)]['ip']
                    device_user = data[str(device)]['username']
                    device_pswd = data[str(device)]['password']
                    if device_ip and device_user and device_pswd:
                        if device.startswith("RHEL"):
                            self.connectLinux(device_ip, device_user,
                                              device_pswd, softwares,
                                              self.tcname)
                        elif device.startswith("Windows"):
                            self.connectWin(device_ip, device_user,
                                            device_pswd, softwares,
                                            self.tcname)
                        elif device.startswith("Switch"):
                            self.connectSwitch(device_ip, device_user,
                                               device_pswd, self.tcname)
                elif device.lower().startswith("hitachi"):
                    ip = data[device]['rest_ip']
                    u_name = data[device]['rest_username']
                    pwd = data[device]['rest_password']
                    model = data[device]['model']
                    serial_number = data[device]['serial_number']
                    port = data[device]['rest_port']
                    self.validate_hitachi_software(ip, u_name, pwd, model,
                                                   serial_number, port,
                                                   softwares, self.tcname)
                elif device.lower().startswith("netapp"):
                    ip = data[device]['rest_ip']
                    u_name = data[device]['rest_username']
                    pwd = data[device]['rest_password']
                    netapp_ip = data[device]['netapp_ip']
                    netapp_username = data[device]['netapp_username']
                    netapp_password = data[device]['netapp_password']
                    array_name = data[device]['array_name']
                    self.validate_netapp_software(ip, u_name, pwd, netapp_ip,
                                                  netapp_username,
                                                  netapp_password, array_name,
                                                  softwares, self.tcname)
            except KeyError as e:
                text = "Device {}, connection info missing in config file" \
                    "so, software cannot be checked for this device." \
                       "Hence skipping the Test case {} " .format(device,
                                                                  self.tcname)
                logger.error(text)
                notify.message(text)
                raise Exception(e)
            except Exception as e:
                logger.error(str(e))
                notify.message(str(e))
                raise Exception(e)
示例#13
0
    def validate_netapp_software(self, url, u_name, pwd, netapp_ip,
                                 netapp_username, netapp_password, array_name,
                                 licenses, tcname):
        """
        Connects to Netapp host and checks for License existence

        - **parameters**, **types**, **return** and **return types**::

            :param host_ip: Netapp array IP
            :param u_name:  Netapp array username
            :param p_word:  Netapp array Password
            :param  softwares: List of software to be checked
            :type host_ip: string
            :type u_name: string
            :type p_word: string
            :type softwares: list

            TODO: license check is pending because of rest api unavailability.
        """
        try:
            burl = url + '/api/1.0/admin/storage-systems'
            logger.info('*** Connecting to Netapp Rest Server...')
            resp = requests.get(burl, auth=(u_name, pwd), verify=False)
            data = resp.json()
            if 'result' in data:
                if 'records' in data['result']:
                    for record in data['result']['records']:
                        if record['name']==array_name and \
                            record['ipv4_address']==netapp_ip:
                            logger.info(array_name + " is available "
                                        "in Netapp OCSM")

                            break
                        else:
                            msg = "Netapp is not registered "\
                                "with provided rest server Management server"
                            logger.error(msg)
                            raise Exception(msg)
        except Exception:
            msg = "Unable to connect Netapp... Hardware requirement failed."\
                "Hence Skipping the Test case {}..." .format(tcname)
            notify.message(msg)
            logger.error(msg, console=False)
            raise Exception(msg)
        try:
            logger.info('*** Connecting to Netapp Array...')
            conn = SSH(netapp_ip, netapp_username, netapp_password)
            conn.connect()
        except Exception:
            logger.error(
                'Unable to ssh. Check the connectivity, ip and credentials.')
            raise Exception(
                'Unable to Connect to FAS.Hardware Validation Failed.Hence Skipping the Test case {}...'
            )
        returncode, stdout, stderr = conn.command_exec('system license show')
        logger.info(stdout)
        if returncode:
            logger.error(stdout)
            raise Exception(stdout)
        for licen in licenses:
            lic_found = re.search(licen, stdout, re.IGNORECASE)
            if lic_found is not None:
                msg = '%s license is available' % licen
                logger.info(msg)
            else:
                msg = '{} licence is not available,Software validation failed.Hence Skipping the Test case {}...'.format(
                    licen, tcname)
                logger.error(msg)
                raise Exception(msg)
        conn.close()
 def chk_stats(outputfile):
     """
     Check Test statistics in the file output xml file
     Returns True if atleast 1 Test case in a Test Suite fails
     Parses the xml file and get error messages for each failed test case
     Form the summary and description with error messages.
     """
     out_file = os.path.join(outputfile, 'output.xml')
     if not os.path.isfile(out_file):
         raise Exception(
             "Log file output.xml not generated since no tests are executed"
         )
     tree = ET.ElementTree(file=out_file)
     root = tree.getroot()
     skipped = 0
     message = None
     msg1 = "hardware requirement failed"
     msg2 = "software requirement failed"
     msg3 = "dependency tests failed"
     msg4 = "hence skipping the test case"
     for test in root.iter("test"):
         for kw in test.iter("kw"):
             keyword = kw.attrib.get("library")
             if keyword:
                 keyword = keyword.lower()
             if not keyword == "teardown":
                 message = None
                 for msg in kw.iter("msg"):
                     if msg.attrib["level"] == "ERROR":
                         message = (msg.text).lower()
                         if (msg1 in message) or (msg2 in message) or \
                                                 (msg3 in message) or (msg4 in message):
                             skipped = skipped + 1
                         break
                 if not message:
                     for msg in kw.iter("msg"):
                         if msg.attrib["level"] == "FAIL":
                             message = (msg.text).lower()
                             if (msg1 in message) or \
                                 (msg2 in message) or (msg3 in message) or (msg4 in message):
                                 skipped = skipped + 1
                             break
     stats = root.find('statistics')
     if stats:
         childs = stats.find('suite').getchildren()
         for child in childs:
             if child.tag == 'stat':
                 items = list(child.items())
                 passed = int(child.attrib['pass'])
                 failed = int(child.attrib['fail']) - skipped
                 text = str(passed) + " Pass, " + str(
                     skipped) + " Skip, " + str(failed) + " Fail\n"
                 os.environ['suiteresult'] = "{},{},{}".format(
                     passed, skipped, failed)
                 pad = '*' * len(text) + '\n'
                 text = pad + text + pad
                 notify.message(text)
                 for item in items:
                     if item[0] == 'fail' and item[1] != '0':
                         return True
     return False
示例#15
0
    def get_test_case_tags(conn, ts_id, testtype, rerun=None, type='failed'):
        """
        param: conn: jira connection object
        param: ts_id: test suite id
        """
        globfilepath = os.path.join(os.path.expanduser('~'),
                                    "global_conf.yaml")
        globdata = get_data_from_yaml(globfilepath)
        enable_test_mgt = True
        if 'EnableTestManagement' not in globdata or globdata.get(
                'EnableTestManagement', 'no').lower() == "no":
            enable_test_mgt = False
        # fetching test cases from given master test suite.
        if ',' in ts_id:
            test_cases = []
            ts_id = ts_id.split(',')
            for parent in ts_id:
                cases = conn.search_issues('parent=' + parent,
                                           startAt=0,
                                           maxResults=100)
                cases_b = conn.search_issues('parent=' + parent,
                                             startAt=100,
                                             maxResults=100)
                cases.extend(cases_b)
                test_cases.extend(cases)
        else:
            test_cases = []
            test_cases = conn.search_issues('parent=' + ts_id,
                                            startAt=0,
                                            maxResults=100)
            test_cases_b = conn.search_issues('parent=' + ts_id,
                                              startAt=100,
                                              maxResults=100)
            test_cases.extend(test_cases_b)
        if not test_cases:
            raise Exception(
                "No Testcases found to clone for the given Suite {}".format(
                    ts_id))
        fieldmap = {field['name']: field['id'] for field in conn.fields()}
        os.environ.__dict__['fieldmap'] = {}
        os.environ.__dict__['fieldmap'].update(fieldmap)
        #sutas_id and Automated are customfields added fro sutas framework, \
        # so we don't get these fields dirctly with issue object.
        sutas_id_field = fieldmap['sutas_id']
        try:
            auto_field = fieldmap['Automated?']
        except KeyError:
            auto_field = fieldmap['Automated']
        not_planned = '\n Below mentioned test cases are  in "not planned"' \
            'state hence not running them.\n'
        not_automated = "\n Below mentioned test cases has Automated field" \
            "as 'No' hence not running them.\n"
        np_summ = []
        na_summ = []
        np_id = []
        na_id = []
        tc_list = []
        tc_data = {}
        to_be_cloned_test_cases = []
        np_slack_str = ''
        na_slack_str = ''
        #checking wheather automated and sutas_id fields are existed or not
        if auto_field and sutas_id_field:
            # if test case marked as not planed or it is not automatable, those kind \
            # of test cases will be ignored
            for test_case in test_cases:
                if test_case.fields().status.name.lower() == 'not planned':
                    np_summ.append(test_case.fields().summary.encode('utf-8'))
                    np_id.append(test_case.key)
                elif test_case.raw['fields'][auto_field] == None:
                    na_summ.append(test_case.fields().summary.encode('utf-8'))
                    na_id.append(test_case.key)
                elif test_case.fields().status.name.lower() != 'not planned' and \
                     test_case.raw['fields'][auto_field][0]['value'].lower() == 'yes':
                    if test_case.raw['fields'][sutas_id_field]:
                        tc_list.append(test_case.raw['fields'][sutas_id_field])
                        to_be_cloned_test_cases.append(test_case)
                #sending not planned and not aumatable testcase list as notification through slack
                np_slack_str = TestManagement._format_slack_str(
                    test_case, np_summ, np_id)
                na_slack_str = TestManagement._format_slack_str(
                    test_case, na_summ, na_id)
            if np_slack_str:
                notify.message(not_planned)
                notify.message(np_slack_str)
            if na_slack_str:
                logger.info(not_automated)
                logger.info(na_slack_str)
                #notify.message(not_automated)
                #notify.message(na_slack_str)
            if tc_list:
                logger.info(
                    "Testcases which are automated and updated with sutas_id in jira {}"
                    .format(tc_list))
                #It will filter test cases based on the conifiguration provided by user in user_configuration file
                #for test_type and sprint_no
                robosuitepath = os.environ['robosuitepath']
                suite = TestData(parent=None, source=robosuitepath)
                robotctagids = []
                robotcnames = []
                for testcase in suite.testcase_table:
                    robotcnames.append(testcase.name.lower())
                    robotctagids.append(testcase.tags.value)
                robotcdict = dict(list(zip(robotcnames, robotctagids)))
                if '-t' in sys.argv:
                    to_be_cloned_test_cases = []
                    tcnames = os.environ['testnames'].lower().split(',')
                    for tc in tcnames:
                        if tc in robotcnames:
                            for jira_tc in tc_list:
                                if jira_tc in robotcdict[tc]:
                                    tcid = jira_tc
                                    to_be_cloned_test_cases.append(
                                        conn.issue(tcid))
                        else:
                            raise Exception(
                                "Robot file doesn't contain tc {} Mentioned".
                                format(tc))
                else:
                    to_be_cloned_test_cases = TestManagement.filter_tcs(
                        conn, to_be_cloned_test_cases, testtype)
                if not to_be_cloned_test_cases:
                    raise Exception(
                        "Not found any testcase to clone for the given suite with given configuration"
                    )
                final_tcs = []
                for test_case in to_be_cloned_test_cases:
                    if not rerun:
                        for robotctagid in robotctagids:
                            if robotctagid:
                                if test_case.raw['fields'][
                                        sutas_id_field] in robotctagid:
                                    final_tcs.append(test_case.raw['fields']
                                                     [sutas_id_field])
                                    continue
                    else:
                        if test_case.fields().status.name.lower(
                        ) == 'failed' and type == 'failed':
                            final_tcs.append(
                                test_case.raw['fields'][sutas_id_field])
                        elif test_case.fields().status.name.lower(
                        ) == 'skipped' and type == 'skipped':
                            final_tcs.append(
                                test_case.raw['fields'][sutas_id_field])
                tc_list = list(set(final_tcs))
                tags = 'OR'.join(tc_list)
                logger.info(tags)
            else:
                raise UserException("Make sure fields 'sutas_id' and " \
                            "'Automated' must be there in every test case")
        if not tags:
            raise UserException(
                "No test cases found in provided test suite : ", ts_id)
        issue_obj = None
        if isinstance(ts_id, list):
            os.environ['multiplesuiteids'] = ','.join(ts_id)
            iss_obj = conn.issue(ts_id[-1])
        else:
            iss_obj = conn.issue(ts_id)
        #checking testmanagent enabled or not in configuration files
        if enable_test_mgt:
            if iss_obj:
                if not rerun:
                    #clning the test suite and its test cases from Master test suite
                    clone_testcases = [conn.issue(tc) for tc in tc_list]
                    issue_obj = TestManagement.clone_test_suite(\
                        conn, iss_obj, clone_testcases, testtype)
                    logger.warn("cloned test suite id : " + issue_obj.key)
                    notify.message("cloned test suite id : " + issue_obj.key)
                else:
                    issue_obj = iss_obj
                    logger.warn("Rerunning test suite of id : " +
                                issue_obj.key)
                    notify.message("Rerunning test suite of id : " +
                                   issue_obj.key)
                ts_id = issue_obj.id
                # fetching test cases from cloned test suite.
                test_cases = conn.search_issues('parent=' + ts_id)
                for test_case in test_cases:
                    tc_data[test_case.raw['fields'][sutas_id_field]] = \
                        (test_case.key, test_case.fields().summary)
                    if issue_obj.fields().status.name.upper() in [
                            'TODO', 'TO DO'
                    ] and not rerun:
                        for test_case in test_cases:
                            if test_case.raw['fields'][sutas_id_field]:
                                status = test_case.fields().status.name.lower()
                                if status in ['test in progress','running',\
                                                'passed', 'failed', 'skipped', 'blocked']:
                                    raise Exception(
                                        "Test case already executed, Before \
                                                    executing a test case make sure\
                                                    status in todo or ready to run state."
                                    )
                            else:
                                raise Exception(
                                    "Make sure 'sutas_id' field updateed \
                                                            with test case ID")
                            transitions = conn.transitions(ts_id)
                            #moving test suite to running state
                            for transition in transitions:
                                if transition['name'].lower() in [
                                        'run', 'suite in progress'
                                ]:
                                    conn.transition_issue(
                                        ts_id, str(transition['id']))

                    elif issue_obj.fields().status.name.lower() in [
                            'running', 'suite in progress'
                    ]:
                        if not rerun:
                            raise Exception(
                                "Test suite won't run because it is in Running state,\
                                            If you want to run test suit then clone the master \
                                            suite and provide cloned test suite id"
                            )
                    elif issue_obj.fields().status.name.lower() in [
                            'done', 'completed'
                    ]:
                        if not rerun:
                            raise Exception(
                                "Test suite won't run because it is in Completed state, \
                            If you want to run test suit then clone the master suite and \
                            provide cloned test suite id")
                    os.environ.__dict__["testids"] = {}
                    os.environ.__dict__["testids"].update(tc_data)
            else:
                raise Exception(
                    "No test suite found with provided test suite id :", ts_id)
        else:
            issue_obj = iss_obj
        return tags, issue_obj
示例#16
0
    def user_setup(self):
        """
        Gets the user config details
        """
        username = self.prevdata('Jira.username', self.userprevdata)
        password = self.prevdata('Jira.password', self.userprevdata)
        jira_url = self.prevdata('Jira.url', self.globalprevdata)
        jira_proj = self.prevdata('Jira.project', self.globalprevdata)
        raise_bugs = self.prevdata('Raise_Bugs', self.globalprevdata)
        jirabugpriority = self.prevdata('Jira.bugpriority',
                                        self.globalprevdata)
        jirabugseverity = self.prevdata('Jira.bugseverity',
                                        self.globalprevdata)
        jira_affect_version = self.prevdata('Jira.affects_version',
                                            self.globalprevdata)
        environment = self.prevdata('environment', self.globalprevdata)
        jira_watcher = self.prevdata('Jira.watcher', self.globalprevdata)
        tmproject = self.prevdata('TM_Project', self.globalprevdata)
        sprintnumber = self.prevdata('sprint_number', self.globalprevdata)
        fixversion = self.prevdata('fix_version', self.globalprevdata)
        log_level = self.prevdata('LogLevel', self.globalprevdata)
        symmetric_key = "Enter a key to encrypt/decrypt passwords [" +\
            self.prevdata('symmetric_key', self.globalprevdata) + "]: "
        symmetric_key = self.get_input(symmetric_key)
        environment = "Enter the Execution Environment [" + environment + "]: "
        environment = self.get_input(environment)
        tmproject = "Enter Jira Test Management Project Key [" + \
            tmproject + "]: "
        tmproject = self.get_input(tmproject)
        sprintnumber = "Enter Current Sprint Name [" + \
            sprintnumber + "]: "
        sprintnumber = self.get_input(sprintnumber)
        fixversion = "Enter Jira testcase/testsuite fix version [" + \
            fixversion + "]: "
        fixversion = self.get_input(fixversion)
        glob_details = {
            "symmetric_key": symmetric_key,
            'environment': environment,
            'sprint_number': sprintnumber,
            'fix_version': fixversion,
            'TM_Project': tmproject
        }
        self.update_dict(self.globalfilepath, glob_details)
        enabletestmanagement = "Do you want to enable test management as jira [" +\
            self.prevdata('EnableTestManagement',
                          self.globalprevdata) + "]:(Yes/No)"
        enabletestmanagement = self.get_input(enabletestmanagement,
                                              choices=["yes", "no"])

        if enabletestmanagement.lower() == 'yes':
            username = "******" + username + "]:"
            username = self.get_input(username)
            password = self.get_password("enter Jira APIKEY:", password)
            jira_url = "Enter Jira URL [" + jira_url + "]: "
            jira_url = self.get_input(jira_url)
            raise_bugs = "Do you want to enable Bug Management [" +\
                self.prevdata('Raise_Bugs', self.globalprevdata) + "]:(Yes/No)"
            raise_bugs = self.get_input(raise_bugs, choices=["yes", "no"])
            if raise_bugs.lower() == 'yes':
                jira_proj = "Enter Jira Bug Management Project [" + jira_proj + "]: "
                jira_proj = self.get_input(jira_proj)
                jirabugpriority = "Enter Jira bug priority(1:Critcical,2:High,3:Medium,4:Low,5:Trivial) [" + \
                    jirabugpriority + "]: "
                jirabugpriority = self.get_input(
                    jirabugpriority, choices=['1', '2', '3', '4', '5'])
                jirabugseverity = "Enter Jira bug severity(1:Critcical,2:Major,3:Moderate,4:Low,5:Trivial) [" + \
                    jirabugseverity + "]: "
                jirabugseverity = self.get_input(
                    jirabugseverity, choices=['1', '2', '3', '4', '5'])
                jira_affect_version = "Enter the Affects Version [" \
                    + jira_affect_version + "]: "
                jira_affect_version = self.get_input(jira_affect_version)
                logger.warn("By default project lead and test user "
                            "will be added as watcher")
                if jira_watcher:
                    value = 'yes'
                else:
                    value = 'no'
                    add_watcher = "Do you want to add more watcher:(Yes/No)[" + \
                        value + "]: "
                    add_watcher = self.get_input(add_watcher)
                    if add_watcher.lower() == 'yes':
                        jira_watcher = "Enter user name to add as a watcher [" +\
                            jira_watcher + "]: "
                        jira_watcher = self.get_input(jira_watcher)
                    else:
                        jira_watcher = ''
        glob_dict = {
            'EnableTestManagement': enabletestmanagement,
            'Jira': {
                'url': jira_url,
                'project': jira_proj
            }
        }
        jira_dict = {'Jira': {'username': username, 'password': password}}
        glob_dict.update({'Raise_Bugs': raise_bugs})
        raise_bugs_dict = {
            'bugseverity': jirabugseverity,
            'bugpriority': jirabugpriority,
            'affects_version': jira_affect_version,
            'watcher': jira_watcher,
        }
        glob_dict['Jira'].update(raise_bugs_dict)
        self.update_dict(self.filepath, jira_dict)
        self.update_dict(self.globalfilepath, glob_dict)
        db_dict = self.add_dbconf()
        slack_dict = self.add_slackconf()
        teams_dict = self.add_teamsconf()
        email_dict = self.add_mailconf()
        artifact_dict = self.add_artifactserverdetails()
        self.update_dict(self.filepath, db_dict[0])
        self.update_dict(self.globalfilepath, db_dict[1])
        self.update_dict(self.filepath, slack_dict[0])
        self.update_dict(self.globalfilepath, slack_dict[1])
        self.update_dict(self.globalfilepath, email_dict)
        self.update_dict(self.globalfilepath, teams_dict)
        self.update_dict(self.filepath, artifact_dict[0])
        self.update_dict(self.globalfilepath, artifact_dict[1])
        log_level = "\nEnter the log level (info or debug or warn) [" +\
            'warn' + "]:"
        log_level = self.get_input(log_level,
                                   choices=["info", "debug", "warn", "error"])
        log_dict = {"LogLevel": log_level.lower()}

        self.update_dict(self.globalfilepath, log_dict)
        val_obj = ValidateUserConfig()
        globdata = get_data_from_yaml(self.globalfilepath)
        jiralist = []
        dblist = []
        cronlist = []
        maillist = []
        comlist = []
        comlist1 = []
        if globdata.get('Raise_Bugs', 'no').lower() == 'yes':
            try:
                val_obj.validate_jira()
                jiralist = ["Jira", "Validated Successfully"]
            except Exception as e:
                notify.message('`\t\t' + str(e).replace("\n", "\n\t\t") + '`')
                jiralist = [
                    'Jira', "Validation Failed with below error:\n\t\t\t" +
                    str(e).replace("\n", "\n\t\t\t")
                ]
        else:
            jiralist = [
                "Jira", "TestManagement is set to 'no'. Hence not validating"
            ]

        if globdata.get('EnableDatabase', 'no').lower() == 'yes':
            try:
                val_obj.validate_database()
                dblist = ["Database", "Validated Successfully"]
            except Exception as e:
                notify.message('`\t\t' + str(e).replace("\n", "\n\t\t") + '`')
                dblist = [
                    "Database", "Validation Failed with below error:\n\t\t\t" +
                    str(e).replace("\n", "\n\t\t\t")
                ]
        else:
            dblist = [
                "Database",
                "EnableDatabase is set to 'no'. Hence not validating"
            ]

        if globdata.get('EnableTestArtifacts', 'no').lower() == 'yes':
            try:
                val_obj.ckeck_cronjob_in_appache_server()
                cronlist = ["TestArtifact server", "Validated Successfully"]
            except Exception as e:
                notify.message('`\t\t' + str(e).replace("\n", "\n\t\t") + '`')
                cronlist = [
                    "TestArtifact server",
                    "Validation Failed with below error:\n\t\t\t" +
                    str(e).replace("\n", "\n\t\t\t")
                ]
        else:
            cronlist = [
                "TestArtifact server",
                "EnableTestArtifacts is set to 'no'. Hence not validating"
            ]

        if globdata.get('EmailNotifications', 'no').lower() == 'yes':
            try:
                val_obj.validate_email()
                maillist = ["Email", "Validated Successfully"]
            except Exception as e:
                notify.message('`\t\t' + str(e).replace("\n", "\n\t\t") + '`')
                maillist = [
                    "Email", "Validation Failed with below error:\n\t\t\t" +
                    str(e).replace("\n", "\n\t\t\t")
                ]
        else:
            maillist = [
                "Email",
                "EmailNotifications is set to 'no'. Hence not validating"
            ]

        msg = ''
        if globdata.get('SlackNotifications','no').lower() == 'yes' and \
                globdata.get('TeamsNotifications','no').lower() == 'yes':
            msg = "Slack and MS Teams"
        elif globdata.get('SlackNotifications','no').lower() == 'yes' and \
                globdata.get('TeamsNotifications','no').lower() == 'no':
            msg = "Slack"
            comlist1 = [
                "MS Teams",
                "TeamsNotifications is set to no. Hence not validating."
            ]
        elif globdata.get('SlackNotifications','no').lower() == 'no' and \
                globdata.get('TeamsNotifications','no').lower() == 'yes':
            msg = "MS Teams"
            comlist1 = [
                "Slack",
                "SlackNotifications is set to no. Hence not validating."
            ]

        if msg:
            try:
                val_obj.validate_communication_channels()
                comlist = [msg, "Validated Successfully"]
            except Exception as e:
                if "Slack" in msg and "Teams" in msg:
                    if "Slack" in e and "Teams" not in e:
                        comlist = [
                            "Slack",
                            "Validation Failed with below error:\n\t\t\t" +
                            str(e).replace("\n", "\n\t\t\t")
                        ]
                        comlist1 = ["MS Teams", "Validated Successfully"]
                    elif "Teams" in e and "Slack" not in e:
                        comlist = [
                            "MS Teams",
                            "Validation Failed with below error:\n\t\t\t" +
                            str(e).replace("\n", "\n\t\t\t")
                        ]
                        comlist1 = ["Slack", "Validated Successfully"]
                else:
                    comlist = [
                        msg, "Validation Failed with below error:\n\t\t\t" +
                        str(e).replace("\n", "\n\t\t\t")
                    ]
        else:
            comlist = [
                "Slack",
                "SlackNotifications is set to no. Hence not validating."
            ]
            comlist1 = [
                "MS Teams",
                "TeamsNotifications is set to no. Hence not validating."
            ]

        msg = tabulate([
            jiralist, [], [], dblist, [], [], cronlist, [], [], maillist, [],
            [], comlist, [], [], comlist1
        ],
                       headers=['Application/Server', 'Validation status'],
                       tablefmt='pipe')
        logger.warn('\n\n' + msg)
示例#17
0
    def run(self):
        """
        This method will add test case status in to global_conf file.
        """
        tc_data = {}
        end_time = datetime.datetime.now()
        result = None
        tc_status_db_id = None
        att = None
        fix_version_db_id = None
        msg = None
        tc_db_id = None
        error_msg = None
        new_issue = None
        try:
            tcname = BuiltIn().get_variable_value("${TEST NAME}")
            tcstatus = BuiltIn().get_variable_value("${TEST STATUS}")
            testresultlist = BuiltIn().get_variable_value("${outlist}")
            suitename = BuiltIn().get_variable_value("${SUITE NAME}")
            suitestatus = BuiltIn().get_variable_value("${SUITE STATUS}")
            prevtestmessage = BuiltIn().get_variable_value(
                "${PREV TEST MESSAGE}")
            context = os.environ.__dict__["context"]
            raise_bugs = context.get('Raise_Bugs')
            if suitestatus == 'FAIL' and not tcstatus and 'Parent' in prevtestmessage:
                new_issue = None
                error_msg = BuiltIn().get_variable_value("${SUITE MESSAGE}")
                if raise_bugs == 'yes' and error_msg and 'skipping' not in error_msg:
                    obj = Jiralib(context.get('url'), context.get('username'),
                                  context.get('pwd'))
                    keyword = error_msg.split('\n')[0]
                    tcname = 'Test Suite' + suitename
                    att = get_individual_log(suitename)
                    conn = obj.conn
                    parse_obj = ParseAndRaiseBug(\
                        context.get('url'), context.get('username'),\
                        context.get('pwd'), context.get('proj'), \
                        context.get('affects_version'), context.get('environment'), \
                        context.get('watcher'), context.get('ts_id'), \
                        context.get('outputdir'), context.get('robo_file'), \
                        context.get('tc_management'))
                    error_msg = ''.join(error_msg.split('\n')[:2])
                    new_issue = parse_obj.parse(suitename, tcname, keyword,
                                                error_msg, att, raise_bugs)
                    if context.get('tc_management') is True:
                        conn.create_issue_link('is blocked by',
                                               context.get('ts_id'), new_issue)
            elif suitestatus == 'FAIL' and not tcstatus:
                att = get_individual_log(suitename)
            else:
                if not testresultlist:
                    if "TestStatus" in os.environ.__dict__:
                        os.environ.__dict__["TestStatus"][tcname] = tcstatus
                    else:
                        os.environ.__dict__["TestStatus"] = {tcname: tcstatus}
                    sutas_id = ''
                    clone_id = ''
                    if "testids" in os.environ.__dict__:
                        for tckey, clonetc in list(
                                os.environ.__dict__["testids"].items()):
                            if tcname == os.environ.__dict__["testids"][tckey][
                                    1].split('CLONE - ')[1]:
                                sutas_id = tckey
                                clone_id = os.environ.__dict__["testids"][
                                    tckey][0]
                    msg = BuiltIn().get_variable_value("${TEST MESSAGE}")
                    if tcstatus == 'FAIL':
                        logger.error(msg)
                        if ":" in msg:
                            msg = msg.split(":")[1]
                        if "skipping" in msg.lower():
                            result = "SKIP"
                        else:
                            result = "FAIL"
                        smsg = "*{} --> {}* --> {}* --> {}*".format(
                            tcname, sutas_id, clone_id, result)
                        notify.message("%s\n\terror_msg: %s" %
                                       (smsg, msg.strip()))
                    else:
                        result = "PASS"
                        smsg = "*{} --> {}* --> {}* --> PASS*".format(
                            tcname, sutas_id, clone_id)
                        notify.message(smsg)
                    tcstatus = result
                    if not suitestatus:
                        att = get_individual_log(tcname)
                        logger.warn(att)
                        file_pointer = open(att, "r")
                        data = file_pointer.read()
                        file_pointer.seek(0)
                        ##            kws = re.findall(r"(ERROR)+\s+(\w+:)+\s+(\w.*)+\s+", data)
                        error_msg = None
                        for line in file_pointer:
                            kws = re.findall(r"(ERROR)+\s+(\w+:)+\s+(\w.*)",
                                             line)
                            if kws:
                                break
                        strng = ""
                        for line in file_pointer:
                            date = datetime.date.today().strftime('%Y-%m-%d')
                            if date in line:
                                break
                            else:
                                strng += line

                            k = list(kws[0])
                            kws = [k]
                            kws[0][2] = kws[0][2] + " " + strng
                        keyword = ''
                        if kws:
                            keyword = kws[0][1]
                            error_msg = kws[0][2]
                        else:
                            error_msg = re.findall(r"(ERROR)+\s+(.*)", data)
                            if error_msg:
                                error_msg = error_msg[0][1]
                    else:
                        att = None
                    if raise_bugs.lower(
                    ) == 'yes' and error_msg and 'skipping' not in error_msg and tcstatus == 'FAIL':
                        obj = Jiralib(context.get('url'),
                                      context.get('username'),
                                      context.get('pwd'))
                        conn = obj.conn
                        parse_obj = ParseAndRaiseBug(\
                                                context.get('url'), context.get('username'),\
                                                context.get('pwd'), context.get('proj'), \
                                                context.get('affects_version'), context.get('environment'), \
                                                context.get('watcher'), context.get('ts_id'), \
                                                context.get('outputdir'), context.get('robo_file'), \
                                                context.get('tc_management'))
                        suite_name = BuiltIn().get_variable_value(
                            "${SUITE NAME}")
                        new_issue = parse_obj.parse(suite_name, tcname,
                                                    keyword, error_msg, att,
                                                    raise_bugs)
                else:
                    for count, testresult in enumerate(testresultlist):
                        tc_id = context.get('tc_id')[count]
                        tcstatus = testresult[0]
                        keyword = None
                        try:
                            error_msg = testresult[1]
                        except IndexError:
                            error_msg = None
                        if raise_bugs.lower(
                        ) == 'yes' and error_msg and 'skipping' not in error_msg and tcstatus == 'FAIL':
                            obj = Jiralib(context.get('url'),
                                          context.get('username'),
                                          context.get('pwd'))
                            conn = obj.conn
                            parse_obj = ParseAndRaiseBug(\
                                                    context.get('url'), context.get('username'),\
                                                    context.get('pwd'), context.get('proj'), \
                                                    context.get('affects_version'), context.get('environment'), \
                                                    context.get('watcher'), context.get('ts_id'), \
                                                    context.get('outputdir'), context.get('robo_file'), \
                                                    context.get('tc_management'))
                            suite_name = BuiltIn().get_variable_value(
                                "${SUITE NAME}")
                            new_issue = parse_obj.parse(
                                suite_name, tcname, keyword, error_msg, att,
                                raise_bugs)
                            if context.get('tc_management') is True:
                                conn.create_issue_link('is blocked by', tc_id,
                                                       new_issue)
                fix_version_db_id = None
                end_time = datetime.datetime.now()
                tc_status = []
                if context.get('database').lower() == 'yes':
                    db_util_obj = Db_utils()
                if context.get('tc_management') and tcname:
                    obj = Jiralib(context.get('url'), context.get('username'),
                                  context.get('pwd'))
                    conn = obj.conn
                    if testresultlist:
                        tc_status = [
                            status[0]
                            for count, status in enumerate(testresultlist)
                        ]
                    else:
                        tc_status.append(tcstatus)
                    TestManagement.get_actual_tc_id(tcname, tc_status, obj.conn, \
                                                    context.get('robo_file'), new_issue, error = error_msg)
                    tc_ids = context.get('tc_id')
                    tc_obj = conn.issue(tc_ids[0])
                    jira_tc_status = tc_obj.fields().status.name
                    if context.get('database').lower() == 'yes':
                        fix_versions = tc_obj.fields().fixVersions
                        if fix_versions:
                            fix_ver = fix_versions[-1]
                            fix_ver_data = {
                                'fix_version': fix_ver.name,
                            }
                            descr = fix_ver.__dict__.get('description')
                            release_date = fix_ver.__dict__.get('releaseDate')
                            if descr:
                                fix_ver_data.update({
                                    'description': descr,
                                })
                            if release_date:
                                release_date = datetime.datetime.strptime(
                                    release_date, "%Y-%m-%d").date()
                                fix_ver_data.update({
                                    'release_date':
                                    release_date,
                                })
                            fix_version_db_id = db_util_obj.chk_fix_version(
                                fix_version, fix_ver.name)
                            if not fix_version_db_id:
                                fix_ver_obj = fix_version()
                                fix_version_db_id = db_util_obj.write(
                                    fix_ver_obj, fix_ver_data)
                    if context.get('database').lower() == 'yes' and tcname:
                        tc_status_db_id = db_util_obj.get_id_by_name(
                            issue_status, jira_tc_status)
                        if not tc_status_db_id:
                            tc_status_data = {'name': jira_tc_status}
                            tc_table_obj = issue_status()
                            tc_status_db_id = db_util_obj.write(
                                tc_table_obj, tc_status_data)
                    flag = True
                    for count, tc_id in enumerate(tc_ids):
                        tc_obj = conn.issue(tc_id)
                        jira_tc_status = tc_obj.fields().status.name
                        if context.get('database').lower() == 'yes':
                            fix_versions = tc_obj.fields().fixVersions
                            if fix_versions:
                                fix_ver = fix_versions[-1]
                                fix_ver_data = {
                                    'fix_version': fix_ver.name,
                                }
                                descr = fix_ver.__dict__.get('description')
                                release_date = fix_ver.__dict__.get(
                                    'releaseDate')
                                if descr:
                                    fix_ver_data.update({
                                        'description': descr,
                                    })
                                if release_date:
                                    release_date = datetime.datetime.strptime(
                                        release_date, "%Y-%m-%d").date()
                                    fix_ver_data.update({
                                        'release_date':
                                        release_date,
                                    })
                                fix_version_db_id = db_util_obj.chk_fix_version(
                                    fix_version, fix_ver.name)
                                if not fix_version_db_id:
                                    fix_ver_obj = fix_version()
                                    fix_version_db_id = db_util_obj.write(
                                        fix_ver_obj, fix_ver_data)
                        if context.get('database').lower() == 'yes' and tcname:
                            tc_status_db_id = db_util_obj.get_id_by_name(
                                issue_status, jira_tc_status)
                            if not tc_status_db_id:
                                tc_status_data = {'name': jira_tc_status}
                                tc_table_obj = issue_status()
                                tc_status_db_id = db_util_obj.write(
                                    tc_table_obj, tc_status_data)
                        if new_issue and context.get(
                                'database').lower() == 'yes':
                            fieldmap = {
                                field['name']: field['id']
                                for field in conn.fields()
                            }
                            hit_count = fieldmap['HitCount']
                            hit_count = new_issue.raw['fields'][hit_count]
                            hit_count = int(hit_count)
                            bug_data = {}
                            bug_db_id = db_util_obj.chk_bug_id(
                                bugs, new_issue.key)
                            status = new_issue.fields().status.name
                            status_db_id = db_util_obj.get_id_by_name(
                                issue_status, status)
                            bugpriority = context.get('bugpriority')
                            bugseverity = context.get('bugseverity')
                            bugpriorities = {
                                '0': None,
                                '1': 'Critcical',
                                '2': 'High',
                                '3': 'Medium',
                                '4': 'Low',
                                '5': 'Trivial'
                            }
                            bugseverities = {
                                '0': None,
                                '1': 'Critcical',
                                '2': 'Major',
                                '3': 'Moderate',
                                '4': 'Low',
                                '5': 'Trivial'
                            }
                            if bugpriority not in bugpriorities:
                                bugpriority = '0'
                            if bugpriority not in bugseverities:
                                bugseverity = '0'
                            if not status_db_id:
                                status_data = {'name': status}
                                table_obj = issue_status()
                                status_db_id = db_util_obj.write(
                                    table_obj, status_data)
                            if bug_db_id:
                                if hit_count > 1 and status == 'Reopened':
                                    tc_data.update({'hitcount': hit_count})
                                    bug_typ = 'reopen'
                                elif hit_count > 1:
                                    bug_typ = 'exist'
                                    tc_data.update({'hitcount': hit_count})
                                bug_typ_db_id = db_util_obj.get_id_by_name(
                                    bug_type, bug_typ)
                                if not bug_typ_db_id:
                                    bug_typ = {'name': bug_typ}
                                    table_obj = bug_type()
                                    bug_typ_db_id = db_util_obj.write(
                                        table_obj, bug_typ)
                                bug_data.update({
                                    'type':
                                    bug_typ_db_id,
                                    'status':
                                    status_db_id,
                                    'bugpriority':
                                    bugpriorities[bugpriority],
                                    'bugseverity':
                                    bugseverities[bugseverity],
                                    'affects_version':
                                    context.get('affects_version')
                                })
                                logger.info("BugData:{}".format(bug_data),
                                            console=False)
                                db_util_obj.update_data_bulk(
                                    bugs, bug_db_id, bug_data)
                                tc_data.update({'bug_id': bug_db_id})
                            else:
                                if hit_count > 1 and status == 'Reopened':
                                    bug_typ = 'reopen'
                                    bug_data.update(
                                        {'jira_bug_id': new_issue.key})
                                    tc_data.update({'hitcount': hit_count})
                                elif hit_count > 1:
                                    bug_typ = 'exist'
                                    bug_data.update(
                                        {'jira_bug_id': new_issue.key})
                                    tc_data.update({'hitcount': hit_count})
                                else:
                                    bug_typ = 'new'
                                    bug_data.update(
                                        {'jira_bug_id': new_issue.key})
                                    tc_data.update({'hitcount': hit_count})
                                bug_typ_db_id = db_util_obj.get_id_by_name(
                                    bug_type, bug_typ)
                                if not bug_typ_db_id:
                                    bug_typ = {'name': bug_typ}
                                    table_obj = bug_type()
                                    bug_typ_db_id = db_util_obj.write(
                                        table_obj, bug_typ)
                                bug_data.update({
                                    'type':
                                    bug_typ_db_id,
                                    'status':
                                    status_db_id,
                                    'bugpriority':
                                    bugpriorities[bugpriority],
                                    'bugseverity':
                                    bugseverities[bugseverity],
                                    'affects_version':
                                    context.get('affects_version')
                                })
                                bug_obj = bugs()
                                logger.info("BugData:{}".format(bug_data),
                                            console=False)
                                bug_db_id = db_util_obj.write(
                                    bug_obj, bug_data)
                            tc_data.update({
                                'bug_id': bug_db_id,
                            })
                            error_msgs = []
                            if testresultlist:
                                for testresults in testresultlist:
                                    try:
                                        msg = testresults[1]
                                    except IndexError:
                                        #msg = None
                                        pass
                                    finally:
                                        error_msgs.append(msg)
                            else:
                                error_msgs.append(msg)
                            if context.get('database').lower() == 'yes':
                                tc_data.update( {'end_time':end_time,'result':tc_status[count], 'status':tc_status_db_id, \
                                                'log_path': att, 'reason_for_failure': error_msgs[count], \
                                                'fix_version':fix_version_db_id,'environment':context.get('environment')})
                                tc_db_ids = context.get('tc_db_ids')
                                logger.info("TCData:{}".format(tc_data),
                                            console=False)
                                db_util_obj.update_data_bulk(
                                    test_case, tc_db_ids[count], tc_data)
                                flag = False
                    else:
                        if flag:
                            error_msgs = None
                            tc_status = 'PASS'
                            if context.get('database').lower() == 'yes':
                                tc_data.update( {'end_time':end_time,'result':result, 'status':tc_status_db_id, \
                                                 'log_path': att, 'reason_for_failure': error_msgs, \
                                                 'fix_version':fix_version_db_id,'environment':context.get('environment')})
                                tc_db_ids = context.get('tc_db_ids')
                                logger.info("TCData:{}".format(tc_data),
                                            console=False)
                                db_util_obj.update_data_bulk(
                                    test_case, tc_db_ids[0], tc_data)
                else:
                    if context.get('database').lower() == 'yes' and tcname:
                        db_util_obj = Db_utils()
                        tc_data.update( {'end_time':end_time,'result':result, 'status':tc_status_db_id, \
                                                 'log_path': att, 'reason_for_failure': msg, \
                                                 'fix_version':fix_version_db_id,'environment':context.get('environment')})
                        tc_db_ids = context.get('tc_db_ids')
                        logger.info("TCData:{}".format(tc_data), console=False)
                        db_util_obj.update_data_bulk(test_case, tc_db_ids[0],
                                                     tc_data)

        except Exception as err:
            logger.error(str(err))
            out = "\n" + traceback.format_exc()
            logger.warn(out)
            raise err
        finally:
            art_obj = TestArtifact(att)
            art_obj.check_diskspace()
            att = art_obj.push_artifacts()