cisco_node_utils 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/.rubocop.yml +13 -0
- data/.travis.yml +4 -1
- data/CHANGELOG.md +81 -2
- data/CONTRIBUTING.md +2 -17
- data/Gemfile +5 -0
- data/README.md +92 -47
- data/Rakefile +23 -1
- data/bin/git/hooks/hook_lib +7 -0
- data/bin/git/hooks/pre-commit/check_unstaged_changes +18 -0
- data/bin/git/hooks/pre-commit/rubocop +7 -2
- data/bin/git/hooks/pre-commit/validate-diffs +18 -4
- data/bin/git/hooks/pre-commit/validate-yaml +18 -0
- data/bin/git/update-hooks +64 -6
- data/cisco_node_utils.gemspec +9 -6
- data/docs/README-develop-best-practices.md +149 -50
- data/docs/README-develop-node-utils-APIs.md +92 -42
- data/docs/README-maintainers.md +7 -4
- data/docs/README-test-execution.md +57 -0
- data/docs/cisco_node_utils.yaml.example +30 -0
- data/docs/template-router.rb +4 -0
- data/ext/mkrf_conf.rb +63 -0
- data/lib/.rubocop.yml +2 -2
- data/lib/cisco_node_utils.rb +5 -0
- data/lib/cisco_node_utils/aaa_authentication_login.rb +5 -6
- data/lib/cisco_node_utils/aaa_authorization_service.rb +1 -1
- data/lib/cisco_node_utils/ace.rb +165 -12
- data/lib/cisco_node_utils/acl.rb +2 -1
- data/lib/cisco_node_utils/bgp.rb +184 -21
- data/lib/cisco_node_utils/bgp_af.rb +94 -249
- data/lib/cisco_node_utils/bgp_neighbor.rb +94 -14
- data/lib/cisco_node_utils/bgp_neighbor_af.rb +75 -8
- data/lib/cisco_node_utils/bridge_domain.rb +183 -0
- data/lib/cisco_node_utils/bridge_domain_vni.rb +206 -0
- data/lib/cisco_node_utils/cisco_cmn_utils.rb +85 -2
- data/lib/cisco_node_utils/client.rb +35 -0
- data/lib/cisco_node_utils/client/client.rb +234 -0
- data/lib/cisco_node_utils/client/grpc.rb +33 -0
- data/lib/cisco_node_utils/client/grpc/client.rb +311 -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/nxapi.rb +31 -0
- data/lib/cisco_node_utils/client/nxapi/client.rb +305 -0
- data/lib/cisco_node_utils/client/utils.rb +164 -0
- data/lib/cisco_node_utils/cmd_ref/README_YAML.md +222 -254
- data/lib/cisco_node_utils/cmd_ref/aaa_auth_login_service.yaml +11 -8
- data/lib/cisco_node_utils/cmd_ref/aaa_authentication_login.yaml +22 -15
- data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +11 -8
- data/lib/cisco_node_utils/cmd_ref/acl.yaml +21 -16
- data/lib/cisco_node_utils/cmd_ref/bgp.yaml +239 -109
- data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +114 -55
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +76 -52
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +106 -62
- data/lib/cisco_node_utils/cmd_ref/bridge_domain.yaml +71 -0
- data/lib/cisco_node_utils/cmd_ref/bridge_domain_vni.yaml +33 -0
- data/lib/cisco_node_utils/cmd_ref/dnsclient.yaml +35 -14
- data/lib/cisco_node_utils/cmd_ref/encapsulation.yaml +25 -0
- data/lib/cisco_node_utils/cmd_ref/evpn_vni.yaml +23 -17
- data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +94 -83
- data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +22 -17
- data/lib/cisco_node_utils/cmd_ref/feature.yaml +76 -26
- data/lib/cisco_node_utils/cmd_ref/images.yaml +3 -2
- data/lib/cisco_node_utils/cmd_ref/interface.yaml +381 -153
- data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +21 -11
- data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +21 -21
- data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +30 -21
- data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +18 -13
- data/lib/cisco_node_utils/cmd_ref/inventory.yaml +26 -31
- 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 +17 -6
- data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +10 -3
- data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +17 -5
- data/lib/cisco_node_utils/cmd_ref/ospf.yaml +33 -29
- data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +12 -10
- data/lib/cisco_node_utils/cmd_ref/pim.yaml +16 -19
- data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +40 -25
- data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +17 -12
- data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +71 -35
- data/lib/cisco_node_utils/cmd_ref/radius_server_group.yaml +10 -5
- data/lib/cisco_node_utils/cmd_ref/show_system.yaml +6 -2
- data/lib/cisco_node_utils/cmd_ref/show_version.yaml +47 -43
- data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +13 -11
- data/lib/cisco_node_utils/cmd_ref/snmp_group.yaml +4 -2
- data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +23 -21
- data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +26 -22
- data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +19 -17
- data/lib/cisco_node_utils/cmd_ref/snmpnotification.yaml +18 -6
- data/lib/cisco_node_utils/cmd_ref/stp_global.yaml +234 -0
- data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +24 -9
- data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +5 -3
- data/lib/cisco_node_utils/cmd_ref/system.yaml +4 -3
- data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +22 -20
- data/lib/cisco_node_utils/cmd_ref/tacacs_server_group.yaml +27 -15
- data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +45 -16
- data/lib/cisco_node_utils/cmd_ref/vdc.yaml +21 -11
- data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +3 -2
- data/lib/cisco_node_utils/cmd_ref/vlan.yaml +60 -32
- data/lib/cisco_node_utils/cmd_ref/vpc.yaml +118 -101
- data/lib/cisco_node_utils/cmd_ref/vrf.yaml +54 -58
- data/lib/cisco_node_utils/cmd_ref/vrf_af.yaml +118 -0
- data/lib/cisco_node_utils/cmd_ref/vtp.yaml +19 -25
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +28 -18
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +34 -17
- data/lib/cisco_node_utils/cmd_ref/yum.yaml +6 -4
- data/lib/cisco_node_utils/command_reference.rb +261 -142
- data/lib/cisco_node_utils/constants.rb +33 -0
- data/lib/cisco_node_utils/encapsulation.rb +112 -0
- data/lib/cisco_node_utils/environment.rb +102 -0
- data/lib/cisco_node_utils/evpn_vni.rb +5 -3
- data/lib/cisco_node_utils/exceptions.rb +111 -0
- data/lib/cisco_node_utils/fabricpath_global.rb +52 -35
- data/lib/cisco_node_utils/fabricpath_topology.rb +44 -57
- data/lib/cisco_node_utils/feature.rb +165 -3
- data/lib/cisco_node_utils/interface.rb +1051 -260
- data/lib/cisco_node_utils/interface_channel_group.rb +11 -10
- data/lib/cisco_node_utils/interface_ospf.rb +1 -2
- data/lib/cisco_node_utils/interface_portchannel.rb +4 -12
- data/lib/cisco_node_utils/interface_service_vni.rb +7 -7
- data/lib/cisco_node_utils/itd_device_group.rb +248 -0
- data/lib/cisco_node_utils/itd_device_group_node.rb +144 -0
- data/lib/cisco_node_utils/itd_service.rb +523 -0
- data/lib/cisco_node_utils/logger.rb +75 -0
- data/lib/cisco_node_utils/node.rb +62 -192
- data/lib/cisco_node_utils/node_util.rb +56 -10
- data/lib/cisco_node_utils/overlay_global.rb +2 -2
- data/lib/cisco_node_utils/pim.rb +2 -13
- data/lib/cisco_node_utils/pim_group_list.rb +1 -1
- data/lib/cisco_node_utils/pim_rp_address.rb +1 -1
- data/lib/cisco_node_utils/platform.rb +52 -21
- data/lib/cisco_node_utils/portchannel_global.rb +89 -19
- data/lib/cisco_node_utils/radius_server.rb +168 -37
- data/lib/cisco_node_utils/router_ospf.rb +20 -35
- data/lib/cisco_node_utils/router_ospf_vrf.rb +4 -4
- data/lib/cisco_node_utils/snmpserver.rb +1 -6
- data/lib/cisco_node_utils/snmpuser.rb +6 -4
- data/lib/cisco_node_utils/stp_global.rb +676 -0
- data/lib/cisco_node_utils/syslog_server.rb +77 -18
- data/lib/cisco_node_utils/syslog_settings.rb +1 -1
- data/lib/cisco_node_utils/tacacs_server_group.rb +8 -4
- data/lib/cisco_node_utils/tacacs_server_host.rb +115 -25
- data/lib/cisco_node_utils/vdc.rb +12 -0
- data/lib/cisco_node_utils/version.rb +1 -1
- data/lib/cisco_node_utils/vlan.rb +147 -29
- data/lib/cisco_node_utils/vpc.rb +55 -3
- data/lib/cisco_node_utils/vrf.rb +72 -11
- data/lib/cisco_node_utils/vrf_af.rb +114 -29
- data/lib/cisco_node_utils/vtp.rb +34 -52
- data/lib/cisco_node_utils/vxlan_vtep.rb +34 -8
- data/lib/cisco_node_utils/vxlan_vtep_vni.rb +36 -4
- 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 +263 -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 +75 -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 +2 -2
- data/tests/CSCuxdublin-1.0.0-7.0.3.I3.1.lib32_n9000.rpm +0 -0
- data/tests/basetest.rb +96 -36
- data/tests/ciscotest.rb +220 -12
- data/tests/cmd_config.yaml +71 -49
- data/tests/cmd_config_invalid.yaml +1 -1
- data/tests/test_aaa_authentication_login.rb +1 -0
- data/tests/test_aaa_authentication_login_service.rb +9 -0
- data/tests/test_aaa_authorization_service.rb +173 -367
- data/tests/test_ace.rb +171 -100
- data/tests/test_acl.rb +10 -1
- data/tests/test_bgp_af.rb +395 -728
- data/tests/test_bgp_neighbor.rb +274 -115
- data/tests/test_bgp_neighbor_af.rb +178 -77
- data/tests/test_bridge_domain.rb +191 -0
- data/tests/test_bridge_domain_vni.rb +116 -0
- data/tests/test_client_utils.rb +111 -0
- data/tests/test_command_config.rb +9 -5
- data/tests/test_command_reference.rb +380 -102
- data/tests/test_dns_domain.rb +13 -3
- data/tests/test_domain_name.rb +13 -3
- data/tests/test_encapsulation.rb +77 -0
- data/tests/test_evpn_vni.rb +25 -7
- data/tests/test_fabricpath_global.rb +167 -163
- data/tests/test_fabricpath_topology.rb +12 -33
- data/tests/test_feature.rb +215 -0
- data/tests/test_grpc.rb +166 -0
- data/tests/test_interface.rb +585 -344
- data/tests/test_interface_bdi.rb +80 -0
- data/tests/test_interface_channel_group.rb +6 -3
- data/tests/test_interface_ospf.rb +26 -24
- data/tests/test_interface_portchannel.rb +1 -0
- data/tests/test_interface_private_vlan.rb +724 -0
- data/tests/test_interface_service_vni.rb +37 -66
- data/tests/test_interface_svi.rb +98 -101
- data/tests/test_interface_switchport.rb +419 -549
- 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 +298 -0
- data/tests/test_logger.rb +43 -0
- data/tests/test_name_server.rb +11 -2
- data/tests/test_node.rb +16 -75
- data/tests/test_node_ext.rb +174 -163
- data/tests/test_node_util.rb +119 -0
- data/tests/test_ntp_config.rb +5 -1
- data/tests/test_ntp_server.rb +2 -2
- data/tests/test_nxapi.rb +221 -0
- data/tests/test_overlay_global.rb +47 -38
- data/tests/test_pim.rb +2 -0
- data/tests/test_pim_group_list.rb +2 -0
- data/tests/test_pim_rp_address.rb +2 -0
- data/tests/test_platform.rb +86 -39
- data/tests/test_portchannel_global.rb +211 -135
- data/tests/test_radius_global.rb +13 -5
- data/tests/test_radius_server.rb +256 -104
- data/tests/test_radius_server_group.rb +2 -0
- data/tests/test_router_bgp.rb +781 -485
- data/tests/test_router_ospf.rb +26 -103
- data/tests/test_router_ospf_vrf.rb +52 -57
- data/tests/test_snmp_notification_receiver.rb +2 -0
- data/tests/test_snmpcommunity.rb +2 -0
- data/tests/test_snmpgroup.rb +2 -0
- data/tests/test_snmpnotification.rb +40 -21
- data/tests/test_snmpserver.rb +2 -0
- data/tests/test_snmpuser.rb +2 -0
- data/tests/test_stp_global.rb +563 -0
- data/tests/test_syslog_server.rb +32 -8
- data/tests/test_syslog_settings.rb +22 -9
- data/tests/test_tacacs_server.rb +32 -27
- data/tests/test_tacacs_server_group.rb +100 -45
- data/tests/test_tacacs_server_host.rb +135 -43
- data/tests/test_vdc.rb +2 -16
- data/tests/test_vlan.rb +106 -54
- data/tests/test_vlan_mt_full.rb +11 -21
- data/tests/test_vlan_private.rb +669 -0
- data/tests/test_vpc.rb +312 -159
- data/tests/test_vrf.rb +122 -113
- data/tests/test_vrf_af.rb +238 -0
- data/tests/test_vtp.rb +58 -102
- data/tests/test_vxlan_vtep.rb +38 -17
- data/tests/test_vxlan_vtep_vni.rb +61 -9
- data/tests/test_yum.rb +49 -25
- metadata +122 -36
- data/lib/cisco_node_utils/cmd_ref/fex.yaml +0 -9
- data/lib/cisco_node_utils/cmd_ref/vni.yaml +0 -76
- data/lib/cisco_node_utils/vni.rb +0 -227
- data/tests/test_vni.rb +0 -106
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Copyright (c) 2016 Cisco and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
require_relative 'ciscotest'
|
|
16
|
+
require_relative '../lib/cisco_node_utils/node_util'
|
|
17
|
+
|
|
18
|
+
# TestNodeUtil - Minitest for NodeUtil class
|
|
19
|
+
class TestNodeUtil < CiscoTestCase
|
|
20
|
+
attr_reader :nu
|
|
21
|
+
def setup
|
|
22
|
+
@nu = NodeUtil.new
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_node
|
|
26
|
+
assert_equal(node, nu.node)
|
|
27
|
+
assert_equal(node, NodeUtil.node)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_client
|
|
31
|
+
assert_equal(node.client, nu.client)
|
|
32
|
+
assert_equal(node.client, NodeUtil.client)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_config_get
|
|
36
|
+
result = node.config_get('show_version', 'system_image')
|
|
37
|
+
result2 = nu.config_get('show_version', 'system_image')
|
|
38
|
+
result3 = NodeUtil.config_get('show_version', 'system_image')
|
|
39
|
+
assert_equal(node.system, result)
|
|
40
|
+
assert_equal(result, result2)
|
|
41
|
+
assert_equal(result, result3)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_config_get_default
|
|
45
|
+
result = node.config_get_default('bgp', 'graceful_restart_timers_restart')
|
|
46
|
+
result2 = nu.config_get_default('bgp', 'graceful_restart_timers_restart')
|
|
47
|
+
result3 = NodeUtil.config_get_default('bgp',
|
|
48
|
+
'graceful_restart_timers_restart')
|
|
49
|
+
assert_equal(120, result)
|
|
50
|
+
assert_equal(result, result2)
|
|
51
|
+
assert_equal(result, result3)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_config_set_error_handling
|
|
55
|
+
# The Node error has no context information
|
|
56
|
+
e = assert_raises(Cisco::CliError) do
|
|
57
|
+
node.config_set('interface', 'shutdown',
|
|
58
|
+
name: interfaces[0], state: 'foobar')
|
|
59
|
+
end
|
|
60
|
+
assert_match(/^The command '.*shutdown' was rejected with error:/,
|
|
61
|
+
e.message)
|
|
62
|
+
rejected_input = e.rejected_input
|
|
63
|
+
clierror = e.clierror
|
|
64
|
+
|
|
65
|
+
# The NodeUtil class error just provides the class name by default...
|
|
66
|
+
e = assert_raises(Cisco::CliError) do
|
|
67
|
+
NodeUtil.config_set('interface', 'shutdown',
|
|
68
|
+
name: interfaces[0], state: 'foobar')
|
|
69
|
+
end
|
|
70
|
+
assert_match(
|
|
71
|
+
/^\[Cisco::NodeUtil\] The command '.*shutdown' was rejected with error:/,
|
|
72
|
+
e.message)
|
|
73
|
+
# Make sure error context from the Node was preserved
|
|
74
|
+
assert_equal(rejected_input, e.rejected_input)
|
|
75
|
+
assert_equal(clierror, e.clierror)
|
|
76
|
+
|
|
77
|
+
# ...but uses self.to_s if implemented
|
|
78
|
+
def NodeUtil.to_s
|
|
79
|
+
'Hello world'
|
|
80
|
+
end
|
|
81
|
+
e = assert_raises(Cisco::CliError) do
|
|
82
|
+
NodeUtil.config_set('interface', 'shutdown',
|
|
83
|
+
name: interfaces[0], state: 'foobar')
|
|
84
|
+
end
|
|
85
|
+
assert_match(
|
|
86
|
+
/^\[Hello world\] The command '.*shutdown' was rejected with error:/,
|
|
87
|
+
e.message)
|
|
88
|
+
# Make sure error context from the Node was preserved
|
|
89
|
+
assert_equal(rejected_input, e.rejected_input)
|
|
90
|
+
assert_equal(clierror, e.clierror)
|
|
91
|
+
|
|
92
|
+
# Similarly, the nu instance error provides the instance by default...
|
|
93
|
+
e = assert_raises(Cisco::CliError) do
|
|
94
|
+
nu.config_set('interface', 'shutdown',
|
|
95
|
+
name: interfaces[0], state: 'foobar')
|
|
96
|
+
end
|
|
97
|
+
assert_match(
|
|
98
|
+
/^\[#<Cisco::NodeUtil:0x.*>\] The command '.*shutdown' was rejected/,
|
|
99
|
+
e.message)
|
|
100
|
+
# Make sure error context from the Node was preserved
|
|
101
|
+
assert_equal(rejected_input, e.rejected_input)
|
|
102
|
+
assert_equal(clierror, e.clierror)
|
|
103
|
+
|
|
104
|
+
# ...but is happy to use the instance to_s
|
|
105
|
+
def nu.to_s
|
|
106
|
+
'NodeUtil #1'
|
|
107
|
+
end
|
|
108
|
+
e = assert_raises(Cisco::CliError) do
|
|
109
|
+
nu.config_set('interface', 'shutdown',
|
|
110
|
+
name: interfaces[0], state: 'foobar')
|
|
111
|
+
end
|
|
112
|
+
assert_match(
|
|
113
|
+
/^\[NodeUtil #1\] The command '.*shutdown' was rejected with error:/,
|
|
114
|
+
e.message)
|
|
115
|
+
# Make sure error context from the Node was preserved
|
|
116
|
+
assert_equal(rejected_input, e.rejected_input)
|
|
117
|
+
assert_equal(clierror, e.clierror)
|
|
118
|
+
end
|
|
119
|
+
end
|
data/tests/test_ntp_config.rb
CHANGED
|
@@ -28,7 +28,11 @@ class TestNtpConfig < CiscoTestCase
|
|
|
28
28
|
|
|
29
29
|
def no_ntpconfig
|
|
30
30
|
# Turn the feature off for a clean test.
|
|
31
|
-
|
|
31
|
+
if platform == :ios_xr
|
|
32
|
+
config("no ntp source #{interfaces[0]}")
|
|
33
|
+
else
|
|
34
|
+
config("no ntp source-interface #{interfaces[0]}")
|
|
35
|
+
end
|
|
32
36
|
end
|
|
33
37
|
|
|
34
38
|
# TESTS
|
data/tests/test_ntp_server.rb
CHANGED
|
@@ -34,8 +34,8 @@ class TestNtpServer < CiscoTestCase
|
|
|
34
34
|
|
|
35
35
|
def no_ntpserver_uk
|
|
36
36
|
# Turn the feature off for a clean test.
|
|
37
|
-
config('no
|
|
38
|
-
'no
|
|
37
|
+
config('no ntp server 130.88.203.12',
|
|
38
|
+
'no ntp server 2003::5')
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
# TESTS
|
data/tests/test_nxapi.rb
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# November 2014, Glenn F. Matthews
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2014-2016 Cisco and/or its affiliates.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
require_relative 'basetest'
|
|
18
|
+
require_relative '../lib/cisco_node_utils/node'
|
|
19
|
+
|
|
20
|
+
# TestNxapi - NXAPI client unit tests
|
|
21
|
+
class TestNxapi < TestCase
|
|
22
|
+
@@client = nil # rubocop:disable Style/ClassVars
|
|
23
|
+
|
|
24
|
+
def self.runnable_methods
|
|
25
|
+
# If we're pointed to a gRPC node (as evidenced by presence of a port num)
|
|
26
|
+
# then these tests don't apply
|
|
27
|
+
return [:all_skipped] if Cisco::Environment.environment[:port]
|
|
28
|
+
super
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def all_skipped
|
|
32
|
+
skip 'Node under test does not appear to use the NXAPI client'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def setup
|
|
36
|
+
super
|
|
37
|
+
@product_id = Cisco::Node.new.product_id if @product_id.nil?
|
|
38
|
+
cleanup
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def teardown
|
|
42
|
+
cleanup
|
|
43
|
+
super
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def cleanup
|
|
47
|
+
config_no_warn('no interface loopback41', 'no interface loopback42')
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def client
|
|
51
|
+
unless @@client
|
|
52
|
+
client = Cisco::Client::NXAPI.new(Cisco::Environment.environment)
|
|
53
|
+
client.cache_enable = true
|
|
54
|
+
client.cache_auto = true
|
|
55
|
+
@@client = client # rubocop:disable Style/ClassVars
|
|
56
|
+
end
|
|
57
|
+
@@client
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Test cases for new NXAPI client APIs
|
|
61
|
+
|
|
62
|
+
def test_cli_set_string
|
|
63
|
+
client.set(context: 'interface loopback41', values: 'descr panda')
|
|
64
|
+
run = client.get(command: 'show run int loopback41')
|
|
65
|
+
desc = run.match(/description (.*)/)[1]
|
|
66
|
+
assert_equal(desc, 'panda')
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_cli_set_array
|
|
70
|
+
client.set(context: ['int loopback41'], values: ['descr elephant'])
|
|
71
|
+
run = client.get(command: 'show run int loopback41')
|
|
72
|
+
desc = run.match(/description (.*)/)[1]
|
|
73
|
+
assert_equal(desc, 'elephant')
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_cli_set_invalid
|
|
77
|
+
input = ['int loopback41', 'exit', 'int loopback42', 'plover']
|
|
78
|
+
successful = ['int loopback41', 'exit', 'int loopback42']
|
|
79
|
+
rejected = 'plover'
|
|
80
|
+
|
|
81
|
+
msg = case @product_id
|
|
82
|
+
when /N(5|6|7)/
|
|
83
|
+
'Input CLI command error'
|
|
84
|
+
when /N(3|8|9)/
|
|
85
|
+
'CLI execution error'
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
e = assert_raises Cisco::CliError do
|
|
89
|
+
client.set(values: input)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
cli_rcs = "
|
|
93
|
+
cli return codes:
|
|
94
|
+
successful : #{e.successful_input}
|
|
95
|
+
rejected : #{e.rejected_input}
|
|
96
|
+
msg : #{e.msg}
|
|
97
|
+
code : #{e.code}
|
|
98
|
+
clierror : #{e.clierror}
|
|
99
|
+
"
|
|
100
|
+
assert_equal(successful, e.successful_input, cli_rcs)
|
|
101
|
+
assert_equal(rejected, e.rejected_input, cli_rcs)
|
|
102
|
+
|
|
103
|
+
assert_match(msg, e.msg, cli_rcs)
|
|
104
|
+
assert_equal('400', e.code, cli_rcs)
|
|
105
|
+
assert_match('% Invalid command', e.clierror, cli_rcs)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def test_get_cli_default
|
|
109
|
+
result = client.get(command: 'show hostname')
|
|
110
|
+
s = @device.cmd('show hostname')
|
|
111
|
+
assert_equal(result.strip, s.split("\n")[1].strip)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def test_get_cli_invalid
|
|
115
|
+
assert_raises Cisco::CliError do
|
|
116
|
+
client.get(command: 'show plugh')
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def test_element_get_cli_incomplete
|
|
121
|
+
assert_raises Cisco::CliError do
|
|
122
|
+
client.get(command: 'show ')
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def test_get_cli_explicit
|
|
127
|
+
result = client.get(command: 'show hostname', data_format: :cli)
|
|
128
|
+
s = @device.cmd('show hostname')
|
|
129
|
+
assert_equal(result.strip, s.split("\n")[1].strip)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def test_get_cli_empty
|
|
133
|
+
result = client.get(command: 'show hostname | incl foo | excl foo',
|
|
134
|
+
data_format: :cli)
|
|
135
|
+
assert_nil(result)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def test_get_nxapi_structured
|
|
139
|
+
result = client.get(command: 'show hostname',
|
|
140
|
+
data_format: :nxapi_structured)
|
|
141
|
+
s = @device.cmd('show hostname')
|
|
142
|
+
assert_equal(result['hostname'], s.split("\n")[1].strip)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_get_nxapi_structured_invalid
|
|
146
|
+
assert_raises Cisco::CliError do
|
|
147
|
+
client.get(command: 'show frobozz', data_format: :nxapi_structured)
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def test_get_nxapi_structured_unsupported
|
|
152
|
+
cmd = { command: 'show snmp internal globals',
|
|
153
|
+
data_format: :nxapi_structured }
|
|
154
|
+
if @product_id[/N(5|6)/]
|
|
155
|
+
assert_empty(client.get(cmd))
|
|
156
|
+
else
|
|
157
|
+
assert_raises(Cisco::RequestNotSupported) { client.get(cmd) }
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def test_connection_refused
|
|
162
|
+
@device.cmd('configure terminal')
|
|
163
|
+
@device.cmd('no feature nxapi')
|
|
164
|
+
@device.cmd('end')
|
|
165
|
+
assert_raises Cisco::ConnectionRefused do
|
|
166
|
+
client.cache_flush
|
|
167
|
+
client.get(command: 'show version')
|
|
168
|
+
end
|
|
169
|
+
assert_raises Cisco::ConnectionRefused do
|
|
170
|
+
client.set(values: 'interface loopback41')
|
|
171
|
+
end
|
|
172
|
+
# On the off chance that things behave differently when NXAPI is
|
|
173
|
+
# disabled while we're connected, versus trying to connect afresh...
|
|
174
|
+
@@client = nil # rubocop:disable Style/ClassVars
|
|
175
|
+
assert_raises Cisco::ConnectionRefused do
|
|
176
|
+
client.get(command: 'show version')
|
|
177
|
+
end
|
|
178
|
+
assert_raises Cisco::ConnectionRefused do
|
|
179
|
+
client.set(values: 'interface loopback41')
|
|
180
|
+
end
|
|
181
|
+
ensure
|
|
182
|
+
@device.cmd('configure terminal')
|
|
183
|
+
@device.cmd('feature nxapi')
|
|
184
|
+
@device.cmd('end')
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def test_unauthorized
|
|
188
|
+
def client.password=(new) # rubocop:disable Style/TrivialAccessors
|
|
189
|
+
@password = new
|
|
190
|
+
end
|
|
191
|
+
client.password = 'wrong_password'
|
|
192
|
+
client.cache_flush
|
|
193
|
+
assert_raises Cisco::AuthenticationFailed do
|
|
194
|
+
client.get(command: 'show version')
|
|
195
|
+
end
|
|
196
|
+
assert_raises Cisco::AuthenticationFailed do
|
|
197
|
+
client.set(values: 'interface loopback41')
|
|
198
|
+
end
|
|
199
|
+
ensure
|
|
200
|
+
client.password = password
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def test_unsupported
|
|
204
|
+
# Add a method to the NXAPI that sends a request of invalid type
|
|
205
|
+
def client.hello
|
|
206
|
+
req('hello', 'world')
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
assert_raises Cisco::RequestNotSupported do
|
|
210
|
+
client.hello
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def test_smart_create
|
|
215
|
+
autoclient = Cisco::Client.create
|
|
216
|
+
assert_equal(Cisco::Client::NXAPI, autoclient.class)
|
|
217
|
+
assert(autoclient.supports?(:cli))
|
|
218
|
+
assert(autoclient.supports?(:nxapi_structured))
|
|
219
|
+
assert_equal(:nexus, autoclient.platform)
|
|
220
|
+
end
|
|
221
|
+
end
|
|
@@ -21,82 +21,91 @@ include Cisco
|
|
|
21
21
|
|
|
22
22
|
# TestOverlayGlobal - Minitest for OverlayGlobal node utility
|
|
23
23
|
class TestOverlayGlobal < CiscoTestCase
|
|
24
|
+
@skip_unless_supported = 'overlay_global'
|
|
25
|
+
|
|
24
26
|
def setup
|
|
25
27
|
super
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
vxlan_linecard?
|
|
29
|
+
vdc_lc_state('f3')
|
|
30
|
+
config_no_warn('no feature fabric forwarding')
|
|
31
|
+
config_no_warn('no nv overlay evpn')
|
|
32
|
+
config_no_warn('l2rib dup-host-mac-detection default')
|
|
29
33
|
end
|
|
30
34
|
|
|
31
35
|
def test_dup_host_ip_addr_detection
|
|
32
|
-
|
|
36
|
+
o = OverlayGlobal.new
|
|
37
|
+
if validate_property_excluded?('overlay_global',
|
|
38
|
+
'dup_host_ip_addr_detection')
|
|
39
|
+
assert_raises(Cisco::UnsupportedError) do
|
|
40
|
+
o.dup_host_ip_addr_detection_set(200, 20)
|
|
41
|
+
end
|
|
42
|
+
return
|
|
43
|
+
end
|
|
33
44
|
|
|
34
45
|
# Before enabling 'nv overlay evpn', these properties do not exist
|
|
35
|
-
assert_nil(
|
|
36
|
-
assert_nil(
|
|
46
|
+
assert_nil(o.dup_host_ip_addr_detection_host_moves)
|
|
47
|
+
assert_nil(o.dup_host_ip_addr_detection_timeout)
|
|
37
48
|
|
|
38
49
|
# Set them to the default value and they should now be present
|
|
39
|
-
default = [
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
assert_equal(default[0],
|
|
43
|
-
|
|
44
|
-
assert_equal(default[1],
|
|
45
|
-
overlay_global.dup_host_ip_addr_detection_timeout)
|
|
50
|
+
default = [o.default_dup_host_ip_addr_detection_host_moves,
|
|
51
|
+
o.default_dup_host_ip_addr_detection_timeout]
|
|
52
|
+
o.dup_host_ip_addr_detection_set(*default)
|
|
53
|
+
assert_equal(default[0], o.dup_host_ip_addr_detection_host_moves)
|
|
54
|
+
assert_equal(default[1], o.dup_host_ip_addr_detection_timeout)
|
|
46
55
|
assert(Feature.nv_overlay_evpn_enabled?)
|
|
47
56
|
|
|
48
57
|
# Set them to non-default values
|
|
49
58
|
val = [200, 20]
|
|
50
|
-
|
|
51
|
-
assert_equal(val,
|
|
52
|
-
assert_equal(val[0],
|
|
53
|
-
|
|
54
|
-
assert_equal(val[1],
|
|
55
|
-
overlay_global.dup_host_ip_addr_detection_timeout)
|
|
59
|
+
o.dup_host_ip_addr_detection_set(*val)
|
|
60
|
+
assert_equal(val, o.dup_host_ip_addr_detection)
|
|
61
|
+
assert_equal(val[0], o.dup_host_ip_addr_detection_host_moves)
|
|
62
|
+
assert_equal(val[1], o.dup_host_ip_addr_detection_timeout)
|
|
56
63
|
end
|
|
57
64
|
|
|
58
65
|
def test_dup_host_mac_detection
|
|
59
|
-
|
|
66
|
+
o = OverlayGlobal.new
|
|
60
67
|
# These properties always exist, even without 'nv overlay evpn'
|
|
61
|
-
default = [
|
|
62
|
-
|
|
63
|
-
assert_equal(default,
|
|
68
|
+
default = [o.default_dup_host_mac_detection_host_moves,
|
|
69
|
+
o.default_dup_host_mac_detection_timeout]
|
|
70
|
+
assert_equal(default, o.dup_host_mac_detection)
|
|
64
71
|
refute(Feature.nv_overlay_evpn_enabled?)
|
|
65
72
|
|
|
66
73
|
# Set to a non-default value
|
|
67
74
|
val = [160, 16]
|
|
68
|
-
|
|
69
|
-
assert_equal(val,
|
|
75
|
+
o.dup_host_mac_detection_set(*val)
|
|
76
|
+
assert_equal(val, o.dup_host_mac_detection)
|
|
70
77
|
refute(Feature.nv_overlay_evpn_enabled?)
|
|
71
78
|
|
|
72
79
|
# Use the special defaulter method
|
|
73
|
-
|
|
74
|
-
assert_equal(default,
|
|
80
|
+
o.dup_host_mac_detection_default
|
|
81
|
+
assert_equal(default, o.dup_host_mac_detection)
|
|
75
82
|
refute(Feature.nv_overlay_evpn_enabled?)
|
|
76
83
|
|
|
77
84
|
# Set explicitly to default too
|
|
78
|
-
|
|
79
|
-
assert_equal(default,
|
|
85
|
+
o.dup_host_mac_detection_set(*default)
|
|
86
|
+
assert_equal(default, o.dup_host_mac_detection)
|
|
80
87
|
refute(Feature.nv_overlay_evpn_enabled?)
|
|
81
88
|
end
|
|
82
89
|
|
|
83
90
|
def test_anycast_gateway_mac
|
|
84
|
-
|
|
91
|
+
o = OverlayGlobal.new
|
|
92
|
+
if validate_property_excluded?('overlay_global', 'anycast_gateway_mac')
|
|
93
|
+
assert_raises(Cisco::UnsupportedError) { o.anycast_gateway_mac = '1.1.1' }
|
|
94
|
+
return
|
|
95
|
+
end
|
|
96
|
+
|
|
85
97
|
# Before enabling 'nv overlay evpn', this property does not exist
|
|
86
|
-
assert_nil(
|
|
98
|
+
assert_nil(o.anycast_gateway_mac)
|
|
87
99
|
|
|
88
100
|
# Explicitly set to default and it should be enabled
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
assert_equal(overlay_global.default_anycast_gateway_mac,
|
|
92
|
-
overlay_global.anycast_gateway_mac)
|
|
101
|
+
o.anycast_gateway_mac = o.default_anycast_gateway_mac
|
|
102
|
+
assert_equal(o.default_anycast_gateway_mac, o.anycast_gateway_mac)
|
|
93
103
|
assert(Feature.nv_overlay_evpn_enabled?)
|
|
94
104
|
|
|
95
105
|
# Set to various non-default values
|
|
96
106
|
%w(1.1.1 55.a10.ffff 1223.3445.5668).each do |mac|
|
|
97
|
-
|
|
98
|
-
assert_equal(Utils.zero_pad_macaddr(mac),
|
|
99
|
-
overlay_global.anycast_gateway_mac)
|
|
107
|
+
o.anycast_gateway_mac = mac
|
|
108
|
+
assert_equal(Utils.zero_pad_macaddr(mac), o.anycast_gateway_mac)
|
|
100
109
|
end
|
|
101
110
|
end
|
|
102
111
|
end
|