def t_cifs_domain():
    nas = getNasServer()
    dns = getDns(nas)

    interfaces = [fi for fi in FI.list() if fi().parent == nas()]
    for interface in interfaces[:-1]:
        interface().delete()

    interface = getInterface(nas)
    cifs = getCifsServer(nas)
    cifs().delete()

    Timer.add(30.0)

    cifs = getCifsServer(nas)
    interface().modify()
    cifs().modify()

    # with ethernet ports
    interface().modify()
    cifs().modify()

    # CIFS uses DNS
    dns().delete(is_error=True)

    interface().delete()

    # no interface
    cifs().delete(is_error=True)

    getInterface(nas)

    cifs().delete()
Example #2
0
    def apply_list(self, **kwargs):
        Timer.add(self.time)
        result = []

        for _, value in OBJECTS[self.type].items():
            if len(kwargs):
                for filter_key, filter_value in kwargs.items():
                    if hasattr(value, filter_key) and getattr(value, filter_key) == filter_value:
                        result.append(value)
            else:
                result.append(value)

        return result
def t_cifs_skip_unjoin_reuse():
    nas = getNasServer()
    getDns(nas)
    getInterface(nas)
    cifs = getCifsServer(nas)

    cifs().modify()
    cifs().modify()
    cifs().delete()

    Timer.add(30.0)

    cifs = getCifsServer(nas)
    cifs().delete()

    Timer.add(30.0)

    getCifsServer(nas)
Example #4
0
    def apply(self, node = None, is_error = False, **kwargs):
        if self.method == 'list':
            return self.apply_list(**kwargs)

        if is_error:
            Timer.add(self.error_time)
            return None
        Timer.add(self.time)

        if node is None or self.left is None:
            return None

        if type(node) is weakref.ReferenceType:
            node = node()

        node_id = None
        node_name = node.name
        if hasattr(node, 'id'):
            node_id = node.id

        node = self.__find_left_base(node)

        if self.is_applicable(node, node_name, node_id):
            # create new
            left_node = self.copy_left()
            right_node = self.copy_right()

            # merge
            def merge_diff_rec(left, right, orig, passed_node_id, passed_node_name):
                result = []

                # some nodes are added in rule
                if len(left.children) < len(right.children):
                    # find these nodes
                    for right_child in right.children:
                        found = False
                        for left_child in left.children:
                            if left_child == right_child:
                                found = True
                                break

                        if not found:
                            orig.add(right_child)
                            result += self.__find_terminal(right_child)
                # some nodes are deleted in rule
                elif len(left.children) > len(right.children):
                    for left_child in left.children:
                        found = False
                        # try to find the same symbol in right side of rule
                        for right_child in right.children:
                            if left_child == right_child:
                                found = True
                                break

                        # if such symbol is not found it means that this symbol should be deleted
                        if not found:
                            # find and remove such symbol
                            for inx in range(len(orig.children)):
                                orig_child = orig.children[inx]
                                if self.__ndeep_eq(left_child, orig_child) and orig_child.id == passed_node_id:
                                    orig.children.pop(inx)
                                    self.__delete_terminal_node(orig_child)
                                    break
                # if nodes are the same
                elif len(left.children) == len(right.children):
                    orig_children = []

                    left_inx, right_inx, orig_inx = 0, 0, 0

                    # modify case
                    if len(left.children) == len(right.children) == 0 and \
                        passed_node_id and orig.terminal and orig.id == passed_node_id:
                        orig.__dict__.update(**kwargs)

                    # no need id if name is None, but it's not set to None before, because
                    # it need for checking modify case
                    if passed_node_name is None:
                        passed_node_id = None

                    while left_inx < len(left.children):
                        left_child  = left.children[left_inx]
                        right_child = right.children[right_inx]
                        orig_child  = orig.children[orig_inx]

                        while orig_inx < len(orig.children):
                            cmp_result = Rule.__ndeep_eq(left_child, orig_child)
                            dfs_result = Rule.__dfs_by_id(orig_child, passed_node_name, passed_node_id)
                            in_context = (orig_child.name, orig_child.terminal) in self.context

                            if cmp_result and \
                                    (passed_node_id is None or \
                                     not passed_node_id is None and (dfs_result or in_context)):
                                break

                            orig_inx += 1
                            orig_child = orig.children[orig_inx]

                        if len(orig.children) == orig_inx:
                            break

                        if left_child != right_child:
                            orig.children[orig_inx] = None
                            self.__delete_terminal_node(orig_child)

                            # substitute the node from right tree
                            orig.children[orig_inx] = right_child
                            orig_child = right_child
                            right_child.parent = orig

                            if not left_child.terminal:
                                result += self.__find_terminal(orig_child)

                        orig_children.append(orig_child)

                        left_inx += 1
                        right_inx += 1
                        orig_inx += 1

                    # We don't need the id below the objects with pointed name,
                    # because there is no such nodes and hence there is no such id.
                    if orig.name == passed_node_name:
                        passed_node_name = None

                    for left_child, right_child, orig_child in zip(left.children, right.children, orig_children):
                        result.extend(merge_diff_rec(left_child, right_child, orig_child, passed_node_id, passed_node_name))

                return result

            result = merge_diff_rec(left_node, right_node, node, node_id, node_name)

            for n in result:
                n().handle_id()
                n().type = self.type

                OBJECTS[n().name][n().id] = n
                # That is a case when diamond inheritance is applied
                if n().name != n().type:
                    OBJECTS[n().type][n().id] = n

            if len(result) == 1:
                result[0]().__dict__.update(**kwargs)
                return result[0]
            else:
                return result

        return None