Skip to content

Commit

Permalink
Merge pull request #201 from chef/i5pranay93/support_aix
Browse files Browse the repository at this point in the history
Support AIX for chef adhoc runs
  • Loading branch information
vkarve-chef authored Jan 18, 2022
2 parents 4b68d60 + 443c8c7 commit 4973633
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions lib/chef_apply/action/install_chef.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/chef_apply/target_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -178,6 +181,8 @@ def base_os
:macos
elsif platform.solaris?
:solaris
elsif platform.aix?
:aix
else
:other
end
Expand Down
55 changes: 55 additions & 0 deletions lib/chef_apply/target_host/aix.rb
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions spec/unit/target_host/aix_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4973633

Please sign in to comment.