Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ORAchk to the Oracle Toolkit (#35) #220

Merged
merged 27 commits into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e4b2fe0
Add ORAchk to the Oracle Toolkit (#35)
jkstill Mar 6, 2025
1d1714c
Merge remote-tracking branch 'oracle-toolkit/master' into rel/oratk-5…
jkstill Mar 13, 2025
27fb68c
Remove unintended changes to manage_devices_on_vm.sh
jkstill Mar 14, 2025
c652c40
Remove unintended changes to presubmit_tests/test-pr-poc.sh
jkstill Mar 14, 2025
da19496
removed orachk.sh, run-orack.sh. moved the tasks to ansible
jkstill Mar 24, 2025
329904c
Merge branch 'master' into rel/oratk-57-orachk
jkstill Mar 24, 2025
f9fc032
removed check-oracle-vars.yml - no longer used
jkstill Mar 24, 2025
928d74a
reverted master:roles/common/defaults/main.yml. Unsure why it had be…
jkstill Mar 24, 2025
f0fac13
set export ANSIBLE_DISPLAY_SKIPPED_HOSTS=false. Shorten up orachk ru…
jkstill Mar 24, 2025
cd8eff7
shellcheck
jkstill Mar 24, 2025
43285fc
quoted $0
jkstill Mar 24, 2025
0731637
added copyright
jkstill Mar 24, 2025
7480284
working on PR changes
jkstill Mar 26, 2025
dd91795
continued work on PR requested changes
jkstill Mar 26, 2025
6fa6ecc
further changes as per PR requests. also added facility for expedite…
jkstill Mar 26, 2025
52ab35f
updated orachk install, run and uninstall docs
jkstill Mar 27, 2025
a2ad6df
use a gsutil to get AHF file to local host, then copy to remote
jkstill Mar 27, 2025
59f1184
removed unnecessary comments
jkstill Mar 27, 2025
64f9cb6
minor adjustments
jkstill Mar 27, 2025
8ebb803
now using ansible stat to check for file existence on localhost. usin…
jkstill Mar 28, 2025
bda6d83
change from gsutil cp to gcloud storage cp
jkstill Mar 28, 2025
2d0886a
fixed quoting for gcloud storage cp
jkstill Mar 28, 2025
e43a8b3
fixed assignment operator ${ORACLE_SID:="NOOP"} was backwards with "=:"
jkstill Mar 28, 2025
2cffcb4
use become: to fetch the file due to permissions
jkstill Mar 29, 2025
5bf4efa
Merge branch 'master' into rel/oratk-57-orachk
jkstill Apr 3, 2025
6d9ed2b
updated to use become: true|false where explicitly needed. uninstall…
jkstill Apr 3, 2025
028aeb6
added become: true for fetching orachk report. create /tmp/orachk/ fo…
jkstill Apr 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
229 changes: 229 additions & 0 deletions check-oracle.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind running these shell scripts through a linter like shellcheck? It has a bunch of lint-style warnings around quoting and the like.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only remaining shell script is check-oracle.sh, and I have run it through shellcheck, and made any modifications that were appropriate.

Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
#!/bin/bash
# Copyright 2025 Google LLC
#
# 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.

# used for oracle ORAchk. install, run and uninstall ORAchk
#
# Check if we're using the Mac stock getopt and fail if true
# shellcheck disable=SC2034
out="$(getopt -T)"
if [ $? != 4 ]; then
echo -e "Your getopt does not support long parameters, possibly you're on a Mac, if so please install gnu-getopt with brew"
echo -e "\thttps://brewformulas.org/Gnu-getopt"
exit 1
fi

# do not display skipped hosts -
# a misnomer, as it does not display all 'skipped' tasks
export ANSIBLE_EXTRA_VARS=''
# use ANSIBLE_DISPLAY_SKIPPED_HOSTS=true ./check-oracle.sh to see skipped tasks
: ${ANSIBLE_DISPLAY_SKIPPED_HOSTS:=false}
export ANSIBLE_DISPLAY_SKIPPED_HOSTS
#echo ANSIBLE_DISPLAY_SKIPPED_HOSTS: $ANSIBLE_DISPLAY_SKIPPED_HOSTS

export INVENTORY_FILE=''
export AHF_LOCATION=''

export AHF_LOCATION_PARAM='^gs://.+[^/]$'

export ORACLE_SERVER=''
export AHF_DIR='AHF'
export AHF_FILE=''
export AHF_INSTALL=0
export AHF_UNINSTALL=0
export RUN_ORACHK=0

export GETOPT_MANDATORY="instance-ip-addr:"
export GETOPT_OPTIONAL="extra-vars:,ahf-location:,db-name:,inventory-file:,ahf-install,ahf-uninstall,run-orachk,help,debug"

export GETOPT_LONG="$GETOPT_MANDATORY,$GETOPT_OPTIONAL"
export GETOPT_SHORT="h"

options="$(getopt --longoptions "$GETOPT_LONG" --options "$GETOPT_SHORT" -- "$@")"

# shellcheck disable=SC2181
[ $? -eq 0 ] || {
echo "Invalid options provided: $*" >&2
exit 1
}

eval set -- "$options"

help () {

echo -e "\tUsage: $(basename "$0")"
echo "${GETOPT_MANDATORY}" | sed 's/,/\n/g' | sed 's/:/ <value>/' | sed 's/\(.\+\)/\t --\1/'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do like the autogeneration of usage, but when I run it, I don't see --install-ahf at all:

$ bash ./check-oracle.sh --inventory-file inventory_files/inventory_new_RAC
Usage: check-oracle.sh
--instance-ip-addr
[ --extra-vars ]
[ --ahf-location ]
[ --db-name ]
[ --inventory-file ]
[ --ahf-install ]
[ --ahf-uninstall ]
[ --run-orachk ]
[ --help ]
[ --debug ]

--ahf-install and --run-orachk may be combined to install and run
--extra-vars is used to pass extra ansible vars
example: --extra-vars var1=val1 var2=val2 ...

echo "${GETOPT_OPTIONAL}" | sed 's/,/\n/g' | sed 's/:/ <value>/' | sed 's/\(.\+\)/\t [ --\1 ]/'
echo
echo "--ahf-install and --run-orachk may be combined to install and run"
echo "--extra-vars is used to pass extra ansible vars"
echo " example: --extra-vars "var1=val1 var2=val2 ...""

}

# check if both install and run were specified together
export RUN_ENABLED=0
export INSTALL_ENABLED=0

while true
do

case "$1" in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I ask for a --debug parameter like install-oracle.sh does, which adds verbosity to the ansible-playbook command? Maybe even an --extra-vars to pass extra stuff to ansible if needed?


--extra-vars)
ANSIBLE_EXTRA_VARS="$2"
;;

--ahf-location)
AHF_LOCATION="$2"
;;

--debug)
export ANSIBLE_DEBUG=1
export ANSIBLE_DISPLAY_SKIPPED_HOSTS=true
;;

--help | -h)
help >&2
exit 0
;;

--inventory-file)
INVENTORY_FILE="$2"
shift;
;;

--db-name)
ORACLE_SID="$2"
shift
;;

--instance-ip-addr)
ORACLE_SERVER="$2"
shift
;;

--ahf-install)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no command is specified, this script exits with success and no output at all. It would be better to show an error in this case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something here does not seem right.

When I run without any options, I get this:

$ ./check-oracle.sh
please specify --oracle-server

When run with --ahf-install

$ ./check-oracle.sh --ahf-install
please specify --oracle-server

I think it would probably be good to include the help message here, but, there is output.

Can you verify that check-oracle.sh is correct?

What I see in google-toolkit-for-oracle in rel/oratk-57-orachk

$ sha256sum check-oracle.sh
1ffdb2c72f52ce073f8a7b0c6cc3309653adc9226cef072a4faf06174f9a0928  check-oracle.sh

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my case, I'm saw the error message and passed --oracle-server as requested (but no command). And I got success and blank output.

: ${ORACLE_SID:='NOOP'}
AHF_UNINSTALL=1
AHF_INSTALL=1
INSTALL_ENABLED=1
;;

--ahf-uninstall)
ORACLE_SID='NOOP'
AHF_UNINSTALL=1
AHF_INSTALL=0
;;

--run-orachk)
AHF_UNINSTALL=0
AHF_INSTALL=0
RUN_ORACHK=1
RUN_ENABLED=1
;;

--)
shift
break
;;

esac

shift

done

# one of install, uninstall or run must be called

[[ $AHF_INSTALL -eq 0 ]] && [[ $AHF_UNINSTALL -eq 0 ]] && [[ $RUN_ORACHK -eq 0 ]] && { help; exit 1; }


[[ -n $ANSIBLE_EXTRA_VARS ]] && {

if [[ ! "$ANSIBLE_EXTRA_VARS" =~ ^([a-zA-Z_][a-zA-Z0-9_]*=[^[:space:]]+)([[:space:]]+[a-zA-Z_][a-zA-Z0-9_]*=[^[:space:]]+)*$ ]]; then
echo "Invalid format for --extra-vars"
echo "the extra vars should be a string of 1 or more name=value pairs separated by a space"
echo "example: varname1=value varname2=value2 varname3=value3"
exit 1
fi

}

[ "$RUN_ENABLED" -eq 1 ] && [ "$INSTALL_ENABLED" -eq 1 ] && {
AHF_UNINSTALL=1
AHF_INSTALL=1
INSTALL_ENABLED=1
}

[[ -z $ORACLE_SID ]] && { echo "please specify --db-name"; echo; help; exit 1; }

# if an ip address is passed for --instance-ip-address, and inventory file is not specified on the cli, check for an inventory file by lookup of target hostname
[[ "$ORACLE_SERVER" =~ ^[[:digit:]]{1,3}[.][[:digit:]]{1,3}[.][[:digit:]]{1,3}[.][[:digit:]]{1,3}$ ]] && [[ -z "$INVENTORY_FILE" ]] && {
TARGET_HOSTNAME="$( dig +short -x $ORACLE_SERVER | cut -f1 -d\. )"
TEST_INVENTORY_FILE=inventory_files/inventory_${TARGET_HOSTNAME}_${ORACLE_SID}
[[ -r $TEST_INVENTORY_FILE ]] && INVENTORY_FILE="$TEST_INVENTORY_FILE"
}

# if the inventory file is specified on the cli, then the --instance-ip-addr or ORACLE_SERVER are not required
if [[ -z $INVENTORY_FILE ]]; then
[[ -z $ORACLE_SERVER ]] && { echo "please specify --instance-ip-addr"; echo; help; exit 1; }
INVENTORY_FILE=inventory_files/inventory_${ORACLE_SERVER}_${ORACLE_SID}
fi

[[ -r $INVENTORY_FILE ]] || {
echo "cannot read inventory file '$INVENTORY_FILE'"
echo " please check and --instance-ip-addr"
echo " and --inventory-file"
exit 1
}

# fail early if the AFH file format is incorrect and/or the file does not exist.
[[ -n "$AHF_LOCATION" ]] || [[ $AHF_INSTALL -eq 1 ]] && {

[[ ! "$AHF_LOCATION" =~ $AHF_LOCATION_PARAM ]] && {
echo "Incorrect parameter provided for AHF_LOCATION: $AHF_LOCATION"
echo "Example: gs://my-gcs-bucket/ahf/ahf.zip"
exit 1
}

( gsutil ls "$AHF_LOCATION" >/dev/null 2>&1 ) || {
echo "--ahf-location file '$AHF_LOCATION' not found"
exit 1;
}
}

# Uninstall AHF
[[ $AHF_UNINSTALL -eq 1 ]] && {

ansible-playbook -i "$INVENTORY_FILE" check-oracle.yml \
--extra-vars "uninstall_ahf=true $ANSIBLE_EXTRA_VARS"
}

# Install AHF
[[ $AHF_INSTALL -eq 1 ]] && {


ansible-playbook -i "$INVENTORY_FILE" check-oracle.yml \
--extra-vars "uninstall_ahf=false AHF_LOCATION=$AHF_LOCATION $ANSIBLE_EXTRA_VARS"
}

# run ORAchk
[[ $RUN_ORACHK -eq 1 ]] && {

ansible-playbook -i "$INVENTORY_FILE" check-oracle.yml \
--extra-vars "uninstall_ahf=false run_orachk=true ORACLE_SID=$ORACLE_SID $ANSIBLE_EXTRA_VARS"
}


Loading