示例#1
0
    def test_list(self):
        """ Test Python->Tcl and Tcl->Python list conversion. """

        py_list = ['a', 'b b']
        tcl_list_length = self.tcl.eval('llength ' +
                                        py_list_to_tcl_list(py_list))
        assert int(tcl_list_length) == 2

        tcl_list = '{a} {b b}'
        python_list = tcl_list_2_py_list(tcl_list)
        assert len(python_list) == 2
        assert type(python_list[0]) is str
        assert type(python_list[1]) is str

        tcl_list = '{{a} {b b}}'
        python_list = tcl_list_2_py_list(tcl_list)
        assert len(python_list) == 2
        assert type(python_list[0]) is list
        assert type(python_list[1]) is list
        assert len(python_list[1]) == 2

        tcl_list = ''
        assert len(tcl_list_2_py_list(tcl_list)) == 0

        tcl_list = '{}'
        assert len(tcl_list_2_py_list(tcl_list)) == 0

        tcl_list = '[["a"], ["b", "b"]]'
        assert len(tcl_list_2_py_list(tcl_list)) == 2
示例#2
0
    def read_stats(self):
        """ Reads the statistics view from Avalanche and saves it in statistics dictionary. """

        #         self.statistcs = self.rdo.get_attributes()
        raw_stats = self.project.api.avl_command('perform getValues {}'.format(
            self.rds.ref))
        if raw_stats != '{Values {}}':
            for sample_num in tcl_list_2_py_list(raw_stats[9:-2]):
                timestamp, stats = tcl_list_2_py_list(sample_num)
                self.statistics[timestamp] = {
                    key_val.split()[0]: key_val.split()[1]
                    for key_val in tcl_list_2_py_list(stats)
                }
示例#3
0
 def discover(self):
     self.logger.info('Discover card {}'.format(self.obj_name()))
     for pid in range(1, self.portCount + 1):
         IxePort(self, self.uri + '/' + str(pid))
     try:
         rg_info_list = tcl_list_2_py_list(self.resourceGroupInfoList,
                                           within_tcl_str=True)
         for entry in rg_info_list:
             matches = re.finditer(self.regex, entry.strip())
             for match in matches:
                 IxeResourceGroup(
                     self, str(int(match.group(1)) + 1), match.group(2),
                     match.group(3),
                     [int(p) for p in match.group(4).strip().split()],
                     [int(p) for p in match.group(5).strip().split()],
                     [int(p) for p in match.group(6).strip().split()])
         if self.type == 110:
             operationMode = self.operationMode
             if operationMode == 2:
                 ports = [13]
                 operationMode = '10000'
             else:
                 ports = range(1, 13)
                 operationMode = '1000'
             IxeResourceGroup(self, 1, operationMode, -1, ports, ports,
                              ports)
     except Exception as _:
         print("no resource group support")
示例#4
0
    def perform(self, command, **arguments):
        """ Execute a command.

        :param command: requested command.
        :param arguments: additional arguments.
        :return: dictionary {attribute, value} as returned by 'perform command'.
        """

        rc = self.stc_command('perform', command, get_args_pairs(arguments))
        self.command_rc = {k[1:]: v for k, v in dict(zip(*[iter(tcl_list_2_py_list(rc))] * 2)).items()}
        return self.command_rc
示例#5
0
    def test_list(self):
        """ Test Python->Tcl and Tcl->Python list conversion. """

        py_list = ['a', 'b b']
        tcl_list_length = self.tcl.eval('llength ' +
                                        py_list_to_tcl_list(py_list))
        assert (int(tcl_list_length) == 2)

        tcl_list = '{a} {b b}'
        py_list_length = len(tcl_list_2_py_list(tcl_list))
        assert (py_list_length == 2)
示例#6
0
def test_list(tcl: TgnTclWrapper) -> None:
    """Test Python->Tcl and Tcl->Python list conversion."""
    py_list = ["a", "b b"]
    tcl_list_length = tcl.eval("llength " + py_list_to_tcl_list(py_list))
    assert int(tcl_list_length) == 2

    tcl_list = "{a} {b b}"
    python_list = tcl_list_2_py_list(tcl_list)
    assert len(python_list) == 2
    assert isinstance(python_list[0], str)
    assert isinstance(python_list[1], str)

    tcl_list = "{{a} {b b}}"
    python_list = tcl_list_2_py_list(tcl_list)
    assert len(python_list) == 2
    assert isinstance(python_list[0], str)
    assert isinstance(python_list[1], str)

    tcl_list = '{{"a" "b b"}}'
    python_list = tcl_list_2_py_list(tcl_list)
    assert len(python_list) == 1

    tcl_list = ""
    assert len(tcl_list_2_py_list(tcl_list)) == 0

    tcl_list = "{}"
    assert len(tcl_list_2_py_list(tcl_list)) == 0

    tcl_list = '[["a"], ["b", "b"]]'
    assert len(tcl_list_2_py_list(tcl_list)) == 2
示例#7
0
    def get(self, obj_ref, attribute=None):
        """ Returns the value(s) of one or more object attributes or a set of object handles.

        :param obj_ref: requested object reference.
        :param attribute: requested attribute. If empty - return values of all object attributes.
        :return: requested value(s) as returned by get command.
            If all attributes were requested the return value is dictionary
            {attrib_name:attrib_val, attrib_name:attrib_val, ..}
            If single attribute was requested, the returned value is simple str.
        """

        output = self.stc_command('get', obj_ref, '-' + attribute if attribute is not None else '')
        if attribute:
            return output
        attributes_dict = dict(zip(*[iter(tcl_list_2_py_list(output))] * 2))
        return dict(zip([s[1:] for s in attributes_dict.keys()], attributes_dict.values()))
示例#8
0
    def getList(self, obj_ref, attribute):

        output = self.stc_command('get', obj_ref, '-' + attribute if attribute is not None else '')
        return tcl_list_2_py_list(output)
示例#9
0
    def getList(self, obj_ref, attribute):

        output = self.stc_command(
            "get", obj_ref, "-" + attribute if attribute is not None else "")
        return tcl_list_2_py_list(output)
示例#10
0
 def getListAttribute(self, objRef, attribute):
     return tcl_list_2_py_list(self.getAttribute(objRef, attribute))
示例#11
0
 def getList(self, objRef, childList):
     children_list = self.ixnCommand('getList', objRef, childList)
     return tcl_list_2_py_list(children_list)
示例#12
0
 def getListAttribute(self, objRef, attribute):
     value = tcl_list_2_py_list(self.getAttribute(objRef, attribute))
     # Is there better way to determine that we have list of lists?
     return value if value[0][0] != '{' else [
         tcl_list_2_py_list(v[1:-1]) for v in value
     ]