Fix linters error and enable linters zuul gate
Fix below linters errors and exclude openstack path for linter E003 Indent not multiple of 4 E011 Then keyword is not on same line as if or elif keyword E001 Trailing Whitespace ignore : E006 Line too long Story: 2003372 Task: 24435 Change-Id: I9221fc4c07633c49d8a7cb9afa0f6a1624304cb9 Signed-off-by: Sun Austin <austin.sun@intel.com>
This commit is contained in:
parent
17312ac4d0
commit
f01fd03136
|
@ -3,8 +3,8 @@
|
||||||
check:
|
check:
|
||||||
jobs:
|
jobs:
|
||||||
- openstack-tox-pep8
|
- openstack-tox-pep8
|
||||||
|
- openstack-tox-linters
|
||||||
gate:
|
gate:
|
||||||
jobs:
|
jobs:
|
||||||
- openstack-tox-pep8
|
- openstack-tox-pep8
|
||||||
|
- openstack-tox-linters
|
||||||
|
|
|
@ -4,17 +4,16 @@
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
#
|
#
|
||||||
|
|
||||||
backup_dir="/opt/backups"
|
backup_dir="/opt/backups"
|
||||||
tmp_dir="${backup_dir}/image_temp"
|
tmp_dir="${backup_dir}/image_temp"
|
||||||
|
|
||||||
function usage {
|
function usage {
|
||||||
cat <<"EOF"
|
cat <<"EOF"
|
||||||
Helper tool for backing up Glance images
|
Helper tool for backing up Glance images
|
||||||
Usage:
|
Usage:
|
||||||
image-backup export <uuid> - export the image with <uuid> into backup file /opt/backups/image_<uuid>.tgz
|
image-backup export <uuid> - export the image with <uuid> into backup file /opt/backups/image_<uuid>.tgz
|
||||||
image-backup import image_<uuid>.tgz - import the image from the backup source file at /opt/backups/image_<uuid>.tgz
|
image-backup import image_<uuid>.tgz - import the image from the backup source file at /opt/backups/image_<uuid>.tgz
|
||||||
into the corresponding image.
|
into the corresponding image.
|
||||||
|
|
||||||
Temporary files are stored in /opt/backups/image_temp
|
Temporary files are stored in /opt/backups/image_temp
|
||||||
|
|
||||||
|
@ -23,22 +22,22 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_tmp {
|
function create_tmp {
|
||||||
if [ ! -d ${backup_dir} ]; then
|
if [ ! -d ${backup_dir} ]; then
|
||||||
echo "Error: backup directory ${backup_dir} does not exist"
|
echo "Error: backup directory ${backup_dir} does not exist"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
# Create temporary directory
|
# Create temporary directory
|
||||||
if [ ! -d ${tmp_dir} ]; then
|
if [ ! -d ${tmp_dir} ]; then
|
||||||
mkdir ${tmp_dir}
|
mkdir ${tmp_dir}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_tmp {
|
function remove_tmp {
|
||||||
# Remove temporary files and directory if not empty
|
# Remove temporary files and directory if not empty
|
||||||
local uuid=$1
|
local uuid=$1
|
||||||
rm -f ${tmp_dir}/${uuid}*
|
rm -f ${tmp_dir}/${uuid}*
|
||||||
rmdir --ignore-fail-on-non-empty ${tmp_dir} &>/dev/null
|
rmdir --ignore-fail-on-non-empty ${tmp_dir} &>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
function export_file_from_rbd_image {
|
function export_file_from_rbd_image {
|
||||||
|
@ -56,9 +55,9 @@ function export_image {
|
||||||
# Check if the corresponding image is present in the RBD pool
|
# Check if the corresponding image is present in the RBD pool
|
||||||
rbd -p images ls | grep -q -e "^${uuid}$"
|
rbd -p images ls | grep -q -e "^${uuid}$"
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: Corresponding file for image with id: ${uuid} was not found in the RBD images pool"
|
echo "Error: Corresponding file for image with id: ${uuid} was not found in the RBD images pool"
|
||||||
remove_tmp; exit 1
|
remove_tmp; exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Export original image
|
# Export original image
|
||||||
export_file_from_rbd_image ${uuid}
|
export_file_from_rbd_image ${uuid}
|
||||||
|
@ -66,21 +65,21 @@ function export_image {
|
||||||
# Export raw cache if present
|
# Export raw cache if present
|
||||||
rbd -p images ls | grep -q ${uuid}_raw
|
rbd -p images ls | grep -q ${uuid}_raw
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
export_file_from_rbd_image ${uuid}_raw
|
export_file_from_rbd_image ${uuid}_raw
|
||||||
raw="${uuid}_raw"
|
raw="${uuid}_raw"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -n "Creating backup archive..."
|
echo -n "Creating backup archive..."
|
||||||
archive="${backup_dir}/image_${uuid}.tgz"
|
archive="${backup_dir}/image_${uuid}.tgz"
|
||||||
tar czf ${archive} -C ${tmp_dir} ${uuid} ${raw}
|
tar czf ${archive} -C ${tmp_dir} ${uuid} ${raw}
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: Failed to create archive ${archive}"
|
echo "Error: Failed to create archive ${archive}"
|
||||||
remove_tmp; exit 1
|
remove_tmp; exit 1
|
||||||
else
|
else
|
||||||
echo "done"
|
echo "done"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Backup archive ${archive} created"
|
echo "Backup archive ${archive} created"
|
||||||
}
|
}
|
||||||
|
|
||||||
function import_file_to_rbd_image {
|
function import_file_to_rbd_image {
|
||||||
|
@ -88,17 +87,17 @@ function import_file_to_rbd_image {
|
||||||
local snap="images/${file}@snap"
|
local snap="images/${file}@snap"
|
||||||
rbd import --image-format 2 ${tmp_dir}/${file} images/${file}
|
rbd import --image-format 2 ${tmp_dir}/${file} images/${file}
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: Failed to import image ${file} into Ceph images pool, please check status of storage cluster"
|
echo "Error: Failed to import image ${file} into Ceph images pool, please check status of storage cluster"
|
||||||
remove_tmp; exit 1
|
remove_tmp; exit 1
|
||||||
fi
|
fi
|
||||||
rbd snap create ${snap} 1>/dev/null
|
rbd snap create ${snap} 1>/dev/null
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: Failed to create snapshot ${snap}, please check status of storage cluster"
|
echo "Error: Failed to create snapshot ${snap}, please check status of storage cluster"
|
||||||
remove_tmp; exit 1
|
remove_tmp; exit 1
|
||||||
fi
|
fi
|
||||||
rbd snap protect ${snap} 1>/dev/null
|
rbd snap protect ${snap} 1>/dev/null
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: Failed to protect snapshot ${snap}, please check status of storage cluster"
|
echo "Error: Failed to protect snapshot ${snap}, please check status of storage cluster"
|
||||||
remove_tmp; exit 1
|
remove_tmp; exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -108,15 +107,15 @@ function import_image {
|
||||||
|
|
||||||
# Storage cluster must be healthy before starting the import
|
# Storage cluster must be healthy before starting the import
|
||||||
if [ ! "$(ceph health)" = "HEALTH_OK" ]; then
|
if [ ! "$(ceph health)" = "HEALTH_OK" ]; then
|
||||||
echo "Error: The storage cluster health must be HEALTH_OK before proceding"
|
echo "Error: The storage cluster health must be HEALTH_OK before proceding"
|
||||||
remove_tmp; exit 1
|
remove_tmp; exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if the corresponding image is already present in the RBD pool
|
# Check if the corresponding image is already present in the RBD pool
|
||||||
rbd -p images ls | grep -q -e "^${uuid}$"
|
rbd -p images ls | grep -q -e "^${uuid}$"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "Error: Image with id: ${uuid} is already imported"
|
echo "Error: Image with id: ${uuid} is already imported"
|
||||||
remove_tmp; exit 1
|
remove_tmp; exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Import original image
|
# Import original image
|
||||||
|
@ -124,17 +123,16 @@ function import_image {
|
||||||
|
|
||||||
# Import raw cache
|
# Import raw cache
|
||||||
if [ -f "${tmp_dir}/${uuid}_raw" ]; then
|
if [ -f "${tmp_dir}/${uuid}_raw" ]; then
|
||||||
import_file_to_rbd_image ${uuid}_raw
|
import_file_to_rbd_image ${uuid}_raw
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ $EUID -ne 0 ]; then
|
if [ $EUID -ne 0 ]; then
|
||||||
echo "This script must be executed as root"
|
echo "This script must be executed as root"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $# -ne 2 ] ;
|
if [ $# -ne 2 ]; then
|
||||||
then
|
|
||||||
usage
|
usage
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
@ -144,69 +142,68 @@ source /etc/nova/openrc
|
||||||
# Check if glance is using ceph as RBD
|
# Check if glance is using ceph as RBD
|
||||||
cat /etc/glance/glance-api.conf | grep -q -e "^stores.*=.*rbd"
|
cat /etc/glance/glance-api.conf | grep -q -e "^stores.*=.*rbd"
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: Glance is not configured to use the ceph backend."
|
echo "Error: Glance is not configured to use the ceph backend."
|
||||||
echo "This command should be used only on setups with configured Ceph storage."
|
echo "This command should be used only on setups with configured Ceph storage."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" = "export" ]; then
|
if [ "$1" = "export" ]; then
|
||||||
# Check that glance image is present in glance
|
# Check that glance image is present in glance
|
||||||
glance image-list | tail -n +3 | awk '{print $2}' | grep -q $2
|
glance image-list | tail -n +3 | awk '{print $2}' | grep -q $2
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: Glance image with id: $2 not found. Please try with an existing image id."
|
echo "Error: Glance image with id: $2 not found. Please try with an existing image id."
|
||||||
remove_tmp; exit 1
|
remove_tmp; exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Only allow backup of images that use rbd as backend.
|
# Only allow backup of images that use rbd as backend.
|
||||||
glance image-show $2 | grep 'direct_url' | awk '{print $4}' | grep -q '^rbd://'
|
glance image-show $2 | grep 'direct_url' | awk '{print $4}' | grep -q '^rbd://'
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Image with id: $2 is not stored in Ceph RBD. Backup using image-backup tool is not needed."
|
echo "Image with id: $2 is not stored in Ceph RBD. Backup using image-backup tool is not needed."
|
||||||
echo "Please consult the Software Management Manual for more details."
|
echo "Please consult the Software Management Manual for more details."
|
||||||
remove_tmp; exit 1
|
remove_tmp; exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
create_tmp
|
create_tmp
|
||||||
export_image $2
|
export_image $2
|
||||||
remove_tmp
|
remove_tmp
|
||||||
|
|
||||||
elif [ "$1" = "import" ]; then
|
elif [ "$1" = "import" ]; then
|
||||||
# Check that the input file format is correct
|
# Check that the input file format is correct
|
||||||
if [[ ! $2 =~ ^image_.*\.tgz$ ]]; then
|
if [[ ! $2 =~ ^image_.*\.tgz$ ]]; then
|
||||||
echo "Error: Source file name must conform to image_<uuid>.tgz format"
|
echo "Error: Source file name must conform to image_<uuid>.tgz format"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check that the source file exists
|
|
||||||
if [ ! -f ${backup_dir}/$2 ]; then
|
|
||||||
echo "Error: File $2 does not exists in ${backup_dir}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get glance uuid from filename
|
# Check that the source file exists
|
||||||
uuid=$(echo $2 | sed "s/^image_\(.*\)\.tgz/\1/g")
|
if [ ! -f ${backup_dir}/$2 ]; then
|
||||||
|
echo "Error: File $2 does not exists in ${backup_dir}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Check that glance has this image in the database
|
# Get glance uuid from filename
|
||||||
glance image-list | grep -q $uuid
|
uuid=$(echo $2 | sed "s/^image_\(.*\)\.tgz/\1/g")
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Error: Glance image with id: ${uuid} not found. Please try with an existing image id."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
create_tmp
|
# Check that glance has this image in the database
|
||||||
|
glance image-list | grep -q $uuid
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Error: Glance image with id: ${uuid} not found. Please try with an existing image id."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Extract the files that need to be imported into the temp directory
|
create_tmp
|
||||||
echo -n "Extracting files..."
|
|
||||||
tar xfz ${backup_dir}/$2 -C ${tmp_dir} 1>/dev/null
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Error: Failed to extract archive ${backup_dir}/$2 into ${tmp_dir}."
|
|
||||||
remove_tmp; exit 1
|
|
||||||
fi
|
|
||||||
echo "done"
|
|
||||||
|
|
||||||
# Importing images into RBD
|
# Extract the files that need to be imported into the temp directory
|
||||||
import_image $uuid
|
echo -n "Extracting files..."
|
||||||
remove_tmp
|
tar xfz ${backup_dir}/$2 -C ${tmp_dir} 1>/dev/null
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Error: Failed to extract archive ${backup_dir}/$2 into ${tmp_dir}."
|
||||||
|
remove_tmp; exit 1
|
||||||
|
fi
|
||||||
|
echo "done"
|
||||||
|
|
||||||
|
# Importing images into RBD
|
||||||
|
import_image $uuid
|
||||||
|
remove_tmp
|
||||||
else
|
else
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ find /mnt/huge-1048576kB/|xargs ls -ld >> ${logfile} 2>> ${logfile}
|
||||||
|
|
||||||
echo "Locked smaps" >> ${logfile}
|
echo "Locked smaps" >> ${logfile}
|
||||||
echo "------------" >> ${logfile}
|
echo "------------" >> ${logfile}
|
||||||
grep Locked: /proc/*/smaps 2>/dev/null| awk '($2 > 0) {a[$1]+=$2} END {for (i in a) print i,a[i]/1024.0, "MiB";}' >> ${logfile} 2>> ${logfile}
|
grep Locked: /proc/*/smaps 2>/dev/null | awk '($2 > 0) {a[$1]+=$2} END {for (i in a) print i,a[i]/1024.0, "MiB";}' >> ${logfile} 2>> ${logfile}
|
||||||
|
|
||||||
date '+%F %T' >> ${logfile} 2>> ${logfile}
|
date '+%F %T' >> ${logfile} 2>> ${logfile}
|
||||||
|
|
||||||
|
|
10
tox.ini
10
tox.ini
|
@ -14,6 +14,8 @@ deps = -r{toxinidir}/test-requirements.txt
|
||||||
|
|
||||||
[testenv:linters]
|
[testenv:linters]
|
||||||
whitelist_externals = bash
|
whitelist_externals = bash
|
||||||
|
#bashate ignore
|
||||||
|
#E006 Line too long
|
||||||
commands =
|
commands =
|
||||||
bash -c "find {toxinidir} \
|
bash -c "find {toxinidir} \
|
||||||
-not \( -type d -name .?\* -prune \) \
|
-not \( -type d -name .?\* -prune \) \
|
||||||
|
@ -21,11 +23,11 @@ commands =
|
||||||
-not -name \*~ \
|
-not -name \*~ \
|
||||||
-not -name \*.md \
|
-not -name \*.md \
|
||||||
-name \*.sh \
|
-name \*.sh \
|
||||||
-print0 | xargs -0 bashate -v"
|
-print0 | xargs -0 bashate -v -i E006"
|
||||||
bash -c "find {toxinidir} \
|
bash -c "find {toxinidir} \
|
||||||
\( -name middleware/io-monitor/recipes-common/io-monitor/io-monitor/io_monitor/test-tools/yaml/* -prune \) \
|
\( -path '{toxinidir}/openstack/python-heat/python-heat/templates*' \
|
||||||
-o \( -name .tox -prune \) \
|
-o -path '{toxinidir}/.tox' \) -a -prune \
|
||||||
-o -type f -name '*.yaml' \
|
-o -name '*.yaml' \
|
||||||
-print0 | xargs -0 yamllint"
|
-print0 | xargs -0 yamllint"
|
||||||
|
|
||||||
[testenv:pep8]
|
[testenv:pep8]
|
||||||
|
|
Loading…
Reference in New Issue