diff --git a/cspell.json b/cspell.json index c867af1f0..973c32ddc 100644 --- a/cspell.json +++ b/cspell.json @@ -53,7 +53,8 @@ "CHEFINT", "Alnum", "succ", - "proto" + "proto", + "installp" ], // flagWords - list of words to be always considered incorrect // This is useful for offensive words and common spelling errors. diff --git a/lib/chef_apply/action/install_chef.rb b/lib/chef_apply/action/install_chef.rb index f0657a029..f9453b100 100644 --- a/lib/chef_apply/action/install_chef.rb +++ b/lib/chef_apply/action/install_chef.rb @@ -99,6 +99,8 @@ def train_to_mixlib(platform) opts[:platform] = "sles" when "solaris" opts[:platform] = "solaris2" + when "aix" + opts[:platform] = "aix" when "amazon" opts[:platform] = "el" if platform.release.to_i > 2010 # legacy Amazon version 1 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..85f15513f --- /dev/null +++ b/lib/chef_apply/target_host/aix.rb @@ -0,0 +1,55 @@ +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 = "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..4fc7ee079 --- /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 + xit "Doing nothing for this right now on aix" + end + + context "#install_package" do + context "run the correct pkg run command " do + let(:expected_command) { "installp -aXYgd chef-17.9.26-1.powerpc.bff all" } + it "should run the correct install command" do + expect(subject).to receive(:run_command!).with expected_command + subject.install_package("chef-17.9.26-1.powerpc.bff") + end + + end + end +end