Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Inconsistent attribute value when using number pool #66

Closed
BaptisteGi opened this issue Oct 10, 2024 · 5 comments · Fixed by #184
Closed

bug: Inconsistent attribute value when using number pool #66

BaptisteGi opened this issue Oct 10, 2024 · 5 comments · Fixed by #184
Assignees
Labels
type/bug Something isn't working as expected

Comments

@BaptisteGi
Copy link
Contributor

Component

Python SDK

Infrahub SDK version

0.14

Current Behavior

When I populate a number using a pool the object then contains a dict { "value": 1000 }

Expected Behavior

I expect the value field to contain the actual value (e.g. 1000) instead of a dict with again value key ({ "value": 1000 })

Steps to Reproduce

  • invoke demo.build demo.start demo.load-infra-schema demo.load-infra-data
  • Open a Python interpreter with SDK installed
  • Run the following code
from infrahub_sdk import InfrahubClient, Config
from infrahub_sdk.protocols import CoreNumberPool

class MyClassSoICanDoAsyncStuff:
    def __init__(self) -> None:
        self.client: InfrahubClient =  InfrahubClient(config=Config(api_token="06438eb2-8019-4776-878c-0941b1f1d1ec"), address="http://localhost:8000")

    async def create_number_pool(self) -> None:
        # Create number pool
        number_pool: CoreNumberPool = await self.client.create(
            kind="CoreNumberPool",
            name="My Number Pool",
            node="InfraVLAN",
            node_attribute="vlan_id",
            start_range=1000,
            end_range=1999
        )

        # Save it
        await number_pool.save()
        self.number_pool = number_pool

    async def create_vlans(self) -> None:
        # Create VLAN without pool
        vlan = await self.client.create(
            kind="InfraVLAN",
            name="my-vlan-without-pool",
            vlan_id=2000,
            description="My vlan production",
            status="active",
            role="server"
        )

        await vlan.save()

        print(f"VLAN ID = {vlan.vlan_id.value} (without pool)")

        # Create VLAN with pool
        vlan = await self.client.create(
            kind="InfraVLAN",
            name="my-vlan-with-pool",
            vlan_id=self.number_pool,
            description="My vlan production",
            status="active",
            role="server"
        )

        await vlan.save()

        print(f"VLAN ID = {vlan.vlan_id.value} (with pool)")


myclass = MyClassSoICanDoAsyncStuff()
await myclass.create_number_pool()
await myclass.create_vlans()
  • This yield the following results
VLAN ID = 2000 (without pool)
VLAN ID = {'value': 1000} (with pool)

Additional Information

No response

@BaptisteGi BaptisteGi added the type/bug Something isn't working as expected label Oct 10, 2024
@gmazoyer
Copy link
Contributor

I'm unable to reproduce this issue with the SDK v1.0.1. I wonder if this has been fixed alongside another issue somehow. Can you confirm if you still observe this issue?

@exalate-issue-sync exalate-issue-sync bot added the state/need-more-info This issue needs more information label Dec 4, 2024
@BaptisteGi
Copy link
Contributor Author

@gmazoyer I faced that one with SDK in v1.1.0

> pip show infrahub-sdk
Name: infrahub-sdk
Version: 1.1.0
Summary: Python Client to interact with Infrahub

@gmazoyer
Copy link
Contributor

So it turns out it's a difference of behaviour between the sync and async code. I was testing with the sync one, hence not seeing the same results. I'll have a deeper look into the async code to fix it.

@gmazoyer gmazoyer removed the state/need-more-info This issue needs more information label Dec 27, 2024
@BaptisteGi
Copy link
Contributor Author

@gmazoyer I'm having a weird one here. Using the same generator, when I run it using infrahubctl I still face this issue:

infrahubctl generator dedicated_internet_generator service_identifier="SRV-123"

Even tho I have the latest version of the SDK:

> infrahubctl version
Infrahub: v1.1.1
Python SDK: v1.1.0

However running the same piece of code from infrahub (from proposed change ...) I don't have the issue ...

Is it in the realm of possible that this could behave differently between infrahubctl and infrahub?

@gmazoyer
Copy link
Contributor

gmazoyer commented Jan 8, 2025

The fix has been published in release 1.3.0 of the Python SDK. I believe Infrahub 1.1.1 uses an even newer version than this one so it should have the fix too. That said, you seem to run CTL with SDK 1.1.0, could this be the cause of the discrepancy that you observe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants