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

Decompile fails to escape backslashes in regex strings resulting in incorrect recompile #291

Closed
nutken opened this issue Feb 28, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@nutken
Copy link

nutken commented Feb 28, 2024

Describe the bug
A Simple.multiline type profile variable with a regex validation string including tokens such as \r, \n, \t do not get properly escaped during decompile. Recompiling the generated blueprint results in an incorrect validation string. A subsequent decompile of the recompiled blueprint will result in failure.

Branch/Container
Tag v3.7.2.1

To Reproduce
Create a BP with a multiline profile variable. Configure a regex validation string which contains tokens such as \r, \n, \t.
Decompile blueprint and observe the generated regex value for that variable in the blueprint.py. You will see the tokens are not escaped (ie, \r, \n, \t, etc). Compile generated blueprint and observe the incorrect regex in the GUI. Likewise, decompile this blueprint and observe the decompile fails.

Expected behavior
The blueprint should be decompiled such that the resulting output can be compiled to produce a functionally equivalent blueprint.

Findings/Troubleshooting Done
If the generated regex string were a raw string, the issue should not occur.

Screenshots
Original multi-line field DSL (created with escaped tokens)
image
Original multi-line field in GUI (token present in regex)
image

Decompiled multi-line field DSL(tokens not escaped)
image
Recompiled multi-line field in GUI (tokens not visible in regex)
image

** System Configuration:**
Python 3.11.6 / Mac OS X
PC 2023.04 / Calm 3.7.2.1

Additional context
Add any other context about the problem here.

@nutken nutken added the bug Something isn't working label Feb 28, 2024
dwivediprab pushed a commit that referenced this issue Mar 15, 2024
### Summary
Include static ip address assosciated with nics in the schema
open issue: #213
decompiled the blueprint with the following nic config:
<img width="1182" alt="Screenshot 2023-10-08 at 3 06 55 PM"
src="https://github.com/ideadevice/calm-dsl/assets/89129891/34eed26b-3a94-43df-a92f-c2a9d3fe492e">

following is the output after decompiling
```
# THIS FILE IS AUTOMATICALLY GENERATED.
# Disclaimer: Please test this file before using in production.
"""
Generated blueprint DSL (.py)
"""

import json  # no_qa
import os  # no_qa

from calm.dsl.builtins import *  # no_qa

# Secret Variables

BP_CRED_c1_PASSWORD = read_local_file("BP_CRED_c1_PASSWORD")

# Credentials
BP_CRED_c1 = basic_cred(
    "admin",
    BP_CRED_c1_PASSWORD,
    name="c1",
    type="PASSWORD",
    default=True,
)

class Service1(Service):

    pass

class vmcalm_timeResources(AhvVmResources):

    memory = 1
    vCPUs = 1
    cores_per_vCPU = 1
    disks = [
        AhvVmDisk.Disk.Scsi.cloneFromImageService(
            "Centos7HadoopMaster.qcow2", bootable=True
        )
    ]
    nics = [
        AhvVmNic.NormalNic.ingress(
            "abc", cluster="auto_cluster_prod_4f683249d95b", ip_endpoints=["10.1.0.9"]
        ),
        AhvVmNic.NormalNic.ingress(
            "vlan.154", cluster="auto_cluster_prod_4f683249d95b"
        ),
    ]

class vmcalm_time(AhvVm):

    name = "vm-@@{calm_time}@@"
    resources = vmcalm_timeResources
    cluster = Ref.Cluster(name="auto_cluster_prod_4f683249d95b")

class VM1(Substrate):

    account = Ref.Account("NTNX_LOCAL_AZ")
    os_type = "Linux"
    provider_type = "AHV_VM"
    provider_spec = vmcalm_time

    readiness_probe = readiness_probe(
        connection_type="SSH",
        disabled=True,
        retries="5",
        connection_port=22,
        address="@@{platform.status.resources.nic_list[0].ip_endpoint_list[0].ip}@@",
        delay_secs="0",
    )

class Package1(Package):

    services = [ref(Service1)]

class d2d34557_deployment(Deployment):

    min_replicas = "1"
    max_replicas = "1"
    default_replicas = "1"

    packages = [ref(Package1)]
    substrate = ref(VM1)

class Default(Profile):

    environments = [Ref.Environment(name="Default Environment")]
    deployments = [d2d34557_deployment]

    @action
    def UntitledAction1(name="Untitled Action1"):

        CalmTask.Exec.ssh(
            name="Task1",
            filename=os.path.join(
                "scripts", "Profile_Default_Action_UntitledAction1_Task_Task1.sh"
            ),
            target=ref(Service1),
        )

class test_nic_bp(Blueprint):

    services = [Service1]
    packages = [Package1]
    substrates = [VM1]
    profiles = [Default]
    credentials = [BP_CRED_c1]

class BpMetadata(Metadata):

    categories = {"TemplateType": "Vm"}

```
also verified that the compile works correctly on the above decompiled
bp, following is the output of compilation

(cherry picked from commit acfb95a0ece7de6234347772fe2b350a26c43a81)
@dwivediprab
Copy link
Contributor

Issue is fixed in DSL v3.7.2.2 release, Hence closing it.

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

No branches or pull requests

3 participants