Example #1
0
    def _add_terminal_prop_stmts(self, prop):
        """Add test case statements for leaf or leaf-list."""
        path = self._get_element_path(prop)
        if is_leaflist_prop(prop):
            path = '{}[0]'.format(path)
            value = self._get_value(prop)
            if isinstance(value, BitsValue):
                return
                # # ConfD internal error for leaflist of bits
                # path, value = self._render_bits_value(path, value.val)
                # self.stmts.add_assignment(path, value)
            self._add_declaration_stmt(prop)
            self._add_leaflist_append_stmts(prop)
        else:
            value = self._get_value(prop)
            if isinstance(value, BitsValue):
                if self.lang == 'py' and is_union_prop(prop):
                    # add additional dec, assignment stmt
                    # for UnionType contains Bits
                    dec_obj = self._get_element_path(value.type_spec)
                    dec = get_qn(self.lang, value.type_spec)
                    self.stmts.add_assignment(path, dec_obj)
                    self.stmts.add_declaration(dec_obj, dec)

                path, value = self._render_bits_value(path, value.val)

            self.stmts.add_assignment(path, value)
Example #2
0
    def _add_terminal_prop_stmts(self, prop):
        """Add test case statements for leaf or leaf-list."""
        path = self._get_element_path(prop)
        if is_leaflist_prop(prop):
            path = '{}[0]'.format(path)
            value = self._get_value(prop)
            if isinstance(value, BitsValue):
                return
                # # ConfD internal error for leaflist of bits
                # path, value = self._render_bits_value(path, value.val)
                # self.stmts.add_assignment(path, value)
            self._add_declaration_stmt(prop)
            self._add_leaflist_append_stmts(prop)
        else:
            value = self._get_value(prop)
            if isinstance(value, BitsValue):
                if self.lang == 'py' and is_union_prop(prop):
                    # add additional dec, assignment stmt
                    # for UnionType contains Bits
                    dec_obj = self._get_element_path(value.type_spec)
                    dec = get_qn(self.lang, value.type_spec)
                    self.stmts.add_assignment(path, dec_obj)
                    self.stmts.add_declaration(dec_obj, dec)

                path, value = self._render_bits_value(path, value.val)

            self.stmts.add_assignment(path, value)
 def _handle_identity(self):
     """Chose and return identity from available derived identities.
     Identity could come from different bundle.
     """
     identities = set()
     self._collect_identities(self.type_spec, identities)
     identity = choice(list(identities))
     identity_value = '{}()'.format(get_qn(self.lang, identity))
     return IdentityValue(val=identity_value, identity=identity)
Example #4
0
    def _add_declaration_stmt(self, element):
        """Add declaration statements."""
        obj_name = get_obj_name(element)

        if isinstance(element, (atypes.Bits, atypes.Class)):
            value = get_qn(self.lang, element)
            self.stmts.add_declaration(obj_name, value)
        else:
            # add dec stmt for bits value
            value = self._get_value(element)
            self.stmts.add_assignment(obj_name, value)
            if isinstance(value, BitsValue):
                value = value.type_spec
                self.stmts.add_declaration(obj_name, value)
Example #5
0
    def _add_declaration_stmt(self, element):
        """Add declaration statements."""
        obj_name = get_obj_name(element)

        if isinstance(element, (atypes.Bits, atypes.Class)):
            value = get_qn(self.lang, element)
            self.stmts.add_declaration(obj_name, value)
        else:
            # add dec stmt for bits value
            value = self._get_value(element)
            self.stmts.add_assignment(obj_name, value)
            if isinstance(value, BitsValue):
                value = value.type_spec
                self.stmts.add_declaration(obj_name, value)
Example #6
0
 def _add_reference_stmts(self, prop):
     """Add reference statements and its requisites."""
     refprop, refclass = self._get_reference_prop(prop)
     top_class = get_top_class(prop)
     top_refclass = get_top_class(refprop)
     if top_class != top_refclass:
         top_refclass_name = get_qn(self.lang, top_refclass)
         self.ref_top_classes[top_refclass_name] = top_refclass
         self._add_mandatory_stmts(top_refclass)
         self._add_declaration_stmt(top_refclass)
     # addjust the key value in leafref path
     self._add_leafref_path_key_stmts(prop)
     self._add_list_stmts(refclass)
     self._add_prop_stmts(refprop)
     self._add_reference_stmt(prop, refprop)
Example #7
0
 def _add_reference_stmts(self, prop):
     """Add reference statements and its requisites."""
     refprop, refclass = self._get_reference_prop(prop)
     top_class = get_top_class(prop)
     top_refclass = get_top_class(refprop)
     if top_class != top_refclass:
         top_refclass_name = get_qn(self.lang, top_refclass)
         self.ref_top_classes[top_refclass_name] = top_refclass
         self._add_mandatory_stmts(top_refclass)
         self._add_declaration_stmt(top_refclass)
     # addjust the key value in leafref path
     self._add_leafref_path_key_stmts(prop)
     self._add_list_stmts(refclass)
     self._add_prop_stmts(refprop)
     self._add_reference_stmt(prop, refprop)
Example #8
0
    def _print_crud_read_stmts(self, top_class):
        top_obj_name = get_obj_name(top_class)
        read_obj_name = '{}_read'.format(top_obj_name)
        filter_obj_name = '{}_filter'.format(top_obj_name)
        qn = get_qn(self.lang, top_class)
        self._print_logging('Reading {}...'.format(top_obj_name))
        self._write_end(self.declaration_fmt.format(filter_obj_name, qn))

        fmt = self._get_crud_fmt('read')
        stmt = fmt.format(filter_obj_name)
        fmt = self.read_ret_fmt
        if self.lang == 'py':
            self._write_end(fmt.format(read_obj_name, stmt))
        elif self.lang == 'cpp':
            self._write_end('auto read_unique_ptr = {}'.format(stmt))
            self._write_end('CHECK( read_unique_ptr != nullptr)')
            self._write_end(fmt.format(read_obj_name, qn, 'read_unique_ptr'))
Example #9
0
    def _print_crud_read_stmts(self, top_class):
        top_obj_name = get_obj_name(top_class)
        read_obj_name = '{}_read'.format(top_obj_name)
        filter_obj_name = '{}_filter'.format(top_obj_name)
        qn = get_qn(self.lang, top_class)
        self._print_logging('Reading {}...'.format(top_obj_name))
        self._write_end(self.declaration_fmt.format(filter_obj_name, qn))

        fmt = self._get_crud_fmt('read')
        stmt = fmt.format(filter_obj_name)
        fmt = self.read_ret_fmt
        if self.lang == 'py':
            self._write_end(fmt.format(read_obj_name, stmt))
        elif self.lang == 'cpp':
            self._write_end('auto read_shared_ptr = {}'.format(stmt))
            self._write_end('CHECK( read_shared_ptr != nullptr)')
            self._write_end(fmt.format(read_obj_name, qn, 'read_shared_ptr'))
Example #10
0
 def _handle_enum(self):
     """Chose an return enum literal."""
     literal = choice(self.type_spec.literals)
     qn = get_qn(self.lang, self.type_spec)
     return self.nmsp_sep.join([qn, literal.name])