diff options
author | sawanoboly <sawanoboriyu@higanworks.com> | 2020-12-10 14:42:43 +0900 |
---|---|---|
committer | sawanoboly <sawanoboriyu@higanworks.com> | 2020-12-10 14:42:43 +0900 |
commit | a2987d3d5d152f651039642e024b8d3f2ef34bb7 (patch) | |
tree | d716709c25b24c23f948cdb42067b69612b9efbe /spec | |
parent | a807a2c2d52890c72700b722e87184e47311ba3a (diff) | |
parent | 3ef9243c91c67a529bff67dc6a30e356c80b9d2b (diff) | |
download | ohai-a2987d3d5d152f651039642e024b8d3f2ef34bb7.tar.gz |
Merge remote-tracking branch 'origin/master' into imds-v2
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/plugins/aix/network_spec.rb | 26 | ||||
-rw-r--r-- | spec/unit/plugins/c_spec.rb | 13 | ||||
-rw-r--r-- | spec/unit/plugins/chef_spec.rb | 1 | ||||
-rw-r--r-- | spec/unit/plugins/digital_ocean_spec.rb | 1 | ||||
-rw-r--r-- | spec/unit/plugins/docker_spec.rb | 23 | ||||
-rw-r--r-- | spec/unit/plugins/grub2_spec.rb | 51 | ||||
-rw-r--r-- | spec/unit/plugins/linode_spec.rb | 24 | ||||
-rw-r--r-- | spec/unit/plugins/linux/network_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/plugins/linux/selinux_spec.rb | 52 | ||||
-rw-r--r-- | spec/unit/plugins/packages_spec.rb | 8 | ||||
-rw-r--r-- | spec/unit/plugins/scaleway_spec.rb | 1 | ||||
-rw-r--r-- | spec/unit/plugins/shard_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/plugins/solaris2/network_spec.rb | 2 |
13 files changed, 141 insertions, 65 deletions
diff --git a/spec/unit/plugins/aix/network_spec.rb b/spec/unit/plugins/aix/network_spec.rb index af944160..d1aa92c9 100644 --- a/spec/unit/plugins/aix/network_spec.rb +++ b/spec/unit/plugins/aix/network_spec.rb @@ -21,19 +21,19 @@ require "spec_helper" describe Ohai::System, "AIX network plugin" do before do @netstat_rn = <<~NETSTAT_RN - Destination Gateway Flags Refcnt Use Interface - Destination Gateway Flags Refs Use If Exp Groups - Only the root user can specify the Z flag - (Internet): - default 172.31.0.1 UG 2 1652046 en0 - - => - 127/8 127.0.0.1 U 5 2455591 lo0 - - => - 172.31.0.0 172.31.10.23 UHSb 0 0 en0 - - => - 172.31/20 172.31.10.23 U 1 1015674 en0 - - => - 172.31.10.23 127.0.0.1 UGHS 0 1 lo0 - - - 172.31.15.255 172.31.10.23 UHSb 0 1 en0 - - => - Only the root user can specify the Z flag - (Internet v6): - ::1%1 ::1%1 UH 1 677032 lo0 - - => + Destination Gateway Flags Refcnt Use Interface + Destination Gateway Flags Refs Use If Exp Groups + Only the root user can specify the Z flag + (Internet): + default 172.31.0.1 UG 2 1652046 en0 - - => + 127/8 127.0.0.1 U 5 2455591 lo0 - - => + 172.31.0.0 172.31.10.23 UHSb 0 0 en0 - - => + 172.31/20 172.31.10.23 U 1 1015674 en0 - - => + 172.31.10.23 127.0.0.1 UGHS 0 1 lo0 - - + 172.31.15.255 172.31.10.23 UHSb 0 1 en0 - - => + Only the root user can specify the Z flag + (Internet v6): + ::1%1 ::1%1 UH 1 677032 lo0 - - => NETSTAT_RN @ifconfig = <<~IFCONFIG diff --git a/spec/unit/plugins/c_spec.rb b/spec/unit/plugins/c_spec.rb index 319bc476..0b895291 100644 --- a/spec/unit/plugins/c_spec.rb +++ b/spec/unit/plugins/c_spec.rb @@ -1,4 +1,3 @@ - # Author:: Doug MacEachern <dougm@vmware.com> # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 @@ -66,6 +65,11 @@ C_XLC = <<~EOF.freeze Version: 09.00.0000.0000 EOF +C_XLC_NEWER = <<~EOF.freeze + IBM XL C/C++ for AIX, V13.1.3 (5725-C72, 5765-J07) + Version: 13.01.0003.0000 +EOF + C_SUN = <<~EOF.freeze cc: Sun C 5.8 Patch 121016-06 2007/08/01 EOF @@ -109,6 +113,13 @@ describe Ohai::System, "plugin c" do expect(plugin[:languages][:c]).not_to have_key(:xlc) end + it "properly parses 3 part version numbers in newer XLC releases" do + expect(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(0, C_XLC_NEWER, "")) + plugin.run + expect(plugin.languages[:c][:xlc][:version]).to eql("13.1.3") + expect(plugin.languages[:c][:xlc][:description]).to eql("IBM XL C/C++ for AIX, V13.1.3 (5725-C72, 5765-J07)") + end + it "does not set the languages[:c][:xlc] tree up if xlc command fails" do allow(plugin).to receive(:shell_out).with("xlc -qversion").and_raise(Ohai::Exceptions::Exec) plugin.run diff --git a/spec/unit/plugins/chef_spec.rb b/spec/unit/plugins/chef_spec.rb index 9199adc3..2584a278 100644 --- a/spec/unit/plugins/chef_spec.rb +++ b/spec/unit/plugins/chef_spec.rb @@ -33,7 +33,6 @@ begin pending "would set [:chef_packages][:chef][:version] if chef was available", unless: defined?(Chef) end - rescue LoadError # the chef module is not available, ignoring. diff --git a/spec/unit/plugins/digital_ocean_spec.rb b/spec/unit/plugins/digital_ocean_spec.rb index 280668c8..ed1d55a4 100644 --- a/spec/unit/plugins/digital_ocean_spec.rb +++ b/spec/unit/plugins/digital_ocean_spec.rb @@ -35,6 +35,7 @@ describe Ohai::System, "plugin digital_ocean" do end before do + allow(plugin).to receive(:collect_os).and_return(:linux) allow(plugin).to receive(:hint?).with("digital_ocean").and_return(false) end diff --git a/spec/unit/plugins/docker_spec.rb b/spec/unit/plugins/docker_spec.rb index c3105048..5816bc37 100644 --- a/spec/unit/plugins/docker_spec.rb +++ b/spec/unit/plugins/docker_spec.rb @@ -40,12 +40,13 @@ expected_output = { "local", ], "Network" => %w{ -bridge -host -ipvlan -macvlan -null -overlay}, + bridge + host + ipvlan + macvlan + null + overlay + }, "Authorization" => nil, "Log" => %w{ awslogs @@ -77,10 +78,14 @@ overlay}, describe Ohai::System, "plugin docker" do let(:plugin) { get_plugin("docker") } + before do + plugin[:virtualization] = Mash.new + plugin[:virtualization][:systems] = Mash.new + allow(plugin).to receive(:collect_os).and_return(:linux) + end + context "without docker installed" do it "does not create a docker attribute" do - plugin[:virtualization] = Mash.new - plugin[:virtualization][:systems] = Mash.new plugin.run expect(plugin).not_to have_key(:docker) end @@ -88,8 +93,6 @@ describe Ohai::System, "plugin docker" do context "with docker installed" do it "creates a docker attribute with correct data" do - plugin[:virtualization] = Mash.new - plugin[:virtualization][:systems] = Mash.new plugin[:virtualization][:systems][:docker] = "host" allow(plugin).to receive(:shell_out).with("docker info --format '{{json .}}'").and_return(mock_shell_out(0, docker_output, "")) plugin.run diff --git a/spec/unit/plugins/grub2_spec.rb b/spec/unit/plugins/grub2_spec.rb new file mode 100644 index 00000000..03fae9cd --- /dev/null +++ b/spec/unit/plugins/grub2_spec.rb @@ -0,0 +1,51 @@ +# +# Author:: Davide Cavalca <dcavalca@fb.com> +# Copyright:: Copyright (c) 2020 Facebook +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require "spec_helper" + +describe Ohai::System, "grub2 plugin" do + let(:plugin) { get_plugin("grub2") } + + before do + allow(plugin).to receive(:collect_os).and_return(:linux) + end + + it "populates grub2 if grub2-editenv is found" do + editenv_out = <<-EDITENV_OUT +saved_entry=f4fd6be6243646e1a76a42d50f219818-5.2.9-229 +boot_success=1 +kernelopts=root=UUID=6db0ffcd-70ec-4333-86c3-873a9e2a0d77 ro + EDITENV_OUT + allow(plugin).to receive(:which).with("grub2-editenv").and_return("/bin/grub2-editenv") + allow(plugin).to receive(:shell_out).with("/bin/grub2-editenv list").and_return(mock_shell_out(0, editenv_out, "")) + plugin.run + expect(plugin[:grub2].to_hash).to eq({ + "environment" => { + "saved_entry" => "f4fd6be6243646e1a76a42d50f219818-5.2.9-229", + "boot_success" => "1", + "kernelopts" => "root=UUID=6db0ffcd-70ec-4333-86c3-873a9e2a0d77 ro", + }, + }) + end + + it "does not populate grub2 if grub2-editenv is not found" do + allow(plugin).to receive(:which).with("grub2-editenv").and_return(false) + plugin.run + expect(plugin[:grub2]).to be(nil) + end +end diff --git a/spec/unit/plugins/linode_spec.rb b/spec/unit/plugins/linode_spec.rb index 75d1a933..a591b564 100644 --- a/spec/unit/plugins/linode_spec.rb +++ b/spec/unit/plugins/linode_spec.rb @@ -20,7 +20,12 @@ require "spec_helper" describe Ohai::System, "plugin linode" do let(:plugin) { get_plugin("linode") } + let(:apt_sources) { "# \n\n# deb cdrom:[Ubuntu-Server 20.04.1 LTS _Focal Fossa_ - Release amd64 (20200731)]/ focal main restricted\n\n#deb cdrom:[Ubuntu-Server 20.04.1 LTS _Focal Fossa_ - Release amd64 (20200731)]/ focal main restricted\n\n# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to\n# newer versions of the distribution.\ndeb http://mirrors.linode.com/ubuntu/ focal main restricted\n# deb-src http://mirrors.linode.com/ubuntu/ focal main restricted\n\n## Major bug fix updates produced after the final release of the\n## distribution.\ndeb http://mirrors.linode.com/ubuntu/ focal-updates main restricted\n# deb-src http://mirrors.linode.com/ubuntu/ focal-updates main restricted\n\n## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu\n## team. Also, please note that software in universe WILL NOT receive any\n## review or updates from the Ubuntu security team.\ndeb http://mirrors.linode.com/ubuntu/ focal universe\n# deb-src http://mirrors.linode.com/ubuntu/ focal universe\ndeb http://mirrors.linode.com/ubuntu/ focal-updates universe\n# deb-src http://mirrors.linode.com/ubuntu/ focal-updates universe\n\n## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu \n## team, and may not be under a free licence. Please satisfy yourself as to \n## your rights to use the software. Also, please note that software in \n## multiverse WILL NOT receive any review or updates from the Ubuntu\n## security team.\ndeb http://mirrors.linode.com/ubuntu/ focal multiverse\n# deb-src http://mirrors.linode.com/ubuntu/ focal multiverse\ndeb http://mirrors.linode.com/ubuntu/ focal-updates multiverse\n# deb-src http://mirrors.linode.com/ubuntu/ focal-updates multiverse\n\n## N.B. software from this repository may not have been tested as\n## extensively as that contained in the main release, although it includes\n## newer versions of some applications which may provide useful features.\n## Also, please note that software in backports WILL NOT receive any review\n## or updates from the Ubuntu security team.\ndeb http://mirrors.linode.com/ubuntu/ focal-backports main restricted universe multiverse\n# deb-src http://mirrors.linode.com/ubuntu/ focal-backports main restricted universe multiverse\n\n## Uncomment the following two lines to add software from Canonical's\n## 'partner' repository.\n## This software is not part of Ubuntu, but is offered by Canonical and the\n## respective vendors as a service to Ubuntu users.\n# deb http://archive.canonical.com/ubuntu focal partner\n# deb-src http://archive.canonical.com/ubuntu focal partner\n\ndeb http://security.ubuntu.com/ubuntu focal-security main restricted\n# deb-src http://security.ubuntu.com/ubuntu focal-security main restricted\ndeb http://security.ubuntu.com/ubuntu focal-security universe\n# deb-src http://security.ubuntu.com/ubuntu focal-security universe\ndeb http://security.ubuntu.com/ubuntu focal-security multiverse\n# deb-src http://security.ubuntu.com/ubuntu focal-security multiverse\n\n# This system was installed using small removable media\n# (e.g. netinst, live or single CD). The matching \"deb cdrom\"\n# entries were disabled at the end of the installation process.\n# For information about how to configure apt package sources,\n# see the sources.list(5) manual.\n" } + before do + allow(plugin).to receive(:collect_os).and_return(:linux) + allow(plugin).to receive(:file_exist?).with("/etc/apt/sources.list").and_return(false) + plugin[:domain] = "nope.example.com" plugin[:network] = { "interfaces" => { "eth0" => { @@ -69,17 +74,13 @@ describe Ohai::System, "plugin linode" do end - context "without linode kernel" do - before do - plugin[:kernel] = { "release" => "3.5.2-x86_64" } - end - + context "without linode domain or apt data" do it_behaves_like "!linode" end - context "with linode kernel" do + context "with linode domain" do before do - plugin[:kernel] = { "release" => "3.5.2-x86_64-linode24" } + plugin[:domain] = "members.linode.com" end it_behaves_like "linode" @@ -116,6 +117,15 @@ describe Ohai::System, "plugin linode" do end + describe "with linode apt sources" do + before do + allow(plugin).to receive(:file_exist?).with("/etc/apt/sources.list").and_return(true) + allow(plugin).to receive(:file_read).with("/etc/apt/sources.list").and_return(apt_sources) + end + + it_behaves_like "linode" + end + describe "with linode hint file" do before do allow(plugin).to receive(:hint?).with("linode").and_return({}) diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb index 978160bb..744fafa8 100644 --- a/spec/unit/plugins/linux/network_spec.rb +++ b/spec/unit/plugins/linux/network_spec.rb @@ -720,7 +720,7 @@ describe Ohai::System, "Linux Network Plugin" do end it "detects the ipv6 addresses of an ethernet subinterface" do - %w{ 1111:2222:3333:4444::2 1111:2222:3333:4444::3 }.each do |addr| + %w{1111:2222:3333:4444::2 1111:2222:3333:4444::3}.each do |addr| expect(plugin["network"]["interfaces"]["eth0.11"]["addresses"].keys).to include(addr) expect(plugin["network"]["interfaces"]["eth0.11"]["addresses"][addr]["scope"]).to eq("Global") expect(plugin["network"]["interfaces"]["eth0.11"]["addresses"][addr]["prefixlen"]).to eq("64") diff --git a/spec/unit/plugins/linux/selinux_spec.rb b/spec/unit/plugins/linux/selinux_spec.rb index 6f8ceef4..dd642b30 100644 --- a/spec/unit/plugins/linux/selinux_spec.rb +++ b/spec/unit/plugins/linux/selinux_spec.rb @@ -26,35 +26,35 @@ describe Ohai::System, "Linux selinux plugin" do end it "populates selinux if sestatus is found" do - sestatus_out = <<-SESTATUS_OUT -SELinux status: enabled -SELinuxfs mount: /sys/fs/selinux -SELinux root directory: /etc/selinux -Loaded policy name: test -Current mode: permissive -Mode from config file: permissive -Policy MLS status: disabled -Policy deny_unknown status: allowed -Max kernel policy version: 31 + sestatus_out = <<~SESTATUS_OUT + SELinux status: enabled + SELinuxfs mount: /sys/fs/selinux + SELinux root directory: /etc/selinux + Loaded policy name: test + Current mode: permissive + Mode from config file: permissive + Policy MLS status: disabled + Policy deny_unknown status: allowed + Max kernel policy version: 31 -Policy booleans: -secure_mode_policyload off + Policy booleans: + secure_mode_policyload off -Process contexts: -Current context: user_u:base_r:admin_t -Init context: system_u:system_r:init_t -/usr/sbin/sshd system_u:base_r:base_t + Process contexts: + Current context: user_u:base_r:admin_t + Init context: system_u:system_r:init_t + /usr/sbin/sshd system_u:base_r:base_t -File contexts: -Controlling terminal: system_u:object_r:file_t -/etc/passwd user_u:object_r:file_t -/etc/shadow user_u:object_r:file_t -/bin/bash user_u:object_r:file_t -/bin/login user_u:object_r:file_t -/bin/sh user_u:object_r:file_t -> user_u:object_r:file_t -/sbin/agetty user_u:object_r:file_t -/sbin/init user_u:object_r:file_t -> user_u:object_r:init_exec_t -/usr/sbin/sshd user_u:object_r:file_t + File contexts: + Controlling terminal: system_u:object_r:file_t + /etc/passwd user_u:object_r:file_t + /etc/shadow user_u:object_r:file_t + /bin/bash user_u:object_r:file_t + /bin/login user_u:object_r:file_t + /bin/sh user_u:object_r:file_t -> user_u:object_r:file_t + /sbin/agetty user_u:object_r:file_t + /sbin/init user_u:object_r:file_t -> user_u:object_r:init_exec_t + /usr/sbin/sshd user_u:object_r:file_t SESTATUS_OUT allow(plugin).to receive(:which).with("sestatus").and_return("/usr/sbin/sestatus") allow(plugin).to receive(:shell_out).with("/usr/sbin/sestatus -v -b").and_return(mock_shell_out(0, sestatus_out, "")) diff --git a/spec/unit/plugins/packages_spec.rb b/spec/unit/plugins/packages_spec.rb index 0406aaac..cc658bff 100644 --- a/spec/unit/plugins/packages_spec.rb +++ b/spec/unit/plugins/packages_spec.rb @@ -190,10 +190,10 @@ describe Ohai::System, "plugin packages" do "Publisher" => "nxsec.com", "InstallDate" => "20150511", }, - { "DisplayName" => "Chef Development Kit v0.7.0", - "DisplayVersion" => "0.7.0.1", - "Publisher" => "\"Chef Software, Inc. <maintainers@chef.io>\"", - "InstallDate" => "20150925" }] + { "DisplayName" => "Chef Development Kit v0.7.0", + "DisplayVersion" => "0.7.0.1", + "Publisher" => "\"Chef Software, Inc. <maintainers@chef.io>\"", + "InstallDate" => "20150925" }] end shared_examples "windows_package_plugin" do diff --git a/spec/unit/plugins/scaleway_spec.rb b/spec/unit/plugins/scaleway_spec.rb index 1869322a..238cd51d 100644 --- a/spec/unit/plugins/scaleway_spec.rb +++ b/spec/unit/plugins/scaleway_spec.rb @@ -21,6 +21,7 @@ describe Ohai::System, "plugin scaleway" do let(:plugin) { get_plugin("scaleway") } before do + allow(plugin).to receive(:collect_os).and_return(:linux) allow(plugin).to receive(:hint?).with("scaleway").and_return(false) allow(plugin).to receive(:file_exist?).with("/proc/cmdline").and_return(false) end diff --git a/spec/unit/plugins/shard_spec.rb b/spec/unit/plugins/shard_spec.rb index f0da5fb5..b0f3b154 100644 --- a/spec/unit/plugins/shard_spec.rb +++ b/spec/unit/plugins/shard_spec.rb @@ -119,7 +119,7 @@ describe Ohai::System, "shard plugin" do let(:os) { "aix" } it "provides a shard with a default-safe set of sources" do - # Note: this is different than the other defaults. + # NOTE: this is different than the other defaults. expect(subject).to eq(253499154) end end diff --git a/spec/unit/plugins/solaris2/network_spec.rb b/spec/unit/plugins/solaris2/network_spec.rb index 07151ce7..9bbf300c 100644 --- a/spec/unit/plugins/solaris2/network_spec.rb +++ b/spec/unit/plugins/solaris2/network_spec.rb @@ -177,7 +177,7 @@ describe Ohai::System, "Solaris2.X network plugin" do end it "finds the flags for a PHYSRUNNING interface" do - expect(@plugin[:network][:interfaces]["net1:1"][:flags]).to eq(%w{ UP BROADCAST RUNNING MULTICAST IPv4 PHYSRUNNING }) + expect(@plugin[:network][:interfaces]["net1:1"][:flags]).to eq(%w{UP BROADCAST RUNNING MULTICAST IPv4 PHYSRUNNING}) end it "finds the default interface for a solaris 11 zone" do |