net-tnsping 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +14 -0
- data/README +12 -22
- data/Rakefile +31 -24
- data/lib/net/tnsping.rb +236 -228
- data/net-tnsping.gemspec +21 -24
- data/test/test_net_tnsping.rb +199 -144
- metadata +45 -21
data/CHANGES
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
== 1.3.2 - 1-Mar-2011
|
2
|
+
* Case is now ignored for the database name when searching through the
|
3
|
+
tnsnames.ora file.
|
4
|
+
* Removed explicit timeout accessor. It's already inherited.
|
5
|
+
* Fixed the driver accessor. It was not being set in the constructor.
|
6
|
+
* Removed a useless call to tns_admin in the constructor.
|
7
|
+
* Flip-flopped the db and database accessor and alias.
|
8
|
+
* Refactored tests to use declarative syntax, added some tests, and
|
9
|
+
did some general refactoring. Also, the default database name is
|
10
|
+
set to "XE" (Express Edition). Change as needed.
|
11
|
+
* Updated the Rakefile, removing the non-gem installation task, and
|
12
|
+
adding a clean task.
|
13
|
+
* Updated the gemspec. The gem build is now handled by a rake task.
|
14
|
+
|
1
15
|
== 1.3.1 - 8-Aug-2009
|
2
16
|
* Switched test-unit from a runtime dependency to a development dependency.
|
3
17
|
* Minor documentation updates.
|
data/README
CHANGED
@@ -1,27 +1,19 @@
|
|
1
1
|
== Description
|
2
|
-
|
2
|
+
The net-tnsping library emulates the Oracle tnsping utility. It pings
|
3
|
+
both the listener and the datasource.
|
3
4
|
|
4
5
|
== Prerequisites
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
Any of the Oracle database drivers (oracle, oci8, ruby9i, etc)
|
6
|
+
* dbi
|
7
|
+
* net-ping
|
8
|
+
* Any of the Oracle database drivers (oracle, oci8, ruby9i, etc)
|
9
9
|
|
10
10
|
== Installation
|
11
|
+
gem install net-tnsping
|
11
12
|
|
12
|
-
=== Manual Installation
|
13
|
-
rake test (optional)
|
14
|
-
rake install
|
15
|
-
|
16
|
-
=== Gem Installation
|
17
|
-
rake test (optional)
|
18
|
-
ruby net-tnsping.gemspec
|
19
|
-
gem install net-tnsping-<version>.gem
|
20
|
-
|
21
13
|
=== Test Note
|
22
14
|
You may want to manually tweak one instance variable (@@database) in the
|
23
15
|
test suite in order to get a more robust set of test results. Set it to
|
24
|
-
a known database name.
|
16
|
+
a known database name. By default it uses "XE" (Express Edition).
|
25
17
|
|
26
18
|
== Synopsis
|
27
19
|
require "net/tnsping"
|
@@ -30,14 +22,14 @@
|
|
30
22
|
t = Ping::TNS.new("my_db")
|
31
23
|
|
32
24
|
if t.ping?
|
33
|
-
|
25
|
+
puts "Database appears to be up and running"
|
34
26
|
else
|
35
|
-
|
27
|
+
puts "There was a problem: " + t.exception
|
36
28
|
end
|
37
29
|
|
38
30
|
== Constants
|
39
31
|
VERSION
|
40
|
-
The version number of this
|
32
|
+
The version number of this library, returned as a String.
|
41
33
|
|
42
34
|
== Class Methods
|
43
35
|
Ping::TNS.new(db, driver="OCI8", host=nil, port=1521, timeout=5)
|
@@ -165,7 +157,7 @@ Ping::TNS#tns_file=(path)
|
|
165
157
|
more reliable solution.
|
166
158
|
|
167
159
|
== Known Bugs
|
168
|
-
None that I'm aware of.
|
160
|
+
None that I'm aware of. Please log any bug reports on the project page
|
169
161
|
at http://www.rubyforge.org/projects/shards
|
170
162
|
|
171
163
|
== Acknowledgements
|
@@ -173,7 +165,7 @@ Ping::TNS#tns_file=(path)
|
|
173
165
|
with some questions I had.
|
174
166
|
|
175
167
|
== Copyright
|
176
|
-
(C) 2003-
|
168
|
+
(C) 2003-2011 Daniel J. Berger
|
177
169
|
All rights reserved.
|
178
170
|
|
179
171
|
== Warranty
|
@@ -186,5 +178,3 @@ Ping::TNS#tns_file=(path)
|
|
186
178
|
|
187
179
|
== Author
|
188
180
|
Daniel J. Berger
|
189
|
-
djberg96 at nospam at gmail dot com
|
190
|
-
imperator on IRC (irc.freenode.net)
|
data/Rakefile
CHANGED
@@ -1,24 +1,31 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
CLEAN.include("**/*.gem", "**/*.rbc", "**/*.log")
|
6
|
+
|
7
|
+
namespace :gem do
|
8
|
+
desc "Create the net-tnsping gem"
|
9
|
+
task :create => [:clean] do
|
10
|
+
spec = eval(IO.read('net-tnsping.gemspec'))
|
11
|
+
Gem::Builder.new(spec).build
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Install the net-tnsping gem"
|
15
|
+
task :install => [:create] do
|
16
|
+
file = Dir['*.gem'].first
|
17
|
+
sh "gem install #{file}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Run the example program"
|
22
|
+
task :example do |dsn|
|
23
|
+
ruby "-Ilib examples/example_tnsping.rb #{dsn}"
|
24
|
+
end
|
25
|
+
|
26
|
+
Rake::TestTask.new do |t|
|
27
|
+
t.warning = true
|
28
|
+
t.verbose = true
|
29
|
+
end
|
30
|
+
|
31
|
+
task :default => :test
|
data/lib/net/tnsping.rb
CHANGED
@@ -4,243 +4,251 @@ require 'net/ping'
|
|
4
4
|
# The Net module serves as a namespace only.
|
5
5
|
module Net
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
# The name of the oracle driver to use for connections. Defaults to OCI8.
|
35
|
-
attr_accessor :driver
|
36
|
-
|
37
|
-
# The timeout value for connection attempts. The default is 5 seconds.
|
38
|
-
attr_accessor :timeout
|
39
|
-
|
40
|
-
# A list of hosts for the given database name.
|
41
|
-
attr_reader :hosts
|
42
|
-
|
43
|
-
# A list of ports for the given database name
|
44
|
-
attr_reader :ports
|
45
|
-
|
46
|
-
# The port used when attempting a connection. The default is 1521.
|
47
|
-
attr_reader :port
|
48
|
-
|
49
|
-
# Creates and returns a new Ping::TNS object. If the db specified cannot
|
50
|
-
# be found in the tnsnames.ora file, then a Ping::TNS::Error is raised.
|
51
|
-
#
|
52
|
-
def initialize(db, driver='OCI8', host=nil, port=1521, timeout=5)
|
53
|
-
@db = db
|
54
|
-
@dsn = "dbi:#{driver}:" << db
|
55
|
-
@host = host
|
56
|
-
@timeout = timeout
|
57
|
-
@port = port
|
58
|
-
@tns_admin = tns_admin
|
59
|
-
@ports = [] # There can be more than one host/port
|
60
|
-
@hosts = [] # for each dsn. Try them in order.
|
61
|
-
@sid = nil
|
62
|
-
|
63
|
-
@tns_admin = ENV['TNS_ADMIN']
|
64
|
-
@ora_home = ENV['ORACLE_HOME'] || ENV['ORA_HOME']
|
65
|
-
|
66
|
-
if @tns_admin
|
67
|
-
@tns_file = File.join(@tns_admin, 'tnsnames.ora')
|
68
|
-
elsif @ora_home
|
69
|
-
@tns_file = File.join(@ora_home, 'network', 'admin', 'tnsnames.ora')
|
70
|
-
else
|
71
|
-
@tns_file = File.join((ENV['HOME'] || ENV['USERPROFILE']), 'tnsnames.ora')
|
72
|
-
end
|
73
|
-
|
74
|
-
yield self if block_given?
|
75
|
-
|
76
|
-
# If the host is not specified, look for it in the tnsnames.ora file
|
77
|
-
if host.nil?
|
78
|
-
err_msg = "tnsnames.ora file could not be found"
|
79
|
-
raise Error, err_msg unless File.exists?(@tns_file)
|
80
|
-
parse_tns_file
|
81
|
-
else
|
82
|
-
@hosts.push(host)
|
83
|
-
@ports.push(port)
|
84
|
-
end
|
85
|
-
end
|
7
|
+
# The Ping::TNS class encapsulates the information and behavior of tns ping.
|
8
|
+
class Ping::TNS < Ping::TCP
|
9
|
+
|
10
|
+
# The error class typically raised if any of the Ping::TNS methods fail.
|
11
|
+
class Error < StandardError; end
|
12
|
+
|
13
|
+
# The version of the net-tnsping library.
|
14
|
+
VERSION = '1.3.2'
|
15
|
+
|
16
|
+
# Database name.
|
17
|
+
attr_accessor :database
|
18
|
+
|
19
|
+
# Database source name.
|
20
|
+
attr_accessor :dsn
|
21
|
+
|
22
|
+
# The full path to the tnsnames.ora file.
|
23
|
+
attr_accessor :tns_file
|
24
|
+
|
25
|
+
# The name of the host the database sits on.
|
26
|
+
attr_accessor :host
|
27
|
+
|
28
|
+
# The toplevel tns admin path.
|
29
|
+
attr_accessor :tns_admin
|
30
|
+
|
31
|
+
# The value of your ORACLE_HOME or ORA_HOME environment variable.
|
32
|
+
attr_accessor :ora_home
|
86
33
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
34
|
+
# The name of the oracle driver to use for connections. Defaults to OCI8.
|
35
|
+
attr_accessor :driver
|
36
|
+
|
37
|
+
# A list of hosts for the given database name.
|
38
|
+
attr_reader :hosts
|
39
|
+
|
40
|
+
# A list of ports for the given database name
|
41
|
+
attr_reader :ports
|
42
|
+
|
43
|
+
# The port used when attempting a connection. The default is 1521.
|
44
|
+
attr_reader :port
|
45
|
+
|
46
|
+
# Creates and returns a new Ping::TNS object. If the db specified cannot
|
47
|
+
# be found in the tnsnames.ora file, then a Ping::TNS::Error is raised.
|
48
|
+
#
|
49
|
+
def initialize(database, driver='OCI8', host=nil, port=1521, timeout=5)
|
50
|
+
@database = database
|
51
|
+
@dsn = "dbi:#{driver}:" << database
|
52
|
+
@host = host
|
53
|
+
@timeout = timeout
|
54
|
+
@port = port
|
55
|
+
@driver = driver
|
56
|
+
@ports = [] # There can be more than one host/port
|
57
|
+
@hosts = [] # for each dsn. Try them in order.
|
58
|
+
@sid = nil
|
59
|
+
|
60
|
+
@tns_admin = ENV['TNS_ADMIN']
|
61
|
+
@ora_home = ENV['ORACLE_HOME'] || ENV['ORA_HOME']
|
62
|
+
|
63
|
+
if @tns_admin
|
64
|
+
@tns_file = File.join(@tns_admin, 'tnsnames.ora')
|
65
|
+
elsif @ora_home
|
66
|
+
@tns_file = File.join(@ora_home, 'network', 'admin', 'tnsnames.ora')
|
67
|
+
else
|
68
|
+
home = ENV['HOME'] || ENV['USERPROFILE']
|
69
|
+
@tns_file = File.join(home, 'tnsnames.ora')
|
94
70
|
end
|
95
71
|
|
96
|
-
|
97
|
-
|
98
|
-
#
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
72
|
+
yield self if block_given?
|
73
|
+
|
74
|
+
# If the host is not specified, look for it in the tnsnames.ora file
|
75
|
+
if host.nil?
|
76
|
+
err_msg = "tnsnames.ora file could not be found"
|
77
|
+
raise Error, err_msg unless File.exists?(@tns_file)
|
78
|
+
parse_tns_file
|
79
|
+
else
|
80
|
+
@hosts.push(host)
|
81
|
+
@ports.push(port)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Sets the port that the Ping::TNS#ping_listener? method will use. If
|
86
|
+
# this is set, then a ping will only be attempted on this port
|
87
|
+
# regardless of what is in the tnsnames.ora file.
|
88
|
+
#
|
89
|
+
def port=(num)
|
90
|
+
@port = num
|
91
|
+
@ports = [num]
|
92
|
+
end
|
93
|
+
|
94
|
+
# Performs a TCP ping on the listener. The host and port are determined from
|
95
|
+
# your tnsnames.ora file. If more than one host and/or port are found in the
|
96
|
+
# tnsnames.ora file, then each will be tried. So long as at least one of
|
97
|
+
# them connects successfully, true is returned.
|
98
|
+
#
|
99
|
+
# If you specify a host and port in the constructor, then the attempt will
|
100
|
+
# only be made against that host on the given port.
|
101
|
+
#
|
102
|
+
# Remember, this only pings the listener. If you want to ping the listener
|
103
|
+
# and the database, use the ping_all? method.
|
104
|
+
#--
|
105
|
+
# Try each host/port listed for a given entry. Return a true result if
|
106
|
+
# any one of them succeeds and break out of the loop.
|
107
|
+
#
|
108
|
+
def ping?
|
109
|
+
if @hosts.empty?
|
110
|
+
raise Error, "No hosts found"
|
130
111
|
end
|
131
112
|
|
132
|
-
#
|
133
|
-
|
134
|
-
|
135
|
-
#
|
136
|
-
# Note that each of the arguments for this method use the defaults
|
137
|
-
# passed to the constructor (or have a default otherwise set). You
|
138
|
-
# generally should not pass any arguments to this method.
|
139
|
-
# In the event that this method fails, false is returned and the error
|
140
|
-
# can be viewed via Ping::TNS#exception.
|
141
|
-
#--
|
142
|
-
# I have intentionally set the user and password to something random in
|
143
|
-
# order to avoid the possibility of accidentally guessing them. In
|
144
|
-
# case of cosmic coincidence, set them yourself.
|
145
|
-
#
|
146
|
-
def ping_database?(dsn=@dsn, timeout=@timeout, user=@sid, passwd=Time.now.to_s)
|
147
|
-
re = /ORA-01017/
|
148
|
-
dbh = nil
|
149
|
-
user ||= Time.now.to_s
|
150
|
-
rv = false
|
151
|
-
begin
|
152
|
-
Timeout.timeout(timeout){
|
153
|
-
dbh = DBI.connect(dsn,user,passwd)
|
154
|
-
}
|
155
|
-
rescue DBI::DatabaseError => e
|
156
|
-
if re.match(e.to_s)
|
157
|
-
rv = true
|
158
|
-
else
|
159
|
-
@exception = e
|
160
|
-
end
|
161
|
-
rescue Timeout::Error, StandardError => e
|
162
|
-
@exception = e
|
163
|
-
ensure
|
164
|
-
if dbh
|
165
|
-
dbh.disconnect if dbh.connected?
|
166
|
-
end
|
167
|
-
end
|
168
|
-
rv
|
113
|
+
# Use 1521 if no ports were found in the tnsnames.ora file.
|
114
|
+
if @ports.empty?
|
115
|
+
@ports.push(@port)
|
169
116
|
end
|
170
117
|
|
171
|
-
#
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
118
|
+
# If the host is provided, only ping that host
|
119
|
+
if @host
|
120
|
+
0.upto(@ports.length-1){ |n|
|
121
|
+
@port = @ports[n]
|
122
|
+
return super
|
123
|
+
}
|
124
|
+
else
|
125
|
+
0.upto(@ports.length-1){ |n|
|
126
|
+
@port = @ports[n]
|
127
|
+
@host = @hosts[n]
|
128
|
+
return super
|
129
|
+
}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# Attempts to make a connection using a bogus login and password via the
|
134
|
+
# DBI class. If an ORA-01017 Oracle error is returned, that means the
|
135
|
+
# database is up and running and true is returned.
|
136
|
+
#
|
137
|
+
# Note that each of the arguments for this method use the defaults
|
138
|
+
# passed to the constructor (or have a default otherwise set). You
|
139
|
+
# generally should not pass any arguments to this method.
|
140
|
+
# In the event that this method fails, false is returned and the error
|
141
|
+
# can be viewed via Ping::TNS#exception.
|
142
|
+
#--
|
143
|
+
# I have intentionally set the user and password to something random in
|
144
|
+
# order to avoid the possibility of accidentally guessing them. In
|
145
|
+
# case of cosmic coincidence, set them yourself.
|
146
|
+
#
|
147
|
+
def ping_database?(dsn=@dsn, timeout=@timeout, user=@sid, passwd=Time.now.to_s)
|
148
|
+
re = /ORA-01017/
|
149
|
+
dbh = nil
|
150
|
+
user ||= Time.now.to_s
|
151
|
+
rv = false
|
152
|
+
|
153
|
+
begin
|
154
|
+
Timeout.timeout(timeout){
|
155
|
+
dbh = DBI.connect(dsn,user,passwd)
|
156
|
+
}
|
157
|
+
rescue DBI::DatabaseError => e
|
158
|
+
if re.match(e.to_s)
|
159
|
+
rv = true
|
160
|
+
else
|
161
|
+
@exception = e
|
162
|
+
end
|
163
|
+
rescue Timeout::Error, StandardError => e
|
164
|
+
@exception = e
|
165
|
+
ensure
|
166
|
+
if dbh
|
167
|
+
dbh.disconnect if dbh.connected?
|
168
|
+
end
|
177
169
|
end
|
178
170
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
@ports.push(value.to_i)
|
234
|
-
when 'sid'
|
235
|
-
@sid = value
|
236
|
-
end
|
237
|
-
}
|
171
|
+
rv
|
172
|
+
end
|
173
|
+
|
174
|
+
# Simple wrapper for ping_listener? + ping_database?
|
175
|
+
#
|
176
|
+
def ping_all?
|
177
|
+
return false unless self.ping_listener?
|
178
|
+
return false unless self.ping_database?
|
179
|
+
true
|
180
|
+
end
|
181
|
+
|
182
|
+
private
|
183
|
+
|
184
|
+
# parse_tns_file
|
185
|
+
#
|
186
|
+
# Search for the dsn entry within the tnsnames.ora file and get the host
|
187
|
+
# and port information. Private method.
|
188
|
+
#
|
189
|
+
def parse_tns_file(file=@tns_file, db=@database)
|
190
|
+
re_blank = /^$/
|
191
|
+
re_comment = /^#/
|
192
|
+
re_tns_sentry = /^#{db}.*?=/i # specific entry
|
193
|
+
re_tns_gentry = /^\w.*?=/ # generic entry
|
194
|
+
re_tns_pair = /\w+\s*\=\s*[\w\.]+/ # used to parse key=val
|
195
|
+
re_keys = /\bhost\b|\bport\b|\bsid\b/i
|
196
|
+
|
197
|
+
data_string = ""
|
198
|
+
found = false
|
199
|
+
|
200
|
+
IO.foreach(file){ |line|
|
201
|
+
next if re_blank.match(line)
|
202
|
+
next if re_comment.match(line)
|
203
|
+
line.chomp!
|
204
|
+
|
205
|
+
# Skip over lines until an entry for the db is found.
|
206
|
+
match = re_tns_sentry.match(line)
|
207
|
+
|
208
|
+
if match
|
209
|
+
found = true
|
210
|
+
data_string << match.post_match # slurp the rest of the line
|
211
|
+
next
|
212
|
+
end
|
213
|
+
|
214
|
+
# Once found, slurp the lines into a variable until the next
|
215
|
+
# db entry is encountered.
|
216
|
+
if found
|
217
|
+
break if re_tns_gentry.match(line)
|
218
|
+
line.strip!
|
219
|
+
data_string << line
|
220
|
+
end
|
221
|
+
}
|
222
|
+
|
223
|
+
unless found
|
224
|
+
raise Error, "unable to find '#{db}' in #{file}"
|
238
225
|
end
|
239
226
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
227
|
+
# Break each 'key = value' line into its parts
|
228
|
+
data_string.scan(re_tns_pair).each{ |pair|
|
229
|
+
key, value = pair.split("=")
|
230
|
+
key.strip!
|
231
|
+
value.strip!
|
232
|
+
|
233
|
+
next unless re_keys.match(key)
|
234
|
+
|
235
|
+
case key.downcase
|
236
|
+
when 'host'
|
237
|
+
@hosts.push(value)
|
238
|
+
when 'port'
|
239
|
+
@ports.push(value.to_i)
|
240
|
+
when 'sid'
|
241
|
+
@sid = value
|
242
|
+
end
|
243
|
+
}
|
244
|
+
end
|
245
|
+
|
246
|
+
# Aliases
|
247
|
+
|
248
|
+
alias db database
|
249
|
+
alias database_source_name dsn
|
250
|
+
alias ping_listener? ping?
|
251
|
+
alias oracle_home ora_home
|
252
|
+
alias oracle_home= ora_home=
|
253
|
+
end
|
246
254
|
end
|
data/net-tnsping.gemspec
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'net-tnsping'
|
5
|
+
spec.version = '1.3.2'
|
6
|
+
spec.license = 'Artistic 2.0'
|
7
|
+
spec.author = 'Daniel J. Berger'
|
8
|
+
spec.email = 'djberg96@gmail.com'
|
9
|
+
spec.homepage = 'http://www.rubyforge.org/projects/shards'
|
10
|
+
spec.summary = 'A library for pinging Oracle listeners and databases'
|
11
|
+
spec.test_file = 'test/test_net_tnsping.rb'
|
12
|
+
spec.has_rdoc = true
|
13
|
+
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
spec.rubyforge_project = 'shards'
|
16
|
+
spec.extra_rdoc_files = ['CHANGES', 'MANIFEST', 'README']
|
18
17
|
|
19
|
-
|
20
|
-
|
18
|
+
spec.add_dependency('net-ping', '>= 1.4.0')
|
19
|
+
spec.add_development_dependency('test-unit', '>= 2.1.2')
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
spec.description = <<-EOF
|
22
|
+
The net-tnsping library provides a way to ping Oracle databases and
|
23
|
+
ensure that they're up and running. Unlike the tnsping command line
|
24
|
+
program, which only pings the listener, the net-tnsping library
|
25
|
+
pings both the listener and the database itself.
|
26
|
+
EOF
|
28
27
|
end
|
29
|
-
|
30
|
-
Gem::Builder.new(spec).build
|
data/test/test_net_tnsping.rb
CHANGED
@@ -9,150 +9,205 @@ gem 'test-unit'
|
|
9
9
|
|
10
10
|
require 'test/unit'
|
11
11
|
require 'net/tnsping'
|
12
|
-
include Net
|
13
12
|
|
14
13
|
class TC_TNS_Ping < Test::Unit::TestCase
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
14
|
+
def self.startup
|
15
|
+
@@database = 'xe'
|
16
|
+
@@username = 'hr'
|
17
|
+
@@password = 'hr'
|
18
|
+
@@hostname = Socket.gethostname
|
19
|
+
end
|
20
|
+
|
21
|
+
def setup
|
22
|
+
@tnsp = Net::Ping::TNS.new(@@database)
|
23
|
+
end
|
24
|
+
|
25
|
+
test "version number is expected value" do
|
26
|
+
assert_equal('1.3.2', Net::Ping::TNS::VERSION)
|
27
|
+
end
|
28
|
+
|
29
|
+
test "database reader basic functionality" do
|
30
|
+
assert_respond_to(@tnsp, :database)
|
31
|
+
assert_nothing_raised{ @tnsp.database }
|
32
|
+
assert_equal(@@database, @tnsp.database)
|
33
|
+
end
|
34
|
+
|
35
|
+
test "db is an alias for database" do
|
36
|
+
assert_respond_to(@tnsp, :db)
|
37
|
+
assert_alias_method(@tnsp, :db, :database)
|
38
|
+
end
|
39
|
+
|
40
|
+
test "database writer basic functionality" do
|
41
|
+
assert_respond_to(@tnsp, :database=)
|
42
|
+
assert_nothing_raised{ @tnsp.database = 'fubar' }
|
43
|
+
assert_equal('fubar', @tnsp.database)
|
44
|
+
end
|
45
|
+
|
46
|
+
test "dsn reader basic functionality" do
|
47
|
+
assert_respond_to(@tnsp, :dsn)
|
48
|
+
assert_nothing_raised{ @tnsp.dsn }
|
49
|
+
assert_equal("dbi:OCI8:#{@@database}", @tnsp.dsn)
|
50
|
+
end
|
51
|
+
|
52
|
+
test "database_source_name is an alias for dsn" do
|
53
|
+
assert_respond_to(@tnsp, :database_source_name)
|
54
|
+
assert_alias_method(@tnsp, :database_source_name, :dsn)
|
55
|
+
end
|
56
|
+
|
57
|
+
test "dsn writer basic functionality" do
|
58
|
+
assert_respond_to(@tnsp, :dsn=)
|
59
|
+
assert_nothing_raised{ @tnsp.dsn = 'dbi:OCI8:fubar' }
|
60
|
+
assert_equal('dbi:OCI8:fubar', @tnsp.dsn)
|
61
|
+
end
|
62
|
+
|
63
|
+
test "port reader basic functionality" do
|
64
|
+
assert_respond_to(@tnsp, :port)
|
65
|
+
assert_equal(1521, @tnsp.port)
|
66
|
+
end
|
67
|
+
|
68
|
+
test "port writer basic functionality" do
|
69
|
+
assert_respond_to(@tnsp, :port=)
|
70
|
+
assert_nothing_raised{ @tnsp.port = 1555 }
|
71
|
+
assert_equal(1555, @tnsp.port)
|
72
|
+
end
|
73
|
+
|
74
|
+
test "ports reader basic functionality" do
|
75
|
+
assert_respond_to(@tnsp, :ports)
|
76
|
+
assert_kind_of(Array, @tnsp.ports)
|
77
|
+
assert(@tnsp.ports.length > 0)
|
78
|
+
end
|
79
|
+
|
80
|
+
test "host reader basic functionality" do
|
81
|
+
assert_respond_to(@tnsp, :host)
|
82
|
+
assert_nil(@tnsp.host)
|
83
|
+
end
|
84
|
+
|
85
|
+
test "host writer basic functionality" do
|
86
|
+
assert_respond_to(@tnsp, :host=)
|
87
|
+
assert_nothing_raised{ @tnsp.host = 'fubar' }
|
88
|
+
assert_equal('fubar', @tnsp.host)
|
89
|
+
end
|
90
|
+
|
91
|
+
test "hosts reader basic functionality" do
|
92
|
+
assert_respond_to(@tnsp, :hosts)
|
93
|
+
assert_kind_of(Array, @tnsp.hosts)
|
94
|
+
assert(@tnsp.hosts.length > 0)
|
95
|
+
end
|
96
|
+
|
97
|
+
test "there is no hosts writer method" do
|
98
|
+
assert_raise(NoMethodError){ @tnsp.hosts = %w[foo bar] }
|
99
|
+
end
|
100
|
+
|
101
|
+
test "tns_file reader basic functionality" do
|
102
|
+
assert_respond_to(@tnsp, :tns_file)
|
103
|
+
assert_kind_of(String, @tnsp.tns_file)
|
104
|
+
assert_true(File.exist?(@tnsp.tns_file))
|
105
|
+
end
|
106
|
+
|
107
|
+
test "tns_file writer basic functionality" do
|
108
|
+
assert_respond_to(@tnsp, :tns_file=)
|
109
|
+
assert_nothing_raised{ @tnsp.tns_file = 'fu_tnsnames.ora' }
|
110
|
+
assert_equal('fu_tnsnames.ora', @tnsp.tns_file)
|
111
|
+
end
|
112
|
+
|
113
|
+
test "oracle_home reader basic functionality" do
|
114
|
+
assert_respond_to(@tnsp, :oracle_home)
|
115
|
+
assert_kind_of([String, NilClass], @tnsp.oracle_home)
|
116
|
+
end
|
117
|
+
|
118
|
+
test "ora_home is an alias for oracle_home" do
|
119
|
+
assert_respond_to(@tnsp, :ora_home)
|
120
|
+
assert_alias_method(@tnsp, :ora_home, :oracle_home)
|
121
|
+
end
|
122
|
+
|
123
|
+
test "oracle_home writer basic functionality" do
|
124
|
+
assert_respond_to(@tnsp, :oracle_home=)
|
125
|
+
assert_nothing_raised{ @tnsp.oracle_home = ENV['HOME'] }
|
126
|
+
assert_equal(ENV['HOME'], @tnsp.oracle_home)
|
127
|
+
end
|
128
|
+
|
129
|
+
test "ora_home= is an alias for oracle_home=" do
|
130
|
+
assert_respond_to(@tnsp, :ora_home=)
|
131
|
+
assert_alias_method(@tnsp, :ora_home=, :oracle_home=)
|
132
|
+
end
|
133
|
+
|
134
|
+
test "tns_admin reader basic functionality" do
|
135
|
+
assert_respond_to(@tnsp, :tns_admin)
|
136
|
+
assert_kind_of([String, NilClass], @tnsp.tns_admin)
|
137
|
+
end
|
138
|
+
|
139
|
+
test "tns_admin writer basic functionality" do
|
140
|
+
assert_respond_to(@tnsp, :tns_admin=)
|
141
|
+
assert_nothing_raised{ @tnsp.tns_admin = ENV['HOME'] }
|
142
|
+
assert_equal(ENV['HOME'], @tnsp.tns_admin)
|
143
|
+
end
|
144
|
+
|
145
|
+
test "timeout reader basic functionality" do
|
146
|
+
assert_respond_to(@tnsp, :timeout)
|
147
|
+
assert_kind_of(Fixnum, @tnsp.timeout)
|
148
|
+
end
|
149
|
+
|
150
|
+
test "timeout writer basic functionality" do
|
151
|
+
assert_respond_to(@tnsp, :timeout=)
|
152
|
+
assert_nothing_raised{ @tnsp.timeout = 10 }
|
153
|
+
assert_equal(10, @tnsp.timeout)
|
154
|
+
end
|
155
|
+
|
156
|
+
test "driver reader basic functionality" do
|
157
|
+
assert_respond_to(@tnsp, :driver)
|
158
|
+
assert_kind_of(String, @tnsp.driver)
|
159
|
+
end
|
160
|
+
|
161
|
+
test "driver writer basic functionality" do
|
162
|
+
assert_respond_to(@tnsp, :driver=)
|
163
|
+
assert_nothing_raised{ @tnsp.driver = "oracle" }
|
164
|
+
assert_equal("oracle", @tnsp.driver)
|
165
|
+
end
|
166
|
+
|
167
|
+
test "ping_listener? basic functionality" do
|
168
|
+
assert_respond_to(@tnsp, :ping_listener?)
|
169
|
+
assert_nothing_raised{ @tnsp.ping_listener? }
|
170
|
+
end
|
171
|
+
|
172
|
+
test "ping_listener? returns a boolean value" do
|
173
|
+
assert_boolean(@tnsp.ping_listener?)
|
174
|
+
end
|
175
|
+
|
176
|
+
test "ping? is an alias for ping_listener?" do
|
177
|
+
end
|
178
|
+
|
179
|
+
test "ping_database? basic functionality" do
|
180
|
+
assert_respond_to(@tnsp, :ping_database?)
|
181
|
+
assert_nothing_raised{ @tnsp.ping_database? }
|
182
|
+
end
|
183
|
+
|
184
|
+
test "ping_database? returns a boolean value" do
|
185
|
+
assert_boolean(@tnsp.ping_database?)
|
186
|
+
end
|
187
|
+
|
188
|
+
test "ping_all? basic functionality" do
|
189
|
+
assert_respond_to(@tnsp, :ping_all?)
|
190
|
+
assert_nothing_raised{ @tnsp.ping_all? }
|
191
|
+
end
|
192
|
+
|
193
|
+
test "ping_all? returns a boolean value" do
|
194
|
+
assert_boolean(@tnsp.ping_all?)
|
195
|
+
end
|
196
|
+
|
197
|
+
test "ping fails against a bogus database" do
|
198
|
+
assert_raises(Net::Ping::TNS::Error){ Net::Ping::TNS.new('bogus_db') }
|
199
|
+
@tnsp.port = 9999
|
200
|
+
assert_false(@tnsp.ping_listener?)
|
201
|
+
end
|
202
|
+
|
203
|
+
def teardown
|
204
|
+
@tnsp = nil
|
205
|
+
end
|
206
|
+
|
207
|
+
def self.shutdown
|
208
|
+
@@username = nil
|
209
|
+
@@password = nil
|
210
|
+
@@database = nil
|
211
|
+
@@hostname = nil
|
212
|
+
end
|
158
213
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-tnsping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 3
|
9
|
+
- 2
|
10
|
+
version: 1.3.2
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Daniel J. Berger
|
@@ -9,30 +15,42 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2011-03-01 00:00:00 -07:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: net-ping
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 4
|
33
|
+
- 0
|
34
|
+
version: 1.4.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
25
37
|
- !ruby/object:Gem::Dependency
|
26
38
|
name: test-unit
|
27
|
-
|
28
|
-
|
29
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
30
42
|
requirements:
|
31
43
|
- - ">="
|
32
44
|
- !ruby/object:Gem::Version
|
33
|
-
|
34
|
-
|
35
|
-
|
45
|
+
hash: 15
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 1
|
49
|
+
- 2
|
50
|
+
version: 2.1.2
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
description: " The net-tnsping library provides a way to ping Oracle databases and\n ensure that they're up and running. Unlike the tnsping command line\n program, which only pings the listener, the net-tnsping library\n pings both the listener and the database itself.\n"
|
36
54
|
email: djberg96@gmail.com
|
37
55
|
executables: []
|
38
56
|
|
@@ -43,14 +61,14 @@ extra_rdoc_files:
|
|
43
61
|
- MANIFEST
|
44
62
|
- README
|
45
63
|
files:
|
46
|
-
- CHANGES
|
47
|
-
- examples/example_tnsping.rb
|
48
|
-
- lib/net/tnsping.rb
|
49
|
-
- MANIFEST
|
50
|
-
- net-tnsping.gemspec
|
51
64
|
- Rakefile
|
52
65
|
- README
|
66
|
+
- net-tnsping.gemspec
|
67
|
+
- lib/net/tnsping.rb
|
68
|
+
- CHANGES
|
69
|
+
- examples/example_tnsping.rb
|
53
70
|
- test/test_net_tnsping.rb
|
71
|
+
- MANIFEST
|
54
72
|
has_rdoc: true
|
55
73
|
homepage: http://www.rubyforge.org/projects/shards
|
56
74
|
licenses:
|
@@ -61,21 +79,27 @@ rdoc_options: []
|
|
61
79
|
require_paths:
|
62
80
|
- lib
|
63
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
64
83
|
requirements:
|
65
84
|
- - ">="
|
66
85
|
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
67
89
|
version: "0"
|
68
|
-
version:
|
69
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
70
92
|
requirements:
|
71
93
|
- - ">="
|
72
94
|
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
96
|
+
segments:
|
97
|
+
- 0
|
73
98
|
version: "0"
|
74
|
-
version:
|
75
99
|
requirements: []
|
76
100
|
|
77
101
|
rubyforge_project: shards
|
78
|
-
rubygems_version: 1.3.
|
102
|
+
rubygems_version: 1.3.7
|
79
103
|
signing_key:
|
80
104
|
specification_version: 3
|
81
105
|
summary: A library for pinging Oracle listeners and databases
|