cisco_node_utils_mgx 2.1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rubocop.yml +96 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +676 -0
- data/CONTRIBUTING.md +43 -0
- data/Gemfile +10 -0
- data/LICENSE +201 -0
- data/README.md +246 -0
- data/Rakefile +44 -0
- data/SUPPORT.md +3 -0
- data/bin/.rubocop.yml +18 -0
- data/bin/check_metric_limits.rb +109 -0
- data/bin/git/hooks/commit-msg/enforce_style +89 -0
- data/bin/git/hooks/hook_lib +115 -0
- data/bin/git/hooks/hooks-wrapper +38 -0
- data/bin/git/hooks/post-flow-hotfix-start/update-version +24 -0
- data/bin/git/hooks/post-flow-release-finish/update-version +29 -0
- data/bin/git/hooks/post-flow-release-start/update-version +19 -0
- data/bin/git/hooks/post-merge/update-hooks +6 -0
- data/bin/git/hooks/post-rewrite/update-hooks +6 -0
- data/bin/git/hooks/pre-commit/check_unstaged_changes +18 -0
- data/bin/git/hooks/pre-commit/rubocop +25 -0
- data/bin/git/hooks/pre-commit/validate-diffs +45 -0
- data/bin/git/hooks/pre-commit/validate-yaml +18 -0
- data/bin/git/hooks/pre-push/check-changelog +24 -0
- data/bin/git/hooks/pre-push/rubocop +7 -0
- data/bin/git/update-hooks +123 -0
- data/bin/show_running_yang.rb +233 -0
- data/cisco_node_utils.gemspec +41 -0
- data/docs/README-develop-best-practices.md +521 -0
- data/docs/README-develop-node-utils-APIs.md +570 -0
- data/docs/README-maintainers.md +77 -0
- data/docs/README-test-execution.md +57 -0
- data/docs/README-utilities.md +14 -0
- data/docs/agent_files.png +0 -0
- data/docs/cisco_node_utils.yaml.example +36 -0
- data/docs/template-router.rb +123 -0
- data/docs/template-test_router.rb +104 -0
- data/ext/mkrf_conf.rb +63 -0
- data/lib/.rubocop.yml +18 -0
- data/lib/cisco_node_utils/aaa_authentication_login.rb +95 -0
- data/lib/cisco_node_utils/aaa_authentication_login_service.rb +138 -0
- data/lib/cisco_node_utils/aaa_authorization_service.rb +156 -0
- data/lib/cisco_node_utils/ace.rb +467 -0
- data/lib/cisco_node_utils/acl.rb +101 -0
- data/lib/cisco_node_utils/banner.rb +63 -0
- data/lib/cisco_node_utils/bfd_global.rb +305 -0
- data/lib/cisco_node_utils/bgp.rb +988 -0
- data/lib/cisco_node_utils/bgp_af.rb +545 -0
- data/lib/cisco_node_utils/bgp_af_aggr_addr.rb +207 -0
- data/lib/cisco_node_utils/bgp_neighbor.rb +527 -0
- data/lib/cisco_node_utils/bgp_neighbor_af.rb +780 -0
- data/lib/cisco_node_utils/bridge_domain.rb +178 -0
- data/lib/cisco_node_utils/bridge_domain_vni.rb +206 -0
- data/lib/cisco_node_utils/cisco_cmn_utils.rb +444 -0
- data/lib/cisco_node_utils/client/client.rb +238 -0
- data/lib/cisco_node_utils/client/grpc/client.rb +395 -0
- data/lib/cisco_node_utils/client/grpc/ems.proto +148 -0
- data/lib/cisco_node_utils/client/grpc/ems.rb +111 -0
- data/lib/cisco_node_utils/client/grpc/ems_services.rb +49 -0
- data/lib/cisco_node_utils/client/grpc.rb +33 -0
- data/lib/cisco_node_utils/client/nxapi/client.rb +368 -0
- data/lib/cisco_node_utils/client/nxapi.rb +31 -0
- data/lib/cisco_node_utils/client/utils.rb +180 -0
- data/lib/cisco_node_utils/client.rb +35 -0
- data/lib/cisco_node_utils/cmd_ref/README_YAML.md +590 -0
- data/lib/cisco_node_utils/cmd_ref/aaa_auth_login_service.yaml +25 -0
- data/lib/cisco_node_utils/cmd_ref/aaa_authentication_login.yaml +38 -0
- data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +40 -0
- data/lib/cisco_node_utils/cmd_ref/acl.yaml +48 -0
- data/lib/cisco_node_utils/cmd_ref/banner.yaml +11 -0
- data/lib/cisco_node_utils/cmd_ref/bfd_global.yaml +117 -0
- data/lib/cisco_node_utils/cmd_ref/bgp.yaml +383 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +223 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_af_aa.yaml +38 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +174 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +236 -0
- data/lib/cisco_node_utils/cmd_ref/bridge_domain.yaml +49 -0
- data/lib/cisco_node_utils/cmd_ref/bridge_domain_vni.yaml +33 -0
- data/lib/cisco_node_utils/cmd_ref/dhcp_relay_global.yaml +128 -0
- data/lib/cisco_node_utils/cmd_ref/dnsclient.yaml +55 -0
- data/lib/cisco_node_utils/cmd_ref/encapsulation.yaml +25 -0
- data/lib/cisco_node_utils/cmd_ref/evpn_multicast.yaml +12 -0
- data/lib/cisco_node_utils/cmd_ref/evpn_multisite.yaml +18 -0
- data/lib/cisco_node_utils/cmd_ref/evpn_stormcontrol.yaml +18 -0
- data/lib/cisco_node_utils/cmd_ref/evpn_vni.yaml +48 -0
- data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +183 -0
- data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +40 -0
- data/lib/cisco_node_utils/cmd_ref/feature.yaml +126 -0
- data/lib/cisco_node_utils/cmd_ref/hostname.yaml +8 -0
- data/lib/cisco_node_utils/cmd_ref/hsrp_global.yaml +25 -0
- data/lib/cisco_node_utils/cmd_ref/images.yaml +8 -0
- data/lib/cisco_node_utils/cmd_ref/interface.yaml +781 -0
- data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +45 -0
- data/lib/cisco_node_utils/cmd_ref/interface_evpn_multisite.yaml +17 -0
- data/lib/cisco_node_utils/cmd_ref/interface_hsrp_group.yaml +120 -0
- data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +112 -0
- data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +87 -0
- data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +42 -0
- data/lib/cisco_node_utils/cmd_ref/inventory.yaml +45 -0
- data/lib/cisco_node_utils/cmd_ref/ip_multicast.yaml +22 -0
- data/lib/cisco_node_utils/cmd_ref/itd_device_group.yaml +83 -0
- data/lib/cisco_node_utils/cmd_ref/itd_service.yaml +119 -0
- data/lib/cisco_node_utils/cmd_ref/memory.yaml +24 -0
- data/lib/cisco_node_utils/cmd_ref/ntp_auth_key.yaml +10 -0
- data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +27 -0
- data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +34 -0
- data/lib/cisco_node_utils/cmd_ref/object_group.yaml +32 -0
- data/lib/cisco_node_utils/cmd_ref/ospf.yaml +91 -0
- data/lib/cisco_node_utils/cmd_ref/ospf_area.yaml +91 -0
- data/lib/cisco_node_utils/cmd_ref/ospf_area_vlink.yaml +88 -0
- data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +37 -0
- data/lib/cisco_node_utils/cmd_ref/pim.yaml +43 -0
- data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +86 -0
- data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +37 -0
- data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +100 -0
- data/lib/cisco_node_utils/cmd_ref/radius_server_group.yaml +19 -0
- data/lib/cisco_node_utils/cmd_ref/route_map.yaml +601 -0
- data/lib/cisco_node_utils/cmd_ref/show_system.yaml +9 -0
- data/lib/cisco_node_utils/cmd_ref/show_version.yaml +84 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +81 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_group.yaml +9 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +74 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +91 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +57 -0
- data/lib/cisco_node_utils/cmd_ref/snmpnotification.yaml +23 -0
- data/lib/cisco_node_utils/cmd_ref/span_session.yaml +65 -0
- data/lib/cisco_node_utils/cmd_ref/stp_global.yaml +235 -0
- data/lib/cisco_node_utils/cmd_ref/syslog_facility.yaml +10 -0
- data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +34 -0
- data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +45 -0
- data/lib/cisco_node_utils/cmd_ref/system.yaml +7 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_global.yaml +37 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +63 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_server_group.yaml +45 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +64 -0
- data/lib/cisco_node_utils/cmd_ref/upgrade.yaml +38 -0
- data/lib/cisco_node_utils/cmd_ref/vdc.yaml +52 -0
- data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +8 -0
- data/lib/cisco_node_utils/cmd_ref/vlan.yaml +106 -0
- data/lib/cisco_node_utils/cmd_ref/vpc.yaml +233 -0
- data/lib/cisco_node_utils/cmd_ref/vrf.yaml +86 -0
- data/lib/cisco_node_utils/cmd_ref/vrf_af.yaml +139 -0
- data/lib/cisco_node_utils/cmd_ref/vtp.yaml +32 -0
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +114 -0
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +71 -0
- data/lib/cisco_node_utils/cmd_ref/yang.yaml +7 -0
- data/lib/cisco_node_utils/cmd_ref/yum.yaml +68 -0
- data/lib/cisco_node_utils/command_reference.rb +724 -0
- data/lib/cisco_node_utils/configparser_lib.rb +195 -0
- data/lib/cisco_node_utils/constants.rb +40 -0
- data/lib/cisco_node_utils/dhcp_relay_global.rb +302 -0
- data/lib/cisco_node_utils/dns_domain.rb +93 -0
- data/lib/cisco_node_utils/domain_name.rb +82 -0
- data/lib/cisco_node_utils/encapsulation.rb +112 -0
- data/lib/cisco_node_utils/environment.rb +110 -0
- data/lib/cisco_node_utils/evpn_multicast.rb +66 -0
- data/lib/cisco_node_utils/evpn_multisite.rb +96 -0
- data/lib/cisco_node_utils/evpn_stormcontrol.rb +84 -0
- data/lib/cisco_node_utils/evpn_vni.rb +159 -0
- data/lib/cisco_node_utils/exceptions.rb +140 -0
- data/lib/cisco_node_utils/fabricpath_global.rb +405 -0
- data/lib/cisco_node_utils/fabricpath_topology.rb +137 -0
- data/lib/cisco_node_utils/feature.rb +377 -0
- data/lib/cisco_node_utils/hostname.rb +62 -0
- data/lib/cisco_node_utils/hsrp_global.rb +97 -0
- data/lib/cisco_node_utils/interface.rb +2128 -0
- data/lib/cisco_node_utils/interface_channel_group.rb +142 -0
- data/lib/cisco_node_utils/interface_evpn_multisite.rb +72 -0
- data/lib/cisco_node_utils/interface_hsrp_group.rb +557 -0
- data/lib/cisco_node_utils/interface_ospf.rb +378 -0
- data/lib/cisco_node_utils/interface_portchannel.rb +180 -0
- data/lib/cisco_node_utils/interface_service_vni.rb +132 -0
- data/lib/cisco_node_utils/ip_multicast.rb +90 -0
- data/lib/cisco_node_utils/itd_device_group.rb +228 -0
- data/lib/cisco_node_utils/itd_device_group_node.rb +144 -0
- data/lib/cisco_node_utils/itd_service.rb +511 -0
- data/lib/cisco_node_utils/logger.rb +78 -0
- data/lib/cisco_node_utils/name_server.rb +64 -0
- data/lib/cisco_node_utils/node.rb +443 -0
- data/lib/cisco_node_utils/node_util.rb +111 -0
- data/lib/cisco_node_utils/ntp_auth_key.rb +67 -0
- data/lib/cisco_node_utils/ntp_config.rb +83 -0
- data/lib/cisco_node_utils/ntp_server.rb +86 -0
- data/lib/cisco_node_utils/object_group.rb +75 -0
- data/lib/cisco_node_utils/object_group_entry.rb +143 -0
- data/lib/cisco_node_utils/overlay_global.rb +142 -0
- data/lib/cisco_node_utils/pim.rb +131 -0
- data/lib/cisco_node_utils/pim_group_list.rb +109 -0
- data/lib/cisco_node_utils/pim_rp_address.rb +103 -0
- data/lib/cisco_node_utils/platform.rb +217 -0
- data/lib/cisco_node_utils/portchannel_global.rb +347 -0
- data/lib/cisco_node_utils/radius_global.rb +165 -0
- data/lib/cisco_node_utils/radius_server.rb +421 -0
- data/lib/cisco_node_utils/radius_server_group.rb +117 -0
- data/lib/cisco_node_utils/route_map.rb +2540 -0
- data/lib/cisco_node_utils/router_ospf.rb +77 -0
- data/lib/cisco_node_utils/router_ospf_area.rb +416 -0
- data/lib/cisco_node_utils/router_ospf_area_vlink.rb +313 -0
- data/lib/cisco_node_utils/router_ospf_vrf.rb +342 -0
- data/lib/cisco_node_utils/snmp_notification_receiver.rb +176 -0
- data/lib/cisco_node_utils/snmpcommunity.rb +109 -0
- data/lib/cisco_node_utils/snmpgroup.rb +54 -0
- data/lib/cisco_node_utils/snmpnotification.rb +57 -0
- data/lib/cisco_node_utils/snmpserver.rb +132 -0
- data/lib/cisco_node_utils/snmpuser.rb +403 -0
- data/lib/cisco_node_utils/span_session.rb +149 -0
- data/lib/cisco_node_utils/stp_global.rb +676 -0
- data/lib/cisco_node_utils/syslog_facility.rb +64 -0
- data/lib/cisco_node_utils/syslog_server.rb +146 -0
- data/lib/cisco_node_utils/syslog_settings.rb +174 -0
- data/lib/cisco_node_utils/tacacs_global.rb +137 -0
- data/lib/cisco_node_utils/tacacs_server.rb +173 -0
- data/lib/cisco_node_utils/tacacs_server_group.rb +149 -0
- data/lib/cisco_node_utils/tacacs_server_host.rb +216 -0
- data/lib/cisco_node_utils/upgrade.rb +122 -0
- data/lib/cisco_node_utils/vdc.rb +118 -0
- data/lib/cisco_node_utils/version.rb +21 -0
- data/lib/cisco_node_utils/vlan.rb +301 -0
- data/lib/cisco_node_utils/vpc.rb +466 -0
- data/lib/cisco_node_utils/vrf.rb +192 -0
- data/lib/cisco_node_utils/vrf_af.rb +327 -0
- data/lib/cisco_node_utils/vtp.rb +125 -0
- data/lib/cisco_node_utils/vxlan_vtep.rb +286 -0
- data/lib/cisco_node_utils/vxlan_vtep_vni.rb +331 -0
- data/lib/cisco_node_utils/yang.rb +160 -0
- data/lib/cisco_node_utils/yum.rb +213 -0
- data/lib/cisco_node_utils.rb +21 -0
- data/lib/minitest/environment_plugin.rb +31 -0
- data/lib/minitest/log_level_plugin.rb +41 -0
- data/spec/client_spec.rb +7 -0
- data/spec/environment_spec.rb +384 -0
- data/spec/grpc_client_spec.rb +23 -0
- data/spec/isolate/all_clients_spec.rb +9 -0
- data/spec/isolate/grpc_only_spec.rb +16 -0
- data/spec/isolate/no_clients_spec.rb +26 -0
- data/spec/isolate/nxapi_only_spec.rb +16 -0
- data/spec/nxapi_client_spec.rb +42 -0
- data/spec/schema.yaml +82 -0
- data/spec/shared_examples_for_clients.rb +14 -0
- data/spec/spec_helper.rb +91 -0
- data/spec/whitespace_spec.rb +10 -0
- data/spec/yaml_spec.rb +42 -0
- data/tests/.rubocop.yml +18 -0
- data/tests/CSCuxdublin-1.0.0-7.0.3.I3.1.lib32_n9000.rpm +0 -0
- data/tests/basetest.rb +243 -0
- data/tests/ciscotest.rb +577 -0
- data/tests/cmd_config.yaml +75 -0
- data/tests/cmd_config_invalid.yaml +16 -0
- data/tests/n9000_sample-1.0.0-7.0.3.x86_64.rpm +0 -0
- data/tests/noop.rb +7 -0
- data/tests/platform_info.rb +63 -0
- data/tests/tacacs_server.yaml.example +6 -0
- data/tests/test_aaa_authentication_login.rb +243 -0
- data/tests/test_aaa_authentication_login_service.rb +761 -0
- data/tests/test_aaa_authorization_service.rb +874 -0
- data/tests/test_ace.rb +304 -0
- data/tests/test_acl.rb +185 -0
- data/tests/test_banner.rb +85 -0
- data/tests/test_bfd_global.rb +272 -0
- data/tests/test_bgp_af.rb +875 -0
- data/tests/test_bgp_af_aa.rb +108 -0
- data/tests/test_bgp_neighbor.rb +596 -0
- data/tests/test_bgp_neighbor_af.rb +781 -0
- data/tests/test_bridge_domain.rb +198 -0
- data/tests/test_bridge_domain_vni.rb +109 -0
- data/tests/test_client_utils.rb +111 -0
- data/tests/test_cmn_utils.rb +76 -0
- data/tests/test_command_config.rb +206 -0
- data/tests/test_command_reference.rb +669 -0
- data/tests/test_dhcp_relay_global.rb +286 -0
- data/tests/test_dns_domain.rb +123 -0
- data/tests/test_domain_name.rb +96 -0
- data/tests/test_encapsulation.rb +75 -0
- data/tests/test_evpn_multicast.rb +65 -0
- data/tests/test_evpn_multisite.rb +70 -0
- data/tests/test_evpn_stormcontrol.rb +56 -0
- data/tests/test_evpn_vni.rb +131 -0
- data/tests/test_fabricpath_global.rb +246 -0
- data/tests/test_fabricpath_topology.rb +77 -0
- data/tests/test_feature.rb +272 -0
- data/tests/test_grpc.rb +166 -0
- data/tests/test_hostname.rb +64 -0
- data/tests/test_hsrp_global.rb +79 -0
- data/tests/test_interface.rb +1958 -0
- data/tests/test_interface_bdi.rb +80 -0
- data/tests/test_interface_channel_group.rb +131 -0
- data/tests/test_interface_evpn_multisite.rb +94 -0
- data/tests/test_interface_hsrp.rb +134 -0
- data/tests/test_interface_hsrp_group.rb +570 -0
- data/tests/test_interface_ospf.rb +820 -0
- data/tests/test_interface_portchannel.rb +135 -0
- data/tests/test_interface_private_vlan.rb +365 -0
- data/tests/test_interface_service_vni.rb +203 -0
- data/tests/test_interface_svi.rb +210 -0
- data/tests/test_interface_switchport.rb +468 -0
- data/tests/test_ip_multicast.rb +80 -0
- data/tests/test_itd_device_group.rb +145 -0
- data/tests/test_itd_device_group_node.rb +199 -0
- data/tests/test_itd_service.rb +314 -0
- data/tests/test_logger.rb +43 -0
- data/tests/test_name_server.rb +94 -0
- data/tests/test_node.rb +50 -0
- data/tests/test_node_ext.rb +406 -0
- data/tests/test_node_util.rb +119 -0
- data/tests/test_ntp_auth_key.rb +77 -0
- data/tests/test_ntp_config.rb +100 -0
- data/tests/test_ntp_server.rb +146 -0
- data/tests/test_nxapi.rb +236 -0
- data/tests/test_object_group.rb +122 -0
- data/tests/test_overlay_global.rb +108 -0
- data/tests/test_pim.rb +203 -0
- data/tests/test_pim_group_list.rb +147 -0
- data/tests/test_pim_rp_address.rb +155 -0
- data/tests/test_platform.rb +254 -0
- data/tests/test_portchannel_global.rb +322 -0
- data/tests/test_radius_global.rb +108 -0
- data/tests/test_radius_server.rb +377 -0
- data/tests/test_radius_server_group.rb +151 -0
- data/tests/test_route_map.rb +1479 -0
- data/tests/test_router_bgp.rb +1325 -0
- data/tests/test_router_ospf.rb +56 -0
- data/tests/test_router_ospf_area.rb +433 -0
- data/tests/test_router_ospf_area_vlink.rb +298 -0
- data/tests/test_router_ospf_vrf.rb +690 -0
- data/tests/test_snmp_notification_receiver.rb +169 -0
- data/tests/test_snmpcommunity.rb +422 -0
- data/tests/test_snmpgroup.rb +71 -0
- data/tests/test_snmpnotification.rb +91 -0
- data/tests/test_snmpserver.rb +251 -0
- data/tests/test_snmpuser.rb +666 -0
- data/tests/test_span_session.rb +155 -0
- data/tests/test_stp_global.rb +575 -0
- data/tests/test_syslog_facility.rb +80 -0
- data/tests/test_syslog_server.rb +119 -0
- data/tests/test_syslog_settings.rb +123 -0
- data/tests/test_tacacs_global.rb +109 -0
- data/tests/test_tacacs_server.rb +436 -0
- data/tests/test_tacacs_server_group.rb +434 -0
- data/tests/test_tacacs_server_host.rb +427 -0
- data/tests/test_upgrade.rb +105 -0
- data/tests/test_vdc.rb +64 -0
- data/tests/test_vlan.rb +386 -0
- data/tests/test_vlan_private.rb +656 -0
- data/tests/test_vpc.rb +548 -0
- data/tests/test_vrf.rb +248 -0
- data/tests/test_vrf_af.rb +288 -0
- data/tests/test_vtp.rb +278 -0
- data/tests/test_vxlan_vtep.rb +327 -0
- data/tests/test_vxlan_vtep_vni.rb +326 -0
- data/tests/test_yang.rb +369 -0
- data/tests/test_yum.rb +109 -0
- data/tests/upgrade_info.yaml.example +3 -0
- data/tests/yum_package.yaml +94 -0
- metadata +534 -0
@@ -0,0 +1,669 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# November 2014, Glenn F. Matthews
|
4
|
+
#
|
5
|
+
# Copyright (c) 2014-2016 Cisco and/or its affiliates.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require_relative 'basetest'
|
21
|
+
|
22
|
+
require 'tempfile'
|
23
|
+
require_relative '../lib/cisco_node_utils/command_reference'
|
24
|
+
|
25
|
+
# TestCmdRef - Minitest for CommandReference and CmdRef classes.
|
26
|
+
class TestCmdRef < Minitest::Test
|
27
|
+
include Cisco
|
28
|
+
|
29
|
+
def setup
|
30
|
+
@input_file = Tempfile.new('test.yaml')
|
31
|
+
end
|
32
|
+
|
33
|
+
def teardown
|
34
|
+
@input_file.close!
|
35
|
+
end
|
36
|
+
|
37
|
+
def load_file(**args)
|
38
|
+
CommandReference.new(**args, :files => [@input_file.path])
|
39
|
+
end
|
40
|
+
|
41
|
+
def write(string)
|
42
|
+
@input_file.write(string + "\n")
|
43
|
+
@input_file.flush
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_data_sanity
|
47
|
+
# Make sure the actual YAML in our library loads for various platforms
|
48
|
+
CommandReference.new
|
49
|
+
|
50
|
+
CommandReference.new(platform: :nexus,
|
51
|
+
data_formats: [:nxapi_structured, :cli])
|
52
|
+
|
53
|
+
CommandReference.new(platform: :nexus,
|
54
|
+
product: 'N9K-C9396PX',
|
55
|
+
data_formats: [:nxapi_structured, :cli])
|
56
|
+
|
57
|
+
CommandReference.new(platform: :nexus,
|
58
|
+
product: 'N7K-C7010',
|
59
|
+
data_formats: [:nxapi_structured, :cli])
|
60
|
+
|
61
|
+
CommandReference.new(platform: :nexus,
|
62
|
+
product: 'N3K-C3064PQ-10GE',
|
63
|
+
data_formats: [:nxapi_structured, :cli])
|
64
|
+
|
65
|
+
CommandReference.new(platform: :ios_xr,
|
66
|
+
data_formats: [:cli])
|
67
|
+
|
68
|
+
CommandReference.new(platform: :ios_xr,
|
69
|
+
product: 'R-IOSXRV9000-CH',
|
70
|
+
data_formats: [:cli])
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_load_empty_file
|
74
|
+
# should load successfully but yield an empty hash
|
75
|
+
reference = load_file
|
76
|
+
assert_empty(reference)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_load_whitespace_only
|
80
|
+
write(' ')
|
81
|
+
reference = load_file
|
82
|
+
assert_empty(reference)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_load_not_valid_yaml
|
86
|
+
# The control characters embedded below are not permitted in YAML.
|
87
|
+
write("
|
88
|
+
name\a\e\b\f:
|
89
|
+
default_value:\vtrue")
|
90
|
+
assert_raises(RuntimeError) { load_file }
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_load_feature_name_no_data
|
94
|
+
write("
|
95
|
+
name:")
|
96
|
+
assert_raises(RuntimeError) do
|
97
|
+
load_file
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_load_feature_name_default
|
102
|
+
write("
|
103
|
+
name:
|
104
|
+
default_value: true")
|
105
|
+
reference = load_file
|
106
|
+
assert(!reference.empty?)
|
107
|
+
ref = reference.lookup('test', 'name')
|
108
|
+
assert_equal(true, ref.default_value)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_load_duplicate_name
|
112
|
+
write("
|
113
|
+
name:
|
114
|
+
default_value: false
|
115
|
+
name:
|
116
|
+
get_command: 'show feature'")
|
117
|
+
assert_raises(RuntimeError) { load_file }
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_load_duplicate_param
|
121
|
+
write("
|
122
|
+
name:
|
123
|
+
default_value: false
|
124
|
+
default_value: true")
|
125
|
+
assert_raises(RuntimeError) { load_file }
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_load_unsupported_key
|
129
|
+
write("
|
130
|
+
name:
|
131
|
+
get_command: 'show feature'
|
132
|
+
what_is_this: \"I don't even\"")
|
133
|
+
assert_raises(RuntimeError) { load_file }
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_load_unalphabetized
|
137
|
+
write("
|
138
|
+
name_b:
|
139
|
+
default_value: true
|
140
|
+
name_a:
|
141
|
+
default_value: false")
|
142
|
+
assert_raises(RuntimeError) { load_file }
|
143
|
+
end
|
144
|
+
|
145
|
+
def type_check(obj, cls)
|
146
|
+
assert(obj.is_a?(cls), "'#{obj}' type should be #{cls} but is #{obj.class}")
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_load_types
|
150
|
+
write(%q(
|
151
|
+
name:
|
152
|
+
default_value: true
|
153
|
+
get_command: show hello
|
154
|
+
get_context: ['/hello/i']
|
155
|
+
get_value: '/world/'
|
156
|
+
set_context: [ "hello", "world" ]
|
157
|
+
set_value:
|
158
|
+
- "hello"
|
159
|
+
- "world"
|
160
|
+
))
|
161
|
+
reference = load_file
|
162
|
+
ref = reference.lookup('test', 'name')
|
163
|
+
type_check(ref.default_value, TrueClass)
|
164
|
+
type_check(ref.get_command, String)
|
165
|
+
type_check(ref.get_context, Array)
|
166
|
+
type_check(ref.get_context[0], String)
|
167
|
+
type_check(ref.get_value, String)
|
168
|
+
type_check(ref.set_context, Array)
|
169
|
+
type_check(ref.set_context[0], String)
|
170
|
+
type_check(ref.set_value, Array)
|
171
|
+
type_check(ref.set_value[0], String)
|
172
|
+
assert_raises(IndexError) { ref.context }
|
173
|
+
|
174
|
+
assert(ref.default_value?)
|
175
|
+
assert(ref.get_command?)
|
176
|
+
assert(ref.get_context?)
|
177
|
+
assert(ref.get_value?)
|
178
|
+
assert(ref.getter?)
|
179
|
+
assert(ref.set_context?)
|
180
|
+
assert(ref.set_value?)
|
181
|
+
assert(ref.setter?)
|
182
|
+
end
|
183
|
+
|
184
|
+
def write_variants
|
185
|
+
write("
|
186
|
+
name:
|
187
|
+
default_value: 'generic'
|
188
|
+
nexus:
|
189
|
+
default_value: 'NXAPI base'
|
190
|
+
C3064:
|
191
|
+
default_value: 'NXAPI C3064'
|
192
|
+
C3132:
|
193
|
+
default_value: 'NXAPI C3132'
|
194
|
+
C3172:
|
195
|
+
default_value: 'NXAPI C3172'
|
196
|
+
N7k:
|
197
|
+
default_value: ~
|
198
|
+
N9k:
|
199
|
+
default_value: 'NXAPI N9K'
|
200
|
+
ios_xr:
|
201
|
+
XRv9k:
|
202
|
+
default_value: ~
|
203
|
+
else:
|
204
|
+
default_value: 'gRPC base'
|
205
|
+
")
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_load_generic
|
209
|
+
write_variants
|
210
|
+
# Neither NXAPI nor gRPC
|
211
|
+
reference = load_file
|
212
|
+
assert_equal('generic', reference.lookup('test', 'name').default_value)
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_load_n9k
|
216
|
+
write_variants
|
217
|
+
reference = load_file(platform: :nexus,
|
218
|
+
product: 'N9K-C9396PX',
|
219
|
+
data_formats: [:nxapi_structured, :cli])
|
220
|
+
assert_equal('NXAPI N9K', reference.lookup('test', 'name').default_value)
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_load_n7k
|
224
|
+
write_variants
|
225
|
+
reference = load_file(platform: :nexus,
|
226
|
+
product: 'N7K-C7010',
|
227
|
+
data_formats: [:nxapi_structured, :cli])
|
228
|
+
assert_equal(nil, reference.lookup('test', 'name').default_value)
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_load_n3k
|
232
|
+
write_variants
|
233
|
+
reference = load_file(platform: :nexus,
|
234
|
+
product: 'N3K',
|
235
|
+
data_formats: [:nxapi_structured, :cli])
|
236
|
+
assert_equal('NXAPI base', reference.lookup('test', 'name').default_value)
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_load_n3k_3064
|
240
|
+
write_variants
|
241
|
+
reference = load_file(platform: :nexus,
|
242
|
+
product: 'N3K-C3064PQ-10GE',
|
243
|
+
data_formats: [:nxapi_structured, :cli])
|
244
|
+
assert_equal('NXAPI C3064', reference.lookup('test', 'name').default_value)
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_load_n3k_3132
|
248
|
+
write_variants
|
249
|
+
reference = load_file(platform: :nexus,
|
250
|
+
product: 'N3K-C3132Q-40GE',
|
251
|
+
data_formats: [:nxapi_structured, :cli])
|
252
|
+
assert_equal('NXAPI C3132', reference.lookup('test', 'name').default_value)
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_load_n3k_3172
|
256
|
+
write_variants
|
257
|
+
reference = load_file(platform: :nexus,
|
258
|
+
product: 'N3K-C3172PQ-10GE',
|
259
|
+
data_formats: [:nxapi_structured, :cli])
|
260
|
+
assert_equal('NXAPI C3172', reference.lookup('test', 'name').default_value)
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_load_ios_xr_xrv9k
|
264
|
+
write_variants
|
265
|
+
reference = load_file(platform: :ios_xr,
|
266
|
+
product: 'R-IOSXRV9000-CH',
|
267
|
+
data_formats: [:cli])
|
268
|
+
assert_nil(reference.lookup('test', 'name').default_value)
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_load_ios_xr_generic
|
272
|
+
write_variants
|
273
|
+
reference = load_file(platform: :ios_xr,
|
274
|
+
data_formats: [:cli])
|
275
|
+
assert_equal('gRPC base', reference.lookup('test', 'name').default_value)
|
276
|
+
end
|
277
|
+
|
278
|
+
def write_exclusions
|
279
|
+
write("
|
280
|
+
_exclude:
|
281
|
+
- N9k
|
282
|
+
|
283
|
+
name:
|
284
|
+
_exclude: [N3k]
|
285
|
+
default_value: hello
|
286
|
+
|
287
|
+
rank:
|
288
|
+
default_value: 27
|
289
|
+
")
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_exclude_whole_file
|
293
|
+
write_exclusions
|
294
|
+
reference = load_file(product: 'N9K-C9396PX')
|
295
|
+
|
296
|
+
ref = reference.lookup('test', 'name')
|
297
|
+
# default_value is nil for an unsupported property
|
298
|
+
assert(ref.default_value?, 'default_value? returned false')
|
299
|
+
assert_nil(ref.default_value)
|
300
|
+
refute(ref.getter?)
|
301
|
+
assert_raises(Cisco::UnsupportedError) { ref.getter }
|
302
|
+
refute(ref.setter?)
|
303
|
+
assert_raises(Cisco::UnsupportedError) { ref.setter }
|
304
|
+
|
305
|
+
# Because the whole file is excluded, we don't know which
|
306
|
+
# attributes are 'valid' - so any attribute name is permitted:
|
307
|
+
ref = reference.lookup('test', 'foobar')
|
308
|
+
assert(ref.default_value?)
|
309
|
+
assert_nil(ref.default_value)
|
310
|
+
refute(ref.getter?)
|
311
|
+
assert_raises(Cisco::UnsupportedError) { ref.getter }
|
312
|
+
refute(ref.setter?)
|
313
|
+
assert_raises(Cisco::UnsupportedError) { ref.setter }
|
314
|
+
end
|
315
|
+
|
316
|
+
def test_exclude_whole_item
|
317
|
+
write_exclusions
|
318
|
+
reference = load_file(product: 'N3K-C3172PQ')
|
319
|
+
assert_equal(27, reference.lookup('test', 'rank').default_value)
|
320
|
+
|
321
|
+
ref = reference.lookup('test', 'name')
|
322
|
+
assert(ref.default_value?)
|
323
|
+
assert_nil(ref.default_value)
|
324
|
+
refute(ref.getter?)
|
325
|
+
assert_raises(Cisco::UnsupportedError) { ref.getter }
|
326
|
+
refute(ref.setter?)
|
327
|
+
assert_raises(Cisco::UnsupportedError) { ref.setter }
|
328
|
+
end
|
329
|
+
|
330
|
+
def test_exclude_no_exclusion
|
331
|
+
write_exclusions
|
332
|
+
reference = load_file(product: 'N7K-C7010')
|
333
|
+
assert_equal('hello', reference.lookup('test', 'name').default_value)
|
334
|
+
assert_equal(27, reference.lookup('test', 'rank').default_value)
|
335
|
+
end
|
336
|
+
|
337
|
+
def test_exclude_implicit
|
338
|
+
# TODO: something is hinky with this test.
|
339
|
+
write("
|
340
|
+
name:
|
341
|
+
cli:
|
342
|
+
default_value: 1
|
343
|
+
")
|
344
|
+
reference = load_file(platform: 'nexus', data_formats: [])
|
345
|
+
ref = reference.lookup('test', 'name')
|
346
|
+
assert(ref.default_value?)
|
347
|
+
assert_nil(ref.default_value)
|
348
|
+
end
|
349
|
+
|
350
|
+
def test_default_only
|
351
|
+
write("
|
352
|
+
name:
|
353
|
+
default_only: 'x'
|
354
|
+
")
|
355
|
+
reference = load_file
|
356
|
+
ref = reference.lookup('test', 'name')
|
357
|
+
assert(ref.default_only?)
|
358
|
+
assert(ref.default_value?)
|
359
|
+
assert_equal('x', ref.default_value)
|
360
|
+
refute(ref.getter?)
|
361
|
+
assert_raises(Cisco::UnsupportedError) { ref.getter }
|
362
|
+
refute(ref.setter?)
|
363
|
+
assert_raises(Cisco::UnsupportedError) { ref.setter }
|
364
|
+
end
|
365
|
+
|
366
|
+
def test_default_only_cleanup
|
367
|
+
write("
|
368
|
+
name:
|
369
|
+
default_only: 'x'
|
370
|
+
set_value: 'foo'
|
371
|
+
")
|
372
|
+
reference = load_file
|
373
|
+
ref = reference.lookup('test', 'name')
|
374
|
+
assert(ref.default_only?)
|
375
|
+
assert(ref.default_value?)
|
376
|
+
assert_equal('x', ref.default_value)
|
377
|
+
refute(ref.set_value?)
|
378
|
+
assert_raises(Cisco::UnsupportedError) { ref.set_value }
|
379
|
+
refute(ref.setter?)
|
380
|
+
assert_raises(Cisco::UnsupportedError) { ref.setter }
|
381
|
+
|
382
|
+
write("
|
383
|
+
name2:
|
384
|
+
set_value: 'foo'
|
385
|
+
default_only: 'x'
|
386
|
+
")
|
387
|
+
reference = load_file
|
388
|
+
ref = reference.lookup('test', 'name2')
|
389
|
+
assert(ref.default_only?)
|
390
|
+
assert(ref.default_value?)
|
391
|
+
assert_equal('x', ref.default_value)
|
392
|
+
refute(ref.set_value?)
|
393
|
+
assert_raises(Cisco::UnsupportedError) { ref.set_value }
|
394
|
+
refute(ref.setter?)
|
395
|
+
assert_raises(Cisco::UnsupportedError) { ref.setter }
|
396
|
+
end
|
397
|
+
|
398
|
+
def test_default_only_default_value
|
399
|
+
write("
|
400
|
+
name:
|
401
|
+
kind: int
|
402
|
+
nexus:
|
403
|
+
default_value: 10
|
404
|
+
set_value: 'hello'
|
405
|
+
default_only: 0
|
406
|
+
")
|
407
|
+
reference = load_file
|
408
|
+
ref = reference.lookup('test', 'name')
|
409
|
+
assert(ref.default_only?)
|
410
|
+
assert(ref.default_value?)
|
411
|
+
assert_equal(0, ref.default_value)
|
412
|
+
refute(ref.set_value?)
|
413
|
+
assert_raises(Cisco::UnsupportedError) { ref.set_value }
|
414
|
+
refute(ref.setter?)
|
415
|
+
assert_raises(Cisco::UnsupportedError) { ref.setter }
|
416
|
+
|
417
|
+
reference = load_file(data_formats: [:nxapi_structured, :cli],
|
418
|
+
platform: 'nexus')
|
419
|
+
ref = reference.lookup('test', 'name')
|
420
|
+
refute(ref.default_only?)
|
421
|
+
assert(ref.default_value?)
|
422
|
+
assert_equal(10, ref.default_value)
|
423
|
+
assert(ref.set_value?)
|
424
|
+
assert(ref.setter?)
|
425
|
+
assert_raises(IndexError) { ref.get_value }
|
426
|
+
end
|
427
|
+
|
428
|
+
def test_getter_hash_substitution
|
429
|
+
write(%q(
|
430
|
+
name:
|
431
|
+
get_context:
|
432
|
+
['/^router ospf <name>$/',
|
433
|
+
'(?)/^vrf <vrf>$/']
|
434
|
+
get_value: '/^router-id (\S+)$/'
|
435
|
+
test2:
|
436
|
+
get_context: ['(?)abc <val1> def']
|
437
|
+
get_value: 'xyz <val2>'
|
438
|
+
test3:
|
439
|
+
get_context: ['foo']
|
440
|
+
# no get_value
|
441
|
+
test4:
|
442
|
+
get_value: 'xyz <val1> <val2>'
|
443
|
+
))
|
444
|
+
reference = load_file
|
445
|
+
ref = reference.lookup('test', 'name')
|
446
|
+
# vrf context is flagged as optional
|
447
|
+
getter = ref.getter(name: 'red')
|
448
|
+
assert_equal({
|
449
|
+
command: nil,
|
450
|
+
context: ['/^router ospf red$/'],
|
451
|
+
value: '/^router-id (\S+)$/',
|
452
|
+
data_format: :cli,
|
453
|
+
}, getter)
|
454
|
+
|
455
|
+
getter = ref.getter(name: 'blue', vrf: 'green')
|
456
|
+
assert_equal({
|
457
|
+
command: nil,
|
458
|
+
context: ['/^router ospf blue$/', '/^vrf green$/'],
|
459
|
+
value: '/^router-id (\S+)$/',
|
460
|
+
data_format: :cli,
|
461
|
+
}, getter)
|
462
|
+
|
463
|
+
# ospf name is not flagged as optional
|
464
|
+
assert_raises(ArgumentError) { ref.getter(vrf: 'green') }
|
465
|
+
|
466
|
+
ref = reference.lookup('test', 'test2')
|
467
|
+
getter = ref.getter(val1: '1', val2: '2')
|
468
|
+
assert_equal({
|
469
|
+
command: nil,
|
470
|
+
context: ['abc 1 def'],
|
471
|
+
value: 'xyz 2',
|
472
|
+
data_format: :cli,
|
473
|
+
}, getter)
|
474
|
+
|
475
|
+
# value params are mandatory
|
476
|
+
assert_raises(ArgumentError) { ref.getter(val1: '1', extra_val: 'asdf') }
|
477
|
+
|
478
|
+
# context params are optional only if flagged!
|
479
|
+
getter = ref.getter(val2: '2')
|
480
|
+
assert_equal({
|
481
|
+
command: nil,
|
482
|
+
context: [],
|
483
|
+
value: 'xyz 2',
|
484
|
+
data_format: :cli,
|
485
|
+
}, getter)
|
486
|
+
|
487
|
+
e = assert_raises(ArgumentError) { ref.getter }
|
488
|
+
assert_equal("No value specified for 'val2' in 'xyz <val2>'", e.message)
|
489
|
+
|
490
|
+
e = assert_raises(ArgumentError) { ref.getter(extra: 'x') }
|
491
|
+
assert_equal("No value specified for 'val2' in 'xyz <val2>'", e.message)
|
492
|
+
|
493
|
+
e = assert_raises(ArgumentError) { ref.getter('x') }
|
494
|
+
assert_match(/requires keyword args/, e.message)
|
495
|
+
|
496
|
+
# No get_value and no get_command means no getter
|
497
|
+
ref = reference.lookup('test', 'test3')
|
498
|
+
refute(ref.getter?)
|
499
|
+
assert_raises(UnsupportedError) { ref.getter }
|
500
|
+
assert_raises(UnsupportedError) { ref.getter(val1: '1') }
|
501
|
+
assert_raises(UnsupportedError) { ref.getter('x') }
|
502
|
+
|
503
|
+
# Multiple keys in a single parameter
|
504
|
+
ref = reference.lookup('test', 'test4')
|
505
|
+
getter = ref.getter(val1: 1, val2: 2.2)
|
506
|
+
assert_equal({
|
507
|
+
command: nil,
|
508
|
+
context: [],
|
509
|
+
value: 'xyz 1 2.2',
|
510
|
+
data_format: :cli,
|
511
|
+
}, getter)
|
512
|
+
|
513
|
+
e = assert_raises(ArgumentError) { ref.getter }
|
514
|
+
assert_match(/No value specified for 'val1'/, e.message)
|
515
|
+
e = assert_raises(ArgumentError) { ref.getter(val1: 1) }
|
516
|
+
assert_equal("No value specified for 'val2' in 'xyz 1 <val2>'", e.message)
|
517
|
+
e = assert_raises(ArgumentError) { ref.getter(val2: 2.2) }
|
518
|
+
assert_equal("No value specified for 'val1' in 'xyz <val1> 2.2'", e.message)
|
519
|
+
end
|
520
|
+
|
521
|
+
def test_getter_printf_substitution
|
522
|
+
write("
|
523
|
+
name:
|
524
|
+
get_context: ['/^interface %s$/i']
|
525
|
+
get_value: '/^description (.*)/'
|
526
|
+
test3:
|
527
|
+
get_context: ['/^foo %s$/']
|
528
|
+
# no get_value
|
529
|
+
")
|
530
|
+
reference = load_file
|
531
|
+
ref = reference.lookup('test', 'name')
|
532
|
+
getter = ref.getter('Ethernet1/1')
|
533
|
+
assert_equal({
|
534
|
+
command: nil,
|
535
|
+
context: ['/^interface Ethernet1/1$/i'],
|
536
|
+
value: '/^description (.*)/',
|
537
|
+
data_format: :cli,
|
538
|
+
}, getter)
|
539
|
+
# Negative tests - wrong # of args
|
540
|
+
e = assert_raises(ArgumentError) { ref.getter }
|
541
|
+
assert_equal('wrong number of arguments (0 for 1)', e.message)
|
542
|
+
|
543
|
+
e = assert_raises(ArgumentError) { ref.getter('eth1/1', 'foo') }
|
544
|
+
assert_equal('wrong number of arguments (2 for 1)', e.message)
|
545
|
+
|
546
|
+
# Wrong kind of args
|
547
|
+
e = assert_raises(ArgumentError) { ref.getter(name: 'eth1/1', val: 'foo') }
|
548
|
+
assert_match(/requires positional args/, e.message)
|
549
|
+
|
550
|
+
ref = reference.lookup('test', 'test3')
|
551
|
+
refute(ref.getter?)
|
552
|
+
assert_raises(UnsupportedError) { ref.getter }
|
553
|
+
assert_raises(UnsupportedError) { ref.getter('1') }
|
554
|
+
assert_raises(UnsupportedError) { ref.getter(foo: '1') }
|
555
|
+
end
|
556
|
+
|
557
|
+
RAW_1 = {
|
558
|
+
'name' => {
|
559
|
+
'_exclude' => ['N3k'],
|
560
|
+
'default_value' => 'generic',
|
561
|
+
'nexus' => {
|
562
|
+
'default_value' => 'NXAPI base',
|
563
|
+
'N7k' => { 'default_value' => nil },
|
564
|
+
'N9k' => { 'default_value' => 'NXAPI N9K' },
|
565
|
+
},
|
566
|
+
'ios_xr' => {
|
567
|
+
'XRv9k' => { 'default_value' => nil },
|
568
|
+
'else' => { 'default_value' => 'gRPC base' },
|
569
|
+
},
|
570
|
+
}
|
571
|
+
}
|
572
|
+
|
573
|
+
FILTERED_1_NEXUS = {
|
574
|
+
'name' => {
|
575
|
+
'default_value' => 'generic',
|
576
|
+
'nexus' => { 'default_value' => 'NXAPI base' },
|
577
|
+
}
|
578
|
+
}
|
579
|
+
|
580
|
+
FILTERED_1_NEXUS_N7K = {
|
581
|
+
'name' => {
|
582
|
+
'default_value' => 'generic',
|
583
|
+
'nexus' => {
|
584
|
+
'default_value' => 'NXAPI base',
|
585
|
+
'N7k' => { 'default_value' => nil },
|
586
|
+
},
|
587
|
+
}
|
588
|
+
}
|
589
|
+
|
590
|
+
FILTERED_1_NEXUS_N3K = {
|
591
|
+
'name' => {}
|
592
|
+
}
|
593
|
+
|
594
|
+
RAW_2 = {
|
595
|
+
'_template' => {
|
596
|
+
'ios_xr' => {
|
597
|
+
'cli' => { 'get_command' => 'show inventory' },
|
598
|
+
'set_value' => 'show inventory',
|
599
|
+
},
|
600
|
+
'nexus' => {
|
601
|
+
'nxapi_structured' => { get_command: 'show inventory' },
|
602
|
+
'set_value' => 'show inventory | no-more',
|
603
|
+
},
|
604
|
+
}
|
605
|
+
}
|
606
|
+
|
607
|
+
FILTERED_2_IOS_XR = {
|
608
|
+
'_template' => {
|
609
|
+
'ios_xr' => {
|
610
|
+
'set_value' => 'show inventory'
|
611
|
+
}
|
612
|
+
}
|
613
|
+
}
|
614
|
+
|
615
|
+
FILTERED_2_IOS_XR_CLI = {
|
616
|
+
'_template' => {
|
617
|
+
'ios_xr' => {
|
618
|
+
'cli' => { 'get_command' => 'show inventory' },
|
619
|
+
'set_value' => 'show inventory',
|
620
|
+
}
|
621
|
+
}
|
622
|
+
}
|
623
|
+
|
624
|
+
def test_filter_hash
|
625
|
+
filtered = CommandReference.filter_hash(RAW_1)
|
626
|
+
assert_equal({ 'name' => { 'default_value' => 'generic' } }, filtered)
|
627
|
+
|
628
|
+
filtered = CommandReference.filter_hash(RAW_1,
|
629
|
+
platform: :nexus)
|
630
|
+
assert_equal(FILTERED_1_NEXUS, filtered)
|
631
|
+
|
632
|
+
filtered = CommandReference.filter_hash(RAW_1,
|
633
|
+
platform: :nexus,
|
634
|
+
product_id: 'N7K-C7010')
|
635
|
+
assert_equal(FILTERED_1_NEXUS_N7K, filtered)
|
636
|
+
|
637
|
+
filtered = CommandReference.filter_hash(RAW_1,
|
638
|
+
platform: :nexus,
|
639
|
+
product_id: 'N3K-C3172PQ')
|
640
|
+
assert_equal(FILTERED_1_NEXUS_N3K, filtered)
|
641
|
+
|
642
|
+
filtered = CommandReference.filter_hash(RAW_2)
|
643
|
+
assert_equal({ '_template' => {} }, filtered)
|
644
|
+
|
645
|
+
filtered = CommandReference.filter_hash(RAW_2,
|
646
|
+
platform: :ios_xr)
|
647
|
+
assert_equal(FILTERED_2_IOS_XR, filtered)
|
648
|
+
|
649
|
+
filtered = CommandReference.filter_hash(RAW_2,
|
650
|
+
platform: :ios_xr,
|
651
|
+
data_formats: [:cli])
|
652
|
+
assert_equal(FILTERED_2_IOS_XR_CLI, filtered)
|
653
|
+
end
|
654
|
+
|
655
|
+
def test_hash_merge_no_template
|
656
|
+
merged = CommandReference.hash_merge(FILTERED_1_NEXUS)
|
657
|
+
assert_equal({ 'default_value' => 'NXAPI base' }, merged)
|
658
|
+
|
659
|
+
merged = CommandReference.hash_merge(FILTERED_1_NEXUS_N7K)
|
660
|
+
assert_equal({ 'default_value' => nil }, merged)
|
661
|
+
|
662
|
+
merged = CommandReference.hash_merge(FILTERED_2_IOS_XR)
|
663
|
+
assert_equal({ 'set_value' => 'show inventory' }, merged)
|
664
|
+
|
665
|
+
merged = CommandReference.hash_merge(FILTERED_2_IOS_XR_CLI)
|
666
|
+
assert_equal({ 'set_value' => 'show inventory',
|
667
|
+
'get_command' => 'show inventory' }, merged)
|
668
|
+
end
|
669
|
+
end
|