def load_path_json(self, path_login_testdata):
     """ Retrieves data from json file. Returns None if exception occurs."""
     result = False
     data = None
     try:
         with open(path_login_testdata) as json_file:
             data = json.load(json_file)
             result = True
     except Exception as exception:
         pNote(exception, "error")
     return result, data
    def _execute_step_list(self):
        """
        """

        goto_stepnum = False
        step_num = 0
        while step_num < len(self.step_list):

            index = step_num
            step = self.step_list[step_num]
            step_num += 1

            self.system_executed = self._get_system_executed(index)
            if self.stop_after_current_step:
                break

            # when there is no goto
            if not goto_stepnum:
                result = self._execute_step(self.system_executed, step_num,
                                            index, goto_stepnum)

            # when goto is triggered and matches the current step number
            elif (goto_stepnum and goto_stepnum == str(step_num)):
                result = self._execute_step(self.system_executed, step_num,
                                            index, goto_stepnum)
                goto_stepnum = False

            # when goto is triggered and does not match current step... skip
            elif goto_stepnum and goto_stepnum != str(step_num):
                result = self._update_skip_results(step, self.system_executed,
                                                   step_num)
                self.kw_resultfile_list.append(result[1])
                continue

            step_status = result[0]
            kw_resultfile = result[1]
            step_impact = result[2]
            exec_type_onerror = result[3]

            self._update_status_items(step_status, kw_resultfile, step_impact)
            goto_stepnum, step_num = self._compute_runmode_goto_operations(step, step_status,
                                                                           exec_type_onerror,
                                                                           goto_stepnum, step_num)
            if (goto_stepnum == 'ABORT'):
                if any([self.iter_type_list[index] == "once_per_tc",
                       self.iter_type_list[index] == "end_of_tc"]):
                    pNote("step iter_type={0}, and onerror action=ABORT hence aborting execution"
                          "compeletely".format(self.iter_type_list[index]), "debug")
                    self.stop_after_current_iteration = True
                    self.stop_after_current_step = True
                goto_stepnum = False
                break

        return
Ejemplo n.º 3
0
def just_a_tuple(element):
    """ This function evaluates the value of the files tag and returned
    validated data.

        input: string

        (path/to/file4.txt;content_type), (path/to/file1.txt;content_type)

        output: dict

        {
        file4.txt: (file4.txt, open file4.txt (in binary mode), content_type)
        file1.txt: (file1.txt, open file1.txt (in binary mode), content_type)
        }

    """
    final_dict = {}
    temp_list = []
    element = element.strip(")")
    element = element.strip("(")
    if element is not None and element is not False and element != "":
        element = element.split(";")
        for i in range(0, len(element)):
            element[i] = element[i].strip()
        if element[0] is not None and element[0] is not False \
                and element[0] != "":
            abs_path = file_Utils.getAbsPath(element[0], sys.path[0])
            if os.path.exists(abs_path):
                temp_list.append(os.path.basename(os.path.normpath(
                    element[0])))
                temp_list.append(open(abs_path, 'rb'))
                if len(element) > 1:
                    if element[1] is not None and element[1] is not False \
                            and element[1] != "":
                        temp_list.append(element[1])
            else:
                pNote("{0} doesn't exist!".format(element[0]), "error")
        else:
            if element == "":
                pNote("File path cannot be empty!", "error")
            else:
                pNote("File path cannot be {0}!".format(element[0]), "error")
        if temp_list != []:
            if len(temp_list) > 2:
                final_dict[temp_list[0]] = (temp_list[0], temp_list[1],
                                            temp_list[2])
            else:
                final_dict[temp_list[0]] = (temp_list[0], temp_list[1])
    else:
        if element == "":
            pNote("File path cannot be empty!", "error")
        else:
            pNote("File path cannot be {0}!".format(element), "error")
    return final_dict
    def import_requests(self):
        """Import the requests module """
        try:
            import requests
        except ImportError:
            pNote("Requests module is not installed"\
                       "Please install requests module to"\
                       "perform any activities related to REST interfaces", "error")

        else:
            self.req = requests
Ejemplo n.º 5
0
 def check_type(var, varname, datatype):
     """check that vars are of correct datatype
     """
     vartype = type(var)
     status = True
     if vartype is not datatype:
         pNote(
             '{} is expected to be {} type, but found to be of '
             '{} type'.format(varname, datatype, vartype), "error")
         status = False
     return status
Ejemplo n.º 6
0
def warrior_framework_details():
    """This gets framework details such the executing framework path, release
        & version details.
    """
    #The logic uses relative file path to locate Warrior framework and its\
    # release notes.Assumes the relative structure remains constant.
    release = False
    version = False
    version_file_path = os.path.normpath(
        os.path.join(__file__, "..{0}..{0}..".format(os.sep)))
    version_file = os.path.join(version_file_path, "version.txt")
    version_file_exists = file_Utils.fileExists(version_file)
    if version_file_exists:
        release_notes = open(version_file, "r")
        for line in release_notes:
            line = line.strip()
            #pattern matching Release:<>
            if re.match('(Release.*):(.*)', line):
                match = re.match(r'(Release.*):(.*)', line)
                release = match.group(2)
            #pattern matching Version:<>
            if re.match('(Version.*):(.*)', line):
                match = re.match(r'(Version.*):(.*)', line)
                version = match.group(2)
    user = getpass.getuser()
    proc1 = subprocess.Popen(['git', 'branch'], stdout=subprocess.PIPE)
    proc2 = subprocess.Popen(['grep', '*'],
                             stdin=proc1.stdout,
                             stdout=subprocess.PIPE,
                             stderr=None)
    proc1.stdout.close()  # Allow proc1 to receive a SIGPIPE if proc2 exits.
    branch = proc2.communicate()[0]

    if release and version and version_file_path:
        pNote(
            "========================== WARRIOR FRAMEWORK DETAILS ==========================",
            'notype')
        print_info(
            'The Warrior framework used is {0}'.format(version_file_path))
        print_info('The Warrior framework user is {0}'.format(user))
        print_info('The Warrior framework Release is{0}'.format(release))
        print_info('The Warrior framework version is{0}'.format(version))
        print_info('The Warrior framework branch is{0}'.format(
            branch.strip('*')))
        print_info(
            'The Warrior framework running on python version: {0} with OS: {1}'
            .format(platform.python_version(), platform.platform()))
        pNote(
            "========================== WARRIOR FRAMEWORK DETAILS ==========================",
            'notype')

    #Sleep for the user to view the console for a second on the framework detail
    time.sleep(2)
    return None
 def check_tmp_file_exists(self, system_name="", filename=""):
     """ check if temp folder exist in the parallel execution result tmp dir """
     if system_name != "" and filename == "":
         filename = data_Utils.getSystemData(self.datafile, system_name,
                                             "filename")
     elif system_name == "" and filename == "":
         pNote("No system or filename found, needs to provide at least one",
               "error")
     path = data_Utils.get_object_from_datarepository(
         "parallel_exec_tmp_dir")
     path = os.path.join(path, filename)
     return file_Utils.fileExists(path)
Ejemplo n.º 8
0
    def edit_config_from_string(self,
                                datastore,
                                config,
                                system_name,
                                session_name=None,
                                default_operation=None,
                                test_option=None,
                                error_option=None):
        """ Loads all or part of the specified config(not file) to the datastore
        :Arguments:
            1. datastore(string) = Name of datastore being edited
            2. config(string) = The configuration xml string.
            3. system_name(string) = Name of the system from the input datafile
            4. session_name(string) = Name of the session to the system
            5. default_operation(string) = [merge | replace | none (default)]
            6. test_option(string) = [test_then_set | set | test-only | none (default)]
            7. error_option(string) = [stop-on-error | continue-on-error
                                      | rollback-on-error | none (default)]
                    rollback-on-error depends on :rollback-on-error capability
        :Returns:
            1. status(bool)= True / False
            2. Edit Response in the data repository {data:reply(xml)}
         """
        wdesc = "Edit system configuration data"
        pSubStep(wdesc)
        pNote(system_name)
        pNote(self.datafile)

        self.clear_notification_buffer_all(system_name, session_name)
        session_id = Utils.data_Utils.get_session_id(system_name, session_name)
        netconf_object = Utils.data_Utils.get_object_from_datarepository(
            session_id)

        reply = netconf_object.edit_config(datastore,
                                           config,
                                           default_operation=default_operation,
                                           test_option=test_option,
                                           error_option=error_option)
        if netconf_object.isCOMPLD:
            status = True
            if reply:
                reply = parseString(reply).toprettyxml(indent="  ",
                                                       encoding="UTF-8")
            pNote('edit-config: Reply= {}'.format(reply))
        else:
            pNote('edit-config: Reply= {}'.format(reply))
            pNote('edit-config: Failed {}'.format(netconf_object.ErrorMessage),
                  "error")
            status = False
        report_substep_status(status)
        reply_key = '{}_edit_config_reply'.format(system_name)
        return status, {reply_key: reply}
Ejemplo n.º 9
0
 def remove(self, filename):
     """remove the filename from the system
     :Arguments:
         filename - filename path to be removed from system
     :Returns:
         True if successful otherwise False
     """
     wdesc = "remove the filename from the system"
     pNote(wdesc)
     status = file_Utils.remove(filename)
     pStep('removing {!r}'.format(filename))
     file_Utils.log_result("remove", status)
     return status
Ejemplo n.º 10
0
 def clear_notification_buffer_for_print(self, system_name, session_name=None):
     """clear the notification print buffer
         :Arguments:
             1. system_name (string) = system name
             2. session_name (string) = session name
         :Returns:
             1. status (bool)
     """
     wdesc = "clear the notification print buffer"
     pNote(wdesc)
     session_id = Utils.data_Utils.get_session_id(system_name, session_name)
     netconf_object = Utils.data_Utils.get_object_from_datarepository(session_id)
     return netconf_object.clear_notification_buffer_for_print()
 def instantiate_list_key_in_data_repository(self, key):
     """
     This will create a key in the data_repository
     :param key: name of the key that should be created in the data_repository.
                 The data type of it's value will be list.
     :return: status (bool), output_dict (dict)
     """
     wdesc = "This keyword will create a key in the data repository"
     pNote(wdesc)
     status = True
     output_dict = {key: []}
     pNote("Updating Data Repository with key: {0}".format(key))
     return status, output_dict
 def close_trap_listner_job(cls, port):
     """
     Close the trap listner job
     :param transportDispatcher:
     :return:None
     """
     snmpEngine = cls.get_asyncoredispatcher(port)
     snmpEngine.transportDispatcher.jobFinished(1)
     try :
         snmpEngine.transportDispatcher.unregisterTransport(udp.domainName)
     except:
         testcase_Utils.pNote("Can not unregister udp Transport domain",
                              'warning')
Ejemplo n.º 13
0
    def close(self):
        '''
        #session close
        '''
        try:
            self.__chan.close()
            self.__t.close()
        except Exception as e:
            pNote(str(e), "error")
            traceback.print_exc()
        self.__isOpen = False
        pNote("netconf: port closed")

        return True
Ejemplo n.º 14
0
    def cs_get_topo_details(self, topology_path):
        """To get the Cloudshell topology details for a given path

        :Datafile usage:
             NA
        :Arguments:
            1. topology_path(string) = Specify the full topology name. Include
               the full path from the root to the topology, separated by slashes.
               For example: FolderName/Topologies/TopologyName

        :Returns:
            1. status(bool)= True/False
        """

        wdesc = "To get the Cloudshell topology details for a given path"
        testcase_Utils.pSubStep(wdesc)
        testcase_Utils.pNote(file_Utils.getDateTime())

        status = False
        testcase_Utils.pNote("cs_get_topo_details, cs obj-{}".\
                             format(cloud_shell), "info")
        try:
            xml_resp = cloud_shell.GetTopologyDetails(topology_path)
            if xml_resp is not None:
                testcase_Utils.pNote("\n\n *** Get Topolopy \"%s\" successfull\n"\
                                     % (topology_path), "info")
                status = True
            else:
                testcase_Utils.pNote("\n\n *** Get Topolopy \"%s\" failed\n"\
                                     % (topology_path), "warning")
        except Exception as exception:
            print_exception(exception)

        testcase_Utils.report_substep_status(status)
        return status
Ejemplo n.º 15
0
    def cs_logoff(self):
        """To logoff from CS

        :Datafile usage:
             NA
        :Arguments:
             NA
        :Returns:
            1. status(bool)= True/False
        """

        wdesc = "To logoff from CS"
        testcase_Utils.pSubStep(wdesc)
        testcase_Utils.pNote(file_Utils.getDateTime())

        status = False
        testcase_Utils.pNote("cs_logoff, cs obj-{}".format(cloud_shell),
                             "info")
        xml_resp = cloud_shell.Logoff()

        if xml_resp is not None:
            testcase_Utils.pNote(
                "\n\n *** Cloudshell LogOff successfull-%s" %
                (cloud_shell.host), "info")
            status = True
        else:
            testcase_Utils.pNote(
                "\n\n *** Cloudshell LogOff failed-%s" % (cloud_shell.host),
                "warning")

        testcase_Utils.report_substep_status(status)
        return status
Ejemplo n.º 16
0
    def connect_to_cs(self, system_name):
        """Logs in to API host using passed user credentials and domain

        :Datafile usage:
             NA
        :Arguments:
            1. system_name(string) = Name of the system from the datafile

        :Returns:
            1. status(bool)= True/False
        """

        wdesc = "Logon to CloudShell API Host"
        testcase_Utils.pSubStep(wdesc)
        testcase_Utils.pNote(file_Utils.getDateTime())

        global cloud_shell
        cloud_shell = self._create_cs_obj(system_name)
        testcase_Utils.pNote("Login, cs obj-{}".format(cloud_shell), "info")

        status = False
        if cloud_shell is not None:
            testcase_Utils.pNote("\n\n *** Login to Cloudshell System-{}"
                                 " successfull, domain-{}\n".\
                                 format(cloud_shell.host,\
                                 cloud_shell.domain), "info")
            status = True
        else:
            testcase_Utils.pNote(
                "\n\n *** Login to Cloudshell System"
                " failed\n", "warning")

        testcase_Utils.report_substep_status(status)
        return status
Ejemplo n.º 17
0
    def discard_changes(self, system_name, session_name=None):
        """Revert the candidate configuration to the currently running configuration.
        Uncommitted changes will be discarded.

        :Arguments:
            1. system_name(string)  = Name of the system from the input datafile
            2. session_name(string) = Name of the session to the system
        :Returns:
            1. status(bool)= True / False
            2. Discard Response in the data repository {data:reply(xml)}
         """
        wdesc = "Discard any uncommitted changes to the candidate configuration"
        pSubStep(wdesc)
        pNote(system_name)
        pNote(self.datafile)

        self.clear_notification_buffer_all(system_name, session_name)
        session_id = Utils.data_Utils.get_session_id(system_name, session_name)
        netconf_object = Utils.data_Utils.get_object_from_datarepository(
            session_id)
        reply = netconf_object.discard_changes()
        if reply:
            reply = parseString(reply).toprettyxml(indent="  ")
        pNote('discard-changes: Reply= {}'.format(reply))
        if netconf_object.isCOMPLD:
            status = True
        else:
            pNote(
                'discard-changes: Failed {}'.format(
                    netconf_object.ErrorMessage), "error")
            status = False
        report_substep_status(status)
        reply_key = '{}_discard_changes_reply'.format(system_name)
        return status, {reply_key: reply}
Ejemplo n.º 18
0
 def copy(self, filename, newname):
     """copy filename to newname
     :Arguments:
         filename - filename path to be copied
         newname - new file name or path to which the file has to be copied
     :Returns:
         True if successful otherwise False
     """
     wdesc = "copy filename to newname"
     pNote(wdesc)
     status = file_Utils.copy(filename, newname)
     pStep('Copying {!r} to {!r}'.format(filename, newname))
     file_Utils.log_result("copy", status)
     return status
Ejemplo n.º 19
0
    def lock(self, datastore, system_name, session_name=None):
        """Lock the configuration system

        :Arguments:
            1. datastore(string) = name of the configuration datastore to be locked
            2. system_name(string)  = Name of the system from the input datafile
            3. session_name(string) = Name of the session to the system
        :Returns:
            1. status(bool)= True / False
            2. Lock Response in the data repository {data:reply(xml)}
         """
        wdesc = "Lock the configuration datastore"
        pSubStep(wdesc)
        pNote(system_name)
        pNote(self.datafile)

        session_id = Utils.data_Utils.get_session_id(system_name, session_name)
        netconf_object = Utils.data_Utils.get_object_from_datarepository(session_id)
        reply = netconf_object.lock(datastore)
        pNote('Lock Reply= {}'.format(reply))
        if netconf_object.isCOMPLD:
            status = True
        else:
            pNote('Lock Failed {}'.format(netconf_object.ErrorMessage), "error")
            status = False
        report_substep_status(status)
        reply_key = '{}_lock_reply'.format(system_name)
        return status, {reply_key: reply}
Ejemplo n.º 20
0
    def testfor_killsession(self, system_name, session_name=None):
        """kill-session test keyword
           create another session to same NE and kills it.
        :Arguments:
            1. system_name(string) = Name of the system from the input datafile
            2. session_name(string) = Name of the session to the system
        :Returns:
            1. status(bool)= True / False
        """
        wdesc = "kill-session, create another session and kill it"
        pSubStep(wdesc)
        pNote(system_name)
        pNote(self.datafile)

        test_netconf = WNetConf()
        session_parameters = [
            'ip', 'nc_port', 'username', 'password', 'allow_agent',
            'hostkey_verify', 'look_for_keys', 'timeout', 'device_name'
        ]
        session_credentials = Utils.data_Utils.get_credentials(
            self.datafile, system_name, session_parameters)
        session_credentials["password"] = decrypt(
            session_credentials["password"])
        if test_netconf.open(session_credentials):
            time.sleep(1)
            sid = test_netconf.session_id
            status, reply = self.kill_session(system_name, sid, session_name)
        else:
            status = False
        if status:
            pNote("kill-session PASS")
        else:
            pNote("kill-session FAIL", "error")
        report_substep_status(status)
        return status
Ejemplo n.º 21
0
    def kill_session(self, system_name, netconf_session_id=None, session_name=None):
        """Force the termination of a NETCONF session (not the current one!)
        :Arguments:
            1. system_name(string)  = Name of the system from the input datafile
            2. netconf_session_id(string) = session-id of netconf
            3. session_name(string) = Name of the session to the system
        :Returns:
            1. status(bool)= True / False
            2. Kill Response in the data repository {data:reply(xml)}
         """
        wdesc = "Force the termination of a NETCONF session (not the current one!)"
        pSubStep(wdesc)
        pNote(system_name)
        pNote(self.datafile)

        self.clear_notification_buffer_all(system_name, session_name)
        session_id = Utils.data_Utils.get_session_id(system_name, session_name)
        netconf_object = Utils.data_Utils.get_object_from_datarepository(
            session_id)
        if not netconf_session_id:
            netconf_session_id = "0"
        reply = netconf_object.kill_session(netconf_session_id)
        if reply:
            reply = parseString(reply).toprettyxml(
                indent="  ", encoding="UTF-8")
        pNote('kill-session: Reply= {}'.format(reply))
        if netconf_object.isCOMPLD:
            status = True
        else:
            pNote('kill-session: Failed {}'.format(netconf_object.ErrorMessage), "error")
            status = False
        report_substep_status(status)
        reply_key = '{}_kill_session_netconf_reply'.format(system_name)
        return status, {reply_key: reply}
Ejemplo n.º 22
0
    def get(self, system_name, session_name=None, filter_string=None, filter_type=None):
        """Retrieve operational state information.

        :Arguments:
            1. system_name(string)  = Name of the system from the input datafile
            2. session_name(string) = Name of the session to the system
            3. filter_string(string) = specifies the portion of the state information to retrieve
               (by default entire state information is retrieved)
            4. filter_type(string) = subtree or xpath
        :Returns:
            1. status(bool)= True / False
            2. Retrieve Response in the data repository {data:reply(xml)}
         """
        wdesc = "Retrieve operational state information (get rpc)."
        pSubStep(wdesc)
        pNote(system_name)
        pNote(self.datafile)

        self.clear_notification_buffer_all(system_name, session_name)
        session_id = Utils.data_Utils.get_session_id(system_name, session_name)
        netconf_object = Utils.data_Utils.get_object_from_datarepository(
            session_id)
        reply = netconf_object.get(filter_string, filter_type)
        if reply:
            reply = parseString(reply).toprettyxml(
                indent="  ", encoding="UTF-8")
        pNote('get: Reply= {}'.format(reply))
        if netconf_object.isCOMPLD:
            status = True
        else:
            pNote('get: Failed {}'.format(netconf_object.ErrorMessage), "error")
            status = False
        report_substep_status(status)
        reply_key = '{}_get_config_reply'.format(system_name)
        return status, {reply_key: reply}
Ejemplo n.º 23
0
    def unlock(self, datastore, system_name, session_name=None):
        """Release the configuration lock

        :Arguments:
            1. datastore(string) = name of the configuration datastore to be unlocked
            2. system_name(string)  = Name of the system from the input datafile
            3. session_name(string) = Name of the session to the system
        :Returns:
            1. status(bool)= True / False
            2. Unlock Response in the data repository {data:reply(xml)}
         """
        wdesc = "Unlock the configuration datastore"
        pSubStep(wdesc)
        pNote(system_name)
        pNote(self.datafile)

        self.clear_notification_buffer_all(system_name, session_name)
        session_id = Utils.data_Utils.get_session_id(system_name, session_name)
        netconf_object = Utils.data_Utils.get_object_from_datarepository(
            session_id)
        reply = netconf_object.unlock(datastore)
        if reply:
            reply = parseString(reply).toprettyxml(
                indent="  ", encoding="UTF-8")
        pNote('unlock: Reply= {}'.format(reply))
        if netconf_object.isCOMPLD:
            status = True
        else:
            pNote('unlock: Failed {}'.format(
                netconf_object.ErrorMessage), "error")
            status = False
        report_substep_status(status)
        reply_key = '{}_unlock_reply'.format(system_name)
        return status, {reply_key: reply}
 def end_of_tc_with_system_name_not_given(self, system_name, step_num):
     """
         It is used to test the functionality of end of tc with no system name given in the test case
         Arguments:
             system_name: Name of the system on which it needs to be run
             step_num: It is the step_num in the test case file
         Returns:
             Returns True
     """
     wdesc = "End of testcase with system name not given"
     pNote(wdesc)
     key = 'end_of_tc_with_system_name_not_given_' + str(step_num)
     self.write_to_file(key, system_name)
     return True
Ejemplo n.º 25
0
    def commit(self, system_name,
               confirmed=False, timeout=None, persist=None, persist_id=None, session_name=None):
        """Commit the candidate datastore as the device's new current configuration
        :Arguments:
            1. system_name(string)  = Name of the system from the input datafile
            2. confirmed(bool) = Commit is reverted if there is no followup commit
                within the timeout interval.
            3. timeout(int seconds) = The confirm timeout (Default=600 seconds)
            4. persist(string) = persist-id
            5. persist_id(string) = persist-id which specified in previous confirmed commit
            6. session_name(string) = Name of the session to the system
        :Returns:
            1. status(bool)= True / False
            2. Commit Response in the data repository {data:reply(xml)}
         """
        wdesc = "Commit the candidate datastore"
        pSubStep(wdesc)
        pNote(system_name)
        pNote(self.datafile)

        session_id = Utils.data_Utils.get_session_id(system_name, session_name)
        netconf_object = Utils.data_Utils.get_object_from_datarepository(session_id)
        reply = netconf_object.commit(confirmed, timeout, persist, persist_id)
        pNote('Commit Reply= {}'.format(reply))
        if netconf_object.isCOMPLD:
            status = True
        else:
            pNote('Commit Failed {}'.format(netconf_object.ErrorMessage), "error")
            status = False
        report_substep_status(status)
        reply_key = '{}_commit_reply'.format(system_name)
        return status, {reply_key: reply}
