diff --git a/lib/chef_apply/target_host.rb b/lib/chef_apply/target_host.rb index b1f6de96e..8a9651f2a 100644 --- a/lib/chef_apply/target_host.rb +++ b/lib/chef_apply/target_host.rb @@ -144,6 +144,9 @@ class << self; include ChefApply::TargetHost::MacOS; end when :solaris require_relative "target_host/solaris" class << self; include ChefApply::TargetHost::Solaris; end + when :aix + require_relative "target_host/aix" + class << self; include ChefApply::TargetHost::Aix; end when :other raise ChefApply::TargetHost::UnsupportedTargetOS.new(platform.name) end @@ -178,6 +181,8 @@ def base_os :macos elsif platform.solaris? :solaris + elsif platform.aix? + :aix else :other end diff --git a/lib/chef_apply/target_host/aix.rb b/lib/chef_apply/target_host/aix.rb new file mode 100644 index 000000000..346841c58 --- /dev/null +++ b/lib/chef_apply/target_host/aix.rb @@ -0,0 +1,57 @@ +module ChefApply + class TargetHost + module Aix + + def omnibus_manifest_path + # Note that we can't use File::Join, because that will render for the + # CURRENT platform - not the platform of the target. + "/opt/chef/version-manifest.json" + end + + def mkdir(path) + run_command!("mkdir -p #{path}") + end + + def chown(path, owner) + owner ||= user + run_command!("chown #{owner} '#{path}'") + nil + end + + def make_temp_dir + # We will cache this so that we only run this once + @tempdir ||= begin + res = run_command!("bash -c '#{MKTEMP_COMMAND}'") + res.stdout.chomp.strip + end + end + + def install_package(target_package_path) + # command = "pkg install -g #{target_package_path} chef" + # command = "installp -ld #{target_package_path}" + command = "installp -aXYgd #{target_package_path} all" + run_command!(command) + end + + def del_file(path) + run_command!("rm -rf #{path}") + end + + def del_dir(path) + del_file(path) + end + + def ws_cache_path + "/var/chef-workstation" + end + + # Nothing to escape in a unix-based path + def normalize_path(path) + path + end + + MKTEMP_COMMAND = "d=$(mktemp -d -p${TMPDIR:-/tmp} chef_XXXXXX); echo $d".freeze + + end + end +end diff --git a/spec/unit/target_host/aix_spec.rb b/spec/unit/target_host/aix_spec.rb new file mode 100644 index 000000000..a47c19fab --- /dev/null +++ b/spec/unit/target_host/aix_spec.rb @@ -0,0 +1,50 @@ +require "spec_helper" +require "chef_apply/target_host" +require "chef_apply/target_host/aix" + +RSpec.describe ChefApply::TargetHost::Aix do + let(:user) { "testuser" } + let(:host) { "mock://#{user}@example.com" } + let(:family) { "aix" } + let(:name) { "aix" } + let(:path) { "/tmp/blah" } + + subject do + ChefApply::TargetHost.mock_instance(host, family: family, name: name) + end + + context "#make_temp_dir" do + it "creates the directory using a properly formed make_temp_dir" do + expect(subject).to receive(:run_command!) + .with("bash -c '#{ChefApply::TargetHost::Aix::MKTEMP_COMMAND}'") + .and_return(instance_double("result", stdout: "/tmp/blah")) + expect(subject.make_temp_dir).to eq "/tmp/blah" + end + end + + context "#mkdir" do + it "uses a properly formed mkdir to create the directory and changes ownership to connected user" do + expect(subject).to receive(:run_command!).with("mkdir -p /tmp/dir") + subject.mkdir("/tmp/dir") + end + end + + context "#chown" do + it "uses a properly formed chown to change owning user to the provided user" do + expect(subject).to receive(:run_command!).with("chown newowner '/tmp/dir'") + subject.chown("/tmp/dir", "newowner") + end + end + + context "#install_package" do + context "run the correct pkg run command " do + let(:expected_command) { "installp -ld chef-12.0.0-rc.0-1.powerpc.bff" } + it "should run the correct install command" do + expect(subject).to receive(:run_command!).with expected_command + subject.install_package("/my/chef-17.3.48-1.i386.p5p") + + end + + end + end +end