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

Unable to provision a config-template with local data source via the REST API #13506

Closed
desnoe opened this issue Aug 18, 2023 · 7 comments · Fixed by #13869
Closed

Unable to provision a config-template with local data source via the REST API #13506

desnoe opened this issue Aug 18, 2023 · 7 comments · Fixed by #13869
Assignees
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@desnoe
Copy link
Contributor

desnoe commented Aug 18, 2023

NetBox version

v3.6.1

Python version

3.11.4

Steps to Reproduce

  1. Start from a fresh NetBox instance, configure an API token and configure these 2 environment variables:
TOKEN=mynetboxtoken
NETBOX_URL=http://my.netbox.url

Please replace with values relevant to your NetBox instance.

  1. Create /etc/netbox/templates directory on the NetBox instance and create a trivial Jinja2 template to the NetBox instance in it:
mkdir -p /etc/netbox/templates
echo 'This is a simple Jinja2 template.' > /etc/netbox/templates/basic.j2
  1. Provision a new local data source using the REST API:
curl -X POST \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
$NETBOX_URL/api/core/data-sources/ \
--data '{
    "name": "templates",
    "type": "local",
    "source_url": "file:///etc/netbox/templates",
    "enabled": true
}'

Make sure it is correctly created and note down its id:

DATASOURCE_ID=1

Please replace with the id of the created object.

  1. Sync this new local data source using the REST API:
curl -X POST \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
$NETBOX_URL/api/core/data-sources/$DATASOURCE_ID/sync/ \
  1. Provision a new config template based on the basic.j2 Jinja2 template in this local data source using the REST API:
curl -X POST \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
$NETBOX_URL/api/extras/config-templates/ \
--data '{
    "name": "basic",
    "template_code": "Will be overwritten after data_file is synced",
    "data_source": {"name": "templates"},
    "data_file": {"path": "basic.j2"}
}'

Make sure it is correctly created and note down its id:

CONFIGTEMPLATE_ID=1

Please replace with the id of the created object.

  1. Sync this new config template:
curl -X POST \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
$NETBOX_URL/api/extras/config-templates/$CONFIGTEMPLATE_ID/sync/

Now, the config template can be used on a device or device-role.

Expected Behavior

At step 6, I expect data_file to be correctly populated in the JSON data of the POST response. I should get:

{
    ...
    "data_file": {
        ...
        "path": "basic.j2"
    },
    ...
}

Observed Behavior

At step 6, the JSON data I'm really receiving in the POST response is:

{
    ...
    "data_file": null,
    ...
}
@desnoe desnoe added the type: bug A confirmed report of unexpected behavior in the application label Aug 18, 2023
@desnoe
Copy link
Contributor Author

desnoe commented Aug 18, 2023

Check this link for the discussion on Slack:
https://netdev-community.slack.com/archives/C01P0FRSXRV/p1692216027078659

@jeremystretch
Copy link
Member

Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.

@jeremystretch jeremystretch added the status: revisions needed This issue requires additional information to be actionable label Aug 21, 2023
@jeremystretch
Copy link
Member

This issue is being closed as no further information has been provided. If you would like to revisit this topic, please first modify your original post to include all the requested detail, and then ask that the issue be reopened.

@jeremystretch jeremystretch closed this as not planned Won't fix, can't repro, duplicate, stale Aug 28, 2023
@desnoe
Copy link
Contributor Author

desnoe commented Sep 14, 2023

I have added more details to reproduce the problem, step by step, and I hope this will be clear enough. Could you please reopen this issue ?

I also have a bugfix ready.

@jeremystretch jeremystretch removed the status: revisions needed This issue requires additional information to be actionable label Sep 15, 2023
@jeremystretch jeremystretch reopened this Sep 15, 2023
@jeremystretch
Copy link
Member

This occurs because the data_source and data_file fields on ConfigTemplateSerializer are read-only. I can't say at this point what the reasoning was for preventing write operations to these fields.

@desnoe I'll assign this to you as you mention having a fix prepared. Thanks!

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation severity: medium Results in substantial degraded or broken functionality for specfic workflows labels Sep 21, 2023
@desnoe
Copy link
Contributor Author

desnoe commented Sep 22, 2023

Thanks @jeremystretch, I just opened the PR.
I only modified data_filewhich was read-only, data_source is not read-only in ConfigTemplateSerializer and is already working fine through the API.

@jeremystretch
Copy link
Member

I only modified data_file which was read-only, data_source is not read-only in ConfigTemplateSerializer and is already working fine through the API.

My mistake, I must have misread the code.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants