cisco_node_utils 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +81 -1
- data/.travis.yml +9 -0
- data/CHANGELOG.md +72 -6
- data/CONTRIBUTING.md +32 -7
- data/README.md +70 -7
- data/Rakefile +17 -0
- data/bin/check_metric_limits.rb +109 -0
- data/bin/git/hooks/commit-msg/enforce_style +81 -0
- data/bin/git/hooks/hook_lib +108 -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/rubocop +20 -0
- data/bin/git/hooks/pre-commit/validate-diffs +31 -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 +65 -0
- data/cisco_node_utils.gemspec +9 -3
- data/docs/README-develop-best-practices.md +404 -0
- data/docs/README-develop-node-utils-APIs.md +215 -365
- data/docs/README-maintainers.md +33 -3
- data/docs/template-router.rb +89 -91
- data/docs/template-test_router.rb +52 -55
- data/lib/.rubocop.yml +18 -0
- data/lib/cisco_node_utils.rb +2 -19
- data/lib/cisco_node_utils/README_YAML.md +1 -9
- data/lib/cisco_node_utils/bgp.rb +664 -0
- data/lib/cisco_node_utils/bgp_af.rb +530 -0
- data/lib/cisco_node_utils/bgp_neighbor.rb +425 -0
- data/lib/cisco_node_utils/bgp_neighbor_af.rb +709 -0
- data/lib/cisco_node_utils/cisco_cmn_utils.rb +59 -25
- data/lib/cisco_node_utils/command_reference.rb +72 -74
- data/lib/cisco_node_utils/command_reference_common.yaml +174 -9
- data/lib/cisco_node_utils/command_reference_common_bgp.yaml +535 -0
- data/lib/cisco_node_utils/command_reference_n7k.yaml +4 -0
- data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -9
- data/lib/cisco_node_utils/configparser_lib.rb +152 -147
- data/lib/cisco_node_utils/dns_domain.rb +79 -0
- data/lib/cisco_node_utils/domain_name.rb +71 -0
- data/lib/cisco_node_utils/interface.rb +167 -161
- data/lib/cisco_node_utils/interface_ospf.rb +78 -81
- data/lib/cisco_node_utils/name_server.rb +64 -0
- data/lib/cisco_node_utils/node.rb +154 -198
- data/lib/cisco_node_utils/node_util.rb +61 -0
- data/lib/cisco_node_utils/ntp_config.rb +65 -0
- data/lib/cisco_node_utils/ntp_server.rb +76 -0
- data/lib/cisco_node_utils/platform.rb +174 -165
- data/lib/cisco_node_utils/radius_global.rb +146 -0
- data/lib/cisco_node_utils/radius_server.rb +295 -0
- data/lib/cisco_node_utils/router_ospf.rb +59 -63
- data/lib/cisco_node_utils/router_ospf_vrf.rb +226 -210
- data/lib/cisco_node_utils/snmpcommunity.rb +52 -58
- data/lib/cisco_node_utils/snmpgroup.rb +22 -23
- data/lib/cisco_node_utils/snmpserver.rb +99 -103
- data/lib/cisco_node_utils/snmpuser.rb +294 -274
- data/lib/cisco_node_utils/syslog_server.rb +92 -0
- data/lib/cisco_node_utils/syslog_settings.rb +69 -0
- data/lib/cisco_node_utils/tacacs_server.rb +137 -133
- data/lib/cisco_node_utils/tacacs_server_host.rb +84 -87
- data/lib/cisco_node_utils/version.rb +2 -1
- data/lib/cisco_node_utils/vlan.rb +28 -31
- data/lib/cisco_node_utils/vrf.rb +80 -0
- data/lib/cisco_node_utils/vtp.rb +100 -97
- data/lib/cisco_node_utils/yum.rb +15 -17
- data/tests/.rubocop.yml +15 -0
- data/tests/basetest.rb +81 -36
- data/tests/ciscotest.rb +38 -78
- data/{lib/cisco_node_utils → tests}/platform_info.rb +12 -8
- data/{lib/cisco_node_utils → tests}/platform_info.yaml +1 -1
- data/tests/test_bgp_af.rb +920 -0
- data/tests/test_bgp_neighbor.rb +403 -0
- data/tests/test_bgp_neighbor_af.rb +589 -0
- data/tests/test_command_config.rb +65 -62
- data/tests/test_command_reference.rb +31 -45
- data/tests/test_dns_domain.rb +113 -0
- data/tests/test_domain_name.rb +86 -0
- data/tests/test_interface.rb +424 -548
- data/tests/test_interface_ospf.rb +248 -432
- data/tests/test_interface_svi.rb +56 -79
- data/tests/test_interface_switchport.rb +196 -272
- data/tests/test_name_server.rb +85 -0
- data/tests/test_node.rb +7 -6
- data/tests/test_node_ext.rb +133 -186
- data/tests/test_ntp_config.rb +49 -0
- data/tests/test_ntp_server.rb +74 -0
- data/tests/test_platform.rb +58 -37
- data/tests/test_radius_global.rb +78 -0
- data/tests/test_radius_server.rb +185 -0
- data/tests/test_router_bgp.rb +838 -0
- data/tests/test_router_ospf.rb +49 -80
- data/tests/test_router_ospf_vrf.rb +274 -392
- data/tests/test_snmpcommunity.rb +128 -172
- data/tests/test_snmpgroup.rb +12 -14
- data/tests/test_snmpserver.rb +160 -189
- data/tests/test_snmpuser.rb +568 -717
- data/tests/test_syslog_server.rb +88 -0
- data/tests/test_syslog_settings.rb +54 -0
- data/tests/test_tacacs_server.rb +113 -148
- data/tests/test_tacacs_server_host.rb +108 -161
- data/tests/test_vlan.rb +63 -79
- data/tests/test_vrf.rb +92 -0
- data/tests/test_vtp.rb +108 -126
- data/tests/test_yum.rb +47 -41
- metadata +92 -56
- data/.rubocop_todo.yml +0 -293
- data/docs/.rubocop.yml +0 -13
- data/docs/template-feature.rb +0 -45
- data/docs/template-test_feature.rb +0 -51
- data/tests/test_all_cisco.rb +0 -46
data/lib/cisco_node_utils/yum.rb
CHANGED
@@ -17,13 +17,11 @@
|
|
17
17
|
# See the License for the specific language governing permissions and
|
18
18
|
# limitations under the License.
|
19
19
|
|
20
|
-
|
20
|
+
require_relative 'node_util'
|
21
21
|
|
22
22
|
module Cisco
|
23
23
|
# This Yum class provides cisco package management functions through nxapi.
|
24
|
-
class Yum
|
25
|
-
@@node = Cisco::Node.instance
|
26
|
-
|
24
|
+
class Yum < NodeUtil
|
27
25
|
def self.decompose_name(file_name)
|
28
26
|
# ex: chef-12.0.0alpha.2+20150319.git.1.b6f-1.el5.x86_64.rpm
|
29
27
|
name_ver_arch_regex = /^([\w\-\+]+)-(\d+\..*)\.(\w{4,})(?:\.rpm)?$/
|
@@ -40,7 +38,7 @@ module Cisco
|
|
40
38
|
end
|
41
39
|
|
42
40
|
def self.validate(pkg)
|
43
|
-
file_name = pkg.strip.
|
41
|
+
file_name = pkg.strip.tr(':', '/').split('/').last
|
44
42
|
pkg_info = Yum.decompose_name(file_name)
|
45
43
|
if pkg_info.nil?
|
46
44
|
query_name = file_name
|
@@ -54,22 +52,22 @@ module Cisco
|
|
54
52
|
should_ver = pkg_info[2] if pkg_info && pkg_info[3]
|
55
53
|
ver = query(query_name)
|
56
54
|
if ver.nil? || (!should_ver.nil? && should_ver != ver)
|
57
|
-
|
55
|
+
fail 'Failed to install the requested rpm'
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
61
|
-
def self.
|
59
|
+
def self.detect_vrf
|
62
60
|
# Detect current namespace from agent environment
|
63
|
-
inode = File::Stat.new(
|
61
|
+
inode = File::Stat.new('/proc/self/ns/net').ino
|
64
62
|
# -L reqd for guestshell's find command
|
65
63
|
vrfname = File.basename(`find -L /var/run/netns/ -inum #{inode}`.chop)
|
66
|
-
vrf =
|
64
|
+
vrf = 'vrf ' + vrfname unless vrfname.empty?
|
67
65
|
vrf
|
68
66
|
end
|
69
67
|
|
70
|
-
def self.install(pkg, vrf
|
71
|
-
vrf = vrf.nil? ?
|
72
|
-
|
68
|
+
def self.install(pkg, vrf=nil)
|
69
|
+
vrf = vrf.nil? ? detect_vrf : "vrf #{vrf}"
|
70
|
+
config_set('yum', 'install', pkg, vrf)
|
73
71
|
|
74
72
|
# HACK: The current nxos host installer is a multi-part command
|
75
73
|
# which may fail at a later stage yet return a false positive;
|
@@ -80,15 +78,15 @@ module Cisco
|
|
80
78
|
|
81
79
|
# returns version of package, or false if package doesn't exist
|
82
80
|
def self.query(pkg)
|
83
|
-
|
84
|
-
|
85
|
-
b =
|
86
|
-
|
81
|
+
fail TypeError unless pkg.is_a? String
|
82
|
+
fail ArgumentError if pkg.empty?
|
83
|
+
b = config_get('yum', 'query', pkg)
|
84
|
+
fail "Multiple matching packages found for #{pkg}" if b && b.size > 1
|
87
85
|
b.nil? ? nil : b.first
|
88
86
|
end
|
89
87
|
|
90
88
|
def self.remove(pkg)
|
91
|
-
|
89
|
+
config_set('yum', 'remove', pkg)
|
92
90
|
end
|
93
91
|
end
|
94
92
|
end
|
data/tests/.rubocop.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
inherit_from: ../.rubocop.yml
|
2
|
+
|
3
|
+
# Code complexity metrics for the tests/ subdirectory
|
4
|
+
|
5
|
+
Metrics/AbcSize:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Metrics/CyclomaticComplexity:
|
9
|
+
Max: 15
|
10
|
+
|
11
|
+
Metrics/MethodLength:
|
12
|
+
Max: 86
|
13
|
+
|
14
|
+
Metrics/PerceivedComplexity:
|
15
|
+
Max: 17
|
data/tests/basetest.rb
CHANGED
@@ -17,67 +17,78 @@
|
|
17
17
|
# See the License for the specific language governing permissions and
|
18
18
|
# limitations under the License.
|
19
19
|
|
20
|
+
require 'simplecov'
|
21
|
+
SimpleCov.start do
|
22
|
+
# Don't calculate coverage of our test code itself!
|
23
|
+
add_filter '/tests/'
|
24
|
+
end
|
25
|
+
|
20
26
|
require 'rubygems'
|
21
|
-
gem 'minitest', '
|
27
|
+
gem 'minitest', '~> 5.0'
|
22
28
|
require 'minitest/autorun'
|
23
29
|
require 'net/telnet'
|
24
|
-
require 'test/unit'
|
25
30
|
begin
|
26
31
|
require 'cisco_nxapi'
|
27
32
|
rescue LoadError
|
28
|
-
require File.expand_path(
|
33
|
+
require File.expand_path('../../../cisco-nxapi/lib/cisco_nxapi')
|
29
34
|
end
|
30
35
|
|
31
|
-
|
36
|
+
# rubocop:disable Style/ClassVars
|
37
|
+
# We *want* the address/username/password class variables to be shared
|
38
|
+
# with all child classes, so that we only need to initialize them once.
|
39
|
+
|
40
|
+
# TestCase - common base class for all minitest cases in this module.
|
41
|
+
# Most node utility tests should inherit from CiscoTestCase instead.
|
42
|
+
class TestCase < Minitest::Test
|
43
|
+
# These variables can be set in one of three ways:
|
44
|
+
# 1) ARGV:
|
45
|
+
# $ ruby basetest.rb -- address username password
|
46
|
+
# 2) NODE environment variable
|
47
|
+
# $ export NODE="address username password"
|
48
|
+
# $ rake test
|
49
|
+
# 3) At run time:
|
50
|
+
# $ rake test
|
51
|
+
# Enter address or hostname of node under test:
|
32
52
|
@@address = nil
|
33
53
|
@@username = nil
|
34
54
|
@@password = nil
|
35
55
|
|
36
|
-
def process_arguments
|
37
|
-
if ARGV.length != 3 and ARGV.length != 4
|
38
|
-
puts "Usage:"
|
39
|
-
puts " ruby test_nxapi.rb [options] -- <address> <username> <password> [debug]"
|
40
|
-
exit
|
41
|
-
end
|
42
|
-
|
43
|
-
# Record the version of Ruby we got invoked with.
|
44
|
-
puts "\nRuby Version - #{RUBY_VERSION}"
|
45
|
-
|
46
|
-
@@address = ARGV[0]
|
47
|
-
@@username = ARGV[1]
|
48
|
-
@@password = ARGV[2]
|
49
|
-
|
50
|
-
if ARGV.length == 4
|
51
|
-
if ARGV[3] == "debug"
|
52
|
-
CiscoLogger.debug_enable
|
53
|
-
else
|
54
|
-
puts "Only 'debug' is allowed"
|
55
|
-
exit
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# setup-once params
|
61
56
|
def address
|
62
|
-
|
57
|
+
@@address ||= ARGV[0]
|
58
|
+
@@address ||= ENV['NODE'].split(' ')[0] if ENV['NODE']
|
59
|
+
unless @@address
|
60
|
+
print 'Enter address or hostname of node under test: '
|
61
|
+
@@address = gets.chomp
|
62
|
+
end
|
63
63
|
@@address
|
64
64
|
end
|
65
65
|
|
66
66
|
def username
|
67
|
-
|
67
|
+
@@username ||= ARGV[1]
|
68
|
+
@@username ||= ENV['NODE'].split(' ')[1] if ENV['NODE']
|
69
|
+
unless @@username
|
70
|
+
print 'Enter username for node under test: '
|
71
|
+
@@username = gets.chomp
|
72
|
+
end
|
68
73
|
@@username
|
69
74
|
end
|
70
75
|
|
71
76
|
def password
|
72
|
-
|
77
|
+
@@password ||= ARGV[2]
|
78
|
+
@@password ||= ENV['NODE'].split(' ')[2] if ENV['NODE']
|
79
|
+
unless @@password
|
80
|
+
print 'Enter password for node under test: '
|
81
|
+
@@password = gets.chomp
|
82
|
+
end
|
73
83
|
@@password
|
74
84
|
end
|
75
85
|
|
76
86
|
def setup
|
77
|
-
@device = Net::Telnet.new(
|
87
|
+
@device = Net::Telnet.new('Host' => address, 'Timeout' => 240)
|
78
88
|
@device.login(username, password)
|
89
|
+
CiscoLogger.debug_enable if ARGV[3] == 'debug' || ENV['DEBUG'] == '1'
|
79
90
|
rescue Errno::ECONNREFUSED
|
80
|
-
puts
|
91
|
+
puts 'Connection refused - please check that the IP address is correct'
|
81
92
|
puts " and that you have enabled 'feature telnet' on the UUT"
|
82
93
|
exit
|
83
94
|
end
|
@@ -87,7 +98,41 @@ class TestCase < Test::Unit::TestCase
|
|
87
98
|
GC.start
|
88
99
|
end
|
89
100
|
|
90
|
-
def
|
91
|
-
#
|
101
|
+
def config(*args)
|
102
|
+
# Send the entire config as one string but be sure not to return until
|
103
|
+
# we are safely back out of config mode, i.e. prompt is
|
104
|
+
# 'switch#' not 'switch(config)#' or 'switch(config-if)#' etc.
|
105
|
+
@device.cmd('String' => "configure terminal\n" + args.join("\n") + "\nend",
|
106
|
+
'Match' => /^[^()]+[$%#>] \z/n)
|
107
|
+
end
|
108
|
+
|
109
|
+
def assert_show_match(pattern: nil, command: nil, msg: nil)
|
110
|
+
pattern ||= @default_output_pattern
|
111
|
+
refute_nil(pattern)
|
112
|
+
command ||= @default_show_command
|
113
|
+
refute_nil(command)
|
114
|
+
|
115
|
+
output = @device.cmd(command)
|
116
|
+
msg = message(msg) do
|
117
|
+
"Expected #{mu_pp pattern} to match " \
|
118
|
+
"output of '#{mu_pp command}':\n#{output}"
|
119
|
+
end
|
120
|
+
assert pattern =~ output, msg
|
121
|
+
pattern.match(output)
|
122
|
+
end
|
123
|
+
|
124
|
+
def refute_show_match(pattern: nil, command: nil, msg: nil)
|
125
|
+
pattern ||= @default_output_pattern
|
126
|
+
refute_nil(pattern)
|
127
|
+
command ||= @default_show_command
|
128
|
+
refute_nil(command)
|
129
|
+
|
130
|
+
output = @device.cmd(command)
|
131
|
+
msg = message(msg) do
|
132
|
+
"Expected #{mu_pp pattern} to NOT match " \
|
133
|
+
"output of '#{mu_pp command}':\n#{output}"
|
134
|
+
end
|
135
|
+
refute pattern =~ output, msg
|
92
136
|
end
|
93
137
|
end
|
138
|
+
# rubocop:enable Style/ClassVars
|
data/tests/ciscotest.rb
CHANGED
@@ -12,125 +12,85 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
require_relative 'basetest'
|
16
|
+
require_relative 'platform_info'
|
17
|
+
require_relative '../lib/cisco_node_utils/node'
|
18
18
|
|
19
19
|
include Cisco
|
20
20
|
|
21
21
|
Node.lazy_connect = true # we'll specify the connection info later
|
22
22
|
|
23
|
+
# CiscoTestCase - base class for all node utility minitests
|
23
24
|
class CiscoTestCase < TestCase
|
25
|
+
# rubocop:disable Style/ClassVars
|
24
26
|
@@node = nil
|
25
27
|
@@interfaces = nil
|
26
28
|
@@interfaces_id = nil
|
29
|
+
# rubocop:enable Style/ClassVars
|
27
30
|
|
28
31
|
def node
|
29
32
|
unless @@node
|
30
|
-
@@node = Node.instance
|
31
|
-
@@node.connect(
|
33
|
+
@@node = Node.instance # rubocop:disable Style/ClassVars
|
34
|
+
@@node.connect(address, username, password)
|
32
35
|
@@node.cache_enable = true
|
33
36
|
@@node.cache_auto = true
|
34
|
-
|
37
|
+
# Record the platform we're running on
|
38
|
+
puts "\nNode under test:"
|
39
|
+
puts " - name - #{@@node.host_name}"
|
40
|
+
puts " - type - #{@@node.product_id}"
|
41
|
+
puts " - image - #{@@node.system}\n\n"
|
35
42
|
end
|
36
43
|
@@node
|
44
|
+
rescue CiscoNxapi::HTTPUnauthorized
|
45
|
+
puts "Unauthorized to connect as #{username}:#{password}@#{address}"
|
46
|
+
exit
|
37
47
|
end
|
38
48
|
|
39
|
-
def
|
49
|
+
def setup
|
40
50
|
super
|
41
|
-
node
|
42
|
-
# Record the platform we're running on
|
43
|
-
puts "Platform:"
|
44
|
-
puts " - name - #{@@node.host_name}"
|
45
|
-
puts " - type - #{@@node.product_id}"
|
46
|
-
puts " - image - #{@@node.system}\n\n"
|
51
|
+
node
|
47
52
|
end
|
48
53
|
|
49
54
|
def cmd_ref
|
50
55
|
node.cmd_ref
|
51
56
|
end
|
52
57
|
|
58
|
+
def config(*args)
|
59
|
+
result = super
|
60
|
+
node.cache_flush
|
61
|
+
result
|
62
|
+
end
|
63
|
+
|
53
64
|
def interfaces
|
54
65
|
unless @@interfaces
|
55
66
|
# Build the platform_info, used for interface lookup
|
67
|
+
# rubocop:disable Style/ClassVars
|
56
68
|
begin
|
57
69
|
platform_info = PlatformInfo.new(node.host_name)
|
58
|
-
@@interfaces = platform_info.get_value_from_key(
|
59
|
-
rescue
|
60
|
-
# If there is a problem reading platform_info.yaml,
|
61
|
-
|
62
|
-
|
70
|
+
@@interfaces = platform_info.get_value_from_key('interfaces')
|
71
|
+
rescue RuntimeError => e
|
72
|
+
# If there is a problem reading platform_info.yaml,
|
73
|
+
# assign default values
|
74
|
+
default_interfaces = ['Ethernet1/1', 'Ethernet1/2', 'Ethernet1/3']
|
75
|
+
puts "Caught exception: #{e}, assigning interfaces to default " \
|
76
|
+
"- #{default_interfaces}"
|
63
77
|
@@interfaces = default_interfaces
|
64
78
|
end
|
79
|
+
# rubocop:enable Style/ClassVars
|
65
80
|
end
|
66
81
|
@@interfaces
|
67
82
|
end
|
68
83
|
|
69
84
|
def interfaces_id
|
70
85
|
unless @@interfaces_id
|
86
|
+
# rubocop:disable Style/ClassVars
|
71
87
|
@@interfaces_id = []
|
72
|
-
interfaces.each
|
73
|
-
id = interface.split(
|
88
|
+
interfaces.each do |interface|
|
89
|
+
id = interface.split('Ethernet')[1]
|
74
90
|
@@interfaces_id << id
|
75
|
-
|
91
|
+
end
|
92
|
+
# rubocop:enable Style/ClassVars
|
76
93
|
end
|
77
94
|
@@interfaces_id
|
78
95
|
end
|
79
|
-
|
80
|
-
# Class method method to set the class variable 'debug_flag'
|
81
|
-
# Can be true or false.
|
82
|
-
def self.debug_flag=(flag)
|
83
|
-
@@debug_flag = flag
|
84
|
-
end
|
85
|
-
|
86
|
-
# Class method to set the class variable 'debug_method'
|
87
|
-
# Can be name of the method or "all"
|
88
|
-
def self.debug_method=(name)
|
89
|
-
@@debug_method = name
|
90
|
-
end
|
91
|
-
|
92
|
-
# Class method to set the class variable 'debug_group'
|
93
|
-
# Can be the name of the method or "all"
|
94
|
-
def self.debug_group=(group)
|
95
|
-
@@debug_group = group
|
96
|
-
end
|
97
|
-
|
98
|
-
# Class method to set the class variable 'debug_detail'
|
99
|
-
# Can be true or false
|
100
|
-
def self.debug_detail=(detail)
|
101
|
-
@@debug_detail = detail
|
102
|
-
end
|
103
|
-
|
104
|
-
# Class method to dump debug data.
|
105
|
-
# The passed in parameters will control what is printed and how.
|
106
|
-
# Parameters:
|
107
|
-
# method - Name of the method the debug belongs to.
|
108
|
-
# group - Name of the group the debug belongs to.
|
109
|
-
# indent - Indent controls the display of the data.
|
110
|
-
# detail - Detail controls if detail debugs should be displayed.
|
111
|
-
# data - Data to be displayed. Must be a fully formatted string.
|
112
|
-
def self.debug(method, group, indent, data)
|
113
|
-
if (@@debug_flag) &&
|
114
|
-
(((@@debug_method == method) || (@@debug_method == "all")) ||
|
115
|
-
((@@debug_group == group) || (@@debug_group == "all")))
|
116
|
-
indent_spaces = " " * indent
|
117
|
-
puts "#{indent_spaces}#{method} - #{data}"
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
# Class method to dump detailed debug data.
|
122
|
-
# The passed in parameters will control what is printed and how.
|
123
|
-
# Parameters:
|
124
|
-
# method - Name of the method the debug belongs to.
|
125
|
-
# group - Name of the group the debug belongs to.
|
126
|
-
# indent - Indent controls the display of the data.
|
127
|
-
# data - Data to be displayed. Must be a fully formatted string.
|
128
|
-
def self.debug_detail(method, group, indent, data)
|
129
|
-
if (@@debug_detail) &&
|
130
|
-
(((@@debug_method == method) || (@@debug_method == "all")) ||
|
131
|
-
((@@debug_group == group) || (@@debug_group == "all")))
|
132
|
-
indent_spaces = " " * indent
|
133
|
-
puts "#{indent_spaces}#{method} - #{data}"
|
134
|
-
end
|
135
|
-
end
|
136
96
|
end
|
@@ -15,7 +15,7 @@
|
|
15
15
|
require 'yaml'
|
16
16
|
|
17
17
|
# Class: PlatformInfo
|
18
|
-
# This class reads device specific details from
|
18
|
+
# This class reads device specific details from platform_info.yaml
|
19
19
|
# These details can be used to customize unit tests for a device
|
20
20
|
class PlatformInfo
|
21
21
|
# Default constructor for the PlatformInfo class. This class
|
@@ -28,17 +28,21 @@ class PlatformInfo
|
|
28
28
|
# UTs are to be run
|
29
29
|
#
|
30
30
|
def initialize(device_name)
|
31
|
-
|
31
|
+
if device_name.nil? || device_name.empty?
|
32
|
+
fail 'device name must be specified in PlatformInfo constructor.'
|
33
|
+
end
|
32
34
|
@platform_info_hash = {}
|
33
35
|
|
34
36
|
begin
|
35
|
-
project_info_hash = YAML.load_file(File.join(File.dirname(__FILE__),
|
36
|
-
|
37
|
-
|
37
|
+
project_info_hash = YAML.load_file(File.join(File.dirname(__FILE__),
|
38
|
+
'platform_info.yaml'))
|
39
|
+
rescue RuntimeError
|
40
|
+
raise 'Error - could not open platform file - platform_info.yaml'
|
38
41
|
end
|
39
42
|
|
40
43
|
@platform_info_hash = project_info_hash[device_name]
|
41
|
-
|
44
|
+
fail "Error - could not find #{device_name} device specific information " \
|
45
|
+
'in platform_info.yaml' if @platform_info_hash.nil?
|
42
46
|
end
|
43
47
|
|
44
48
|
# The following instance method will return the value associated with
|
@@ -48,10 +52,10 @@ class PlatformInfo
|
|
48
52
|
# in @platform_info_hash
|
49
53
|
#
|
50
54
|
def get_value_from_key(key)
|
51
|
-
|
55
|
+
fail 'key must be specified in the method get_value_from_key' if key.nil?
|
52
56
|
|
53
57
|
value = @platform_info_hash[key]
|
54
|
-
|
58
|
+
fail "no value exists for the key #{key}" if value.nil?
|
55
59
|
|
56
60
|
value
|
57
61
|
end
|