Add --service-client option to migration script
We are migrating service clients to tempeset-lib, but we needed to update many places by hands even if using the migration script. There is a pattern of update, so this patch adds a new option --service-client for updating them automatically. We can use it like: $ tools/migrate_from_tempest.sh -u ../tempest -s \ tempest/services/compute/json/availability_zone_client.py \ tempest/tests/services/compute/test_availability_zone_client.py \ tempest/api_schema/response/compute/v2_1/availability_zone.py Partially implements blueprint migrate-service-clients-to-tempest-lib Change-Id: Iab832501725cedd5c5fcc65d760ce8a9794223ac
This commit is contained in:
@@ -23,12 +23,14 @@ function usage {
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
output_dir=""
|
output_dir=""
|
||||||
|
service_client=0
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h|--help) usage; exit;;
|
-h|--help) usage; exit;;
|
||||||
-o|--output_dir) output_dir="$2"; shift;;
|
-o|--output_dir) output_dir="$2"; shift;;
|
||||||
-u|--tempest_git_url) tempest_git_url="$2"; shift;;
|
-u|--tempest_git_url) tempest_git_url="$2"; shift;;
|
||||||
|
-s|--service_client) service_client=1;;
|
||||||
*) files="$files $1";;
|
*) files="$files $1";;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
@@ -64,9 +66,28 @@ for file in $files; do
|
|||||||
dirname="$output_dir"
|
dirname="$output_dir"
|
||||||
else
|
else
|
||||||
dirname=`echo $dirname | sed s@tempest\/@tempest_lib/\@`
|
dirname=`echo $dirname | sed s@tempest\/@tempest_lib/\@`
|
||||||
|
if [ $service_client -eq 1 ]; then
|
||||||
|
# Remove /json path because tempest-lib supports JSON only without XML
|
||||||
|
dirname=`echo $dirname | sed s@\/json@@`
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
dest_file="$dirname/$filename"
|
dest_file="$dirname/$filename"
|
||||||
cp -r "$tmpdir/$file" "$dest_file"
|
cp -r "$tmpdir/$file" "$dest_file"
|
||||||
|
|
||||||
|
if [ $service_client -eq 1 ]; then
|
||||||
|
# service_client module is not necessary in tempest-lib because rest_client can be used instead
|
||||||
|
sed -i s/"from tempest.common import service_client"/"from tempest_lib.common import rest_client"/ $dest_file
|
||||||
|
sed -i s/"service_client.ServiceClient"/"rest_client.RestClient"/ $dest_file
|
||||||
|
sed -i s/"service_client.ResponseBody"/"rest_client.ResponseBody"/ $dest_file
|
||||||
|
sed -i s/"from tempest\."/"from tempest_lib\."/ $dest_file
|
||||||
|
|
||||||
|
# Replace mocked path in unit tests
|
||||||
|
sed -i s/"tempest.common.rest_client"/"tempest_lib.common.rest_client"/ $dest_file
|
||||||
|
|
||||||
|
# Remove ".json" from import line
|
||||||
|
sed -i -e "s/^\(from tempest_lib\.services\..*\)\.json\(.*\)/\1\2/" $dest_file
|
||||||
|
fi
|
||||||
|
|
||||||
git add "$dest_file"
|
git add "$dest_file"
|
||||||
if [[ -z "$file_list" ]]; then
|
if [[ -z "$file_list" ]]; then
|
||||||
file_list="$filename"
|
file_list="$filename"
|
||||||
|
Reference in New Issue
Block a user