Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Specinfra to 2.91.0 #22

Merged
merged 1 commit into from
Oct 25, 2024
Merged
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
1 change: 1 addition & 0 deletions mrblib/specinfra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def backend
c.add_setting :scp, :default => nil
c.add_setting :sudo_password, :default => nil
c.add_setting :winrm, :default => nil
c.add_setting :docker_container, :default => nil
c.add_setting :architecture, :default => :x86_64
Specinfra.configuration.defaults.each { |k, v| c.add_setting k, :default => v }
c.before :each do
Expand Down
2 changes: 2 additions & 0 deletions mrblib/specinfra/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
# require 'specinfra/backend/powershell/command'
# require 'specinfra/backend/cmd'
# require 'specinfra/backend/docker'
# require 'specinfra/backend/dockercli'
# require 'specinfra/backend/lxc'
# require 'specinfra/backend/lxd'
# require 'specinfra/backend/winrm'
# require 'specinfra/backend/shell_script'
# require 'specinfra/backend/dockerfile'
Expand Down
2 changes: 1 addition & 1 deletion mrblib/specinfra/backend/1_exec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# require 'singleton'
# require 'fileutils'
# require 'shellwords'
# require 'sfl'
# require 'sfl' if Specinfra.ruby_is_older_than?(1, 9, 0)

module Specinfra
module Backend
Expand Down
34 changes: 34 additions & 0 deletions mrblib/specinfra/backend/dockercli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

module Specinfra
module Backend
# Docker command line transport
class Dockercli < Exec
def build_command(cmd)
docker_cmd = %w[docker exec]
docker_cmd << '--interactive' if get_config(:interactive_shell)
docker_cmd << '--tty' if get_config(:request_pty)
docker_cmd << instance
(docker_cmd << super(cmd)).join(' ')
end

def send_file(from, to)
to = Pathname.new(to).dirname.to_s if File.directory?(from)
cmd = %W[docker cp #{from} #{instance}:#{to}]
spawn_command(cmd.join(' '))
end

def send_directory(from, to)
send_file(from, to)
end

private

def instance
raise 'Please specify docker_container' unless (container = get_config(:docker_container))

container
end
end
end
end
39 changes: 39 additions & 0 deletions mrblib/specinfra/backend/lxd.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

# require 'singleton'
# require 'fileutils'
# require 'shellwords'
# require 'sfl' if Specinfra.ruby_is_older_than?(1, 9, 0)

module Specinfra
module Backend
# LXD transport
class Lxd < Exec
def build_command(cmd)
lxc_cmd = %W[lxc exec #{instance}]
lxc_cmd << '-t' if get_config(:interactive_shell)
lxc_cmd << '--'
(lxc_cmd << super(cmd)).join(' ')
end

def send_file(source, destination)
flags = %w[--create-dirs]
if File.directory?(source)
flags << '--recursive'
destination = Pathname.new(destination).dirname.to_s
end
cmd = %W[lxc file push #{source} #{instance}#{destination}] + flags
spawn_command(cmd.join(' '))
end

private

def instance
raise 'Please specify lxd_instance' unless (instance = get_config(:lxd_instance))
raise 'Please specify lxd_remote' unless (remote = get_config(:lxd_remote))

[remote, instance].compact.join(':')
end
end
end
end
7 changes: 7 additions & 0 deletions mrblib/specinfra/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Command
# require 'specinfra/command/module/zfs'
# require 'specinfra/command/module/ss'
# require 'specinfra/command/module/openrc'
# require 'specinfra/command/module/runit'

# Base
# require 'specinfra/command/base'
Expand Down Expand Up @@ -407,3 +408,9 @@ module Command
# require 'specinfra/command/poky/base/inventory'
# require 'specinfra/command/poky/base/package'
# require 'specinfra/command/poky/base/service'

# VoidLinux (inherit Linux)
# require 'specinfra/command/voidlinux'
# require 'specinfra/command/voidlinux/base'
# require 'specinfra/command/voidlinux/base/package'
# require 'specinfra/command/voidlinux/base/service'
24 changes: 24 additions & 0 deletions mrblib/specinfra/command/0_module/0_service/runit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ def check_is_running_under_runit(service)
def check_is_enabled_under_runit(service)
"test ! -f /etc/sv/#{escape(service)}/down"
end

def enable_under_runit(service)
"ln -s /etc/sv/#{service} /var/service/"
end

def disable_under_runit(service)
"rm /var/service/#{service}"
end

def start_under_runit(service)
"sv up /var/service/#{service}"
end

def stop_under_runit(service)
"sv down /var/service/#{service}"
end

def restart_under_runit(service)
"sv restart /var/service/#{service}"
end

def reload_under_runit(service)
"sv reload /var/service/#{service}"
end
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions mrblib/specinfra/command/0_module/runit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Specinfra
module Command
module Module
module Runit
include Specinfra::Command::Module::Service::Runit
extend Specinfra::Command::Module::Service::Delegator
def_delegator_service_under :runit
end
end
end
end
2 changes: 2 additions & 0 deletions mrblib/specinfra/command/voidlinux.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Specinfra::Command::Voidlinux < Specinfra::Command::Linux
end
2 changes: 2 additions & 0 deletions mrblib/specinfra/command/voidlinux/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Specinfra::Command::Voidlinux::Base < Specinfra::Command::Linux::Base
end
21 changes: 21 additions & 0 deletions mrblib/specinfra/command/voidlinux/base/package.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Specinfra::Command::Voidlinux::Base::Package < Specinfra::Command::Linux::Base::Package
class << self
def check_is_installed(package, version=nil)
"xbps-query -S #{escape(package)} | grep -q 'state: installed'"
end

alias :check_is_installed_by_xbps :check_is_installed

def get_version(package, opts=nil)
"xbps-query -S #{package} | sed -nE 's/^pkgver: #{package}-([^\)+])/\1/p'"
end

def install(package, version=nil, option='')
"xbps-install --yes #{package}"
end

def remove(package, option='')
"xbps-remove --yes #{option} #{package}"
end
end
end
5 changes: 5 additions & 0 deletions mrblib/specinfra/command/voidlinux/base/service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Specinfra::Command::Voidlinux::Base::Service < Specinfra::Command::Linux::Base::Service
class << self
include Specinfra::Command::Module::Runit
end
end
2 changes: 2 additions & 0 deletions mrblib/specinfra/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class << self
:docker_image,
:docker_url,
:lxc,
:lxd_remote,
:lxd_instance,
:request_pty,
:ssh_options,
:ssh_without_env,
Expand Down
16 changes: 14 additions & 2 deletions mrblib/specinfra/ec2_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ def initialize(host_inventory)
@host_inventory = host_inventory

@base_uri = 'http://169.254.169.254/latest/meta-data/'
@token_uri = 'http://169.254.169.254/latest/api/token'
@token = ''
@metadata = {}
end

def get
@token = get_token
@metadata = get_metadata
self
end
Expand Down Expand Up @@ -65,7 +68,7 @@ def inspect
def get_metadata(path='')
metadata = {}

keys = @host_inventory.backend.run_command("curl -s #{@base_uri}#{path}").stdout.split("\n")
keys = @host_inventory.backend.run_command("curl -H \"X-aws-ec2-metadata-token: #{@token}\" -s #{@base_uri}#{path}").stdout.split("\n")

keys.each do |key|
if key =~ %r{/$}
Expand All @@ -85,7 +88,16 @@ def get_metadata(path='')
end

def get_endpoint(path)
ret = @host_inventory.backend.run_command("curl -s #{@base_uri}#{path}")
ret = @host_inventory.backend.run_command("curl -H \"X-aws-ec2-metadata-token: #{@token}\" -s #{@base_uri}#{path}")
if ret.success?
ret.stdout
else
nil
end
end

def get_token
ret = @host_inventory.backend.run_command("curl -X PUT -H \"X-aws-ec2-metadata-token-ttl-seconds: 21600\" -s #{@token_uri}")
if ret.success?
ret.stdout
else
Expand Down
1 change: 1 addition & 0 deletions mrblib/specinfra/ext/class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def subclasses
Specinfra::Helper::DetectOs::Redhat,
Specinfra::Helper::DetectOs::Solaris,
Specinfra::Helper::DetectOs::Suse,
Specinfra::Helper::DetectOs::Voidlinux,
]
else
raise "#{self} is not supposed by mruby-specinfra Class#subclasses"
Expand Down
1 change: 1 addition & 0 deletions mrblib/specinfra/helper/detect_os.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ def detect
# require 'specinfra/helper/detect_os/redhat'
# require 'specinfra/helper/detect_os/solaris'
# require 'specinfra/helper/detect_os/suse'
# require 'specinfra/helper/detect_os/voidlinux'
11 changes: 11 additions & 0 deletions mrblib/specinfra/helper/detect_os/voidlinux.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Specinfra::Helper::DetectOs::Voidlinux < Specinfra::Helper::DetectOs
def detect
if run_command("ls /etc/os-release").success?
line = run_command("cat /etc/os-release").stdout

if line =~ /^ID="void"/
{ :family => 'voidlinux', :release => nil }
end
end
end
end
4 changes: 2 additions & 2 deletions mrblib/specinfra/host_inventory/virtualization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def get

cmd = backend.command.get(:get_inventory_system_product_name)
ret = backend.run_command(cmd)
if ret.exit_status == 0 and ret.stdout.length > 0
res[:system] = parse_system_product_name(ret.stdout)
if ret.success? and (parsed = parse_system_product_name(ret.stdout))
res[:system] = parsed
return res
end

Expand Down
6 changes: 5 additions & 1 deletion mrblib/specinfra/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module Specinfra
VERSION = "2.87.0"
VERSION = "2.91.0"

def self.ruby_is_older_than?(*version)
(RUBY_VERSION.split('.').map(&:to_i) <=> version) < 0
end
end
2 changes: 1 addition & 1 deletion update_specinfra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# 1. Update SPECINFRA_VERSION
# 2. Run ./update_specinfra.rb
SPECINFRA_REPO = 'mizzy/specinfra'
SPECINFRA_VERSION = 'v2.87.0'
SPECINFRA_VERSION = 'v2.91.0'

module GitHubFetcher
def self.fetch(repo, tag:, path:)
Expand Down
Loading