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

JUNOS - ValueError: Can't convert with callable None #1932

Closed
1 task done
teresalves opened this issue May 23, 2023 · 3 comments
Closed
1 task done

JUNOS - ValueError: Can't convert with callable None #1932

teresalves opened this issue May 23, 2023 · 3 comments

Comments

@teresalves
Copy link

Description of Issue/Question

Note: Please check https://guides.github.com/features/mastering-markdown/
to see how to properly format your request.

Did you follow the steps from https://github.com/napalm-automation/napalm#faq

(Place an x between the square brackets where applicable)

  • Yes
  • [] No

Setup

napalm version

(Paste verbatim output from pip freeze | grep napalm between quotes below)

napalm==4.0.0

Network operating system version

(Paste verbatim output from show version - or equivalent - between quotes below)

Model: vmx
Junos: 17.2R1.13
JUNOS OS Kernel 64-bit  [20170523.350481_builder_stable_10]
JUNOS OS libs [20170523.350481_builder_stable_10]
JUNOS OS runtime [20170523.350481_builder_stable_10]
JUNOS OS time zone information [20170523.350481_builder_stable_10]
JUNOS network stack and utilities [20170601.185252_builder_junos_172_r1]
JUNOS modules [20170601.185252_builder_junos_172_r1]
JUNOS mx modules [20170601.185252_builder_junos_172_r1]
JUNOS libs [20170601.185252_builder_junos_172_r1]
JUNOS OS libs compat32 [20170523.350481_builder_stable_10]
JUNOS OS 32-bit compatibility [20170523.350481_builder_stable_10]
JUNOS libs compat32 [20170601.185252_builder_junos_172_r1]
JUNOS runtime [20170601.185252_builder_junos_172_r1]
JUNOS Packet Forwarding Engine Simulation Package [20170601.185252_builder_junos_172_r1]
JUNOS py extensions [20170601.185252_builder_junos_172_r1]
JUNOS py base [20170601.185252_builder_junos_172_r1]
JUNOS OS vmguest [20170523.350481_builder_stable_10]
JUNOS OS crypto [20170523.350481_builder_stable_10]
JUNOS mx libs compat32 [20170601.185252_builder_junos_172_r1]
JUNOS mx runtime [20170601.185252_builder_junos_172_r1]
JUNOS common platform support [20170601.185252_builder_junos_172_r1]
JUNOS mx libs [20170601.185252_builder_junos_172_r1]
JUNOS mtx Data Plane Crypto Support [20170601.185252_builder_junos_172_r1]
JUNOS daemons [20170601.185252_builder_junos_172_r1]
JUNOS mx daemons [20170601.185252_builder_junos_172_r1]
JUNOS Services URL Filter package [20170601.185252_builder_junos_172_r1]
JUNOS Services TLB Service PIC package [20170601.185252_builder_junos_172_r1]

Steps to Reproduce the Issue

Get a junos router that contains "multihop" or "cluster" in the bgp config

Error Traceback

(Paste the complete traceback of the exception between quotes below)

/usr/lib/python3/dist-packages/napalm/junos/junos.py:1316: in get_bgp_config
    {key: napalm.base.helpers.convert(datatype, value, default)}
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

to = None, who = 'multihop', default = None

    def convert(to: Callable[[T], R], who: Optional[T], default: Optional[R] = None) -> R:
        """
        Converts data to a specific datatype.
        In case of error, will return a default value.
    
        :param to:      datatype to be casted to.
        :param who:     value to cast.
        :param default: default value to return in case of an error with the conversion function.
        :return:        the result of the cast or a default value.
        """
        if default is None:
            # Mypy is currently unable to resolve the Optional[R] correctly, therefore the following
            # assignments to 'default' need a 'type: ignore' statement.
            # Ref: https://github.com/python/mypy/issues/8708
            if to in [str, ip, mac]:
                default = ""  # type: ignore
            elif to in [float, int]:
                default = 0  # type: ignore
            elif to == bool:
                default = False  # type: ignore
            elif to == list:
                default = []  # type: ignore
            else:
                print("ERROR for " + str(who))
>               raise ValueError(
                    f"Can't convert with callable {to} - no default is defined for this type."
                )
E               ValueError: Can't convert with callable None - no default is defined for this type.

/usr/lib/python3/dist-packages/napalm/base/helpers.py:465: ValueError
@teresalves
Copy link
Author

Related to this issue as well: #1754

@teresalves
Copy link
Author

The code keeps breaking on this line: https://github.com/napalm-automation/napalm/blob/develop/napalm/junos/junos.py#L1339
when there is a key that is not included in the GROUP_FIELDS_DATATYPE_MAP
In particular, for the group names "multihop" and "cluster" this is a problem because it will inevitably show up in the router configs, but the datatype will always be None, which will provoke this error:
ValueError: Can't convert with callable None - no default is defined for this type.
originating from here.

In previous versions, this convert function was not doing the type checks, so if it was just returning None. The value for this case is irrelevant because both are deleted from the config further (here and here), respectively. Their existence in the config is temporary and not necessary - it is only used to produce/update other values (here and here)

@teresalves
Copy link
Author

PR: #1931

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants