diff options
author | Tim Smith <tsmith@chef.io> | 2018-02-15 11:59:46 -0800 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-02-15 12:06:27 -0800 |
commit | 1839dedf1888c71267a8495e0dbaf92957ff18d2 (patch) | |
tree | 36ad1d9426be462f8ea16ea349af1a54d50feced | |
parent | 52a3878b8b167aee8700d292fadf051fca9ee020 (diff) | |
download | ohai-docker.tar.gz |
Add specs for the new functionalitydocker
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | spec/unit/plugins/darwin/virtualization_spec.rb | 9 | ||||
-rw-r--r-- | spec/unit/plugins/docker_spec.rb | 100 | ||||
-rw-r--r-- | spec/unit/plugins/linux/virtualization_spec.rb | 11 |
3 files changed, 120 insertions, 0 deletions
diff --git a/spec/unit/plugins/darwin/virtualization_spec.rb b/spec/unit/plugins/darwin/virtualization_spec.rb index fbf509ed..44d57d08 100644 --- a/spec/unit/plugins/darwin/virtualization_spec.rb +++ b/spec/unit/plugins/darwin/virtualization_spec.rb @@ -29,6 +29,7 @@ describe Ohai::System, "Darwin virtualization platform" do allow(plugin).to receive(:ioreg_exists?).and_return(false) allow(plugin).to receive(:vboxmanage_exists?).and_return(false) allow(plugin).to receive(:fusion_exists?).and_return(false) + allow(plugin).to receive(:docker_exists?).and_return(false) end describe "when detecting OS X virtualization" do @@ -37,6 +38,14 @@ describe Ohai::System, "Darwin virtualization platform" do expect(plugin[:virtualization]).to eq({ "systems" => {} }) end + it "should set docker host if docker exists" do + allow(plugin).to receive(:docker_exists?).and_return(true) + plugin.run + expect(plugin[:virtualization][:system]).to eq("docker") + expect(plugin[:virtualization][:role]).to eq("host") + expect(plugin[:virtualization][:systems][:docker]).to eq("host") + end + it "should set vmware host if /Applications/VMware\ Fusion.app exists" do allow(plugin).to receive(:fusion_exists?).and_return(true) plugin.run diff --git a/spec/unit/plugins/docker_spec.rb b/spec/unit/plugins/docker_spec.rb new file mode 100644 index 00000000..e524d7a9 --- /dev/null +++ b/spec/unit/plugins/docker_spec.rb @@ -0,0 +1,100 @@ +# +# Copyright:: 2018 Chef Software, Inc. +# 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_relative "../../spec_helper.rb" + +docker_output = <<EOF +{"ID":"KZET:VDFN:2V2G:JS5Z:HAKO:SOGI:AFSZ:HDMT:GVEM:V2NT:DUSW:J3Z6","Containers":11,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":11,"Images":30,"Driver":"overlay2","DriverStatus":[["Backing Filesystem","extfs"],["Supports d_type","true"],["Native Overlay Diff","true"]],"SystemStatus":null,"Plugins":{"Volume":["local"],"Network":["bridge","host","ipvlan","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":true,"NFd":21,"OomKillDisable":true,"NGoroutines":39,"SystemTime":"2018-02-15T19:12:40.214106068Z","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","NEventsListener":2,"KernelVersion":"4.9.60-linuxkit-aufs","OperatingSystem":"Docker for Mac","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":[],"AllowNondistributableArtifactsHostnames":[],"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":[],"Secure":true,"Official":true}},"Mirrors":[]},"NCPU":4,"MemTotal":2095816704,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"docker.for.mac.http.internal:3128","HttpsProxy":"docker.for.mac.http.internal:3129","NoProxy":"","Name":"linuxkit-025000000001","Labels":[],"ExperimentalBuild":true,"ServerVersion":"17.12.0-ce","ClusterStore":"","ClusterAdvertise":"","Runtimes":{"runc":{"path":"docker-runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"89623f28b87a6004d4b785663257362d1658a729","Expected":"89623f28b87a6004d4b785663257362d1658a729"},"RuncCommit":{"ID":"b2567b37d7b75eb4cf325b77297b140ea686ce8f","Expected":"b2567b37d7b75eb4cf325b77297b140ea686ce8f"},"InitCommit":{"ID":"949e6fa","Expected":"949e6fa"},"SecurityOptions":["name=seccomp,profile=default"]} +EOF + +expected_output = { + "version_string" => "17.12.0-ce", + "version" => "17.12.0", + "runtimes" => { + "runc" => { + "path" => "docker-runc", + }, + }, + "root_dir" => "/var/lib/docker", + "containers" => { + "total" => 11, + "running" => 0, + "paused" => 0, + "stopped" => 11, + }, + "plugins" => { + "Volume" => [ + "local", + ], + "Network" => %w{ +bridge +host +ipvlan +macvlan +null +overlay}, + "Authorization" => nil, + "Log" => [ + "awslogs", + "fluentd", + "gcplogs", + "gelf", + "journald", + "json-file", + "logentries", + "splunk", + "syslog", + ], + }, + "networking" => { + "ipv4_forwarding" => true, + "bridge_nf_iptables" => true, + "bridge_nf_ipv6_iptables" => true, + }, + "swarm" => { + "NodeID" => "", + "NodeAddr" => "", + "LocalNodeState" => "inactive", + "ControlAvailable" => false, + "Error" => "", + "RemoteManagers" => nil, + }, +} + +describe Ohai::System, "plugin docker" do + let(:plugin) { get_plugin("docker") } + + context "if the machine does not have docker installed" do + it "should 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 + end + + context "if the machine has docker installed" do + it "should create 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 + expect(plugin).to have_key(:docker) + expect(plugin[:docker]).to eq(expected_output) + end + end +end diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb index 57357b58..613319bb 100644 --- a/spec/unit/plugins/linux/virtualization_spec.rb +++ b/spec/unit/plugins/linux/virtualization_spec.rb @@ -45,6 +45,7 @@ describe Ohai::System, "Linux virtualization platform" do # default the which wrappers to nil allow(plugin).to receive(:which).with("lxc-version").and_return(nil) allow(plugin).to receive(:which).with("lxc-start").and_return(nil) + allow(plugin).to receive(:which).with("docker").and_return(nil) allow(plugin).to receive(:nova_exists?).and_return(false) end @@ -85,6 +86,16 @@ describe Ohai::System, "Linux virtualization platform" do end end + describe "when we are checking for docker" do + it "sets docker host if docker binary exists" do + allow(plugin).to receive(:which).with("docker").and_return(true) + plugin.run + expect(plugin[:virtualization][:system]).to eq("docker") + expect(plugin[:virtualization][:role]).to eq("host") + expect(plugin[:virtualization][:systems][:docker]).to eq("host") + end + end + describe "when we are checking for openstack" do it "sets openstack host if nova binary exists" do allow(plugin).to receive(:nova_exists?).and_return("/usr/bin/nova") |