Ejemplo n.º 26
0
 def copystat(self, filename, newname):
     """copy only stats of filename to newname and not its contents
     :Arguments:
         filename - stats of the filename path to be copied
         newname - new file name or path to which the stats has to be copied
     :Returns:
         True if successful otherwise False
     """
     wdesc = "copy stats of filename to newname"
     pNote(wdesc)
     status = file_Utils.copystat(filename, newname)
     pStep('Copying stat of {!r} to {!r}'.format(filename, newname))
     file_Utils.log_result("copystat", status)
     return status
Ejemplo n.º 27
0
    def validate(self, datastore, system_name, session_name=None):
        """"Validate the contents of the specified configuration.
        :Arguments:
            1. datastore(string) = Name of the configuration datastore to be validated
            2. system_name(string)  = Name of the system from the input datafile
            3. session_name(string) = Name of the session to the system
        :Returns:
            1. status(bool)= True / False
            2. Validation Response in the data repository {data:reply(xml)}
         """
        wdesc = "Validate the contents of the specified configuration."
        pSubStep(wdesc)
        pNote(system_name)
        pNote(self.datafile)

        self.clear_notification_buffer_all(system_name, session_name)
        session_id = Utils.data_Utils.get_session_id(system_name, session_name)
        netconf_object = Utils.data_Utils.get_object_from_datarepository(
            session_id)
        reply = netconf_object.validate(datastore)
        if reply:
            reply = parseString(reply).toprettyxml(indent="  ")
        pNote('validate: Reply= {}'.format(reply))
        if netconf_object.isCOMPLD:
            status = True
        else:
            pNote('validate: Failed {}'.format(netconf_object.ErrorMessage),
                  "error")
            status = False

        report_substep_status(status)
        reply_key = '{}_validate_netconf_reply'.format(system_name)
        return status, {reply_key: reply}
Ejemplo n.º 28
0
 def __send(self, data):
     '''
     #send data to host
     #  data = data to send (xml string)
     '''
     ret = True
     if self.__isOpen:
         pNote("netconf send:\n" + parseString(data).toprettyxml())
         self.__send_data = data
         self.__response_buffer = ""
         self.__notification_buffer = ""
         try:
             data = XML_HEADER + data + NETCONF_DELIM
             while data:
                 n = self.__chan.send(data)
                 if n <= 0:
                     pNote("netconf: send data failed.", "error")
                     ret = False
                     break
                 data = data[n:]
         except socket.error as e:
             pNote(str(e.__class__) + ': ' + str(e), "error")
             traceback.print_exc()
             ret = False
     else:
         pNote("netconf: port not opened", "warning")
         ret = False
     return ret
Ejemplo n.º 29
0
    def cancel_commit(self, system_name, persist_id=None, session_name=None):
        """cancel-commit
        :Arguments:
            1. system_name(string) = Name of the system from the input datafile
            2. persist_id(string) = persist-id which specified in confirm-commit
            3. session_name(string) = name of the session to the system
        :Returns:
            1. command_status(bool)
            2. {data:reply.data(xml)}
        """
        wdesc = "cancel-commit"
        pSubStep(wdesc)
        pNote(system_name)
        pNote(self.datafile)

        self.clear_notification_buffer_all(system_name, session_name)
        session_id = Utils.data_Utils.get_session_id(system_name, session_name)
        netconf_object = Utils.data_Utils.get_object_from_datarepository(
            session_id)
        reply = netconf_object.cancel_commit(persist_id)
        if reply:
            reply = parseString(reply).toprettyxml(indent="  ")
        pNote('cancel-commit: Reply= {}'.format(reply))
        if netconf_object.isCOMPLD:
            status = True
        else:
            pNote(
                'cancel-commit: Failed {}'.format(netconf_object.ErrorMessage),
                "error")
            status = False

        report_substep_status(status)
        reply_key = '{}_request_rpc_reply'.format(system_name)
        return status, {reply_key: reply}
Ejemplo n.º 30
0
 def rename(self, filename, newname):
     """rename or move filename to newname
     :Arguments:
         filename - filename path to be renamed or moved
         newname - new file name or path to which the file has to be moved
     :Returns:
         True if successful otherwise False
     """
     wdesc = "rename or move a file"
     pNote(wdesc)
     status = file_Utils.move(filename, newname)
     pStep('renaming {!r} to {!r}'.format(filename, newname))
     file_Utils.log_result("rename", status)
     return status