Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 46 additions & 48 deletions bin/running-sushi
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# rubocop:disable Style/AccessorMethodName, Style/RedundantReturn, GlobalVars

require 'chef_diff/repo/svn'
require 'chef_diff/repo/git'
Expand All @@ -29,8 +30,6 @@ require 'optparse'
require 'logger'
require 'json'

# rubocop:disable GlobalVars

class ChangeProxy
attr_accessor :full_name

Expand Down Expand Up @@ -82,7 +81,7 @@ end

def read_checkpoint
RunningSushi::Log.debug("Reading #{checkpoint_path}")
File.exists?(checkpoint_path) ? File.read(checkpoint_path).strip : nil
File.exist?(checkpoint_path) ? File.read(checkpoint_path).strip : nil
end

def node_checkpoint_path
Expand All @@ -97,14 +96,13 @@ end

def read_node_checkpoint
RunningSushi::Log.debug("Reading #{node_checkpoint_path}")
if File.exists?(node_checkpoint_path)
upload_checkpoint = JSON.parse(File.read(node_checkpoint_path))
checkpoint = upload_checkpoint[0]
nodes = upload_checkpoint[1]
return checkpoint, nodes
else
return nil, []
end

return nil, [] unless File.exist?(node_checkpoint_path)

upload_checkpoint = JSON.parse(File.read(node_checkpoint_path))
checkpoint = upload_checkpoint[0]
nodes = upload_checkpoint[1]
return checkpoint, nodes
end

def get_pod_config
Expand Down Expand Up @@ -149,7 +147,7 @@ def chef_upload(knife, repo, checkpoint, local_head)
role_local_dir:
role_local_dir,
role_dir:
RunningSushi::Config.role_path,
RunningSushi::Config.role_path
)
rescue ChefDiff::Changeset::ReferenceError
RunningSushi::Log.error('Repo error, invalid revision, exiting')
Expand All @@ -161,12 +159,12 @@ def chef_upload(knife, repo, checkpoint, local_head)
x.status == :modified || x.status == :created
end
deleted_roles = changeset.roles.select do |x|
x.status == :deleted
x.status == :deleted
end
added_roles = changeset.roles.select do |x|
x.status == :modified || x.status == :created
end
deleted_roles_local = changeset.roles_local.select { |x| x.status == :deleted }
deleted_roles_local = changeset.roles_local.select { |x| x.status == :deleted }
added_roles_local = changeset.roles_local.select do |x|
x.status == :modified || x.status == :created
end
Expand All @@ -189,11 +187,11 @@ def chef_upload(knife, repo, checkpoint, local_head)
reupload_nodes = verify_nodes.reject { |x| knife.verify_node_upload(File.split(x)[-1], verify_checkpoint) }
reupload_nodes.each do |x|
node_file = File.join(RunningSushi::Config.master_path, RunningSushi::Config.reponame, node_dir) + "/#{x}.json"
if File.file?(node_file)
# Only re-upload if node has not been deleted from repo
node_proxy = ChangeProxy.new(x)
added_nodes.push(node_proxy)
end
next unless File.file?(node_file)

# Only re-upload if node has not been deleted from repo
node_proxy = ChangeProxy.new(x)
added_nodes.push(node_proxy)
end
end

Expand Down Expand Up @@ -226,12 +224,12 @@ def chef_upload(knife, repo, checkpoint, local_head)
if deleted_roles_local
deleted_roles_local.each do |x|
rolefile = File.join(RunningSushi::Config.master_path, RunningSushi::Config.reponame, RunningSushi::Config.role_path) + "/#{x.name}.json"
if File.file?(rolefile)
role_proxy = ChangeProxy.new(x.name)
added_roles.push(role_proxy)
deleted_roles_local.reject! do |y|
x.name == y.name
end
next unless File.file?(rolefile)

role_proxy = ChangeProxy.new(x.name)
added_roles.push(role_proxy)
deleted_roles_local.reject! do |y|
x.name == y.name
end
end
end
Expand Down Expand Up @@ -285,20 +283,20 @@ def upload_changed(repo, checkpoint)
node_dir, client_dir, environment_dir, role_local_dir = get_pod_config

knife = RunningSushi::Knife.new(
logger: RunningSushi::Log,
config: RunningSushi::Config.knife_config,
bin: RunningSushi::Config.knife_bin,
master_path: RunningSushi::Config.master_path,
base_dir: base_dir,
client_dir: File.join(base_dir, client_dir),
cookbook_dirs: RunningSushi::Config.cookbook_paths.map do |x|
File.join(base_dir, x)
end,
databag_dir: File.join(base_dir, RunningSushi::Config.databag_path),
environment_dir: File.join(base_dir, environment_dir),
node_dir: File.join(base_dir, node_dir),
role_dir: File.join(base_dir, RunningSushi::Config.role_path),
role_local_dir: File.join(base_dir, role_local_dir),
logger: RunningSushi::Log,
config: RunningSushi::Config.knife_config,
bin: RunningSushi::Config.knife_bin,
master_path: RunningSushi::Config.master_path,
base_dir: base_dir,
client_dir: File.join(base_dir, client_dir),
cookbook_dirs: RunningSushi::Config.cookbook_paths.map do |x|
File.join(base_dir, x)
end,
databag_dir: File.join(base_dir, RunningSushi::Config.databag_path),
environment_dir: File.join(base_dir, environment_dir),
node_dir: File.join(base_dir, node_dir),
role_dir: File.join(base_dir, RunningSushi::Config.role_path),
role_local_dir: File.join(base_dir, role_local_dir)
)

chef_upload(knife, repo, checkpoint, local_head)
Expand All @@ -315,17 +313,17 @@ def setup_config
end
opts.on('-v', '--verbosity', 'Verbosity level. Twice for debug.') do
# If -vv is supplied this block is executed twice
if options[:verbosity]
options[:verbosity] = ::Logger::DEBUG
else
options[:verbosity] = ::Logger::INFO
end
options[:verbosity] = if options[:verbosity]
::Logger::DEBUG
else
::Logger::INFO
end
end
opts.on('-T', '--timestamp', 'Timestamp output') do |s|
options[:timestamp] = s
end
opts.on('-c', '--config-file FILE', 'config file') do |s|
unless File.exists?(File.expand_path(s))
unless File.exist?(File.expand_path(s))
RunningSushi::Log.error("Config file #{s} not found.")
exit(2)
end
Expand All @@ -338,7 +336,7 @@ def setup_config
options[:pidfile] = s
end
end.parse!
if File.exists?(File.expand_path(options[:config_file]))
if File.exist?(File.expand_path(options[:config_file]))
RunningSushi::Config.from_file(options[:config_file])
end
RunningSushi::Config.merge!(options)
Expand Down Expand Up @@ -405,8 +403,8 @@ if RunningSushi::Config.dry_run && !repo.exists?
end

checkpoint = read_checkpoint
node_checkpoint, uploaded_nodes = read_node_checkpoint
if repo.exists? && repo.head_rev == checkpoint && uploaded_nodes.size == 0
_node_checkpoint, uploaded_nodes = read_node_checkpoint
if repo.exists? && repo.head_rev == checkpoint && uploaded_nodes.empty?
RunningSushi::Log.warn('Repo has not changed and no node uploads to check, nothing to do...')
$success = true
$status_msg = "Success at #{checkpoint}"
Expand Down
2 changes: 1 addition & 1 deletion lib/running_sushi/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def self.atexit(_dryrun, _success, _msg)
end

def self.get(file)
class_eval(File.read(file), __FILE__, __LINE__) if File.exists?(file)
class_eval(File.read(file), __FILE__, __LINE__) if File.exist?(file)
end
end
end
Loading