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.
Files changed (255) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +13 -0
  5. data/.travis.yml +4 -1
  6. data/CHANGELOG.md +81 -2
  7. data/CONTRIBUTING.md +2 -17
  8. data/Gemfile +5 -0
  9. data/README.md +92 -47
  10. data/Rakefile +23 -1
  11. data/bin/git/hooks/hook_lib +7 -0
  12. data/bin/git/hooks/pre-commit/check_unstaged_changes +18 -0
  13. data/bin/git/hooks/pre-commit/rubocop +7 -2
  14. data/bin/git/hooks/pre-commit/validate-diffs +18 -4
  15. data/bin/git/hooks/pre-commit/validate-yaml +18 -0
  16. data/bin/git/update-hooks +64 -6
  17. data/cisco_node_utils.gemspec +9 -6
  18. data/docs/README-develop-best-practices.md +149 -50
  19. data/docs/README-develop-node-utils-APIs.md +92 -42
  20. data/docs/README-maintainers.md +7 -4
  21. data/docs/README-test-execution.md +57 -0
  22. data/docs/cisco_node_utils.yaml.example +30 -0
  23. data/docs/template-router.rb +4 -0
  24. data/ext/mkrf_conf.rb +63 -0
  25. data/lib/.rubocop.yml +2 -2
  26. data/lib/cisco_node_utils.rb +5 -0
  27. data/lib/cisco_node_utils/aaa_authentication_login.rb +5 -6
  28. data/lib/cisco_node_utils/aaa_authorization_service.rb +1 -1
  29. data/lib/cisco_node_utils/ace.rb +165 -12
  30. data/lib/cisco_node_utils/acl.rb +2 -1
  31. data/lib/cisco_node_utils/bgp.rb +184 -21
  32. data/lib/cisco_node_utils/bgp_af.rb +94 -249
  33. data/lib/cisco_node_utils/bgp_neighbor.rb +94 -14
  34. data/lib/cisco_node_utils/bgp_neighbor_af.rb +75 -8
  35. data/lib/cisco_node_utils/bridge_domain.rb +183 -0
  36. data/lib/cisco_node_utils/bridge_domain_vni.rb +206 -0
  37. data/lib/cisco_node_utils/cisco_cmn_utils.rb +85 -2
  38. data/lib/cisco_node_utils/client.rb +35 -0
  39. data/lib/cisco_node_utils/client/client.rb +234 -0
  40. data/lib/cisco_node_utils/client/grpc.rb +33 -0
  41. data/lib/cisco_node_utils/client/grpc/client.rb +311 -0
  42. data/lib/cisco_node_utils/client/grpc/ems.proto +148 -0
  43. data/lib/cisco_node_utils/client/grpc/ems.rb +111 -0
  44. data/lib/cisco_node_utils/client/grpc/ems_services.rb +49 -0
  45. data/lib/cisco_node_utils/client/nxapi.rb +31 -0
  46. data/lib/cisco_node_utils/client/nxapi/client.rb +305 -0
  47. data/lib/cisco_node_utils/client/utils.rb +164 -0
  48. data/lib/cisco_node_utils/cmd_ref/README_YAML.md +222 -254
  49. data/lib/cisco_node_utils/cmd_ref/aaa_auth_login_service.yaml +11 -8
  50. data/lib/cisco_node_utils/cmd_ref/aaa_authentication_login.yaml +22 -15
  51. data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +11 -8
  52. data/lib/cisco_node_utils/cmd_ref/acl.yaml +21 -16
  53. data/lib/cisco_node_utils/cmd_ref/bgp.yaml +239 -109
  54. data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +114 -55
  55. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +76 -52
  56. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +106 -62
  57. data/lib/cisco_node_utils/cmd_ref/bridge_domain.yaml +71 -0
  58. data/lib/cisco_node_utils/cmd_ref/bridge_domain_vni.yaml +33 -0
  59. data/lib/cisco_node_utils/cmd_ref/dnsclient.yaml +35 -14
  60. data/lib/cisco_node_utils/cmd_ref/encapsulation.yaml +25 -0
  61. data/lib/cisco_node_utils/cmd_ref/evpn_vni.yaml +23 -17
  62. data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +94 -83
  63. data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +22 -17
  64. data/lib/cisco_node_utils/cmd_ref/feature.yaml +76 -26
  65. data/lib/cisco_node_utils/cmd_ref/images.yaml +3 -2
  66. data/lib/cisco_node_utils/cmd_ref/interface.yaml +381 -153
  67. data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +21 -11
  68. data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +21 -21
  69. data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +30 -21
  70. data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +18 -13
  71. data/lib/cisco_node_utils/cmd_ref/inventory.yaml +26 -31
  72. data/lib/cisco_node_utils/cmd_ref/itd_device_group.yaml +83 -0
  73. data/lib/cisco_node_utils/cmd_ref/itd_service.yaml +119 -0
  74. data/lib/cisco_node_utils/cmd_ref/memory.yaml +17 -6
  75. data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +10 -3
  76. data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +17 -5
  77. data/lib/cisco_node_utils/cmd_ref/ospf.yaml +33 -29
  78. data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +12 -10
  79. data/lib/cisco_node_utils/cmd_ref/pim.yaml +16 -19
  80. data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +40 -25
  81. data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +17 -12
  82. data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +71 -35
  83. data/lib/cisco_node_utils/cmd_ref/radius_server_group.yaml +10 -5
  84. data/lib/cisco_node_utils/cmd_ref/show_system.yaml +6 -2
  85. data/lib/cisco_node_utils/cmd_ref/show_version.yaml +47 -43
  86. data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +13 -11
  87. data/lib/cisco_node_utils/cmd_ref/snmp_group.yaml +4 -2
  88. data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +23 -21
  89. data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +26 -22
  90. data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +19 -17
  91. data/lib/cisco_node_utils/cmd_ref/snmpnotification.yaml +18 -6
  92. data/lib/cisco_node_utils/cmd_ref/stp_global.yaml +234 -0
  93. data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +24 -9
  94. data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +5 -3
  95. data/lib/cisco_node_utils/cmd_ref/system.yaml +4 -3
  96. data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +22 -20
  97. data/lib/cisco_node_utils/cmd_ref/tacacs_server_group.yaml +27 -15
  98. data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +45 -16
  99. data/lib/cisco_node_utils/cmd_ref/vdc.yaml +21 -11
  100. data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +3 -2
  101. data/lib/cisco_node_utils/cmd_ref/vlan.yaml +60 -32
  102. data/lib/cisco_node_utils/cmd_ref/vpc.yaml +118 -101
  103. data/lib/cisco_node_utils/cmd_ref/vrf.yaml +54 -58
  104. data/lib/cisco_node_utils/cmd_ref/vrf_af.yaml +118 -0
  105. data/lib/cisco_node_utils/cmd_ref/vtp.yaml +19 -25
  106. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +28 -18
  107. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +34 -17
  108. data/lib/cisco_node_utils/cmd_ref/yum.yaml +6 -4
  109. data/lib/cisco_node_utils/command_reference.rb +261 -142
  110. data/lib/cisco_node_utils/constants.rb +33 -0
  111. data/lib/cisco_node_utils/encapsulation.rb +112 -0
  112. data/lib/cisco_node_utils/environment.rb +102 -0
  113. data/lib/cisco_node_utils/evpn_vni.rb +5 -3
  114. data/lib/cisco_node_utils/exceptions.rb +111 -0
  115. data/lib/cisco_node_utils/fabricpath_global.rb +52 -35
  116. data/lib/cisco_node_utils/fabricpath_topology.rb +44 -57
  117. data/lib/cisco_node_utils/feature.rb +165 -3
  118. data/lib/cisco_node_utils/interface.rb +1051 -260
  119. data/lib/cisco_node_utils/interface_channel_group.rb +11 -10
  120. data/lib/cisco_node_utils/interface_ospf.rb +1 -2
  121. data/lib/cisco_node_utils/interface_portchannel.rb +4 -12
  122. data/lib/cisco_node_utils/interface_service_vni.rb +7 -7
  123. data/lib/cisco_node_utils/itd_device_group.rb +248 -0
  124. data/lib/cisco_node_utils/itd_device_group_node.rb +144 -0
  125. data/lib/cisco_node_utils/itd_service.rb +523 -0
  126. data/lib/cisco_node_utils/logger.rb +75 -0
  127. data/lib/cisco_node_utils/node.rb +62 -192
  128. data/lib/cisco_node_utils/node_util.rb +56 -10
  129. data/lib/cisco_node_utils/overlay_global.rb +2 -2
  130. data/lib/cisco_node_utils/pim.rb +2 -13
  131. data/lib/cisco_node_utils/pim_group_list.rb +1 -1
  132. data/lib/cisco_node_utils/pim_rp_address.rb +1 -1
  133. data/lib/cisco_node_utils/platform.rb +52 -21
  134. data/lib/cisco_node_utils/portchannel_global.rb +89 -19
  135. data/lib/cisco_node_utils/radius_server.rb +168 -37
  136. data/lib/cisco_node_utils/router_ospf.rb +20 -35
  137. data/lib/cisco_node_utils/router_ospf_vrf.rb +4 -4
  138. data/lib/cisco_node_utils/snmpserver.rb +1 -6
  139. data/lib/cisco_node_utils/snmpuser.rb +6 -4
  140. data/lib/cisco_node_utils/stp_global.rb +676 -0
  141. data/lib/cisco_node_utils/syslog_server.rb +77 -18
  142. data/lib/cisco_node_utils/syslog_settings.rb +1 -1
  143. data/lib/cisco_node_utils/tacacs_server_group.rb +8 -4
  144. data/lib/cisco_node_utils/tacacs_server_host.rb +115 -25
  145. data/lib/cisco_node_utils/vdc.rb +12 -0
  146. data/lib/cisco_node_utils/version.rb +1 -1
  147. data/lib/cisco_node_utils/vlan.rb +147 -29
  148. data/lib/cisco_node_utils/vpc.rb +55 -3
  149. data/lib/cisco_node_utils/vrf.rb +72 -11
  150. data/lib/cisco_node_utils/vrf_af.rb +114 -29
  151. data/lib/cisco_node_utils/vtp.rb +34 -52
  152. data/lib/cisco_node_utils/vxlan_vtep.rb +34 -8
  153. data/lib/cisco_node_utils/vxlan_vtep_vni.rb +36 -4
  154. data/lib/minitest/environment_plugin.rb +31 -0
  155. data/lib/minitest/log_level_plugin.rb +41 -0
  156. data/spec/client_spec.rb +7 -0
  157. data/spec/environment_spec.rb +263 -0
  158. data/spec/grpc_client_spec.rb +23 -0
  159. data/spec/isolate/all_clients_spec.rb +9 -0
  160. data/spec/isolate/grpc_only_spec.rb +16 -0
  161. data/spec/isolate/no_clients_spec.rb +26 -0
  162. data/spec/isolate/nxapi_only_spec.rb +16 -0
  163. data/spec/nxapi_client_spec.rb +42 -0
  164. data/spec/schema.yaml +75 -0
  165. data/spec/shared_examples_for_clients.rb +14 -0
  166. data/spec/spec_helper.rb +91 -0
  167. data/spec/whitespace_spec.rb +10 -0
  168. data/spec/yaml_spec.rb +42 -0
  169. data/tests/.rubocop.yml +2 -2
  170. data/tests/CSCuxdublin-1.0.0-7.0.3.I3.1.lib32_n9000.rpm +0 -0
  171. data/tests/basetest.rb +96 -36
  172. data/tests/ciscotest.rb +220 -12
  173. data/tests/cmd_config.yaml +71 -49
  174. data/tests/cmd_config_invalid.yaml +1 -1
  175. data/tests/test_aaa_authentication_login.rb +1 -0
  176. data/tests/test_aaa_authentication_login_service.rb +9 -0
  177. data/tests/test_aaa_authorization_service.rb +173 -367
  178. data/tests/test_ace.rb +171 -100
  179. data/tests/test_acl.rb +10 -1
  180. data/tests/test_bgp_af.rb +395 -728
  181. data/tests/test_bgp_neighbor.rb +274 -115
  182. data/tests/test_bgp_neighbor_af.rb +178 -77
  183. data/tests/test_bridge_domain.rb +191 -0
  184. data/tests/test_bridge_domain_vni.rb +116 -0
  185. data/tests/test_client_utils.rb +111 -0
  186. data/tests/test_command_config.rb +9 -5
  187. data/tests/test_command_reference.rb +380 -102
  188. data/tests/test_dns_domain.rb +13 -3
  189. data/tests/test_domain_name.rb +13 -3
  190. data/tests/test_encapsulation.rb +77 -0
  191. data/tests/test_evpn_vni.rb +25 -7
  192. data/tests/test_fabricpath_global.rb +167 -163
  193. data/tests/test_fabricpath_topology.rb +12 -33
  194. data/tests/test_feature.rb +215 -0
  195. data/tests/test_grpc.rb +166 -0
  196. data/tests/test_interface.rb +585 -344
  197. data/tests/test_interface_bdi.rb +80 -0
  198. data/tests/test_interface_channel_group.rb +6 -3
  199. data/tests/test_interface_ospf.rb +26 -24
  200. data/tests/test_interface_portchannel.rb +1 -0
  201. data/tests/test_interface_private_vlan.rb +724 -0
  202. data/tests/test_interface_service_vni.rb +37 -66
  203. data/tests/test_interface_svi.rb +98 -101
  204. data/tests/test_interface_switchport.rb +419 -549
  205. data/tests/test_itd_device_group.rb +145 -0
  206. data/tests/test_itd_device_group_node.rb +199 -0
  207. data/tests/test_itd_service.rb +298 -0
  208. data/tests/test_logger.rb +43 -0
  209. data/tests/test_name_server.rb +11 -2
  210. data/tests/test_node.rb +16 -75
  211. data/tests/test_node_ext.rb +174 -163
  212. data/tests/test_node_util.rb +119 -0
  213. data/tests/test_ntp_config.rb +5 -1
  214. data/tests/test_ntp_server.rb +2 -2
  215. data/tests/test_nxapi.rb +221 -0
  216. data/tests/test_overlay_global.rb +47 -38
  217. data/tests/test_pim.rb +2 -0
  218. data/tests/test_pim_group_list.rb +2 -0
  219. data/tests/test_pim_rp_address.rb +2 -0
  220. data/tests/test_platform.rb +86 -39
  221. data/tests/test_portchannel_global.rb +211 -135
  222. data/tests/test_radius_global.rb +13 -5
  223. data/tests/test_radius_server.rb +256 -104
  224. data/tests/test_radius_server_group.rb +2 -0
  225. data/tests/test_router_bgp.rb +781 -485
  226. data/tests/test_router_ospf.rb +26 -103
  227. data/tests/test_router_ospf_vrf.rb +52 -57
  228. data/tests/test_snmp_notification_receiver.rb +2 -0
  229. data/tests/test_snmpcommunity.rb +2 -0
  230. data/tests/test_snmpgroup.rb +2 -0
  231. data/tests/test_snmpnotification.rb +40 -21
  232. data/tests/test_snmpserver.rb +2 -0
  233. data/tests/test_snmpuser.rb +2 -0
  234. data/tests/test_stp_global.rb +563 -0
  235. data/tests/test_syslog_server.rb +32 -8
  236. data/tests/test_syslog_settings.rb +22 -9
  237. data/tests/test_tacacs_server.rb +32 -27
  238. data/tests/test_tacacs_server_group.rb +100 -45
  239. data/tests/test_tacacs_server_host.rb +135 -43
  240. data/tests/test_vdc.rb +2 -16
  241. data/tests/test_vlan.rb +106 -54
  242. data/tests/test_vlan_mt_full.rb +11 -21
  243. data/tests/test_vlan_private.rb +669 -0
  244. data/tests/test_vpc.rb +312 -159
  245. data/tests/test_vrf.rb +122 -113
  246. data/tests/test_vrf_af.rb +238 -0
  247. data/tests/test_vtp.rb +58 -102
  248. data/tests/test_vxlan_vtep.rb +38 -17
  249. data/tests/test_vxlan_vtep_vni.rb +61 -9
  250. data/tests/test_yum.rb +49 -25
  251. metadata +122 -36
  252. data/lib/cisco_node_utils/cmd_ref/fex.yaml +0 -9
  253. data/lib/cisco_node_utils/cmd_ref/vni.yaml +0 -76
  254. data/lib/cisco_node_utils/vni.rb +0 -227
  255. data/tests/test_vni.rb +0 -106
@@ -39,7 +39,9 @@ class TestVlanMtFull < CiscoTestCase
39
39
 
40
40
  def setup
41
41
  super
42
- cleanup unless @@cleaned
42
+ return if @@cleaned
43
+ cleanup
44
+ remove_all_bridge_domains # BDs may conflict with our test vlans
43
45
  @@cleaned = true # rubocop:disable Style/ClassVars
44
46
  end
45
47
 
@@ -48,25 +50,12 @@ class TestVlanMtFull < CiscoTestCase
48
50
  end
49
51
 
50
52
  def interface_ethernet_default(ethernet_id)
51
- config("default interface ethernet #{ethernet_id}")
52
- end
53
-
54
- def compatible_interface?
55
- # MT-full tests require a specific linecard; either because they need a
56
- # compatible interface or simply to enable the features. Either way
57
- # we will provide an appropriate interface name if the linecard is present.
58
- # Example 'show mod' output to match against:
59
- # '9 12 10/40 Gbps Ethernet Module N7K-F312FQ-25 ok'
60
- sh_mod = @device.cmd("sh mod | i '^[0-9]+.*N7K-F3'")[/^(\d+)\s.*N7K-F3/]
61
- slot = sh_mod.nil? ? nil : Regexp.last_match[1]
62
- skip('Unable to find a compatible interface in chassis') if slot.nil?
63
-
64
- "ethernet#{slot}/1"
53
+ config("default interface #{ethernet_id}")
65
54
  end
66
55
 
67
56
  def mt_full_env_setup
68
57
  skip('Platform does not support MT-full') unless VxlanVtep.mt_full_support
69
- compatible_interface?
58
+ mt_full_interface?
70
59
  v = Vdc.new('default')
71
60
  v.limit_resource_module_type = 'f3' unless
72
61
  v.limit_resource_module_type == 'f3'
@@ -77,8 +66,9 @@ class TestVlanMtFull < CiscoTestCase
77
66
 
78
67
  # Test for valid mode
79
68
  v = Vlan.new(2000)
80
- assert_equal('ce', v.mode,
81
- 'Mode should have been default to ce')
69
+ default = v.default_mode
70
+ assert_equal(default, v.mode,
71
+ 'Mode should have been default value: #{default}')
82
72
  v.mode = 'fabricpath'
83
73
  assert_equal(:enabled, v.fabricpath_feature,
84
74
  'Fabricpath feature should have been enabled')
@@ -87,9 +77,9 @@ class TestVlanMtFull < CiscoTestCase
87
77
 
88
78
  # Test for invalid mode
89
79
  v = Vlan.new(100)
90
- assert_equal('ce', v.mode,
91
- 'Mode should have been default to ce')
80
+ assert_equal(default, v.mode,
81
+ 'Mode should have been default value: #{default}')
92
82
 
93
- assert_raises(RuntimeError) { v.mode = 'junk' }
83
+ assert_raises(CliError) { v.mode = 'junk' }
94
84
  end
95
85
  end
@@ -0,0 +1,669 @@
1
+ # NXAPI New test for feature private-vlan
2
+ # Davide Celotto Febraury 2016
3
+ # Copyright (c) 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 'ciscotest'
18
+ require_relative '../lib/cisco_node_utils/vlan'
19
+
20
+ include Cisco
21
+
22
+ # TestVlan - Minitest for Vlan node utility
23
+ class TestVlan < CiscoTestCase
24
+ @skip_unless_supported = 'vlan'
25
+
26
+ @@cleaned = false # rubocop:disable Style/ClassVars
27
+ def cleanup
28
+ Vlan.vlans.each do |vlan, obj|
29
+ # skip reserved vlans
30
+ next if vlan == '1'
31
+ next if node.product_id[/N5K|N6K|N7K/] && (1002..1005).include?(vlan.to_i)
32
+ obj.destroy
33
+ end
34
+ config_no_warn('no feature vtp')
35
+ config_no_warn('no feature private-vlan')
36
+ end
37
+
38
+ def setup
39
+ super
40
+ cleanup unless @@cleaned
41
+ @@cleaned = true # rubocop:disable Style/ClassVars
42
+ end
43
+
44
+ def teardown
45
+ cleanup
46
+ end
47
+
48
+ def test_private_type_default
49
+ config_no_warn('no feature vtp')
50
+ config_no_warn('feature private-vlan')
51
+ v1 = Vlan.new(100)
52
+ pv_type = ''
53
+ if validate_property_excluded?('vlan', 'private_vlan_type')
54
+ assert_nil(v1.private_vlan_type)
55
+ else
56
+ assert_equal(pv_type, v1.private_vlan_type)
57
+ end
58
+ end
59
+
60
+ def test_private_association_default
61
+ config_no_warn('no feature vtp')
62
+ config_no_warn('feature private-vlan')
63
+ v1 = Vlan.new(100)
64
+ if validate_property_excluded?('vlan', 'private_vlan_type')
65
+ assert_nil(v1.private_vlan_type)
66
+ return
67
+ else
68
+ result = []
69
+ assert_equal(result, v1.private_vlan_association)
70
+ end
71
+ end
72
+
73
+ def test_private_vlan_type_primary
74
+ v1 = Vlan.new(100)
75
+ pv_type = 'primary'
76
+ if validate_property_excluded?('vlan', 'private_vlan_type')
77
+ assert_nil(v1.private_vlan_type)
78
+ assert_raises(Cisco::UnsupportedError) do
79
+ v1.private_vlan_type = pv_type
80
+ end
81
+ else
82
+ v1.private_vlan_type = pv_type
83
+ assert_equal(pv_type, v1.private_vlan_type)
84
+ end
85
+ end
86
+
87
+ def test_no_private_vlan_type_primary
88
+ v1 = Vlan.new(200)
89
+ pv_type = 'primary'
90
+ if validate_property_excluded?('vlan', 'private_vlan_type')
91
+ assert_nil(v1.private_vlan_type)
92
+ assert_raises(Cisco::UnsupportedError) do
93
+ v1.private_vlan_type = pv_type
94
+ end
95
+ return
96
+ else
97
+ v1.private_vlan_type = pv_type
98
+ assert_equal(pv_type, v1.private_vlan_type)
99
+ pv_type = ''
100
+ v1.private_vlan_type = pv_type
101
+ assert_equal(pv_type, v1.private_vlan_type)
102
+ end
103
+ end
104
+
105
+ def test_multi_private_vlan_type_primary
106
+ v1 = Vlan.new(100)
107
+ v2 = Vlan.new(101)
108
+ v3 = Vlan.new(200)
109
+ v4 = Vlan.new(201)
110
+ v5 = Vlan.new(203)
111
+ pv_type = 'primary'
112
+ if validate_property_excluded?('vlan', 'private_vlan_type')
113
+ assert_nil(v1.private_vlan_type)
114
+ assert_raises(Cisco::UnsupportedError) do
115
+ v1.private_vlan_type = pv_type
116
+ end
117
+ return
118
+ else
119
+ v1.private_vlan_type = pv_type
120
+ v2.private_vlan_type = pv_type
121
+ v3.private_vlan_type = pv_type
122
+ v4.private_vlan_type = pv_type
123
+ v5.private_vlan_type = pv_type
124
+
125
+ assert_equal(pv_type, v1.private_vlan_type)
126
+ assert_equal(pv_type, v2.private_vlan_type)
127
+ assert_equal(pv_type, v3.private_vlan_type)
128
+ assert_equal(pv_type, v4.private_vlan_type)
129
+ assert_equal(pv_type, v5.private_vlan_type)
130
+ end
131
+ end
132
+
133
+ def test_private_vlan_type_isolated
134
+ v1 = Vlan.new(100)
135
+ pv_type = 'isolated'
136
+ if validate_property_excluded?('vlan', 'private_vlan_type')
137
+ assert_nil(v1.private_vlan_type)
138
+ assert_raises(Cisco::UnsupportedError) do
139
+ v1.private_vlan_type = pv_type
140
+ end
141
+ else
142
+ v1.private_vlan_type = pv_type
143
+ assert_equal(pv_type, v1.private_vlan_type)
144
+ end
145
+ end
146
+
147
+ def test_private_vlan_type_community
148
+ v1 = Vlan.new(100)
149
+ pv_type = 'community'
150
+ if validate_property_excluded?('vlan', 'private_vlan_type')
151
+ assert_nil(v1.private_vlan_type)
152
+ assert_raises(Cisco::UnsupportedError) do
153
+ v1.private_vlan_type = pv_type
154
+ end
155
+ else
156
+ v1.private_vlan_type = pv_type
157
+ assert_equal(pv_type, v1.private_vlan_type)
158
+ end
159
+ end
160
+
161
+ def test_private_vlan_type_isolated_primary
162
+ v1 = Vlan.new(100)
163
+ pv_type = 'isolated'
164
+ if validate_property_excluded?('vlan', 'private_vlan_type')
165
+ assert_nil(v1.private_vlan_type)
166
+ assert_raises(Cisco::UnsupportedError) do
167
+ v1.private_vlan_type = pv_type
168
+ end
169
+ return
170
+ else
171
+ v1.private_vlan_type = pv_type
172
+ assert_equal(pv_type, v1.private_vlan_type)
173
+ v2 = Vlan.new(200)
174
+ pv_type = 'primary'
175
+ v2.private_vlan_type = pv_type
176
+ assert_equal(pv_type, v2.private_vlan_type)
177
+ end
178
+ end
179
+
180
+ def test_private_vlan_type_isolated_community_primary
181
+ v1 = Vlan.new(100)
182
+ pv_type = 'isolated'
183
+ if validate_property_excluded?('vlan', 'private_vlan_type')
184
+ assert_nil(v1.private_vlan_type)
185
+ assert_raises(Cisco::UnsupportedError) do
186
+ v1.private_vlan_type = pv_type
187
+ end
188
+ return
189
+ else
190
+ v1.private_vlan_type = pv_type
191
+ assert_equal(pv_type, v1.private_vlan_type)
192
+ v2 = Vlan.new(200)
193
+ pv_type = 'primary'
194
+ v2.private_vlan_type = pv_type
195
+ assert_equal(pv_type, v2.private_vlan_type)
196
+ v3 = Vlan.new(300)
197
+ pv_type = 'community'
198
+ v3.private_vlan_type = pv_type
199
+ assert_equal(pv_type, v3.private_vlan_type)
200
+ end
201
+ end
202
+
203
+ def test_private_vlan_type_change_isolated_to_primary
204
+ v1 = Vlan.new(100)
205
+ pv_type = 'isolated'
206
+ if validate_property_excluded?('vlan', 'private_vlan_type')
207
+ assert_nil(v1.private_vlan_type)
208
+ assert_raises(Cisco::UnsupportedError) do
209
+ v1.private_vlan_type = pv_type
210
+ end
211
+ return
212
+ else
213
+ v1.private_vlan_type = pv_type
214
+ assert_equal(pv_type, v1.private_vlan_type)
215
+ pv_type = 'primary'
216
+ v1.private_vlan_type = pv_type
217
+ assert_equal(pv_type, v1.private_vlan_type)
218
+ end
219
+ end
220
+
221
+ def test_private_vlan_type_change_isolated_to_community
222
+ v1 = Vlan.new(100)
223
+ pv_type = 'isolated'
224
+ if validate_property_excluded?('vlan', 'private_vlan_type')
225
+ assert_nil(v1.private_vlan_type)
226
+ assert_raises(Cisco::UnsupportedError) do
227
+ v1.private_vlan_type = pv_type
228
+ end
229
+ return
230
+ else
231
+ v1.private_vlan_type = pv_type
232
+ assert_equal(pv_type, v1.private_vlan_type)
233
+ pv_type = 'community'
234
+ v1.private_vlan_type = pv_type
235
+ assert_equal(pv_type, v1.private_vlan_type)
236
+ end
237
+ end
238
+
239
+ def test_private_vlan_type_change_community_to_isolated
240
+ v1 = Vlan.new(100)
241
+ pv_type = 'community'
242
+ if validate_property_excluded?('vlan', 'private_vlan_type')
243
+ assert_nil(v1.private_vlan_type)
244
+ assert_raises(Cisco::UnsupportedError) do
245
+ v1.private_vlan_type = pv_type
246
+ end
247
+ return
248
+ else
249
+ v1.private_vlan_type = pv_type
250
+ assert_equal(pv_type, v1.private_vlan_type)
251
+ pv_type = 'isolated'
252
+ v1.private_vlan_type = pv_type
253
+ assert_equal(pv_type, v1.private_vlan_type)
254
+ end
255
+ end
256
+
257
+ def test_private_vlan_type_change_community_to_primary
258
+ v1 = Vlan.new(100)
259
+ pv_type = 'community'
260
+ if validate_property_excluded?('vlan', 'private_vlan_type')
261
+ assert_nil(v1.private_vlan_type)
262
+ assert_raises(Cisco::UnsupportedError) do
263
+ v1.private_vlan_type = pv_type
264
+ end
265
+ return
266
+ else
267
+ v1.private_vlan_type = pv_type
268
+ assert_equal(pv_type, v1.private_vlan_type)
269
+ pv_type = 'primary'
270
+ v1.private_vlan_type = pv_type
271
+ assert_equal(pv_type, v1.private_vlan_type)
272
+ end
273
+ end
274
+
275
+ def test_private_vlan_type_change_primary_to_isolated
276
+ v1 = Vlan.new(100)
277
+ pv_type = 'primary'
278
+ if validate_property_excluded?('vlan', 'private_vlan_type')
279
+ assert_nil(v1.private_vlan_type)
280
+ assert_raises(Cisco::UnsupportedError) do
281
+ v1.private_vlan_type = pv_type
282
+ end
283
+ return
284
+ else
285
+ v1.private_vlan_type = pv_type
286
+ assert_equal(pv_type, v1.private_vlan_type)
287
+ pv_type = 'isolated'
288
+ v1.private_vlan_type = pv_type
289
+ assert_equal(pv_type, v1.private_vlan_type)
290
+ end
291
+ end
292
+
293
+ def test_private_vlan_type_change_primary_to_community
294
+ v1 = Vlan.new(100)
295
+ pv_type = 'primary'
296
+ if validate_property_excluded?('vlan', 'private_vlan_type')
297
+ assert_nil(v1.private_vlan_type)
298
+ assert_raises(Cisco::UnsupportedError) do
299
+ v1.private_vlan_type = pv_type
300
+ end
301
+ return
302
+ else
303
+ v1.private_vlan_type = pv_type
304
+ assert_equal(pv_type, v1.private_vlan_type)
305
+ pv_type = 'community'
306
+ v1.private_vlan_type = pv_type
307
+ assert_equal(pv_type, v1.private_vlan_type)
308
+ end
309
+ end
310
+
311
+ def test_private_vlan_isolate_association
312
+ vlan_list = %w(100 101)
313
+ result = ['101']
314
+ v1 = Vlan.new(vlan_list[0])
315
+ v2 = Vlan.new(vlan_list[1])
316
+ pv_type = 'primary'
317
+ if validate_property_excluded?('vlan', 'private_vlan_type')
318
+ assert_nil(v1.private_vlan_type)
319
+ assert_raises(Cisco::UnsupportedError) do
320
+ v1.private_vlan_type = pv_type
321
+ end
322
+ return
323
+ else
324
+ v1.private_vlan_type = pv_type
325
+ assert_equal(pv_type, v1.private_vlan_type)
326
+ pv_type = 'isolated'
327
+ v2.private_vlan_type = pv_type
328
+ assert_equal(pv_type, v2.private_vlan_type)
329
+
330
+ v1.private_vlan_association = ['101']
331
+
332
+ assert_equal(result, v1.private_vlan_association)
333
+ end
334
+ end
335
+
336
+ def test_private_vlan_community_association
337
+ vlan_list = %w(100 101)
338
+ result = ['101']
339
+ v1 = Vlan.new(vlan_list[0])
340
+ v2 = Vlan.new(vlan_list[1])
341
+ pv_type = 'primary'
342
+ if validate_property_excluded?('vlan', 'private_vlan_type')
343
+ assert_nil(v1.private_vlan_type)
344
+ assert_raises(Cisco::UnsupportedError) do
345
+ v1.private_vlan_type = pv_type
346
+ end
347
+ return
348
+ else
349
+ v1.private_vlan_type = pv_type
350
+ assert_equal(pv_type, v1.private_vlan_type)
351
+ pv_type = 'community'
352
+ v2.private_vlan_type = pv_type
353
+ assert_equal(pv_type, v2.private_vlan_type)
354
+
355
+ v1.private_vlan_association = ['101']
356
+
357
+ assert_equal(result, v1.private_vlan_association)
358
+ end
359
+ end
360
+
361
+ def test_private_vlan_association_failure
362
+ vlan_list = %w(100 101 200)
363
+ result = %w(101 200)
364
+ v1 = Vlan.new(vlan_list[0])
365
+ v2 = Vlan.new(vlan_list[1])
366
+ v3 = Vlan.new(vlan_list[2])
367
+ pv_type = 'primary'
368
+ if validate_property_excluded?('vlan', 'private_vlan_type')
369
+ assert_nil(v1.private_vlan_type)
370
+ assert_raises(Cisco::UnsupportedError) do
371
+ v1.private_vlan_type = pv_type
372
+ end
373
+ return
374
+ else
375
+ v1.private_vlan_type = pv_type
376
+ assert_equal(pv_type, v1.private_vlan_type)
377
+ pv_type = 'isolated'
378
+ v2.private_vlan_type = pv_type
379
+ assert_equal(pv_type, v2.private_vlan_type)
380
+ pv_type = 'community'
381
+ v3.private_vlan_type = pv_type
382
+ assert_equal(pv_type, v3.private_vlan_type)
383
+
384
+ v1.private_vlan_association = %w(101 200)
385
+
386
+ assert_equal(result, v1.private_vlan_association)
387
+
388
+ pv_type = 'isolated'
389
+ assert_raises(RuntimeError, 'vlan misconf did not raise RuntimeError') do
390
+ v3.private_vlan_type = pv_type
391
+ end
392
+
393
+ assert_equal(result, v1.private_vlan_association)
394
+
395
+ end
396
+ end
397
+
398
+ def test_private_vlan_association_operational_and_not_operational
399
+ vlan_list = %w(100 101 200)
400
+ result = %w(101 200)
401
+
402
+ v1 = Vlan.new(vlan_list[0])
403
+ v2 = Vlan.new(vlan_list[1])
404
+
405
+ pv_type = 'primary'
406
+ if validate_property_excluded?('vlan', 'private_vlan_type')
407
+ assert_nil(v1.private_vlan_type)
408
+ assert_raises(Cisco::UnsupportedError) do
409
+ v1.private_vlan_type = pv_type
410
+ end
411
+ return
412
+ else
413
+ v1.private_vlan_type = pv_type
414
+ assert_equal(pv_type, v1.private_vlan_type)
415
+
416
+ pv_type = 'isolated'
417
+ v2.private_vlan_type = pv_type
418
+ assert_equal(pv_type, v2.private_vlan_type)
419
+
420
+ v1.private_vlan_association = %w(101 200)
421
+
422
+ assert_equal(result, v1.private_vlan_association)
423
+ end
424
+ end
425
+
426
+ def test_private_vlan_association_vlan_not_configured
427
+ vlan_list = %w(100 101 200)
428
+ result = %w(101 200)
429
+ v1 = Vlan.new(vlan_list[0])
430
+ v2 = Vlan.new(vlan_list[1])
431
+ pv_type = 'primary'
432
+ if validate_property_excluded?('vlan', 'private_vlan_type')
433
+ assert_nil(v1.private_vlan_type)
434
+ assert_raises(Cisco::UnsupportedError) do
435
+ v1.private_vlan_type = pv_type
436
+ end
437
+ return
438
+ else
439
+ v1.private_vlan_type = pv_type
440
+ assert_equal(pv_type, v1.private_vlan_type)
441
+ pv_type = 'isolated'
442
+ v2.private_vlan_type = pv_type
443
+ assert_equal(pv_type, v2.private_vlan_type)
444
+
445
+ v1.private_vlan_association = %w(101 200)
446
+ assert_equal(result, v1.private_vlan_association)
447
+ end
448
+ end
449
+
450
+ def test_private_vlan_association_add_vlan
451
+ vlan_list = %w(100 101)
452
+ result = ['101']
453
+ v1 = Vlan.new(vlan_list[0])
454
+ v2 = Vlan.new(vlan_list[1])
455
+ pv_type = 'primary'
456
+ if validate_property_excluded?('vlan', 'private_vlan_type')
457
+ assert_nil(v1.private_vlan_type)
458
+ assert_raises(Cisco::UnsupportedError) do
459
+ v1.private_vlan_type = pv_type
460
+ end
461
+ return
462
+ else
463
+ v1.private_vlan_type = pv_type
464
+ assert_equal(pv_type, v1.private_vlan_type)
465
+ pv_type = 'isolated'
466
+ v2.private_vlan_type = pv_type
467
+ assert_equal(pv_type, v2.private_vlan_type)
468
+
469
+ v1.private_vlan_association = ['101']
470
+ assert_equal(result, v1.private_vlan_association)
471
+ end
472
+ end
473
+
474
+ def test_private_vlan_association_remove_vlan
475
+ vlan_list = %w(100 101 200)
476
+ result = %w(101 200)
477
+ v1 = Vlan.new(vlan_list[0])
478
+ v2 = Vlan.new(vlan_list[1])
479
+ v3 = Vlan.new(vlan_list[2])
480
+ pv_type = 'primary'
481
+ if validate_property_excluded?('vlan', 'private_vlan_type')
482
+ assert_nil(v1.private_vlan_type)
483
+ assert_raises(Cisco::UnsupportedError) do
484
+ v1.private_vlan_type = pv_type
485
+ end
486
+ return
487
+ else
488
+ v1.private_vlan_type = pv_type
489
+ assert_equal(pv_type, v1.private_vlan_type)
490
+ pv_type = 'isolated'
491
+ v2.private_vlan_type = pv_type
492
+ assert_equal(pv_type, v2.private_vlan_type)
493
+
494
+ pv_type = 'community'
495
+ v3.private_vlan_type = pv_type
496
+ assert_equal(pv_type, v3.private_vlan_type)
497
+
498
+ v1.private_vlan_association = %w(101 200)
499
+ assert_equal(result, v1.private_vlan_association)
500
+
501
+ # v1.private_vlan_association_remove_vlans = '101'
502
+ # result = '200'
503
+ # assert_equal(result, vlan_list(v1))
504
+
505
+ end
506
+ end
507
+
508
+ def test_no_private_vlan_association
509
+ vlan_list = %w(100 101 200)
510
+ result = %w(101 200)
511
+ v1 = Vlan.new(vlan_list[0])
512
+ v2 = Vlan.new(vlan_list[1])
513
+ v3 = Vlan.new(vlan_list[2])
514
+
515
+ pv_type = 'primary'
516
+ if validate_property_excluded?('vlan', 'private_vlan_type')
517
+ assert_nil(v1.private_vlan_type)
518
+ assert_raises(Cisco::UnsupportedError) do
519
+ v1.private_vlan_type = pv_type
520
+ end
521
+ return
522
+ else
523
+ v1.private_vlan_type = pv_type
524
+ assert_equal(pv_type, v1.private_vlan_type)
525
+
526
+ pv_type = 'isolated'
527
+ v2.private_vlan_type = pv_type
528
+ assert_equal(pv_type, v2.private_vlan_type)
529
+
530
+ pv_type = 'community'
531
+ v3.private_vlan_type = pv_type
532
+ assert_equal(pv_type, v3.private_vlan_type)
533
+
534
+ v1.private_vlan_association = %w(101 200)
535
+ assert_equal(result, v1.private_vlan_association)
536
+
537
+ v1.private_vlan_association = ['200']
538
+ result = ['200']
539
+ assert_equal(result, v1.private_vlan_association)
540
+
541
+ end
542
+ end
543
+
544
+ def test_no_private_vlan_association_all
545
+ vlan_list = %w(100 101 200)
546
+ result = %w(101 200)
547
+ v1 = Vlan.new(vlan_list[0])
548
+ v2 = Vlan.new(vlan_list[1])
549
+ v3 = Vlan.new(vlan_list[2])
550
+
551
+ pv_type = 'primary'
552
+ if validate_property_excluded?('vlan', 'private_vlan_type')
553
+ assert_nil(v1.private_vlan_type)
554
+ assert_raises(Cisco::UnsupportedError) do
555
+ v1.private_vlan_type = pv_type
556
+ end
557
+ return
558
+ else
559
+ v1.private_vlan_type = pv_type
560
+ assert_equal(pv_type, v1.private_vlan_type)
561
+
562
+ pv_type = 'isolated'
563
+ v2.private_vlan_type = pv_type
564
+ assert_equal(pv_type, v2.private_vlan_type)
565
+
566
+ pv_type = 'community'
567
+ v3.private_vlan_type = pv_type
568
+ assert_equal(pv_type, v3.private_vlan_type)
569
+
570
+ v1.private_vlan_association = %w(101 200)
571
+ assert_equal(result, v1.private_vlan_association)
572
+ v1.private_vlan_association = []
573
+ result = []
574
+ assert_equal(result, v1.private_vlan_association)
575
+
576
+ end
577
+ end
578
+
579
+ def test_private_vlan_isolate_community_association
580
+ vlan_list = %w(100 101 200)
581
+ result = %w(101 200)
582
+ v1 = Vlan.new(vlan_list[0])
583
+ v2 = Vlan.new(vlan_list[1])
584
+ v3 = Vlan.new(vlan_list[2])
585
+ pv_type = 'primary'
586
+ if validate_property_excluded?('vlan', 'private_vlan_type')
587
+ assert_nil(v1.private_vlan_type)
588
+ assert_raises(Cisco::UnsupportedError) do
589
+ v1.private_vlan_type = pv_type
590
+ end
591
+ return
592
+ else
593
+ v1.private_vlan_type = pv_type
594
+ assert_equal(pv_type, v1.private_vlan_type)
595
+ pv_type = 'isolated'
596
+ v2.private_vlan_type = pv_type
597
+ assert_equal(pv_type, v2.private_vlan_type)
598
+ pv_type = 'community'
599
+ v3.private_vlan_type = pv_type
600
+ assert_equal(pv_type, v3.private_vlan_type)
601
+
602
+ v1.private_vlan_association = %w(101 200)
603
+
604
+ assert_equal(result, v1.private_vlan_association)
605
+ end
606
+ end
607
+
608
+ def test_private_vlan_multi_isolate_community_association
609
+ vlan_list = %w(100 101 102 104 105 200 201 202)
610
+ result = %w(101 104 105 200 202)
611
+ v1 = Vlan.new(vlan_list[0])
612
+
613
+ pv_type = 'primary'
614
+ if validate_property_excluded?('vlan', 'private_vlan_type')
615
+ assert_nil(v1.private_vlan_type)
616
+ assert_raises(Cisco::UnsupportedError) do
617
+ v1.private_vlan_type = pv_type
618
+ end
619
+ return
620
+ else
621
+ v2 = Vlan.new(vlan_list[1])
622
+ v3 = Vlan.new(vlan_list[2])
623
+ v4 = Vlan.new(vlan_list[3])
624
+ v5 = Vlan.new(vlan_list[4])
625
+ v6 = Vlan.new(vlan_list[5])
626
+ v7 = Vlan.new(vlan_list[6])
627
+
628
+ v1.private_vlan_type = pv_type
629
+ assert_equal(pv_type, v1.private_vlan_type)
630
+
631
+ pv_type = 'isolated'
632
+ v2.private_vlan_type = pv_type
633
+ assert_equal(pv_type, v2.private_vlan_type)
634
+
635
+ pv_type = 'isolated'
636
+ v3.private_vlan_type = pv_type
637
+ assert_equal(pv_type, v3.private_vlan_type)
638
+
639
+ pv_type = 'community'
640
+ v4.private_vlan_type = pv_type
641
+ assert_equal(pv_type, v4.private_vlan_type)
642
+
643
+ pv_type = 'community'
644
+ v5.private_vlan_type = pv_type
645
+ assert_equal(pv_type, v5.private_vlan_type)
646
+
647
+ pv_type = 'community'
648
+ v6.private_vlan_type = pv_type
649
+ assert_equal(pv_type, v6.private_vlan_type)
650
+
651
+ pv_type = 'primary'
652
+ v7.private_vlan_type = pv_type
653
+ assert_equal(pv_type, v7.private_vlan_type)
654
+
655
+ v1.private_vlan_association = ['101', '104-105', '200', '202']
656
+
657
+ assert_equal(result, v1.private_vlan_association)
658
+
659
+ v1.private_vlan_association = ['101', '103-105', '108']
660
+
661
+ result = %w(101 103 104 105 108)
662
+ assert_equal(result, v1.private_vlan_association)
663
+
664
+ v1.private_vlan_association = ['101', '103-105', '108']
665
+ result = %w(101 103 104 105 108)
666
+ assert_equal(result, v1.private_vlan_association)
667
+ end
668
+ end
669
+ end