Skip to content

Commit

Permalink
Merged the current main branch and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skiera6 committed Oct 26, 2024
1 parent bc7a86d commit 222cabc
Show file tree
Hide file tree
Showing 29 changed files with 329 additions and 338 deletions.
4 changes: 2 additions & 2 deletions examples/device-simulation/device2yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ def cleanup
print data.gsub("\e", '\e')
end
ch.request_pty(term: 'vt100') do |_ch, success_pty|
raise NoShell, "Can't get PTY" unless success_pty
raise Error::NoShell, "Can't get PTY" unless success_pty

ch.send_channel_request 'shell' do |_ch, success_shell|
raise NoShell, "Can't get shell" unless success_shell
raise Error::NoShell, "Can't get shell" unless success_shell
end
end
ch.on_extended_data do |_ch, _type, data|
Expand Down
2 changes: 1 addition & 1 deletion extra/rest_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Config
begin
CFGS.load
rescue StandardError => e
raise InvalidConfig, "Error loading config: #{e.message}"
raise Error::InvalidConfig, "Error loading config: #{e.message}"
end

restcfg = CFGS.cfg.rest
Expand Down
2 changes: 1 addition & 1 deletion extra/syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Config
begin
CFGS.load
rescue StandardError => e
raise InvalidConfig, "Error loading config: #{e.message}"
raise Error::InvalidConfig, "Error loading config: #{e.message}"
ensure
CFG = CFGS.cfg # convenienence, instead of Config.cfg.password, CFG.password
end
Expand Down
4 changes: 2 additions & 2 deletions lib/oxidized/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ def self.load(cmd_opts = {})
begin
asetus.load # load system+user configs, merge to Config.cfg
rescue StandardError => e
raise InvalidConfig, "Error loading config: #{e.message}"
raise Error::InvalidConfig, "Error loading config: #{e.message}"
end


# @!visibility private
# If the configuration is being created for the first time, raise NoConfig
raise NoConfig, "edit #{@configfile}" if asetus.create
raise Error::NoConfig, "edit #{@configfile}" if asetus.create

# @!visibility private
# Override debug setting if provided in the command line options
Expand Down
4 changes: 2 additions & 2 deletions lib/oxidized/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def initialize(_args)
Oxidized.mgr = Manager.new
Oxidized.hooks = HookManager.from_config(Oxidized.config)
nodes = Nodes.new
raise NoNodesFound, 'source returns no usable nodes' if nodes.empty?
raise Error::NoNodesFound, 'source returns no usable nodes' if nodes.empty?

@worker = Worker.new nodes
@need_reload = false
Expand All @@ -43,7 +43,7 @@ def initialize(_args)
begin
require 'oxidized/web'
rescue LoadError
raise OxidizedError, 'oxidized-web not found: sudo gem install oxidized-web - \
raise Error::OxidizedError, 'oxidized-web not found: sudo gem install oxidized-web - \
or disable web support by setting "rest: false" in your configuration'
end
@rest = API::Web.new nodes, Oxidized.config.rest
Expand Down
2 changes: 1 addition & 1 deletion lib/oxidized/error/gitcrypterror.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class GitCryptError < OxidizedError; end
begin
require 'git'
rescue LoadError
raise OxidizedError, 'git not found: sudo gem install git'
raise Error::OxidizedError, 'git not found: sudo gem install git'
end
end
end
2 changes: 1 addition & 1 deletion lib/oxidized/error/giterror.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GitError < OxidizedError; end
begin
require 'rugged'
rescue LoadError
raise OxidizedError, 'rugged not found: sudo gem install rugged'
raise Error::OxidizedError, 'rugged not found: sudo gem install rugged'
end
end
end
86 changes: 43 additions & 43 deletions lib/oxidized/hook/githubrepo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def run_hook(ctx)
return
end

log "Pushing local repository(#{repo.path})..."
log "to remote: #{url}"
log "Pushing local repository(#{repo.path})..."
log "to remote: #{url}"

if repo.remotes['origin'].nil?
repo.remotes.create('origin', url)
elsif repo.remotes['origin'].url != url
repo.remotes.set_url('origin', url)
end
remote = repo.remotes['origin']
if repo.remotes['origin'].nil?
repo.remotes.create('origin', url)
elsif repo.remotes['origin'].url != url
repo.remotes.set_url('origin', url)
end
remote = repo.remotes['origin']

begin
fetch_and_merge_remote(repo, creds)
Expand All @@ -80,19 +80,19 @@ def fetch_and_merge_remote(repo, creds)
result = repo.fetch('origin', [repo.head.name], credentials: creds)
log result.inspect, :debug

their_branch = remote_branch(repo)
their_branch = remote_branch(repo)

unless their_branch
log 'remote branch does not exist yet, nothing to merge', :debug
return
end
unless their_branch
log 'remote branch does not exist yet, nothing to merge', :debug
return
end

result = repo.merge_analysis(their_branch.target_id)
result = repo.merge_analysis(their_branch.target_id)

if result.include? :up_to_date
log 'nothing to merge', :debug
return
end
if result.include? :up_to_date
log 'nothing to merge', :debug
return
end

log "merging fetched branch #{their_branch.name}", :debug

Expand Down Expand Up @@ -164,32 +164,32 @@ def remote_repo(node)
cfg.remote_repo[node.group].url
end
end
end
end

def rugged_sshkey(args = {})
git_user = args[:git_user]
privkey = args[:privkey]
pubkey = args[:pubkey] || (privkey + '.pub')
Rugged::Credentials::SshKey.new(username: git_user,
publickey: File.expand_path(pubkey),
privatekey: File.expand_path(privkey),
passphrase: ENV.fetch("OXIDIZED_SSH_PASSPHRASE", nil))
end
def rugged_sshkey(args = {})
git_user = args[:git_user]
privkey = args[:privkey]
pubkey = args[:pubkey] || (privkey + '.pub')
Rugged::Credentials::SshKey.new(username: git_user,
publickey: File.expand_path(pubkey),
privatekey: File.expand_path(privkey),
passphrase: ENV.fetch("OXIDIZED_SSH_PASSPHRASE", nil))
end

def remote_repo(node)
if node.group.nil? || cfg.remote_repo.is_a?(String)
cfg.remote_repo
elsif cfg.remote_repo[node.group].is_a?(String)
cfg.remote_repo[node.group]
elsif cfg.remote_repo[node.group].url.is_a?(String)
cfg.remote_repo[node.group].url
end
end
def remote_repo(node)
if node.group.nil? || cfg.remote_repo.is_a?(String)
cfg.remote_repo
elsif cfg.remote_repo[node.group].is_a?(String)
cfg.remote_repo[node.group]
elsif cfg.remote_repo[node.group].url.is_a?(String)
cfg.remote_repo[node.group].url
end
end

# Returns a Rugged::Branch to the remote branch or nil if it doen't exist
def remote_branch(repo)
head_branch = repo.branches[repo.head.name]
repo.branches['origin/' + head_branch.name]
# Returns a Rugged::Branch to the remote branch or nil if it doen't exist
def remote_branch(repo)
head_branch = repo.branches[repo.head.name]
repo.branches['origin/' + head_branch.name]
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/oxidized/input/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def connect(node)
begin
require "mechanize"
rescue LoadError
raise OxidizedError, "mechanize not found: sudo gem install mechanize"
raise Error::OxidizedError, "mechanize not found: sudo gem install mechanize"
end

@m = Mechanize.new
Expand Down
4 changes: 2 additions & 2 deletions lib/oxidized/input/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ def shell_open(ssh)
@output = @node.model.expects @output
end
ch.request_pty(@pty_options) do |_ch, success_pty|
raise NoShell, "Can't get PTY" unless success_pty
raise Error::NoShell, "Can't get PTY" unless success_pty

ch.send_channel_request 'shell' do |_ch, success_shell|
raise NoShell, "Can't get shell" unless success_shell
raise Error::NoShell, "Can't get shell" unless success_shell
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/oxidized/model/aosw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class AOSW < Oxidized::Models::Model
# Support for Mobility Access Switches tested with S2500-48P & S2500-24P running 7.4.1.4_54199 and S2500-24P running 7.4.1.7_57823
# All IAPs connected to a Instant Controller will have the same config output. Only the controller needs to be monitored.

comment '# '
# @!visibility private
# see /spec/model/aosw_spec.rb for prompt examples
prompt /^\(?[\w\:.@-]+\)? ?[*^]?(\[[\w\/]+\] ?)?[#>] ?$/
comment '# '

# @!visibility private
# see /spec/model/aosw_spec.rb for prompt examples
prompt /^\(?[\w\:.@-]+\)? ?[*^]?(\[[\w\/]+\] ?)?[#>] ?$/

# @!visibility private
# Ignore cariage returns - also for the prompt
Expand Down
24 changes: 12 additions & 12 deletions lib/oxidized/model/firewareos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ module Models
class FirewareOS < Oxidized::Models::Model
using Refinements

# @!visibility private
# matched prompts:
# [FAULT]WG<managed-by-wsm><master>>
# WG<managed-by-wsm><master>>
# WG<managed-by-wsm>>
# [FAULT]WG<non-master>>
# [FAULT]WG>
# WG>

prompt /^\[?\w*\]?\w*?(?:<[\w-]+>)*(#|>)\s*$/

comment '-- '
# @!visibility private
# matched prompts:
# [FAULT]WG<managed-by-wsm><master>>
# WG<managed-by-wsm><master>>
# WG<managed-by-wsm>>
# [FAULT]WG<non-master>>
# [FAULT]WG>
# WG>

prompt /^\[?\w*\]?\w*?(?:<[\w-]+>)*(#|>)\s*$/

comment '-- '

cmd :all do |cfg|
cfg.cut_both
Expand Down
4 changes: 2 additions & 2 deletions lib/oxidized/nodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ def update_nodes(nodes)
def yield_node_output(node_name)
with_lock do
node = find { |n| n.name == node_name }
raise(NodeNotFound, "unable to find '#{node_name}'") if node.nil?
raise(Error::NodeNotFound, "unable to find '#{node_name}'") if node.nil?

output = node.output.new
raise NotSupported unless output.respond_to? :fetch
raise Error::NotSupported unless output.respond_to? :fetch

yield node, output
end
Expand Down
66 changes: 33 additions & 33 deletions lib/oxidized/output/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,44 @@ class OxidizedFile < Output

attr_reader :commitref

# Initializes the OxidizedFile instance.
#
# @return [void]
def initialize
super
@cfg = Oxidized.config.output.file
end
# Initializes the OxidizedFile instance.
#
# @return [void]
def initialize
super
@cfg = Oxidized.config.output.file
end

def setup
return unless @cfg.empty?
def setup
return unless @cfg.empty?

Oxidized.asetus.user.output.file.directory = File.join(Config::ROOT, 'configs')
Oxidized.asetus.save :user
raise NoConfig, "no output file config, edit #{Oxidized::Config.configfile}"
end
Oxidized.asetus.user.output.file.directory = File.join(Config::ROOT, 'configs')
Oxidized.asetus.save :user
raise Error::NoConfig, "no output file config, edit #{Oxidized::Config.configfile}"
end

def store(node, outputs, opt = {})
file = File.expand_path @cfg.directory
file = File.join File.dirname(file), opt[:group] if opt[:group]
FileUtils.mkdir_p file
file = File.join file, node
File.write(file, outputs.to_cfg)
@commitref = file
end
def store(node, outputs, opt = {})
file = File.expand_path @cfg.directory
file = File.join File.dirname(file), opt[:group] if opt[:group]
FileUtils.mkdir_p file
file = File.join file, node
File.write(file, outputs.to_cfg)
@commitref = file
end

def fetch(node, group)
cfg_dir = File.expand_path @cfg.directory
node_name = node.name
def fetch(node, group)
cfg_dir = File.expand_path @cfg.directory
node_name = node.name

if group # group is explicitly defined by user
cfg_dir = File.join File.dirname(cfg_dir), group
File.read File.join(cfg_dir, node_name)
elsif File.exist? File.join(cfg_dir, node_name) # node configuration file is stored on base directory
File.read File.join(cfg_dir, node_name)
else
path = Dir.glob(File.join(File.dirname(cfg_dir), '**', node_name)).first # fetch node in all groups
File.read path
end
if group # group is explicitly defined by user
cfg_dir = File.join File.dirname(cfg_dir), group
File.read File.join(cfg_dir, node_name)
elsif File.exist? File.join(cfg_dir, node_name) # node configuration file is stored on base directory
File.read File.join(cfg_dir, node_name)
else
path = Dir.glob(File.join(File.dirname(cfg_dir), '**', node_name)).first # fetch node in all groups
File.read path
end

# Sets up the output directory for configuration files.
#
Expand Down
Loading

0 comments on commit 222cabc

Please sign in to comment.