rortel 0.1.1

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.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2010-07-19
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,36 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ bin/rortel
7
+ features/login_msc.feature
8
+ features/login_rnd_unix.feature
9
+ features/patching_msc.feature
10
+ features/post_info_and_get_patch_list.feature
11
+ features/step_definitions/rortel.rb
12
+ features/support/env.rb
13
+ lib/rortel.rb
14
+ lib/rortel/base.rb
15
+ lib/rortel/cli.rb
16
+ lib/rortel/dms.rb
17
+ lib/rortel/expectical.rb
18
+ lib/rortel/ftp_access.rb
19
+ lib/rortel/msc.rb
20
+ lib/rortel/pacs_host.rb
21
+ lib/rortel/pls_host.rb
22
+ lib/rortel/unix.rb
23
+ rortel.gemspec
24
+ script/console
25
+ script/destroy
26
+ script/generate
27
+ spec/ftp_access_spec.rb
28
+ spec/msc_spec.rb
29
+ spec/pacs_host_spec.rb
30
+ spec/pls_host_spec.rb
31
+ spec/rortel_cli_spec.rb
32
+ spec/rortel_spec.rb
33
+ spec/spec.opts
34
+ spec/spec_helper.rb
35
+ tasks/rcov.rake
36
+ tasks/rspec.rake
data/PostInstall.txt ADDED
@@ -0,0 +1,7 @@
1
+
2
+ For more information on rortel, see http://rortel.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
data/README.rdoc ADDED
@@ -0,0 +1,43 @@
1
+ = rortel
2
+
3
+ == DESCRIPTION:
4
+
5
+ CLI lib for nortel networks devices
6
+
7
+ == FEATURES/PROBLEMS:
8
+
9
+ CLI lib for nortel networks devices
10
+
11
+ == SYNOPSIS:
12
+
13
+
14
+ == REQUIREMENTS:
15
+
16
+
17
+ == INSTALL:
18
+
19
+
20
+ == LICENSE:
21
+
22
+ (The MIT License)
23
+
24
+ Copyright (c) 2010 David Ruan
25
+
26
+ Permission is hereby granted, free of charge, to any person obtaining
27
+ a copy of this software and associated documentation files (the
28
+ 'Software'), to deal in the Software without restriction, including
29
+ without limitation the rights to use, copy, modify, merge, publish,
30
+ distribute, sublicense, and/or sell copies of the Software, and to
31
+ permit persons to whom the Software is furnished to do so, subject to
32
+ the following conditions:
33
+
34
+ The above copyright notice and this permission notice shall be
35
+ included in all copies or substantial portions of the Software.
36
+
37
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
38
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
39
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
40
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
41
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
42
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
43
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/rortel'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'rortel' do
14
+ self.developer 'David Ruan', 'ruanwz@gmail.com'
15
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
18
+
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ # task :default => [:spec, :features]
data/bin/rortel ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2010-7-19.
4
+ # Copyright (c) 2010. All rights reserved.
5
+
6
+ require 'rubygems'
7
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/rortel")
8
+ require "rortel/cli"
9
+
10
+ Rortel::CLI.execute(STDOUT, ARGV)
@@ -0,0 +1,21 @@
1
+ Feature: login msc
2
+ As a operator
3
+ I want to login msc
4
+ So that I can perform other operation
5
+
6
+ Scenario: login and logout ATCA
7
+ Given the login info for user "davidruan2" on "atcag1"
8
+ When I start to login msc
9
+ Then I get the login passed info " Logged in"
10
+ When I logout
11
+ Then I get the logout info " Logged out on"
12
+
13
+ Scenario: login and logout XACore
14
+ Given the login info for user "davidruan2" on "gsmr"
15
+ When I start to login msc
16
+ Then I get the login passed info " Logged in"
17
+ When I logout
18
+ Then I get the logout info " Logged out on"
19
+
20
+
21
+
@@ -0,0 +1,12 @@
1
+ Feature: login rnd unix
2
+ As a operator
3
+ I want to login unix
4
+ So that I can perform other operation
5
+
6
+ Scenario: login and logout unix
7
+ Given the login info for user "davidrua" on unix "rnd94"
8
+ When I start to login unix
9
+ Then I get the login passed info "/home/davidrua>"
10
+ When I logout
11
+ Then I get the logout info "Connection closed by foreign host"
12
+
@@ -0,0 +1,41 @@
1
+ Feature: login msc
2
+ As a operator
3
+ I want to patch on msc
4
+ So that I can upgrade software without reboot the msc
5
+
6
+ Scenario: get patch list on ATCA msc
7
+ Given the login info for user "davidruan2" on "atcag1"
8
+ When I start to login msc
9
+ Then I get the login passed info " Logged in"
10
+ When I run command "prsm;report dest cm"
11
+ When I parse the patch list
12
+ Then I get the patch list
13
+ When I logout
14
+ Then I get the logout info " Logged out on"
15
+
16
+ Scenario: get patch list on XACore msc
17
+ Given the login info for user "davidruan2" on "gsmr"
18
+ When I start to login msc
19
+ Then I get the login passed info " Logged in"
20
+ When I run command "prsm;report dest cm"
21
+ When I parse the patch list
22
+ Then I get the patch list
23
+ When I logout
24
+ Then I get the logout info " Logged out on"
25
+
26
+ Scenario: remove and apply a patch on ATCA msc
27
+ Given the login info for user "davidruan2" on "atcag1"
28
+ When I start to login msc
29
+ Then I get the login passed info " Logged in"
30
+ When I run command "prsm;report dest cm"
31
+ When I parse the patch list
32
+ Then I get the patch list
33
+ Then the patch list include "rud03p9c"
34
+ When "remove" the patch "rud03p9c"
35
+ Then query the status of patch "rud03p9c" is "R" using "prsm;report prsu"
36
+ When "apply" the patch "rud03p9c"
37
+ Then query the status of patch "rud03p9c" is "A" using "prsm;report prsu"
38
+ When I logout
39
+ Then I get the logout info " Logged out on"
40
+
41
+
@@ -0,0 +1,12 @@
1
+ Feature: post info and get patch list
2
+ As a operator
3
+ I want to get the current patch list from web
4
+ So that I can know how many patches are still unapplied on msc
5
+
6
+ Scenario: post release and cpu info and get the patch list from web
7
+ Given the release and cpu info "MSCS0200.PPC4"
8
+ When I post the form to the website "http://gsds.ca.nortel.com/cgi-bin/RPSFORMS/pcl2patch.cgi"
9
+ Then I get the patch list text
10
+ When I parse the patch list text
11
+ Then I get the patch list from web
12
+
@@ -0,0 +1,85 @@
1
+ Given /^the login info for user "([^"]*)" on "([^"]*)"$/ do |username,host_name|
2
+ @host=Rortel::Msc.new :ip=>host_name, :user=>username, :password=>username
3
+ end
4
+
5
+ When /^I start to login msc$/ do
6
+ @host.login
7
+ end
8
+
9
+ Then /the login passed info "([^"]*)"$/ do |login_in_msg|
10
+ @host.output.last.should include login_in_msg
11
+ end
12
+
13
+ When /^I logout$/ do
14
+ @host.logout
15
+ end
16
+
17
+ Then /^I get the logout info "([^"]*)"$/ do |logout_msg|
18
+ @host.output.last.should include logout_msg
19
+ end
20
+
21
+ Given /^the login info for user "([^"]*)" on unix "([^"]*)"$/ do |user, host|
22
+ @host=Rortel::PlsHost.new :ip=>host, :user=>user, :password=>TestData::Password
23
+ end
24
+
25
+ When /^I start to login unix$/ do
26
+ @host.login
27
+ end
28
+
29
+ When /^I run command "([^"]*)"$/ do |command|
30
+ @host.run command
31
+ end
32
+ When /^I parse the patch list$/ do
33
+ @host.parse_patch_list
34
+ end
35
+
36
+
37
+ Then /^I get the patch list$/ do
38
+ @host.patch_list.should_not be_empty
39
+ end
40
+
41
+ Then /^the patch list include "([^"]*)"$/ do |patch_id|
42
+ @host.patch_list.should include patch_id.upcase
43
+ end
44
+
45
+ Then /^query the status of patch "([^"]*)" is "([^"]*)" using "([^"]*)"$/ do |patch_id, status, command|
46
+ @host.run "#{command} #{patch_id}"
47
+ @v=@host.parse_prsu_status
48
+ @v.should == status
49
+ end
50
+
51
+ When /^"([^"]*)" the patch "([^"]*)"$/ do |operation,patch_id|
52
+ @host.change_patch operation, patch_id
53
+ end
54
+
55
+ Given /^the release and cpu info "([^"]*)"$/ do |pcl_load|
56
+ @pcl_load=pcl_load
57
+ end
58
+
59
+ When /^I post the form to the website "([^"]*)"$/ do |address|
60
+
61
+ @web_result = Net::HTTP.post_form(URI.parse(address), {'next_sort'=>'1',
62
+ 'max_section'=>'1',
63
+ 'add_to_section'=>'0',
64
+ 'query_id_1'=>'MSCS0200.PPC4'})
65
+ #next_sort=1&max_section=1&add_to_section=0&query_id_1=MSCS0200.PPC4
66
+ #puts @web_result
67
+ end
68
+
69
+ Then /^I get the patch list text$/ do
70
+ @web_result.code.should == '200'
71
+ end
72
+
73
+ When /^I parse the patch list text$/ do
74
+ @web_patch_list=[]
75
+ @web_result.body.to_s.each do |line|
76
+ m= /PTCHCMD ([A-Z]{3}\d\d\S{3}) /.match(line)
77
+ @web_patch_list << m[1] if m
78
+ end
79
+ end
80
+
81
+ Then /^I get the patch list from web$/ do
82
+ @web_patch_list.should_not be_empty
83
+ puts @web_patch_list
84
+ end
85
+
@@ -0,0 +1,4 @@
1
+ $: << File.join(File.dirname(__FILE__), "/../../lib" )
2
+ require 'rortel'
3
+ require 'net/http'
4
+ require 'uri'
@@ -0,0 +1,19 @@
1
+ module Rortel
2
+ class Base
3
+ def initialize opt
4
+ @ip=opt[:ip]
5
+ @user=opt[:user]
6
+ @password=opt[:password]
7
+ @pw=@user+' '+@password
8
+ @timeout = opt[:timeout] || 3
9
+ @r = "/dev/null" #reader socket
10
+ @w = "/dev/null" #writer socket
11
+ @p = nil #pid to kill later
12
+ @prompt = />/
13
+ @output = Array.new
14
+ @info = Array.new #store configuration info gleaned from config
15
+ @error = Array.new
16
+ end
17
+
18
+ end
19
+ end
data/lib/rortel/cli.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'optparse'
2
+
3
+ module Rortel
4
+ class CLI
5
+ def self.execute(stdout, arguments=[])
6
+
7
+ # NOTE: the option -p/--path= is given as an example, and should be replaced in your application.
8
+
9
+ options = {
10
+ :path => '~'
11
+ }
12
+ mandatory_options = %w( )
13
+
14
+ parser = OptionParser.new do |opts|
15
+ opts.banner = <<-BANNER.gsub(/^ /,'')
16
+ This application is wonderful because...
17
+
18
+ Usage: #{File.basename($0)} [options]
19
+
20
+ Options are:
21
+ BANNER
22
+ opts.separator ""
23
+ opts.on("-p", "--path PATH", String,
24
+ "This is a sample message.",
25
+ "For multiple lines, add more strings.",
26
+ "Default: ~") { |arg| options[:path] = arg }
27
+ opts.on("-h", "--help",
28
+ "Show this help message.") { stdout.puts opts; exit }
29
+ opts.parse!(arguments)
30
+
31
+ if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
32
+ stdout.puts opts; exit
33
+ end
34
+ end
35
+
36
+ path = options[:path]
37
+
38
+ # do stuff
39
+ stdout.puts "To update this executable, look in lib/rortel/cli.rb"
40
+ end
41
+ end
42
+ end
data/lib/rortel/dms.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'expect'
2
+ require 'pty'
3
+
4
+ module Rortel
5
+ module Dms
6
+ attr_accessor :patch_list
7
+ include Expectical
8
+ def login
9
+ cmd="telnet #{@ip}"
10
+ begin
11
+ PTY.spawn(cmd) do |r,w,p|
12
+ @r,@w,@p=r,w,p
13
+ @prompt=/\r\n>/
14
+ #read(@r,@timeout, @prompt)
15
+ if @ip =~/atca/
16
+ expect_times(/pass|>/,4)
17
+ else
18
+ expect_times(/pass|>/,5)
19
+ end
20
+ #clear_read_buffer
21
+ run(@pw)
22
+ read(@r,@timeout, @prompt)
23
+ end
24
+
25
+ rescue Exception => ee
26
+ @error.push("ERROR: Exception for host in login:#{ee.to_s}\n\nBad ip address?")
27
+ end
28
+
29
+ end
30
+
31
+ def logout
32
+ saved_prompt=@prompt
33
+ @prompt="Logged out on "
34
+ run("logout")
35
+ @prompt=saved_prompt
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,60 @@
1
+ require 'expect'
2
+ require 'pty'
3
+
4
+ module Rortel
5
+ module Expectical
6
+ attr_accessor :output, :info, :error
7
+
8
+ def read(r=@r,timeout=@timeout,prompt=@prompt)
9
+ begin
10
+ r.expect(prompt,timeout) do |rec|
11
+ if rec == nil then
12
+ @error.push("ERROR: Timeout talking to device")
13
+ #close()
14
+ return rec
15
+ else
16
+ rec=rec.to_s
17
+ @output.push(rec)
18
+ return rec
19
+ end
20
+ end
21
+ rescue Exception => ee
22
+ @error.push "ERROR:Exception trying to read stream: #{ee.to_s}"
23
+ return @output
24
+ end
25
+ end
26
+ def run(cmd,prompt=@prompt)
27
+ begin
28
+ @w.print("#{cmd}\n")
29
+ buffer = read(@r,@timeout,prompt)
30
+ rescue Exception => ee
31
+ @error.push("ERROR: Exception for host while executing #{cmd}: #{ee.to_s}")
32
+ end
33
+ return buffer
34
+ end
35
+ def expect_times(pat,count,r=@r,timeout=@timeout)
36
+ count.times.each do
37
+ r.expect(pat,timeout)
38
+ end
39
+ end
40
+
41
+ def close
42
+ begin
43
+ @w.close
44
+ @r.close
45
+ #just to be sure, nuke it
46
+ Process.kill(:SIGKILL, @p)
47
+ @output.push("connection closed in close method")
48
+ rescue Exception => ee
49
+ @error.push("ERROR: Problem closing connection: #{ee.to_s}")
50
+ end
51
+ end
52
+ def clear_read_buffer
53
+ puts "before"
54
+ while @r.gets != nil
55
+ @r.gets
56
+ end
57
+ puts "after"
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,43 @@
1
+ require 'net/ftp'
2
+
3
+ module Rortel
4
+ module FtpAccess
5
+ def connect_ftp_access(user,password)
6
+ @ftp=Net::FTP.new
7
+ @ftp.connect(@ip,21)
8
+ @ftp.login(user,password)
9
+ end
10
+ def setup_ftp_access
11
+ yield @ftp
12
+ end
13
+ def upload_patch(patch_file_path)
14
+ @ftp.putbinaryfile(patch_file_path,File.basename(patch_file_path,".*")+'$patch')
15
+ end
16
+ def delete_patch(patch_id)
17
+ patch_file=patch_id+'$PATCH'
18
+ file_list=@ftp.nlst
19
+ if file_list.include? patch_file
20
+ puts "delete patch#{patch_id}"
21
+ begin
22
+ @ftp.delete patch_file
23
+ rescue Net::FTPReplyError => ee
24
+ raise unless ee.message =~ /200 Command okay./
25
+ end
26
+ else
27
+ puts "can't delete #{patch_id} because it is not on the disk"
28
+ end
29
+ end
30
+ def disconnect_ftp_access
31
+ @ftp.close
32
+ end
33
+ def list_file
34
+ @f.nlst
35
+ end
36
+ def upload_all_patch_in_dir (dir)
37
+ Dir.glob('/home/ruan/sshfs/pacs_dir/*').each do |file|
38
+ upload_patch(file)
39
+ end
40
+ end
41
+
42
+ end
43
+ end
data/lib/rortel/msc.rb ADDED
@@ -0,0 +1,75 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ module Rortel
4
+ class Msc < Base
5
+ include Dms
6
+ include FtpAccess
7
+ def parse_prsu_status
8
+ # 33
9
+ # 78
10
+ #RUD03P9C RUD03MOD AA01 GEN N A 20100726 10:52 NA CACM
11
+ @output.last.each do |line|
12
+ m=/^[A-Z]{3}\d\d\S{3} /.match(line)
13
+ return line[37,2].strip if m
14
+ end
15
+
16
+ end
17
+ def change_patch(operation,patch_id)
18
+ check_before_and_after(patch_id) do |status|
19
+ run "prsm;#{operation} #{patch_id}"
20
+ if status == 'A' and operation == "remove"
21
+ run "prsm;#{operation} #{patch_id}"
22
+ run "y"
23
+ end
24
+ if status != 'A' and operation == "apply"
25
+ run "prsm;#{operation} #{patch_id}"
26
+ run "y"
27
+ end
28
+ end
29
+ end
30
+ def check_before_and_after(patch_id)
31
+ run "prsm;report prsu #{patch_id}"
32
+ result = parse_prsu_status
33
+ result||="none"
34
+ yield result if block_given?
35
+ run "prsm;report prsu #{patch_id}"
36
+ result = parse_prsu_status
37
+ result||="none"
38
+
39
+ end
40
+ def remove_patch(patch_id)
41
+ end
42
+ def parse_patch_list
43
+ patch_list = []
44
+ @output.last.each do |line|
45
+ m=/[A-Z]{3}\d\d\S{3}/.match(line)
46
+ patch_list<<m[0] if m
47
+ end
48
+ @patch_list=patch_list
49
+ end
50
+ def get_web_patch_list(pcl)
51
+ address="http://gsds.ca.nortel.com/cgi-bin/RPSFORMS/pcl2patch.cgi"
52
+ @web_patch_list=[]
53
+
54
+ web_result = Net::HTTP.post_form(URI.parse(address), {'next_sort'=>'1',
55
+ 'max_section'=>'1',
56
+ 'add_to_section'=>'0',
57
+ 'query_id_1'=>pcl})
58
+ web_result.body.to_s.each do |line|
59
+ m= /PTCHCMD ([A-Z]{3}\d\d\S{3}) /.match(line)
60
+ @web_patch_list << m[1] if m
61
+ end
62
+ return @web_patch_list
63
+
64
+ end
65
+ def quser
66
+ user_list=[]
67
+ run "quser"
68
+ @output.last.each do |line|
69
+ m= /(\S+)\s+TELNSVR/.match(line)
70
+ user_list << m[1] if m
71
+ end
72
+ user_list
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,17 @@
1
+ module Rortel
2
+ class PacsHost < Base
3
+ include Unix
4
+ def enter_pacs
5
+ @prompt=/\(pacs-\d*\): /
6
+ @timeout= 120
7
+ run('cd pacs_dir;pacs')
8
+ end
9
+ def download(patch_id)
10
+ run("download #{patch_id}")
11
+ end
12
+ def quit_pacs
13
+ @prompt=/>$/
14
+ run('quit')
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ module Rortel
2
+ class PlsHost < Base
3
+ include Unix
4
+ def enter_pls
5
+ @prompt="PLS(dmspl):"
6
+ @timeout= 120
7
+ run('pls dmspl')
8
+ end
9
+ def quit_pls
10
+ @prompt=/>$/
11
+ run('qq')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,30 @@
1
+ module Rortel
2
+ module Unix
3
+ include Expectical
4
+ def login
5
+ cmd="telnet #{@ip}\n"
6
+ begin
7
+ PTY.spawn(cmd) do |r,w,p|
8
+ @r,@w,@p=r,w,p
9
+ read(@r,@timeout, /\r\nlogin:/)
10
+ run(@user, "Password:")
11
+ run(@password, "/home/davidrua>")
12
+ end
13
+
14
+ rescue Exception => ee
15
+ @error.push("ERROR: Exception for host in login:#{ee.to_s}\n\nBad ip address?")
16
+ end
17
+
18
+ end
19
+
20
+ def logout
21
+ saved_prompt=@prompt
22
+ @prompt="Connection closed by foreign host"
23
+ run("logout")
24
+ @prompt=saved_prompt
25
+ end
26
+
27
+
28
+ end
29
+
30
+ end
data/lib/rortel.rb ADDED
@@ -0,0 +1,16 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module Rortel
5
+ VERSION = '0.1.1'
6
+ end
7
+
8
+ require 'rortel/expectical'
9
+ require 'rortel/dms'
10
+ require 'rortel/base'
11
+ require 'rortel/ftp_access'
12
+ require 'rortel/msc'
13
+ require 'rortel/unix'
14
+ require 'rortel/pls_host'
15
+ require 'rortel/pacs_host'
16
+ require 'test_data'
data/rortel.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rortel}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["David Ruan"]
9
+ s.date = %q{2010-07-20}
10
+ s.default_executable = %q{rortel}
11
+ s.description = %q{CLI lib for nortel networks devices}
12
+ s.email = ["ruanwz@gmail.com"]
13
+ s.executables = ["rortel"]
14
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt"]
15
+ s.files = [".Rakefile.swp", "History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "bin/rortel", "features/login_msc.feature", "features/login_rnd_unix.feature", "features/step_definitions/rortel.rb", "features/support/env.rb", "lib/rortel.rb", "lib/rortel/base.rb", "lib/rortel/cli.rb", "lib/rortel/dms.rb", "lib/rortel/expectical.rb", "lib/rortel/msc.rb", "lib/rortel/pls_host.rb", "lib/rortel/unix.rb", "rortel.gemspec", "script/console", "script/destroy", "script/generate", "spec/msc_spec.rb", "spec/pls_host_spec.rb", "spec/rortel_cli_spec.rb", "spec/rortel_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/.rcov.rake.swp", "tasks/rcov.rake", "tasks/rspec.rake"]
16
+ s.homepage = %q{http://github.com/ruanwz/rortel}
17
+ s.post_install_message = %q{PostInstall.txt}
18
+ s.rdoc_options = ["--main", "README.rdoc"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{rortel}
21
+ s.rubygems_version = %q{1.3.7}
22
+ s.summary = %q{CLI lib for nortel networks devices}
23
+
24
+ if s.respond_to? :specification_version then
25
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 3
27
+
28
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
29
+ s.add_development_dependency(%q<rubyforge>, [">= 2.0.4"])
30
+ s.add_development_dependency(%q<hoe>, [">= 2.6.1"])
31
+ else
32
+ s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
33
+ s.add_dependency(%q<hoe>, [">= 2.6.1"])
34
+ end
35
+ else
36
+ s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
37
+ s.add_dependency(%q<hoe>, [">= 2.6.1"])
38
+ end
39
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/rortel.rb'}"
9
+ puts "Loading rortel gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ # Time to add your specs!
4
+ # http://rspec.info/
5
+ module Rortel
6
+ describe FtpAccess do
7
+ context "starting up" do
8
+
9
+ it "should upload the patch file from local disk on ATCA" do
10
+ msc=Msc.new :ip=>'atcag1', :user=>'davidruan2', :password=>'davidruan2'
11
+ # msc.login
12
+ # msc.output.last.should =~ /Logged in on /m
13
+ # msc.logout
14
+ # msc.output.last.should =~ /Logged out on /m
15
+ # msc.error.should be_empty
16
+ msc.connect_ftp_access('admin','admin')
17
+ msc.setup_ftp_access do |f|
18
+ remote_file_list=f.nlst
19
+ begin
20
+ f.delete 'RUD03P9C$PATCH' if remote_file_list.include? 'RUD03P9C$PATCH'
21
+ rescue Net::FTPReplyError => ee
22
+ raise unless ee.message =~ /200 Command okay./
23
+ end
24
+ f.site('lrecl 128')
25
+ end
26
+ msc.upload_patch '/home/ruan/sshfs/rud03p9c.ptchppcp'
27
+ msc.disconnect_ftp_access
28
+ msc.login
29
+ msc.output.last.should =~ /Logged in on /m
30
+ msc.run('listsf all')
31
+ msc.output.last.should =~ /RUD03P9C\$PATCH/m
32
+ msc.logout
33
+ msc.output.last.should =~ /Logged out on /m
34
+ msc.error.should be_empty
35
+
36
+ end
37
+
38
+ it "should upload the files from the directoryto local disk on ATCA" do
39
+ msc=Msc.new :ip=>'atcag1', :user=>'davidruan2', :password=>'davidruan2'
40
+ msc.connect_ftp_access('admin','admin')
41
+ msc.upload_all_patch_in_dir '/home/ruan/sshfs/pacs_dir'
42
+ msc.disconnect_ftp_access
43
+ end
44
+ end
45
+
46
+ end
47
+ end
data/spec/msc_spec.rb ADDED
@@ -0,0 +1,66 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ # Time to add your specs!
4
+ # http://rspec.info/
5
+ module Rortel
6
+ describe Msc do
7
+ context "starting up" do
8
+
9
+ it "should send the welcome message and the bye message on ATCA" do
10
+ msc=Msc.new :ip=>'atcag1', :user=>'davidruan2', :password=>'davidruan2'
11
+ msc.login
12
+ msc.output.last.should =~ /Logged in on /m
13
+ msc.logout
14
+ msc.output.last.should =~ /Logged out on /m
15
+ #msc.error.should be_empty
16
+ end
17
+
18
+ it "should send the welcome message and the bye message on XA-Core" do
19
+ msc=Msc.new :ip=>'gsmr', :user=>'davidruan2', :password=>'davidruan2'
20
+ msc.login
21
+ msc.output.last.should =~ /Logged in on /m
22
+ msc.logout
23
+ msc.output.last.should =~ /Logged out on /m
24
+ #msc.error.should be_empty
25
+ end
26
+ end
27
+
28
+ context "patching" do
29
+ it "should parse the report prsu patch status" do
30
+ msc=Msc.new :ip=>'atcag1', :user=>'davidruan2', :password=>'davidruan2'
31
+ msc.login
32
+ msc.output.last.should =~ /Logged in on /m
33
+ msc.run "prsm;report prsu rud03p9c"
34
+ msc.parse_prsu_status.should_not be_empty
35
+ msc.logout
36
+ msc.output.last.should =~ /Logged out on /m
37
+ end
38
+
39
+ it "should remove the patch and apply the patch" do
40
+ msc=Msc.new :ip=>'atcag1', :user=>'davidruan2', :password=>'davidruan2'
41
+ msc.login
42
+ msc.output.last.should =~ /Logged in on /m
43
+ msc.change_patch "remove", "rud03p9c"
44
+ msc.run "prsm;report prsu rud03p9c"
45
+ msc.parse_prsu_status.should == "R"
46
+
47
+ msc.connect_ftp_access('admin','admin')
48
+ msc.setup_ftp_access do |f|
49
+ remote_file_list=f.nlst
50
+ begin
51
+ f.delete 'RUD03P9C$PATCH' if remote_file_list.include? 'RUD03P9C$PATCH'
52
+ rescue Net::FTPReplyError => ee
53
+ raise unless ee.message =~ /200 Command okay./
54
+ end
55
+ f.site('lrecl 128')
56
+ end
57
+ msc.upload_patch '/home/ruan/sshfs/rud03p9c.ptchppcp'
58
+ msc.disconnect_ftp_access
59
+ msc.run "listsf all"
60
+ msc.change_patch "apply","rud03p9c"
61
+ msc.run "prsm;report prsu rud03p9c"
62
+ msc.parse_prsu_status.should == "A"
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ # Time to add your specs!
3
+ # http://rspec.info/
4
+ module Rortel
5
+ describe PacsHost do
6
+ context "starting up" do
7
+
8
+ it "should login unix, enter pacs env and download patch" do
9
+ pacs=PacsHost.new :ip=>'rnd94', :user=>'davidrua', :password=>TestData::Password
10
+ pacs.login
11
+ pacs.enter_pacs
12
+ pacs.output.last.should =~ /\(pacs-\d*\): /m
13
+ pacs.download('rud03p9c')
14
+ pacs.download('alb12p9c')
15
+ pacs.quit_pacs
16
+ pacs.logout
17
+ pacs.output.last.should =~ /Connection closed by foreign host/m
18
+ pacs.error.should be_empty
19
+ end
20
+
21
+
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ # Time to add your specs!
3
+ # http://rspec.info/
4
+ module Rortel
5
+ describe PlsHost do
6
+ context "starting up" do
7
+
8
+ it "should login unix and enter pls env" do
9
+ pls=PlsHost.new :ip=>'rnd94', :user=>'davidrua', :password=>TestData::Password
10
+ pls.login
11
+ pls.enter_pls
12
+ pls.output.last.should =~ /PLS\(dmspl\):/m
13
+ pls.quit_pls
14
+ pls.logout
15
+ pls.output.last.should =~ /Connection closed by foreign host/m
16
+ pls.error.should be_empty
17
+ end
18
+
19
+
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'rortel/cli'
3
+
4
+ describe Rortel::CLI, "execute" do
5
+ before(:each) do
6
+ @stdout_io = StringIO.new
7
+ Rortel::CLI.execute(@stdout_io, [])
8
+ @stdout_io.rewind
9
+ @stdout = @stdout_io.read
10
+ end
11
+
12
+ it "should print default output" do
13
+ @stdout.should =~ /To update this executable/
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ # Time to add your specs!
4
+ # http://rspec.info/
5
+ describe "Place your specs here" do
6
+
7
+ it "find this spec in spec directory" do
8
+ # violated "Be sure to write your specs"
9
+ end
10
+
11
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'rortel'
data/tasks/rcov.rake ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'spec/rake/spectask'
4
+ namespace :spec do
5
+ desc "Run specs with RCov"
6
+ Spec::Rake::SpecTask.new('rcov' ) do |t|
7
+ t.spec_files = FileList['spec/**/*_spec.rb' ]
8
+ t.rcov = true
9
+ t.rcov_opts = ['--exclude' , '\/Library\/Ruby' ]
10
+ end
11
+ end
12
+
data/tasks/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rortel
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - David Ruan
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-27 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rubyforge
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 2
32
+ - 0
33
+ - 4
34
+ version: 2.0.4
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: hoe
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 21
46
+ segments:
47
+ - 2
48
+ - 6
49
+ - 1
50
+ version: 2.6.1
51
+ type: :development
52
+ version_requirements: *id002
53
+ description: CLI lib for nortel networks devices
54
+ email:
55
+ - ruanwz@gmail.com
56
+ executables:
57
+ - rortel
58
+ extensions: []
59
+
60
+ extra_rdoc_files:
61
+ - History.txt
62
+ - Manifest.txt
63
+ - PostInstall.txt
64
+ files:
65
+ - History.txt
66
+ - Manifest.txt
67
+ - PostInstall.txt
68
+ - README.rdoc
69
+ - Rakefile
70
+ - bin/rortel
71
+ - features/login_msc.feature
72
+ - features/login_rnd_unix.feature
73
+ - features/patching_msc.feature
74
+ - features/post_info_and_get_patch_list.feature
75
+ - features/step_definitions/rortel.rb
76
+ - features/support/env.rb
77
+ - lib/rortel.rb
78
+ - lib/rortel/base.rb
79
+ - lib/rortel/cli.rb
80
+ - lib/rortel/dms.rb
81
+ - lib/rortel/expectical.rb
82
+ - lib/rortel/ftp_access.rb
83
+ - lib/rortel/msc.rb
84
+ - lib/rortel/pacs_host.rb
85
+ - lib/rortel/pls_host.rb
86
+ - lib/rortel/unix.rb
87
+ - rortel.gemspec
88
+ - script/console
89
+ - script/destroy
90
+ - script/generate
91
+ - spec/ftp_access_spec.rb
92
+ - spec/msc_spec.rb
93
+ - spec/pacs_host_spec.rb
94
+ - spec/pls_host_spec.rb
95
+ - spec/rortel_cli_spec.rb
96
+ - spec/rortel_spec.rb
97
+ - spec/spec.opts
98
+ - spec/spec_helper.rb
99
+ - tasks/rcov.rake
100
+ - tasks/rspec.rake
101
+ has_rdoc: true
102
+ homepage:
103
+ licenses: []
104
+
105
+ post_install_message: PostInstall.txt
106
+ rdoc_options:
107
+ - --main
108
+ - README.rdoc
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ requirements: []
130
+
131
+ rubyforge_project: rortel
132
+ rubygems_version: 1.3.7
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: CLI lib for nortel networks devices
136
+ test_files: []
137
+