specinfra-2.82.8/0000755000004100000410000000000013614203316013614 5ustar www-datawww-dataspecinfra-2.82.8/README.md0000644000004100000410000000224213614203316015073 0ustar www-datawww-data# Specinfra TODO: Write a gem description ## Installation Add this line to your application's Gemfile: gem 'specinfra' And then execute: ``` bundle ``` Or install it yourself as: ``` gem install specinfra ``` ## Running tests ``` bundle exec rake ``` ## Usage TODO: Write usage instructions here ---- ## Maintenance policy of Serverspec/Specinfra * The person who found a bug should fix the bug by themself. * If you find a bug and cannot fix it by yourself, send a pull request and attach test code to reproduce the bug, please. * The person who want a new feature should implement it by themself. * For above reasons, I accept pull requests only and disable issues. * If you'd like to discuss about a new feature before implement it, make an empty commit and send [a WIP pull request](http://ben.straub.cc/2015/04/02/wip-pull-request/). But It is better that the WIP PR has some code than an empty commit. ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request specinfra-2.82.8/spec/0000755000004100000410000000000013614203316014546 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/0000755000004100000410000000000013614203316016164 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/esxi/0000755000004100000410000000000013614203316017134 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/esxi/package_spec.rb0000644000004100000410000000055313614203316022071 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, { :family => 'esxi' } describe get_command(:check_package_is_installed, 'httpd') do it { should eq 'esxcli software vib list | grep -w -- httpd' } end describe get_command(:check_package_is_installed, 'httpd', '2.0') do it { should eq 'esxcli software vib list | grep -w -- httpd | grep -w -- 2.0'} end specinfra-2.82.8/spec/command/ubuntu/0000755000004100000410000000000013614203316017506 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/ubuntu/ppa_spec.rb0000644000004100000410000000070113614203316021623 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'ubuntu' describe get_command(:check_ppa_exists, 'nginx/stable') do it { should eq %(find /etc/apt/ -name *.list | xargs grep -o -E "deb +[\\\"']?http://ppa.launchpad.net/nginx/stable") } end describe get_command(:check_ppa_is_enabled, 'nginx/stable') do it { should eq %(find /etc/apt/ -name *.list | xargs grep -o -E "^deb +[\\\"']?http://ppa.launchpad.net/nginx/stable") } end specinfra-2.82.8/spec/command/openbsd57/0000755000004100000410000000000013614203316017772 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/openbsd57/service_spec.rb0000644000004100000410000000156713614203316023002 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'openbsd', :release => '5.7' describe get_command(:check_service_is_enabled, 'httpd') do it { should eq 'rcctl get httpd status' } end describe get_command(:check_service_is_running, 'httpd') do it { should eq 'rcctl check httpd' } end describe get_command(:enable_service, 'httpd') do it { should eq 'rcctl set httpd status on' } end describe get_command(:disable_service, 'httpd') do it { should eq 'rcctl set httpd status off' } end describe get_command(:start_service, 'httpd') do it { should eq 'rcctl start httpd' } end describe get_command(:stop_service, 'httpd') do it { should eq 'rcctl stop httpd' } end describe get_command(:restart_service, 'httpd') do it { should eq 'rcctl restart httpd' } end describe get_command(:reload_service, 'httpd') do it { should eq 'rcctl reload httpd' } end specinfra-2.82.8/spec/command/linux/0000755000004100000410000000000013614203316017323 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/linux/interface_spec.rb0000644000004100000410000000250513614203316022624 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'linux' describe get_command(:check_interface_has_ipv6_address, 'eth0', '2001:0db8:bd05:01d2:288a:1fc0:0001:10ee') do it { should eq "ip -6 addr show eth0 | grep 'inet6 2001:0db8:bd05:01d2:288a:1fc0:0001:10ee/'" } end describe get_command(:check_interface_has_ipv6_address, 'eth0', '2001:0db8:bd05:01d2:288a:1fc0:0001:10ee/64') do it { should eq "ip -6 addr show eth0 | grep 'inet6 2001:0db8:bd05:01d2:288a:1fc0:0001:10ee/64 '" } end describe get_command(:check_interface_has_ipv4_address, 'eth0', '192.168.0.123') do it { should eq "ip -4 addr show eth0 | grep 'inet 192\\.168\\.0\\.123/'" } end describe get_command(:check_interface_has_ipv4_address, 'eth0', '192.168.0.123/24') do it { should eq "ip -4 addr show eth0 | grep 'inet 192\\.168\\.0\\.123/24 '" } end describe get_command(:get_interface_ipv4_address, 'eth0') do it { should eq "ip -4 addr show eth0 | grep eth0$ | awk '{print $2}'" } end describe get_command(:get_interface_ipv6_address, 'eth0') do it { should eq "ip -6 addr show eth0 | grep inet6 | awk '{print $2}'" } end describe get_command(:get_interface_link_state, 'eth0') do it { should eq "cat /sys/class/net/eth0/operstate" } end describe get_command(:get_interface_mtu_of, 'eth0') do it { should eq "cat /sys/class/net/eth0/mtu" } end specinfra-2.82.8/spec/command/linux/ip6tables_spec.rb0000644000004100000410000000030513614203316022551 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe get_command(:check_ip6tables_has_rule, 'rule') do it { should eq 'ip6tables -S | grep -- rule || ip6tables-save | grep -- rule' } end specinfra-2.82.8/spec/command/linux/file_spec.rb0000644000004100000410000000053413614203316021603 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'linux' describe get_command(:check_file_is_immutable, 'some_file') do it { should eq "lsattr -d some_file 2>&1 | awk '$1~/^[A-Za-z-]+$/ && $1~/i/ {exit 0} {exit 1}'" } end describe get_command(:get_file_selinuxlabel, 'some_file') do it { should eq 'stat -c %C some_file' } end specinfra-2.82.8/spec/command/linux/inventory_spec.rb0000644000004100000410000000110513614203316022714 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe get_command(:get_inventory_memory) do it { should eq 'cat /proc/meminfo' } end describe get_command(:get_inventory_cpu) do it { should eq 'cat /proc/cpuinfo' } end describe get_command(:get_inventory_kernel) do it { should eq 'uname -s -r' } end describe get_command(:get_inventory_block_device) do block_device_dirs = '/sys/block/*/{size,removable,device/{model,rev,state,timeout,vendor},queue/rotational}' it { should eq "for f in $(ls #{block_device_dirs}); do echo -e \"${f}\t$(cat ${f})\"; done" } end specinfra-2.82.8/spec/command/linux/selinux_module_spec.rb0000644000004100000410000000056213614203316023721 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'linux' describe get_command(:check_selinux_module_is_installed, 'dnsmasq') do it { should eq "semodule -l | grep $'^dnsmasq\\t'" } end describe get_command(:check_selinux_module_is_enabled, 'dnsmasq') do it { should eq "semodule -l | grep $'^dnsmasq\\t' | grep -v $'^dnsmasq\\t.*\\tDisabled$'" } end specinfra-2.82.8/spec/command/linux/bond_spec.rb0000644000004100000410000000047313614203316021610 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'linux' describe get_command(:check_bond_exists, 'bond0') do it { should eq "ip link show bond0" } end describe get_command(:check_bond_has_interface, 'br0', 'eth0') do it { should eq "grep -o 'Slave Interface: eth0' /proc/net/bonding/br0" } end specinfra-2.82.8/spec/command/linux/bridge_spec.rb0000644000004100000410000000044313614203316022117 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'linux' describe get_command(:check_bridge_exists, 'br0') do it { should eq "ip link show br0" } end describe get_command(:check_bridge_has_interface, 'br0', 'eth0') do it { should eq "brctl show br0 | grep -o eth0" } end specinfra-2.82.8/spec/command/linux/selinux_spec.rb0000644000004100000410000000167213614203316022357 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'linux' describe get_command(:check_selinux_has_mode, 'disabled') do it do should eq %Q{test ! -f /etc/selinux/config || ( ( (} + %Q{getenforce | grep -i -- disabled) ||} + %Q{ (getenforce | grep -i -- permissive) )} + %Q{ && grep -iE -- '^\\s*SELINUX=disabled\\>' /etc/selinux/config)} end end describe get_command(:check_selinux_has_mode, 'permissive', nil) do it do should eq %Q{(getenforce | grep -i -- permissive)} + %Q{ && grep -iE -- '^\\s*SELINUX=permissive\\>' /etc/selinux/config} end end describe get_command(:check_selinux_has_mode, 'enforcing', 'targeted') do it do should eq %Q{(getenforce | grep -i -- enforcing)} + %Q{ && grep -iE -- '^\\s*SELINUX=enforcing\\>' /etc/selinux/config} + %Q{ && grep -iE -- '^\\s*SELINUXTYPE=targeted\\>' /etc/selinux/config} end end specinfra-2.82.8/spec/command/debian/0000755000004100000410000000000013614203316017406 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/debian/package_spec.rb0000644000004100000410000000277613614203316022354 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'debian' describe get_command(:check_package_is_installed, 'telnet') do it { should eq "dpkg-query -f '${Status}' -W telnet | grep -E '^(install|hold) ok installed$'" } end describe get_command(:check_package_is_installed, 'telnet', '0.17-36build2') do it { should eq "dpkg-query -f '${Status} ${Version}' -W telnet | grep -E '^(install|hold) ok installed 0\\.17\\-36build2$'" } end describe get_command(:check_package_is_installed, 'linux-headers-$(uname -r)') do it 'should be escaped (that is, command substitution should not work)' do should eq "dpkg-query -f '${Status}' -W linux-headers-\\$\\(uname\\ -r\\) | grep -E '^(install|hold) ok installed$'" end end describe get_command(:install_package, 'telnet') do it { should eq "DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install telnet" } end describe get_command(:install_package, 'telnet', '0.17-36build2') do it { should eq "DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install telnet\\=0.17-36build2" } end describe get_command(:install_package, 'linux-headers-$(uname -r)') do it 'should be escaped (that is, command substitution should not work)' do should eq "DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install linux-headers-\\$\\(uname\\ -r\\)" end end specinfra-2.82.8/spec/command/debian/service_spec.rb0000644000004100000410000000126013614203316022404 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'debian' describe get_command(:enable_service, 'apache2') do it { should eq 'update-rc.d apache2 defaults' } end describe get_command(:disable_service, 'apache2') do it { should eq 'update-rc.d -f apache2 remove' } end describe get_command(:start_service, 'apache2') do it { should eq 'service apache2 start' } end describe get_command(:stop_service, 'apache2') do it { should eq 'service apache2 stop' } end describe get_command(:restart_service, 'apache2') do it { should eq 'service apache2 restart' } end describe get_command(:reload_service, 'apache2') do it { should eq 'service apache2 reload' } end specinfra-2.82.8/spec/command/debian/port_spec.rb0000644000004100000410000000027113614203316021731 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'debian' describe get_command(:check_port_is_listening, '80') do it { should eq 'netstat -tunl | grep -- :80\ ' } end specinfra-2.82.8/spec/command/debian8/0000755000004100000410000000000013614203316017476 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/debian8/port_spec.rb0000644000004100000410000000030713614203316022021 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'debian', :release => '8' describe get_command(:check_port_is_listening, '80') do it { should eq 'ss -tunl | grep -E -- :80\ ' } end specinfra-2.82.8/spec/command/factory_spec.rb0000644000004100000410000000163013614203316021172 0ustar www-datawww-datarequire 'spec_helper' describe 'create_command_class work correctly' do before do property[:os] = nil end context 'family: base, release: nil' do before do set :os, :family => 'base' end it { expect(Specinfra.command.send(:create_command_class, 'file')).to eq Specinfra::Command::Base::File } end context 'family: redhat, release: nil' do before do set :os, :family => 'redhat' end it { expect(Specinfra.command.send(:create_command_class, 'file')).to eq Specinfra::Command::Redhat::Base::File } it { expect(Specinfra.command.send(:create_command_class, 'selinux')).to eq Specinfra::Command::Linux::Base::Selinux } end context 'family: redhat, release: 7' do before do set :os, :family => 'redhat', :release => 7 end it { expect(Specinfra.command.send(:create_command_class, 'file')).to eq Specinfra::Command::Redhat::V7::File } end end specinfra-2.82.8/spec/command/debian9/0000755000004100000410000000000013614203316017477 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/debian9/service_spec.rb0000644000004100000410000000041013614203316022471 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'debian', :release => '9' describe get_command(:check_service_is_enabled, 'apache') do it { should eq 'systemctl --quiet is-enabled apache||ls /etc/rc[S5].d/S??apache >/dev/null 2>/dev/null' } end specinfra-2.82.8/spec/command/debian9/port_spec.rb0000644000004100000410000000031013614203316022014 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'debian', :release => '9' describe get_command(:check_port_is_listening, '80') do it { should eq 'ss -tunl | grep -E -- :80\ ' } end specinfra-2.82.8/spec/command/sles15/0000755000004100000410000000000013614203316017300 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/sles15/service_spec.rb0000644000004100000410000000032113614203316022273 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'sles', :release => '15' describe get_command(:check_service_is_enabled, 'httpd') do it { should eq 'systemctl --quiet is-enabled httpd' } end specinfra-2.82.8/spec/command/module/0000755000004100000410000000000013614203316017451 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/module/ss_spec.rb0000644000004100000410000000501313614203316021434 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Command::Module::Ss do class Specinfra::Command::Module::Ss::Test < Specinfra::Command::Base extend Specinfra::Command::Module::Ss end let(:klass) { Specinfra::Command::Module::Ss::Test } it { expect(klass.check_is_listening('80')).to eq 'ss -tunl | grep -E -- :80\ ' } it { expect(klass.check_is_listening('80', options={:protocol => 'tcp'})).to eq 'ss -tnl4 | grep -E -- :80\ ' } it { expect(klass.check_is_listening('80', options={:protocol => 'tcp6'})).to eq 'ss -tnl6 | grep -E -- :80\ ' } it { expect(klass.check_is_listening('80', options={:protocol => 'udp'})).to eq 'ss -unl4 | grep -E -- :80\ ' } it { expect(klass.check_is_listening('80', options={:protocol => 'udp6'})).to eq 'ss -unl6 | grep -E -- :80\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '0.0.0.0'})).to eq 'ss -tunl | grep -E -- \ \\\\\*:80\ \\|\\ 0\\\\.0\\\\.0\\\\.0:80\\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '0.0.0.0', :protocol => 'tcp'})).to eq 'ss -tnl4 | grep -E -- \ \\\\\*:80\ \\|\\ 0\\\\.0\\\\.0\\\\.0:80\\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '0.0.0.0', :protocol => 'tcp6'})).to eq 'ss -tnl6 | grep -E -- \ \\\\\*:80\ \\|\\ 0\\\\.0\\\\.0\\\\.0:80\\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '0.0.0.0', :protocol => 'udp'})).to eq 'ss -unl4 | grep -E -- \ \\\\\*:80\ \\|\\ 0\\\\.0\\\\.0\\\\.0:80\\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '0.0.0.0', :protocol => 'udp6'})).to eq 'ss -unl6 | grep -E -- \ \\\\\*:80\ \\|\\ 0\\\\.0\\\\.0\\\\.0:80\\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '1.2.3.4'})).to eq 'ss -tunl | grep -E -- \ 1.2.3.4:80\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '1.2.3.4', :protocol => 'tcp'})).to eq 'ss -tnl4 | grep -E -- \ 1.2.3.4:80\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '1.2.3.4', :protocol => 'tcp6'})).to eq 'ss -tnl6 | grep -E -- \ 1.2.3.4:80\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '1.2.3.4', :protocol => 'udp'})).to eq 'ss -unl4 | grep -E -- \ 1.2.3.4:80\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '1.2.3.4', :protocol => 'udp6'})).to eq 'ss -unl6 | grep -E -- \ 1.2.3.4:80\ ' } it { expect{klass.check_is_listening('80', options={:protocol => 'bad_proto'})}.to raise_error(ArgumentError, 'Unknown protocol [bad_proto]') } end specinfra-2.82.8/spec/command/module/service/0000755000004100000410000000000013614203316021111 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/module/service/daemontools_spec.rb0000644000004100000410000000320213614203316024771 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Command::Module::Service::Daemontools do class Specinfra::Command::Module::Service::Daemontools::Test < Specinfra::Command::Base extend Specinfra::Command::Module::Service::Daemontools end let(:klass) { Specinfra::Command::Module::Service::Daemontools::Test } it { expect(klass.check_is_enabled_under_daemontools('httpd')).to eq "test -L $([ -d /service ] && echo /service || echo /etc/service)/httpd && test -f $([ -d /service ] && echo /service || echo /etc/service)/httpd/run" } it { expect(klass.check_is_running_under_daemontools('httpd')).to eq "svstat $([ -d /service ] && echo /service || echo /etc/service)/httpd | grep -E 'up \\(pid [0-9]+\\)'" } it { expect(klass.enable_under_daemontools('httpd', '/tmp/service/httpd')).to eq 'ln -snf /tmp/service/httpd $([ -d /service ] && echo /service || echo /etc/service)/httpd' } it { expect(klass.disable_under_daemontools('httpd')).to eq '( cd $([ -d /service ] && echo /service || echo /etc/service)/httpd && rm -f $([ -d /service ] && echo /service || echo /etc/service)/httpd && svc -dx . log )' } it { expect(klass.start_under_daemontools('httpd')).to eq 'svc -u $([ -d /service ] && echo /service || echo /etc/service)/httpd' } it { expect(klass.stop_under_daemontools('httpd')).to eq 'svc -d $([ -d /service ] && echo /service || echo /etc/service)/httpd' } it { expect(klass.restart_under_daemontools('httpd')).to eq 'svc -t $([ -d /service ] && echo /service || echo /etc/service)/httpd' } it { expect(klass.reload_under_daemontools('httpd')).to eq 'svc -h $([ -d /service ] && echo /service || echo /etc/service)/httpd' } end specinfra-2.82.8/spec/command/module/service/systemd_spec.rb0000644000004100000410000000176513614203316024151 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Command::Module::Service::Systemd do class Specinfra::Command::Module::Service::Systemd::Test < Specinfra::Command::Base extend Specinfra::Command::Module::Service::Systemd end let(:klass) { Specinfra::Command::Module::Service::Systemd::Test } it { expect(klass.check_is_enabled_under_systemd('httpd')).to eq "systemctl --quiet is-enabled httpd" } it { expect(klass.check_is_running_under_systemd('httpd')).to eq 'systemctl is-active httpd' } it { expect(klass.enable_under_systemd('httpd')).to eq 'systemctl enable httpd' } it { expect(klass.disable_under_systemd('httpd')).to eq 'systemctl disable httpd' } it { expect(klass.start_under_systemd('httpd')).to eq 'systemctl start httpd' } it { expect(klass.stop_under_systemd('httpd')).to eq 'systemctl stop httpd' } it { expect(klass.restart_under_systemd('httpd')).to eq 'systemctl restart httpd' } it { expect(klass.reload_under_systemd('httpd')).to eq 'systemctl reload httpd' } end specinfra-2.82.8/spec/command/module/service/init_spec.rb0000644000004100000410000000167613614203316023425 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Command::Module::Service::Init do class Specinfra::Command::Module::Service::Init::Test < Specinfra::Command::Base extend Specinfra::Command::Module::Service::Init end let(:klass) { Specinfra::Command::Module::Service::Init::Test } it { expect(klass.check_is_enabled_under_init('httpd')).to eq "chkconfig --list httpd | grep 3:on" } it { expect(klass.check_is_running_under_init('httpd')).to eq 'service httpd status' } it { expect(klass.enable_under_init('httpd')).to eq 'chkconfig httpd on' } it { expect(klass.disable_under_init('httpd')).to eq 'chkconfig httpd off' } it { expect(klass.start_under_init('httpd')).to eq 'service httpd start' } it { expect(klass.stop_under_init('httpd')).to eq 'service httpd stop' } it { expect(klass.restart_under_init('httpd')).to eq 'service httpd restart' } it { expect(klass.reload_under_init('httpd')).to eq 'service httpd reload' } end specinfra-2.82.8/spec/command/module/systemd_spec.rb0000644000004100000410000000124313614203316022500 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Command::Redhat::V7::Service do let(:klass) { Specinfra::Command::Redhat::V7::Service } it { expect(klass.check_is_enabled('httpd')).to eq "systemctl --quiet is-enabled httpd" } it { expect(klass.check_is_enabled('httpd', 'multi-user.target')).to eq "systemctl --quiet is-enabled httpd" } it { expect(klass.check_is_enabled('httpd.service')).to eq "systemctl --quiet is-enabled httpd.service" } it { expect(klass.check_is_enabled('sshd.socket')).to eq "systemctl --quiet is-enabled sshd.socket" } it { expect(klass.check_is_enabled('logrotate.timer')).to eq "systemctl --quiet is-enabled logrotate.timer" } end specinfra-2.82.8/spec/command/module/zfs_spec.rb0000644000004100000410000000053413614203316021614 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Command::Solaris::Base::Zfs do let(:klass) { Specinfra::Command::Solaris::Base::Zfs } it { expect(klass.check_exists('rpool')).to eq "zfs list -H rpool" } it { expect(klass.check_has_property('rpool', {'mountpoint' => '/rpool' })).to eq "zfs list -H -o mountpoint rpool | grep -- \\^/rpool\\$" } end specinfra-2.82.8/spec/command/freebsd/0000755000004100000410000000000013614203316017576 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/freebsd/interface_spec.rb0000644000004100000410000000401713614203316023077 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'freebsd' describe get_command(:check_interface_has_ipv6_address, 'vtnet0', '2001:0db8:bd05:01d2:288a:1fc0:0001:10ee') do it { should eq "ifconfig vtnet0 inet6 | grep 'inet6 2001:0db8:bd05:01d2:288a:1fc0:0001:10ee '" } end describe get_command(:check_interface_has_ipv6_address, 'vtnet0', '2001:0db8:bd05:01d2:288a:1fc0:0001:10ee/64') do it { should eq "ifconfig vtnet0 inet6 | grep 'inet6 2001:0db8:bd05:01d2:288a:1fc0:0001:10ee prefixlen 64'" } end describe get_command(:check_interface_has_ipv6_address, 'vtnet0', 'fe80::5054:ff:fe01:10ee/64') do it { should eq "ifconfig vtnet0 inet6 | grep 'inet6 fe80::5054:ff:fe01:10ee%vtnet0 prefixlen 64'" } end describe get_command(:check_interface_has_ipv6_address, 'vtnet0', 'fe80::5054:ff:fe01:10ee') do it { should eq "ifconfig vtnet0 inet6 | grep 'inet6 fe80::5054:ff:fe01:10ee%vtnet0 '" } end describe get_command(:check_interface_has_ipv4_address, 'vtnet0', '192.168.0.123') do it { should eq "ifconfig vtnet0 inet | grep 'inet 192\\.168\\.0\\.123 '" } end describe get_command(:check_interface_has_ipv4_address, 'vtnet0', '192.168.0.123/24') do it { should eq "ifconfig vtnet0 inet | grep 'inet 192\\.168\\.0\\.123 '" } end describe get_command(:get_interface_ipv4_address, 'vtnet0') do it { should eq "ifconfig vtnet0 inet | grep inet | awk '{print $2}'" } end describe get_command(:get_interface_ipv6_address, 'vtnet0') do it { should eq "ifconfig vtnet0 inet6 | grep inet6 | awk '{print $2$3$4}' | sed 's/prefixlen/\//'; exit" } end describe get_command(:get_interface_link_state, 'vtnet0') do it { should eq %Q{ifconfig -u vtnet0 2>&1 | awk -v s=up '/status:/ && $2 != "active" { s="down" }; END {print s}'} } end describe get_command(:get_interface_speed_of, 'vtnet0') do it { should eq "ifconfig vtnet0 | awk '/media:/{if(match($0,/[0-9]+/)){ print substr($0, RSTART, RLENGTH);}}'" } end describe get_command(:get_interface_mtu_of, 'vtnet0') do it { should eq "ifconfig vtnet0 | awk '/mtu /{print $NF}'" } end specinfra-2.82.8/spec/command/freebsd/file_spec.rb0000644000004100000410000000051213614203316022052 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'freebsd' describe get_command(:check_file_is_owned_by, '/tmp', 'root') do it { should eq 'stat -f%Su /tmp | grep -- \\^root\\$' } end describe get_command(:check_file_is_grouped, '/tmp', 'wheel') do it { should eq 'stat -f%Sg /tmp | grep -- \\^wheel\\$' } end specinfra-2.82.8/spec/command/freebsd/package_spec.rb0000644000004100000410000001500413614203316022530 0ustar www-datawww-datarequire 'spec_helper' describe 'command/freebsd/package works correctly' do before do property[:os] = nil end context 'freebsd-base' do before do set :os, :family => 'freebsd' end describe 'get_command(:check_package_is_installed, "figlet")' do it { expect(get_command(:check_package_is_installed, 'figlet')).to match /^pkg +info +-e +figlet$/ } end describe 'get_command(:check_package_is_installed, "figlet", "1.2.3")' do it { expect(get_command(:check_package_is_installed, 'figlet', '1.2.3')).to match /^pkg +query +%v +figlet *\| *grep -- 1.2.3$/ } end describe 'get_command(:install_package, "figlet")' do it { expect(get_command(:install_package, 'figlet')).to match /^pkg +install +-y +figlet$/ } end end context 'freebsd-6' do before do set :os, :family => 'freebsd', :release => '6' end describe 'get_command(:check_package_is_installed, "figlet")' do it { expect(get_command(:check_package_is_installed, 'figlet')).to match /^pkg_info +-Ix +figlet$/ } end describe 'get_command(:check_package_is_installed, "figlet", "1.2.3")' do it { expect(get_command(:check_package_is_installed, 'figlet', '1.2.3')).to match /^pkg_info +-I +figlet-1.2.3$/ } end describe 'get_command(:install_package, "figlet")' do it { expect(get_command(:install_package, 'figlet')).to match /^pkg_add +-r +figlet$/ } end end context 'freebsd-7' do before do set :os, :family => 'freebsd', :release => '7' end describe 'get_command(:check_package_is_installed, "figlet")' do it { expect(get_command(:check_package_is_installed, 'figlet')).to match /^pkg_info +-Ix +figlet$/ } end describe 'get_command(:check_package_is_installed, "figlet", "1.2.3")' do it { expect(get_command(:check_package_is_installed, 'figlet', '1.2.3')).to match /^pkg_info +-I +figlet-1.2.3$/ } end describe 'get_command(:install_package, "figlet")' do it { expect(get_command(:install_package, 'figlet')).to match /^pkg_add +-r +figlet$/ } end end context 'freebsd-8' do before do set :os, :family => 'freebsd', :release => '8' end let(:cond) do %r{TMPDIR=/dev/null +ASSUME_ALWAYS_YES=1 +PACKAGESITE=file:///nonexist +pkg +info +-x +'pkg\(-devel\)\?\$' *> */dev/null +2>&1} end describe 'get_command(:check_package_is_installed, "figlet")' do st = /pkg +info +-e +figlet/ sf = /pkg_info +-Ix +\\\^figlet-\\\[0-9\\\]\\\[0-9a-zA-Z_\.,\\\]\\\*\\\$/ it { expect(get_command(:check_package_is_installed, 'figlet')). to match /^if +#{cond} *; *then +#{st} *; *else +#{sf} *; *fi$/ } end describe 'get_command(:check_package_is_installed, "figlet", "1.2.3")' do st = /pkg +query +%v +figlet *\| *grep -- 1.2.3/ sf = /pkg_info +-I +figlet-1.2.3/ it { expect(get_command(:check_package_is_installed, 'figlet', '1.2.3')). to match /^if +#{cond} *; *then +#{st} *; *else +#{sf} *; *fi$/ } end describe 'get_command(:install_package, "figlet")' do st = /pkg +install +-y +figlet/ sf = /pkg_add +-r +figlet/ it { expect(get_command(:install_package, 'figlet')). to match /^if +#{cond} *; *then +#{st} *; *else +#{sf} *; *fi$/ } end describe 'get_command(:get_package_version, "figlet")' do st = /pkg +query +%v +figlet/ sf = /pkg_info +-Ix +\\\^figlet-\\\[0-9\\\]\\\[0-9a-zA-Z_\.,\\\]\\\*\\\$ *\| *cut +-f +1 +-w *\| *sed +-n +'s\/\^figlet-\/\/p'/ it { expect(get_command(:get_package_version, 'figlet')). to match /if +#{cond} *; *then +#{st} *; *else +#{sf} *; *fi/ } end end context 'freebsd-9' do before do set :os, :family => 'freebsd', :release => '9' end let(:cond) do %r{TMPDIR=/dev/null +ASSUME_ALWAYS_YES=1 +PACKAGESITE=file:///nonexist +pkg +info +-x +'pkg\(-devel\)\?\$' *> */dev/null +2>&1} end describe 'get_command(:check_package_is_installed, "figlet")' do st = /pkg +info +-e +figlet/ sf = /pkg_info +-Ix +\\\^figlet-\\\[0-9\\\]\\\[0-9a-zA-Z_\.,\\\]\\\*\\\$/ it { expect(get_command(:check_package_is_installed, 'figlet')). to match /^if +#{cond} *; *then +#{st} *; *else +#{sf} *; *fi$/ } end describe 'get_command(:check_package_is_installed, "figlet", "1.2.3")' do st = /pkg +query +%v +figlet *\| *grep -- 1.2.3/ sf = /pkg_info +-I +figlet-1.2.3/ it { expect(get_command(:check_package_is_installed, 'figlet', '1.2.3')). to match /^if +#{cond} *; *then +#{st} *; *else +#{sf} *; *fi$/ } end describe 'get_command(:install_package, "figlet")' do st = /pkg +install +-y +figlet/ sf = /pkg_add +-r +figlet/ it { expect(get_command(:install_package, 'figlet')). to match /^if +#{cond} *; *then +#{st} *; *else +#{sf} *; *fi$/ } end describe 'get_command(:get_package_version, "figlet")' do st = /pkg +query +%v +figlet/ sf = /pkg_info +-Ix +\\\^figlet-\\\[0-9\\\]\\\[0-9a-zA-Z_\.,\\\]\\\*\\\$ *\| *cut +-f +1 +-w *\| *sed +-n +'s\/\^figlet-\/\/p'/ it { expect(get_command(:get_package_version, 'figlet')). to match /if +#{cond} *; *then +#{st} *; *else +#{sf} *; *fi/ } end end context 'freebsd-10' do before do set :os, :family => 'freebsd', :release => '10' end describe 'get_command(:check_package_is_installed, "figlet")' do it { expect(get_command(:check_package_is_installed, 'figlet')).to match /^pkg +info +-e +figlet$/ } end describe 'get_command(:check_package_is_installed, "figlet", "1.2.3")' do it { expect(get_command(:check_package_is_installed, 'figlet', '1.2.3')).to match /^pkg +query +%v +figlet *\| *grep -- 1.2.3$/ } end describe 'get_command(:install_package, "figlet")' do it { expect(get_command(:install_package, 'figlet')).to match /^pkg +install +-y +figlet$/ } end end context 'freebsd-11' do before do set :os, :family => 'freebsd', :release => '11' end describe 'get_command(:check_package_is_installed, "figlet")' do it { expect(get_command(:check_package_is_installed, 'figlet')).to match /^pkg +info +-e +figlet$/ } end describe 'get_command(:check_package_is_installed, "figlet", "1.2.3")' do it { expect(get_command(:check_package_is_installed, 'figlet', '1.2.3')).to match /^pkg +query +%v +figlet *\| *grep -- 1.2.3$/ } end describe 'get_command(:install_package, "figlet")' do it { expect(get_command(:install_package, 'figlet')).to match /^pkg +install +-y +figlet$/ } end end end specinfra-2.82.8/spec/command/freebsd/service_spec.rb0000644000004100000410000000406613614203316022603 0ustar www-datawww-datarequire 'spec_helper' describe 'command/freebsd/service works correctly' do before do property[:os] = nil end context 'freebsd-base' do before do set :os, :family => 'freebsd' end describe 'get_command(:check_service_is_enabled, "httpd")' do it { expect(get_command(:check_service_is_enabled, 'httpd')).to eq 'service httpd enabled' } end end context 'freebsd-6' do before do set :os, :family => 'freebsd', :release => '6' end describe 'get_command(:check_service_is_enabled, "httpd")' do it { expect(get_command(:check_service_is_enabled, 'httpd')).to eq 'service -e | grep -- /httpd$' } end end context 'freebsd-7' do before do set :os, :family => 'freebsd', :release => '7' end describe 'get_command(:check_service_is_enabled, "httpd")' do it { expect(get_command(:check_service_is_enabled, 'httpd')).to eq 'service -e | grep -- /httpd$' } end end context 'freebsd-8' do before do set :os, :family => 'freebsd', :release => '8' end describe 'get_command(:check_service_is_enabled, "httpd")' do it { expect(get_command(:check_service_is_enabled, 'httpd')).to eq 'service -e | grep -- /httpd$' } end end context 'freebsd-9' do before do set :os, :family => 'freebsd', :release => '9' end describe 'get_command(:check_service_is_enabled, "httpd")' do it { expect(get_command(:check_service_is_enabled, 'httpd')).to eq 'service -e | grep -- /httpd$' } end end context 'freebsd-10' do before do set :os, :family => 'freebsd', :release => '10' end describe 'get_command(:check_service_is_enabled, "httpd")' do it { expect(get_command(:check_service_is_enabled, 'httpd')).to eq 'service httpd enabled' } end end context 'freebsd-11' do before do set :os, :family => 'freebsd', :release => '11' end describe 'get_command(:check_service_is_enabled, "httpd")' do it { expect(get_command(:check_service_is_enabled, 'httpd')).to eq 'service httpd enabled' } end end end specinfra-2.82.8/spec/command/freebsd/host_spec.rb0000644000004100000410000000152713614203316022117 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'freebsd' describe get_command(:check_host_is_reachable, 'pink.unicorn.com', nil, 'tcp', 10) do it { should eq "ping -t 10 -c 2 -n pink.unicorn.com"} end describe get_command(:check_host_is_reachable, 'pink.unicorn.com', 53, 'udp', 66) do it { should eq "nc -vvvvzu pink.unicorn.com 53 -w 66" } end describe get_command(:get_host_ipaddress, 'pink.unicorn.com') do it { should eq "getent hosts pink.unicorn.com | awk '{print $1; exit}'" } end describe get_command(:get_host_ipv4_address, 'pink.unicorn.com') do it { should eq "getent hosts pink.unicorn.com | awk '$1 ~ /^[0-9.]+$/ {print $1}'" } end describe get_command(:get_host_ipv6_address, 'pink.unicorn.com') do it { should eq "getent hosts pink.unicorn.com | awk 'tolower($1) ~ /^[0-9a-f:]+$/ {print $1}'" } end specinfra-2.82.8/spec/command/redhat/0000755000004100000410000000000013614203316017433 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/redhat/package_spec.rb0000644000004100000410000000202713614203316022366 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, { :family => 'redhat' } describe get_command(:check_package_is_installed, 'telnet') do it { should eq 'rpm -q telnet' } end describe get_command(:check_package_is_installed, 'telnet', '0.17-48.el6.x86_64') do it { should eq 'rpm -q telnet | grep -w -- telnet\\-0\\.17\\-48\\.el6\\.x86_64' } end describe get_command(:check_package_is_installed, 'linux-headers-$(uname -r)') do it 'should be escaped (that is, command substitution should not work' do should eq 'rpm -q linux-headers-\\$\\(uname\\ -r\\)' end end describe get_command(:install_package, 'telnet') do it { should eq "yum -y install telnet" } end describe get_command(:install_package, 'telnet', '0.17-48.el6.x86_64') do it { should eq "yum -y install telnet-0.17-48.el6.x86_64" } end describe get_command(:install_package, 'linux-headers-$(uname -r)') do it 'should be escaped (that is, command substitution should no work)' do should eq "yum -y install linux-headers-\\$\\(uname\\ -r\\)" end end specinfra-2.82.8/spec/command/redhat/service_spec.rb0000644000004100000410000000121013614203316022424 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'redhat' describe get_command(:enable_service, 'httpd') do it { should eq 'chkconfig httpd on' } end describe get_command(:disable_service, 'httpd') do it { should eq 'chkconfig httpd off' } end describe get_command(:start_service, 'httpd') do it { should eq 'service httpd start' } end describe get_command(:stop_service, 'httpd') do it { should eq 'service httpd stop' } end describe get_command(:restart_service, 'httpd') do it { should eq 'service httpd restart' } end describe get_command(:reload_service, 'httpd') do it { should eq 'service httpd reload' } end specinfra-2.82.8/spec/command/amazon2/0000755000004100000410000000000013614203316017533 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/amazon2/service_spec.rb0000644000004100000410000000143013614203316022530 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'amazon', :release => '2' describe get_command(:enable_service, 'httpd') do it { should eq 'systemctl enable httpd' } end describe get_command(:disable_service, 'httpd') do it { should eq 'systemctl disable httpd' } end describe get_command(:start_service, 'httpd') do it { should eq 'systemctl start httpd' } end describe get_command(:stop_service, 'httpd') do it { should eq 'systemctl stop httpd' } end describe get_command(:restart_service, 'httpd') do it { should eq 'systemctl restart httpd' } end describe get_command(:reload_service, 'httpd') do it { should eq 'systemctl reload httpd' } end describe get_command(:enable_service, 'sshd.socket') do it { should eq 'systemctl enable sshd.socket' } end specinfra-2.82.8/spec/command/amazon2/port_spec.rb0000644000004100000410000000030713614203316022056 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'amazon', :release => '2' describe get_command(:check_port_is_listening, '80') do it { should eq 'ss -tunl | grep -E -- :80\ ' } end specinfra-2.82.8/spec/command/solaris11/0000755000004100000410000000000013614203316020002 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/solaris11/user_spec.rb0000644000004100000410000000065613614203316022326 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'solaris', :release => '11' describe get_command(:get_user_minimum_days_between_password_change, 'foo') do it { should eq "passwd -s foo | sed 's/ \\{1,\\}/%/g' | tr '%' '\n' | sed '4q;d'" } end describe get_command(:get_user_maximum_days_between_password_change, 'foo') do it { should eq "passwd -s foo | sed 's/ \\{1,\\}/%/g' | tr '%' '\n' | sed '5q;d'" } endspecinfra-2.82.8/spec/command/base/0000755000004100000410000000000013614203316017076 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/base/mail_alias_spec.rb0000644000004100000410000000110013614203316022520 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => nil } describe get_command(:check_mail_alias_is_aliased_to, 'pink', '|/pony') do it do should eq %Q{getent aliases pink | } + %Q{egrep -- \\\[\\\[:space:\\\]\\\]\\\(\\\[\\\"\\'\\\]\\?\\)\\\\\\|/pony\\\\1\\\(,\\\|\\\$\\\)} end end describe get_command(:check_mail_alias_is_aliased_to, 'pink', '|/pony, |/unicorn') do it do should eq %Q{getent aliases pink | } + %Q{egrep -- \\\[\\\[:space:\\\]\\\]\\\(\\\[\\\"\\'\\\]\\?\\)\\\\\\|/pony,\\\ \\\\\\|/unicorn\\\\1\\\(,\\\|\\\$\\\)} end end specinfra-2.82.8/spec/command/base/file_spec.rb0000644000004100000410000000707613614203316021366 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => nil } describe get_command(:check_file_is_directory, '/tmp') do it { should eq 'test -d /tmp' } end describe get_command(:check_file_is_symlink, '/tmp') do it { should eq 'test -L /tmp' } end describe get_command(:change_file_mode, '/tmp', '0644') do it { should eq 'chmod 0644 /tmp' } end describe get_command(:change_file_mode, '/tmp', '0644', :recursive => true) do it { should eq 'chmod -R 0644 /tmp' } end describe get_command(:change_file_owner, '/tmp', 'root') do it { should eq 'chown root /tmp' } end describe get_command(:change_file_owner, '/tmp', 'root', 'root') do it { should eq 'chown root:root /tmp' } end describe get_command(:change_file_owner, '/tmp', 'root', 'Domain Users') do it { should eq 'chown root:Domain\\ Users /tmp' } end describe get_command(:change_file_owner, '/tmp', 'root', 'root', :recursive => true) do it { should eq 'chown -R root:root /tmp' } end describe get_command(:change_file_group, '/tmp', 'root') do it { should eq 'chgrp root /tmp' } end describe get_command(:change_file_group, '/tmp', 'Domain Users') do it { should eq 'chgrp Domain\ Users /tmp' } end describe get_command(:change_file_group, '/tmp', 'root', :recursive => true) do it { should eq 'chgrp -R root /tmp' } end describe get_command(:create_file_as_directory, '/tmp') do it { should eq 'mkdir -p /tmp' } end describe get_command(:get_file_owner_user, '/tmp') do it { should eq 'stat -c %U /tmp' } end describe get_command(:get_file_owner_group, '/tmp') do it { should eq 'stat -c %G /tmp' } end describe get_command(:copy_file, '/src', '/dest') do it { should eq 'cp -p /src /dest' } end describe get_command(:copy_file, '/src', '/dest', :recursive => true) do it { should eq 'cp -pR /src /dest' } end describe get_command(:move_file, '/src', '/dest') do it { should eq 'mv /src /dest' } end describe get_command(:link_file_to, '/link', '/target') do it { should eq 'ln -s /target /link' } end describe get_command(:link_file_to, '/link', '/target', :force => true) do it { should eq 'ln -sf /target /link' } end describe get_command(:link_file_to, '/link', '/target', :no_dereference => true) do it { should eq 'ln -sn /target /link' } end describe get_command(:link_file_to, '/link', '/target', :force => true, :no_dereference => true) do it { should eq 'ln -sfn /target /link' } end describe get_command(:remove_file, '/tmp') do it { should eq 'rm -rf /tmp' } end describe get_command(:check_file_is_link, '/tmp') do it { should eq 'test -L /tmp' } end describe get_command(:check_file_is_pipe, '/tmp') do it { should eq 'test -p /tmp' } end describe get_command(:check_file_is_block_device, '/tmp') do it { should eq 'test -b /tmp' } end describe get_command(:check_file_is_character_device, '/tmp') do it { should eq 'test -c /tmp' } end describe get_command(:get_file_link_target, '/tmp') do it { should eq 'readlink /tmp' } end describe get_command(:get_file_link_realpath, '/tmp') do it { should eq 'readlink -e /tmp' } end describe get_command(:check_file_is_dereferenceable, '/tmp') do it { should eq 'test -n "$(readlink -e /tmp)"' } end describe get_command(:check_file_exists, '/tmp') do it { should eq 'test -e /tmp' } end describe get_command(:get_file_mtime, '/tmp') do it { should eq 'stat -c %Y /tmp' } end describe get_command(:get_file_size, '/tmp') do it { should eq 'stat -c %s /tmp' } end describe get_command(:download_file, 'http://example.com/sample_file', '/tmp/sample_file') do it { should eq 'curl -sSL http://example.com/sample_file -o /tmp/sample_file' } end specinfra-2.82.8/spec/command/base/package_spec.rb0000644000004100000410000000116613614203316022034 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => nil } describe get_command(:check_package_is_installed_by_gem, 'serverspec', '2.0.0') do it { should eq 'gem list --local | grep -iw -- \\^serverspec\\ | grep -w -- "[( ]2.0.0[,)]"' } end describe get_command(:check_package_is_installed_by_td_agent_gem, 'fluent-plugin-forest', '0.3.0') do it { should eq '/usr/sbin/td-agent-gem list --local | grep -iw -- \\^fluent-plugin-forest\\ | grep -w -- "[( ]0.3.0[,)]"' } end describe get_command(:check_package_is_installed_by_rvm, 'rbx', '2.4.1') do it { should eq 'rvm list strings | grep -iw -- \\^rbx | grep -w -- 2.4.1' } end specinfra-2.82.8/spec/command/base/process_spec.rb0000644000004100000410000000025313614203316022113 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => nil } describe get_command(:count_process, 'foo') do it { should eq 'ps aux | grep -w -- foo | grep -v grep | wc -l' } end specinfra-2.82.8/spec/command/base/group_spec.rb0000644000004100000410000000176613614203316021603 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => nil } describe get_command(:get_group_gid, 'foo') do it { should eq "getent group foo | cut -f 3 -d ':'" } end describe get_command(:update_group_gid, 'foo', 1234) do it { should eq "groupmod -g 1234 foo" } end describe get_command(:add_group, 'foo', :gid => 1234) do it { should eq 'groupadd -g 1234 foo' } end describe get_command(:add_group, 'foo', :system_group => true) do it { should eq 'groupadd -r foo' } end describe get_command(:check_group_is_system_group, 'foo') do it { should eq "getent group foo > /dev/null 2>&1 && test \"$(getent group foo | cut -f 3 -d ':')\" -ge \"$(awk 'BEGIN{sys_gid_min=101} {if($1~/^SYS_GID_MIN/){sys_gid_min=$2}} END{print sys_gid_min}' /etc/login.defs)\" && test \"$(getent group foo | cut -f 3 -d ':')\" -le \"$(awk 'BEGIN{sys_gid_max=0;gid_min=1000} {if($1~/^SYS_GID_MAX/){sys_gid_max=$2}if($1~/^GID_MIN/){gid_min=$2}} END{if(sys_gid_max!=0){print sys_gid_max}else{print gid_min-1}}' /etc/login.defs)\"" } end specinfra-2.82.8/spec/command/base/user_spec.rb0000644000004100000410000000446613614203316021425 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => nil } describe get_command(:get_user_uid, 'foo') do it { should eq 'id -u foo' } end describe get_command(:get_user_gid, 'foo') do it { should eq 'id -g foo' } end describe get_command(:get_user_home_directory, 'foo') do it { should eq "getent passwd foo | cut -f 6 -d ':'" } end describe get_command(:update_user_home_directory, 'user', 'dir') do it { should eq "usermod -d dir user" } end describe get_command(:update_user_uid, 'foo', 100) do it { should eq 'usermod -u 100 foo' } end describe get_command(:update_user_gid, 'foo', 100) do it { should eq 'usermod -g 100 foo' } end describe get_command(:add_user, 'foo', :home_directory => '/home/foo', :password => '$6$foo/bar', :shell => '/bin/tcsh', :create_home => true) do it { should eq 'useradd -d /home/foo -p \$6\$foo/bar -s /bin/tcsh -m foo' } end describe get_command(:update_user_encrypted_password, 'foo', 'xxxxxxxx') do it { should eq 'echo foo:xxxxxxxx | chpasswd -e' } end describe get_command(:get_user_encrypted_password, 'foo') do it { should eq "getent shadow foo | cut -f 2 -d ':'" } end describe get_command(:check_user_has_login_shell, 'foo', '/bin/sh') do it { should eq "getent passwd foo | cut -f 7 -d ':' | grep -w -- /bin/sh" } end describe get_command(:get_user_minimum_days_between_password_change, 'foo') do it { should eq "chage -l foo | sed -n 's/^Minimum.*: //p'" } end describe get_command(:get_user_maximum_days_between_password_change, 'foo') do it { should eq "chage -l foo | sed -n 's/^Maximum.*: //p'" } end describe get_command(:get_user_login_shell, 'foo') do it { should eq "getent passwd foo | cut -f 7 -d ':'" } end describe get_command(:update_user_login_shell, 'foo', '/bin/bash') do it { should eq 'usermod -s /bin/bash foo' } end describe get_command(:check_user_is_system_user, 'foo') do it { should eq "getent passwd foo > /dev/null 2>&1 && test \"$(getent passwd foo | cut -f 3 -d ':')\" -ge \"$(awk 'BEGIN{sys_uid_min=101} {if($1~/^SYS_UID_MIN/){sys_uid_min=$2}} END{print sys_uid_min}' /etc/login.defs)\" && test \"$(getent passwd foo | cut -f 3 -d ':')\" -le \"$(awk 'BEGIN{sys_uid_max=0;uid_min=1000} {if($1~/^SYS_UID_MAX/){sys_uid_max=$2}if($1~/^UID_MIN/){uid_min=$2}} END{if(sys_uid_max!=0){print sys_uid_max}else{print uid_min-1}}' /etc/login.defs)\"" } end specinfra-2.82.8/spec/command/base/host_spec.rb0000644000004100000410000000144213614203316021413 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => nil } describe get_command(:check_host_is_reachable, 'pink.unicorn.com', nil, 'tcp', 10) do it { should eq "ping -w 10 -c 2 -n pink.unicorn.com" } end describe get_command(:check_host_is_reachable, 'pink.unicorn.com', '53', 'udp', 2) do it { should eq "nc -w 2 -vvvvzu pink.unicorn.com 53" } end describe get_command(:get_host_ipaddress, 'pink.unicorn.com') do it { should eq "getent hosts pink.unicorn.com | awk '{print $1}'" } end describe get_command(:get_host_ipv4_address, 'pink.unicorn.com') do it { should eq "getent ahostsv4 pink.unicorn.com | awk '{print $1; exit}'" } end describe get_command(:get_host_ipv6_address, 'pink.unicorn.com') do it { should eq "getent ahostsv6 pink.unicorn.com | awk '{print $1; exit}'" } end specinfra-2.82.8/spec/command/base/localhost_spec.rb0000644000004100000410000000027313614203316022427 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => nil } describe get_command(:check_localhost_is_ec2_instance) do it { should eq 'curl --connect-timeout=1 http://169.254.169.254:80/' } end specinfra-2.82.8/spec/command/darwin/0000755000004100000410000000000013614203316017450 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/darwin/interface_spec.rb0000644000004100000410000000340213614203316022746 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'darwin' describe get_command(:check_interface_exists, 'en0') do it { should eq "ifconfig en0" } end describe get_command(:check_interface_has_ipv6_address, 'en0', '2001:0db8:bd05:01d2:288a:1fc0:0001:10ee') do it { should eq "ifconfig en0 inet6 | grep 'inet6 2001:0db8:bd05:01d2:288a:1fc0:0001:10ee '" } end describe get_command(:check_interface_has_ipv6_address, 'en0', '2001:0db8:bd05:01d2:288a:1fc0:0001:10ee/64') do it { should eq "ifconfig en0 inet6 | grep 'inet6 2001:0db8:bd05:01d2:288a:1fc0:0001:10ee prefixlen 64'" } end describe get_command(:check_interface_has_ipv6_address, 'en0', 'fe80::5054:ff:fe01:10ee/64') do it { should eq "ifconfig en0 inet6 | grep 'inet6 fe80::5054:ff:fe01:10ee%en0 prefixlen 64'" } end describe get_command(:check_interface_has_ipv6_address, 'en0', 'fe80::5054:ff:fe01:10ee') do it { should eq "ifconfig en0 inet6 | grep 'inet6 fe80::5054:ff:fe01:10ee%en0 '" } end describe get_command(:check_interface_has_ipv4_address, 'en0', '192.168.0.123') do it { should eq "ifconfig en0 inet | grep 'inet 192\\.168\\.0\\.123 '" } end describe get_command(:check_interface_has_ipv4_address, 'en0', '192.168.0.123/24') do it { should eq "ifconfig en0 inet | grep 'inet 192\\.168\\.0\\.123 '" } end describe get_command(:get_interface_ipv4_address, 'en0') do it { should eq "ifconfig en0 inet | grep inet | awk '{print $2}'" } end describe get_command(:get_interface_ipv6_address, 'en0') do it { should eq "ifconfig en0 inet6 | grep inet6 | awk '{print $2$3$4}' | sed 's/prefixlen/\//'; exit" } end describe get_command(:get_interface_link_state, 'en0') do it { should eq %Q{ifconfig -u en0 2>&1 | awk -v s=up '/status:/ && $2 != "active" { s="down" }; END {print s}'} } end specinfra-2.82.8/spec/command/darwin/file_spec.rb0000644000004100000410000000077313614203316021735 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'darwin' describe get_command(:get_file_sha256sum, '/etc/services') do it { should eq 'ruby -e "require \'digest\'; puts Digest::SHA256.hexdigest File.read \'/etc/services\'"' } end describe get_command(:check_file_is_owned_by, '/tmp', 'root') do it { should eq 'stat -f %Su /tmp | grep -- \\^root\\$' } end describe get_command(:check_file_is_grouped, '/tmp', 'wheel') do it { should eq 'stat -f %Sg /tmp | grep -- \\^wheel\\$' } end specinfra-2.82.8/spec/command/darwin/process_spec.rb0000644000004100000410000000036713614203316022473 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => 'darwin' } describe get_command(:get_process, 'Google Chrome', :format => 'pid=') do it { should eq "ps -A -c -o pid=,command | grep -E -m 1 ^\\ *[0-9]+\\ +Google\\ Chrome$ | awk '{print $1}'" } end specinfra-2.82.8/spec/command/darwin/user_spec.rb0000644000004100000410000000105313614203316021764 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => 'darwin' } describe get_command(:check_user_has_home_directory, 'foo', '/Users/foo') do it { should eq "finger foo | grep -E '^Directory' | awk '{ print $2 }' | grep -E '^/Users/foo$'" } end describe get_command(:check_user_has_login_shell, 'foo', '/bin/bash') do it { should eq "finger foo | grep -E '^Directory' | awk '{ print $4 }' | grep -E '^/bin/bash$'" } end describe get_command(:get_user_home_directory, 'foo') do it { should eq "finger foo | grep -E '^Directory' | awk '{ print $2 }'" } end specinfra-2.82.8/spec/command/darwin/host_spec.rb0000644000004100000410000000274213614203316021771 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'darwin' describe get_command(:check_host_is_resolvable, 'pink.unicorn.com', 'dns') do it { should eq "dig +search +short +time=1 -q pink.unicorn.com a pink.unicorn.com aaaa | grep -qie '^[0-9a-f:.]*$'" } end describe get_command(:check_host_is_resolvable, 'pink.unicorn.com', 'hosts') do it { should eq "sed 's/#.*$//' /etc/hosts | grep -w -- pink.unicorn.com" } end describe get_command(:check_host_is_resolvable, 'pink.unicorn.com', nil) do it { should eq "dscacheutil -q host -a name pink.unicorn.com | grep -q '_address:'" } end describe get_command(:check_host_is_reachable, 'pink.unicorn.com', nil, 'tcp', 10) do it { should eq "ping -t 10 -c 2 -n pink.unicorn.com"} end describe get_command(:check_host_is_reachable, 'pink.unicorn.com', 53, 'udp', 66) do it { should eq "nc -vvvvzu pink.unicorn.com 53 -w 66" } end describe get_command(:get_host_ipaddress, 'pink.unicorn.com') do it do should eq "dscacheutil -q host -a name pink.unicorn.com | " + "awk '/^ipv6_/{ ip = $2 }; /^$/{ exit }; /^ip_/{ ip = $2; exit}; END{ print ip }'" end end describe get_command(:get_host_ipv4_address, 'pink.unicorn.com') do it { should eq "dscacheutil -q host -a name pink.unicorn.com | awk '/^ip_/{ print $2; exit }'" } end describe get_command(:get_host_ipv6_address, 'pink.unicorn.com') do it { should eq "dscacheutil -q host -a name pink.unicorn.com | awk '/^ipv6_/{ ip = $2 } END{ print ip }'" } end specinfra-2.82.8/spec/command/darwin/port_spec.rb0000644000004100000410000000051313614203316021772 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'darwin' describe get_command(:check_port_is_listening, '80') do it { should eq 'lsof -nP -iTCP -sTCP:LISTEN | grep -- :80\ ' } end describe get_command(:check_port_is_listening, '80', :protocol => 'udp') do it { should eq 'lsof -nP -iUDP | grep -- :80\ ' } end specinfra-2.82.8/spec/command/clearlinux/0000755000004100000410000000000013614203316020332 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/clearlinux/package_spec.rb0000644000004100000410000000064113614203316023265 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, { :family => 'clearlinux' } describe get_command(:check_package_is_installed, 'vim') do it { should eq "swupd bundle-list --quiet | grep -w vim" } end describe get_command(:install_package, 'vim') do it { should eq "swupd bundle-add --quiet vim" } end describe get_command(:remove_package, 'vim') do it { should eq "swupd bundle-remove --quiet vim" } endspecinfra-2.82.8/spec/command/windows/0000755000004100000410000000000013614203316017656 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/windows/registry_key_spec.rb0000644000004100000410000000225313614203316023737 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe Specinfra::Command::Windows::Base::RegistryKey do let(:key_path) { "HKLM\\Software\\Microsoft\\Windows" } def stub_exec (command) expect(described_class).to receive(:create_command).with(command) end describe 'has_property?' do it { stub_exec "(Get-Item 'Registry::#{key_path}') -ne $null" described_class.check_exists(key_path) } end [:type_dword, :type_dword_converted].each do |reg_type| it "has_property_value #{reg_type}" do prop = {:name => 'CurrentVersion', :type => reg_type} stub_exec "(Get-Item 'Registry::#{key_path}').GetValueKind('CurrentVersion') -eq 'DWord'" described_class.check_has_property key_path, prop end end [:type_dword, :type_dword_converted].each do |reg_type| describe 'check_has_value' do it { value = reg_type == :type_dword_converted ? "23" : "17" prop = {:name => 'CurrentVersion', :type => reg_type, :value => value} cmd = "(Compare-Object (Get-Item 'Registry::#{key_path}').GetValue('CurrentVersion') 23) -eq $null" stub_exec cmd described_class.check_has_value key_path, prop } end end end specinfra-2.82.8/spec/command/windows/service_spec.rb0000644000004100000410000000321113614203316022652 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe Specinfra::Command::Windows::Base::Service do before :all do property[:os] = nil set :os, :family => 'windows' end let(:service_name) { "Power" } let(:property_map) {{"StartName"=>"Local System","State"=>"Running","StartMode"=>"Auto"}} describe "#check_service_is_running" do it "" do command = get_command(:check_service_is_running, service_name) expect(command.script).to eq("(FindService -name 'Power').State -eq 'Running'") end end describe "#check_service_is_enabled" do it "" do command = get_command(:check_service_is_enabled, service_name) expect(command.script).to eq ("(FindService -name 'Power').StartMode -eq 'Auto'") end end describe "#has_property" do it "includes (FindService -name 'Power').StartName -eq 'Local System" do command = get_command(:check_service_has_property, service_name,property_map) expect(command.script).to include ("(FindService -name 'Power').StartName -eq 'Local System'") end it "includes (FindService -name 'Power').State -eq 'Running" do command = get_command(:check_service_has_property, service_name,property_map) expect(command.script).to include ("(FindService -name 'Power').State -eq 'Running'") end it "includes (FindService -name 'Power').StartMode -eq 'Auto" do command = get_command(:check_service_has_property, service_name,property_map) expect(command.script).to include ("(FindService -name 'Power').StartMode -eq 'Auto'") end end end specinfra-2.82.8/spec/command/redhat7/0000755000004100000410000000000013614203316017522 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/redhat7/interface_spec.rb0000644000004100000410000000036713614203316023027 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, { :family => 'redhat', :release => 7 } describe Specinfra.command.send(:create_command_class, 'interface') do it { should be_an_instance_of(Specinfra::Command::Linux::Base::Interface) } end specinfra-2.82.8/spec/command/redhat7/service_spec.rb0000644000004100000410000000143013614203316022517 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'redhat', :release => '7' describe get_command(:enable_service, 'httpd') do it { should eq 'systemctl enable httpd' } end describe get_command(:disable_service, 'httpd') do it { should eq 'systemctl disable httpd' } end describe get_command(:start_service, 'httpd') do it { should eq 'systemctl start httpd' } end describe get_command(:stop_service, 'httpd') do it { should eq 'systemctl stop httpd' } end describe get_command(:restart_service, 'httpd') do it { should eq 'systemctl restart httpd' } end describe get_command(:reload_service, 'httpd') do it { should eq 'systemctl reload httpd' } end describe get_command(:enable_service, 'sshd.socket') do it { should eq 'systemctl enable sshd.socket' } end specinfra-2.82.8/spec/command/redhat7/host_spec.rb0000644000004100000410000000155313614203316022042 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'redhat', :release => '7' describe get_command(:check_host_is_reachable, 'example.jp', '53', 'udp', 2) do it { should eq "ncat -vvvvu example.jp 53 -w 2 -i 2 2>&1 | grep -q SUCCESS" } end describe get_command(:check_host_is_reachable, 'example.jp', '80', 'tcp', 3) do it { should eq "ncat -vvvvt example.jp 80 -w 3 -i 3 2>&1 | grep -q SUCCESS" } end describe get_command(:get_host_ipaddress, 'pink.unicorn.com') do it { should eq "getent hosts pink.unicorn.com | awk '{print $1}'" } end describe get_command(:get_host_ipv4_address, 'pink.unicorn.com') do it { should eq "getent ahostsv4 pink.unicorn.com | awk '{print $1; exit}'" } end describe get_command(:get_host_ipv6_address, 'pink.unicorn.com') do it { should eq "getent ahostsv6 pink.unicorn.com | awk '{print $1; exit}'" } end specinfra-2.82.8/spec/command/redhat7/port_spec.rb0000644000004100000410000000030713614203316022045 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'redhat', :release => '7' describe get_command(:check_port_is_listening, '80') do it { should eq 'ss -tunl | grep -E -- :80\ ' } end specinfra-2.82.8/spec/command/redhat8/0000755000004100000410000000000013614203316017523 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/redhat8/yumrepo_spec.rb0000644000004100000410000000056213614203316022565 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'redhat', :release => '8' describe get_command(:check_yumrepo_exists, 'epel') do it { should eq "dnf repolist all | grep -qsE \"^[\\!\\*]?epel\(\\s\|$\|\\/)\"" } end describe get_command(:check_yumrepo_is_enabled, 'epel') do it { should eq "dnf repolist enabled | grep -qs \"^[\\!\\*]\\?epel\"" } end specinfra-2.82.8/spec/command/redhat8/selinux_spec.rb0000644000004100000410000000052713614203316022555 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'redhat', :release => '8' describe get_command(:check_selinux_module_is_installed, 'dnsmasq') do it { should eq "semodule -l | grep $'^dnsmasq'" } end describe get_command(:check_selinux_module_is_enabled, 'dnsmasq') do it { should eq "semodule -l | grep $'^dnsmasq'" } end specinfra-2.82.8/spec/command/sles11/0000755000004100000410000000000013614203316017274 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/sles11/user_spec.rb0000644000004100000410000000065613614203316021620 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'sles', :release => '11' describe get_command(:get_user_minimum_days_between_password_change, 'foo') do it { should eq "chage -l foo | sed -n 's/^Minimum://p' | sed 's|^[[:blank:]]*||g'" } end describe get_command(:get_user_maximum_days_between_password_change, 'foo') do it { should eq "chage -l foo | sed -n 's/^Maximum://p' | sed 's|^[[:blank:]]*||g'" } end specinfra-2.82.8/spec/command/cumulus/0000755000004100000410000000000013614203316017661 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/cumulus/ppa_cumuluslinux_spec.rb0000644000004100000410000000036113614203316024635 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'cumuluslinux' describe get_command(:check_ppa_exists, 'git') do it { should eq 'find /etc/apt/ -name *.list | xargs grep -o "deb +http://repo.cumulusnetworks.com/git"' } end specinfra-2.82.8/spec/command/cumulus/ppa_cumulusnetworks_spec.rb0000644000004100000410000000036413614203316025355 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'cumulusnetworks' describe get_command(:check_ppa_exists, 'git') do it { should eq 'find /etc/apt/ -name *.list | xargs grep -o "deb +http://repo.cumulusnetworks.com/git"' } end specinfra-2.82.8/spec/command/alpine/0000755000004100000410000000000013614203316017434 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/alpine/service_spec.rb0000644000004100000410000000106113614203316022431 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'alpine' describe get_command(:enable_service, 'nginx') do it { should eq 'rc-update add nginx' } end describe get_command(:disable_service, 'nginx') do it { should eq 'rc-update del nginx' } end describe get_command(:start_service, 'nginx') do it { should eq 'rc-service nginx start' } end describe get_command(:stop_service, 'nginx') do it { should eq 'rc-service nginx stop' } end describe get_command(:restart_service, 'nginx') do it { should eq 'rc-service nginx restart' } end specinfra-2.82.8/spec/command/openbsd/0000755000004100000410000000000013614203316017616 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/openbsd/mail_alias_spec.rb0000644000004100000410000000117513614203316023254 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => 'openbsd' } describe get_command(:check_mail_alias_is_aliased_to, 'pink', '|/pony') do it do should eq %Q{egrep ^pink:.*\\(\\[\\[:space:\\]\\]\\|,\\)\\[\\\"\\'\\]\\?} + %Q{\\\\\\|/pony\\[\\\"\\'\\]\\?\\(,\\|\\$\\) } + %Q{/etc/mail/aliases} end end describe get_command(:check_mail_alias_is_aliased_to, 'pink', '|/pony, |/unicorn') do it do should eq %Q{egrep ^pink:.*\\(\\[\\[:space:\\]\\]\\|,\\)\\[\\\"\\'\\]\\?} + %Q{\\\\\\|/pony,\\\\\\ \\\\\\|/unicorn\\[\\\"\\'\\]\\?\\(,\\|\\$\\) } + %Q{/etc/mail/aliases} end end specinfra-2.82.8/spec/command/openbsd/interface_spec.rb0000644000004100000410000000364113614203316023121 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'openbsd' describe get_command(:get_interface_speed_of, 'vio0') do it { should eq "ifconfig vio0 | grep 'media\:' | perl -pe 's|.*media\:.*\\((.*?)\\)|\\1|'" } end describe get_command(:check_interface_has_ipv6_address, 'vio0', '2001:0db8:bd05:01d2:288a:1fc0:0001:10ee') do it { should eq "ifconfig vio0 inet6 | grep 'inet6 2001:0db8:bd05:01d2:288a:1fc0:0001:10ee '" } end describe get_command(:check_interface_has_ipv6_address, 'vio0', '2001:0db8:bd05:01d2:288a:1fc0:0001:10ee/64') do it { should eq "ifconfig vio0 inet6 | grep 'inet6 2001:0db8:bd05:01d2:288a:1fc0:0001:10ee prefixlen 64'" } end describe get_command(:check_interface_has_ipv6_address, 'vio0', 'fe80::5054:ff:fe01:10ee/64') do it { should eq "ifconfig vio0 inet6 | grep 'inet6 fe80::5054:ff:fe01:10ee%vio0 prefixlen 64'" } end describe get_command(:check_interface_has_ipv6_address, 'vio0', 'fe80::5054:ff:fe01:10ee') do it { should eq "ifconfig vio0 inet6 | grep 'inet6 fe80::5054:ff:fe01:10ee%vio0 '" } end describe get_command(:check_interface_has_ipv4_address, 'vio0', '192.168.0.123') do it { should eq "ifconfig vio0 inet | grep 'inet 192\\.168\\.0\\.123 '" } end describe get_command(:check_interface_has_ipv4_address, 'vio0', '192.168.0.123/24') do it { should eq "ifconfig vio0 inet | grep 'inet 192\\.168\\.0\\.123 '" } end describe get_command(:get_interface_ipv4_address, 'vio0') do it { should eq "ifconfig vio0 inet | grep inet | awk '{print $2}'" } end describe get_command(:get_interface_ipv6_address, 'vio0') do it { should eq "ifconfig vio0 inet6 | grep inet6 | awk '{print $2$3$4}' | sed 's/prefixlen/\//'; exit" } end describe get_command(:get_interface_link_state, 'vio0') do it do should eq %Q{ifconfig vio0 2>&1 | awk -v s=down -F '[:<>,]' } + %Q{'NR == 1 && $3 == "UP" { s="up" }; /status:/ && $2 != " active" { s="down" }; END{ print s }'} end end specinfra-2.82.8/spec/command/openbsd/file_spec.rb0000644000004100000410000000037613614203316022102 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'openbsd' describe get_command(:get_file_mtime, '/tmp') do it { should eq 'stat -f %m /tmp' } end describe get_command(:get_file_size, '/tmp') do it { should eq 'stat -f %z /tmp' } end specinfra-2.82.8/spec/command/openbsd/service_spec.rb0000644000004100000410000000044213614203316022615 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'openbsd' describe get_command(:check_service_is_enabled, 'httpd') do it { should eq '/etc/rc.d/httpd status' } end describe get_command(:check_service_is_running, 'httpd') do it { should eq '/etc/rc.d/httpd check' } end specinfra-2.82.8/spec/command/openbsd/host_spec.rb0000644000004100000410000000152713614203316022137 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'openbsd' describe get_command(:check_host_is_reachable, 'pink.unicorn.com', nil, 'tcp', 10) do it { should eq "ping -w 10 -c 2 -n pink.unicorn.com"} end describe get_command(:check_host_is_reachable, 'pink.unicorn.com', 53, 'udp', 66) do it { should eq "nc -w 66 -vvvvzu pink.unicorn.com 53" } end describe get_command(:get_host_ipaddress, 'pink.unicorn.com') do it { should eq "getent hosts pink.unicorn.com | awk '{print $1; exit}'" } end describe get_command(:get_host_ipv4_address, 'pink.unicorn.com') do it { should eq "getent hosts pink.unicorn.com | awk '$1 ~ /^[0-9.]+$/ {print $1}'" } end describe get_command(:get_host_ipv6_address, 'pink.unicorn.com') do it { should eq "getent hosts pink.unicorn.com | awk 'tolower($1) ~ /^[0-9a-f:]+$/ {print $1}'" } end specinfra-2.82.8/spec/command/openbsd/port_spec.rb0000644000004100000410000000100213614203316022132 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'openbsd' describe get_command(:check_port_is_listening, '80') do it { should eq "netstat -nat -f inet | egrep '((tcp|udp).*.80.*LISTEN$)'" } end describe get_command(:check_port_is_listening, '22', :protocol => 'tcp') do it { should eq "netstat -nat -f inet | egrep '(tcp.*.22.*LISTEN$)'" } end describe get_command(:check_port_is_listening, '514', :protocol => 'udp') do it { should eq "netstat -nat -f inet | egrep '(udp.*.514.*$)'" } end specinfra-2.82.8/spec/command/amazon/0000755000004100000410000000000013614203316017451 5ustar www-datawww-dataspecinfra-2.82.8/spec/command/amazon/interface_spec.rb0000644000004100000410000000037113614203316022751 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, { :family => 'amazon', :release => nil } describe Specinfra.command.send(:create_command_class, 'interface') do it { should be_an_instance_of(Specinfra::Command::Linux::Base::Interface) } end specinfra-2.82.8/spec/command/amazon/package_spec.rb0000644000004100000410000000023613614203316022404 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => 'amazon' } describe get_command(:check_package_is_installed, 'httpd') do it { should eq 'rpm -q httpd' } end specinfra-2.82.8/spec/command/amazon/service_spec.rb0000644000004100000410000000121013614203316022442 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'amazon' describe get_command(:enable_service, 'httpd') do it { should eq 'chkconfig httpd on' } end describe get_command(:disable_service, 'httpd') do it { should eq 'chkconfig httpd off' } end describe get_command(:start_service, 'httpd') do it { should eq 'service httpd start' } end describe get_command(:stop_service, 'httpd') do it { should eq 'service httpd stop' } end describe get_command(:restart_service, 'httpd') do it { should eq 'service httpd restart' } end describe get_command(:reload_service, 'httpd') do it { should eq 'service httpd reload' } end specinfra-2.82.8/spec/processor_spec.rb0000644000004100000410000000541213614203316020126 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Processor do describe 'check_file_is_mounted' do let(:path) { '/proc' } let(:cmd) { Specinfra.command.get(:check_file_is_mounted, path) } def mock_output(stdout) Specinfra::CommandResult.new :stdout => stdout end context 'freebsd' do before do allow(Specinfra.backend).to receive(:run_command).with(cmd) { mock_output 'procfs on /proc (procfs, local)' } end it 'true when fs type matches' do expect(Specinfra::Processor.check_file_is_mounted(path, {:type => 'procfs'}, false)).to eq(true) end it 'false when fs type is different' do expect(Specinfra::Processor.check_file_is_mounted(path, {:type => 'ufs'}, false)).to eq(false) end it 'true when option matches' do expect(Specinfra::Processor.check_file_is_mounted(path, {:local => true}, false)).to eq(true) end it 'false when option is different' do expect(Specinfra::Processor.check_file_is_mounted(path, {:async => true}, false)).to eq(false) end context 'only_with' do it 'false when extra options present' do expect(Specinfra::Processor.check_file_is_mounted(path, {:local => true, :async => true}, true)).to eq(false) end it 'true when all options met' do expect(Specinfra::Processor.check_file_is_mounted(path, {:device => "procfs", :type => "procfs", :local => true}, true)).to eq(true) end end end context 'linux' do before do allow(Specinfra.backend).to receive(:run_command).with(cmd) { mock_output 'proc on /proc type proc (rw,noexec,nosuid,nodev)' } end it 'true when fs type matches' do expect(Specinfra::Processor.check_file_is_mounted(path, {:type => 'proc'}, false)).to eq(true) end it 'false when fs type is different' do expect(Specinfra::Processor.check_file_is_mounted(path, {:type => 'ufs'}, false)).to eq(false) end it 'true when option matches' do expect(Specinfra::Processor.check_file_is_mounted(path, {:noexec => true, :nosuid => true}, false)).to eq(true) end it 'false when option is different' do expect(Specinfra::Processor.check_file_is_mounted(path, {:noexec => true, :unknown => true}, false)).to eq(false) end context 'only_with' do it 'false when extra options present' do expect(Specinfra::Processor.check_file_is_mounted(path, {:noexec => true, :nosuid => true}, true)).to eq(false) end it 'true when all options are same' do expect(Specinfra::Processor.check_file_is_mounted(path, {:noexec => true, :nosuid => true, :nodev => true, :rw => true, :device => "proc", :type => "proc"}, true)).to eq(true) end end end end end specinfra-2.82.8/spec/configuration_spec.rb0000644000004100000410000000105613614203316020756 0ustar www-datawww-datarequire 'spec_helper' describe 'RSpec.configuration.path' do before do RSpec.configure do |c| c.path = 'foo' end end after do RSpec.configure do |c| c.path = nil end end subject { RSpec.configuration.path } it { should eq Specinfra.configuration.path } end Specinfra.configuration.os = 'foo' describe Specinfra.configuration.os do it { should eq 'foo' } end Specinfra.configuration.instance_variable_set(:@os, nil) RSpec.configuration.os = nil describe Specinfra.configuration.os do it { should be_nil } end specinfra-2.82.8/spec/backend/0000755000004100000410000000000013614203316016135 5ustar www-datawww-dataspecinfra-2.82.8/spec/backend/exec/0000755000004100000410000000000013614203316017061 5ustar www-datawww-dataspecinfra-2.82.8/spec/backend/exec/child_process_spec.rb0000644000004100000410000000127713614203316023250 0ustar www-datawww-data# Ref: https://github.com/sorah/infra_operator/blob/6259aada3fdd9d4bed5759115d39bd1df25a81f2/spec/backends/exec_spec.rb#L36 require 'spec_helper' context "when executed process launches child process like a daemon, and the daemon doesn't close stdout,err" do before :all do set :backend, :exec end subject(:result) { Specinfra::Runner.run_command("ruby -e 'pid = fork { sleep 10; puts :bye }; Process.detach(pid); puts pid'") } it "doesn't block" do a = Time.now result # exec b = Time.now expect((b-a) < 3).to be_truthy expect(result.stderr).to be_empty expect(result.stdout.chomp).to match(/\A\d+\z/) Process.kill :TERM, result.stdout.chomp.to_i end end specinfra-2.82.8/spec/backend/exec/stdxxx_handler_spec.rb0000644000004100000410000000077513614203316023470 0ustar www-datawww-datarequire 'spec_helper' backend = Specinfra::Backend::Exec.new context 'Output of stdout_handler' do subject(:stdout) do out = '' backend.stdout_handler = Proc.new {|o| out += o } backend.run_command('echo foo') out end it { expect(stdout).to eq "foo\n" } end context 'Output of stderr_handler' do subject(:stderr) do err = '' backend.stderr_handler = Proc.new {|e| err += e } backend.run_command('echo foo 1>&2') err end it { expect(stderr).to eq "foo\n" } end specinfra-2.82.8/spec/backend/exec/consume_exited_process_spec.rb0000644000004100000410000000264313614203316025176 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe 'exec backend' do before :all do set :backend, :exec end context 'when executed process had exited before read stdout and stderr,' do let(:backend) { Specinfra::Backend::Exec.new } it 'can consume stdout and stderr from buffer' do allow(IO).to receive(:select).and_wrap_original { |m, *args| sleep 1; m.call(*args) } result = backend.run_command("ruby -e 'STDOUT.puts \"stdout\"; STDERR.puts \"stderr\"'") expect(result.stdout.chomp).to eq('stdout') expect(result.stderr.chomp).to eq('stderr') end end context 'when executed process has exited between reading stdout and stderr,' do let(:backend) { Specinfra::Backend::Exec.new } it 'can consume stdout and stderr from buffer' do backend.stdout_handler = proc { |o| sleep 1 } result = backend.run_command("ruby -e 'STDOUT.puts \"stdout\"; STDOUT.close; STDERR.puts \"stderr\"'") expect(result.stdout.chomp).to eq('stdout') expect(result.stderr.chomp).to eq('stderr') end end context 'Output of stderr_handler' do let(:backend) { Specinfra::Backend::Exec.new } subject(:stderr) do allow(IO).to receive(:select).and_wrap_original { |m, *args| sleep 1; m.call(*args) } err = '' backend.stderr_handler = proc { |e| err += e } backend.run_command('echo foo 1>&2') err end it { expect(stderr).to eq "foo\n" } end end specinfra-2.82.8/spec/backend/exec/build_command_spec.rb0000644000004100000410000001473213614203316023224 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Backend::Exec do before :all do set :backend, :exec end describe '#build_command' do context 'with simple command' do it 'should escape spaces' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -c test\ -f\ /etc/passwd' end end context 'with complex command' do it 'should escape special chars' do expect(Specinfra.backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq '/bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)' end it 'should escape quotes' do if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7') expect(Specinfra.backend.build_command(%Q{find /etc/apt/ -name \*.list | xargs grep -o -E "^deb +[\\"']?http://ppa.launchpad.net/gluster/glusterfs-3.7"})).to eq('/bin/sh -c find\ /etc/apt/\ -name\ \*.list\ \|\ xargs\ grep\ -o\ -E\ \"\^deb\ \+\[\\\\\"\\\'\]\?http://ppa.launchpad.net/gluster/glusterfs-3.7\"') else # Since Ruby 2.7, `+` is not escaped. expect(Specinfra.backend.build_command(%Q{find /etc/apt/ -name \*.list | xargs grep -o -E "^deb +[\\"']?http://ppa.launchpad.net/gluster/glusterfs-3.7"})).to eq('/bin/sh -c find\ /etc/apt/\ -name\ \*.list\ \|\ xargs\ grep\ -o\ -E\ \"\^deb\ +\[\\\\\"\\\'\]\?http://ppa.launchpad.net/gluster/glusterfs-3.7\"') end end end context 'with custom shell' do before do RSpec.configure {|c| c.shell = '/usr/local/bin/tcsh' } end after do RSpec.configure {|c| c.shell = nil } end it 'should use custom shell' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/usr/local/bin/tcsh -c test\ -f\ /etc/passwd' end end context 'with custom shell that needs escaping' do before do RSpec.configure {|c| c.shell = '/usr/test & spec/bin/sh' } end after do RSpec.configure {|c| c.shell = nil } end it 'should use custom shell' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/usr/test\ \&\ spec/bin/sh -c test\ -f\ /etc/passwd' end end context 'with an interactive shell' do before do RSpec.configure {|c| c.interactive_shell = true } end after do RSpec.configure {|c| c.interactive_shell = nil } end it 'should emulate an interactive shell' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -i -c test\ -f\ /etc/passwd' end end context 'with an login shell' do before do RSpec.configure {|c| c.login_shell = true } end after do RSpec.configure {|c| c.login_shell = nil } end it 'should emulate an login shell' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -l -c test\ -f\ /etc/passwd' end end context 'with custom path' do before do RSpec.configure {|c| c.path = '/opt/bin:/opt/foo/bin:$PATH' } end after do RSpec.configure {|c| c.path = nil } end it 'should use custom path' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq 'env PATH="/opt/bin:/opt/foo/bin:$PATH" /bin/sh -c test\ -f\ /etc/passwd' end end context 'with custom path that needs escaping' do before do RSpec.configure {|c| c.path = '/opt/bin:/opt/test & spec/bin:$PATH' } end after do RSpec.configure {|c| c.path = nil } end it 'should use custom path' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq 'env PATH="/opt/bin:/opt/test & spec/bin:$PATH" /bin/sh -c test\ -f\ /etc/passwd' end end end end describe 'os' do before do # clear os information cache property[:os] = nil Specinfra.configuration.instance_variable_set(:@os, nil) Specinfra.backend.instance_variable_set(:@os_info, nil) end context 'test ubuntu with lsb_release command' do before do allow(Specinfra.backend).to receive(:run_command) do |args| if ['cat /etc/debian_version', 'lsb_release -ir'].include? args double( :run_command_response, :success? => true, :stdout => "Distributor ID:\tUbuntu\nRelease:\t12.04\n" ) elsif args == 'uname -m' double :run_command_response, :success? => true, :stdout => "x86_64\n" else double :run_command_response, :success? => false, :stdout => nil end end end subject! { os } it do expect(Specinfra.backend).to have_received(:run_command).at_least(1).times should eq({:family => 'ubuntu', :release => '12.04', :arch => 'x86_64' }) end end context 'test ubuntu with /etc/lsb-release' do before do allow(Specinfra.backend).to receive(:run_command) do |args| if ['cat /etc/debian_version', 'cat /etc/lsb-release'].include? args double( :run_command_response, :success? => true, :stdout => <<-EOF DISTRIB_ID=Ubuntu DISTRIB_RELEASE=12.04 DISTRIB_CODENAME=precise DISTRIB_DESCRIPTION="Ubuntu 12.04.2 LTS" EOF ) elsif args == 'uname -m' double :run_command_response, :success? => true, :stdout => "x86_64\n" else double :run_command_response, :success? => false, :stdout => nil end end end subject! { os } it do expect(Specinfra.backend).to have_received(:run_command).at_least(1).times should eq({:family => 'ubuntu', :release => '12.04', :arch => 'x86_64' }) end end context 'test debian (no lsb_release or lsb-release)' do before do allow(Specinfra.backend).to receive(:run_command) do |args| if args == 'cat /etc/debian_version' double :run_command_response, :success? => true, :stdout => "8.5\n" elsif args == 'uname -m' double :run_command_response, :success? => true, :stdout => "x86_64\n" else double :run_command_response, :success? => false, :stdout => nil end end end subject! { os } it do expect(Specinfra.backend).to have_received(:run_command).at_least(1).times should eq({:family => 'debian', :release => '8.5', :arch => 'x86_64' }) end end end specinfra-2.82.8/spec/backend/exec/env_spec.rb0000644000004100000410000000063713614203316021216 0ustar www-datawww-datarequire 'spec_helper' set :backend, :exec describe Specinfra.backend.run_command('echo $LANG').stdout.strip do it { should eq 'C' } end describe do before do set :backend, :exec ENV['LANG'] = 'C' set :env, :LANG => 'ja_JP.UTF-8' end let(:lang) { Specinfra.backend.run_command('echo $LANG').stdout.strip } it { expect(lang).to eq 'ja_JP.UTF-8' } it { expect(ENV['LANG']).to eq 'C' } end specinfra-2.82.8/spec/backend/exec/read_noblock_spec.rb0000644000004100000410000000247213614203316023047 0ustar www-datawww-datarequire 'spec_helper' def command(cmd) Specinfra::Runner.run_command(cmd) end shared_examples "IO checks" do let (:generator) { "seq 1 #{max}" } let (:expected) { (1..max).map { |x| x.to_s }.join("\n") << "\n" } it "stdout only" do out = command(generator).stdout expect(out).to eq expected end it "stderr only" do out = command("#{generator} >&2" ).stderr expect(out).to eq expected end it "stdout then stderr" do cmd = command("#{generator}; #{generator} >&2" ) expect(cmd.stdout).to eq expected expect(cmd.stderr).to eq expected end it "stderr then stdout" do cmd = command("#{generator} >&2; #{generator}" ) expect(cmd.stdout).to eq expected expect(cmd.stderr).to eq expected end it "stdout and stderr" do cmd = command("(#{generator} &); #{generator} >&2; sleep 2" ) expect(cmd.stdout).to eq expected expect(cmd.stderr).to eq expected end end describe "buffer overflow problem" do before :all do set :backend, :exec end context "with small output amount" do let (:max) { 10 } include_examples "IO checks" end context "with huge output amount" do let (:max) { 999999 } include_examples "IO checks" end end specinfra-2.82.8/spec/backend/ssh/0000755000004100000410000000000013614203316016732 5ustar www-datawww-dataspecinfra-2.82.8/spec/backend/ssh/build_command_spec.rb0000644000004100000410000001170013614203316023065 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Backend::Ssh do before(:all) do set :backend, :ssh end after(:all) do if Specinfra.configuration.instance_variable_defined?(:@ssh_options) Specinfra.configuration.instance_variable_set(:@ssh_options, nil) end end describe '#build_command' do context 'with root user' do before do RSpec.configure do |c| set :ssh_options, :user => 'root' c.ssh = double(:ssh, Specinfra.configuration.ssh_options) end end after do RSpec.configure do |c| c.ssh = nil end end it 'should not prepend sudo' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -c test\ -f\ /etc/passwd' end it 'should escape special characters' do expect(Specinfra.backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq '/bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)' end end context 'with non-root user' do before do RSpec.configure do |c| set :ssh_options, :user => 'foo' c.ssh = double(:ssh, Specinfra.configuration.ssh_options) end end after do RSpec.configure do |c| c.ssh = nil end end it 'should prepend sudo' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq %q{sudo -p 'Password: ' /bin/sh -c test\ -f\ /etc/passwd} end it 'should escape special characters' do expect(Specinfra.backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq %q{sudo -p 'Password: ' /bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)} end end context 'with custom sudo path' do before do RSpec.configure do |c| set :ssh_options, :user => 'foo' c.ssh = double(:ssh, Specinfra.configuration.ssh_options) c.sudo_path = '/usr/local/bin' end end after do RSpec.configure do |c| c.ssh = nil c.sudo_path = nil end end it 'command pattern 1a' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq %q{/usr/local/bin/sudo -p 'Password: ' /bin/sh -c test\ -f\ /etc/passwd} end it 'command pattern 2a' do expect(Specinfra.backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq %q{/usr/local/bin/sudo -p 'Password: ' /bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)} end end context 'without sudo' do before do RSpec.configure do |c| set :ssh_options, :user => 'foo' c.ssh = double(:ssh, Specinfra.configuration.ssh_options) c.disable_sudo = true end end after do RSpec.configure do |c| c.ssh = nil c.disable_sudo = false end end it 'command pattern 1b' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -c test\ -f\ /etc/passwd' end it 'command pattern 2b' do expect(Specinfra.backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq '/bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)' end end context 'with sudo on alternative path' do before do RSpec.configure do |c| set :ssh_options, :user => 'foo' c.ssh = double(:ssh, Specinfra.configuration.ssh_options) c.sudo_path = nil end end after do RSpec.configure do |c| c.ssh = nil c.sudo_options = nil end end context 'command pattern 1a' do subject { Specinfra.backend.build_command('test -f /etc/passwd') } it { should eq %q{sudo -p 'Password: ' /bin/sh -c test\ -f\ /etc/passwd} } end context 'command pattern 2a' do subject { Specinfra.backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)') } it { should eq %q{sudo -p 'Password: ' /bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)} } end end end end specinfra-2.82.8/spec/host_inventory/0000755000004100000410000000000013614203316017640 5ustar www-datawww-dataspecinfra-2.82.8/spec/host_inventory/linux/0000755000004100000410000000000013614203316020777 5ustar www-datawww-dataspecinfra-2.82.8/spec/host_inventory/linux/cpu_spec.rb0000644000004100000410000000573413614203316023136 0ustar www-datawww-datarequire 'spec_helper' str = <<-EOH processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 60 model name : Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz stepping : 3 microcode : 0x19 cpu MHz : 3132.076 cache size : 6144 KB physical id : 0 siblings : 2 core id : 0 cpu cores : 2 apicid : 0 initial apicid : 0 fpu : yes fpu_exception : yes cpuid level : 5 wp : yes flags : fpu vme de pse bogomips : 6264.15 clflush size : 64 cache_alignment : 64 address sizes : 39 bits physical, 48 bits virtual power management: processor : 1 vendor_id : GenuineIntel cpu family : 6 model : 60 model name : Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz stepping : 3 microcode : 0x19 cpu MHz : 3132.076 cache size : 6144 KB physical id : 0 siblings : 2 core id : 1 cpu cores : 2 apicid : 1 initial apicid : 1 fpu : yes fpu_exception : yes cpuid level : 5 wp : yes flags : fpu vme de bogomips : 6264.15 clflush size : 64 cache_alignment : 64 address sizes : 39 bits physical, 48 bits virtual power management: EOH describe Specinfra::HostInventory::Cpu do let(:host_inventory) { nil } describe 'Example of Ubuntu 14.04.1 LTS Kernel version 3.13.11' do ret = Specinfra::HostInventory::Cpu.new(host_inventory).parse(str) example do expect(ret["0"]).to include( "vendor_id" => "GenuineIntel", "cpu_family" => "6", "model" => "60", "model_name" => "Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz", "stepping" => "3", "microcode" => "0x19", "cpu_mhz" => "3132.076", "cache_size" => "6144KB", "physical_id" => "0", "siblings" => "2", "core_id" => "0", "cpu_cores" => "2", "apicid" => "0", "initial_apicid" => "0", "fpu" => "yes", "fpu_exception" => "yes", "cpuid_level" => "5", "wp" => "yes", "flags" => ["fpu", "vme", "de", "pse"], "bogomips" => "6264.15", "clflush_size" => "64", "cache_alignment" => "64", "address_sizes" => "39 bits physical, 48 bits virtual", "power_management" => "" ) end example do expect(ret["1"]).to include( "vendor_id" => "GenuineIntel", "cpu_family" => "6", "model" => "60", "model_name" => "Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz", "stepping" => "3", "microcode" => "0x19", "cpu_mhz" => "3132.076", "cache_size" => "6144KB", "physical_id" => "0", "siblings" => "2", "core_id" => "1", "cpu_cores" => "2", "apicid" => "1", "initial_apicid" => "1", "fpu" => "yes", "fpu_exception" => "yes", "cpuid_level" => "5", "wp" => "yes", "flags" => ["fpu", "vme", "de"], "bogomips" => "6264.15", "clflush_size" => "64", "cache_alignment" => "64", "address_sizes" => "39 bits physical, 48 bits virtual", "power_management" => "" ) end example do expect(ret["total"]).to eq "2" end end end specinfra-2.82.8/spec/host_inventory/linux/filesystem_spec.rb0000644000004100000410000000346013614203316024525 0ustar www-datawww-datarequire 'spec_helper' ## Output from 'df -P' str = <<-EOH Filesystem 1024-blocks Used Available Capacity Mounted on /dev/mapper/vg_idefix-lv_root 51475068 8840540 40013088 19% / tmpfs 509696 872 508824 1% /dev/shm /dev/sdb3 487652 124828 337224 28% /boot /dev/mapper/vg_idefix-lv_home 20857444 17905852 1885404 91% /home EOH describe Specinfra::HostInventory::Filesystem do let(:host_inventory) { nil } describe 'Example of CentOS 6.6 Kernel version 2.6.32-504.23.4.el6.i686' do ret = Specinfra::HostInventory::Filesystem.new(host_inventory).parse(str) example "/dev/mapper/vg_idefix-lv_home" do expect(ret["/dev/mapper/vg_idefix-lv_home"]).to include( "kb_used" => "17905852", "kb_size" => "20857444", "kb_available" => "1885404", "mount" => "/home", "percent_used" => "91%" ) end example "/dev/mapper/vg_idefix-lv_root" do expect(ret["/dev/mapper/vg_idefix-lv_root"]).to include( "kb_used" => "8840540", "kb_size" => "51475068", "kb_available" => "40013088", "mount" => "/", "percent_used" => "19%" ) end example "/dev/sdb3" do expect(ret["/dev/sdb3"]).to include( "kb_used" => "124828", "kb_size" => "487652", "kb_available" => "337224", "mount" => "/boot", "percent_used" => "28%" ) end example "tmpfs" do expect(ret["tmpfs"]).to include( "kb_used" => "872", "kb_size" => "509696", "kb_available" => "508824", "mount" => "/dev/shm", "percent_used" => "1%" ) end end end specinfra-2.82.8/spec/host_inventory/linux/block_device_spec.rb0000644000004100000410000000245013614203316024750 0ustar www-datawww-datarequire 'spec_helper' ## Output from: # # for f in $(ls /sys/block/*/{size,removable,device/{model,rev,state,timeout,vendor},queue/rotational}); do # echo -e "${f}\t$(cat ${f})" # done str = <<-EOH /sys/block/loop0/queue/rotational 1 /sys/block/loop0/removable 0 /sys/block/loop0/size 0 /sys/block/sda/device/model HARDDISK /sys/block/sda/device/rev 1.0 /sys/block/sda/device/state running /sys/block/sda/device/timeout 30 /sys/block/sda/device/vendor ATA /sys/block/sda/queue/rotational 1 /sys/block/sda/removable 0 /sys/block/sda/size 40960000 EOH describe Specinfra::HostInventory::BlockDevice do let(:host_inventory) { nil } describe 'Example of CentOS 6.6 Kernel version 2.6.32-504.23.4.el6.i686' do ret = Specinfra::HostInventory::BlockDevice.new(host_inventory).parse(str) example "/sys/block/loop0" do expect(ret["loop0"]).to include( "rotational" => "1", "removable" => "0", "size" => "0" ) end example "/sys/block/sda" do expect(ret["sda"]).to include( "model" => "HARDDISK", "rev" => "1.0", "state" => "running", "timeout" => "30", "vendor" => "ATA", "rotational" => "1", "removable" => "0", "size" => "40960000" ) end end end specinfra-2.82.8/spec/host_inventory/linux/virtualization_spec.rb0000644000004100000410000000320213614203316025417 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::HostInventory::Virtualization do before :all do set :os, { :family => 'linux' } end virt = Specinfra::HostInventory::Virtualization.new(host_inventory) let(:host_inventory) { nil } it 'Docker Image should return :system => "docker"' do allow(virt.backend).to receive(:run_command).with('grep -Eqa \'docker(/|-[0-9a-f]+)\' /proc/1/cgroup||test -e /.dockerinit') do CommandResult.new(:stdout => '', :exit_status => 0) end expect(virt.get).to include(:system => 'docker') end let(:host_inventory) { nil } it 'Debian Wheezy on OpenVZ should return :system => "openvz"' do allow(virt.backend).to receive(:run_command).with('grep -Eqa \'docker(/|-[0-9a-f]+)\' /proc/1/cgroup||test -e /.dockerinit') do CommandResult.new(:stdout => '', :exit_status => 2) end allow(virt.backend).to receive(:run_command).with('test -d /proc/vz -a ! -d /proc/bc') do CommandResult.new(:stdout => '', :exit_status => 0) end expect(virt.get).to include(:system => 'openvz') end let(:host_inventory) { nil } it 'Debian Jessie on KVM should return :system => "kvm"' do ret = virt.parse_system_product_name("KVM\n") expect(ret).to include('kvm') end let(:host_inventory) { nil } it 'CentOS 6.7 on VMware should return :system => "vmware"' do ret = virt.parse_system_product_name("VMware Virtual Platform\n") expect(ret).to include('vmware') end let(:host_inventory) { nil } it 'Ubuntu 14.04 on VirtualBox should return :system => "vbox"' do ret = virt.parse_system_product_name("VirtualBox\n") expect(ret).to include('vbox') end end specinfra-2.82.8/spec/host_inventory/linux/kernel_spec.rb0000644000004100000410000000160713614203316023622 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::HostInventory::Kernel do describe 'Example of CentOS 6.6 Kernel version 2.6.32-504.30.3.el6.x86_64' do str = 'Linux 2.6.32-504.30.3.el6.x86_64' let(:host_inventory) { nil } ret = Specinfra::HostInventory::Kernel.new(host_inventory).parse_uname(str) example "name" do expect(ret["name"]).to eq("Linux") end example "release" do expect(ret["release"]).to eq("2.6.32-504.30.3.el6.x86_64") end example "version" do expect(ret["version"]).to eq("2.6.32") end example "major" do expect(ret["version_major"]).to eq("2.6") end end describe 'Example of unparseable output' do str = 'unparseable output' let(:host_inventory) { nil } ret = Specinfra::HostInventory::Kernel.new(host_inventory).parse_uname(str) example 'is nil' do expect(ret).to be(nil) end end end specinfra-2.82.8/spec/host_inventory/linux/memory_spec.rb0000644000004100000410000001004713614203316023650 0ustar www-datawww-datarequire 'spec_helper' str = <<-EOH MemTotal: 1019392 kB MemFree: 88248 kB Buffers: 26016 kB Cached: 312856 kB SwapCached: 87708 kB Active: 396664 kB Inactive: 444580 kB Active(anon): 242816 kB Inactive(anon): 308412 kB Active(file): 153848 kB Inactive(file): 136168 kB Unevictable: 16 kB Mlocked: 16 kB HighTotal: 131912 kB HighFree: 312 kB LowTotal: 887480 kB LowFree: 87936 kB SwapTotal: 2064380 kB SwapFree: 1760500 kB Dirty: 0 kB Writeback: 0 kB AnonPages: 473868 kB Mapped: 68192 kB Shmem: 48856 kB Slab: 57696 kB SReclaimable: 14152 kB SUnreclaim: 43544 kB KernelStack: 3240 kB PageTables: 12144 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 2574076 kB Committed_AS: 2517964 kB VmallocTotal: 122880 kB VmallocUsed: 11204 kB VmallocChunk: 95432 kB AnonHugePages: 92160 kB HugePages_Total: 189440 HugePages_Free: 189440 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 907256 kB DirectMap2M: 0 kB EOH describe Specinfra::HostInventory::Memory do let(:host_inventory) { nil } describe 'Example of CentOS 6.6 Kernel version 2.6.32-504.23.4.el6.i686' do ret = Specinfra::HostInventory::Memory.new(host_inventory).parse(str) example "active" do expect(ret["active"]).to include("396664kB") end example "anon_pages" do expect(ret["anon_pages"]).to include("473868kB") end example "bounce" do expect(ret["bounce"]).to include("0kB") end example "buffers" do expect(ret["buffers"]).to include("26016kB") end example "cached" do expect(ret["cached"]).to include("312856kB") end example "commited_as" do expect(ret["committed_as"]).to include("2517964kB") end example "commit_limit" do expect(ret["commit_limit"]).to include("2574076kB") end example "dirty" do expect(ret["dirty"]).to include("0kB") end example "free" do expect(ret["free"]).to include("88248kB") end example "inactive" do expect(ret["inactive"]).to include("444580kB") end example "mapped" do expect(ret["mapped"]).to include("68192kB") end example "nfs_unstable" do expect(ret["nfs_unstable"]).to include("0kB") end example "page_tables" do expect(ret["page_tables"]).to include("12144kB") end example "slab" do expect(ret["slab"]).to include("57696kB") end example "slab_reclaimable" do expect(ret["slab_reclaimable"]).to include("14152kB") end example "slab_unreclaim" do expect(ret["slab_unreclaim"]).to include("43544kB") end example "swap" do expect(ret["swap"]).to include( "free" => "1760500kB", "total" => "2064380kB", "cached" => "87708kB" ) end example "total" do expect(ret["total"]).to include("1019392kB") end example "vmalloc_chunk" do expect(ret["vmalloc_chunk"]).to include("95432kB") end example "vmalloc_total" do expect(ret["vmalloc_total"]).to include("122880kB") end example "vmalloc_used" do expect(ret["vmalloc_used"]).to include("11204kB") end example "writeback" do expect(ret["writeback"]).to include("0kB") end example "annon_huge_pages" do expect(ret["annon_huge_pages"]).to include("92160kB") end example "huge_pages_total" do expect(ret["huge_pages_total"]).to include("189440") end example "huge_pages_free" do expect(ret["huge_pages_free"]).to include("189440") end example "huge_pages_rsvd" do expect(ret["huge_pages_rsvd"]).to include("0") end example "huge_pages_surp" do expect(ret["huge_pages_surp"]).to include("0") end example "huge_page_size" do expect(ret["huge_page_size"]).to include("2048kB") end end end specinfra-2.82.8/spec/host_inventory/aix/0000755000004100000410000000000013614203316020421 5ustar www-datawww-dataspecinfra-2.82.8/spec/host_inventory/aix/filesystem_spec.rb0000644000004100000410000000650213614203316024147 0ustar www-datawww-datarequire 'spec_helper' # Output from 'df -kP' str = <<-EOH Filesystem 1024-blocks Used Available Capacity Mounted on /dev/hd4 524288 67328 456960 13% / /dev/hd2 4194304 3077768 1116536 74% /usr /dev/hd9var 3145728 96588 3049140 4% /var /dev/hd3 2097152 128588 1968564 7% /tmp /dev/hd1 65536 380 65156 1% /home /dev/hd11admin 131072 364 130708 1% /admin /proc - - - - /proc /dev/hd10opt 4194304 725280 3469024 18% /opt /dev/livedump 1572864 568 1572296 1% /var/adm/ras/livedump /dev/fslv00 1048576 127848 920728 13% /audit EOH describe Specinfra::HostInventory::Filesystem do let(:host_inventory) { nil } describe 'Example of AIX 7.1' do ret = Specinfra::HostInventory::Filesystem.new(host_inventory).parse(str) example "/dev/fslv00" do expect(ret["/dev/fslv00"]).to include( "kb_available" => "920728", "kb_size" => "1048576", "kb_used" => "127848", "mount" => "/audit", "percent_used" => "13%" ) end example "/dev/hd1" do expect(ret["/dev/hd1"]).to include( "kb_available" => "65156", "kb_size" => "65536", "kb_used" => "380", "mount" => "/home", "percent_used" => "1%" ) end example "/dev/hd2" do expect(ret["/dev/hd2"]).to include( "kb_available" => "1116536", "kb_used" => "3077768", "kb_size" => "4194304", "mount" => "/usr", "percent_used" => "74%" ) end example "/dev/hd3" do expect(ret["/dev/hd3"]).to include( "kb_available" => "1968564", "kb_size" => "2097152", "kb_used" => "128588", "mount" => "/tmp", "percent_used" => "7%" ) end example "/dev/hd4" do expect(ret["/dev/hd4"]).to include( "kb_available" => "456960", "kb_size" => "524288", "kb_used" => "67328", "mount" => "/", "percent_used" => "13%" ) end example "/dev/hd9var" do expect(ret["/dev/hd9var"]).to include( "kb_available" => "3049140", "kb_size" => "3145728", "kb_used" => "96588", "mount" => "/var", "percent_used" => "4%" ) end example "/dev/hd10opt" do expect(ret["/dev/hd10opt"]).to include( "kb_available" => "3469024", "kb_size" => "4194304", "kb_used" => "725280", "mount" => "/opt", "percent_used" => "18%" ) end example "/dev/hd11admin" do expect(ret["/dev/hd11admin"]).to include( "kb_available" => "130708", "kb_used" => "364", "kb_size" => "131072", "mount" => "/admin", "percent_used" => "1%" ) end example "/dev/livedump" do expect(ret["/dev/livedump"]).to include( "kb_available" => "1572296", "kb_size" => "1572864", "kb_used" => "568", "mount" => "/var/adm/ras/livedump", "percent_used" => "1%" ) end example "/proc" do expect(ret).to_not include( "/proc" ) end end end specinfra-2.82.8/spec/host_inventory/freebsd/0000755000004100000410000000000013614203316021252 5ustar www-datawww-dataspecinfra-2.82.8/spec/host_inventory/freebsd/filesystem_spec.rb0000644000004100000410000000765713614203316025014 0ustar www-datawww-datarequire 'spec_helper' ## Output from 'df -k' str = <<-EOH Filesystem 1024-blocks Used Avail Capacity Mounted on zroot/ROOT/default 2500692 1345720 1154972 54% / devfs 1 1 0 100% /dev zroot/tmp 1155148 176 1154972 0% /tmp zroot/usr/home 1353676 198704 1154972 15% /usr/home zroot/usr/ports 2306832 1151860 1154972 50% /usr/ports zroot/usr/src 1155116 144 1154972 0% /usr/src zroot/var 1361412 206440 1154972 15% /var zroot/var/crash 1155120 148 1154972 0% /var/crash zroot/var/log 1156184 1212 1154972 0% /var/log zroot/var/mail 1155168 196 1154972 0% /var/mail zroot/var/tmp 1188108 33136 1154972 3% /var/tmp EOH describe Specinfra::HostInventory::Filesystem do let(:host_inventory) { nil } describe 'Example of FreeBSD 9.3 amd64' do ret = Specinfra::HostInventory::Filesystem.new(host_inventory).parse(str) example "devfs" do expect(ret["devfs"]).to include( "kb_available" => "0", "kb_size" => "1", "mount" => "/dev", "percent_used" => "100%", "kb_used" => "1" ) end example "zroot/ROOT/default" do expect(ret["zroot/ROOT/default"]).to include( "kb_available" => "1154972", "kb_size" => "2500692", "mount" => "/", "percent_used" => "54%", "kb_used" => "1345720" ) end example "zroot/tmp" do expect(ret["zroot/tmp"]).to include( "kb_available" => "1154972", "kb_size" => "1155148", "mount" => "/tmp", "percent_used" => "0%", "kb_used" => "176" ) end example "zroot/usr/home" do expect(ret["zroot/usr/home"]).to include( "kb_available" => "1154972", "kb_size" => "1353676", "mount" => "/usr/home", "percent_used" => "15%", "kb_used" => "198704" ) end example "zroot/usr/ports" do expect(ret["zroot/usr/ports"]).to include( "kb_available" => "1154972", "kb_size" => "2306832", "mount" => "/usr/ports", "percent_used" => "50%", "kb_used" => "1151860" ) end example "zroot/usr/src" do expect(ret["zroot/usr/src"]).to include( "kb_available" => "1154972", "kb_size" => "1155116", "mount" => "/usr/src", "percent_used" => "0%", "kb_used" => "144" ) end example "zroot/var" do expect(ret["zroot/var"]).to include( "kb_available" => "1154972", "kb_size" => "1361412", "mount" => "/var", "percent_used" => "15%", "kb_used" => "206440" ) end example "zroot/var/crash" do expect(ret["zroot/var/crash"]).to include( "kb_available" => "1154972", "kb_size" => "1155120", "mount" => "/var/crash", "percent_used" => "0%", "kb_used" => "148" ) end example "zroot/var/mail" do expect(ret["zroot/var/mail"]).to include( "kb_available" => "1154972", "kb_size" => "1155168", "mount" => "/var/mail", "percent_used" => "0%", "kb_used" => "196" ) end example "zroot/var/log" do expect(ret["zroot/var/log"]).to include( "kb_available" => "1154972", "kb_size" => "1156184", "mount" => "/var/log", "percent_used" => "0%", "kb_used" => "1212" ) end example "zroot/var/tmp" do expect(ret["zroot/var/tmp"]).to include( "kb_available" => "1154972", "kb_size" => "1188108", "mount" => "/var/tmp", "percent_used" => "3%", "kb_used" => "33136" ) end end end specinfra-2.82.8/spec/host_inventory/solaris/0000755000004100000410000000000013614203316021314 5ustar www-datawww-dataspecinfra-2.82.8/spec/host_inventory/solaris/filesystem_spec.rb0000644000004100000410000001110213614203316025032 0ustar www-datawww-datarequire 'spec_helper' # Output from df -k | nawk -v i=0 '$1 == "swap" { $1=$1i; i++ }; NF == 1 { printf($1); next }; { print }' str = <<-EOH Filesystem kbytes used avail capacity Mounted on / 32769183 5637051 27132132 18% / /dev 32769183 5637051 27132132 18% /dev proc 0 0 0 0% /proc ctfs 0 0 0 0% /system/contract mnttab 0 0 0 0% /etc/mnttab objfs 0 0 0 0% /system/object swap0 8664048 312 8663736 1% /etc/svc/volatile /platform/sun4v/lib/libc_psr/libc_psr_hwcap3.so.1 32769183 5637051 27132132 18% /platform/sun4v/lib/libc_psr.so.1 /platform/sun4v/lib/sparc9/libc_psr/lib_psr_hwcap3.so.1 32769183 5637051 27132132 18% /platform/sun4v/lib/sparcv9/libc_psr.so.1 fd 0 0 0 0% /dev/fd swap1 2097152 160 2096992 1% /tmp swap2 8663784 48 8663736 1% /var/run EOH ## Houston we have problem! ## there are multiple entries called 'swap' in Solaris ## with the current parser they are not getting reported correctly ## only the last entry is being reported! describe Specinfra::HostInventory::Filesystem do let(:host_inventory) { nil } describe 'Example of Solaris 10' do ret = Specinfra::HostInventory::Filesystem.new(host_inventory).parse(str) example "/" do expect(ret["/"]).to include( "kb_available" => "27132132", "kb_size" => "32769183", "kb_used" => "5637051", "mount" => "/", "percent_used" => "18%" ) end example "/dev" do expect(ret["/dev"]).to include( "kb_available" => "27132132", "kb_size" => "32769183", "kb_used" => "5637051", "mount" => "/dev", "percent_used" => "18%" ) end example "/platform/sun4v/lib/libc_psr/libc_psr_hwcap3.so.1" do expect(ret["/platform/sun4v/lib/libc_psr/libc_psr_hwcap3.so.1"]).to include( "kb_available" => "27132132", "kb_size" => "32769183", "kb_used" => "5637051", "mount" => "/platform/sun4v/lib/libc_psr.so.1", "percent_used" => "18%" ) end example "/platform/sun4v/lib/sparc9/libc_psr/lib_psr_hwcap3.so.1" do expect(ret["/platform/sun4v/lib/sparc9/libc_psr/lib_psr_hwcap3.so.1"]).to include( "kb_available" => "27132132", "kb_size" => "32769183", "kb_used" => "5637051", "mount" => "/platform/sun4v/lib/sparcv9/libc_psr.so.1", "percent_used" => "18%" ) end example "ctfs" do expect(ret["ctfs"]).to include( "kb_available" => "0", "kb_size" => "0", "kb_used" => "0", "mount" => "/system/contract", "percent_used" => "0%" ) end example "fd" do expect(ret["fd"]).to include( "kb_available" => "0", "kb_size" => "0", "kb_used" => "0", "mount" => "/dev/fd", "percent_used" => "0%" ) end example "mnttab" do expect(ret["mnttab"]).to include( "kb_available" => "0", "kb_size" => "0", "kb_used" => "0", "mount" => "/etc/mnttab", "percent_used" => "0%" ) end example "objfs" do expect(ret["objfs"]).to include( "kb_available" => "0", "kb_size" => "0", "kb_used" => "0", "mount" => "/system/object", "percent_used" => "0%" ) end example "proc" do expect(ret["proc"]).to include( "kb_available" => "0", "kb_size" => "0", "kb_used" => "0", "mount" => "/proc", "percent_used" => "0%" ) end example "swap0" do expect(ret["swap0"]).to include( "kb_available" => "8663736", "kb_size" => "8664048", "kb_used" => "312", "mount" => "/etc/svc/volatile", "percent_used" => "1%" ) end example "swap1" do expect(ret["swap1"]).to include( "kb_available" => "2096992", "kb_size" => "2097152", "kb_used" => "160", "mount" => "/tmp", "percent_used" => "1%" ) end example "swap2" do expect(ret["swap2"]).to include( "kb_available" => "8663736", "kb_size" => "8663784", "kb_used" => "48", "mount" => "/var/run", "percent_used" => "1%" ) end end end specinfra-2.82.8/spec/host_inventory/solaris/virtualization_spec.rb0000644000004100000410000000161113614203316025736 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::HostInventory::Virtualization do before :all do set :os, { :family => 'solaris' } end virt = Specinfra::HostInventory::Virtualization.new(host_inventory) let(:host_inventory) { nil } it 'OpenIndiana on KVM should return :system => "kvm"' do ret = virt.parse_system_product_name("System Configuration: Red Hat KVM") expect(ret).to include('kvm') end let(:host_inventory) { nil } it 'OpenIndiana on VMware should return :system => "vmware"' do ret = virt.parse_system_product_name("System Configuration: VMware, Inc. VMware Virtual Platform\n") expect(ret).to include('vmware') end let(:host_inventory) { nil } it 'OpenIndiana on VirtualBox should return :system => "vbox"' do ret = virt.parse_system_product_name("System Configuration: innotek GmbH VirtualBox\n") expect(ret).to include('vbox') end end specinfra-2.82.8/spec/host_inventory/base/0000755000004100000410000000000013614203316020552 5ustar www-datawww-dataspecinfra-2.82.8/spec/host_inventory/base/group_spec.rb0000644000004100000410000000703713614203316023254 0ustar www-datawww-datarequire 'spec_helper' str = <<-EOH root:x:0: bin:x:1: daemon:x:2: sys:x:3: adm:x:4: tty:x:5: disk:x:6: lp:x:7: mem:x:8: kmem:x:9: wheel:x:10:hoge cdrom:x:11: mail:x:12:postfix man:x:15: dialout:x:18: floppy:x:19: games:x:20: tape:x:30: video:x:39: ftp:x:50: lock:x:54: audio:x:63: nobody:x:99: users:x:100: avahi-autoipd:x:170: utmp:x:22: utempter:x:35: ssh_keys:x:999: input:x:998: systemd-journal:x:190: systemd-bus-proxy:x:997: systemd-network:x:996: dbus:x:81: polkitd:x:995: dip:x:40: tss:x:59: postdrop:x:90: postfix:x:89: sshd:x:74: ntp:x:38: hoge:x:1000: EOH describe Specinfra::HostInventory::Group do let(:host_inventory) { nil } describe 'Example of CentOS Linux release 7.2.1511' do ret = Specinfra::HostInventory::Group.new(host_inventory).parse(str) example do expect(ret).to include( 'adm' => {'name'=>'adm', 'gid'=>'4', 'members'=>[]}, 'audio' => {'name'=>'audio', 'gid'=>'63', 'members'=>[]}, 'avahi-autoipd' => {'name'=>'avahi-autoipd', 'gid'=>'170', 'members'=>[]}, 'bin' => {'name'=>'bin', 'gid'=>'1', 'members'=>[]}, 'cdrom' => {'name'=>'cdrom', 'gid'=>'11', 'members'=>[]}, 'daemon' => {'name'=>'daemon', 'gid'=>'2', 'members'=>[]}, 'dbus' => {'name'=>'dbus', 'gid'=>'81', 'members'=>[]}, 'dialout' => {'name'=>'dialout', 'gid'=>'18', 'members'=>[]}, 'dip' => {'name'=>'dip', 'gid'=>'40', 'members'=>[]}, 'disk' => {'name'=>'disk', 'gid'=>'6', 'members'=>[]}, 'floppy' => {'name'=>'floppy', 'gid'=>'19', 'members'=>[]}, 'ftp' => {'name'=>'ftp', 'gid'=>'50', 'members'=>[]}, 'games' => {'name'=>'games', 'gid'=>'20', 'members'=>[]}, 'hoge' => {'name'=>'hoge', 'gid'=>'1000', 'members'=>[]}, 'input' => {'name'=>'input', 'gid'=>'998', 'members'=>[]}, 'kmem' => {'name'=>'kmem', 'gid'=>'9', 'members'=>[]}, 'lock' => {'name'=>'lock', 'gid'=>'54', 'members'=>[]}, 'lp' => {'name'=>'lp', 'gid'=>'7', 'members'=>[]}, 'mail' => {'name'=>'mail', 'gid'=>'12', 'members'=>['postfix']}, 'man' => {'name'=>'man', 'gid'=>'15', 'members'=>[]}, 'mem' => {'name'=>'mem', 'gid'=>'8', 'members'=>[]}, 'nobody' => {'name'=>'nobody', 'gid'=>'99', 'members'=>[]}, 'ntp' => {'name'=>'ntp', 'gid'=>'38', 'members'=>[]}, 'polkitd' => {'name'=>'polkitd', 'gid'=>'995', 'members'=>[]}, 'postdrop' => {'name'=>'postdrop', 'gid'=>'90', 'members'=>[]}, 'postfix' => {'name'=>'postfix', 'gid'=>'89', 'members'=>[]}, 'root' => {'name'=>'root', 'gid'=>'0', 'members'=>[]}, 'ssh_keys' => {'name'=>'ssh_keys', 'gid'=>'999', 'members'=>[]}, 'sshd' => {'name'=>'sshd', 'gid'=>'74', 'members'=>[]}, 'sys' => {'name'=>'sys', 'gid'=>'3', 'members'=>[]}, 'systemd-bus-proxy' => {'name'=>'systemd-bus-proxy', 'gid'=>'997', 'members'=>[]}, 'systemd-journal' => {'name'=>'systemd-journal', 'gid'=>'190', 'members'=>[]}, 'systemd-network' => {'name'=>'systemd-network', 'gid'=>'996', 'members'=>[]}, 'tape' => {'name'=>'tape', 'gid'=>'30', 'members'=>[]}, 'tss' => {'name'=>'tss', 'gid'=>'59', 'members'=>[]}, 'tty' => {'name'=>'tty', 'gid'=>'5', 'members'=>[]}, 'users' => {'name'=>'users', 'gid'=>'100', 'members'=>[]}, 'utempter' => {'name'=>'utempter', 'gid'=>'35', 'members'=>[]}, 'utmp' => {'name'=>'utmp', 'gid'=>'22', 'members'=>[]}, 'video' => {'name'=>'video', 'gid'=>'39', 'members'=>[]}, 'wheel' => {'name'=>'wheel', 'gid'=>'10', 'members'=>['hoge']} ) end end end specinfra-2.82.8/spec/host_inventory/base/user_spec.rb0000644000004100000410000001247413614203316023077 0ustar www-datawww-datarequire 'spec_helper' str = <<-EOH root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin systemd-network:x:998:996:systemd Network Management:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:997:995:User for polkitd:/:/sbin/nologin tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin ntp:x:38:38::/etc/ntp:/sbin/nologin hoge:x:1000:1000::/home/hoge:/bin/bash saslauth:x:499:76:Saslauthd user:/run/saslauthd:/sbin/nologin apache:x:48:48:Apache:/opt/rh/httpd24/root/usr/share/httpd:/sbin/nologin postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash EOH describe Specinfra::HostInventory::User do let(:host_inventory) { nil } describe 'Example of CentOS Linux release 7.2.1511' do ret = Specinfra::HostInventory::User.new(host_inventory).parse(str) example do expect(ret).to include( 'root' => {'name' => 'root', 'uid' => '0', 'gid' => '0', 'gecos' => 'root', 'directory' => '/root', 'shell' => '/bin/root'}, 'adm' => {'name'=>'adm', 'uid'=>'3', 'gid'=>'4', 'gecos'=>'adm', 'directory'=>'/var/adm', 'shell'=>'/sbin/nologin'}, 'apache' => {'name'=>'apache', 'uid'=>'48', 'gid'=>'48', 'gecos'=>'Apache', 'directory'=>'/opt/rh/httpd24/root/usr/share/httpd', 'shell'=>'/sbin/nologin'}, 'avahi-autoipd' => {'name'=>'avahi-autoipd', 'uid'=>'170', 'gid'=>'170', 'gecos'=>'Avahi IPv4LL Stack', 'directory'=>'/var/lib/avahi-autoipd', 'shell'=>'/sbin/nologin'}, 'bin' => {'name'=>'bin', 'uid'=>'1', 'gid'=>'1', 'gecos'=>'bin', 'directory'=>'/bin', 'shell'=>'/sbin/nologin'}, 'daemon' => {'name'=>'daemon', 'uid'=>'2', 'gid'=>'2', 'gecos'=>'daemon', 'directory'=>'/sbin', 'shell'=>'/sbin/nologin'}, 'dbus' => {'name'=>'dbus', 'uid'=>'81', 'gid'=>'81', 'gecos'=>'System message bus', 'directory'=>'/', 'shell'=>'/sbin/nologin'}, 'ftp' => {'name'=>'ftp', 'uid'=>'14', 'gid'=>'50', 'gecos'=>'FTP User', 'directory'=>'/var/ftp', 'shell'=>'/sbin/nologin'}, 'games' => {'name'=>'games', 'uid'=>'12', 'gid'=>'100', 'gecos'=>'games', 'directory'=>'/usr/games', 'shell'=>'/sbin/nologin'}, 'halt' => {'name'=>'halt', 'uid'=>'7', 'gid'=>'0', 'gecos'=>'halt', 'directory'=>'/sbin', 'shell'=>'/sbin/halt'}, 'hoge' => {'name'=>'hoge', 'uid'=>'1000', 'gid'=>'1000', 'gecos'=>'', 'directory'=>'/home/hoge', 'shell'=>'/bin/bash'}, 'lp' => {'name'=>'lp', 'uid'=>'4', 'gid'=>'7', 'gecos'=>'lp', 'directory'=>'/var/spool/lpd', 'shell'=>'/sbin/nologin'}, 'mail' => {'name'=>'mail', 'uid'=>'8', 'gid'=>'12', 'gecos'=>'mail', 'directory'=>'/var/spool/mail', 'shell'=>'/sbin/nologin'}, 'nobody' => {'name'=>'nobody', 'uid'=>'99', 'gid'=>'99', 'gecos'=>'Nobody', 'directory'=>'/', 'shell'=>'/sbin/nologin'}, 'ntp' => {'name'=>'ntp', 'uid'=>'38', 'gid'=>'38', 'gecos'=>'', 'directory'=>'/etc/ntp', 'shell'=>'/sbin/nologin'}, 'operator' => {'name'=>'operator', 'uid'=>'11', 'gid'=>'0', 'gecos'=>'operator', 'directory'=>'/root', 'shell'=>'/sbin/nologin'}, 'polkitd' => {'name'=>'polkitd', 'uid'=>'997', 'gid'=>'995', 'gecos'=>'User for polkitd', 'directory'=>'/', 'shell'=>'/sbin/nologin'}, 'postfix' => {'name'=>'postfix', 'uid'=>'89', 'gid'=>'89', 'gecos'=>'', 'directory'=>'/var/spool/postfix', 'shell'=>'/sbin/nologin'}, 'postgres' => {'name'=>'postgres', 'uid'=>'26', 'gid'=>'26', 'gecos'=>'PostgreSQL Server', 'directory'=>'/var/lib/pgsql', 'shell'=>'/bin/bash'}, 'root' => {'name'=>'root', 'uid'=>'0', 'gid'=>'0', 'gecos'=>'root', 'directory'=>'/root', 'shell'=>'/bin/bash'}, 'saslauth' => {'name'=>'saslauth', 'uid'=>'499', 'gid'=>'76', 'gecos'=>'Saslauthd user', 'directory'=>'/run/saslauthd', 'shell'=>'/sbin/nologin'}, 'shutdown' => {'name'=>'shutdown', 'uid'=>'6', 'gid'=>'0', 'gecos'=>'shutdown', 'directory'=>'/sbin', 'shell'=>'/sbin/shutdown'}, 'sshd' => {'name'=>'sshd', 'uid'=>'74', 'gid'=>'74', 'gecos'=>'Privilege-separated SSH', 'directory'=>'/var/empty/sshd', 'shell'=>'/sbin/nologin'}, 'sync' => {'name'=>'sync', 'uid'=>'5', 'gid'=>'0', 'gecos'=>'sync', 'directory'=>'/sbin', 'shell'=>'/bin/sync'}, 'systemd-bus-proxy' => {'name'=>'systemd-bus-proxy', 'uid'=>'999', 'gid'=>'997', 'gecos'=>'systemd Bus Proxy', 'directory'=>'/', 'shell'=>'/sbin/nologin'}, 'systemd-network' => {'name'=>'systemd-network', 'uid'=>'998', 'gid'=>'996', 'gecos'=>'systemd Network Management', 'directory'=>'/', 'shell'=>'/sbin/nologin'}, 'tss' => {'name'=>'tss', 'uid'=>'59', 'gid'=>'59', 'gecos'=>'Account used by the trousers package to sandbox the tcsd daemon', 'directory'=>'/dev/null', 'shell'=>'/sbin/nologin'} ) end end end specinfra-2.82.8/spec/host_inventory/darwin/0000755000004100000410000000000013614203316021124 5ustar www-datawww-dataspecinfra-2.82.8/spec/host_inventory/darwin/filesystem_spec.rb0000644000004100000410000000413413614203316024651 0ustar www-datawww-datarequire 'spec_helper' ## Output from 'df -k' str = <<-EOH Filesystem 1024-blocks Used Available Capacity Mounted on /dev/disk0s2 243358976 213852680 29250296 88% / devfs 126 126 0 100% /dev map -hosts 0 0 0 100% /net map auto_home 0 0 0 100% /home localhost:/zbXdxUd1sN5zY6jeNUAx8l 243358976 243358976 0 100% /Volumes/MobileBackups EOH describe Specinfra::HostInventory::Filesystem do let(:host_inventory) { nil } describe 'Example Darwin (MacOS X) release 11.4.2' do ret = Specinfra::HostInventory::Filesystem.new(host_inventory).parse(str) example "/dev/disk0s2" do expect(ret["/dev/disk0s2"]).to include( "kb_available" => "29250296", "kb_size" => "243358976", "kb_used" => "213852680", "mount" => "/", "percent_used" => "88%" ) end example "map -hosts" do expect(ret["map -hosts"]).to include( "kb_available" => "0", "kb_size" => "0", "kb_used" => "0", "mount" => "/net", "percent_used" => "100%" ) end example "map auto_home" do expect(ret["map auto_home"]).to include( "kb_available" => "0", "kb_size" => "0", "kb_used" => "0", "mount" => "/home", "percent_used" => "100%" ) end example "devfs" do expect(ret["devfs"]).to include( "kb_available" => "0", "kb_size" => "126", "kb_used" => "126", "mount" => "/dev", "percent_used" => "100%" ) end example "localhost:/zbXdxUd1sN5zY6jeNUAx8l" do expect(ret["localhost:/zbXdxUd1sN5zY6jeNUAx8l"]).to include( "kb_available" => "0", "kb_size" => "243358976", "kb_used" => "243358976", "mount" => "/Volumes/MobileBackups", "percent_used" => "100%" ) end end end specinfra-2.82.8/spec/host_inventory/openbsd/0000755000004100000410000000000013614203316021272 5ustar www-datawww-dataspecinfra-2.82.8/spec/host_inventory/openbsd/filesystem_spec.rb0000644000004100000410000000240613614203316025017 0ustar www-datawww-datarequire 'spec_helper' ## Output from 'df -kP' str = <<-EOH Filesystem 1024-blocks Used Available Capacity Mounted on /dev/sd0a 1013006 58408 903948 6% / /dev/sd0e 1822574 18 1731428 0% /home /dev/sd0d 3093230 372244 2566326 13% /usr EOH describe Specinfra::HostInventory::Filesystem do let(:host_inventory) { nil } describe 'Example OpenBSD release 5.7' do ret = Specinfra::HostInventory::Filesystem.new(host_inventory).parse(str) example "/dev/sd0a" do expect(ret["/dev/sd0a"]).to include( "kb_available" => "903948", "kb_size" => "1013006", "kb_used" => "58408", "mount" => "/", "percent_used" => "6%" ) end example "/dev/sd0d" do expect(ret["/dev/sd0d"]).to include( "kb_available" => "2566326", "kb_size" => "3093230", "kb_used" => "372244", "mount" => "/usr", "percent_used" => "13%" ) end example "/dev/sd0e" do expect(ret["/dev/sd0e"]).to include( "kb_available" => "1731428", "kb_size" => "1822574", "kb_used" => "18", "mount" => "/home", "percent_used" => "0%" ) end end end specinfra-2.82.8/spec/host_inventory/openbsd/virtualization_spec.rb0000644000004100000410000000144613614203316025722 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::HostInventory::Virtualization do before :all do set :os, { :family => 'openbsd' } end virt = Specinfra::HostInventory::Virtualization.new(host_inventory) let(:host_inventory) { nil } it 'OpenBSD 5.7 on KVM should return :system => "kvm"' do ret = virt.parse_system_product_name("KVM\n") expect(ret).to include('kvm') end let(:host_inventory) { nil } it 'OpenBSD 5.7 on VMware should return :system => "vmware"' do ret = virt.parse_system_product_name("VMware Virtual Platform\n") expect(ret).to include('vmware') end let(:host_inventory) { nil } it 'OpenBSD 5.7 on VirtualBox should return :system => "vbox"' do ret = virt.parse_system_product_name("VirtualBox\n") expect(ret).to include('vbox') end end specinfra-2.82.8/spec/spec_helper.rb0000644000004100000410000000075613614203316017374 0ustar www-datawww-datarequire 'specinfra' require 'rspec/mocks/standalone' require 'rspec/its' require 'specinfra/helper/set' require 'specinfra/helper/host_inventory' include Specinfra::Helper::Set set :backend, :exec module Specinfra module Backend class Ssh def run_command(cmd, opts={}) CommandResult.new :stdout => nil, :exit_status => 0 end end end end module GetCommand def get_command(method, *args) Specinfra.command.get(method, *args) end end include GetCommand specinfra-2.82.8/spec/helper/0000755000004100000410000000000013614203316016025 5ustar www-datawww-dataspecinfra-2.82.8/spec/helper/set_spec.rb0000644000004100000410000000073413614203316020163 0ustar www-datawww-datarequire 'spec_helper' describe 'set method set value to Specinfra.configuration' do it 'set method handle string value correctly' do set :host, 'localhost' expect(Specinfra.configuration.host).to eq 'localhost' end it 'set method handle hash value correctly' do set :ssh_options, :password => 'password', :port => 2222 ssh_options = { :password => 'password', :port => 2222 } expect(Specinfra.configuration.ssh_options).to eq ssh_options end end specinfra-2.82.8/spec/helper/properties_spec.rb0000644000004100000410000000033313614203316021557 0ustar www-datawww-datarequire 'spec_helper' include Specinfra::Helper::Properties describe 'Properties Helper' do before :all do set_property :role => 'proxy' end subject { property } it { should include :role => 'proxy' } end specinfra-2.82.8/spec/helper/os_spec.rb0000644000004100000410000000312713614203316020010 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe 'os', :order => :defined do def set_stub_chain(keys, value) allow(Specinfra).to receive_message_chain([:configuration, keys].flatten).and_return(value) end describe 'no ssh connection without cache' do before do property[:os] = nil set_stub_chain(:ssh, nil) set_stub_chain(:ssh_options, nil) set_stub_chain(:host, 'localhost') set_stub_chain(:os, :family => 'redhat') end it { expect(os[:family]).to eq 'redhat' } end describe 'no ssh connection with cache' do it { expect(property[:os]).to eq(:family => 'redhat') } end describe 'ssh_options without cache' do before do property[:os] = nil set_stub_chain(:ssh, nil) set_stub_chain(:ssh_options, :port => 22) set_stub_chain(:host, 'localhost') set_stub_chain(:os, :family => 'ubuntu') end it { expect(os[:family]).to eq 'ubuntu' } end describe 'ssh_options with cache' do it { expect(property[:os]).to eq(:family => 'ubuntu') } end describe 'ssh_connection without cache' do before do property[:os] = nil set_stub_chain([:ssh, :host], 'localhost') set_stub_chain([:ssh, :options], :port => 2222) set_stub_chain(:os, :family => 'nixos') end it { expect(os[:family]).to eq 'nixos' } end describe 'ssh_connection with cache' do before do set_stub_chain([:ssh, :host], 'localhost') set_stub_chain([:ssh, :options], :port => 2222) set_stub_chain(:os, :family => 'nixos') end it { expect(property[:os]).to eq(:family => 'nixos') } end end specinfra-2.82.8/spec/helper/detect_os/0000755000004100000410000000000013614203316017776 5ustar www-datawww-dataspecinfra-2.82.8/spec/helper/detect_os/aix_spec.rb0000644000004100000410000000371113614203316022120 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/aix' describe Specinfra::Helper::DetectOs::Aix do aix = Specinfra::Helper::DetectOs::Aix.new(:exec) it 'Should return aix 10.11 powerpc when (fictional) AIX 10.11 is installed.' do allow(aix).to receive(:run_command).with('uname -s') { CommandResult.new(:stdout => 'AIX', :exit_status => 0) } allow(aix).to receive(:run_command).with('uname -rvp') { CommandResult.new(:stdout => '11 10 powerpc', :exit_status => 0) } expect(aix.detect).to include( :family => 'aix', :release => '10.11', :arch => 'powerpc' ) end it 'Should return aix 7.1 powerpc when AIX 7.1 is installed.' do allow(aix).to receive(:run_command).with('uname -s') { CommandResult.new(:stdout => 'AIX', :exit_status => 0) } allow(aix).to receive(:run_command).with('uname -rvp') { CommandResult.new(:stdout => '1 7 powerpc', :exit_status => 0) } expect(aix.detect).to include( :family => 'aix', :release => '7.1', :arch => 'powerpc' ) end it 'Should return aix 6.1 powerpc when AIX 6.1 is installed.' do allow(aix).to receive(:run_command).with('uname -s') { CommandResult.new(:stdout => 'AIX', :exit_status => 0) } allow(aix).to receive(:run_command).with('uname -rvp') { CommandResult.new(:stdout => '1 6 powerpc', :exit_status => 0) } expect(aix.detect).to include( :family => 'aix', :release => '6.1', :arch => 'powerpc' ) end it 'Should return aix nil nil when AIX FooBar is installed.' do allow(aix).to receive(:run_command).with('uname -s') { CommandResult.new(:stdout => 'AIX', :exit_status => 0) } allow(aix).to receive(:run_command).with('uname -rvp') { CommandResult.new(:stdout => 'Foo Bar batz', :exit_status => 1) } expect(aix.detect).to include( :family => 'aix', :release => nil, :arch => nil ) end end specinfra-2.82.8/spec/helper/detect_os/darwin_spec.rb0000644000004100000410000000260613614203316022625 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/darwin' describe Specinfra::Helper::DetectOs::Darwin do darwin = Specinfra::Helper::DetectOs::Darwin.new(Specinfra.backend) it 'Should return darwin 13.4.0 when Mac OS X 10.9.5 (Mavericks) is installed.' do allow(darwin).to receive(:run_command) { CommandResult.new(:stdout => 'Darwin 13.4.0', :exit_status => 0) } expect(darwin.detect).to include( :family => 'darwin', :release => '13.4.0' ) end it 'Should return darwin 12.6.0 when Mac OS X 10.8.5 (Mountain Lion) is installed.' do allow(darwin).to receive(:run_command) { CommandResult.new(:stdout => 'Darwin 12.6.0', :exit_status => 0) } expect(darwin.detect).to include( :family => 'darwin', :release => '12.6.0' ) end it 'Should return darwin 11.4.2 when Mac OS X 10.7.5 (Lion) is installed.' do allow(darwin).to receive(:run_command) { CommandResult.new(:stdout => 'Darwin 11.4.2', :exit_status => 0) } expect(darwin.detect).to include( :family => 'darwin', :release => '11.4.2' ) end it 'Should return darwin nil when Darwin FooBar is installed.' do allow(darwin).to receive(:run_command) { CommandResult.new(:stdout => 'Darwin FooBar', :exit_status => 0) } expect(darwin.detect).to include( :family => 'darwin', :release => nil ) end end specinfra-2.82.8/spec/helper/detect_os/eos_spec.rb0000644000004100000410000000214013614203316022120 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/eos' describe Specinfra::Helper::DetectOs::Eos do eos = Specinfra::Helper::DetectOs::Eos.new(:exec) it 'Should return eos family and the correct version.' do allow(eos).to receive(:run_command).with('ls /etc/Eos-release') { CommandResult.new(:stdout => '/etc/Eos-release', :exit_status => 0) } allow(eos).to receive(:run_command).with('cat /etc/Eos-release') { CommandResult.new(:stdout => 'Arista Networks EOS 4.15.3F', :exit_status => 0) } expect(eos.detect).to include( :family => 'eos', :release => '4.15.3F' ) end it 'Should return eos nil when a non-conforming EOS version is installed.' do allow(eos).to receive(:run_command).with('ls /etc/Eos-release') { CommandResult.new(:stdout => '/etc/Eos-release', :exit_status => 0) } allow(eos).to receive(:run_command).with('cat /etc/Eos-release') { CommandResult.new(:stdout => 'Arista Networks EOS foo', :exit_status => 0) } expect(eos.detect).to include( :family => 'eos', :release => nil ) end end specinfra-2.82.8/spec/helper/detect_os/esxi_spec.rb0000644000004100000410000000130513614203316022304 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/esxi' describe Specinfra::Helper::DetectOs::Esxi do esxi = Specinfra::Helper::DetectOs::Esxi.new(:exec) it 'Should return esxi when esxi is installed.' do allow(esxi).to receive(:run_command) { CommandResult.new(:stdout => 'VMware ESXi 5.0.0 build-123445', :exit_status => 0) } expect(esxi.detect).to include( :family => 'esxi', :release => '5.0.0 build-123445' ) end it 'Should not return esxi when VMware Workstation is installed.' do allow(esxi).to receive(:run_command) { CommandResult.new(:stdout => 'VMware Workstation', :exit_status => 0) } expect(esxi.detect).to be_nil end end specinfra-2.82.8/spec/helper/detect_os/openbsd_spec.rb0000644000004100000410000000253513614203316022774 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/openbsd' describe Specinfra::Helper::DetectOs::Openbsd do openbsd = Specinfra::Helper::DetectOs::Openbsd.new(:exec) it 'Should return (fictional) openbsd 10.11 when OpenBSD 10.11 is installed.' do allow(openbsd).to receive(:run_command) { CommandResult.new(:stdout => 'OpenBSD 10.11', :exit_status => 0) } expect(openbsd.detect).to include( :family => 'openbsd', :release => '10.11' ) end it 'Should return openbsd 5.7 when OpenBSD 5.7 is installed.' do allow(openbsd).to receive(:run_command) { CommandResult.new(:stdout => 'OpenBSD 5.7', :exit_status => 0) } expect(openbsd.detect).to include( :family => 'openbsd', :release => '5.7' ) end it 'Should return openbsd 5.6 when OpenBSD 5.6 is installed.' do allow(openbsd).to receive(:run_command) { CommandResult.new(:stdout => 'OpenBSD 5.6', :exit_status => 0) } expect(openbsd.detect).to include( :family => 'openbsd', :release => '5.6' ) end it 'Should return openbsd nil when OpenBSD FooBar is installed.' do allow(openbsd).to receive(:run_command) { CommandResult.new(:stdout => 'OpenBSD FooBar', :exit_status => 0) } expect(openbsd.detect).to include( :family => 'openbsd', :release => nil ) end end specinfra-2.82.8/spec/helper/detect_os/clearlinux_spec.rb0000644000004100000410000000152613614203316023507 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/clearlinux' describe Specinfra::Helper::DetectOs::Clearlinux do clearlinux = Specinfra::Helper::DetectOs::Clearlinux.new(:exec) it 'Should return clearlinux & release when clearlinux is installed.' do allow(clearlinux).to receive(:run_command) { CommandResult.new(:stdout => 'Installed version: 30340', :exit_status => 0) } expect(clearlinux.detect).to include( :family => 'clearlinux', :release => '30340' ) end it 'Should return clearlinux but not the release when the command returns the wrong line' do allow(clearlinux).to receive(:run_command) { CommandResult.new(:stdout => 'Foobar version: 30340', :exit_status => 0) } expect(clearlinux.detect).to include( :family => 'clearlinux', :release => nil ) end endspecinfra-2.82.8/spec/helper/detect_os/debian_spec.rb0000644000004100000410000000570613614203316022567 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/debian' describe Specinfra::Helper::DetectOs::Debian do debian = Specinfra::Helper::DetectOs::Debian.new(Specinfra.backend) it 'Should return debian 8.5 when jessie is installed.' do allow(debian).to receive(:run_command).with('cat /etc/debian_version') { CommandResult.new(:stdout => "8.5\n", :exit_status => 0) } allow(debian).to receive(:run_command).with('lsb_release -ir') { CommandResult.new(:stdout => "8.5\n", :exit_status => 1) } allow(debian).to receive(:run_command).with('cat /etc/lsb-release') { CommandResult.new(:stdout => "8.5\n", :exit_status => 1) } expect(debian.detect).to include( :family => 'debian', :release => '8.5' ) end it 'Should return ubuntu 16.10 when yakkety is installed.' do allow(debian).to receive(:run_command).with('cat /etc/debian_version') { CommandResult.new(:stdout => "stretch/sid", :exit_status => 0) } allow(debian).to receive(:run_command).with('lsb_release -ir') { CommandResult.new(:stdout => "Distributor ID:Ubuntu\nRelease:16.10\n", :exit_status => 0) } allow(debian).to receive(:run_command).with('cat /etc/lsb-release') { CommandResult.new(:stdout => "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=16.10\nDISTRIB_CODENAME=yakkety\nDISTRIB_DESCRIPTION=\"Ubuntu 16.10\"", :exit_status => 0) } expect(debian.detect).to include( :family => 'ubuntu', :release => '16.10' ) end it 'Should return ubuntu 16.04 when xenial is installed.' do allow(debian).to receive(:run_command).with('cat /etc/debian_version') { CommandResult.new(:stdout => "stretch/sid", :exit_status => 0) } allow(debian).to receive(:run_command).with('lsb_release -ir') { CommandResult.new(:stdout => "Distributor ID:Ubuntu\nRelease:16.04\n", :exit_status => 0) } allow(debian).to receive(:run_command).with('cat /etc/lsb-release') { CommandResult.new(:stdout => "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=16.04\nDISTRIB_CODENAME=xenial\nDISTRIB_DESCRIPTION=\"Ubuntu 16.04.2 LTS\"", :exit_status => 0) } expect(debian.detect).to include( :family => 'ubuntu', :release => '16.04' ) end it 'Should return ubuntu 16.04 when xenial is installed in docker.' do allow(debian).to receive(:run_command).with('cat /etc/debian_version') { CommandResult.new(:stdout => "stretch/sid", :exit_status => 0) } allow(debian).to receive(:run_command).with('lsb_release -ir') { CommandResult.new(:stdout => 'lsb-release is not installed in docker image by default', :exit_status => 1) } allow(debian).to receive(:run_command).with('cat /etc/lsb-release') { CommandResult.new(:stdout => "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=16.04\nDISTRIB_CODENAME=xenial\nDISTRIB_DESCRIPTION=\"Ubuntu 16.04.2 LTS\"", :exit_status => 0) } expect(debian.detect).to include( :family => 'ubuntu', :release => '16.04' ) end end specinfra-2.82.8/spec/helper/detect_os/freebsd_spec.rb0000644000004100000410000000257113614203316022754 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/freebsd' describe Specinfra::Helper::DetectOs::Freebsd do freebsd = Specinfra::Helper::DetectOs::Freebsd.new(:exec) it 'Should return freebsd 10 when FreeBSD 10.1-RELEASE is installed.' do allow(freebsd).to receive(:run_command) { CommandResult.new(:stdout => 'FreeBSD 10.1--RELEASE', :exit_status => 0) } expect(freebsd.detect).to include( :family => 'freebsd', :release => '10' ) end it 'Should return freebsd 9 when FreeBSD 9.3-RELEASE is installed.' do allow(freebsd).to receive(:run_command) { CommandResult.new(:stdout => 'FreeBSD 9.3-RELEASE', :exit_status => 0) } expect(freebsd.detect).to include( :family => 'freebsd', :release => '9' ) end it 'Should return freebsd 8 when FreeBSD 8.2-RELEASE-p3 is installed.' do allow(freebsd).to receive(:run_command) { CommandResult.new(:stdout => 'FreeBSD 8.2-RELEASE-p3', :exit_status => 0) } expect(freebsd.detect).to include( :family => 'freebsd', :release => '8' ) end it 'Should return freebsd nil when FreeBSD FooBar is installed.' do allow(freebsd).to receive(:run_command) { CommandResult.new(:stdout => 'FreeBSD FooBar', :exit_status => 0) } expect(freebsd.detect).to include( :family => 'freebsd', :release => nil ) end end specinfra-2.82.8/spec/helper/detect_os/suse_spec.rb0000644000004100000410000000430013614203316022311 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/suse' describe Specinfra::Helper::DetectOs::Suse do suse = Specinfra::Helper::DetectOs::Suse.new(:exec) it 'Should return opensuse 42.2 when openSUSE 42.2 is installed.' do allow(suse).to receive(:run_command) { CommandResult.new(:stdout => "NAME=\"openSUSE Leap\"\nVERSION=\"42.2\"\nID=opensuse\nID_LIKE=\"suse\"\nVERSION_ID=\"42.2\"\nPRETTY_NAME=\"openSUSE Leap 42.2\"\nANSI_COLOR=\"0;32\"\nCPE_NAME=\"cpe:/o:opensuse:leap:42.2\"\nBUG_REPORT_URL=\"https://bugs.opensuse.org\"\nHOME_URL=\"https://www.opensuse.org/\"\n", :exit_status => 0) } expect(suse.detect).to include( :family => 'opensuse', :release => '42.2' ) end it 'Should return opensuse 13.2 when openSUSE 13.2 is installed.' do allow(suse).to receive(:run_command) { CommandResult.new(:stdout => "NAME=openSUSE\nVERSION=\"13.2 (Harlequin)\"\nVERSION_ID=\"13.2\"\nPRETTY_NAME=\"openSUSE 13.2 (Harlequin) (x86_64)\"\nID=opensuse\nANSI_COLOR=\"0;32\"\nCPE_NAME=\"cpe:/o:opensuse:opensuse:13.2\"\nBUG_REPORT_URL=\"https://bugs.opensuse.org\"\nHOME_URL=\"https://opensuse.org/\"\nID_LIKE=\"suse\"\n", :exit_status => 0) } expect(suse.detect).to include( :family => 'opensuse', :release => '13.2' ) end it 'Should return sles 12.2 when SUSE Linux Enterprise Server 12.2 is installed.' do allow(suse).to receive(:run_command) { CommandResult.new(:stdout => "NAME=\"SLES\"\nVERSION=\"12.2\"\nVERSION_ID=\"12.2\"\nPRETTY_NAME=\"SUSE Linux Enterprise Server 12\"\nID=\"sles\"\nANSI_COLOR=\"0;32\"\nCPE_NAME=\"cpe:/o:suse:sles:12\"\n", :exit_status => 0) } expect(suse.detect).to include( :family => 'sles', :release => '12.2' ) end it 'Should return sles 11.4 when SUSE Linux Enterprise Server 11.4 is installed.' do allow(suse).to receive(:run_command) { CommandResult.new(:stdout => "NAME=\"SLES\"\nVERSION=\"11.4\"\nVERSION_ID=\"11.4\"\nPRETTY_NAME=\"SUSE Linux Enterprise Server 11 SP4\"\nID=\"sles\"\nANSI_COLOR=\"0;32\"\nCPE_NAME=\"cpe:/o:suse:sles:11:4\"", :exit_status => 0) } expect(suse.detect).to include( :family => 'sles', :release => '11.4' ) end end specinfra-2.82.8/Rakefile0000644000004100000410000000215313614203316015262 0ustar www-datawww-datarequire "bundler/gem_tasks" begin require "rspec/core/rake_task" require "octorelease" rescue LoadError end if defined?(RSpec) task :spec => 'spec:all' task :default => 'spec:all' namespace :spec do task :all => [ :helper, :backend, :configuration, :processor, :command, :host_inventory ] RSpec::Core::RakeTask.new(:helper) do |t| t.pattern = "spec/helper/**/*_spec.rb" end task :backend => 'backend:all' namespace :backend do backends = %w[exec ssh] task :all => backends backends.each do |backend| RSpec::Core::RakeTask.new(backend) do |t| t.pattern = "spec/backend/#{backend}/*_spec.rb" end end end RSpec::Core::RakeTask.new(:configuration) do |t| t.pattern = "spec/configuration_spec.rb" end RSpec::Core::RakeTask.new(:processor) do |t| t.pattern = "spec/processor_spec.rb" end RSpec::Core::RakeTask.new(:command) do |t| t.pattern = "spec/command/**/*.rb" end RSpec::Core::RakeTask.new(:host_inventory) do |t| t.pattern = "spec/host_inventory/**/*_spec.rb" end end end specinfra-2.82.8/lib/0000755000004100000410000000000013614203316014362 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/0000755000004100000410000000000013614203316016334 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/runner.rb0000644000004100000410000000145613614203316020200 0ustar www-datawww-datamodule Specinfra class Runner def self.method_missing(meth, *args) backend = Specinfra.backend processor = Specinfra::Processor if ! os.include?(:family) || os[:family] != 'windows' if processor.respond_to?(meth) processor.send(meth, *args) elsif backend.respond_to?(meth) backend.send(meth, *args) else run(meth, *args) end else if backend.respond_to?(meth) backend.send(meth, *args) else run(meth, *args) end end end private def self.run(meth, *args) cmd = Specinfra.command.get(meth, *args) ret = Specinfra.backend.run_command(cmd) if meth.to_s =~ /^check/ ret.success? else ret end end end end specinfra-2.82.8/lib/specinfra/version.rb0000644000004100000410000000005213614203316020343 0ustar www-datawww-datamodule Specinfra VERSION = "2.82.8" end specinfra-2.82.8/lib/specinfra/command/0000755000004100000410000000000013614203316017752 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/coreos/0000755000004100000410000000000013614203316021244 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/coreos/base.rb0000644000004100000410000000011513614203316022500 0ustar www-datawww-dataclass Specinfra::Command::Coreos::Base < Specinfra::Command::Linux::Base end specinfra-2.82.8/lib/specinfra/command/coreos/base/0000755000004100000410000000000013614203316022156 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/coreos/base/service.rb0000644000004100000410000000024513614203316024144 0ustar www-datawww-dataclass Specinfra::Command::Coreos::Base::Service < Specinfra::Command::Linux::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.82.8/lib/specinfra/command/esxi/0000755000004100000410000000000013614203316020722 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/esxi/base.rb0000644000004100000410000000011313614203316022154 0ustar www-datawww-dataclass Specinfra::Command::Esxi::Base < Specinfra::Command::Linux::Base end specinfra-2.82.8/lib/specinfra/command/esxi/base/0000755000004100000410000000000013614203316021634 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/esxi/base/package.rb0000644000004100000410000000051713614203316023557 0ustar www-datawww-dataclass Specinfra::Command::Esxi::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) cmd = "esxcli software vib list | grep -w -- #{escape(package)}" if version cmd = "#{cmd} | grep -w -- #{escape(version)}" end cmd end end end specinfra-2.82.8/lib/specinfra/command/opensuse/0000755000004100000410000000000013614203316021613 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/opensuse/base.rb0000644000004100000410000000011713614203316023051 0ustar www-datawww-dataclass Specinfra::Command::Opensuse::Base < Specinfra::Command::Suse::Base end specinfra-2.82.8/lib/specinfra/command/opensuse/base/0000755000004100000410000000000013614203316022525 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/opensuse/base/service.rb0000644000004100000410000000054113614203316024512 0ustar www-datawww-dataclass Specinfra::Command::Opensuse::Base::Service < Specinfra::Command::Suse::Base::Service class << self include Specinfra::Command::Module::Systemd def check_is_running(service) "service #{escape(service)} status" end def check_is_enabled(service, level=nil) "systemctl is-enabled #{escape(service)}" end end end specinfra-2.82.8/lib/specinfra/command/ubuntu/0000755000004100000410000000000013614203316021274 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/ubuntu/v15/0000755000004100000410000000000013614203316021707 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/ubuntu/v15/service.rb0000644000004100000410000000024513614203316023675 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu::V15::Service < Specinfra::Command::Ubuntu::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.82.8/lib/specinfra/command/ubuntu/base.rb0000644000004100000410000000011613614203316022531 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu::Base < Specinfra::Command::Debian::Base end specinfra-2.82.8/lib/specinfra/command/ubuntu/v18/0000755000004100000410000000000013614203316021712 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/ubuntu/v18/port.rb0000644000004100000410000000023213614203316023220 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu::V18::Port < Specinfra::Command::Ubuntu::Base::Port class << self include Specinfra::Command::Module::Ss end end specinfra-2.82.8/lib/specinfra/command/ubuntu/base/0000755000004100000410000000000013614203316022206 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/ubuntu/base/ppa.rb0000644000004100000410000000102213614203316023306 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu::Base::Ppa < Specinfra::Command::Debian::Base::Ppa class << self def check_exists(package) %Q{find /etc/apt/ -name \*.list | xargs grep -o -E "deb +[\\"']?http://ppa.launchpad.net/#{to_apt_line_uri(package)}"} end def check_is_enabled(package) %Q{find /etc/apt/ -name \*.list | xargs grep -o -E "^deb +[\\"']?http://ppa.launchpad.net/#{to_apt_line_uri(package)}"} end private def to_apt_line_uri(repo) escape(repo.gsub(/^ppa:/,'')) end end end specinfra-2.82.8/lib/specinfra/command/ubuntu/base/port.rb0000644000004100000410000000042013614203316023513 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu::Base::Port < Specinfra::Command::Linux::Base::Port class << self def create(os_info=nil) if (os_info || os)[:release].to_i < 18 self else Specinfra::Command::Ubuntu::V18::Port end end end end specinfra-2.82.8/lib/specinfra/command/ubuntu/base/service.rb0000644000004100000410000000065513614203316024201 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu::Base::Service < Specinfra::Command::Debian::Base::Service class << self def check_is_running(service) "service #{escape(service)} status && service #{escape(service)} status | egrep 'running|online'" end def create(os_info=nil) if (os_info || os)[:release].to_i < 15 self else Specinfra::Command::Ubuntu::V15::Service end end end end specinfra-2.82.8/lib/specinfra/command/ubuntu/v15.rb0000644000004100000410000000011613614203316022232 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu::V15 < Specinfra::Command::Ubuntu::Base; end specinfra-2.82.8/lib/specinfra/command/ubuntu/v18.rb0000644000004100000410000000011613614203316022235 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu::V18 < Specinfra::Command::Ubuntu::Base; end specinfra-2.82.8/lib/specinfra/command/debian.rb0000644000004100000410000000004613614203316021521 0ustar www-datawww-dataclass Specinfra::Command::Debian; end specinfra-2.82.8/lib/specinfra/command/windows.rb0000644000004100000410000000004713614203316021772 0ustar www-datawww-dataclass Specinfra::Command::Windows; end specinfra-2.82.8/lib/specinfra/command/linux/0000755000004100000410000000000013614203316021111 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/linux/base.rb0000644000004100000410000000010513614203316022344 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/linux/base/0000755000004100000410000000000013614203316022023 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/linux/base/iptables.rb0000644000004100000410000000053713614203316024160 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Iptables < Specinfra::Command::Base::Iptables class << self def check_has_rule(rule, table=nil, chain=nil) cmd = "iptables" cmd += " -t #{escape(table)}" if table cmd += " -S" cmd += " #{escape(chain)}" if chain cmd += " | grep -- #{escape(rule)}" cmd end end end specinfra-2.82.8/lib/specinfra/command/linux/base/interface.rb0000644000004100000410000000233313614203316024311 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Interface < Specinfra::Command::Base::Interface class << self def check_exists(name) "ip link show #{name}" end def get_speed_of(name) "cat /sys/class/net/#{name}/speed" end def get_mtu_of(name) "cat /sys/class/net/#{name}/mtu" end def check_has_ipv4_address(interface, ip_address) ip_address = ip_address.dup if ip_address =~ /\/\d+$/ ip_address << " " else ip_address << "/" end ip_address.gsub!(".", "\\.") "ip -4 addr show #{interface} | grep 'inet #{ip_address}'" end def check_has_ipv6_address(interface, ip_address) ip_address = ip_address.dup if ip_address =~ /\/\d+$/ ip_address << " " else ip_address << "/" end ip_address.downcase! "ip -6 addr show #{interface} | grep 'inet6 #{ip_address}'" end def get_ipv4_address(interface) "ip -4 addr show #{interface} | grep #{interface}$ | awk '{print $2}'" end def get_ipv6_address(interface) "ip -6 addr show #{interface} | grep inet6 | awk '{print $2}'" end def get_link_state(name) "cat /sys/class/net/#{name}/operstate" end end end specinfra-2.82.8/lib/specinfra/command/linux/base/selinux_module.rb0000644000004100000410000000074513614203316025412 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::SelinuxModule < Specinfra::Command::Base::SelinuxModule class << self def check_is_installed(name, version=nil) cmd = "semodule -l | grep $'^#{escape(name)}\\t" cmd += "#{escape(version)}\\t" unless version.nil? cmd += "'" cmd end def check_is_enabled(name) cmd = "semodule -l | grep $'^#{escape(name)}\\t'" cmd += " | grep -v $'^#{escape(name)}\\t.*\\tDisabled$'" cmd end end end specinfra-2.82.8/lib/specinfra/command/linux/base/yumrepo.rb0000644000004100000410000000012713614203316024050 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Yumrepo < Specinfra::Command::Base::Yumrepo end specinfra-2.82.8/lib/specinfra/command/linux/base/kernel_module.rb0000644000004100000410000000027313614203316025177 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::KernelModule < Specinfra::Command::Base::KernelModule class << self def check_is_loaded(name) "lsmod | grep ^#{name}" end end end specinfra-2.82.8/lib/specinfra/command/linux/base/lxc_container.rb0000644000004100000410000000104713614203316025202 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::LxcContainer < Specinfra::Command::Base::LxcContainer class << self def check_exists(container) [ "lxc-ls -1 | grep -w #{escape(container)}", "virsh -c lxc:/// list --all --name | grep -w '^#{escape(container)}$'" ].join(' || ') end def check_is_running(container) [ "lxc-info -n #{escape(container)} -s | grep -w RUNNING", "virsh -c lxc:/// list --all --name --state-running | grep -w '^#{escape(container)}$'" ].join(' || ') end end end specinfra-2.82.8/lib/specinfra/command/linux/base/fstab.rb0000644000004100000410000000043313614203316023447 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Fstab < Specinfra::Command::Base::Fstab class << self def check_has_entry(mount_point) %Q(awk '{if($2=="#{escape(mount_point)}")print}' /etc/fstab | grep -v '^[[:space:]]*#') end alias :get_entry :check_has_entry end end specinfra-2.82.8/lib/specinfra/command/linux/base/ppa.rb0000644000004100000410000000011713614203316023127 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Ppa < Specinfra::Command::Base::Ppa end specinfra-2.82.8/lib/specinfra/command/linux/base/bridge.rb0000644000004100000410000000042313614203316023603 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Bridge < Specinfra::Command::Base::Bridge class << self def check_exists(name) "ip link show #{name}" end def check_has_interface(name, interface) "brctl show #{name} | grep -o #{interface}" end end end specinfra-2.82.8/lib/specinfra/command/linux/base/package.rb0000644000004100000410000000012713614203316023743 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Package < Specinfra::Command::Base::Package end specinfra-2.82.8/lib/specinfra/command/linux/base/zfs.rb0000644000004100000410000000022113614203316023145 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Zfs < Specinfra::Command::Base::Zfs class << self include Specinfra::Command::Module::Zfs end end specinfra-2.82.8/lib/specinfra/command/linux/base/kvm_guest.rb0000644000004100000410000000073413614203316024360 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::KvmGuest < Specinfra::Command::Base::KvmGuest class << self def check_exists(guest) "virsh -c qemu:///system list --all --name | grep -w '^#{escape(guest)}$'" end def check_is_running(guest) "virsh -c qemu:///system list --name | grep -w '^#{escape(guest)}$'" end def check_is_enabled(guest) "virsh -c qemu:///system dominfo #{escape(guest)} | grep -E '^Autostart:\s+enable$'" end end end specinfra-2.82.8/lib/specinfra/command/linux/base/bond.rb0000644000004100000410000000044713614203316023277 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Bond < Specinfra::Command::Base::Bond class << self def check_exists(name) "ip link show #{name}" end def check_has_interface(name, interface) "grep -o 'Slave Interface: #{interface}' /proc/net/bonding/#{name}" end end end specinfra-2.82.8/lib/specinfra/command/linux/base/file.rb0000644000004100000410000000103313614203316023264 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::File < Specinfra::Command::Base::File class << self def check_is_accessible_by_user(file, user, access) "sudo -u #{user} test -#{access} #{file}" end def check_is_immutable(file) check_attribute(file, 'i') end def check_attribute(file, attribute) "lsattr -d #{escape(file)} 2>&1 | " + "awk '$1~/^[A-Za-z-]+$/ && $1~/#{escape(attribute)}/ {exit 0} {exit 1}'" end def get_selinuxlabel(file) "stat -c %C #{escape(file)}" end end end specinfra-2.82.8/lib/specinfra/command/linux/base/service.rb0000644000004100000410000000012713614203316024010 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Service < Specinfra::Command::Base::Service end specinfra-2.82.8/lib/specinfra/command/linux/base/inventory.rb0000644000004100000410000000147113614203316024410 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Inventory < Specinfra::Command::Base::Inventory class << self def get_memory 'cat /proc/meminfo' end def get_cpu 'cat /proc/cpuinfo' end def get_hostname 'hostname -s' end def get_domain 'dnsdomainname' end def get_fqdn 'hostname -f' end def get_filesystem 'df -P' end def get_kernel 'uname -s -r' end def get_block_device block_device_dirs = '/sys/block/*/{size,removable,device/{model,rev,state,timeout,vendor},queue/rotational}' "for f in $(ls #{block_device_dirs}); do echo -e \"${f}\t$(cat ${f})\"; done" end def get_system_product_name "dmidecode -s system-product-name" end def get_mount 'cat /proc/mounts' end end end specinfra-2.82.8/lib/specinfra/command/linux/base/ip6tables.rb0000644000004100000410000000073313614203316024244 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Ip6tables < Specinfra::Command::Base::Ip6tables class << self def check_has_rule(rule, table=nil, chain=nil) cmd = "ip6tables" cmd += " -t #{escape(table)}" if table cmd += " -S" cmd += " #{escape(chain)}" if chain cmd += " | grep -- #{escape(rule)}" cmd += " || ip6tables-save" cmd += " -t #{escape(table)}" if table cmd += " | grep -- #{escape(rule)}" cmd end end end specinfra-2.82.8/lib/specinfra/command/linux/base/selinux.rb0000644000004100000410000000233413614203316024041 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Selinux < Specinfra::Command::Base::Selinux class << self def check_has_mode(mode, policy = nil) cmd = "" # If disabled, then the absence of /etc/selinux/config is sufficient cmd += "test ! -f /etc/selinux/config || " if mode == "disabled" # If disabled, wrap the rest of the test in parentheses # i.e. only test this stuff if /etc/selinux/config exists cmd += "( ( " if mode == "disabled" # Does getenforce return the same value as we are checking for? cmd += "(getenforce | grep -i -- #{escape(mode)})" # If disabled, then permissive is considered a pass cmd += " || (getenforce | grep -i -- #{escape('permissive')}) )" if mode == "disabled" # Ensure that /etc/selinux/config contains the mode we specify cmd += %Q{ && grep -iE -- '^\\s*SELINUX=#{escape(mode)}\\>' /etc/selinux/config} # If we have specified a policy, ensure that is included in /etc/selinux/config cmd += %Q{ && grep -iE -- '^\\s*SELINUXTYPE=#{escape(policy)}\\>' /etc/selinux/config} if policy != nil # End parenthesis for tests when /etc/selinux/config exists cmd += ")" if mode == "disabled" cmd end end end specinfra-2.82.8/lib/specinfra/command/debian/0000755000004100000410000000000013614203316021174 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/debian/base.rb0000644000004100000410000000012613614203316022432 0ustar www-datawww-dataclass Specinfra::Command::Debian::Base < Specinfra::Command::Linux::Base end specinfra-2.82.8/lib/specinfra/command/debian/v8/0000755000004100000410000000000013614203316021531 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/debian/v8/port.rb0000644000004100000410000000023113614203316023036 0ustar www-datawww-dataclass Specinfra::Command::Debian::V8::Port < Specinfra::Command::Debian::Base::Port class << self include Specinfra::Command::Module::Ss end end specinfra-2.82.8/lib/specinfra/command/debian/v8/service.rb0000644000004100000410000000065013614203316023517 0ustar www-datawww-dataclass Specinfra::Command::Debian::V8::Service < Specinfra::Command::Debian::Base::Service class << self include Specinfra::Command::Module::Systemd def check_is_enabled_under_systemd(service, level=nil) [ super(service), "ls /etc/rc[S5].d/S??#{escape(service)} >/dev/null 2>/dev/null" ].join('||') end alias_method :check_is_enabled, :check_is_enabled_under_systemd end end specinfra-2.82.8/lib/specinfra/command/debian/base/0000755000004100000410000000000013614203316022106 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/debian/base/ppa.rb0000644000004100000410000000012713614203316023213 0ustar www-datawww-dataclass Specinfra::Command::Debian::Base::Ppa < Specinfra::Command::Linux::Base::Ppa end specinfra-2.82.8/lib/specinfra/command/debian/base/package.rb0000644000004100000410000000223513614203316024030 0ustar www-datawww-dataclass Specinfra::Command::Debian::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) escaped_package = escape(package) if version cmd = "dpkg-query -f '${Status} ${Version}' -W #{escaped_package} | grep -E '^(install|hold) ok installed #{Regexp.escape(version)}$'" else cmd = "dpkg-query -f '${Status}' -W #{escaped_package} | grep -E '^(install|hold) ok installed$'" end cmd end alias :check_is_installed_by_apt :check_is_installed def install(package, version=nil, option='') if version full_package = "#{package}=#{version}" else full_package = package end "DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' #{option} install #{escape(full_package)}" end def get_version(package, opts=nil) "dpkg-query -f '${Status} ${Version}' -W #{package} | sed -n 's/^install ok installed //p'" end def remove(package, option='') "DEBIAN_FRONTEND='noninteractive' apt-get -y #{option} remove #{package}" end end end specinfra-2.82.8/lib/specinfra/command/debian/base/port.rb0000644000004100000410000000041613614203316023420 0ustar www-datawww-dataclass Specinfra::Command::Debian::Base::Port < Specinfra::Command::Linux::Base::Port class << self def create(os_info=nil) if (os_info || os)[:release].to_i < 8 self else Specinfra::Command::Debian::V8::Port end end end end specinfra-2.82.8/lib/specinfra/command/debian/base/service.rb0000644000004100000410000000171313614203316024075 0ustar www-datawww-dataclass Specinfra::Command::Debian::Base::Service < Specinfra::Command::Linux::Base::Service class << self def create(os_info=nil) if (os_info || os)[:release].to_i < 8 self else Specinfra::Command::Debian::V8::Service end end def check_is_enabled(service, level=3) # Until everything uses Upstart, this needs an OR. "ls /etc/rc#{level}.d/ | grep -- '^S..#{escape(service)}$' || grep '^\s*start on' /etc/init/#{escape(service)}.conf" end def enable(service) "update-rc.d #{escape(service)} defaults" end def disable(service) "update-rc.d -f #{escape(service)} remove" end def start(service) "service #{escape(service)} start" end def stop(service) "service #{escape(service)} stop" end def restart(service) "service #{escape(service)} restart" end def reload(service) "service #{escape(service)} reload" end end end specinfra-2.82.8/lib/specinfra/command/debian/v8.rb0000644000004100000410000000011413614203316022052 0ustar www-datawww-dataclass Specinfra::Command::Debian::V8 < Specinfra::Command::Debian::Base end specinfra-2.82.8/lib/specinfra/command/esxi.rb0000644000004100000410000000004413614203316021245 0ustar www-datawww-dataclass Specinfra::Command::Esxi; end specinfra-2.82.8/lib/specinfra/command/opensuse.rb0000644000004100000410000000005013614203316022133 0ustar www-datawww-dataclass Specinfra::Command::Opensuse; end specinfra-2.82.8/lib/specinfra/command/redhat.rb0000644000004100000410000000004513614203316021545 0ustar www-datawww-dataclass Specinfra::Command::Redhat;end specinfra-2.82.8/lib/specinfra/command/linuxmint/0000755000004100000410000000000013614203316022001 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/linuxmint/base.rb0000644000004100000410000000012113614203316023232 0ustar www-datawww-dataclass Specinfra::Command::Linuxmint::Base < Specinfra::Command::Ubuntu::Base end specinfra-2.82.8/lib/specinfra/command/nixos.rb0000644000004100000410000000004513614203316021436 0ustar www-datawww-dataclass Specinfra::Command::Nixos; end specinfra-2.82.8/lib/specinfra/command/suse.rb0000644000004100000410000000004413614203316021254 0ustar www-datawww-dataclass Specinfra::Command::Suse; end specinfra-2.82.8/lib/specinfra/command/arch/0000755000004100000410000000000013614203316020667 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/arch/base.rb0000644000004100000410000000012413614203316022123 0ustar www-datawww-dataclass Specinfra::Command::Arch::Base < Specinfra::Command::Linux::Base end specinfra-2.82.8/lib/specinfra/command/arch/base/0000755000004100000410000000000013614203316021601 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/arch/base/package.rb0000644000004100000410000000161513614203316023524 0ustar www-datawww-dataclass Specinfra::Command::Arch::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package,version=nil) if version grep = version.include?('-') ? "^#{escape(version)}$" : "^#{escape(version)}-" "pacman -Q #{escape(package)} | awk '{print $2}' | grep '#{grep}'" else "pacman -Q #{escape(package)} || pacman -Qg #{escape(package)}" end end def get_version(package, opts=nil) "pacman -Qi #{package} | grep Version | awk '{print $3}'" end def install(package, version=nil, option='') # Pacman doesn't support to install specific version. "pacman -S --noconfirm #{option} #{package}" end # Should this method be here or not ? def sync_repos "pacman -Syy" end def remove(package, option='') "pacman -R --noconfirm #{option} #{package}" end end end specinfra-2.82.8/lib/specinfra/command/arch/base/service.rb0000644000004100000410000000024313614203316023565 0ustar www-datawww-dataclass Specinfra::Command::Arch::Base::Service < Specinfra::Command::Linux::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.82.8/lib/specinfra/command/plamo/0000755000004100000410000000000013614203316021062 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/plamo/base.rb0000644000004100000410000000011513614203316022316 0ustar www-datawww-dataclass Specinfra::Command::Plamo::Base < Specinfra::Command::Linux::Base end specinfra-2.82.8/lib/specinfra/command/plamo/base/0000755000004100000410000000000013614203316021774 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/plamo/base/package.rb0000644000004100000410000000061013614203316023711 0ustar www-datawww-dataclass Specinfra::Command::Plamo::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) cmd = "ls /var/log/packages/#{escape(package)}" if version cmd = "#{cmd} && grep -E \"PACKAGE NAME:.+#{escape(package)}-#{escape(version)}\" /var/log/packages/#{escape(package)}" end cmd end end end specinfra-2.82.8/lib/specinfra/command/plamo/base/service.rb0000644000004100000410000000053513614203316023764 0ustar www-datawww-dataclass Specinfra::Command::Plamo::Base::Service < Specinfra::Command::Linux::Base::Service class << self def check_is_enabled(service, level=3) # This check is not necessarily detected whether service is enabled or not # TODO: check rc.inet2 $SERV variable "test -x /etc/rc.d/init.d/#{escape(service)}" end end end specinfra-2.82.8/lib/specinfra/command/gentoo/0000755000004100000410000000000013614203316021245 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/gentoo/base.rb0000644000004100000410000000011513614203316022501 0ustar www-datawww-dataclass Specinfra::Command::Gentoo::Base < Specinfra::Command::Linux::Base end specinfra-2.82.8/lib/specinfra/command/gentoo/base/0000755000004100000410000000000013614203316022157 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/gentoo/base/package.rb0000644000004100000410000000125013614203316024075 0ustar www-datawww-dataclass Specinfra::Command::Gentoo::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) "eix #{escape(package)} --installed | grep -v \"No matches found\"" end def get_version(package, opts=nil) "equery -q list #{package} | sed -e 's!^.*/?#{package}-!!'" end def install(package, version=nil, option='') if version full_package = "=#{package}-#{version}" else full_package = package end cmd = "emerge #{option} #{full_package}" end def remove(package, option='') cmd = "emerge --unmerge #{option} #{package}" end end end specinfra-2.82.8/lib/specinfra/command/gentoo/base/service.rb0000644000004100000410000000056013614203316024145 0ustar www-datawww-dataclass Specinfra::Command::Gentoo::Base::Service < Specinfra::Command::Linux::Base::Service class << self def check_is_enabled(service, level=3) regexp = /\s*#{service}\s*\|\s*(boot|default)/ "rc-update show | grep -- #{escape(regexp)}" end def check_is_running(service) "/etc/init.d/#{escape(service)} status" end end end specinfra-2.82.8/lib/specinfra/command/elementary/0000755000004100000410000000000013614203316022117 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/elementary/base.rb0000644000004100000410000000012213614203316023351 0ustar www-datawww-dataclass Specinfra::Command::Elementary::Base < Specinfra::Command::Ubuntu::Base end specinfra-2.82.8/lib/specinfra/command/fedora/0000755000004100000410000000000013614203316021212 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/fedora/v15/0000755000004100000410000000000013614203316021625 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/fedora/v15/service.rb0000644000004100000410000000024513614203316023613 0ustar www-datawww-dataclass Specinfra::Command::Fedora::V15::Service < Specinfra::Command::Fedora::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.82.8/lib/specinfra/command/fedora/base.rb0000644000004100000410000000011613614203316022447 0ustar www-datawww-dataclass Specinfra::Command::Fedora::Base < Specinfra::Command::Redhat::Base end specinfra-2.82.8/lib/specinfra/command/fedora/base/0000755000004100000410000000000013614203316022124 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/fedora/base/service.rb0000644000004100000410000000043213614203316024110 0ustar www-datawww-dataclass Specinfra::Command::Fedora::Base::Service < Specinfra::Command::Redhat::Base::Service class << self def create(os_info=nil) if (os_info || os)[:release].to_i < 15 self else Specinfra::Command::Fedora::V15::Service end end end end specinfra-2.82.8/lib/specinfra/command/fedora/v15.rb0000644000004100000410000000011513614203316022147 0ustar www-datawww-dataclass Specinfra::Command::Fedora::V15 < Specinfra::Command::Fedora::Base end specinfra-2.82.8/lib/specinfra/command/openbsd.rb0000644000004100000410000000004713614203316021732 0ustar www-datawww-dataclass Specinfra::Command::Openbsd; end specinfra-2.82.8/lib/specinfra/command/aix/0000755000004100000410000000000013614203316020533 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/aix/base.rb0000644000004100000410000000010313614203316021764 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/aix/base/0000755000004100000410000000000013614203316021445 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/aix/base/group.rb0000644000004100000410000000045613614203316023133 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base::Group < Specinfra::Command::Base::Group class << self def check_exists(group) "lsgroup #{escape(group)}" end def check_has_gid(group, gid) "lsgroup -a id #{escape(group)} | cut -f 2 -d '=' | grep -w -- #{escape(gid)}" end end end specinfra-2.82.8/lib/specinfra/command/aix/base/user.rb0000644000004100000410000000112013614203316022742 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base::User < Specinfra::Command::Base::User class << self def check_belongs_to_group(user, group) "lsuser -a groups #{escape(user)} | awk -F'=' '{print $2}'| sed -e 's/,/ /g' |grep -w -- #{escape(group)}" end def check_has_login_shell(user, path_to_shell) "lsuser -a shell #{escape(user)} |awk -F'=' '{print $2}' | grep -w -- #{escape(path_to_shell)}" end def check_has_home_directory(user, path_to_home) "lsuser -a home #{escape(user)} | awk -F'=' '{print $2}' | grep -w -- #{escape(path_to_home)}" end end end specinfra-2.82.8/lib/specinfra/command/aix/base/package.rb0000644000004100000410000000050213614203316023362 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base::Package < Specinfra::Command::Base::Package class << self def check_is_installed(package, version=nil) if version "lslpp -L #{escape(package)} | awk '{print $2}' | grep -w -- #{version}" else "lslpp -L #{escape(package)}" end end end end specinfra-2.82.8/lib/specinfra/command/aix/base/port.rb0000644000004100000410000000037213614203316022760 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base::Port < Specinfra::Command::Base::Port class << self def check_is_listening(port, options={}) regexp = "*.#{port} " "netstat -an -f inet | awk '{print $4}' | grep -- #{regexp}" end end end specinfra-2.82.8/lib/specinfra/command/aix/base/file.rb0000644000004100000410000000116713614203316022716 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base::File < Specinfra::Command::Base::File class << self def check_is_accessible_by_user(file, user, access) "su -s sh -c \"test -#{access} #{file}\" #{user}" end def check_has_mode(file, mode) "find #{file} -prune -perm #{mode} | grep ^#{file}$" end def check_is_owned_by(file, owner) regexp = "^#{owner}$" "ls -al #{escape(file)} | awk '{print $3}' | grep -- #{escape(regexp)}" end def check_is_grouped(file, group) regexp = "^#{group}$" "ls -al #{escape(file)} | awk '{print $4}' | grep -- #{escape(regexp)}" end end end specinfra-2.82.8/lib/specinfra/command/aix/base/service.rb0000644000004100000410000000046413614203316023436 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base::Service < Specinfra::Command::Base::Service class << self def check_is_enabled(service,level=nil) "lssrc -s #{escape(service)} | grep active" end def check_is_running(service) "ps -ef | grep -v grep | grep #{escape(service)}" end end end specinfra-2.82.8/lib/specinfra/command/aix/base/inventory.rb0000644000004100000410000000202213614203316024023 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base::Inventory < Specinfra::Command::Base::Inventory class << self def get_memory 'false' end def get_cpu 'false' end def get_hostname 'uname -n' end def get_domain # This is emulating the dnsdomainname command in Linux # Requires proper configuration of /etc/resolv.conf # and DNS. # The exit at the end is to only return one entry if # the host is running in dualstack mode (IPv4 and IPv6) 'host -n `uname -n` | ' + 'awk -v h=`uname -n` \'$1 ~ h { sub(h".", "", $1); print $1; exit }\'' end def get_fqdn # This is emulating the hostname -f command in Linux # Requires proper configuration of /etc/resolv.conf # and DNS. # The exit at the end is to only return one entry if # the host is running in dualstack mode (IPv4 and IPv6) 'host -n `uname -n` | awk -v h=`uname -n` \'$1 ~ h"." { print $1; exit }\'' end def get_filesystem 'df -kP' end end end specinfra-2.82.8/lib/specinfra/command/aix/base/host.rb0000644000004100000410000000105513614203316022750 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base::Host < Specinfra::Command::Base::Host class << self def check_is_resolvable(name, type) if type == "dns" %Q[lookup=$(nslookup -timeout=1 #{escape(name)} | grep -A1 'Name:' | grep Address | awk -F': ' '{print $2}'); if [ "$lookup" ]; then $(exit 0); else $(exit 1); fi] elsif type == "hosts" "grep -w -- #{escape(name)} /etc/hosts" else "host #{escape(name)}" end end def get_ipaddress(name) "host #{escape(name)} | awk '{print $3}'" end end end specinfra-2.82.8/lib/specinfra/command/elementary.rb0000644000004100000410000000005213614203316022441 0ustar www-datawww-dataclass Specinfra::Command::Elementary; end specinfra-2.82.8/lib/specinfra/command/suse/0000755000004100000410000000000013614203316020731 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/suse/base.rb0000644000004100000410000000011313614203316022163 0ustar www-datawww-dataclass Specinfra::Command::Suse::Base < Specinfra::Command::Linux::Base end specinfra-2.82.8/lib/specinfra/command/suse/base/0000755000004100000410000000000013614203316021643 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/suse/base/package.rb0000644000004100000410000000110513614203316023560 0ustar www-datawww-dataclass Specinfra::Command::Suse::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package,version=nil) cmd = "rpm -q #{escape(package)}" if version cmd = "#{cmd} | grep -w -- #{escape(version)}" end cmd end alias :check_is_installed_by_rpm :check_is_installed def install(package, version=nil, option='') cmd = "zypper -n #{option} install #{package}" end def get_version(package, opts=nil) "rpm -qi #{package} | grep Version | awk '{print $3}'" end end end specinfra-2.82.8/lib/specinfra/command/suse/base/service.rb0000644000004100000410000000035413614203316023632 0ustar www-datawww-dataclass Specinfra::Command::Suse::Base::Service < Specinfra::Command::Linux::Base::Service class << self def check_is_enabled(service, level=3) "chkconfig --list #{escape(service)} | grep #{level}:on" end end end specinfra-2.82.8/lib/specinfra/command/freebsd.rb0000644000004100000410000000004713614203316021712 0ustar www-datawww-dataclass Specinfra::Command::Freebsd; end specinfra-2.82.8/lib/specinfra/command/smartos/0000755000004100000410000000000013614203316021442 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/smartos/base.rb0000644000004100000410000000012113614203316022673 0ustar www-datawww-dataclass Specinfra::Command::Smartos::Base < Specinfra::Command::Solaris::Base end specinfra-2.82.8/lib/specinfra/command/smartos/base/0000755000004100000410000000000013614203316022354 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/smartos/base/package.rb0000644000004100000410000000064013614203316024274 0ustar www-datawww-dataclass Specinfra::Command::Smartos::Base::Package < Specinfra::Command::Solaris::Base::Package class << self def check_is_installed(package, version=nil) cmd = "pkg_info -qE #{escape(package)}" if version cmd = "#{cmd}-#{escape(version)}" end cmd end def get_version(package, opts=nil) "pkg_info -E #{escape(package)} | awk -F '-' '{print $NF}'" end end end specinfra-2.82.8/lib/specinfra/command/smartos/base/file.rb0000644000004100000410000000054113614203316023620 0ustar www-datawww-dataclass Specinfra::Command::Smartos::Base::File < Specinfra::Command::Solaris::Base::File class << self def get_md5sum(file) "/usr/bin/digest -a md5 -v #{escape(file)} | cut -d '=' -f 2 | cut -c 2-" end def get_sha256sum(file) "/usr/bin/digest -a sha256 -v #{escape(file)} | cut -d '=' -f 2 | cut -c 2-" end end end specinfra-2.82.8/lib/specinfra/command/smartos/base/service.rb0000644000004100000410000000057613614203316024351 0ustar www-datawww-dataclass Specinfra::Command::Smartos::Base::Service < Specinfra::Command::Solaris::Base::Service class << self def check_is_enabled(service, level=nil) "svcs -l #{escape(service)} 2>/dev/null | grep '^enabled *true$' >/dev/null" end def check_is_running(service) "svcs -Ho state #{escape(service)} 2>/dev/null |grep '^online$' >/dev/null" end end end specinfra-2.82.8/lib/specinfra/command/linux.rb0000644000004100000410000000004513614203316021435 0ustar www-datawww-dataclass Specinfra::Command::Linux; end specinfra-2.82.8/lib/specinfra/command/arch.rb0000644000004100000410000000004413614203316021212 0ustar www-datawww-dataclass Specinfra::Command::Arch; end specinfra-2.82.8/lib/specinfra/command/base.rb0000644000004100000410000000055213614203316021213 0ustar www-datawww-datarequire 'shellwords' class Specinfra::Command::Base class << self class NotImplementedError < Exception; end def create self end def escape(target) str = case target when Regexp target.source else target.to_s end Shellwords.shellescape(str) end end end specinfra-2.82.8/lib/specinfra/command/sles/0000755000004100000410000000000013614203316020720 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/sles/base.rb0000644000004100000410000000011213614203316022151 0ustar www-datawww-dataclass Specinfra::Command::Sles::Base < Specinfra::Command::Suse::Base end specinfra-2.82.8/lib/specinfra/command/sles/v11/0000755000004100000410000000000013614203316021327 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/sles/v11/user.rb0000644000004100000410000000062513614203316022635 0ustar www-datawww-dataclass Specinfra::Command::Sles::V11::User < Specinfra::Command::Sles::Base::User class << self def get_minimum_days_between_password_change(user) "chage -l #{escape(user)} | sed -n 's/^Minimum://p' | sed 's|^[[:blank:]]*||g'" end def get_maximum_days_between_password_change(user) "chage -l #{escape(user)} | sed -n 's/^Maximum://p' | sed 's|^[[:blank:]]*||g'" end end endspecinfra-2.82.8/lib/specinfra/command/sles/base/0000755000004100000410000000000013614203316021632 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/sles/base/service.rb0000644000004100000410000000042413614203316023617 0ustar www-datawww-dataclass Specinfra::Command::Sles::Base::Service < Specinfra::Command::Suse::Base::Service class << self def create(os_info=nil) if (os_info || os)[:release].to_i < 12 self else Specinfra::Command::Sles::V12::Service end end end end specinfra-2.82.8/lib/specinfra/command/sles/v12/0000755000004100000410000000000013614203316021330 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/sles/v12/service.rb0000644000004100000410000000024113614203316023312 0ustar www-datawww-dataclass Specinfra::Command::Sles::V12::Service < Specinfra::Command::Sles::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.82.8/lib/specinfra/command/sles/v12.rb0000644000004100000410000000011213614203316021647 0ustar www-datawww-dataclass Specinfra::Command::Sles::V12 < Specinfra::Command::Sles::Base end specinfra-2.82.8/lib/specinfra/command/sles/v11.rb0000644000004100000410000000011113614203316021645 0ustar www-datawww-dataclass Specinfra::Command::Sles::V11 < Specinfra::Command::Sles::Base end specinfra-2.82.8/lib/specinfra/command/darwin.rb0000644000004100000410000000004613614203316021563 0ustar www-datawww-dataclass Specinfra::Command::Darwin; end specinfra-2.82.8/lib/specinfra/command/module/0000755000004100000410000000000013614203316021237 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/module/systemd.rb0000644000004100000410000000041713614203316023256 0ustar www-datawww-datamodule Specinfra module Command module Module module Systemd include Specinfra::Command::Module::Service::Systemd extend Specinfra::Command::Module::Service::Delegator def_delegator_service_under :systemd end end end end specinfra-2.82.8/lib/specinfra/command/module/ss.rb0000644000004100000410000000243313614203316022213 0ustar www-datawww-datamodule Specinfra module Command module Module module Ss def check_is_listening(port, options={}) if options[:local_address] pattern = inaddr_any_to_asterisk(options[:local_address]).map { |l| " #{l}:#{port} " } pattern = pattern.join('|') else pattern = ":#{port} " end "ss #{command_options(options[:protocol])} | grep -E -- #{escape(pattern)}" end private # WORKAROUND: # Older ss versions display "*" instead of "0.0.0.0". # But serverspec validates IP address by `valid_ip_address?` method: # https://github.com/serverspec/serverspec/blob/master/lib/serverspec/type/port.rb def inaddr_any_to_asterisk(local_address) if local_address == '0.0.0.0' [ '\*' , '0\.0\.0\.0' ] else [ local_address ] end end def command_options(protocol) case protocol.to_s when 'tcp' then "-tnl4" when 'tcp6' then "-tnl6" when 'udp' then "-unl4" when 'udp6' then "-unl6" when '' then "-tunl" else raise ArgumentError, "Unknown protocol [#{protocol}]" end end end end end end specinfra-2.82.8/lib/specinfra/command/module/zfs.rb0000644000004100000410000000112413614203316022364 0ustar www-datawww-datamodule Specinfra module Command module Module module Zfs def check_exists(zfs) "zfs list -H #{escape(zfs)}" end def check_has_property(zfs, property=nil) commands = [] property.sort.each do |key, value| regexp = "^#{value}$" commands << "zfs list -H -o #{escape(key)} #{escape(zfs)} | grep -- #{escape(regexp)}" end commands.join(' && ') end def get_property(zfs) "zfs get -Hp -o property,value all #{escape(zfs)}" end end end end end specinfra-2.82.8/lib/specinfra/command/module/service/0000755000004100000410000000000013614203316022677 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/module/service/supervisor.rb0000644000004100000410000000042713614203316025450 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module Supervisor def check_is_running_under_supervisor(service) "supervisorctl status #{escape(service)} | grep RUNNING" end end end end end end specinfra-2.82.8/lib/specinfra/command/module/service/runit.rb0000644000004100000410000000060113614203316024362 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module Runit def check_is_running_under_runit(service) "sv status #{escape(service)} | grep -E '^run: '" end def check_is_enabled_under_runit(service) "test ! -f /etc/sv/#{escape(service)}/down" end end end end end end specinfra-2.82.8/lib/specinfra/command/module/service/systemd.rb0000644000004100000410000000203313614203316024712 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module Systemd def check_is_enabled_under_systemd(service, level=nil) "systemctl --quiet is-enabled #{escape(service)}" end def check_is_running_under_systemd(service) "systemctl is-active #{escape(service)}" end def enable_under_systemd(service) "systemctl enable #{escape(service)}" end def disable_under_systemd(service) "systemctl disable #{escape(service)}" end def start_under_systemd(service) "systemctl start #{escape(service)}" end def stop_under_systemd(service) "systemctl stop #{escape(service)}" end def restart_under_systemd(service) "systemctl restart #{escape(service)}" end def reload_under_systemd(service) "systemctl reload #{escape(service)}" end end end end end end specinfra-2.82.8/lib/specinfra/command/module/service/init.rb0000644000004100000410000000176113614203316024174 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module Init def check_is_enabled_under_init(service, level=3) "chkconfig --list #{escape(service)} | grep #{level}:on" end def check_is_running_under_init(service) "service #{escape(service)} status" end def enable_under_init(service) "chkconfig #{escape(service)} on" end def disable_under_init(service) "chkconfig #{escape(service)} off" end def start_under_init(service) "service #{escape(service)} start" end def stop_under_init(service) "service #{escape(service)} stop" end def restart_under_init(service) "service #{escape(service)} restart" end def reload_under_init(service) "service #{escape(service)} reload" end end end end end end specinfra-2.82.8/lib/specinfra/command/module/service/upstart.rb0000644000004100000410000000041313614203316024724 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module Upstart def check_is_running_under_upstart(service) "initctl status #{escape(service)} | grep running" end end end end end end specinfra-2.82.8/lib/specinfra/command/module/service/daemontools.rb0000644000004100000410000000254313614203316025554 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module Daemontools def check_is_enabled_under_daemontools(service) "test -L #{service_dir}/#{escape(service)} && test -f #{service_dir}/#{escape(service)}/run" end def check_is_running_under_daemontools(service) "svstat #{service_dir}/#{escape(service)} | grep -E 'up \\(pid [0-9]+\\)'" end def enable_under_daemontools(service, directory) "ln -snf #{escape(directory)} #{service_dir}/#{escape(service)}" end def disable_under_daemontools(service) "( cd #{service_dir}/#{escape(service)} && rm -f #{service_dir}/#{escape(service)} && svc -dx . log )" end def start_under_daemontools(service) "svc -u #{service_dir}/#{escape(service)}" end def stop_under_daemontools(service) "svc -d #{service_dir}/#{escape(service)}" end def restart_under_daemontools(service) "svc -t #{service_dir}/#{escape(service)}" end def reload_under_daemontools(service) "svc -h #{service_dir}/#{escape(service)}" end private def service_dir '$([ -d /service ] && echo /service || echo /etc/service)' end end end end end end specinfra-2.82.8/lib/specinfra/command/module/service/delegator.rb0000644000004100000410000000155413614203316025177 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module Delegator def def_delegator_service_under(under) self.send(:alias_method, :check_is_enabled, :"check_is_enabled_under_#{under}") self.send(:alias_method, :check_is_running, :"check_is_running_under_#{under}") self.send(:alias_method, :enable, :"enable_under_#{under}") self.send(:alias_method, :disable, :"disable_under_#{under}") self.send(:alias_method, :start, :"start_under_#{under}") self.send(:alias_method, :stop, :"stop_under_#{under}") self.send(:alias_method, :restart, :"restart_under_#{under}") self.send(:alias_method, :reload, :"reload_under_#{under}") end end end end end end specinfra-2.82.8/lib/specinfra/command/module/service/god.rb0000644000004100000410000000035713614203316024002 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module God def check_is_monitored_by_god(service) "god status #{escape(service)}" end end end end end end specinfra-2.82.8/lib/specinfra/command/module/service/monit.rb0000644000004100000410000000034213614203316024351 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module Monit def check_is_monitored_by_monit(service) "monit status" end end end end end end specinfra-2.82.8/lib/specinfra/command/nixos/0000755000004100000410000000000013614203316021112 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/nixos/base.rb0000644000004100000410000000011413614203316022345 0ustar www-datawww-dataclass Specinfra::Command::Nixos::Base < Specinfra::Command::Linux::Base end specinfra-2.82.8/lib/specinfra/command/nixos/base/0000755000004100000410000000000013614203316022024 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/nixos/base/package.rb0000644000004100000410000000106413614203316023745 0ustar www-datawww-dataclass Specinfra::Command::Nixos::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) if version "nix-store -q --references /var/run/current-system/sw | grep #{escape(package)}-#{escape(version)}" else "nix-store -q --references /var/run/current-system/sw | grep #{escape(package)}" end end alias :check_is_installed_by_nix :check_is_installed def install(package, version=nil, option='') "nix-env -i #{option} #{package}" end end end specinfra-2.82.8/lib/specinfra/command/nixos/base/service.rb0000644000004100000410000000024413614203316024011 0ustar www-datawww-dataclass Specinfra::Command::Nixos::Base::Service < Specinfra::Command::Linux::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.82.8/lib/specinfra/command/freebsd/0000755000004100000410000000000013614203316021364 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/freebsd/v7.rb0000644000004100000410000000011613614203316022243 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V7 < Specinfra::Command::Freebsd::Base end specinfra-2.82.8/lib/specinfra/command/freebsd/v9.rb0000644000004100000410000000011613614203316022245 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V9 < Specinfra::Command::Freebsd::Base end specinfra-2.82.8/lib/specinfra/command/freebsd/v6/0000755000004100000410000000000013614203316021717 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/freebsd/v6/user.rb0000644000004100000410000000114313614203316023221 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V6::User < Specinfra::Command::Freebsd::Base::User class << self def check_has_home_directory(user, path_to_home) "pw user show #{escape(user)} | cut -f 9 -d ':' | grep -w -- #{escape(path_to_home)}" end def check_has_login_shell(user, path_to_shell) "pw user show #{escape(user)} | cut -f 10 -d ':' | grep -w -- #{escape(path_to_shell)}" end def get_home_directory(user) "pw user show #{escape(user)} | cut -f 9 -d ':'" end def get_login_shell(user) "pw user show #{escape(user)} | cut -f 10 -d ':'" end end end specinfra-2.82.8/lib/specinfra/command/freebsd/v6/package.rb0000644000004100000410000000103713614203316023640 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V6::Package < Specinfra::Command::Base::Package class << self def check_is_installed(package, version=nil) if version "pkg_info -I #{escape(package)}-#{escape(version)}" else "pkg_info -Ix #{escape(package)}" end end def install(package, version=nil, option='') "pkg_add -r #{option} #{package}" end def get_version(package, opts=nil) "pkg_info -Ix #{escape(package)} | cut -f 1 -w | sed -n 's/^#{escape(package)}-//p'" end end end specinfra-2.82.8/lib/specinfra/command/freebsd/v6/service.rb0000644000004100000410000000032213614203316023701 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V6::Service < Specinfra::Command::Base::Service class << self def check_is_enabled(service, level=3) "service -e | grep -- /#{escape(service)}$" end end end specinfra-2.82.8/lib/specinfra/command/freebsd/base.rb0000644000004100000410000000011013614203316022613 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/freebsd/v9/0000755000004100000410000000000013614203316021722 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/freebsd/v9/package.rb0000644000004100000410000000013713614203316023643 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V9::Package < Specinfra::Command::Freebsd::V8::Package end specinfra-2.82.8/lib/specinfra/command/freebsd/v9/service.rb0000644000004100000410000000013613614203316023707 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V9::Service < Specinfra::Command::Freebsd::V8::Service end specinfra-2.82.8/lib/specinfra/command/freebsd/v11/0000755000004100000410000000000013614203316021773 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/freebsd/v11/interface.rb0000644000004100000410000000056513614203316024266 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V11::Interface < Specinfra::Command::Freebsd::Base::Interface class << self def get_ipv4_address(interface) "ifconfig -f inet:cidr #{interface} inet | awk '/inet /{print $2}'" end def get_ipv6_address(interface) "ifconfig -f inet6:cidr #{interface} inet6 | awk '/inet6 /{print $2}' | tail -1" end end end specinfra-2.82.8/lib/specinfra/command/freebsd/v8/0000755000004100000410000000000013614203316021721 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/freebsd/v8/package.rb0000644000004100000410000000332013614203316023637 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V8::Package < Specinfra::Command::Freebsd::Base::Package class << self def pkg_info_pattern(package) # allow portorigin (origin/portname) as package argument, so that we get # similar answers from either "pkg info" and "pkg_info" "^#{package.split('/', 2)[-1]}-[0-9][0-9a-zA-Z_\.,]*$" end def shell_check_pkgng # See manpage of pkg(8), the paragraph devoted to -N flag # https://www.freebsd.org/cgi/man.cgi?query=pkg 'TMPDIR=/dev/null ASSUME_ALWAYS_YES=1 PACKAGESITE=file:///nonexist ' \ 'pkg info -x \'pkg(-devel)?$\' > /dev/null 2>&1' end def shell_ifelse(cond, stmt_t, stmt_f) "if #{cond}; then #{stmt_t}; else #{stmt_f}; fi" end def check_is_installed(package, version = nil) if version shell_ifelse( shell_check_pkgng(), "pkg query %v #{escape(package)} | grep -- #{escape(version)}", "pkg_info -I #{escape(package)}-#{escape(version)}" ) else pattern = pkg_info_pattern(package) shell_ifelse( shell_check_pkgng(), "pkg info -e #{escape(package)}", "pkg_info -Ix #{escape(pattern)}" ) end end def install(package, _version = nil, option = '') shell_ifelse( shell_check_pkgng(), "pkg install -y #{option} #{package}", "pkg_add -r #{option} #{package}" ) end def get_version(package, _options = nil) pattern = pkg_info_pattern(package) shell_ifelse( shell_check_pkgng(), "pkg query %v #{escape(package)}", "pkg_info -Ix #{escape(pattern)} | cut -f 1 -w | sed -n 's/^#{escape(package)}-//p'" ) end end end specinfra-2.82.8/lib/specinfra/command/freebsd/v8/service.rb0000644000004100000410000000013613614203316023706 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V8::Service < Specinfra::Command::Freebsd::V7::Service end specinfra-2.82.8/lib/specinfra/command/freebsd/v6.rb0000644000004100000410000000011613614203316022242 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V6 < Specinfra::Command::Freebsd::Base end specinfra-2.82.8/lib/specinfra/command/freebsd/base/0000755000004100000410000000000013614203316022276 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/freebsd/base/interface.rb0000644000004100000410000000401613614203316024564 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Interface < Specinfra::Command::Base::Interface class << self def check_exists(name) "ifconfig #{name}" end def get_speed_of(name) "ifconfig #{name} | awk '/media:/{if(match($0,/[0-9]+/)){ print substr($0, RSTART, RLENGTH);}}'" end def get_mtu_of(name) "ifconfig #{name} | awk '/mtu /{print $NF}'" end def check_has_ipv4_address(interface, ip_address) ip_address = ip_address.dup if ip_address =~ /\/\d+$/ # remove the prefix - better would be to calculate the netmask ip_address.gsub!(/\/\d+$/, "") end ip_address << " " ip_address.gsub!(".", "\\.") "ifconfig #{interface} inet | grep 'inet #{ip_address}'" end def check_has_ipv6_address(interface, ip_address) ip_address = ip_address.dup (ip_address, prefixlen) = ip_address.split(/\//) ip_address.downcase! if ip_address =~ /^fe80::/i # link local needs the scope (interface) appended ip_address << "%#{interface}" end unless prefixlen.to_s.empty? # append prefixlen ip_address << " prefixlen #{prefixlen}" else ip_address << " " end "ifconfig #{interface} inet6 | grep 'inet6 #{ip_address}'" end def get_ipv4_address(interface) "ifconfig #{interface} inet | grep inet | awk '{print $2}'" end def get_ipv6_address(interface) # Awk refuses to print '/' even with using escapes or hex so workaround with sed employed here. "ifconfig #{interface} inet6 | grep inet6 | awk '{print $2$3$4}' | sed 's/prefixlen/\//'; exit" end def get_link_state(interface) # Checks if interfaces is administratively up with the -u arg. # L1 check via status. Virtual interfaces like tapX missing the status will report up. # Emulates operstate in linux with exception of the unknown status. %Q{ifconfig -u #{interface} 2>&1 | awk -v s=up '/status:/ && $2 != "active" { s="down" }; END {print s}'} end end end specinfra-2.82.8/lib/specinfra/command/freebsd/base/group.rb0000644000004100000410000000060713614203316023762 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Group < Specinfra::Command::Base::Group class << self def update_gid(group, gid) "pw groupmod #{escape(group)} -g #{escape(gid)}" end def add(group, options) command = %w[pw group add] command << escape(group) command << '-g' << escape(options[:gid]) if options[:gid] command.join(' ') end end end specinfra-2.82.8/lib/specinfra/command/freebsd/base/kernel_module.rb0000644000004100000410000000027513614203316025454 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::KernelModule < Specinfra::Command::Base::KernelModule class << self def check_is_loaded(name) "kldstat -q -m #{name}" end end end specinfra-2.82.8/lib/specinfra/command/freebsd/base/user.rb0000644000004100000410000000325513614203316023606 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::User < Specinfra::Command::Base::User class << self def create(os_info=nil) if (os_info || os)[:release].to_i < 7 Specinfra::Command::Freebsd::V6::User else self end end def get_minimum_days_between_password_change(user) 'echo 0' end def get_maximum_days_between_password_change(user) "pw usershow -n #{escape(user)} | cut -d':' -f 6" end def update_home_directory(user, directory) "pw user mod #{escape(user)} -d #{escape(directory)}" end def update_login_shell(user, shell) "pw user mod #{escape(user)} -s #{escape(shell)}" end def update_uid(user, uid) "pw user mod #{escape(user)} -u #{escape(uid)}" end def update_gid(user, gid) "pw user mod #{escape(user)} -g #{escape(gid)}" end def add(user, options) command = ['pw', 'user', 'add', escape(user)] command << '-g' << escape(options[:gid]) if options[:gid] command << '-d' << escape(options[:home_directory]) if options[:home_directory] command << '-s' << escape(options[:shell]) if options[:shell] command << '-m' if options[:create_home] command << '-u' << escape(options[:uid]) if options[:uid] if options[:password] command.concat(['&&', 'chpass', '-p', "\'#{options[:password]}\'", escape(user)]) end command.join(' ') end def update_encrypted_password(user, encrypted_password) "chpass -p \'#{encrypted_password}\' #{escape(user)}" end def get_encrypted_password(user) "getent passwd #{escape(user)} | awk -F: '{ print $2 }'" end end end specinfra-2.82.8/lib/specinfra/command/freebsd/base/package.rb0000644000004100000410000000151713614203316024222 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Package < Specinfra::Command::Base::Package class << self def check_is_installed(package, version=nil) if version "pkg query %v #{escape(package)} | grep -- #{escape(version)}" else "pkg info -e #{escape(package)}" end end alias :check_is_installed_by_pkg :check_is_installed def check_is_installed_by_rpm(package, version=nil) cmd = "rpm -q #{escape(package)}" if version cmd = "#{cmd} | grep -w -- #{escape(package)}-#{escape(version)}" end cmd end alias :check_is_installed_by_yum :check_is_installed_by_rpm def install(package, version=nil, option='') "pkg install -y #{option} #{package}" end def get_version(package, opts=nil) "pkg query %v #{escape(package)}" end end end specinfra-2.82.8/lib/specinfra/command/freebsd/base/zfs.rb0000644000004100000410000000022313614203316023422 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Zfs < Specinfra::Command::Base::Zfs class << self include Specinfra::Command::Module::Zfs end end specinfra-2.82.8/lib/specinfra/command/freebsd/base/port.rb0000644000004100000410000000036613614203316023614 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Port < Specinfra::Command::Base::Port class << self def check_is_listening(port, options={}) regexp = ":#{port} " "sockstat -46l -p #{port} | grep -- #{escape(regexp)}" end end end specinfra-2.82.8/lib/specinfra/command/freebsd/base/file.rb0000644000004100000410000000220213614203316023536 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::File < Specinfra::Command::Base::File class << self def check_is_grouped(file, group) regexp = "^#{group}$" "stat -f%Sg #{escape(file)} | grep -- #{escape(regexp)}" end def get_owner_group(file) "stat -f%Sg #{escape(file)}" end def check_is_owned_by(file, owner) regexp = "^#{owner}$" "stat -f%Su #{escape(file)} | grep -- #{escape(regexp)}" end def get_owner_user(file) "stat -f%Su #{escape(file)}" end def check_has_mode(file, mode) "test `stat -f%Mp%Lp #{escape(file)} | sed 's/^0*//'` -eq #{escape(mode)}" end def get_mode(file) "stat -f%Mp%Lp #{escape(file)} | sed 's/^0*//'" end def check_is_linked_to(link, target) "stat -f%Y #{escape(link)} | grep -- #{escape(target)}" end def get_mtime(file) "stat -f%m #{escape(file)}" end def get_size(file) "stat -f%z #{escape(file)}" end def get_sha256sum(file) "sha256 #{escape(file)} | cut -d ' ' -f 4" end def get_md5sum(file) "md5 #{escape(file)} | cut -d ' ' -f 4" end end end specinfra-2.82.8/lib/specinfra/command/freebsd/base/service.rb0000644000004100000410000000051013614203316024257 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Service < Specinfra::Command::Base::Service class << self def check_is_enabled(service, level=3) "service #{escape(service)} enabled" end def check_is_running_under_init(service) "service #{escape(service)} status | grep -E 'as (pid [0-9]+)'" end end end specinfra-2.82.8/lib/specinfra/command/freebsd/base/inventory.rb0000644000004100000410000000103413614203316024656 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Inventory < Specinfra::Command::Base::Inventory class << self def get_memory 'false' end def get_cpu 'false' end def get_hostname 'hostname -s' end def get_domain 'hostname -f | ' + 'awk -v h=`hostname -s` \'$1 ~ h { sub(h".", "", $1); print $1 }\'' end def get_fqdn 'hostname -f' end def get_filesystem 'df -k' end def get_system_product_name 'kenv smbios.system.product' end end end specinfra-2.82.8/lib/specinfra/command/freebsd/base/process.rb0000644000004100000410000000073413614203316024305 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Process < Specinfra::Command::Base::Process class << self def get(process, opts) "ps -p `pgrep -xn #{escape(process)}` -o #{opts[:format]}" end def count(process) "pgrep #{escape(process)} | wc -l" end def check_is_running(process) "pgrep -q #{escape(process)}" end def check_count(process,count) "test `pgrep #{escape(process)} | wc -l` -eq #{escape(count)}" end end end specinfra-2.82.8/lib/specinfra/command/freebsd/base/host.rb0000644000004100000410000000166413614203316023607 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Host < Specinfra::Command::Base::Host class << self def check_is_reachable(host, port, proto, timeout) if port.nil? "ping -t #{escape(timeout)} -c 2 -n #{escape(host)}" else "nc -vvvvz#{escape(proto[0].chr)} #{escape(host)} #{escape(port)} -w #{escape(timeout)}" end end def get_ipaddress(name) # getent hosts will return both the ipv6 and ipv4 record. # this will only pick the first one. (Linux behavior) "getent hosts #{escape(name)} | awk '{print $1; exit}'" end def get_ipv4_address(name) # May return multiple values pick the one matching ipv4 "getent hosts #{escape(name)} | awk '$1 ~ /^[0-9.]+$/ {print $1}'" end def get_ipv6_address(name) # May return multiple values pick the one matching ipv6 "getent hosts #{escape(name)} | awk 'tolower($1) ~ /^[0-9a-f:]+$/ {print $1}'" end end end specinfra-2.82.8/lib/specinfra/command/freebsd/base/routing_table.rb0000644000004100000410000000045013614203316025460 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::RoutingTable < Specinfra::Command::Base::RoutingTable class << self def check_has_entry(destination) %Q{netstat -rnW | grep #{destination} | awk '{print $1, "via", $2, "dev", $6, " "}'} end alias :get_entry :check_has_entry end end specinfra-2.82.8/lib/specinfra/command/freebsd/v7/0000755000004100000410000000000013614203316021720 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/freebsd/v7/package.rb0000644000004100000410000000013713614203316023641 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V7::Package < Specinfra::Command::Freebsd::V6::Package end specinfra-2.82.8/lib/specinfra/command/freebsd/v7/service.rb0000644000004100000410000000013613614203316023705 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V7::Service < Specinfra::Command::Freebsd::V6::Service end specinfra-2.82.8/lib/specinfra/command/freebsd/v8.rb0000644000004100000410000000011613614203316022244 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V8 < Specinfra::Command::Freebsd::Base end specinfra-2.82.8/lib/specinfra/command/freebsd/v11.rb0000644000004100000410000000011713614203316022317 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V11 < Specinfra::Command::Freebsd::Base end specinfra-2.82.8/lib/specinfra/command/poky/0000755000004100000410000000000013614203316020734 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/poky/base.rb0000644000004100000410000000011313614203316022166 0ustar www-datawww-dataclass Specinfra::Command::Poky::Base < Specinfra::Command::Linux::Base end specinfra-2.82.8/lib/specinfra/command/poky/base/0000755000004100000410000000000013614203316021646 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/poky/base/interface.rb0000644000004100000410000000014113614203316024127 0ustar www-datawww-dataclass Specinfra::Command::Poky::Base::Interface < Specinfra::Command::Linux::Base::Interface end specinfra-2.82.8/lib/specinfra/command/poky/base/package.rb0000644000004100000410000000141213614203316023564 0ustar www-datawww-dataclass Specinfra::Command::Poky::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) package_escaped = escape(package) cmd = "opkg status #{package_escaped} | grep -E '^Version|(user|ok) installed$'" cmd = "#{cmd} | grep -E #{escape(version)}" if version cmd end alias :check_is_installed_by_opkg :check_is_installed def install(package, version=nil, option='') # opkg doesn't support to install specific version. "opkg install #{option} #{package}" end def get_version(package, opts=nil) "opkg list-installed #{package} | cut -d ' ' -f 3" end def remove(package, option='') "opkg remove #{option} #{package}" end end end specinfra-2.82.8/lib/specinfra/command/poky/base/service.rb0000644000004100000410000000024313614203316023632 0ustar www-datawww-dataclass Specinfra::Command::Poky::Base::Service < Specinfra::Command::Linux::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.82.8/lib/specinfra/command/poky/base/inventory.rb0000644000004100000410000000014113614203316024224 0ustar www-datawww-dataclass Specinfra::Command::Poky::Base::Inventory < Specinfra::Command::Linux::Base::Inventory end specinfra-2.82.8/lib/specinfra/command/redhat/0000755000004100000410000000000013614203316021221 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/redhat/v7.rb0000644000004100000410000000011513614203316022077 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V7 < Specinfra::Command::Redhat::Base end specinfra-2.82.8/lib/specinfra/command/redhat/v5.rb0000644000004100000410000000011513614203316022075 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V5 < Specinfra::Command::Redhat::Base end specinfra-2.82.8/lib/specinfra/command/redhat/base.rb0000644000004100000410000000011513614203316022455 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base < Specinfra::Command::Linux::Base end specinfra-2.82.8/lib/specinfra/command/redhat/v8/0000755000004100000410000000000013614203316021556 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/redhat/v8/selinux_module.rb0000644000004100000410000000047413614203316025144 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V8::SelinuxModule < Specinfra::Command::Redhat::Base::SelinuxModule class << self def check_is_installed(name, version=nil) "semodule -l | grep $'^#{escape(name)}'" end def check_is_enabled(name) "semodule -l | grep $'^#{escape(name)}'" end end end specinfra-2.82.8/lib/specinfra/command/redhat/v8/yumrepo.rb0000644000004100000410000000056013614203316023604 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V8::Yumrepo < Specinfra::Command::Redhat::Base::Yumrepo class << self def check_exists(repository) "dnf repolist all | grep -qsE \"^[\\!\\*]?#{escape(repository)}\(\\s\|$\|\\/)\"" end def check_is_enabled(repository) "dnf repolist enabled | grep -qs \"^[\\!\\*]\\?#{escape(repository)}\"" end end end specinfra-2.82.8/lib/specinfra/command/redhat/base/0000755000004100000410000000000013614203316022133 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/redhat/base/iptables.rb0000644000004100000410000000015213614203316024261 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::Iptables < Specinfra::Command::Linux::Base::Iptables end specinfra-2.82.8/lib/specinfra/command/redhat/base/selinux_module.rb0000644000004100000410000000045113614203316025514 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::SelinuxModule < Specinfra::Command::Linux::Base::SelinuxModule class << self def create(os_info=nil) if (os_info || os)[:release].to_i < 8 self else Specinfra::Command::Redhat::V8::SelinuxModule end end end end specinfra-2.82.8/lib/specinfra/command/redhat/base/yumrepo.rb0000644000004100000410000000103413614203316024156 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::Yumrepo < Specinfra::Command::Linux::Base::Yumrepo class << self def create(os_info=nil) if (os_info || os)[:release].to_i < 8 self else Specinfra::Command::Redhat::V8::Yumrepo end end def check_exists(repository) "yum repolist all -C | grep -qsE \"^[\\!\\*]?#{escape(repository)}\(\\s\|$\|\\/)\"" end def check_is_enabled(repository) "yum repolist enabled -C | grep -qs \"^[\\!\\*]\\?#{escape(repository)}\"" end end end specinfra-2.82.8/lib/specinfra/command/redhat/base/package.rb0000644000004100000410000000152213614203316024053 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) cmd = "rpm -q #{escape(package)}" if version full_package = "#{package}-#{version}" cmd = "#{cmd} | grep -w -- #{Regexp.escape(full_package)}" end cmd end alias :check_is_installed_by_rpm :check_is_installed def get_version(package, opts=nil) "rpm -q --qf '%{VERSION}-%{RELEASE}' #{package}" end def install(package, version=nil, option='') if version full_package = "#{package}-#{version}" else full_package = package end cmd = "yum -y #{option} install #{escape(full_package)}" end def remove(package, option='') "yum -y #{option} remove #{package}" end end end specinfra-2.82.8/lib/specinfra/command/redhat/base/port.rb0000644000004100000410000000052513614203316023446 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::Port < Specinfra::Command::Base::Port class << self def create(os_info=nil) release = (os_info || os)[:release].to_i # Dirty hack for Amazon Linux if release < 7 || release > 2000 self else Specinfra::Command::Redhat::V7::Port end end end end specinfra-2.82.8/lib/specinfra/command/redhat/base/service.rb0000644000004100000410000000054513614203316024124 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::Service < Specinfra::Command::Linux::Base::Service class << self def create(os_info=nil) release = (os_info || os)[:release].to_i # Dirty hack for Amazon Linux if release < 7 || release > 2000 self else Specinfra::Command::Redhat::V7::Service end end end end specinfra-2.82.8/lib/specinfra/command/redhat/base/host.rb0000644000004100000410000000052513614203316023437 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::Host < Specinfra::Command::Base::Host class << self def create(os_info=nil) release = (os_info || os)[:release].to_i # Dirty hack for Amazon Linux if release < 7 || release > 2000 self else Specinfra::Command::Redhat::V7::Host end end end end specinfra-2.82.8/lib/specinfra/command/redhat/v5/0000755000004100000410000000000013614203316021553 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/redhat/v5/iptables.rb0000644000004100000410000000045713614203316023711 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V5::Iptables < Specinfra::Command::Redhat::Base::Iptables class << self def check_has_rule(rule, table=nil, chain=nil) cmd = "iptables-save" cmd += " -t #{escape(table)}" if table cmd += " | grep -- #{escape(rule)}" cmd end end end specinfra-2.82.8/lib/specinfra/command/redhat/v7/0000755000004100000410000000000013614203316021555 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/redhat/v7/port.rb0000644000004100000410000000023113614203316023062 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V7::Port < Specinfra::Command::Redhat::Base::Port class << self include Specinfra::Command::Module::Ss end end specinfra-2.82.8/lib/specinfra/command/redhat/v7/service.rb0000644000004100000410000000024413614203316023542 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V7::Service < Specinfra::Command::Redhat::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.82.8/lib/specinfra/command/redhat/v7/host.rb0000644000004100000410000000104013614203316023052 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V7::Host < Specinfra::Command::Redhat::Base::Host class << self def check_is_reachable(host, port, proto, timeout) if port.nil? "ping -w #{escape(timeout)} -c 2 -n #{escape(host)}" else # RHEL7 comes with ncat which does no longer sport the -z option # hence this kludge "ncat -vvvv#{escape(proto[0].chr)} #{escape(host)} #{escape(port)} " + "-w #{escape(timeout)} -i #{escape(timeout)} 2>&1 | " + "grep -q SUCCESS" end end end end specinfra-2.82.8/lib/specinfra/command/redhat/v8.rb0000644000004100000410000000011413614203316022077 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V8 < Specinfra::Command::Redhat::Base end specinfra-2.82.8/lib/specinfra/command/solaris.rb0000644000004100000410000000004713614203316021754 0ustar www-datawww-dataclass Specinfra::Command::Solaris; end specinfra-2.82.8/lib/specinfra/command/solaris/0000755000004100000410000000000013614203316021426 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/solaris/v10/0000755000004100000410000000000013614203316022034 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/solaris/v10/group.rb0000644000004100000410000000031213614203316023511 0ustar www-datawww-dataclass Specinfra::Command::Solaris::V10::Group < Specinfra::Command::Solaris::Base::Group class << self def check_exists(group) "getent group | grep -w -- #{escape(group)}" end end end specinfra-2.82.8/lib/specinfra/command/solaris/v10/user.rb0000644000004100000410000000063713614203316023345 0ustar www-datawww-dataclass Specinfra::Command::Solaris::V10::User < Specinfra::Command::Solaris::Base::User class << self def check_belongs_to_group(user, group) "id -ap #{escape(user)} | grep -- #{escape(group)}" end def check_has_authorized_key(user, key) key.sub!(/\s+\S*$/, '') if key.match(/^\S+\s+\S+\s+\S*$/) "grep -- #{escape(key)} ~#{escape(user)}/.ssh/authorized_keys" end end end specinfra-2.82.8/lib/specinfra/command/solaris/v10/package.rb0000644000004100000410000000046613614203316023762 0ustar www-datawww-dataclass Specinfra::Command::Solaris::V10::Package < Specinfra::Command::Solaris::Base::Package class << self def check_is_installed(package, version=nil) cmd = "pkginfo -q #{escape(package)}" if version cmd = "#{cmd} | grep -- #{escape(version)}" end cmd end end end specinfra-2.82.8/lib/specinfra/command/solaris/v10/file.rb0000644000004100000410000000306313614203316023302 0ustar www-datawww-dataclass Specinfra::Command::Solaris::V10::File < Specinfra::Command::Solaris::Base::File class << self # reference: http://perldoc.perl.org/functions/stat.html def check_has_mode(file, mode) regexp = "^#{mode}$" "perl -e 'printf \"%o\", (stat shift)[2]&07777' #{escape(file)} | grep -- #{escape(regexp)}" end # reference: http://perldoc.perl.org/functions/stat.html # http://www.tutorialspoint.com/perl/perl_getpwuid.htm def check_is_owned_by(file, owner) regexp = "^#{owner}$" "perl -e 'printf \"%s\", getpwuid((stat(\"#{escape(file)}\"))[4])' | grep -- #{escape(regexp)}" end # reference: http://perldoc.perl.org/functions/stat.html # http://www.tutorialspoint.com/perl/perl_getgrgid.htm def check_is_grouped(file, group) regexp = "^#{group}$" "perl -e 'printf \"%s\", getgrgid((stat(\"#{escape(file)}\"))[5])' | grep -- #{escape(regexp)}" end # reference: http://www.tutorialspoint.com/perl/perl_readlink.htm def check_is_linked_to(link, target) regexp = "^#{target}$" "perl -e 'printf \"%s\", readlink(\"#{escape(link)}\")' | grep -- #{escape(regexp)}" end def check_contain(file, expected_pattern) "grep -- #{escape(expected_pattern)} #{escape(file)}" end def get_md5sum(file) "digest -a md5 -v #{escape(file)} | cut -d '=' -f 2 | cut -c 2-" end # reference: http://perldoc.perl.org/functions/stat.html def get_mode(file) "perl -e 'printf \"%o\", (stat shift)[2]&07777' #{escape(file)}" end end end specinfra-2.82.8/lib/specinfra/command/solaris/v10/host.rb0000644000004100000410000000064313614203316023341 0ustar www-datawww-dataclass Specinfra::Command::Solaris::V10::Host < Specinfra::Command::Solaris::Base::Host class << self def check_is_reachable(host, port, proto, timeout) if port.nil? "ping -n #{escape(host)} #{escape(timeout)}" elsif proto == 'tcp' "echo 'quit' | mconnect -p #{escape(port)} #{escape(host)} > /dev/null 2>&1" else raise NotImplementedError.new end end end end specinfra-2.82.8/lib/specinfra/command/solaris/base.rb0000644000004100000410000000010713614203316022663 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/solaris/v11/0000755000004100000410000000000013614203316022035 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/solaris/v11/user.rb0000644000004100000410000000063213614203316023341 0ustar www-datawww-dataclass Specinfra::Command::Solaris::V11::User < Specinfra::Command::Solaris::Base::User class << self def get_minimum_days_between_password_change(user) "passwd -s #{escape(user)} | sed 's/ \\{1,\\}/%/g' | tr '%' '\n' | sed '4q;d'" end def get_maximum_days_between_password_change(user) "passwd -s #{escape(user)} | sed 's/ \\{1,\\}/%/g' | tr '%' '\n' | sed '5q;d'" end end end specinfra-2.82.8/lib/specinfra/command/solaris/v10.rb0000644000004100000410000000011713614203316022360 0ustar www-datawww-dataclass Specinfra::Command::Solaris::V10 < Specinfra::Command::Solaris::Base end specinfra-2.82.8/lib/specinfra/command/solaris/base/0000755000004100000410000000000013614203316022340 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/solaris/base/ipfilter.rb0000644000004100000410000000032113614203316024477 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Ipfilter < Specinfra::Command::Base::Ipfilter class << self def check_has_rule(rule) "ipfstat -io 2> /dev/null | grep -- #{escape(rule)}" end end end specinfra-2.82.8/lib/specinfra/command/solaris/base/group.rb0000644000004100000410000000042013614203316024015 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Group < Specinfra::Command::Base::Group class << self def check_has_gid(group, gid) regexp = "^#{group}:" "getent group | grep -- #{escape(regexp)} | cut -f 3 -d ':' | grep -w -- #{escape(gid)}" end end end specinfra-2.82.8/lib/specinfra/command/solaris/base/kernel_module.rb0000644000004100000410000000036013614203316025511 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::KernelModule < Specinfra::Command::Base::KernelModule class << self def check_is_loaded(name) "modinfo -c | awk '$3 == \"#{escape(name)}\" { print $4 }' | grep ^LOADED" end end end specinfra-2.82.8/lib/specinfra/command/solaris/base/user.rb0000644000004100000410000000101413614203316023637 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::User < Specinfra::Command::Base::User class << self def check_belongs_to_group(user, group) "id -Gn #{escape(user)} | grep -- #{escape(group)}" end def check_has_home_directory(user, path_to_home) "getent passwd #{escape(user)} | cut -f 6 -d ':' | grep -w -- #{escape(path_to_home)}" end def check_has_login_shell(user, path_to_shell) "getent passwd #{escape(user)} | cut -f 7 -d ':' | grep -w -- #{escape(path_to_shell)}" end end end specinfra-2.82.8/lib/specinfra/command/solaris/base/ipnat.rb0000644000004100000410000000035313614203316024001 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Ipnat < Specinfra::Command::Base::Ipnat class << self def check_has_rule(rule) regexp = "^#{rule}$" "ipnat -l 2> /dev/null | grep -- #{escape(regexp)}" end end end specinfra-2.82.8/lib/specinfra/command/solaris/base/package.rb0000644000004100000410000000050213614203316024255 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Package < Specinfra::Command::Base::Package class << self def check_is_installed(package, version=nil) cmd = "pkg list -H #{escape(package)} 2> /dev/null" if version cmd = "#{cmd} | grep -qw -- #{escape(version)}" end cmd end end end specinfra-2.82.8/lib/specinfra/command/solaris/base/zfs.rb0000644000004100000410000000023313614203316023465 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Zfs < Specinfra::Command::Base::Zfs class << self include Specinfra::Command::Module::Zfs end end specinfra-2.82.8/lib/specinfra/command/solaris/base/port.rb0000644000004100000410000000071513614203316023654 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Port < Specinfra::Command::Base::Port class << self def check_is_listening(port, opts=nil) regexp = "\\.#{port} " "netstat -an 2> /dev/null | grep -- LISTEN | grep -- #{escape(regexp)}" end def check_is_listening_with_protocol(port, protocol) regexp = ".*\\.#{port} " "netstat -an -P #{escape(protocol)} 2> /dev/null | grep -- LISTEN | grep -- #{escape(regexp)}" end end end specinfra-2.82.8/lib/specinfra/command/solaris/base/file.rb0000644000004100000410000000166613614203316023615 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::File < Specinfra::Command::Base::File class << self def check_contains_within(file, expected_pattern, from=nil, to=nil) from ||= '1' to ||= '$' sed = "sed -n #{escape(from)},#{escape(to)}p #{escape(file)}" sed_end = "sed -n 1,#{escape(to)}p" checker_with_regexp = check_contains_with_regexp("/dev/stdin", expected_pattern) checker_with_fixed = check_contains_with_fixed_strings("/dev/stdin", expected_pattern) "#{sed} | #{sed_end} | #{checker_with_regexp}|| #{sed} | #{sed_end} | #{checker_with_fixed}" end def check_is_accessible_by_user(file, user, access) # http://docs.oracle.com/cd/E23823_01/html/816-5166/su-1m.html ## No need for login shell as it seems that behavior as superuser is favorable for us, but needs ## to be better tested under real solaris env "su #{user} -c \"test -#{access} #{file}\"" end end end specinfra-2.82.8/lib/specinfra/command/solaris/base/service.rb0000644000004100000410000000130113614203316024320 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Service < Specinfra::Command::Base::Service class << self def check_is_enabled(service, level=nil) "svcs -l #{escape(service)} 2> /dev/null | egrep '^enabled *true$'" end def check_is_running(service) "svcs -H -o state #{escape(service)} 2> /dev/null | egrep '^online$'" end def check_has_property(svc, property) commands = [] property.sort.each do |key, value| regexp = "^#{value}$" commands << "svcprop -p #{escape(key)} #{escape(svc)} | grep -- #{escape(regexp)}" end commands.join(' && ') end def get_property(service) "svcprop -a #{escape(service)}" end end end specinfra-2.82.8/lib/specinfra/command/solaris/base/inventory.rb0000644000004100000410000000240613614203316024724 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Inventory < Specinfra::Command::Base::Inventory class << self def get_memory 'false' end def get_cpu 'false' end def get_hostname 'uname -n' end def get_domain # There is no sure way to get the hostname like on linux # This code is somewhat resembiling the functionality # of the dnsdomainname command. # Assumes either /etc/hosts or DNS is properly configured. %Q{getent hosts `uname -n` | } + %Q{nawk -v h=`uname -n` '{sub(h".", "", $2); if ($2 != h){ print $2 } else { exit 1 } }'} end def get_fqdn # Same as with get_domain assumes that either # /etc/hosts or DNS are configured correctly. %Q{getent hosts `uname -n` | } + %Q{nawk -v h=`unme -n` '{ if ($2 ~ h".") { print $2 } else { exit 1 } }'} end def get_filesystem # emulates df -kP on Linux # Also offers a creative solution for the # multiple swap entries by adding a number suffix. # e.g. swap0, swap1 and so on. %Q{df -k | nawk -v i=0 '$1 == "swap" { $1=$1i; i++ }; NF == 1 { printf($1); next }; { print }'} end def get_system_product_name "prtdiag | grep 'System Configuration'" end end end specinfra-2.82.8/lib/specinfra/command/solaris/base/host.rb0000644000004100000410000000055113614203316023643 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Host < Specinfra::Command::Base::Host class << self def check_is_reachable(host, port, proto, timeout) if port.nil? "ping -n #{escape(host)} #{escape(timeout)}" else "nc -vvvvz#{escape(proto[0].chr)} -w #{escape(timeout)} #{escape(host)} #{escape(port)}" end end end end specinfra-2.82.8/lib/specinfra/command/solaris/base/cron.rb0000644000004100000410000000064213614203316023630 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Cron < Specinfra::Command::Base::Cron class << self def check_has_entry(user, entry) entry_escaped = entry.gsub(/\*/, '\\*').gsub(/\[/, '\\[').gsub(/\]/, '\\]').gsub(/\%/, '\\%') if user.nil? "crontab -l | grep -- #{escape(entry_escaped)}" else "crontab -l #{escape(user)} | grep -- #{escape(entry_escaped)}" end end end end specinfra-2.82.8/lib/specinfra/command/solaris/v11.rb0000644000004100000410000000011713614203316022361 0ustar www-datawww-dataclass Specinfra::Command::Solaris::V11 < Specinfra::Command::Solaris::Base end specinfra-2.82.8/lib/specinfra/command/smartos.rb0000644000004100000410000000004713614203316021770 0ustar www-datawww-dataclass Specinfra::Command::Smartos; end specinfra-2.82.8/lib/specinfra/command/base/0000755000004100000410000000000013614203316020664 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/base/iptables.rb0000644000004100000410000000011013614203316023004 0ustar www-datawww-dataclass Specinfra::Command::Base::Iptables < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/base/interface.rb0000644000004100000410000000011113614203316023142 0ustar www-datawww-dataclass Specinfra::Command::Base::Interface < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/base/ipfilter.rb0000644000004100000410000000011013614203316023017 0ustar www-datawww-dataclass Specinfra::Command::Base::Ipfilter < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/base/selinux_module.rb0000644000004100000410000000011513614203316024242 0ustar www-datawww-dataclass Specinfra::Command::Base::SelinuxModule < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/base/group.rb0000644000004100000410000000245713614203316022355 0ustar www-datawww-dataclass Specinfra::Command::Base::Group < Specinfra::Command::Base class << self def check_exists(group) "getent group #{escape(group)}" end def check_has_gid(group, gid) "getent group #{escape(group)} | cut -f 3 -d ':' | grep -w -- #{escape(gid)}" end def check_is_system_group(group) exists = "getent group #{escape(group)} > /dev/null 2>&1" gid = "getent group #{escape(group)} | cut -f 3 -d ':'" sys_gid_min = "awk 'BEGIN{sys_gid_min=101} {if($1~/^SYS_GID_MIN/){sys_gid_min=$2}} END{print sys_gid_min}' /etc/login.defs" sys_gid_max = "awk 'BEGIN{sys_gid_max=0;gid_min=1000} {if($1~/^SYS_GID_MAX/){sys_gid_max=$2}if($1~/^GID_MIN/){gid_min=$2}} END{if(sys_gid_max!=0){print sys_gid_max}else{print gid_min-1}}' /etc/login.defs" %Q|#{exists} && test "$(#{gid})" -ge "$(#{sys_gid_min})" && test "$(#{gid})" -le "$(#{sys_gid_max})"| end def get_gid(group) "getent group #{escape(group)} | cut -f 3 -d ':'" end def update_gid(group, gid) "groupmod -g #{escape(gid)} #{escape(group)}" end def add(group, options) command = ['groupadd'] command << '-g' << escape(options[:gid]) if options[:gid] command << '-r' if options[:system_group] command << escape(group) command.join(' ') end end end specinfra-2.82.8/lib/specinfra/command/base/yumrepo.rb0000644000004100000410000000011013614203316022701 0ustar www-datawww-dataclass Specinfra::Command::Base::Yumrepo < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/base/kernel_module.rb0000644000004100000410000000011413614203316024032 0ustar www-datawww-dataclass Specinfra::Command::Base::KernelModule < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/base/lxc_container.rb0000644000004100000410000000011413614203316024035 0ustar www-datawww-dataclass Specinfra::Command::Base::LxcContainer < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/base/user.rb0000644000004100000410000000661513614203316022177 0ustar www-datawww-dataclass Specinfra::Command::Base::User < Specinfra::Command::Base class << self def check_exists(user) "id #{escape(user)}" end def check_belongs_to_group(user, group) "id #{escape(user)} | sed 's/ context=.*//g' | cut -f 4 -d '=' | grep -- #{escape(group)}" end def check_belongs_to_primary_group(user, group) "id -gn #{escape(user)}| grep ^#{escape(group)}$" end def check_is_system_user(user) exists = "getent passwd #{escape(user)} > /dev/null 2>&1" uid = "getent passwd #{escape(user)} | cut -f 3 -d ':'" sys_uid_min = "awk 'BEGIN{sys_uid_min=101} {if($1~/^SYS_UID_MIN/){sys_uid_min=$2}} END{print sys_uid_min}' /etc/login.defs" sys_uid_max = "awk 'BEGIN{sys_uid_max=0;uid_min=1000} {if($1~/^SYS_UID_MAX/){sys_uid_max=$2}if($1~/^UID_MIN/){uid_min=$2}} END{if(sys_uid_max!=0){print sys_uid_max}else{print uid_min-1}}' /etc/login.defs" %Q|#{exists} && test "$(#{uid})" -ge "$(#{sys_uid_min})" && test "$(#{uid})" -le "$(#{sys_uid_max})"| end def check_has_uid(user, uid) regexp = "^uid=#{uid}(" "id #{escape(user)} | grep -- #{escape(regexp)}" end def check_has_home_directory(user, path_to_home) "getent passwd #{escape(user)} | cut -f 6 -d ':' | grep -w -- #{escape(path_to_home)}" end def check_has_login_shell(user, path_to_shell) "getent passwd #{escape(user)} | cut -f 7 -d ':' | grep -w -- #{escape(path_to_shell)}" end def check_has_authorized_key(user, key) key.sub!(/\s+\S*$/, '') if key.match(/^\S+\s+\S+\s+\S*$/) "grep -w -- #{escape(key)} ~#{escape(user)}/.ssh/authorized_keys" end def get_minimum_days_between_password_change(user) "chage -l #{escape(user)} | sed -n 's/^Minimum.*: //p'" end def get_maximum_days_between_password_change(user) "chage -l #{escape(user)} | sed -n 's/^Maximum.*: //p'" end def get_uid(user) "id -u #{escape(user)}" end def get_gid(user) "id -g #{escape(user)}" end def get_home_directory(user) "getent passwd #{escape(user)} | cut -f 6 -d ':'" end def get_login_shell(user) "getent passwd #{escape(user)} | cut -f 7 -d ':'" end def update_home_directory(user, directory) "usermod -d #{escape(directory)} #{escape(user)}" end def update_login_shell(user, shell) "usermod -s #{escape(shell)} #{escape(user)}" end def update_uid(user, uid) "usermod -u #{escape(uid)} #{escape(user)}" end def update_gid(user, gid) "usermod -g #{escape(gid)} #{escape(user)}" end def add(user, options) command = ['useradd'] command << '-g' << escape(options[:gid]) if options[:gid] command << '-d' << escape(options[:home_directory]) if options[:home_directory] command << '-p' << escape(options[:password]) if options[:password] command << '-s' << escape(options[:shell]) if options[:shell] command << '-m' if options[:create_home] command << '-r' if options[:system_user] command << '-u' << escape(options[:uid]) if options[:uid] command << escape(user) command.join(' ') end def update_encrypted_password(user, encrypted_password) %Q!echo #{escape("#{user}:#{encrypted_password}")} | chpasswd -e! end def get_encrypted_password(user) "getent shadow #{escape(user)} | cut -f 2 -d ':'" end end end specinfra-2.82.8/lib/specinfra/command/base/fstab.rb0000644000004100000410000000010513614203316022304 0ustar www-datawww-dataclass Specinfra::Command::Base::Fstab < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/base/ppa.rb0000644000004100000410000000010313614203316021763 0ustar www-datawww-dataclass Specinfra::Command::Base::Ppa < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/base/ipnat.rb0000644000004100000410000000010513614203316022320 0ustar www-datawww-dataclass Specinfra::Command::Base::Ipnat < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/base/bridge.rb0000644000004100000410000000010613614203316022442 0ustar www-datawww-dataclass Specinfra::Command::Base::Bridge < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/base/package.rb0000644000004100000410000000446313614203316022613 0ustar www-datawww-dataclass Specinfra::Command::Base::Package < Specinfra::Command::Base class << self def check_is_installed_by_gem(name, version=nil, gem_binary="gem") gem_installed_command(gem_binary, name, version) end def check_is_installed_by_td_agent_gem(name, version=nil) gem_installed_command("/usr/sbin/td-agent-gem", name, version) end def check_is_installed_by_rvm(name, version=nil) regexp = "^#{name}" cmd = "rvm list strings | grep -iw -- #{escape(regexp)}" cmd = "#{cmd} | grep -w -- #{escape(version)}" if version cmd end def check_is_installed_by_npm(name, version=nil) cmd = "npm ls #{escape(name)} -g" cmd = "#{cmd} | grep -w -- #{escape(version)}" if version cmd end def check_is_installed_by_pecl(name, version=nil) regexp = "^#{name}" cmd = "pecl list | grep -iw -- #{escape(regexp)}" cmd = "#{cmd} | grep -w -- #{escape(version)}" if version cmd end def check_is_installed_by_pear(name, version=nil) regexp = "^#{name}" cmd = "pear list -a | grep -iw -- #{escape(regexp)}" cmd = "#{cmd} | grep -w -- #{escape(version)}" if version cmd end def check_is_installed_by_pip(name, version=nil) regexp = "^#{name}" cmd = "pip list | grep -iw -- #{escape(regexp)}" cmd = "#{cmd} | grep -w -- #{escape(version)}" if version cmd end def check_is_installed_by_pip2(name, version=nil) regexp = "^#{name}" cmd = "pip2 list | grep -iw -- #{escape(regexp)}" cmd = "#{cmd} | grep -w -- #{escape(version)}" if version cmd end def check_is_installed_by_pip3(name, version=nil) regexp = "^#{name} " cmd = "pip3 list | grep -iw -- #{escape(regexp)}" cmd = "#{cmd} | grep -w -- #{escape(version)}" if version cmd end def check_is_installed_by_cpan(name, version=nil) regexp = "^#{name}" cmd = "cpan -l | grep -iw -- #{escape(regexp)}" cmd = "#{cmd} | grep -w -- #{escape(version)}" if version cmd end private def gem_installed_command(gem_binary, name, version=nil) regexp = "^#{name} " cmd = "#{gem_binary} list --local | grep -iw -- #{escape(regexp)}" cmd = %Q!#{cmd} | grep -w -- "[( ]#{escape(version)}[,)]"! if version cmd end end end specinfra-2.82.8/lib/specinfra/command/base/localhost.rb0000644000004100000410000000030113614203316023173 0ustar www-datawww-dataclass Specinfra::Command::Base::Localhost < Specinfra::Command::Base class << self def check_is_ec2_instance 'curl --connect-timeout=1 http://169.254.169.254:80/' end end end specinfra-2.82.8/lib/specinfra/command/base/zfs.rb0000644000004100000410000000010413614203316022006 0ustar www-datawww-dataclass Specinfra::Command::Base::Zfs < Specinfra::Command::Base; end specinfra-2.82.8/lib/specinfra/command/base/kvm_guest.rb0000644000004100000410000000011013614203316023205 0ustar www-datawww-dataclass Specinfra::Command::Base::KvmGuest < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/base/bond.rb0000644000004100000410000000010413614203316022126 0ustar www-datawww-dataclass Specinfra::Command::Base::Bond < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/base/port.rb0000644000004100000410000000057513614203316022204 0ustar www-datawww-dataclass Specinfra::Command::Base::Port < Specinfra::Command::Base class << self def check_is_listening(port, options={}) pattern = ":#{port} " pattern = " #{options[:local_address]}#{pattern}" if options[:local_address] pattern = "^#{options[:protocol]} .*#{pattern}" if options[:protocol] "netstat -tunl | grep -- #{escape(pattern)}" end end end specinfra-2.82.8/lib/specinfra/command/base/file.rb0000644000004100000410000001222413614203316022131 0ustar www-datawww-dataclass Specinfra::Command::Base::File < Specinfra::Command::Base class << self def check_is_file(file) "test -f #{escape(file)}" end def check_is_directory(directory) "test -d #{escape(directory)}" end def check_is_pipe(file) "test -p #{escape(file)}" end def check_is_socket(file) "test -S #{escape(file)}" end def check_is_block_device(file) "test -b #{escape(file)}" end def check_is_character_device(file) "test -c #{escape(file)}" end def check_is_symlink(file) "test -L #{escape(file)}" end def check_contains(file, expected_pattern) "#{check_contains_with_regexp(file, expected_pattern)} || #{check_contains_with_fixed_strings(file, expected_pattern)}" end def check_is_grouped(file, group) regexp = "^#{group}$" if group.is_a?(Numeric) || (group =~ /\A\d+\z/ ? true : false) "stat -c %g #{escape(file)} | grep -- #{escape(regexp)}" else "stat -c %G #{escape(file)} | grep -- #{escape(regexp)}" end end def check_is_owned_by(file, owner) regexp = "^#{owner}$" if owner.is_a?(Numeric) || (owner =~ /\A\d+\z/ ? true : false) "stat -c %u #{escape(file)} | grep -- #{escape(regexp)}" else "stat -c %U #{escape(file)} | grep -- #{escape(regexp)}" end end def check_has_mode(file, mode) regexp = "^#{mode}$" "stat -c %a #{escape(file)} | grep -- #{escape(regexp)}" end def check_contains_within(file, expected_pattern, from=nil, to=nil) from ||= '1' to ||= '$' sed = "sed -n #{escape(from)},#{escape(to)}p #{escape(file)}" sed += " | sed -n 1,#{escape(to)}p" if from != '1' and to != '$' checker_with_regexp = check_contains_with_regexp("-", expected_pattern) checker_with_fixed = check_contains_with_fixed_strings("-", expected_pattern) "#{sed} | #{checker_with_regexp} || #{sed} | #{checker_with_fixed}" end def check_contains_lines(file, expected_lines, from=nil, to=nil) require 'digest/md5' from ||= '1' to ||= '$' sed = "sed -n #{escape(from)},#{escape(to)}p #{escape(file)}" head_line = expected_lines.first.chomp lines_checksum = Digest::MD5.hexdigest(expected_lines.map(&:chomp).join("\n") + "\n") afterwards_length = expected_lines.length - 1 "#{sed} | grep -A #{escape(afterwards_length)} -F -- #{escape(head_line)} | md5sum | grep -qiw -- #{escape(lines_checksum)}" end def check_contains_with_regexp(file, expected_pattern) "grep -qs -- #{escape(expected_pattern)} #{escape(file)}" end def check_contains_with_fixed_strings(file, expected_pattern) "grep -qFs -- #{escape(expected_pattern)} #{escape(file)}" end def check_exists(file) "test -e #{escape(file)}" end def get_md5sum(file) "md5sum #{escape(file)} | cut -d ' ' -f 1" end def get_sha256sum(file) "sha256sum #{escape(file)} | cut -d ' ' -f 1" end def get_content(file) "cat #{escape(file)} 2> /dev/null || echo -n" end def check_is_mounted(path) regexp = "on #{path} " "mount | grep -- '#{escape(regexp)}'" end def get_mode(file) "stat -c %a #{escape(file)}" end def get_owner_user(file) "stat -c %U #{escape(file)}" end def get_owner_group(file) "stat -c %G #{escape(file)}" end def check_is_linked_to(link, target) %Q|test x"$(readlink #{escape(link)})" = x"#{escape(target)}"| end def check_is_link(link) "test -L #{escape(link)}" end def get_link_target(link) "readlink #{escape(link)}" end def get_link_realpath(link) "readlink -e #{escape(link)}" end def check_is_dereferenceable(link) %Q|test -n "$(readlink -e #{escape(link)})"| end def get_mtime(file) "stat -c %Y #{escape(file)}" end def get_size(file) "stat -c %s #{escape(file)}" end def change_mode(file, mode, options = {}) option = '-R' if options[:recursive] "chmod #{option} #{mode} #{escape(file)}".squeeze(' ') end def change_owner(file, owner, group=nil, options = {}) option = '-R' if options[:recursive] owner = "#{owner}:#{group}" if group "chown #{option} #{escape(owner)} #{escape(file)}".squeeze(' ') end def change_group(file, group, options = {}) option = '-R' if options[:recursive] "chgrp #{option} #{escape(group)} #{escape(file)}".squeeze(' ') end def create_as_directory(file) "mkdir -p #{escape(file)}" end def copy(src, dest, options = {}) option = '-p' option << 'R' if options[:recursive] "cp #{option} #{escape(src)} #{escape(dest)}" end def move(src, dest) "mv #{escape(src)} #{escape(dest)}" end def link_to(link, target, options = {}) option = '-s' option << 'f' if options[:force] option << 'n' if options[:no_dereference] "ln #{option} #{escape(target)} #{escape(link)}" end def remove(file) "rm -rf #{escape(file)}" end def download(src, dest) "curl -sSL #{escape(src)} -o #{escape(dest)}" end end end specinfra-2.82.8/lib/specinfra/command/base/service.rb0000644000004100000410000000120313614203316022645 0ustar www-datawww-dataclass Specinfra::Command::Base::Service < Specinfra::Command::Base class << self include Specinfra::Command::Module::Service::Init include Specinfra::Command::Module::Service::Systemd include Specinfra::Command::Module::Service::Daemontools include Specinfra::Command::Module::Service::Supervisor include Specinfra::Command::Module::Service::Upstart include Specinfra::Command::Module::Service::Runit include Specinfra::Command::Module::Service::Monit include Specinfra::Command::Module::Service::God extend Specinfra::Command::Module::Service::Delegator def_delegator_service_under :init end end specinfra-2.82.8/lib/specinfra/command/base/mail_alias.rb0000644000004100000410000000102713614203316023304 0ustar www-datawww-dataclass Specinfra::Command::Base::MailAlias < Specinfra::Command::Base class << self def check_is_aliased_to(mail_alias, recipient) ## if the recipient contains pipes escape them ## or egrep will interpret it as an OR recipient = recipient.gsub(/\|/, '\|') recipient = "[[:space:]]([\"']?)#{recipient}\\1(,|$)" "getent aliases #{escape(mail_alias)} | egrep -- #{escape(recipient)}" end def add(mail_alias, recipient) "echo #{mail_alias}: #{recipient} >> /etc/aliases" end end end specinfra-2.82.8/lib/specinfra/command/base/inventory.rb0000644000004100000410000000027613614203316023253 0ustar www-datawww-dataclass Specinfra::Command::Base::Inventory < Specinfra::Command::Base class << self def get_user 'getent passwd' end def get_group 'getent group' end end end specinfra-2.82.8/lib/specinfra/command/base/process.rb0000644000004100000410000000103613614203316022667 0ustar www-datawww-dataclass Specinfra::Command::Base::Process < Specinfra::Command::Base class << self def get(process, opts) "ps -C #{escape(process)} -o #{opts[:format]} | head -1" end def count(process) "ps aux | grep -w -- #{escape(process)} | grep -v grep | wc -l" end def check_is_running(process) "ps aux | grep -w -- #{escape(process)} | grep -qv grep" end def check_count(process,count) "test $(ps aux | grep -w -- #{escape(process)} | grep -v grep | wc -l) -eq #{escape(count)}" end end end specinfra-2.82.8/lib/specinfra/command/base/host.rb0000644000004100000410000000251513614203316022171 0ustar www-datawww-dataclass Specinfra::Command::Base::Host < Specinfra::Command::Base class << self def check_is_resolvable(name, type) if type == "dns" %Q[lookup=$(nslookup -timeout=1 #{escape(name)} | grep -A1 'Name:' | grep Address | awk -F': ' '{print $2}'); if [ "$lookup" ]; then $(exit 0); else $(exit 1); fi] elsif type == "hosts" "sed 's/#.*$//' /etc/hosts | grep -w -- #{escape(name)} /etc/hosts" else "getent hosts #{escape(name)}" end end def check_is_reachable(host, port, proto, timeout) if port.nil? "ping -w #{escape(timeout)} -c 2 -n #{escape(host)}" else "nc -w #{escape(timeout)} -vvvvz#{escape(proto[0].chr)} #{escape(host)} #{escape(port)}" end end # getent hosts on a dualstack machine will most likely # return the ipv6 address to ensure one can more cleary # define the outcome the ipv{4,6}_address are used. def get_ipaddress(name) "getent hosts #{escape(name)} | awk '{print $1}'" end def get_ipv4_address(name) # Will return multiple values pick the first and exit "getent ahostsv4 #{escape(name)} | awk '{print $1; exit}'" end def get_ipv6_address(name) # Will return multiple values pick the first and exit "getent ahostsv6 #{escape(name)} | awk '{print $1; exit}'" end end end specinfra-2.82.8/lib/specinfra/command/base/cron.rb0000644000004100000410000000111013614203316022143 0ustar www-datawww-dataclass Specinfra::Command::Base::Cron < Specinfra::Command::Base class << self def check_has_entry(user, entry) entry_escaped = entry.gsub(/\\/, '\\\\\\').gsub(/\*/, '\\*').gsub(/\[/, '\\[').gsub(/\]/, '\\]') grep_command = "grep -v '^[[:space:]]*#' | grep -- ^#{escape(entry_escaped)}$" if user.nil? "crontab -l | #{grep_command}" else "crontab -u #{escape(user)} -l | #{grep_command}" end end def get_table 'cat /etc/cron.d/* /etc/crontab /var/spool/cron/* /var/spool/cron/crontabs/* 2> /dev/null' end end end specinfra-2.82.8/lib/specinfra/command/base/routing_table.rb0000644000004100000410000000045113614203316024047 0ustar www-datawww-dataclass Specinfra::Command::Base::RoutingTable < Specinfra::Command::Base class << self def check_has_entry(destination) if destination == "default" destination = "0.0.0.0/0" end "ip route show #{destination}" end alias :get_entry :check_has_entry end end specinfra-2.82.8/lib/specinfra/command/base/ip6tables.rb0000644000004100000410000000011113614203316023073 0ustar www-datawww-dataclass Specinfra::Command::Base::Ip6tables < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/base/selinux.rb0000644000004100000410000000010713614203316022676 0ustar www-datawww-dataclass Specinfra::Command::Base::Selinux < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/alpine.rb0000644000004100000410000000004613614203316021547 0ustar www-datawww-dataclass Specinfra::Command::Alpine; end specinfra-2.82.8/lib/specinfra/command/darwin/0000755000004100000410000000000013614203316021236 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/darwin/base.rb0000644000004100000410000000010613614203316022472 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/darwin/base/0000755000004100000410000000000013614203316022150 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/darwin/base/interface.rb0000644000004100000410000000345513614203316024444 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::Interface < Specinfra::Command::Base::Interface class << self def check_exists(name) "ifconfig #{name}" end def check_has_ipv4_address(interface, ip_address) ip_address = ip_address.dup if ip_address =~ /\/\d+$/ # remove the prefix - better would be to calculate the netmask ip_address.gsub!(/\/\d+$/, "") end ip_address << " " ip_address.gsub!(".", "\\.") "ifconfig #{interface} inet | grep 'inet #{ip_address}'" end def check_has_ipv6_address(interface, ip_address) ip_address = ip_address.dup (ip_address, prefixlen) = ip_address.split(/\//) ip_address.downcase! if ip_address =~ /^fe80::/i # link local needs the scope (interface) appended ip_address << "%#{interface}" end unless prefixlen.to_s.empty? # append prefixlen ip_address << " prefixlen #{prefixlen}" else ip_address << " " end "ifconfig #{interface} inet6 | grep 'inet6 #{ip_address}'" end def get_ipv4_address(interface) "ifconfig #{interface} inet | grep inet | awk '{print $2}'" end def get_ipv6_address(interface) # Awk refuses to print '/' even with using escapes or hex so workaround with sed employed here. "ifconfig #{interface} inet6 | grep inet6 | awk '{print $2$3$4}' | sed 's/prefixlen/\//'; exit" end def get_link_state(interface) # Checks if interfaces is administratively up with the -u arg. # L1 check via status. Virtual interfaces like tapX missing the status will report up. # Emulates operstate in linux with exception of the unknown status. %Q{ifconfig -u #{interface} 2>&1 | awk -v s=up '/status:/ && $2 != "active" { s="down" }; END {print s}'} end end end specinfra-2.82.8/lib/specinfra/command/darwin/base/user.rb0000644000004100000410000000102213614203316023446 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::User < Specinfra::Command::Base::User class << self def check_has_home_directory(user, path_to_home) "#{get_home_directory(user)} | grep -E '^#{escape(path_to_home)}$'" end def check_has_login_shell(user, path_to_shell) "finger #{escape(user)} | grep -E '^Directory' | awk '{ print $4 }' | grep -E '^#{escape(path_to_shell)}$'" end def get_home_directory(user) "finger #{escape(user)} | grep -E '^Directory' | awk '{ print $2 }'" end end end specinfra-2.82.8/lib/specinfra/command/darwin/base/package.rb0000644000004100000410000000343513614203316024075 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::Package < Specinfra::Command::Base::Package class << self def check_is_installed(package, version=nil) escaped_package = escape(File.basename(package)) if version cmd = %Q[brew info #{escaped_package} | grep -E "^$(brew --prefix)/Cellar/#{escaped_package}/#{escape(version)}"] else cmd = "#{brew_list} | grep -E '^#{escaped_package}$'" end cmd end alias :check_is_installed_by_homebrew :check_is_installed def check_is_installed_by_homebrew_cask(package, version=nil) escaped_package = escape(File.basename(package)) if version cmd = "brew cask info #{escaped_package} | grep -E '^/opt/homebrew-cask/Caskroom/#{escaped_package}/#{escape(version)}'" else cmd = "#{brew_cask_list} | grep -E '^#{escaped_package}$'" end cmd end def check_is_installed_by_pkgutil(package, version=nil) cmd = "pkgutil --pkg-info #{package}" cmd = "#{cmd} | grep '^version: #{escape(version)}'" if version cmd end def install(package, version=nil, option='') # Homebrew doesn't support to install specific version. cmd = "brew install #{option} '#{package}'" end def remove(package, option='') cmd = "brew uninstall #{option} '#{package}'" end def get_version(package, opts=nil) %Q[ls -1 "$(brew --prefix)/Cellar/#{package}/" | tail -1] end def brew_list # Since `brew list` is slow, directly check Cellar directory 'ls -1 "$(brew --prefix)/Cellar/"' end def brew_cask_list # Since `brew cask list` is slow, directly check Caskroom directory # Brew cask can install in multiple directories "ls -1 /opt/homebrew-cask/Caskroom/ /usr/local/Caskroom" end end end specinfra-2.82.8/lib/specinfra/command/darwin/base/port.rb0000644000004100000410000000077313614203316023470 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::Port < Specinfra::Command::Base::Port class << self def check_is_listening(port, options={}) regexp = ":#{port} " protocol = options[:protocol] || 'tcp' protocol_options = case protocol when 'tcp' "-iTCP -sTCP:LISTEN" when 'tcp6' "-i6TCP -sTCP:LISTEN" when 'udp' "-iUDP" when 'udp6' "-i6UDP" end "lsof -nP #{protocol_options} | grep -- #{escape(regexp)}" end end end specinfra-2.82.8/lib/specinfra/command/darwin/base/file.rb0000644000004100000410000000225613614203316023421 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::File < Specinfra::Command::Base::File class << self def check_is_accessible_by_user(file, user, access) "sudo -u #{user} -s /bin/test -#{access} #{file}" end def get_md5sum(file) "openssl md5 #{escape(file)} | cut -d'=' -f2 | cut -c 2-" end def get_sha256sum(file) "ruby -e \"require 'digest'; puts Digest::SHA256.hexdigest File.read '#{escape(file)}'\"" end def check_is_linked_to(link, target) "stat -f %Y #{escape(link)} | grep -- #{escape(target)}" end def check_has_mode(file, mode) regexp = "^#{mode}$" "stat -f%Lp #{escape(file)} | grep -- #{escape(regexp)}" end def check_is_owned_by(file, owner) regexp = "^#{owner}$" "stat -f %Su #{escape(file)} | grep -- #{escape(regexp)}" end def check_is_grouped(file, group) regexp = "^#{group}$" "stat -f %Sg #{escape(file)} | grep -- #{escape(regexp)}" end def get_mode(file) "stat -f%Lp #{escape(file)}" end def get_owner_user(file) "stat -f %Su #{escape(file)}" end def get_owner_group(file) "stat -f %Sg #{escape(file)}" end end end specinfra-2.82.8/lib/specinfra/command/darwin/base/service.rb0000644000004100000410000000050413614203316024134 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::Service < Specinfra::Command::Base::Service class << self def check_is_enabled(service, level=nil) "launchctl list | grep #{escape(service)}" end def check_is_running(service) "launchctl list | grep #{escape(service)} | grep -E '^[0-9]+'" end end end specinfra-2.82.8/lib/specinfra/command/darwin/base/inventory.rb0000644000004100000410000000071713614203316024537 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::Inventory < Specinfra::Command::Base::Inventory class << self def get_memory 'false' end def get_cpu 'false' end def get_hostname 'hostname -s' end def get_domain 'hostname -f | ' + 'awk -v h=`hostname -s` \'$1 ~ h { sub(h".", "", $1); print $1 }\'' end def get_fqdn 'hostname -f' end def get_filesystem 'df -k' end end end specinfra-2.82.8/lib/specinfra/command/darwin/base/process.rb0000644000004100000410000000040313614203316024150 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::Process < Specinfra::Command::Base::Process class << self def get(process, opts) "ps -A -c -o #{opts[:format]},command | grep -E -m 1 ^\\ *[0-9]+\\ +#{escape(process)}$ | awk '{print $1}'" end end end specinfra-2.82.8/lib/specinfra/command/darwin/base/host.rb0000644000004100000410000000326313614203316023456 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::Host < Specinfra::Command::Base::Host class << self def check_is_resolvable(name, type) if type == "dns" ## try to resolve either A or AAAA record; grep is used to return the appropriate exit code %Q{dig +search +short +time=1 -q #{escape(name)} a #{escape(name)} aaaa | grep -qie '^[0-9a-f:.]*$'} elsif type == "hosts" "sed 's/#.*$//' /etc/hosts | grep -w -- #{escape(name)}" else ## grep is required as dscacheutil always returns exit code 0 "dscacheutil -q host -a name #{escape(name)} | grep -q '_address:'" end end def check_is_reachable(host, port, proto, timeout) if port.nil? "ping -t #{escape(timeout)} -c 2 -n #{escape(host)}" else "nc -vvvvz#{escape(proto[0].chr)} #{escape(host)} #{escape(port)} -w #{escape(timeout)}" end end def get_ipaddress(name) # If the query returns multiple records the most likey match is returned. # Generally this means IPv6 wins over IPv4. %Q{dscacheutil -q host -a name #{escape(name)} | } + %Q{awk '/^ipv6_/{ ip = $2 }; /^$/{ exit }; /^ip_/{ ip = $2; exit}; END{ print ip }'} end def get_ipv4_address(name) ## With dscacheutil multiple IPs can be returned for IPv4 just pick the first one %Q{dscacheutil -q host -a name #{escape(name)} | awk '/^ip_/{ print $2; exit }'} end def get_ipv6_address(name) ## With dscacheutil multiple IPs can be returned. For IPv6 the link-local is displayed first ## hence the last entry is picked. %Q{dscacheutil -q host -a name #{escape(name)} | awk '/^ipv6_/{ ip = $2 } END{ print ip }'} end end end specinfra-2.82.8/lib/specinfra/command/clearlinux/0000755000004100000410000000000013614203316022120 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/clearlinux/base.rb0000644000004100000410000000012013614203316023350 0ustar www-datawww-dataclass Specinfra::Command::Clearlinux::Base < Specinfra::Command::Linux::Base endspecinfra-2.82.8/lib/specinfra/command/clearlinux/base/0000755000004100000410000000000013614203316023032 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/clearlinux/base/package.rb0000644000004100000410000000106513614203316024754 0ustar www-datawww-dataclass Specinfra::Command::Clearlinux::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) "swupd bundle-list --quiet | grep -w #{escape(package)}" end alias :check_is_installed_by_swupd :check_is_installed def get_version(package, opts=nil) "true" end def install(package, version=nil, option='') "swupd bundle-add --quiet #{package}" end def remove(package, option='') "swupd bundle-remove --quiet #{option} #{package}" end end end specinfra-2.82.8/lib/specinfra/command/clearlinux/base/service.rb0000644000004100000410000000025013614203316025014 0ustar www-datawww-dataclass Specinfra::Command::Clearlinux::Base::Service < Specinfra::Command::Linux::Base::Service class << self include Specinfra::Command::Module::Systemd end endspecinfra-2.82.8/lib/specinfra/command/plamo.rb0000644000004100000410000000004513614203316021406 0ustar www-datawww-dataclass Specinfra::Command::Plamo; end specinfra-2.82.8/lib/specinfra/command/cumulus.rb0000644000004100000410000000014513614203316021774 0ustar www-datawww-dataclass Specinfra::Command::Cumuluslinux; end class Specinfra::Command::Cumulusnetworks; end specinfra-2.82.8/lib/specinfra/command/devuan.rb0000644000004100000410000000004613614203316021561 0ustar www-datawww-dataclass Specinfra::Command::Devuan; end specinfra-2.82.8/lib/specinfra/command/aix.rb0000644000004100000410000000004313614203316021055 0ustar www-datawww-dataclass Specinfra::Command::Aix; end specinfra-2.82.8/lib/specinfra/command/windows/0000755000004100000410000000000013614203316021444 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/windows/base.rb0000644000004100000410000000066013614203316022705 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base class << self def create self end private def create_command(command, using_ps1 = nil) Backend::PowerShell::Command.new do using using_ps1 if using_ps1 exec command end end def windows_account account match = /((.+)\\)?(.+)/.match account domain = match[2] name = match[3] [name, domain] end end end specinfra-2.82.8/lib/specinfra/command/windows/base/0000755000004100000410000000000013614203316022356 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/windows/base/group.rb0000644000004100000410000000057513614203316024046 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::Group < Specinfra::Command::Windows::Base class << self def check_exists(group) group_id, domain = windows_account group Backend::PowerShell::Command.new do using 'find_group.ps1' exec "(FindGroup -groupName '#{group_id}'#{domain.nil? ? "" : " -domain '#{domain}'"}) -ne $null" end end end end specinfra-2.82.8/lib/specinfra/command/windows/base/feature.rb0000644000004100000410000000074213614203316024341 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::Feature < Specinfra::Command::Windows::Base class << self def check_is_enabled(name, provider) if provider.nil? cmd = "@(ListWindowsFeatures -feature #{name}).count -gt 0" else cmd = "@(ListWindowsFeatures -feature #{name} -provider #{provider.to_s}).count -gt 0" end Backend::PowerShell::Command.new do using 'list_windows_features.ps1' exec cmd end end end end specinfra-2.82.8/lib/specinfra/command/windows/base/user.rb0000644000004100000410000000156513614203316023670 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::User < Specinfra::Command::Windows::Base class << self def check_exists(user) user_id, domain = windows_account user Backend::PowerShell::Command.new do using 'find_user.ps1' exec "(FindUser -userName '#{user_id}'#{domain.nil? ? "" : " -domain '#{domain}'"}) -ne $null" end end def check_belongs_to_group(user, group) user_id, user_domain = windows_account user group_id, group_domain = windows_account group Backend::PowerShell::Command.new do using 'find_user.ps1' using 'find_group.ps1' using 'find_usergroup.ps1' exec "(FindUserGroup -userName '#{user_id}'#{user_domain.nil? ? "" : " -userDomain '#{user_domain}'"} -groupName '#{group_id}'#{group_domain.nil? ? "" : " -groupDomain '#{group_domain}'"}) -ne $null" end end end end specinfra-2.82.8/lib/specinfra/command/windows/base/iis_app_pool.rb0000644000004100000410000000420013614203316025354 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::IisAppPool < Specinfra::Command::Windows::Base class << self def check_exists(name) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "@(FindIISAppPool -name '#{name}').count -gt 0" end end def check_has_dotnet_version(name, dotnet) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISAppPool -name '#{name}').managedRuntimeVersion -match 'v#{dotnet}'" end end def check_has_32bit_enabled(name) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISAppPool -name '#{name}').enable32BitAppOnWin64 -eq $true" end end def check_has_idle_timeout(name, minutes) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISAppPool -name '#{name}').processModel.idleTimeout.Minutes -eq #{minutes}" end end def check_has_identity_type(name, type) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISAppPool -name '#{name}').processModel.identityType -eq '#{type}'" end end def check_has_user_profile(name) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISAppPool -name '#{name}').processModel.loadUserProfile -eq $true" end end def check_has_username(name, username) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISAppPool -name '#{name}').processModel.username -eq '#{username}'" end end def check_has_periodic_restart(name, minutes) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISAppPool -name '#{name}').recycling.periodicRestart.time.TotalMinutes -eq #{minutes}" end end def check_has_managed_pipeline_mode(name, mode) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISAppPool -name '#{name}').managedPipelineMode -eq '#{mode}'" end end end end specinfra-2.82.8/lib/specinfra/command/windows/base/registry_key.rb0000644000004100000410000000337613614203316025434 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::RegistryKey < Specinfra::Command::Windows::Base class << self REGISTRY_KEY_TYPES = { :type_string => 'String', :type_binary => 'Binary', :type_dword => 'DWord', :type_qword => 'QWord', :type_multistring => 'MultiString', :type_expandstring => 'ExpandString' } def check_exists(key_name) cmd = "(Get-Item 'Registry::#{key_name}') -ne $null" create_command cmd end def check_has_property(key_name, key_property) cmd = "(Get-Item 'Registry::#{key_name}').GetValueKind('#{key_property[:name]}') -eq '#{get_key_type(key_property[:type])}'" create_command cmd end def check_has_value(key_name, key_property) value = convert_key_property_value key_property cmd = "(Compare-Object (Get-Item 'Registry::#{key_name}').GetValue('#{key_property[:name]}') #{value}) -eq $null" create_command cmd end private def do_not_convert?(key_type) key_type.to_s =~ /_converted/i end def get_key_type(key_type) REGISTRY_KEY_TYPES[key_type.to_s.gsub("_converted",'').to_sym] end def convert_key_property_value property return property[:value] if do_not_convert? property[:type] case property[:type] when :type_binary byte_array = [property[:value]].pack('H*').bytes.to_a "([byte[]] #{byte_array.join(',')})" when :type_dword [property[:value].rjust(8, '0').scan(/[0-9a-f]{2}/i).reverse.join].pack("H*").unpack("l").first when :type_qword property[:value].hex else string_array = property[:value].split("\n").map {|s| "'#{s}'"}.reduce {|acc, s| "#{acc},#{s}"} "@(#{string_array})" end end end end specinfra-2.82.8/lib/specinfra/command/windows/base/scheduled_task.rb0000644000004100000410000000050013614203316025660 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::ScheduledTask < Specinfra::Command::Windows::Base class << self def check_exists(name) Backend::PowerShell::Command.new do using 'find_scheduled_task.ps1' exec "(FindScheduledTask -name '#{name}').TaskName -eq '\\#{name}'" end end end end specinfra-2.82.8/lib/specinfra/command/windows/base/package.rb0000644000004100000410000000066313614203316024303 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::Package < Specinfra::Command::Windows::Base class << self def check_is_installed(package, version=nil) version_selection = version.nil? ? "" : "-appVersion '#{version}'" Backend::PowerShell::Command.new do using 'find_installed_application.ps1' exec "(FindInstalledApplication -appName '#{package}' #{version_selection}) -eq $true" end end end end specinfra-2.82.8/lib/specinfra/command/windows/base/hot_fix.rb0000644000004100000410000000114413614203316024343 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::HotFix < Specinfra::Command::Windows::Base class << self def check_is_installed(description, hot_fix_id=nil) hot_fix_id_match = /(KB\d+)/i.match(description) hot_fix_id = hot_fix_id_match ? hot_fix_id_match[1] : description if hot_fix_id.nil? args = [ '-description', "'#{description}'", '-hotFixId', "'#{hot_fix_id}'" ] cmd = "(FindInstalledHotFix #{args.join(' ')})" Backend::PowerShell::Command.new do using 'find_installed_hot_fix.ps1' exec "#{cmd} -eq $true" end end end end specinfra-2.82.8/lib/specinfra/command/windows/base/port.rb0000644000004100000410000000102613614203316023666 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::Port < Specinfra::Command::Windows::Base class << self def check_is_listening(port, options=nil) Backend::PowerShell::Command.new do using 'is_port_listening.ps1' exec "IsPortListening -portNumber #{port}" end end def check_is_listening_with_protocol(port, protocol) Backend::PowerShell::Command.new do using 'is_port_listening.ps1' exec "IsPortListening -portNumber #{port} -protocol '#{protocol}'" end end end end specinfra-2.82.8/lib/specinfra/command/windows/base/file.rb0000644000004100000410000000735613614203316023635 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::File < Specinfra::Command::Windows::Base class << self def check_exists(file) cmd = %Q!Test-Path -Path "#{file}"! Backend::PowerShell::Command.new do exec cmd end end def check_is_file(file) cmd = item_has_attribute file, 'Archive' Backend::PowerShell::Command.new do exec cmd end end def check_is_directory(dir) cmd = item_has_attribute dir, 'Directory' Backend::PowerShell::Command.new do exec cmd end end def check_is_hidden(file) cmd = item_has_attribute file, 'Hidden' Backend::PowerShell::Command.new do exec cmd end end def check_is_readonly(file) cmd = item_has_attribute file, 'ReadOnly' Backend::PowerShell::Command.new do exec cmd end end def check_is_system(file) cmd = item_has_attribute file, 'System' Backend::PowerShell::Command.new do exec cmd end end def get_content(file) %Q!Get-Content("#{file}") | Write-Host! end def get_md5sum(file) <<-EOT $md5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider $sum = [System.BitConverter]::ToString($md5.ComputeHash([System.IO.File]::ReadAllBytes("#{file}"))) echo $sum.ToLower().Replace("-","") EOT end def check_is_accessible_by_user(file, user, access) case access when 'r' check_is_readable(file, user) when 'w' check_is_writable(file, user) when 'x' check_is_executable(file, user) end end def check_is_readable(file, by_whom) Backend::PowerShell::Command.new do using 'check_file_access_rules.ps1' exec "CheckFileAccessRules -path '#{file}' -identity '#{get_identity by_whom}' -rules @('FullControl', 'Modify', 'ReadAndExecute', 'Read', 'ListDirectory')" end end def check_is_writable(file, by_whom) Backend::PowerShell::Command.new do using 'check_file_access_rules.ps1' exec "CheckFileAccessRules -path '#{file}' -identity '#{get_identity by_whom}' -rules @('FullControl', 'Modify', 'Write')" end end def check_is_executable(file, by_whom) Backend::PowerShell::Command.new do using 'check_file_access_rules.ps1' exec "CheckFileAccessRules -path '#{file}' -identity '#{get_identity by_whom}' -rules @('FullControl', 'Modify', 'ReadAndExecute', 'ExecuteFile')" end end def check_contains(file, pattern) Backend::PowerShell::Command.new do exec %Q!(Get-Content("#{file}") | Out-String) -match '#{convert_regexp(pattern)}'! end end def check_contains_within file, pattern, from=nil, to=nil from ||= '^' to ||= '$' Backend::PowerShell::Command.new do using 'crop_text.ps1' exec %Q!(CropText -text (Get-Content("#{file}") | Out-String) -fromPattern '#{convert_regexp(from)}' -toPattern '#{convert_regexp(to)}') -match '#{pattern}'! end end def check_has_version(name,version) cmd = "((Get-Command '#{name}').FileVersionInfo.ProductVersion -eq '#{version}') -or ((Get-Command '#{name}').FileVersionInfo.FileVersion -eq '#{version}')" Backend::PowerShell::Command.new { exec cmd } end def check_is_owned_by(file, owner) Backend::PowerShell::Command.new do exec "$(if((Get-Item '#{file}').GetAccessControl().Owner -match '#{owner}' -or ((Get-Item '#{file}').GetAccessControl().Owner -match '#{owner}').Length -gt 0){ $TRUE } else { $FALSE })" end end private def item_has_attribute item, attribute %Q!((Get-Item -Path "#{item}" -Force).attributes.ToString() -Split ', ') -contains '#{attribute}'! end end end specinfra-2.82.8/lib/specinfra/command/windows/base/service.rb0000644000004100000410000000303113614203316024340 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::Service < Specinfra::Command::Windows::Base class << self def check_is_installed(service) Backend::PowerShell::Command.new do using 'find_service.ps1' exec "@(FindService -name '#{service}').count -gt 0" end end def check_has_start_mode(service, mode) Backend::PowerShell::Command.new do using 'find_service.ps1' exec "'#{mode}' -match (FindService -name '#{service}').StartMode -and (FindService -name '#{service}') -ne $null" end end def check_is_enabled(service, level=nil) Backend::PowerShell::Command.new do using 'find_service.ps1' exec "(FindService -name '#{service}').StartMode -eq 'Auto'" end end def check_is_running(service) Backend::PowerShell::Command.new do using 'find_service.ps1' exec "(FindService -name '#{service}').State -eq 'Running'" end end def check_has_property(service, property) command = [] property.keys.each do |key| value= property[key] command << "(FindService -name '#{service}').#{key} -eq '#{value}'" end executable = command.join(' -and ') Backend::PowerShell::Command.new do using 'find_service.ps1' exec executable end end def get_property(service) Backend::PowerShell::Command.new do using 'find_service.ps1' exec "(FindService -name '#{service}') | Select-Object *" end end end end specinfra-2.82.8/lib/specinfra/command/windows/base/iis_website.rb0000644000004100000410000000413013614203316025207 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::IisWebsite < Specinfra::Command::Windows::Base class << self def check_is_enabled(name) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISWebsite -name '#{name}').serverAutoStart -eq $true" end end def check_is_installed(name) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "@(FindIISWebsite -name '#{name}').count -gt 0" end end def check_is_running(name) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISWebsite -name '#{name}').state -eq 'Started'" end end def check_is_in_app_pool(name, app_pool) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISWebsite -name '#{name}').applicationPool -match '#{app_pool}'" end end def check_has_physical_path(name, path) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "[System.Environment]::ExpandEnvironmentVariables( ( FindIISWebsite -name '#{name}' ).physicalPath ).replace('\\', '/' ) -eq ('#{path}'.trimEnd('/').replace('\\', '/'))" end end def check_has_site_bindings(name, port, protocol, ipaddress, host_header) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindSiteBindings -name '#{name}' -protocol '#{protocol}' -hostHeader '#{host_header}' -port #{port} -ipAddress '#{ipaddress}').count -gt 0" end end def check_has_virtual_dir(name, vdir, path) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindSiteVirtualDir -name '#{name}' -vdir '#{vdir}' -path '#{path}') -eq $true" end end def check_has_site_application(name, app, pool, physical_path) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindSiteApplication -name '#{name}' -app '#{app}' -pool '#{pool}' -physicalPath '#{physical_path}') -eq $true" end end end end specinfra-2.82.8/lib/specinfra/command/windows/base/process.rb0000644000004100000410000000174113614203316024364 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::Process < Specinfra::Command::Windows::Base class << self def check_process(process) Backend::PowerShell::Command.new do exec "(Get-Process '#{process}') -ne $null" end end def get(process, opts) column = opts[:format].chomp '=' case column when 'pid' # map 'pid' to its windows equivalent get_process_property(process, 'processid') when 'user' %Q!gwmi win32_process -filter "name = '#{process}'" | select -first 1 | %{$_.getowner().user}! when 'group' # no concept of process group on Windows raise NotImplementedError.new('Unable to get process group on Windows') else get_process_property(process, column) end end private def get_process_property(process, property) %Q!Get-WmiObject Win32_Process -Filter "name = '#{process}'" | select -First 1 #{property} -ExpandProperty #{property}! end end end specinfra-2.82.8/lib/specinfra/command/windows/base/host.rb0000644000004100000410000000170013614203316023656 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::Host < Specinfra::Command::Windows::Base class << self def check_is_resolvable(name, type) if type == "hosts" cmd = "@(Select-String -path (Join-Path -Path $($env:windir) -ChildPath 'system32/drivers/etc/hosts') -pattern '#{name}\\b').count -gt 0" else cmd = "@([System.Net.Dns]::GetHostAddresses('#{name}')).count -gt 0" end Backend::PowerShell::Command.new { exec cmd } end def check_is_reachable(host, port, proto, timeout) if port.nil? Backend::PowerShell::Command.new do exec "(New-Object System.Net.NetworkInformation.Ping).send('#{host}').Status -eq 'Success'" end else Backend::PowerShell::Command.new do using 'is_remote_port_listening.ps1' exec"(IsRemotePortListening -hostname #{host} -port #{port} -timeout #{timeout} -proto #{proto}) -eq $true" end end end end end specinfra-2.82.8/lib/specinfra/command/windows/base/firewall.rb0000644000004100000410000000242513614203316024513 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::Firewall < Specinfra::Command::Windows::Base class << self def check_exists(displayName) cmd = "(Get-NetFirewallRule -DisplayName '#{displayName}') -ne $null" create_command cmd end def check_is_enabled(displayName) cmd = "((Get-NetFirewallRule -DisplayName '#{displayName}') | where {$_.Enabled -eq 'True'}) -ne $null" create_command cmd end def check_has_action(displayName, action) cmd = "((Get-NetFirewallRule -DisplayName '#{displayName}') | where {$_.Action -eq '#{action}'}) -ne $null" create_command cmd end def check_has_protocol(displayName, protocol) cmd = "((Get-NetFirewallRule -DisplayName '#{displayName}') | Get-NetFirewallPortFilter | where {$_.Protocol -eq '#{protocol}'}) -ne $null" create_command cmd end def check_has_localport(displayName, localport) cmd = "((Get-NetFirewallRule -DisplayName '#{displayName}') | Get-NetFirewallPortFilter | where {$_.LocalPort -eq '#{localport}'}) -ne $null" create_command cmd end def check_has_direction(displayName, direction) cmd = "((Get-NetFirewallRule -DisplayName '#{displayName}') | where {$_.Direction -eq '#{direction}'}) -ne $null" create_command cmd end end end specinfra-2.82.8/lib/specinfra/command/linuxmint.rb0000644000004100000410000000005113614203316022322 0ustar www-datawww-dataclass Specinfra::Command::Linuxmint; end specinfra-2.82.8/lib/specinfra/command/coreos.rb0000644000004100000410000000004613614203316021571 0ustar www-datawww-dataclass Specinfra::Command::Coreos; end specinfra-2.82.8/lib/specinfra/command/eos/0000755000004100000410000000000013614203316020540 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/eos/base.rb0000644000004100000410000000011313614203316021772 0ustar www-datawww-dataclass Specinfra::Command::Eos::Base < Specinfra::Command::Fedora::Base end specinfra-2.82.8/lib/specinfra/command/amazon.rb0000644000004100000410000000004613614203316021564 0ustar www-datawww-dataclass Specinfra::Command::Amazon;end specinfra-2.82.8/lib/specinfra/command/clearlinux.rb0000644000004100000410000000005113614203316022441 0ustar www-datawww-dataclass Specinfra::Command::Clearlinux; endspecinfra-2.82.8/lib/specinfra/command/cumulus/0000755000004100000410000000000013614203316021447 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/cumulus/base.rb0000644000004100000410000000026313614203316022707 0ustar www-datawww-dataclass Specinfra::Command::Cumuluslinux::Base < Specinfra::Command::Debian::Base end class Specinfra::Command::Cumulusnetworks::Base < Specinfra::Command::Cumuluslinux::Base end specinfra-2.82.8/lib/specinfra/command/cumulus/base/0000755000004100000410000000000013614203316022361 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/cumulus/base/ppa.rb0000644000004100000410000000117213614203316023467 0ustar www-datawww-dataclass Specinfra::Command::Cumuluslinux::Base::Ppa < Specinfra::Command::Debian::Base::Ppa class << self def check_exists(package) %Q{find /etc/apt/ -name \*.list | xargs grep -o "deb +http://repo.cumulusnetworks.com/#{to_apt_line_uri(package)}"} end def check_is_enabled(package) %Q{find /etc/apt/ -name \*.list | xargs grep -o "^deb +http://repo.cumulusnetworks.com/#{to_apt_line_uri(package)}"} end private def to_apt_line_uri(repo) escape(repo.gsub(/^ppa:/,'')) end end end class Specinfra::Command::Cumulusnetworks::Base::Ppa < Specinfra::Command::Cumuluslinux::Base::Ppa end specinfra-2.82.8/lib/specinfra/command/cumulus/base/service.rb0000644000004100000410000000056613614203316024355 0ustar www-datawww-dataclass Specinfra::Command::Cumuluslinux::Base::Service < Specinfra::Command::Debian::Base::Service class << self def check_is_running(service) "service #{escape(service)} status && service #{escape(service)} status | grep 'running'" end end end class Specinfra::Command::Cumulusnetworks::Base::Service < Specinfra::Command::Cumuluslinux::Base::Service end specinfra-2.82.8/lib/specinfra/command/eos.rb0000644000004100000410000000004313614203316021062 0ustar www-datawww-dataclass Specinfra::Command::Eos; end specinfra-2.82.8/lib/specinfra/command/raspbian.rb0000644000004100000410000000010513614203316022072 0ustar www-datawww-dataclass Specinfra::Command::Raspbian < Specinfra::Command::Debian; end specinfra-2.82.8/lib/specinfra/command/gentoo.rb0000644000004100000410000000004613614203316021572 0ustar www-datawww-dataclass Specinfra::Command::Gentoo; end specinfra-2.82.8/lib/specinfra/command/fedora.rb0000644000004100000410000000004613614203316021537 0ustar www-datawww-dataclass Specinfra::Command::Fedora; end specinfra-2.82.8/lib/specinfra/command/alpine/0000755000004100000410000000000013614203316021222 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/alpine/base.rb0000644000004100000410000000011513614203316022456 0ustar www-datawww-dataclass Specinfra::Command::Alpine::Base < Specinfra::Command::Linux::Base end specinfra-2.82.8/lib/specinfra/command/alpine/base/0000755000004100000410000000000013614203316022134 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/alpine/base/package.rb0000644000004100000410000000130513614203316024053 0ustar www-datawww-dataclass Specinfra::Command::Alpine::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version = nil) if version.nil? then pkg = escape(package) "apk info -qe #{pkg}" else pkg = "#{package}-#{version}" "apk info -v | grep -w -- '^#{Regexp.escape(pkg)}'" end end alias_method :check_is_installed_by_apk, :check_is_installed def install(package, version = nil, _option = '') pkg = [escape(package), version].compact.join('=') "apk add -U #{pkg}" end def get_version(package, _opts = nil) "apk version #{package} | tail -n1 | awk '{ print $3; }'" end end end specinfra-2.82.8/lib/specinfra/command/alpine/base/service.rb0000644000004100000410000000127513614203316024126 0ustar www-datawww-dataclass Specinfra::Command::Alpine::Base::Service < Specinfra::Command::Linux::Base::Service class << self def check_is_enabled(service, level=3) "rc-update show boot default | grep -w #{escape(service)}" end def check_is_running(service) "/etc/init.d/#{escape(service)} status" end def enable(service) "rc-update add #{escape(service)}" end def disable(service) "rc-update del #{escape(service)}" end def start(service) "rc-service #{escape(service)} start" end def stop(service) "rc-service #{escape(service)} stop" end def restart(service) "rc-service #{escape(service)} restart" end end end specinfra-2.82.8/lib/specinfra/command/alpine/base/process.rb0000644000004100000410000000115213614203316024136 0ustar www-datawww-dataclass Specinfra::Command::Alpine::Base::Process < Specinfra::Command::Base class << self def get(process, opts) col = opts[:format].chomp('=') if col == 'args' "ps -o #{col} | grep #{escape(process)} | head -1" else "ps -o #{col},args | grep -E '\\s+#{process}' | awk '{ print $1 }' | head -1" end end def check_is_running(process) "ps -ocomm | grep -w -- #{escape(process)} | grep -qv grep" end def check_count(process, count) "test $(ps -ocomm | grep -w -- #{escape(process)} | grep -v grep | wc -l) -eq #{escape(count)}" end end end specinfra-2.82.8/lib/specinfra/command/alpine/base/host.rb0000644000004100000410000000060313614203316023435 0ustar www-datawww-dataclass Specinfra::Command::Alpine::Base::Host < Specinfra::Command::Base::Host class << self def check_is_reachable(host, port, proto, timeout) if port.nil? "ping -w #{escape(timeout)} -c 2 -n #{escape(host)}" else "nc -w #{escape(timeout)} -vvvvz#{proto.downcase.start_with?('u') ? 'u' : ''} #{escape(host)} #{escape(port)}" end end end end specinfra-2.82.8/lib/specinfra/command/openbsd/0000755000004100000410000000000013614203316021404 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/openbsd/base.rb0000644000004100000410000000011113614203316022634 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base < Specinfra::Command::Base end specinfra-2.82.8/lib/specinfra/command/openbsd/v57/0000755000004100000410000000000013614203316022025 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/openbsd/v57/service.rb0000644000004100000410000000135413614203316024015 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::V57::Service < Specinfra::Command::Openbsd::Base::Service class << self def check_is_enabled(service, level=nil) "rcctl get #{escape(service)} status" end def check_is_running(service) "rcctl check #{escape(service)}" end def enable(service) "rcctl set #{escape(service)} status on" end def disable(service) "rcctl set #{escape(service)} status off" end def start(service) "rcctl start #{escape(service)}" end def stop(service) "rcctl stop #{escape(service)}" end def restart(service) "rcctl restart #{escape(service)}" end def reload(service) "rcctl reload #{escape(service)}" end end end specinfra-2.82.8/lib/specinfra/command/openbsd/v57.rb0000644000004100000410000000011713614203316022351 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::V57 < Specinfra::Command::Openbsd::Base end specinfra-2.82.8/lib/specinfra/command/openbsd/base/0000755000004100000410000000000013614203316022316 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/openbsd/base/interface.rb0000644000004100000410000000375213614203316024612 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Interface < Specinfra::Command::Base::Interface class << self def check_exists(name) "ifconfig #{name}" end def get_speed_of(name) "ifconfig #{name} | grep 'media\:' | perl -pe 's|.*media\:.*\\((.*?)\\)|\\1|'" end def check_has_ipv4_address(interface, ip_address) ip_address = ip_address.dup if ip_address =~ /\/\d+$/ # remove the prefix - better would be to calculate the netmask ip_address.gsub!(/\/\d+$/, "") end ip_address << " " ip_address.gsub!(".", "\\.") "ifconfig #{interface} inet | grep 'inet #{ip_address}'" end def check_has_ipv6_address(interface, ip_address) ip_address = ip_address.dup (ip_address, prefixlen) = ip_address.split(/\//) ip_address.downcase! if ip_address =~ /^fe80::/i # link local needs the scope (interface) appended ip_address << "%#{interface}" end unless prefixlen.to_s.empty? # append prefixlen ip_address << " prefixlen #{prefixlen}" else ip_address << " " end "ifconfig #{interface} inet6 | grep 'inet6 #{ip_address}'" end def get_ipv4_address(interface) "ifconfig #{interface} inet | grep inet | awk '{print $2}'" end def get_ipv6_address(interface) # Awk refuses to print '/' even with using escapes or hex so workaround with sed employed here. "ifconfig #{interface} inet6 | grep inet6 | awk '{print $2$3$4}' | sed 's/prefixlen/\//'; exit" end def get_link_state(interface) # Checks if interfaces is administratively up by parsing the options. # L1 check via status. Virtual interfaces like tapX missing the status will report up. # Emulates operstate in linux with exception of the unknown status. %Q{ifconfig #{interface} 2>&1 | awk -v s=down -F '[:<>,]' } + %Q{'NR == 1 && $3 == "UP" { s="up" }; /status:/ && $2 != " active" { s="down" }; END{ print s }'} end end end specinfra-2.82.8/lib/specinfra/command/openbsd/base/user.rb0000644000004100000410000000062113614203316023620 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::User < Specinfra::Command::Base::User class << self def check_has_login_shell(user, path_to_shell) "getent passwd #{escape(user)} | cut -f 7 -d ':' | grep #{escape(path_to_shell)}" end def check_has_home_directory(user, path_to_home) "getent passwd #{escape(user)} | cut -f 6 -d ':' | grep #{escape(path_to_home)}" end end end specinfra-2.82.8/lib/specinfra/command/openbsd/base/fstab.rb0000644000004100000410000000043513614203316023744 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Fstab < Specinfra::Command::Base::Fstab class << self def check_has_entry(mount_point) %Q(awk '{if($2=="#{escape(mount_point)}")print}' /etc/fstab | grep -v '^[[:space:]]*#') end alias :get_entry :check_has_entry end end specinfra-2.82.8/lib/specinfra/command/openbsd/base/bridge.rb0000644000004100000410000000041713614203316024101 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Bridge < Specinfra::Command::Base::Bridge class << self def check_exists(name) "ifconfig #{name}" end def check_has_interface(name, interface) "ifconfig #{name} | grep -o #{interface}" end end end specinfra-2.82.8/lib/specinfra/command/openbsd/base/package.rb0000644000004100000410000000070613614203316024241 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Package < Specinfra::Command::Base::Package class << self def check_is_installed(package, version=nil) if version "pkg_info -a | cut -d ' ' -f 1 | grep #{escape(package)}-#{escape(version)}" else "pkg_info -a | cut -d ' ' -f 1 | grep #{escape(package)}" end end def install(package, version=nil, option='') "pkg_add #{option} #{package}" end end end specinfra-2.82.8/lib/specinfra/command/openbsd/base/bond.rb0000644000004100000410000000041313614203316023563 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Bond < Specinfra::Command::Base::Bond class << self def check_exists(name) "ifconfig #{name}" end def check_has_interface(name, interface) "ifconfig #{name} | grep -o #{interface}" end end end specinfra-2.82.8/lib/specinfra/command/openbsd/base/port.rb0000644000004100000410000000071713614203316023634 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Port < Specinfra::Command::Base::Port class << self def check_is_listening(port, opts={}) protocol = opts[:protocol] case protocol when 'tcp' return "netstat -nat -f inet | egrep '(tcp.*.#{port}.*LISTEN$)'" when 'udp' return "netstat -nat -f inet | egrep '(udp.*.#{port}.*$)'" end "netstat -nat -f inet | egrep '((tcp|udp).*\.#{port}.*LISTEN$)'" end end end specinfra-2.82.8/lib/specinfra/command/openbsd/base/file.rb0000644000004100000410000000214313614203316023562 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::File < Specinfra::Command::Base::File class << self def get_md5sum(file) "cksum -qa md5 #{escape(file)} | cut -d ' ' -f 1" end def get_sha256sum(file) "cksum -qa sha256 #{escape(file)} | cut -d ' ' -f 1" end def check_is_linked_to(link, target) "stat -f %Y #{escape(link)} | grep -- #{escape(target)}" end def check_has_mode(file, mode) regexp = "^#{mode}$" "stat -f%Lp #{escape(file)} | grep #{escape(regexp)}" end def check_is_owned_by(file, owner) regexp = "^#{owner}$" "stat -f %Su #{escape(file)} | grep -- #{escape(regexp)}" end def check_is_grouped(file, group) regexp = "^#{group}$" "stat -f %Sg #{escape(file)} | grep -- #{escape(regexp)}" end def check_is_mounted(path) regexp = "on #{path} " "mount | grep #{escape(regexp)}" end def get_mode(file) "stat -f%Lp #{escape(file)}" end def get_mtime(file) "stat -f %m #{escape(file)}" end def get_size(file) "stat -f %z #{escape(file)}" end end end specinfra-2.82.8/lib/specinfra/command/openbsd/base/service.rb0000644000004100000410000000071513614203316024306 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Service < Specinfra::Command::Base::Service class << self def create(os_info=nil) if (os_info || os)[:release].to_f < 5.7 self else Specinfra::Command::Openbsd::V57::Service end end def check_is_enabled(service, level=nil) "/etc/rc.d/#{escape(service)} status" end def check_is_running(service) "/etc/rc.d/#{escape(service)} check" end end end specinfra-2.82.8/lib/specinfra/command/openbsd/base/mail_alias.rb0000644000004100000410000000046713614203316024745 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::MailAlias < Specinfra::Command::Base::MailAlias class << self def check_is_aliased_to(recipient, target) target = %Q{([[:space:]]|,)["']?#{escape(target)}["']?(,|$)} "egrep ^#{escape(recipient)}:.*#{escape(target)} /etc/mail/aliases" end end end specinfra-2.82.8/lib/specinfra/command/openbsd/base/inventory.rb0000644000004100000410000000102513614203316024676 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Inventory < Specinfra::Command::Base::Inventory class << self def get_memory 'false' end def get_cpu 'false' end def get_hostname 'hostname -s' end def get_domain 'hostname | ' + 'awk -v h=`hostname -s` \'$1 ~ h { sub(h".", "", $1); print $1 }\'' end def get_fqdn 'hostname' end def get_filesystem 'df -kP' end def get_system_product_name 'sysctl -n hw.product' end end end specinfra-2.82.8/lib/specinfra/command/openbsd/base/host.rb0000644000004100000410000000125713614203316023625 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Host < Specinfra::Command::Base::Host class << self def get_ipaddress(name) # getent hosts will return both the ipv6 and ipv4 record. # this will only pick the first one. (Linux behavior) "getent hosts #{escape(name)} | awk '{print $1; exit}'" end def get_ipv4_address(name) # May return multiple values pick the one matching ipv4 "getent hosts #{escape(name)} | awk '$1 ~ /^[0-9.]+$/ {print $1}'" end def get_ipv6_address(name) # May return multiple values pick the one matching ipv6 "getent hosts #{escape(name)} | awk 'tolower($1) ~ /^[0-9a-f:]+$/ {print $1}'" end end end specinfra-2.82.8/lib/specinfra/command/openbsd/base/routing_table.rb0000644000004100000410000000042013614203316025475 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::RoutingTable < Specinfra::Command::Base::RoutingTable class << self def check_has_entry(destination) "route -n show -gateway | egrep '^#{destination}' | head -1" end alias :get_entry :check_has_entry end end specinfra-2.82.8/lib/specinfra/command/ubuntu.rb0000644000004100000410000000004613614203316021621 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu; end specinfra-2.82.8/lib/specinfra/command/devuan/0000755000004100000410000000000013614203316021234 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/devuan/base.rb0000644000004100000410000000011613614203316022471 0ustar www-datawww-dataclass Specinfra::Command::Devuan::Base < Specinfra::Command::Debian::Base end specinfra-2.82.8/lib/specinfra/command/devuan/base/0000755000004100000410000000000013614203316022146 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/devuan/base/package.rb0000644000004100000410000000014013614203316024061 0ustar www-datawww-dataclass Specinfra::Command::Devuan::Base::Package < Specinfra::Command::Debian::Base::Package end specinfra-2.82.8/lib/specinfra/command/amazon/0000755000004100000410000000000013614203316021237 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/amazon/base.rb0000644000004100000410000000011613614203316022474 0ustar www-datawww-dataclass Specinfra::Command::Amazon::Base < Specinfra::Command::Redhat::Base end specinfra-2.82.8/lib/specinfra/command/amazon/v2/0000755000004100000410000000000013614203316021566 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/command/amazon/v2/port.rb0000644000004100000410000000023113614203316023073 0ustar www-datawww-dataclass Specinfra::Command::Amazon::V2::Port < Specinfra::Command::Amazon::Base::Port class << self include Specinfra::Command::Module::Ss end end specinfra-2.82.8/lib/specinfra/command/amazon/v2/service.rb0000644000004100000410000000024413614203316023553 0ustar www-datawww-dataclass Specinfra::Command::Amazon::V2::Service < Specinfra::Command::Amazon::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.82.8/lib/specinfra/command/amazon/v2.rb0000644000004100000410000000011413614203316022107 0ustar www-datawww-dataclass Specinfra::Command::Amazon::V2 < Specinfra::Command::Redhat::Base end specinfra-2.82.8/lib/specinfra/command/poky.rb0000644000004100000410000000004413614203316021257 0ustar www-datawww-dataclass Specinfra::Command::Poky; end specinfra-2.82.8/lib/specinfra/command/sles.rb0000644000004100000410000000004413614203316021243 0ustar www-datawww-dataclass Specinfra::Command::Sles; end specinfra-2.82.8/lib/specinfra/command/module.rb0000644000004100000410000000010713614203316021562 0ustar www-datawww-datamodule Specinfra module Command module Module end end end specinfra-2.82.8/lib/specinfra/helper.rb0000644000004100000410000000033013614203316020134 0ustar www-datawww-datarequire 'specinfra/helper/os' require 'specinfra/helper/docker' require 'specinfra/helper/lxc' require 'specinfra/helper/configuration' require 'specinfra/helper/properties' require 'specinfra/helper/host_inventory' specinfra-2.82.8/lib/specinfra/command_factory.rb0000644000004100000410000000467413614203316022041 0ustar www-datawww-dataclass Specinfra::CommandFactory @@types = nil def self.instance self.new(os) end def initialize(os_info) @os_info = os_info end def get(meth, *args) action, resource_type, subaction = breakdown(meth) method = action method += "_#{subaction}" if subaction command_class = create_command_class(resource_type) if command_class.respond_to?(method) command_class.send(method, *args) else raise NotImplementedError.new("#{method} is not implemented in #{command_class}") end end private def create_command_class(resource_type) family = @os_info[:family] version = @os_info[:release] ? "V#{@os_info[:release].to_i}" : nil common_class = Specinfra::Command base_class = common_class.const_get('Base') os_class = family.nil? ? base_class : common_class.const_get(family.capitalize) if family && version begin version_class = os_class.const_get(version) rescue version_class = os_class.const_get('Base') end elsif family.nil? version_class = os_class elsif family != 'base' && version.nil? version_class = os_class.const_get('Base') end begin command_class = version_class.const_get(resource_type.to_camel_case) rescue end if command_class.nil? ||( (command_class < Specinfra::Command::Base).nil? && (command_class < Specinfra::Command::Windows::Base).nil? ) command_class = base_class.const_get(resource_type.to_camel_case) end begin command_class.create(@os_info) rescue ArgumentError command_class.create end end def breakdown(meth) # Sometimes `selinux_module' type matches `selinux' and error occurs. # Reverse sorting is needed to avoid this problem. types = resource_types.map {|t| t.to_snake_case }.sort.reverse.join('|') md = meth.to_s.match(/^([^_]+)_(#{types})_?(.+)?$/) if md.nil? message = "Could not break down `#{meth}' to appropriate type and method.\n" message += "The method name shoud be in the form of `action_type_subaction'." raise message end return md[1], md[2], md[3] end def resource_types if @@types.nil? @@types = [] Specinfra::Command::Base.subclasses.each do |s| @@types << s.to_s.split(':')[-1] end Specinfra::Command::Windows::Base.subclasses.each do |s| @@types << s.to_s.split(':')[-1] end @@types.uniq! end @@types end end specinfra-2.82.8/lib/specinfra/properties.rb0000644000004100000410000000035313614203316021056 0ustar www-datawww-datarequire 'singleton' module Specinfra class Properties include Singleton def initialize @prop = {} end def properties(prop=nil) if ! prop.nil? @prop = prop end @prop end end end specinfra-2.82.8/lib/specinfra/command_result.rb0000644000004100000410000000114313614203316021674 0ustar www-datawww-datamodule Specinfra class CommandResult attr_reader :stdout, :stderr, :exit_status, :exit_signal def initialize(args = {}) @stdout = args[:stdout] || '' @stderr = args[:stderr] || '' @exit_status = args[:exit_status] || 0 @exit_signal = args[:exit_signal] end def success? @exit_status == 0 end def failure? @exit_status != 0 end def [](x) warn "CommandResult#[] is obsolete. Use accessors instead. in #{caller[0]}" case x when :stdout, :stderr, :exit_status, :exit_signal self.send(x) end end end end specinfra-2.82.8/lib/specinfra/processor.rb0000644000004100000410000001674413614203316020714 0ustar www-datawww-datamodule Specinfra class Processor def self.check_service_is_running(service) cmd = Specinfra.command.get(:check_service_is_running, service) ret = Specinfra.backend.run_command(cmd) # In Ubuntu, some services are under upstart and "service foo status" returns # exit status 0 even though they are stopped. # So return false if stdout contains "stopped/waiting" or "stop/waiting". return false if ret.stdout =~ /stop(ped)?\/waiting/ # If the service is not registered, check by ps command if ret.exit_status == 1 cmd = Specinfra.command.get(:check_process_is_running, service) ret = Specinfra.backend.run_command(cmd) end ret.success? end def self.check_service_is_monitored_by_monit(process) cmd = Specinfra.command.get(:check_service_is_monitored_by_monit, process) ret = Specinfra.backend.run_command(cmd) return false unless ret.stdout != nil && ret.success? retlines = ret.stdout.split(/[\r\n]+/).map(&:strip) proc_index = retlines.index("Process '#{process}'") return false unless proc_index retlines[proc_index+2].match(/\Amonitoring status\s+monitored\Z/i) != nil end def self.check_file_is_readable(file, by_whom) cmd = Specinfra.command.get(:get_file_mode, file) mode = sprintf('%04s',Specinfra.backend.run_command(cmd).stdout.strip) mode = mode.split('') mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1 case by_whom.to_s when '' mode_octal & 0444 != 0 when 'owner' mode_octal & 0400 != 0 when 'group' mode_octal & 0040 != 0 when 'others' mode_octal & 0004 != 0 end end def self.check_file_is_writable(file, by_whom) cmd = Specinfra.command.get(:get_file_mode, file) mode = sprintf('%04s',Specinfra.backend.run_command(cmd).stdout.strip) mode = mode.split('') mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1 case by_whom.to_s when '' mode_octal & 0222 != 0 when 'owner' mode_octal & 0200 != 0 when 'group' mode_octal & 0020 != 0 when 'others' mode_octal & 0002 != 0 end end def self.check_file_is_executable(file, by_whom) cmd = Specinfra.command.get(:get_file_mode, file) mode = sprintf('%04s',Specinfra.backend.run_command(cmd).stdout.strip) mode = mode.split('') mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1 case by_whom.to_s when '' mode_octal & 0111 != 0 when 'owner' mode_octal & 0100 != 0 when 'group' mode_octal & 0010 != 0 when 'others' mode_octal & 0001 != 0 end end def self.check_file_is_mounted(path, expected_attr, only_with) cmd = Specinfra.command.get(:check_file_is_mounted, path) ret = Specinfra.backend.run_command(cmd) if expected_attr.nil? || ret.failure? return ret.success? end mount = ret.stdout.scan(/\S+/) actual_attr = { } actual_attr[:device] = mount[0] # Output of mount depends on os: # a) proc on /proc type proc (rw,noexec,nosuid,nodev) # b) procfs on /proc (procfs, local) actual_attr[:type] = mount[4] if mount[3] == 'type' # case a. if match = ret.stdout.match(/\((.*)\)/) options = match[1].split(',') actual_attr[:type] ||= options.shift # case b. options.each do |option| name, val = option.split('=') if val.nil? actual_attr[name.strip.to_sym] = true else val = val.to_i if val.match(/^\d+$/) actual_attr[name.strip.to_sym] = val end end end if ! expected_attr[:options].nil? expected_attr.merge!(expected_attr[:options]) expected_attr.delete(:options) end if only_with actual_attr == expected_attr else expected_attr.each do |key, val| return false if actual_attr[key] != val end true end end def self.check_fstab_has_entry(expected_attr) return false unless expected_attr[:mount_point] cmd = Specinfra.command.get(:get_fstab_entry, expected_attr[:mount_point]) ret = Specinfra.backend.run_command(cmd) return false if ret.failure? fstab = ret.stdout.scan(/\S+/) actual_attr = { :device => fstab[0], :mount_point => fstab[1], :type => fstab[2], :dump => fstab[4].to_i, :pass => fstab[5].to_i } fstab[3].split(',').each do |option| name, val = option.split('=') if val.nil? actual_attr[name.to_sym] = true else val = val.to_i if val.match(/^\d+$/) actual_attr[name.to_sym] = val end end unless expected_attr[:options].nil? expected_attr.merge!(expected_attr[:options]) expected_attr.delete(:options) end expected_attr.each do |key, val| return false if actual_attr[key] != val end true end def self.check_routing_table_has_entry(expected_attr) return false if ! expected_attr[:destination] cmd = Specinfra.command.get(:get_routing_table_entry, expected_attr[:destination]) ret = Specinfra.backend.run_command(cmd) return false if ret.failure? ret.stdout.gsub!(/\r\n/, "\n") if os[:family] == 'openbsd' match = ret.stdout.match(/^(\S+)\s+(\S+).*?(\S+[0-9]+)(\s*)$/) actual_attr = { :destination => $1, :gateway => $2, :interface => expected_attr[:interface] ? $3 : nil } else matches = ret.stdout.scan(/^(\S+)(?: via (\S+))? dev (\S+).+\n|^(\S+).*\n|\s+nexthop via (\S+)\s+dev (\S+).+/) if matches.length > 1 # ECMP route destination = nil matches.each do |groups| if groups[3] destination = groups[3] next end next if expected_attr[:gateway] && expected_attr[:gateway] != groups[4] next if expected_attr[:interface] && expected_attr[:interface] != groups[5] actual_attr = { :destination => destination, :gateway => groups[4], :interface => groups[5] } end elsif matches.length == 1 # Non-ECMP route groups = matches[0] actual_attr = { :destination => groups[0], :gateway => groups[1] ? groups[1] : groups[3], :interface => expected_attr[:interface] ? groups[2] : nil } end end expected_attr.each do |key, val| return false if actual_attr[key] != val end true end def self.get_default_gateway(attr) cmd = Specinfra.command.get(:get_routing_table_entry, 'default') ret = Specinfra.backend.run_command(cmd) return false if ret.failure? ret.stdout.gsub!(/\r\n/, "\n") if os[:family] == 'openbsd' match = ret.stdout.match(/^(\S+)\s+(\S+).*?(\S+[0-9]+)(\s*)$/) if attr == :gateway $2 elsif attr == :interface $3 end else ret.stdout =~ /^(\S+)(?: via (\S+))? dev (\S+).+\n(?:default via (\S+))?/ if attr == :gateway $2 ? $2 : $4 elsif attr == :interface $3 end end end end end specinfra-2.82.8/lib/specinfra/configuration.rb0000644000004100000410000000324513614203316021534 0ustar www-datawww-datamodule Specinfra module Configuration class << self VALID_OPTIONS_KEYS = [ :backend, :env, :path, :shell, :interactive_shell, :login_shell, :pre_command, :stdout, :stderr, :exit_status, :sudo_path, :disable_sudo, :sudo_options, :docker_container_create_options, :docker_container_exec_options, :docker_image, :docker_url, :lxc, :request_pty, :ssh_options, :ssh_without_env, :dockerfile_finalizer, :telnet_options, :jail_name, ].freeze def defaults VALID_OPTIONS_KEYS.inject({}) { |o, k| o.merge!(k => send(k)) } end # Define os method explicitly to avoid stack level # too deep caused by Helper::DetectOS#os def os(value=nil) @os = value if value if @os.nil? && defined?(RSpec) && RSpec.configuration.respond_to?(:os) @os = RSpec.configuration.os end @os end def method_missing(meth, val=nil) key = meth.to_s.gsub(/=$/, '') ret = nil begin if ! val.nil? instance_variable_set("@#{key}", val) RSpec.configuration.send(:"#{key}=", val) if defined?(RSpec) end if instance_variable_defined?("@#{key}") ret = instance_variable_get("@#{key}") end rescue NameError ret = nil ensure if ret.nil? && defined?(RSpec) && RSpec.configuration.respond_to?(key) ret = RSpec.configuration.send(key) end end ret end end end end specinfra-2.82.8/lib/specinfra/ext.rb0000644000004100000410000000007513614203316017463 0ustar www-datawww-datarequire 'specinfra/ext/class' require 'specinfra/ext/string' specinfra-2.82.8/lib/specinfra/ec2_metadata.rb0000644000004100000410000000353413614203316021177 0ustar www-datawww-data# -*- coding: utf-8 -*- module Specinfra class Ec2Metadata def initialize(host_inventory) @host_inventory = host_inventory @base_uri = 'http://169.254.169.254/latest/meta-data/' @metadata = {} end def get @metadata = get_metadata self end def [](key) if key.is_a?(Symbol) key = key.to_s end if @metadata[key].nil? begin require "specinfra/ec2_metadata/#{key}" inventory_class = Specinfra::Ec2Metadata.const_get(key.to_s.to_camel_case) @metadata[key] = inventory_class.new(@host_inventory).get rescue LoadError @metadata[key] = nil end end @metadata[key] end def empty? @metadata.empty? end def each keys.each do |k| yield k, @metadata[k] end end def each_key keys.each do |k| yield k end end def each_value keys.each do |k| yield @metadata[k] end end def keys @metadata.keys end def inspect @metadata end private def get_metadata(path='') metadata = {} keys = @host_inventory.backend.run_command("curl -s #{@base_uri}#{path}").stdout.split("\n") keys.each do |key| if key =~ %r{/$} metadata[key[0..-2]] = get_metadata(path + key) else if key =~ %r{=} key = key.split('=')[0] + '/' metadata[key[0..-2]] = get_metadata(path + key) else ret = get_endpoint(path) metadata[key] = get_endpoint(path + key) if ret end end end metadata end def get_endpoint(path) ret = @host_inventory.backend.run_command("curl -s #{@base_uri}#{path}") if ret.success? ret.stdout else nil end end end end specinfra-2.82.8/lib/specinfra/backend/0000755000004100000410000000000013614203316017723 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/backend/exec.rb0000644000004100000410000001057313614203316021202 0ustar www-datawww-datarequire 'singleton' require 'fileutils' require 'shellwords' require 'sfl' module Specinfra module Backend class Exec < Base def run_command(cmd, opts={}) cmd = build_command(cmd) cmd = add_pre_command(cmd) stdout, stderr, exit_status = with_env do spawn_command(cmd) end if @example @example.metadata[:command] = cmd @example.metadata[:stdout] = stdout end CommandResult.new :stdout => stdout, :stderr => stderr, :exit_status => exit_status end def send_file(from, to) FileUtils.cp(from, to) end def send_directory(from, to) FileUtils.cp_r(from, to) end def build_command(cmd) shell = get_config(:shell) || '/bin/sh' cmd = cmd.shelljoin if cmd.is_a?(Array) shell = shell.shellescape if get_config(:interactive_shell) shell << " -i" end if get_config(:login_shell) shell << " -l" end cmd = "#{shell} -c #{cmd.to_s.shellescape}" path = get_config(:path) if path cmd = %Q{env PATH="#{path}" #{cmd}} end cmd end private def spawn_command(cmd) stdout, stderr = '', '' begin quit_r, quit_w = IO.pipe out_r, out_w = IO.pipe err_r, err_w = IO.pipe th = Thread.new do output = { quit_r => "", out_r => "", err_r => "" } handlers = { quit_r => nil, out_r => @stdout_handler, err_r => @stderr_handler } begin loop do readable_ios, = IO.select(output.keys) readable_ios.each do |fd| loop do begin out = fd.read_nonblock(4096) output[fd] << out handlers[fd].call(out) if handlers[fd] rescue Errno::EAGAIN # Ruby 2.2 has more specific exception class IO::EAGAINWaitReadable break end end end break unless output[quit_r].empty? end rescue EOFError ensure # Consume remained stdout and stderr from buffer output.keys.each do |fd| loop do begin out = fd.read_nonblock(4096) output[fd] << out handlers[fd].call(out) if handlers[fd] rescue Errno::EAGAIN, EOFError # Ruby 2.2 has more specific exception class IO::EAGAINWaitReadable break end end end stdout = output[out_r] stderr = output[err_r] quit_r.close unless quit_r.closed? out_r.close unless out_r.closed? err_r.close unless err_r.closed? end end th.abort_on_exception = true pid = spawn(cmd, :out => out_w, :err => err_w) pid, stats = Process.waitpid2(pid) out_w.close err_w.close begin quit_w.syswrite 1 rescue Errno::EPIPE end th.value # wait ensure quit_w.close unless quit_w.closed? end return stdout, stderr, stats.exitstatus end def with_env keys = %w[BUNDLER_EDITOR BUNDLE_BIN_PATH BUNDLE_GEMFILE RUBYOPT GEM_HOME GEM_PATH GEM_CACHE] keys.each { |key| ENV["_SPECINFRA_#{key}"] = ENV[key] ; ENV.delete(key) } env = get_config(:env) || {} env[:LANG] ||= 'C' env.each do |key, value| key = key.to_s ENV["_SPECINFRA_#{key}"] = ENV[key]; ENV[key] = value end yield ensure keys.each { |key| ENV[key] = ENV.delete("_SPECINFRA_#{key}") } env.each do |key, value| key = key.to_s ENV[key] = ENV.delete("_SPECINFRA_#{key}"); end end def add_pre_command(cmd) if get_config(:pre_command) pre_cmd = build_command(get_config(:pre_command)) "#{pre_cmd} && #{cmd}" else cmd end end end end end specinfra-2.82.8/lib/specinfra/backend/jexec.rb0000644000004100000410000000216013614203316021345 0ustar www-datawww-datamodule Specinfra module Backend class Jexec < Exec def initialize(config = {}) super(config) jname = get_config(:jail_name) jroot = `jls -j #{jname} path`.strip fail 'fail to get jail path!' if jroot.to_s.empty? set_config(:jail_root, jroot) end def send_file(from, to) jroot = get_config(:jail_root) FileUtils.cp(from, "#{jroot}/#{to}") end def send_directory(from, to) jroot = get_config(:jail_root) FileUtils.cp_r(from, "#{jroot}/#{to}") end def build_command(cmd) shell = get_config(:shell) || '/bin/sh' cmd = cmd.shelljoin if cmd.is_a?(Array) shell = shell.shellescape if get_config(:interactive_shell) shell << " -i" end if get_config(:login_shell) shell << " -l" end cmd = "#{shell} -c #{cmd.to_s.shellescape}" path = get_config(:path) if path cmd = %Q{env PATH="#{path}" #{cmd}} end jname = get_config(:jail_name) "jexec #{jname} #{cmd}" end end end end specinfra-2.82.8/lib/specinfra/backend/docker.rb0000644000004100000410000000656613614203316021534 0ustar www-datawww-datamodule Specinfra module Backend class Docker < Exec def initialize(config = {}) super begin require 'docker' unless defined?(::Docker) rescue LoadError fail "Docker client library is not available. Try installing `docker-api' gem." end ::Docker.url = get_config(:docker_url) if image = get_config(:docker_image) @images = [] @base_image = get_or_pull_image(image) create_and_start_container ObjectSpace.define_finalizer(self, proc { cleanup_container }) elsif container = get_config(:docker_container) @container = ::Docker::Container.get(container) else fail 'Please specify docker_image or docker_container.' end end def run_command(cmd, opts={}) cmd = build_command(cmd) run_pre_command(opts) docker_run!(cmd, opts) end def send_file(from, to) if @base_image @images << commit_container if @container @images << current_image.insert_local('localPath' => from, 'outputPath' => to) cleanup_container create_and_start_container elsif @container # This needs Docker >= 1.8 @container.archive_in(from, to) else fail 'Cannot call send_file without docker_image or docker_container.' end end def commit_container @container.commit end private def create_and_start_container opts = { 'Image' => current_image.id } if current_image.json["Config"]["Cmd"].nil? && current_image.json["Config"]["Entrypoint"].nil? opts.merge!({'Cmd' => ['/bin/sh']}) end opts.merge!({'OpenStdin' => true}) if path = get_config(:path) (opts['Env'] ||= []) << "PATH=#{path}" end env = get_config(:env).to_a.map { |v| v.join('=') } opts['Env'] = opts['Env'].to_a.concat(env) opts.merge!(get_config(:docker_container_create_options) || {}) @container = ::Docker::Container.create(opts) @container.start while @container.json['State'].key?('Health') && @container.json['State']['Health']['Status'] == "starting" do sleep 0.5 end end def cleanup_container @container.stop @container.delete end def current_image @images.last || @base_image end def docker_run!(cmd, opts={}) opts.merge!(get_config(:docker_container_exec_options) || {}) stdout, stderr, status = @container.exec(cmd.shellsplit, opts) CommandResult.new :stdout => stdout.join, :stderr => stderr.join, :exit_status => status rescue ::Docker::Error::DockerError => e raise rescue => e @container.kill err = stderr.nil? ? ([e.message] + e.backtrace) : stderr CommandResult.new :stdout => [stdout].join, :stderr => err.join, :exit_status => (status || 1) end def get_or_pull_image(name) begin ::Docker::Image.get(name) rescue ::Docker::Error::NotFoundError ::Docker::Image.create('fromImage' => name) end end def run_pre_command(opts) if get_config(:pre_command) cmd = build_command(get_config(:pre_command)) docker_run!(cmd, opts) end end end end end specinfra-2.82.8/lib/specinfra/backend/cmd.rb0000644000004100000410000000450613614203316021020 0ustar www-datawww-datarequire 'open3' module Specinfra module Backend class Cmd < Base include PowerShell::ScriptHelper def os_info { :family => 'windows', :release => nil, :arch => nil, :cygwin => `echo $0`.include?("sh") } end def run_command(cmd, opts={}) script = create_script(cmd) psh = powershell if os_info[:cygwin] # convert c:\windows... to /cygdrive/c/windows... psh.gsub!("\\", "/") psh.sub!(":", "") psh = psh.prepend("/cygdrive/") end result = execute_script %Q{#{psh} -NoProfile -encodedCommand #{encode_script(script)}} if @example @example.metadata[:command] = script @example.metadata[:stdout] = result[:stdout] + result[:stderr] end CommandResult.new :stdout => result[:stdout], :stderr => result[:stderr], :exit_status => result[:status] end def execute_script script if Open3.respond_to? :capture3 stdout, stderr, status = Open3.capture3(script) # powershell still exits with 0 even if there are syntax errors, although it spits the error out into stderr # so we have to resort to return an error exit code if there is anything in the standard error status = 1 if status == 0 and !stderr.empty? { :stdout => stdout, :stderr => stderr, :status => status } else stdout = `#{script} 2>&1` { :stdout => stdout, :stderr => nil, :status => $? } end end def check_os # Dirty hack for specs 'Windows' end private def powershell architecture = if @example @example.metadata[:architecture] end architecture ||= get_config(:architecture) case architecture when :i386 then x86_powershell when :x86_64 then x64_powershell else raise ArgumentError, "invalid architecture [#{architecture}]" end end def x64_powershell find_powershell(%w(sysnative system32)) end def x86_powershell find_powershell(%w(syswow64 system32)) end def find_powershell(dirs) ( dirs.map { |dir| "#{ENV['WINDIR']}\\#{dir}\\WindowsPowerShell\\v1.0\\powershell.exe" } ).find { |exe| File.exists?(exe) } || 'powershell' end end end end specinfra-2.82.8/lib/specinfra/backend/telnet.rb0000644000004100000410000000506613614203316021552 0ustar www-datawww-data# -*- coding: utf-8 -*- require 'specinfra/backend/exec' require 'net/telnet' module Specinfra module Backend class Telnet < Exec def run_command(cmd, opt={}) cmd = build_command(cmd) cmd = add_pre_command(cmd) ret = with_env do telnet_exec!(cmd) end if @example @example.metadata[:command] = cmd @example.metadata[:stdout] = ret[:stdout] end CommandResult.new ret end def build_command(cmd) cmd = super(cmd) cmd end private def prompt 'Login: ' end def with_env env = get_config(:env) || {} env[:LANG] ||= 'C' env.each do |key, value| key = key.to_s ENV["_SPECINFRA_#{key}"] = ENV[key]; ENV[key] = value end yield ensure env.each do |key, value| key = key.to_s ENV[key] = ENV.delete("_SPECINFRA_#{key}"); end end def add_pre_command(cmd) if get_config(:pre_command) pre_cmd = build_command(get_config(:pre_command)) "#{pre_cmd} && #{cmd}" else cmd end end def telnet_exec!( command ) stdout_data = '' stderr_data = '' exit_status = nil exit_signal = nil retry_prompt = /^Login: / if get_config(:telnet).nil? set_config(:telnet, create_telnet) end telnet = get_config(:telnet) re = [] unless telnet.nil? re = telnet.cmd( "#{command}; echo $?" ).split("\n")[0..-2] exit_status = re.last.to_i stdout_data = re[1..-2].join("\n") end { :stdout => stdout_data, :stderr => stderr_data, :exit_status => exit_status, :exit_signal => exit_signal } end def create_telnet tel = Net::Telnet.new( "Host" => get_config(:host) ) tel.login( "Name" => get_config(:telnet_options)[:user], "Password" => get_config(:telnet_options)[:pass] ) tel rescue return nil end def sudo if sudo_path = get_config(:sudo_path) sudo_path += '/sudo' else sudo_path = 'sudo' end sudo_options = get_config(:sudo_options) if sudo_options sudo_options = sudo_options.shelljoin if sudo_options.is_a?(Array) sudo_options = ' ' + sudo_options end "#{sudo_path.shellescape}#{sudo_options}" end def sudo? false end end end end specinfra-2.82.8/lib/specinfra/backend/powershell/0000755000004100000410000000000013614203316022107 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/backend/powershell/command.rb0000644000004100000410000000154613614203316024060 0ustar www-datawww-datamodule Specinfra module Backend module PowerShell class Command attr_reader :import_functions, :script def initialize &block @import_functions = [] @script = "" instance_eval(&block) if block_given? end def using *functions functions.each { |f| import_functions << f } end def exec code @script = code end def convert_regexp(target) case target when Regexp target.source else target.to_s.gsub '(^\/|\/$)', '' end end def get_identity id raise "You must provide a specific Windows user/group" if id =~ /(owner|group|others)/ identity = id || 'Everyone' end def to_s @script end end end end end specinfra-2.82.8/lib/specinfra/backend/powershell/script_helper.rb0000644000004100000410000000415113614203316025300 0ustar www-datawww-datarequire 'base64' module Specinfra module Backend module PowerShell module ScriptHelper def build_command(cmd) path = get_config(:path) if path cmd.strip! cmd = <<-EOF $env:path = "#{path};$env:path" #{cmd} EOF end cmd end def add_pre_command(cmd) path = get_config(:path) if get_config(:pre_command) cmd.strip! cmd = <<-EOF #{get_config(:pre_command)} #{cmd} EOF cmd = "$env:path = \"#{path};$env:path\"\n#{cmd}" if path end cmd end def encode_script script script_text = script.chars.to_a.join("\x00").chomp script_text << "\x00" unless script_text[-1].eql? "\x00" if script_text.respond_to?(:encode) script_text = script_text.encode('ASCII-8BIT') end if Base64.respond_to?(:strict_encode64) Base64.strict_encode64(script_text) else [ script_text ].pack("m").strip end end def create_script command if command.is_a? Command ps_functions = command.import_functions.map { |f| File.read(File.join(File.dirname(__FILE__), 'support', f)) } script = build_command(command.script) script = add_pre_command(script) <<-EOF $exitCode = 1 $ProgressPreference = "SilentlyContinue" try { #{ps_functions.join("\n")} $success = $(#{script}) if ($success -is [Boolean] -and $success) { $exitCode = 0 } } catch { Write-Output $_.Exception.Message } Write-Output "Exiting with code: $exitCode" exit $exitCode EOF else script = build_command(command.to_s) add_pre_command(script) end end def check_running(process) ret = run_command(commands.check_running(process)) # If the service is not registered, check the process if ret.exit_status == 1 ret = run_command(commands.check_process(process)) end ret.success? end end end end end specinfra-2.82.8/lib/specinfra/backend/powershell/support/0000755000004100000410000000000013614203316023623 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/backend/powershell/support/find_user.ps10000644000004100000410000000041013614203316026221 0ustar www-datawww-datafunction FindUser { param($userName, $domain) if ($domain -eq $null) {$selectionCriteria = " and LocalAccount = true"} else {$selectionCriteria = " and Domain = '$domain'"} Get-WmiObject Win32_UserAccount -filter "Name = '$userName' $selectionCriteria" } specinfra-2.82.8/lib/specinfra/backend/powershell/support/find_usergroup.ps10000644000004100000410000000073513614203316027310 0ustar www-datawww-datafunction FindUserGroup { param($userName, $groupName, $userDomain, $groupDomain) $user = FindUser -userName $userName -domain $userDomain $group = FindGroup -groupName $groupName -domain $groupDomain if ($user -and $group) { Get-WmiObject Win32_GroupUser -filter ("GroupComponent = 'Win32_Group.Domain=`"" + $group.domain + "`",Name=`"" + $group.name + "`"' and PartComponent = 'Win32_UserAccount.Domain=`"" + $user.domain + "`",Name=`"" + $user.name + "`"'") } }specinfra-2.82.8/lib/specinfra/backend/powershell/support/is_remote_port_listening.ps10000644000004100000410000000267113614203316031364 0ustar www-datawww-datafunction IsRemotePortListening{ param( [string]$hostname, [string]$proto="tcp", [int]$port, [int]$timeout) If ($proto -eq "tcp") { $tcpobject = new-Object system.Net.Sockets.TcpClient $connect = $tcpobject.BeginConnect($hostname,$port,$null,$null) $wait = $connect.AsyncWaitHandle.WaitOne($timeout * 1000,$false) #If timeout If(!$wait) { $tcpobject.Close() return $false } else{ $result = $tcpobject.Connected $tcpobject.Close() return $result } } elseif ($proto -eq "udp") { $udpobject = new-Object system.Net.Sockets.Udpclient $udpobject.client.ReceiveTimeout = $timeout * 1000 $udpobject.Connect($hostname,$port) $a = new-object system.text.asciiencoding $byte = $a.GetBytes("$(Get-Date)") [void]$udpobject.Send($byte,$byte.length) $remoteendpoint = New-Object system.net.ipendpoint([system.net.ipaddress]::Any,0) try{ #Blocks until a message returns on this socket from a remote host. $receivebytes = $udpobject.Receive([ref]$remoteendpoint) [string]$returndata = $a.GetString($receivebytes) If ($returndata) { $udpobject.close() return $true } else{ return $false } } catch{ return $false } } else{ throw "Protocol ${proto} not supported" } } specinfra-2.82.8/lib/specinfra/backend/powershell/support/is_port_listening.ps10000644000004100000410000000104713614203316030005 0ustar www-datawww-datafunction IsPortListening { param($portNumber, $protocol) $netstatOutput = netstat -an | Out-String $networkIPs = (Get-WmiObject Win32_NetworkAdapterConfiguration | ? {$_.IPEnabled}) | %{ $_.IPAddress[0] } [array] $networkIPs += "0.0.0.0" [array] $networkIPs += "127.0.0.1" foreach ($ipaddress in $networkIPs) { $matchExpression = ("$ipaddress" + ":" + $portNumber) if ($protocol) { $matchExpression = ($protocol.toUpper() + "\s+$matchExpression") } if ($netstatOutput -match $matchExpression) { return $true } } $false } specinfra-2.82.8/lib/specinfra/backend/powershell/support/find_installed_hot_fix.ps10000644000004100000410000000052413614203316030750 0ustar www-datawww-datafunction FindInstalledHotFix { param($description, $hotFixId) Write-Host "Num Args:" $args.Length; foreach ($arg in $args) { Write-Host "Arg: $arg"; } Write-Host $description Write-Host $hotFixId $keys= (Get-WmiObject -Class WIN32_QuickFixEngineering) @($keys | Where-Object {$_.HotFixID -like $hotFixId}).Length -gt 0 } specinfra-2.82.8/lib/specinfra/backend/powershell/support/find_scheduled_task.ps10000644000004100000410000000020013614203316030222 0ustar www-datawww-datafunction FindScheduledTask { param($name) $task = schtasks /query /v /fo csv /TN "$name" | ConvertFrom-CSV return $task }specinfra-2.82.8/lib/specinfra/backend/powershell/support/crop_text.ps10000644000004100000410000000047113614203316026261 0ustar www-datawww-datafunction CropText { param($text, $fromPattern, $toPattern) $from, $to = ([regex]::matches($text, $fromPattern)), ([regex]::matches($text, $toPattern)) if ($from.count -gt 0 -and $to.count -gt 0) { $text.substring($from[0].index, $to[0].index + $to[0].length - $from[0].index) } else { "" } } specinfra-2.82.8/lib/specinfra/backend/powershell/support/find_installed_application.ps10000644000004100000410000000242413614203316031614 0ustar www-datawww-datafunction FindInstalledApplication { param($appName, $appVersion) if ((Get-WmiObject win32_operatingsystem).OSArchitecture -notmatch '64') { $keys= (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*') $possible_path= 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' if (Test-Path $possible_path) { $keys+= (Get-ItemProperty $possible_path) } } else { $keys = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*','HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*') $possible_path= 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' if (Test-Path $possible_path) { $keys+= (Get-ItemProperty $possible_path) } $possible_path= 'HKCU:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' if (Test-Path $possible_path) { $keys+= (Get-ItemProperty $possible_path) } } if ($appVersion -eq $null) { @($keys | Where-Object {$_.DisplayName -like $appName -or $_.PSChildName -like $appName}).Length -gt 0 } else{ @($keys | Where-Object {$_.DisplayName -like $appName -or $_.PSChildName -like $appName } | Where-Object {$_.DisplayVersion -eq $appVersion} ).Length -gt 0 } } specinfra-2.82.8/lib/specinfra/backend/powershell/support/find_service.ps10000644000004100000410000000020513614203316026705 0ustar www-datawww-datafunction FindService { param($name) Get-WmiObject Win32_Service | Where-Object {$_.Name -eq $name -or $_.DisplayName -eq $name} }specinfra-2.82.8/lib/specinfra/backend/powershell/support/find_group.ps10000644000004100000410000000040413614203316026402 0ustar www-datawww-datafunction FindGroup { param($groupName, $domain) if ($domain -eq $null) {$selectionCriteria = " and LocalAccount = true"} else {$selectionCriteria = " and Domain = '$domain'"} Get-WmiObject Win32_Group -filter "Name = '$groupName' $selectionCriteria" }specinfra-2.82.8/lib/specinfra/backend/powershell/support/find_iis_component.ps10000644000004100000410000000373213614203316030123 0ustar www-datawww-datafunction FindIISWebsite { param($name) Import-Module WebAdministration Try { Get-Item "IIS:\Sites\$name" -Erroraction silentlycontinue } Catch [System.IO.FileNotFoundException] { Get-Item "IIS:\Sites\$name" -Erroraction silentlycontinue } } function FindIISAppPool { param($name) Import-Module WebAdministration Try { Get-Item "IIS:\AppPools\$name" -Erroraction silentlycontinue } Catch [System.IO.FileNotFoundException] { Get-Item "IIS:\AppPools\$name" -Erroraction silentlycontinue } } function FindSiteBindings { param($name, $protocol, $hostHeader, $port, $ipAddress) Import-Module WebAdministration Try { Get-WebBinding -Name $name -Protocol $protocol -HostHeader $hostHeader -Port $port -IPAddress $ipAddress } Catch [System.IO.FileNotFoundException] { Get-WebBinding -Name $name -Protocol $protocol -HostHeader $hostHeader -Port $port -IPAddress $ipAddress } } function FindSiteVirtualDir { param($name, $vdir, $path) Import-Module WebAdministration $webVirtDirPath = [string]::Format('IIS:\Sites\{0}\{1}',$name, $vdir); if (Test-Path $webVirtDirPath) { if ([string]::IsNullOrEmpty($path)) { $true } else { (Get-Item $webVirtDirPath).physicalPath -eq $path } } else { $false } } function FindSiteApplication { param($name, $app, $pool, $physicalPath) Import-Module WebAdministration $path = "IIS:\Sites\${name}\${app}" $result = $false if (Test-Path $path) { $result = $true if ([string]::IsNullOrEmpty($pool) -eq $false) { $result = $result -and (Get-Item $path).applicationPool -eq $pool } if ([string]::IsNullOrEmpty($physicalPath) -eq $false) { $result = $result -and (Get-Item $path).physicalPath -eq $physicalPath } } $result } specinfra-2.82.8/lib/specinfra/backend/powershell/support/check_file_access_rules.ps10000644000004100000410000000055613614203316031065 0ustar www-datawww-datafunction CheckFileAccessRules { param($path, $identity, $rules) $accessRules = @((Get-Acl $path).access | Where-Object {$_.AccessControlType -eq 'Allow' -and $_.IdentityReference -eq $identity }) $match = @($accessRules | Where-Object {($_.FileSystemRights.ToString().Split(',') | % {$_.trim()} | ? {$rules -contains $_}) -ne $null}) $match.count -gt 0 } specinfra-2.82.8/lib/specinfra/backend/powershell/support/list_windows_features.ps10000644000004100000410000000364613614203316030704 0ustar www-datawww-datafunction ListWindowsFeatures { param( [string]$feature, [string]$provider="dism" ) $cachepath = "${env:temp}/ListWindowsFeatures-${provider}.xml" $maxAge = 2 $cache = Get-Item $cachepath -erroraction SilentlyContinue if($cache -ne $null -and ((get-date) - $cache.LastWriteTime).minutes -lt $maxage){ $features = Import-Clixml $cachepath | Select *| Where-Object {(($_.name -like $feature) -or ($_.displayName -like $feature)) -and (($_.installed -eq $true) -or ($_.state -eq "Enabled"))} return $features } else{ switch($provider) { "dism" { return features_dism | Select * | Where-Object {($_.name -eq $feature) -and ($_.state -eq "Enabled")} } "powershell" { return features_powershell | Select * | Where-Object {(($_.name -like $feature) -or ($_.displayName -like $feature)) -and ($_.installed -eq $true)} } default {throw "Unsupported provider"} } } } function features_dism{ try { $out = DISM /Online /Get-Features /Format:List | Where-Object {$_} if($LASTEXITCODE -ne 0) { Write-Error $out Break } $f = $out[4..($out.length-2)] $features = for($i=0; $i -lt $f.length;$i+=2) { $tmp = $f[$i],$f[$i+1] -replace '^([^:]+:\s)' New-Object PSObject -Property @{ Name = $tmp[0] State = $tmp[1] } } $features | Export-Clixml $cachepath return $features } catch { Throw } } function features_powershell{ $ProgressPreference = "SilentlyContinue" import-module servermanager $features = Get-WindowsFeature $features | Export-Clixml $cachepath return Get-WindowsFeature }specinfra-2.82.8/lib/specinfra/backend/base.rb0000644000004100000410000000231113614203316021157 0ustar www-datawww-datarequire 'singleton' require 'specinfra/command_result' module Specinfra module Backend class Base def self.instance @instance ||= self.new end def self.clear @instance = nil end def initialize(config = {}) @config = config @example = nil end def get_config(key) @config[key] || Specinfra.configuration.send(key) end def set_config(key, value) @config[key] = value end def os_info return @os_info if @os_info Specinfra::Helper::DetectOs.subclasses.each do |klass| if @os_info = klass.new(self).detect @os_info[:arch] ||= self.run_command('uname -m').stdout.strip return @os_info end end raise NotImplementedError, 'OS detection failed.' end def command CommandFactory.new(os_info) end def host_inventory @inventory ||= HostInventory.new(self) end def set_example(e) @example = e end def stdout_handler=(block) @stdout_handler = block end def stderr_handler=(block) @stderr_handler = block end end end end specinfra-2.82.8/lib/specinfra/backend/winrm.rb0000644000004100000410000000236513614203316021412 0ustar www-datawww-datamodule Specinfra module Backend class Winrm < Base include PowerShell::ScriptHelper def os_info { :family => 'windows', :release => nil, :arch => nil } end def run_command(cmd, opts={}) script = create_script(cmd) winrm = get_config(:winrm) stdout, stderr = '' exitcode = 0 if Gem.loaded_specs['winrm'].version < Gem::Version.create('2.0') # Use winrm V1 API result = winrm.powershell(script) stdout, stderr = [:stdout, :stderr].map do |s| result[:data].select {|item| item.key? s}.map {|item| item[s]}.join end exitcode = result[:exitcode] else # Use winrm V2 API winrm.shell(:powershell) do |shell| result = shell.run(script) stdout = result.stdout.to_s stderr = result.stderr.to_s exitcode = result.exitcode end end exitcode = 1 if exitcode == 0 and !stderr.empty? if @example @example.metadata[:command] = script @example.metadata[:stdout] = stdout + stderr end CommandResult.new :stdout => stdout, :stderr => stderr, :exit_status => exitcode end end end end specinfra-2.82.8/lib/specinfra/backend/lxc.rb0000644000004100000410000000201213614203316021031 0ustar www-datawww-datamodule Specinfra module Backend class Lxc < Exec def initialize(config = {}) super begin require 'lxc/extra' unless defined?(::LXC::Extra) rescue LoadError fail "LXC client library is not available. Try installing `lxc-extra' gem" end end def run_command(cmd, opts={}) cmd = build_command(cmd) cmd = add_pre_command(cmd) out, ret = ct.execute do out = `#{cmd} 2>&1` [out, $?.dup] end if @example @example.metadata[:command] = cmd @example.metadata[:stdout] = out end CommandResult.new :stdout => out, :exit_status => ret.exitstatus end def build_command(cmd) cmd end def add_pre_command(cmd) cmd end def send_file(from, to) FileUtils.cp(from, File.join(ct.config_item('lxc.rootfs'), to)) end def ct @ct ||= ::LXC::Container.new(get_config(:lxc)) end end end end specinfra-2.82.8/lib/specinfra/backend/ssh.rb0000644000004100000410000001203613614203316021047 0ustar www-datawww-data# -*- coding: utf-8 -*- require 'specinfra/backend/exec' require 'net/ssh' require 'net/scp' module Specinfra module Backend class Ssh < Exec def run_command(cmd, opt={}) cmd = build_command(cmd) cmd = add_pre_command(cmd) if get_config(:ssh_without_env) ret = ssh_exec!(cmd) else ret = with_env do ssh_exec!(cmd) end end ret[:stdout].gsub!(/\r\n/, "\n") ret[:stdout].gsub!(/\A\n/, "") if sudo? if @example @example.metadata[:command] = cmd @example.metadata[:stdout] = ret[:stdout] end CommandResult.new ret end def send_file(from, to) scp_upload!(from, to) end def send_directory(from, to) scp_upload!(from, to, :recursive => true) end def build_command(cmd) cmd = super(cmd) if sudo? cmd = "#{sudo} -p '#{prompt}' #{cmd}" end cmd end private def prompt 'Password: ' end def with_env env = get_config(:env) || {} env[:LANG] ||= 'C' ssh_options = get_config(:ssh_options) || {} ssh_options[:send_env] ||= [] env.each do |key, value| key = key.to_s ENV["_SPECINFRA_#{key}"] = ENV[key]; ENV[key] = value ssh_options[:send_env] << key end yield ensure env.each do |key, value| key = key.to_s ENV[key] = ENV.delete("_SPECINFRA_#{key}"); end end def create_ssh Net::SSH.start( get_config(:host), get_config(:ssh_options)[:user], get_config(:ssh_options) ) end def create_scp ssh = get_config(:ssh) if ssh.nil? ssh = create_ssh end Net::SCP.new(ssh) end def scp_upload!(from, to, opt={}) if get_config(:scp).nil? set_config(:scp, create_scp) end tmp = File.join('/tmp', File.basename(to)) scp = get_config(:scp) scp.upload!(from, tmp, opt) run_command(command.get(:move_file, tmp, to)) end def ssh_exec!(command) stdout_data = '' stderr_data = '' exit_status = nil exit_signal = nil retry_prompt = /^Sorry, try again/ if get_config(:ssh).nil? set_config(:ssh, create_ssh) end ssh = get_config(:ssh) ssh.open_channel do |channel| if get_config(:sudo_password) or get_config(:request_pty) channel.request_pty do |ch, success| abort "Could not obtain pty " if !success end end channel.exec("#{command}") do |ch, success| abort "FAILED: couldn't execute command (ssh.channel.exec)" if !success channel.on_data do |ch, data| if data.match retry_prompt abort "Wrong sudo password! Please confirm your password on #{get_config(:host)}." elsif data.match /^#{prompt}/ channel.send_data "#{get_config(:sudo_password)}\n" # When pty is allocated and the name of the target host # cannot be resolved, this error is injected into stdout. # So exclude this error message. elsif ! data.match /^sudo: unable to resolve host/ stdout_data += data @stdout_handler.call(data) if @stdout_handler end end channel.on_extended_data do |ch, type, data| if data.match /you must have a tty to run sudo/ abort 'Please write "set :request_pty, true" in your spec_helper.rb or other appropriate file.' end if data.match /^sudo: no tty present and no askpass program specified/ abort 'Please set sudo password to Specinfra.configuration.sudo_password.' else stderr_data += data @stderr_handler.call(data) if @stderr_handler end end channel.on_request("exit-status") do |ch, data| exit_status = data.read_long end channel.on_request("exit-signal") do |ch, data| exit_signal = data.read_long end end end ssh.loop { :stdout => stdout_data, :stderr => stderr_data, :exit_status => exit_status, :exit_signal => exit_signal } end def sudo if sudo_path = get_config(:sudo_path) sudo_path += '/sudo' else sudo_path = 'sudo' end sudo_options = get_config(:sudo_options) if sudo_options sudo_options = sudo_options.shelljoin if sudo_options.is_a?(Array) sudo_options = ' ' + sudo_options end "#{sudo_path.shellescape}#{sudo_options}" end def sudo? user = get_config(:ssh_options)[:user] disable_sudo = get_config(:disable_sudo) user != 'root' && !disable_sudo end end end end specinfra-2.82.8/lib/specinfra/backend/shell_script.rb0000644000004100000410000000100013614203316022732 0ustar www-datawww-datarequire 'singleton' module Specinfra module Backend class ShellScript < Base def initialize(config = {}) super @lines = [ "#!/bin/sh", "" ] ObjectSpace.define_finalizer(self, Writer.new(@lines)) end def run_command(cmd, opts={}) @lines << cmd CommandResult.new end class Writer def initialize(lines) @lines = lines end def call(*args) puts @lines end end end end end specinfra-2.82.8/lib/specinfra/backend/dockerfile.rb0000644000004100000410000000124013614203316022354 0ustar www-datawww-datamodule Specinfra module Backend class Dockerfile < Specinfra::Backend::Base def initialize(config = {}) super @lines = [] ObjectSpace.define_finalizer(self) { if get_config(:dockerfile_finalizer).nil? puts @lines else get_config(:dockerfile_finalizer).call(@lines) end } end def run_command(cmd, opts={}) @lines << "RUN #{cmd}" CommandResult.new end def send_file(from, to) @lines << "ADD #{from} #{to}" CommandResult.new end def from(base) @lines << "FROM #{base}" end end end end specinfra-2.82.8/lib/specinfra/host_inventory/0000755000004100000410000000000013614203316021426 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/host_inventory/kernel.rb0000644000004100000410000000126413614203316023236 0ustar www-datawww-datamodule Specinfra class HostInventory class Kernel < Base def get kernel = {} kernel['machine'] = backend.os_info[:arch] cmd = backend.command.get(:get_inventory_kernel) ret = backend.run_command(cmd) if ret.exit_status == 0 kernel = kernel.merge(parse_uname(ret.stdout)) end kernel end def parse_uname(ret) match = ret.match(/^(\w+) (((\d+\.\d+)\.\d+).*)$/) if match name, release, version, major = match.captures Hash['name', name, "release", release, "version", version, "version_major", major] else nil end end end end end specinfra-2.82.8/lib/specinfra/host_inventory/ohai.rb0000644000004100000410000000061213614203316022672 0ustar www-datawww-datamodule Specinfra class HostInventory class Ohai < Base def get begin require 'json' rescue LoadError return nil end begin ret = backend.run_command('ohai --log_level error') rescue StandardError nil end ret.exit_status.zero? ? JSON.parse(ret.stdout) : nil end end end end specinfra-2.82.8/lib/specinfra/host_inventory/group.rb0000644000004100000410000000137713614203316023117 0ustar www-datawww-datamodule Specinfra class HostInventory class Group < Base def get cmd = backend.command.get(:get_inventory_group) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(cmd_ret) groups = {} lines = cmd_ret.split(/\n/) lines.each do |line| group = line.split(':') members = if group[3] group[3].split(',') else [] end groups[group[0]] = { 'name' => group[0], 'gid' => group[2], 'members' => members } end groups end end end end specinfra-2.82.8/lib/specinfra/host_inventory/facter.rb0000644000004100000410000000047613614203316023226 0ustar www-datawww-datamodule Specinfra class HostInventory class Facter < Base require 'yaml' def get begin ret = backend.run_command('facter --puppet --yaml') rescue StandardError nil end ret.exit_status == 0 ? YAML.load(ret.stdout) : nil end end end end specinfra-2.82.8/lib/specinfra/host_inventory/hostname.rb0000644000004100000410000000047113614203316023573 0ustar www-datawww-datamodule Specinfra class HostInventory class Hostname < Base def get cmd = backend.command.get(:get_inventory_hostname) result = backend.run_command(cmd) if result.exit_status == 0 result.stdout.strip else nil end end end end end specinfra-2.82.8/lib/specinfra/host_inventory/memory.rb0000644000004100000410000000616713614203316023275 0ustar www-datawww-datamodule Specinfra class HostInventory class Memory < Base def get cmd = backend.command.get(:get_inventory_memory) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(ret) memory = { 'swap' => {} } ret.each_line do |line| case line when /^SwapCached:\s+(\d+) (.+)$/ memory['swap']['cached'] = "#{$1}#{$2}" when /^SwapTotal:\s+(\d+) (.+)$/ memory['swap']['total'] = "#{$1}#{$2}" when /^SwapFree:\s+(\d+) (.+)$/ memory['swap']['free'] = "#{$1}#{$2}" when /^MemTotal:\s+(\d+) (.+)$/ memory['total'] = "#{$1}#{$2}" when /^MemFree:\s+(\d+) (.+)$/ memory['free'] = "#{$1}#{$2}" when /^Buffers:\s+(\d+) (.+)$/ memory['buffers'] = "#{$1}#{$2}" when /^Cached:\s+(\d+) (.+)$/ memory['cached'] = "#{$1}#{$2}" when /^Active:\s+(\d+) (.+)$/ memory['active'] = "#{$1}#{$2}" when /^Inactive:\s+(\d+) (.+)$/ memory['inactive'] = "#{$1}#{$2}" when /^Dirty:\s+(\d+) (.+)$/ memory['dirty'] = "#{$1}#{$2}" when /^Writeback:\s+(\d+) (.+)$/ memory['writeback'] = "#{$1}#{$2}" when /^AnonPages:\s+(\d+) (.+)$/ memory['anon_pages'] = "#{$1}#{$2}" when /^Mapped:\s+(\d+) (.+)$/ memory['mapped'] = "#{$1}#{$2}" when /^Slab:\s+(\d+) (.+)$/ memory['slab'] = "#{$1}#{$2}" when /^SReclaimable:\s+(\d+) (.+)$/ memory['slab_reclaimable'] = "#{$1}#{$2}" when /^SUnreclaim:\s+(\d+) (.+)$/ memory['slab_unreclaim'] = "#{$1}#{$2}" when /^PageTables:\s+(\d+) (.+)$/ memory['page_tables'] = "#{$1}#{$2}" when /^NFS_Unstable:\s+(\d+) (.+)$/ memory['nfs_unstable'] = "#{$1}#{$2}" when /^Bounce:\s+(\d+) (.+)$/ memory['bounce'] = "#{$1}#{$2}" when /^CommitLimit:\s+(\d+) (.+)$/ memory['commit_limit'] = "#{$1}#{$2}" when /^Committed_AS:\s+(\d+) (.+)$/ memory['committed_as'] = "#{$1}#{$2}" when /^VmallocTotal:\s+(\d+) (.+)$/ memory['vmalloc_total'] = "#{$1}#{$2}" when /^VmallocUsed:\s+(\d+) (.+)$/ memory['vmalloc_used'] = "#{$1}#{$2}" when /^VmallocChunk:\s+(\d+) (.+)$/ memory['vmalloc_chunk'] = "#{$1}#{$2}" when /^AnonHugePages:\s+(\d+) (.+)$/ memory['annon_huge_pages'] = "#{$1}#{$2}" when /^HugePages_Total:\s+(\d+)$/ memory['huge_pages_total'] = "#{$1}" when /^HugePages_Free:\s+(\d+)$/ memory['huge_pages_free'] = "#{$1}" when /^HugePages_Rsvd:\s+(\d+)$/ memory['huge_pages_rsvd'] = "#{$1}" when /^HugePages_Surp:\s+(\d+)$/ memory['huge_pages_surp'] = "#{$1}" when /^Hugepagesize:\s+(\d+) (.+)$/ memory['huge_page_size'] = "#{$1}#{$2}" end end memory end end end end specinfra-2.82.8/lib/specinfra/host_inventory/cpu.rb0000644000004100000410000000534713614203316022553 0ustar www-datawww-datamodule Specinfra class HostInventory class Cpu < Base def get cmd = backend.command.get(:get_inventory_cpu) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(cmd_ret) cpuinfo = {} cpus = cmd_ret.split(/[^^]processor/) cpuinfo['total'] = cpus.length.to_s cpus.each_with_index do |cpu, idx| idx = idx.to_s cpuinfo[idx] = {} cpu.each_line do |line| case line when /^vendor_id\s*:\s+(.+)$/ cpuinfo[idx]['vendor_id'] = $1 when /^cpu family\s*:\s+(\d+)$/ cpuinfo[idx]['cpu_family'] = $1 when /^model\s*:\s+(\d+)$/ cpuinfo[idx]['model'] = $1 when /^model\sname\s*:\s+(.+)$/ cpuinfo[idx]['model_name'] = $1 when /^stepping\s*:\s+(\d+)$/ cpuinfo[idx]['stepping'] = $1 when /^microcode\s*:\s+(.+)$/ cpuinfo[idx]['microcode'] = $1 when /^cpu MHz\s*:\s+(.+)$/ cpuinfo[idx]['cpu_mhz'] = $1 when /^cache size\s*:\s+(\d+) (.+)$/ cpuinfo[idx]['cache_size'] = "#{$1}#{$2}" when /^physical id\s*:\s+(\d+)$/ cpuinfo[idx]['physical_id'] = $1 when /^siblings\s*:\s+(\d+)$/ cpuinfo[idx]['siblings'] = $1 when /^core id\s*:\s+(\d+)$/ cpuinfo[idx]['core_id'] = $1 when /^cpu cores\s*:\s+(\d+)$/ cpuinfo[idx]['cpu_cores'] = $1 when /^apicid\s*:\s+(\d+)$/ cpuinfo[idx]['apicid'] = $1 when /^initial apicid\s*:\s+(\d+)$/ cpuinfo[idx]['initial_apicid'] = $1 when /^fpu\s*:\s+(.+)$/ cpuinfo[idx]['fpu'] = $1 when /^fpu_exception\s*:\s+(.+)$/ cpuinfo[idx]['fpu_exception'] = $1 when /^cpuid level\s*:\s+(\d+)$/ cpuinfo[idx]['cpuid_level'] = $1 when /^wp\s*:\s+(.+)$/ cpuinfo[idx]['wp'] = $1 when /^flags\s*:\s+(.+)$/ cpuinfo[idx]['flags'] = $1.split(/\s/) when /^bogomips\s*:\s+(.+)$/ cpuinfo[idx]['bogomips'] = $1 when /^clflush size\s*:\s+(\d+)$/ cpuinfo[idx]['clflush_size'] = $1 when /^cache_alignment\s*:\s+(\d+)$/ cpuinfo[idx]['cache_alignment'] = $1 when /^address sizes\s*:\s+(.+)$/ cpuinfo[idx]['address_sizes'] = $1 when /^power management\s*:\s+(.*)$/ cpuinfo[idx]['power_management'] = $1 end end end cpuinfo end end end end specinfra-2.82.8/lib/specinfra/host_inventory/platform.rb0000644000004100000410000000021413614203316023574 0ustar www-datawww-datamodule Specinfra class HostInventory class Platform < Base def get backend.os_info[:family] end end end end specinfra-2.82.8/lib/specinfra/host_inventory/user.rb0000644000004100000410000000130213614203316022725 0ustar www-datawww-datamodule Specinfra class HostInventory class User < Base def get cmd = backend.command.get(:get_inventory_user) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(cmd_ret) users = {} lines = cmd_ret.split(/\n/) lines.each do |line| user = line.split(':') users[user[0]] = { 'name' => user[0], 'uid' => user[2], 'gid' => user[3], 'gecos' => user[4], 'directory' => user[5], 'shell' => user[6] } end users end end end end specinfra-2.82.8/lib/specinfra/host_inventory/platform_version.rb0000644000004100000410000000023213614203316025341 0ustar www-datawww-datamodule Specinfra class HostInventory class PlatformVersion < Base def get backend.os_info[:release] end end end end specinfra-2.82.8/lib/specinfra/host_inventory/block_device.rb0000644000004100000410000000163313614203316024367 0ustar www-datawww-datamodule Specinfra class HostInventory class BlockDevice < Base # examples: # /sys/block/sda/size 10000 # /sys/block/sr0/device/model CD-ROM BLOCK_DEVICE_REGEX = %r|\A/sys/block/(\w+)/(\w+)(?:/(\w+))?\t(.+)\z| def get cmd = backend.command.get(:get_inventory_block_device) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(ret) block_device = {} ret.each_line do |line| line.strip! if m = line.match(BLOCK_DEVICE_REGEX) device = m[1].to_s check = m[3].nil? ? m[2].to_s : m[3].to_s value = m[4].to_s block_device[device] = {} if block_device[device].nil? block_device[device][check] = value end end block_device end end end end specinfra-2.82.8/lib/specinfra/host_inventory/base.rb0000644000004100000410000000033613614203316022667 0ustar www-datawww-datamodule Specinfra class HostInventory class Base def initialize(host_inventory) @host_inventory = host_inventory end def backend @host_inventory.backend end end end end specinfra-2.82.8/lib/specinfra/host_inventory/mount.rb0000644000004100000410000000134313614203316023116 0ustar www-datawww-datamodule Specinfra class HostInventory class Mount < Base def get cmd = backend.command.get(:get_inventory_mount) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(ret) mounts = [] ret.each_line do |line| mount = {} if line =~ /^(.+)\s+(.+)\s+(.+)\s+(.+)\s+(\d+)\s+(\d+)$/ mount['device'] = $1 mount['point'] = $2 mount['type'] = $3 mount['options'] = $4.split(',') mount['dump'] = $5 mount['pass'] = $6 end mounts << mount end mounts end end end end specinfra-2.82.8/lib/specinfra/host_inventory/filesystem.rb0000644000004100000410000000153213614203316024140 0ustar www-datawww-datamodule Specinfra class HostInventory class Filesystem < Base def get cmd = backend.command.get(:get_inventory_filesystem) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(ret) filesystem = {} ret.each_line do |line| next if line =~ /^Filesystem\s+/ if line =~ /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/ device = $1 filesystem[device] = {} filesystem[device]['kb_size'] = $2 filesystem[device]['kb_used'] = $3 filesystem[device]['kb_available'] = $4 filesystem[device]['percent_used'] = $5 filesystem[device]['mount'] = $6 end end filesystem end end end end specinfra-2.82.8/lib/specinfra/host_inventory/fqdn.rb0000644000004100000410000000046113614203316022704 0ustar www-datawww-datamodule Specinfra class HostInventory class Fqdn < Base def get cmd = backend.command.get(:get_inventory_fqdn) result = backend.run_command(cmd) if result.exit_status == 0 result.stdout.strip else nil end end end end end specinfra-2.82.8/lib/specinfra/host_inventory/ec2.rb0000644000004100000410000000030013614203316022415 0ustar www-datawww-datarequire 'specinfra/ec2_metadata' module Specinfra class HostInventory class Ec2 < Base def get Specinfra::Ec2Metadata.new(@host_inventory).get end end end end specinfra-2.82.8/lib/specinfra/host_inventory/virtualization.rb0000644000004100000410000000275713614203316025052 0ustar www-datawww-datamodule Specinfra class HostInventory class Virtualization < Base def get res = {} ## docker if backend.run_command('grep -Eqa \'docker(/|-[0-9a-f]+)\' /proc/1/cgroup||test -e /.dockerinit').success? res[:system] = 'docker' return res end ## OpenVZ on Linux if backend.run_command('test -d /proc/vz -a ! -d /proc/bc').success? res[:system] = 'openvz' return res end 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) return res end ret = backend.run_command('systemd-detect-virt') if ret.success? res[:system] = parse_systemd_detect_virt_output(ret.stdout) end res end def parse_system_product_name(ret) product_name = case ret when /.*VMware Virtual Platform/ 'vmware' when /.*VirtualBox/ 'vbox' when /.*KVM/ 'kvm' when /.*OpenStack/ 'openstack' else nil end product_name end def parse_systemd_detect_virt_output(ret) detected = ret.strip case detected when 'vmware', 'kvm', 'qemu' detected when 'oracle' 'vbox' end end end end end specinfra-2.82.8/lib/specinfra/host_inventory/domain.rb0000644000004100000410000000046513614203316023227 0ustar www-datawww-datamodule Specinfra class HostInventory class Domain < Base def get cmd = backend.command.get(:get_inventory_domain) result = backend.run_command(cmd) if result.exit_status == 0 result.stdout.strip else nil end end end end end specinfra-2.82.8/lib/specinfra/command.rb0000644000004100000410000003304013614203316020277 0ustar www-datawww-datamodule Specinfra module Command end end # Module require 'specinfra/command/module' require 'specinfra/command/module/service/init' require 'specinfra/command/module/service/systemd' require 'specinfra/command/module/service/daemontools' require 'specinfra/command/module/service/supervisor' require 'specinfra/command/module/service/upstart' require 'specinfra/command/module/service/runit' require 'specinfra/command/module/service/monit' require 'specinfra/command/module/service/god' require 'specinfra/command/module/service/delegator' require 'specinfra/command/module/systemd' require 'specinfra/command/module/zfs' require 'specinfra/command/module/ss' # Base require 'specinfra/command/base' require 'specinfra/command/base/bridge' require 'specinfra/command/base/bond' require 'specinfra/command/base/cron' require 'specinfra/command/base/file' require 'specinfra/command/base/fstab' require 'specinfra/command/base/group' require 'specinfra/command/base/host' require 'specinfra/command/base/interface' require 'specinfra/command/base/inventory' require 'specinfra/command/base/ipfilter' require 'specinfra/command/base/ipnat' require 'specinfra/command/base/iptables' require 'specinfra/command/base/ip6tables' require 'specinfra/command/base/kernel_module' require 'specinfra/command/base/lxc_container' require 'specinfra/command/base/kvm_guest' require 'specinfra/command/base/localhost' require 'specinfra/command/base/mail_alias' require 'specinfra/command/base/package' require 'specinfra/command/base/port' require 'specinfra/command/base/ppa' require 'specinfra/command/base/process' require 'specinfra/command/base/routing_table' require 'specinfra/command/base/selinux' require 'specinfra/command/base/selinux_module' require 'specinfra/command/base/service' require 'specinfra/command/base/user' require 'specinfra/command/base/yumrepo' require 'specinfra/command/base/zfs' # Linux (inherit Base) require 'specinfra/command/linux' require 'specinfra/command/linux/base' require 'specinfra/command/linux/base/bridge' require 'specinfra/command/linux/base/bond' require 'specinfra/command/linux/base/file' require 'specinfra/command/linux/base/fstab' require 'specinfra/command/linux/base/interface' require 'specinfra/command/linux/base/inventory' require 'specinfra/command/linux/base/iptables' require 'specinfra/command/linux/base/ip6tables' require 'specinfra/command/linux/base/kernel_module' require 'specinfra/command/linux/base/lxc_container' require 'specinfra/command/linux/base/kvm_guest' require 'specinfra/command/linux/base/package' require 'specinfra/command/linux/base/ppa' require 'specinfra/command/linux/base/selinux' require 'specinfra/command/linux/base/selinux_module' require 'specinfra/command/linux/base/service' require 'specinfra/command/linux/base/yumrepo' require 'specinfra/command/linux/base/zfs' # ESXi (inherit Linux) require 'specinfra/command/esxi' require 'specinfra/command/esxi/base' require 'specinfra/command/esxi/base/package' # RedHat (inherit Linux) require 'specinfra/command/redhat' require 'specinfra/command/redhat/base' require 'specinfra/command/redhat/base/host' require 'specinfra/command/redhat/base/iptables' require 'specinfra/command/redhat/base/package' require 'specinfra/command/redhat/base/port' require 'specinfra/command/redhat/base/selinux_module' require 'specinfra/command/redhat/base/service' require 'specinfra/command/redhat/base/yumrepo' # RedHat V5 (inherit RedHat) require 'specinfra/command/redhat/v5' require 'specinfra/command/redhat/v5/iptables' # RedHat V7 (inherit RedHat) require 'specinfra/command/redhat/v7' require 'specinfra/command/redhat/v7/host' require 'specinfra/command/redhat/v7/service' require 'specinfra/command/redhat/v7/port' # RedHat V8 (inherit RedHat) require 'specinfra/command/redhat/v8' require 'specinfra/command/redhat/v8/yumrepo' require 'specinfra/command/redhat/v8/selinux_module' # Fedora (inherit RedhHat) require 'specinfra/command/fedora' require 'specinfra/command/fedora/base' require 'specinfra/command/fedora/base/service' # Fedora >= V15 (inherit Fedora) require 'specinfra/command/fedora/v15' require 'specinfra/command/fedora/v15/service' # Arista EOS (inherit Fedora) require 'specinfra/command/eos' require 'specinfra/command/eos/base' # Amazon Linux (inherit RedHat) require 'specinfra/command/amazon' require 'specinfra/command/amazon/base' # Amazon Linux V2 (inherit RedHat) require 'specinfra/command/amazon/v2' require 'specinfra/command/amazon/v2/service' require 'specinfra/command/amazon/v2/port' # AIX (inherit Base) require 'specinfra/command/aix' require 'specinfra/command/aix/base' require 'specinfra/command/aix/base/file' require 'specinfra/command/aix/base/group' require 'specinfra/command/aix/base/host' require 'specinfra/command/aix/base/inventory' require 'specinfra/command/aix/base/package' require 'specinfra/command/aix/base/port' require 'specinfra/command/aix/base/service' require 'specinfra/command/aix/base/user' # Alpine (inherit Linux) require 'specinfra/command/alpine' require 'specinfra/command/alpine/base' require 'specinfra/command/alpine/base/host' require 'specinfra/command/alpine/base/package' require 'specinfra/command/alpine/base/process' require 'specinfra/command/alpine/base/service' # Arch (inherit Linux) require 'specinfra/command/arch' require 'specinfra/command/arch/base' require 'specinfra/command/arch/base/service' require 'specinfra/command/arch/base/package' # Clear Linux (inherit Linux) require 'specinfra/command/clearlinux' require 'specinfra/command/clearlinux/base' require 'specinfra/command/clearlinux/base/package' require 'specinfra/command/clearlinux/base/service' # CoreOS (inherit Linux) require 'specinfra/command/coreos' require 'specinfra/command/coreos/base' require 'specinfra/command/coreos/base/service' # Darwin (inherit Base) require 'specinfra/command/darwin' require 'specinfra/command/darwin/base' require 'specinfra/command/darwin/base/file' require 'specinfra/command/darwin/base/host' require 'specinfra/command/darwin/base/interface' require 'specinfra/command/darwin/base/inventory' require 'specinfra/command/darwin/base/service' require 'specinfra/command/darwin/base/package' require 'specinfra/command/darwin/base/port' require 'specinfra/command/darwin/base/process' require 'specinfra/command/darwin/base/user' # Debian (inherit Linux) require 'specinfra/command/debian' require 'specinfra/command/debian/base' require 'specinfra/command/debian/base/package' require 'specinfra/command/debian/base/ppa' require 'specinfra/command/debian/base/port' require 'specinfra/command/debian/base/service' # Debian V8 (inherit Debian) require 'specinfra/command/debian/v8' require 'specinfra/command/debian/v8/service' require 'specinfra/command/debian/v8/port' # Devuan (inherit Debian) require 'specinfra/command/devuan' require 'specinfra/command/devuan/base' # Raspbian (inherit Debian) require 'specinfra/command/raspbian' # Ubuntu (inherit Debian) require 'specinfra/command/ubuntu' require 'specinfra/command/ubuntu/base' require 'specinfra/command/ubuntu/base/ppa' require 'specinfra/command/ubuntu/base/service' # Ubuntu v15.xx (inherit Ubuntu) require 'specinfra/command/ubuntu/v15' require 'specinfra/command/ubuntu/v15/service' # Linux Mint (inherit Ubuntu) require 'specinfra/command/linuxmint' require 'specinfra/command/linuxmint/base' # elementary OS (inherit Ubuntu) require 'specinfra/command/elementary' require 'specinfra/command/elementary/base' # Cumulus Networks (inherit Debian) require 'specinfra/command/cumulus' require 'specinfra/command/cumulus/base' require 'specinfra/command/cumulus/base/ppa' require 'specinfra/command/cumulus/base/service' # Gentoo (inherit Linux) require 'specinfra/command/gentoo' require 'specinfra/command/gentoo/base' require 'specinfra/command/gentoo/base/package' require 'specinfra/command/gentoo/base/service' # Plamo (inherit Linux) require 'specinfra/command/plamo' require 'specinfra/command/plamo/base' require 'specinfra/command/plamo/base/package' require 'specinfra/command/plamo/base/service' # NixOS (inherit Linux) require 'specinfra/command/nixos' require 'specinfra/command/nixos/base' require 'specinfra/command/nixos/base/package' require 'specinfra/command/nixos/base/service' # SuSE (inherit Linux) require 'specinfra/command/suse' require 'specinfra/command/suse/base' require 'specinfra/command/suse/base/package' require 'specinfra/command/suse/base/service' # OpenSuSE (inherit SuSE) require 'specinfra/command/opensuse' require 'specinfra/command/opensuse/base' require 'specinfra/command/opensuse/base/service' # SLES (inherit SuSE) require 'specinfra/command/sles' require 'specinfra/command/sles/base' require 'specinfra/command/sles/base/service' require 'specinfra/command/sles/v11' require 'specinfra/command/sles/v11/user' require 'specinfra/command/sles/v12' require 'specinfra/command/sles/v12/service' # FreeBSD (inherit Base) require 'specinfra/command/freebsd' require 'specinfra/command/freebsd/base' require 'specinfra/command/freebsd/base/file' require 'specinfra/command/freebsd/base/group' require 'specinfra/command/freebsd/base/host' require 'specinfra/command/freebsd/base/interface' require 'specinfra/command/freebsd/base/inventory' require 'specinfra/command/freebsd/base/kernel_module' require 'specinfra/command/freebsd/base/package' require 'specinfra/command/freebsd/base/port' require 'specinfra/command/freebsd/base/process' require 'specinfra/command/freebsd/base/service' require 'specinfra/command/freebsd/base/routing_table' require 'specinfra/command/freebsd/base/user' require 'specinfra/command/freebsd/base/zfs' # FreeBSD V6 (inherit FreeBSD) require 'specinfra/command/freebsd/v6' require 'specinfra/command/freebsd/v6/user' require 'specinfra/command/freebsd/v6/package' require 'specinfra/command/freebsd/v6/service' # FreeBSD V7 (inherit FreeBSD) require 'specinfra/command/freebsd/v7' require 'specinfra/command/freebsd/v7/package' require 'specinfra/command/freebsd/v7/service' # FreeBSD V8 (inherit FreeBSD) require 'specinfra/command/freebsd/v8' require 'specinfra/command/freebsd/v8/package' require 'specinfra/command/freebsd/v8/service' # FreeBSD V9 (inherit FreeBSD) require 'specinfra/command/freebsd/v9' require 'specinfra/command/freebsd/v9/package' require 'specinfra/command/freebsd/v9/service' # FreeBSD V11 (inherit FreeBSD) require 'specinfra/command/freebsd/v11' require 'specinfra/command/freebsd/v11/interface' # OpenBSD (inherit Base) require 'specinfra/command/openbsd' require 'specinfra/command/openbsd/base' require 'specinfra/command/openbsd/base/bond' require 'specinfra/command/openbsd/base/bridge' require 'specinfra/command/openbsd/base/file' require 'specinfra/command/openbsd/base/fstab' require 'specinfra/command/openbsd/base/host' require 'specinfra/command/openbsd/base/interface' require 'specinfra/command/openbsd/base/inventory' require 'specinfra/command/openbsd/base/mail_alias' require 'specinfra/command/openbsd/base/package' require 'specinfra/command/openbsd/base/port' require 'specinfra/command/openbsd/base/routing_table' require 'specinfra/command/openbsd/base/service' require 'specinfra/command/openbsd/base/user' # OpenBSD >= V5.7 (inherit OpenBSD) require 'specinfra/command/openbsd/v57' require 'specinfra/command/openbsd/v57/service' # Solaris (inherit Base) require 'specinfra/command/solaris' require 'specinfra/command/solaris/base' require 'specinfra/command/solaris/base/cron' require 'specinfra/command/solaris/base/file' require 'specinfra/command/solaris/base/group' require 'specinfra/command/solaris/base/host' require 'specinfra/command/solaris/base/inventory' require 'specinfra/command/solaris/base/ipfilter' require 'specinfra/command/solaris/base/ipnat' require 'specinfra/command/solaris/base/kernel_module' require 'specinfra/command/solaris/base/package' require 'specinfra/command/solaris/base/port' require 'specinfra/command/solaris/base/service' require 'specinfra/command/solaris/base/user' require 'specinfra/command/solaris/base/zfs' # Solaris 10 (inherit Solaris) require 'specinfra/command/solaris/v10' require 'specinfra/command/solaris/v10/file' require 'specinfra/command/solaris/v10/group' require 'specinfra/command/solaris/v10/host' require 'specinfra/command/solaris/v10/package' require 'specinfra/command/solaris/v10/user' # Solaris 11 (inherit Solaris) require 'specinfra/command/solaris/v11' require 'specinfra/command/solaris/v11/user' # SmartOS (inherit Solaris) require 'specinfra/command/smartos' require 'specinfra/command/smartos/base' require 'specinfra/command/smartos/base/file' require 'specinfra/command/smartos/base/package' require 'specinfra/command/smartos/base/service' # Windows (inherit nothing) require 'specinfra/command/windows' require 'specinfra/command/windows/base' require 'specinfra/command/windows/base/feature' require 'specinfra/command/windows/base/file' require 'specinfra/command/windows/base/group' require 'specinfra/command/windows/base/host' require 'specinfra/command/windows/base/hot_fix' require 'specinfra/command/windows/base/iis_app_pool' require 'specinfra/command/windows/base/iis_website' require 'specinfra/command/windows/base/package' require 'specinfra/command/windows/base/port' require 'specinfra/command/windows/base/process' require 'specinfra/command/windows/base/service' require 'specinfra/command/windows/base/user' require 'specinfra/command/windows/base/registry_key' require 'specinfra/command/windows/base/scheduled_task' # Poky (inherit Linux) require 'specinfra/command/poky' require 'specinfra/command/poky/base' require 'specinfra/command/poky/base/interface' require 'specinfra/command/poky/base/inventory' require 'specinfra/command/poky/base/package' require 'specinfra/command/poky/base/service' specinfra-2.82.8/lib/specinfra/host_inventory.rb0000644000004100000410000000247113614203316021757 0ustar www-datawww-datamodule Specinfra class HostInventory KEYS = %w{ memory ec2 hostname domain fqdn platform platform_version filesystem cpu virtualization kernel block_device user group facter ohai mount } include Enumerable attr_reader :backend def self.instance property[:host_inventory] ||= {} self.new(Specinfra.backend, property[:host_inventory]) end def initialize(backend, inventory = {}) @backend = backend @inventory = inventory end def [](key) @inventory[key.to_sym] ||= {} if @inventory[key.to_sym].empty? begin inventory_class = Specinfra::HostInventory.const_get(key.to_s.to_camel_case) @inventory[key.to_sym] = inventory_class.new(self).get rescue @inventory[key.to_sym] = nil end end @inventory[key.to_sym] end def each KEYS.each do |k| yield k, self[k] end end def each_key KEYS.each do |k| yield k end end def each_value KEYS.each do |k| yield self[k] end end end end require "specinfra/host_inventory/base" Specinfra::HostInventory::KEYS.each do |k| require "specinfra/host_inventory/#{k}" end specinfra-2.82.8/lib/specinfra/backend.rb0000644000004100000410000000074013614203316020251 0ustar www-datawww-datarequire 'specinfra/backend/base' require 'specinfra/backend/exec' require 'specinfra/backend/ssh' require 'specinfra/backend/powershell/script_helper' require 'specinfra/backend/powershell/command' require 'specinfra/backend/cmd' require 'specinfra/backend/docker' require 'specinfra/backend/lxc' require 'specinfra/backend/winrm' require 'specinfra/backend/shell_script' require 'specinfra/backend/dockerfile' require 'specinfra/backend/telnet' require 'specinfra/backend/jexec' specinfra-2.82.8/lib/specinfra/core.rb0000644000004100000410000000062213614203316017611 0ustar www-datawww-datarequire 'specinfra/version' require 'specinfra/ext' require 'specinfra/helper' require 'specinfra/command' require 'specinfra/command_factory' require 'specinfra/command_result' require 'specinfra/backend' require 'specinfra/configuration' require 'specinfra/runner' require 'specinfra/processor' module Specinfra class << self def configuration Specinfra::Configuration end end end specinfra-2.82.8/lib/specinfra/helper/0000755000004100000410000000000013614203316017613 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/helper/docker.rb0000644000004100000410000000042013614203316021403 0ustar www-datawww-datamodule Specinfra module Helper module Docker def self.included(klass) require 'docker' unless defined?(::Docker) rescue LoadError fail "Docker client library is not available. Try installing `docker-api' gem." end end end end specinfra-2.82.8/lib/specinfra/helper/set.rb0000644000004100000410000000023613614203316020734 0ustar www-datawww-datamodule Specinfra module Helper module Set def set(param, *value) Specinfra.configuration.send(param, *value) end end end end specinfra-2.82.8/lib/specinfra/helper/properties.rb0000644000004100000410000000042713614203316022337 0ustar www-datawww-datarequire 'specinfra/properties' module Specinfra module Helper module Properties def property Specinfra::Properties.instance.properties end def set_property(prop) Specinfra::Properties.instance.properties(prop) end end end end specinfra-2.82.8/lib/specinfra/helper/lxc.rb0000644000004100000410000000041713614203316020730 0ustar www-datawww-datamodule Specinfra module Helper module Lxc def self.included(klass) require 'lxc/extra' unless defined?(::LXC::Extra) rescue LoadError fail "LXC client library is not available. Try installing `ruby-lxc' gem." end end end end specinfra-2.82.8/lib/specinfra/helper/configuration.rb0000644000004100000410000000254113614203316023011 0ustar www-datawww-datamodule Specinfra module Helper module Configuration def subject example = RSpec.respond_to?(:current_example) ? RSpec.current_example : self.example example.metadata[:subject] = described_class build_configurations super end # You can create a set of configurations provided to all specs in your spec_helper: # # RSpec.configure { |c| c.pre_command = "source ~/.zshrc" } # # Any configurations you provide with `let(:option_name)` in a spec will # automatically be merged on top of the configurations. # # @example # # describe 'Gem' do # let(:pre_command) { "source ~/.zshrc" } # # %w(pry awesome_print bundler).each do |p| # describe package(p) do # it { should be_installed.by('gem') } # end # end # end def build_configurations Specinfra::Configuration.defaults.keys.each do |c| if self.respond_to?(c.to_sym) value = self.send(c) else value = RSpec.configuration.send(c) if defined?(RSpec) end next if c == :lxc && defined?(Serverspec::Type::Lxc) && value.is_a?(Serverspec::Type::Lxc) Specinfra::Configuration.instance_variable_set("@#{c}", value) end end end end end specinfra-2.82.8/lib/specinfra/helper/os.rb0000644000004100000410000000037613614203316020567 0ustar www-datawww-datarequire 'specinfra/helper/detect_os' module Specinfra module Helper module Os def os property[:os] = Specinfra.configuration.os ? Specinfra.configuration.os : Specinfra.backend.os_info end end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/0000755000004100000410000000000013614203316021564 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/helper/detect_os/photon.rb0000644000004100000410000000062613614203316023424 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Photon < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/os-release').success? line = run_command('cat /etc/os-release').stdout if line =~ /ID=photon/ family = 'photon' if line =~ /VERSION_ID=(\d+\.\d+|\d+)/ release = $1 end { :family => family, :release => release } end end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/debian.rb0000644000004100000410000000212013614203316023326 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Debian < Specinfra::Helper::DetectOs def detect if (debian_version = run_command('cat /etc/debian_version')) && debian_version.success? distro = nil release = nil if (lsb_release = run_command("lsb_release -ir")) && lsb_release.success? lsb_release.stdout.each_line do |line| distro = line.split(':').last.strip if line =~ /^Distributor ID:/ release = line.split(':').last.strip if line =~ /^Release:/ end elsif (lsb_release = run_command("cat /etc/lsb-release")) && lsb_release.success? lsb_release.stdout.each_line do |line| distro = line.split('=').last.strip if line =~ /^DISTRIB_ID=/ release = line.split('=').last.strip if line =~ /^DISTRIB_RELEASE=/ end else if debian_version.stdout.chomp =~ /^[[:digit:]]+\.[[:digit:]]+$/ release = debian_version.stdout.chomp end end distro ||= 'debian' release ||= nil { :family => distro.gsub(/[^[:alnum:]]/, '').downcase, :release => release } end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/esxi.rb0000644000004100000410000000042713614203316023064 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Esxi < Specinfra::Helper::DetectOs def detect if run_command('vmware -v').success? line = run_command('vmware -v').stdout if line =~ /VMware ESXi (.*)/ { :family => 'esxi', :release => $1 } end end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/redhat.rb0000644000004100000410000000172413614203316023364 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Redhat < Specinfra::Helper::DetectOs def detect # Fedora also has an /etc/redhat-release so the Fedora check must # come before the RedHat check if run_command('ls /etc/fedora-release').success? line = run_command('cat /etc/redhat-release').stdout if line =~ /release (\d[\d]*)/ release = $1 end { :family => 'fedora', :release => release } elsif run_command('ls /etc/redhat-release').success? line = run_command('cat /etc/redhat-release').stdout if line =~ /release (\d[\d.]*)/ release = $1 end { :family => 'redhat', :release => release } elsif run_command('ls /etc/system-release').success? line = run_command('cat /etc/system-release').stdout if line =~ /release (\d[\d.]*)/ release = $1 elsif line =~ /Amazon Linux (\d+)/ release = $1 end { :family => 'amazon', :release => release } end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/nixos.rb0000644000004100000410000000032113614203316023245 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Nixos < Specinfra::Helper::DetectOs def detect if run_command('ls /var/run/current-system/sw').success? { :family => 'nixos', :release => nil } end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/suse.rb0000644000004100000410000000170113614203316023067 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Suse < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/os-release').success? and run_command('zypper -V').success? line = run_command('cat /etc/os-release').stdout if line =~ /ID=opensuse/ family = 'opensuse' elsif line =~ /ID="sles"/ family = 'sles' elsif line =~ /ID="sles_sap"/ family = 'sles' end if line =~ /VERSION_ID=\"(\d+\.\d+|\d+)\"/ release = $1 end { :family => family, :release => release } elsif run_command('ls /etc/SuSE-release').success? and run_command('zypper -V').success? line = run_command('cat /etc/SuSE-release').stdout if line =~ /SUSE Linux Enterprise Server (\d+)/ release = $1 family = 'suse' elsif line =~ /openSUSE (\d+\.\d+|\d+)/ release = $1 family = 'opensuse' end { :family => family, :release => release } end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/openbsd.rb0000644000004100000410000000051113614203316023540 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Openbsd < Specinfra::Helper::DetectOs def detect if ( uname = run_command('uname -sr').stdout ) && uname =~ /OpenBSD/i if uname =~ /(\d+\.\d+)/ { :family => 'openbsd', :release => $1 } else { :family => 'openbsd', :release => nil } end end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/freebsd.rb0000644000004100000410000000050613614203316023524 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Freebsd < Specinfra::Helper::DetectOs def detect if ( uname = run_command('uname -sr').stdout ) && uname =~ /FreeBSD/i if uname =~ /(\d+)\./ { :family => 'freebsd', :release => $1 } else { :family => 'freebsd', :release => nil } end end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/arch.rb0000644000004100000410000000030613614203316023025 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Arch < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/arch-release').success? { :family => 'arch', :release => nil } end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/darwin.rb0000644000004100000410000000050713614203316023377 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Darwin < Specinfra::Helper::DetectOs def detect if ( uname = run_command('uname -sr').stdout ) && uname =~ /Darwin/i if uname =~ /([\d.]+)$/ { :family => 'darwin', :release => $1 } else { :family => 'darwin', :release => nil } end end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/solaris.rb0000644000004100000410000000125113614203316023564 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Solaris < Specinfra::Helper::DetectOs def detect if ( uname = run_command('uname -sr').stdout) && uname =~ /SunOS/i if uname =~ /5.10/ { :family => 'solaris', :release => 10 } elsif run_command('grep -q "Oracle Solaris 11" /etc/release').success? { :family => 'solaris', :release => 11 } elsif run_command('grep -q "OpenIndiana" /etc/release').success? { :family => 'solaris', :release => 11 } elsif run_command('grep -q SmartOS /etc/release').success? { :family => 'smartos', :release => nil } else { :family => 'solaris', :release => nil } end end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/alpine.rb0000644000004100000410000000041613614203316023362 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Alpine < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/alpine-release').success? release = run_command('cat /etc/alpine-release').stdout { :family => 'alpine', :release => release } end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/plamo.rb0000644000004100000410000000031513614203316023220 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Plamo < Specinfra::Helper::DetectOs def detect if run_command('ls /usr/lib/setup/Plamo-*').success? { :family => 'plamo', :release => nil } end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/devuan.rb0000644000004100000410000000144613614203316023400 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Devuan < Specinfra::Helper::DetectOs def detect if (devuan_version = run_command('cat /etc/devuan_version')) && devuan_version.success? distro = nil release = nil if (lsb_release = run_command("lsb_release -ir")) && lsb_release.success? lsb_release.stdout.each_line do |line| distro = line.split(':').last.strip if line =~ /^Distributor ID:/ release = line.split(':').last.strip if line =~ /^Release:/ end else if devuan_version.stdout.chomp =~ /^[[:digit:]]+\.[[:digit:]]+$/ release = devuan_version.stdout.chomp end end distro ||= 'devuan' release ||= nil { :family => distro.gsub(/[^[:alnum:]]/, '').downcase, :release => release } end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/aix.rb0000644000004100000410000000060513614203316022673 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Aix < Specinfra::Helper::DetectOs def detect if run_command('uname -s').stdout =~ /AIX/i line = run_command('uname -rvp').stdout if line =~ /(\d+)\s+(\d+)\s+(.*)/ then { :family => 'aix', :release => "#{$2}.#{$1}", :arch => $3 } else { :family => 'aix', :release => nil, :arch => nil } end end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/coreos.rb0000644000004100000410000000115413614203316023404 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Coreos < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/coreos/update.conf').success? distro = nil release = nil lsb_release = run_command("cat /etc/lsb-release") if lsb_release.success? lsb_release.stdout.each_line do |line| distro = 'coreos' if line.include? "CoreOS" release = line.split('=').last.strip if line =~ /^DISTRIB_RELEASE=/ end end distro ||= 'coreos' release ||= nil { :family => distro.gsub(/[^[:alnum:]]/, '').downcase, :release => release } end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/clearlinux.rb0000644000004100000410000000061213614203316024256 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Clearlinux < Specinfra::Helper::DetectOs def detect swupd_info = run_command('swupd info') if swupd_info.success? release = nil swupd_info.stdout.each_line do |line| release = line.gsub(/\s+/, '').split(':').last if line =~ /^Installed version:/ end { :family => 'clearlinux', :release => release } end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/eos.rb0000644000004100000410000000054013614203316022676 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Eos < Specinfra::Helper::DetectOs def detect # Arista Networks EOS if run_command('ls /etc/Eos-release').success? line = run_command('cat /etc/Eos-release').stdout if line =~ /EOS (\d[\d.]*[A-Z]*)/ release = $1 end { :family => 'eos', :release => release } end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/gentoo.rb0000644000004100000410000000031413614203316023402 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Gentoo < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/gentoo-release').success? { :family => 'gentoo', :release => nil } end end end specinfra-2.82.8/lib/specinfra/helper/detect_os/poky.rb0000644000004100000410000000037313614203316023076 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Poky < Specinfra::Helper::DetectOs def detect if ( uname = run_command('uname -r').stdout ) && uname =~ /poky/i { :family => 'poky', :release => run_command('cat /etc/version').stdout } end end end specinfra-2.82.8/lib/specinfra/helper/host_inventory.rb0000644000004100000410000000027613614203316023237 0ustar www-datawww-datarequire 'specinfra/host_inventory' module Specinfra module Helper module HostInventory def host_inventory Specinfra::HostInventory.instance end end end end specinfra-2.82.8/lib/specinfra/helper/detect_os.rb0000644000004100000410000000222713614203316022114 0ustar www-datawww-datamodule Specinfra module Helper class DetectOs def self.detect self.new(Specinfra.backend).detect end def initialize(backend) @backend = backend end def run_command(cmd) @backend.run_command(cmd) end def detect raise NotImplementedError end end end end require 'specinfra/helper/detect_os/aix' require 'specinfra/helper/detect_os/alpine' require 'specinfra/helper/detect_os/arch' require 'specinfra/helper/detect_os/clearlinux' require 'specinfra/helper/detect_os/coreos' require 'specinfra/helper/detect_os/darwin' require 'specinfra/helper/detect_os/debian' require 'specinfra/helper/detect_os/esxi' require 'specinfra/helper/detect_os/eos' require 'specinfra/helper/detect_os/freebsd' require 'specinfra/helper/detect_os/gentoo' require 'specinfra/helper/detect_os/nixos' require 'specinfra/helper/detect_os/openbsd' require 'specinfra/helper/detect_os/photon' require 'specinfra/helper/detect_os/plamo' require 'specinfra/helper/detect_os/poky' require 'specinfra/helper/detect_os/redhat' require 'specinfra/helper/detect_os/solaris' require 'specinfra/helper/detect_os/suse' specinfra-2.82.8/lib/specinfra/ext/0000755000004100000410000000000013614203316017134 5ustar www-datawww-dataspecinfra-2.82.8/lib/specinfra/ext/class.rb0000644000004100000410000000034613614203316020571 0ustar www-datawww-dataclass Class def subclasses result = [] ObjectSpace.each_object(Class) do |k| next unless k < self next if k.respond_to?(:singleton_class?) && k.singleton_class? result << k end result end end specinfra-2.82.8/lib/specinfra/ext/string.rb0000644000004100000410000000045613614203316020774 0ustar www-datawww-dataclass String def to_snake_case self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end def to_camel_case return self if self !~ /_/ && self =~ /[A-Z]+.*/ split('_').map{|e| e.capitalize}.join end end specinfra-2.82.8/lib/specinfra.rb0000644000004100000410000000251213614203316016661 0ustar www-datawww-datarequire 'specinfra/core' include Specinfra include Specinfra::Helper::Os include Specinfra::Helper::Properties include Specinfra::Helper::HostInventory module Specinfra class << self def command Specinfra::CommandFactory.instance end def backend type = Specinfra.configuration.backend if type.nil? if Specinfra.configuration.error_on_missing_backend_type raise "No backend type is specified." end warn "No backend type is specified. Fall back to :exec type." type = :exec end eval "Specinfra::Backend::#{type.to_s.to_camel_case}.instance" end end end if defined?(RSpec) RSpec.configure do |c| c.include(Specinfra::Helper::Configuration) c.add_setting :os, :default => nil c.add_setting :host, :default => nil c.add_setting :ssh, :default => nil c.add_setting :scp, :default => nil c.add_setting :sudo_password, :default => nil c.add_setting :winrm, :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 example = RSpec.respond_to?(:current_example) ? RSpec.current_example : self.example Specinfra.backend.set_example(example) end end end specinfra-2.82.8/specinfra.gemspec0000644000004100000410000000255213614203316017137 0ustar www-datawww-data# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'specinfra/version' Gem::Specification.new do |spec| spec.name = "specinfra" spec.version = Specinfra::VERSION spec.authors = ["Gosuke Miyashita"] spec.email = ["gosukenator@gmail.com"] spec.description = %q{Common layer for serverspec and itamae} spec.summary = %q{Common layer for serverspec and itamae} spec.homepage = 'https://github.com/mizzy/specinfra' spec.license = "MIT" spec.files = %w{LICENSE.txt README.md} + `git ls-files`.split("\n").select { |f| f =~ %r{^(?:lib/)}i } spec.test_files = %w{Gemfile specinfra.gemspec Rakefile} + `git ls-files`.split("\n").select { |f| f =~ %r{^(?:spec/)}i } spec.require_paths = ["lib"] # TODO: at some point pin to a minumum version of ruby to reduce support burden in a major version bump # spec.required_ruby_version = '>= 2.3.0' spec.add_runtime_dependency "net-scp" spec.add_runtime_dependency "net-ssh", ">= 2.7" # TODO: remove the lock when you want to remove ruby < 2.3 support spec.add_runtime_dependency "net-telnet", "0.1.1" spec.add_runtime_dependency "sfl" spec.add_development_dependency "rake", "~> 10.1.1" spec.add_development_dependency "rspec" spec.add_development_dependency "rspec-its" end specinfra-2.82.8/Gemfile0000644000004100000410000000136413614203316015113 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in specinfra.gemspec gemspec ruby_version = Gem::Version.new(RUBY_VERSION.dup) if ruby_version < Gem::Version.new('2.0.0') # net-ssh 3.x dropped Ruby 1.8 and 1.9 support. gem 'net-ssh', '~> 2.7' end if ruby_version < Gem::Version.new('1.9.3') # pry 0.11 dropped Ruby 1.8 support gem 'pry', '0.10.4' # listen 2.0 dropped Ruby 1.8 support gem 'listen', '< 2.0' # hitimes 1.2.3 dropped Ruby 1.8 support gem 'hitimes', '< 1.2.3' elsif ruby_version < Gem::Version.new('2.0.0') # listen 3.0 dropped Ruby 1.8 and 1.9 support gem 'listen', '< 3.0' elsif ruby_version < Gem::Version.new('2.2.3') # listen 3.1 dropped support for Ruby 2.1 and lower gem 'listen', '< 3.1' end specinfra-2.82.8/LICENSE.txt0000644000004100000410000000206113614203316015436 0ustar www-datawww-dataCopyright (c) 2013 Gosuke Miyashita MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.