Skip to content

bug: Issue when saving prefix pool as a relationship to a node #562

@BaptisteGi

Description

@BaptisteGi

Component

Python SDK

Infrahub SDK version

1.14.0

Current Behavior

I have an object (Fabric) that has a relationship toward a resource pool. When I run my script that creates the resource pool and then the fabric object (with relationship to the resource pool), the fabric upsert yields an exception:

infrahubctl run fab/fabric.py --branch test3         
['DatacenterFabricUpsert'] IPPrefixPool: fabric_prefix_pool | A prefixlen or a default_value must be provided to allocate a new prefix

Somehow it looks like it tries to allocate a prefix out of my pool even tho I just saved a fabric object.

Expected Behavior

I expect the mutation to pass or fail with a different message...

Steps to Reproduce

  • Spin infrahub
  • Load the following schema
---
# yaml-language-server: $schema=https://schema.infrahub.app/infrahub/schema/latest.json
version: "1.0"

nodes:
  - name: Fabric
    namespace: Datacenter
    attributes:
      - name: name
        kind: Text
        unique: true
        order_weight: 1000
    relationships:
      - name: resource_pool
        peer: CoreResourcePool
        description: Resource pool to use for Fabric
        cardinality: one
        kind: Attribute
        direction: outbound
        order_weight: 1400
        optional: true

  - name: IPAddress
    namespace: Ipam
    description: IP Address
    label: IP Address
    icon: mdi:ip
    include_in_menu: false
    order_by:
      - address__value
    display_labels:
      - address__value
    inherit_from:
      - BuiltinIPAddress
    uniqueness_constraints:
      - [address__value, ip_namespace]
    human_friendly_id:
      - address__value
      - ip_namespace__name__value
    attributes:
      - name: fqdn
        label: FQDN
        kind: Text
        optional: true
        # https://stackoverflow.com/questions/11809631/fully-qualified-domain-name-validation
        regex: (?=^.{1,253}$)(^(((?!-)[a-zA-Z0-9-]{1,63}(?<!-))|((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63})$)

  - name: Prefix
    namespace: Ipam
    description: IPv4 or IPv6 network (with mask)
    icon: mdi:ip-network
    include_in_menu: false
    label: Prefix
    order_by:
      - prefix__value
    display_labels:
      - prefix__value
    inherit_from:
      - BuiltinIPPrefix
    uniqueness_constraints:
      - [prefix__value, ip_namespace]
    human_friendly_id:
      - prefix__value
      - ip_namespace__name__value
    attributes:
      - name: status
        kind: Dropdown
        choices:
          - name: active
            label: Active
          - name: deprecated
            label: Deprecated
          - name: reserved
            label: Reserved
      - name: role
        kind: Dropdown
        optional: true
        choices:
          - name: loopback
            label: Loopback
            description: Represents internal communications.
            color: "#B0A8B9"
          - name: management
            label: Management
            description: Handles administrative operations.
            color: "#AEC6CF"
          - name: public
            label: Public
            description: Public facing network.
            color: "#FDFD96"
          - name: server
            label: Server
            description: Dedicated to server functions.
            color: "#77DD77"
          - name: supernet
            label: Supernet
            description: Covers multiple networks
            color: "#FFB347"
          - name: technical
            label: Technical
            description: Focused on technical aspects.
            color: "#9678B6"
          - name: loopback-vtep
            label: Loopback VTEP
            description: Facilitates virtualized network communications within loopback configurations.
            color: "#CDB4DB"
  • Load the following object file
---
apiVersion: infrahub.app/v1
kind: Object
spec:
  kind: IpamPrefix
  data:
    - status: active
      prefix: 10.0.0.0/8
      member_type: prefix
      description: Fabric prefix
  • Create the following python script
import logging

from infrahub_sdk import InfrahubClient


async def run(
    client: InfrahubClient, log: logging.Logger, branch: str, **kwargs
) -> None:
    # Create a new prefix pool
    resource_pool = await client.create(
        kind="CoreIPPrefixPool",
        name="fabric_prefix_pool",
        ip_namespace=["default"],
        resources=["10.0.0.0/8"],
    )

    await resource_pool.save(allow_upsert=True)

    # Create a new fabric
    fabric = await client.create(
        kind="DatacenterFabric", name="Fabric1", resource_pool=resource_pool
    )
    await fabric.save(allow_upsert=True)
  • Use Infrahubctl to run the script
infrahubctl run fabric.py

=> ['DatacenterFabricUpsert'] IPPrefixPool: fabric_prefix_pool | A prefixlen or a default_value must be provided to allocate a new prefix

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    state/need-more-infoThis issue needs more informationtype/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions