From f5e3c942eb7bcd7284d005d87e68169880663b63 Mon Sep 17 00:00:00 2001 From: Pranay Singh Date: Tue, 4 Jan 2022 20:55:44 +0530 Subject: [PATCH 1/9] adding aix support in chef run Signed-off-by: Pranay Singh --- lib/chef_apply/target_host.rb | 5 +++ lib/chef_apply/target_host/aix.rb | 57 +++++++++++++++++++++++++++++++ spec/unit/target_host/aix_spec.rb | 50 +++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 lib/chef_apply/target_host/aix.rb create mode 100644 spec/unit/target_host/aix_spec.rb 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 From 605f7980f41bc0f840c787bd1cd34b7e5803cd54 Mon Sep 17 00:00:00 2001 From: Pranay Singh Date: Wed, 5 Jan 2022 18:28:32 +0530 Subject: [PATCH 2/9] adding platform Signed-off-by: Pranay Singh --- lib/chef_apply/action/install_chef.rb | 2 ++ 1 file changed, 2 insertions(+) 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 From ce58edccf61b70a591be70067002a60209be8e74 Mon Sep 17 00:00:00 2001 From: Pranay Singh Date: Mon, 10 Jan 2022 23:52:47 +0530 Subject: [PATCH 3/9] testing for command on instance and cleaning out comments Signed-off-by: Pranay Singh --- lib/chef_apply/target_host/aix.rb | 6 ++---- spec/unit/target_host/aix_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/chef_apply/target_host/aix.rb b/lib/chef_apply/target_host/aix.rb index 346841c58..85f15513f 100644 --- a/lib/chef_apply/target_host/aix.rb +++ b/lib/chef_apply/target_host/aix.rb @@ -13,8 +13,8 @@ def mkdir(path) end def chown(path, owner) - owner ||= user - run_command!("chown #{owner} '#{path}'") + # owner ||= user + # run_command!("chown #{owner} '#{path}'") nil end @@ -27,8 +27,6 @@ def make_temp_dir 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 diff --git a/spec/unit/target_host/aix_spec.rb b/spec/unit/target_host/aix_spec.rb index a47c19fab..36697c163 100644 --- a/spec/unit/target_host/aix_spec.rb +++ b/spec/unit/target_host/aix_spec.rb @@ -38,10 +38,10 @@ 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" } + let(:expected_command) { "installp -aXYgd 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") + subject.install_package("/my/chef-12.0.0-rc.0-1.powerpc.bff") end From 40c77ab538f959a4e28e0026070ff2a24817c2ec Mon Sep 17 00:00:00 2001 From: Pranay Singh Date: Tue, 11 Jan 2022 00:01:31 +0530 Subject: [PATCH 4/9] linting with chefstyle Signed-off-by: Pranay Singh --- spec/unit/target_host/aix_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/unit/target_host/aix_spec.rb b/spec/unit/target_host/aix_spec.rb index 36697c163..881d8d4e5 100644 --- a/spec/unit/target_host/aix_spec.rb +++ b/spec/unit/target_host/aix_spec.rb @@ -16,8 +16,8 @@ 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")) + .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 From 09d4dd34761d7cd90d519f281b1ec9d5e7b15e49 Mon Sep 17 00:00:00 2001 From: Pranay Singh Date: Tue, 11 Jan 2022 00:07:02 +0530 Subject: [PATCH 5/9] removing chmod for aix in test case right now Signed-off-by: Pranay Singh --- spec/unit/target_host/aix_spec.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/spec/unit/target_host/aix_spec.rb b/spec/unit/target_host/aix_spec.rb index 881d8d4e5..2766c7db9 100644 --- a/spec/unit/target_host/aix_spec.rb +++ b/spec/unit/target_host/aix_spec.rb @@ -30,10 +30,11 @@ 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 + # 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 From d3a7258834f8b019fbd49cce6326a655bd753025 Mon Sep 17 00:00:00 2001 From: Pranay Singh Date: Tue, 11 Jan 2022 22:07:10 +0530 Subject: [PATCH 6/9] correcting some test failures Signed-off-by: Pranay Singh --- spec/unit/target_host/aix_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/unit/target_host/aix_spec.rb b/spec/unit/target_host/aix_spec.rb index 2766c7db9..3bd576c5f 100644 --- a/spec/unit/target_host/aix_spec.rb +++ b/spec/unit/target_host/aix_spec.rb @@ -39,10 +39,10 @@ context "#install_package" do context "run the correct pkg run command " do - let(:expected_command) { "installp -aXYgd chef-12.0.0-rc.0-1.powerpc.bff" } + let(:expected_command) { "installp -aXYgd chef-12.0.0-rc.0-1.powerpc.bff all" } it "should run the correct install command" do expect(subject).to receive(:run_command!).with expected_command - subject.install_package("/my/chef-12.0.0-rc.0-1.powerpc.bff") + subject.install_package("chef-12.0.0-rc.0-1.powerpc.bff") end From f5108df499f697d5e7094586919391294061e99e Mon Sep 17 00:00:00 2001 From: Pranay Singh Date: Tue, 4 Jan 2022 20:55:44 +0530 Subject: [PATCH 7/9] adding aix support in chef run Signed-off-by: Pranay Singh --- spec/unit/target_host/aix_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/unit/target_host/aix_spec.rb b/spec/unit/target_host/aix_spec.rb index 3bd576c5f..69c605684 100644 --- a/spec/unit/target_host/aix_spec.rb +++ b/spec/unit/target_host/aix_spec.rb @@ -43,7 +43,6 @@ it "should run the correct install command" do expect(subject).to receive(:run_command!).with expected_command subject.install_package("chef-12.0.0-rc.0-1.powerpc.bff") - end end From c87308f4fb98d225c75bef0c3e23fc1e0e061b0f Mon Sep 17 00:00:00 2001 From: Pranay Singh Date: Tue, 11 Jan 2022 22:31:57 +0530 Subject: [PATCH 8/9] adding installp to cspell file Signed-off-by: Pranay Singh --- cspell.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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. From 443c8c7c61e6d4943037db619ffa51681fde0029 Mon Sep 17 00:00:00 2001 From: Pranay Singh Date: Mon, 17 Jan 2022 13:44:22 +0530 Subject: [PATCH 9/9] updating chef client installer Signed-off-by: Pranay Singh --- spec/unit/target_host/aix_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/unit/target_host/aix_spec.rb b/spec/unit/target_host/aix_spec.rb index 69c605684..4fc7ee079 100644 --- a/spec/unit/target_host/aix_spec.rb +++ b/spec/unit/target_host/aix_spec.rb @@ -39,10 +39,10 @@ context "#install_package" do context "run the correct pkg run command " do - let(:expected_command) { "installp -aXYgd chef-12.0.0-rc.0-1.powerpc.bff all" } + 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-12.0.0-rc.0-1.powerpc.bff") + subject.install_package("chef-17.9.26-1.powerpc.bff") end end