[1/3] ambari git commit: AMBARI-18226. Remove Redundant Embedded Postgres SQL (aonishuk)
Repository: ambari Updated Branches: refs/heads/trunk 51cbf0df6 -> 9dbcac6d5 http://git-wip-us.apache.org/repos/asf/ambari/blob/9dbcac6d/ambari-server/src/main/resources/scripts/change_owner.sh -- diff --git a/ambari-server/src/main/resources/scripts/change_owner.sh b/ambari-server/src/main/resources/scripts/change_owner.sh deleted file mode 100755 index 6f0ac3d..000 --- a/ambari-server/src/main/resources/scripts/change_owner.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - -usage() -{ -cat << EOF -usage: $0 options - -This script set ownership for all table, sequence and views for a given database - -OPTIONS: - -h Show this message - -d Database name - -o Owner - -s Schema (defaults to public) -EOF -} - -DB_NAME=""; -NEW_OWNER=""; -SCHEMA="public"; -while getopts "hd:o:s:" OPTION; do -case $OPTION in -h) -usage; -exit 1; -;; -d) -DB_NAME=$OPTARG; -;; -o) -NEW_OWNER=$OPTARG; -;; -s) -SCHEMA=$OPTARG; -;; -esac -done - -if [[ -z $DB_NAME ]] || [[ -z $NEW_OWNER ]]; then - usage; - exit 1; -fi - -# Using the NULL byte as the separator as its the only character disallowed from PG table names -IFS=\0; -for tbl in `psql -qAt -R\0 -c "SELECT tablename FROM pg_tables WHERE schemaname = '${SCHEMA}';" ${DB_NAME}` \ - `psql -qAt -R\0 -c "SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = '${SCHEMA}';" ${DB_NAME}` \ - `psql -qAt -R\0 -c "SELECT table_name FROM information_schema.views WHERE table_schema = '${SCHEMA}';" ${DB_NAME}` ; -do -psql -c "ALTER TABLE \"${SCHEMA}\".\"$tbl\" OWNER TO ${NEW_OWNER}" ${DB_NAME}; -done -unset IFS; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/9dbcac6d/ambari-server/src/test/python/TestAmbariServer.py -- diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py index 9992eb3..cd1d294 100644 --- a/ambari-server/src/test/python/TestAmbariServer.py +++ b/ambari-server/src/test/python/TestAmbariServer.py @@ -1021,6 +1021,7 @@ class TestAmbariServer(TestCase): run_os_command_mock.return_value = (0, None, None) result = dbms._setup_db() self.assertTrue(run_os_command_mock.called) +self.assertEqual(run_os_command_mock.call_count, 2) self.assertEqual((0, None, None), result) pass @@ -3318,7 +3319,7 @@ class TestAmbariServer(TestCase): def test_prompt_db_properties_postgre_adv(self, gyni_mock, gvsi_mock, gvsi_2_mock, rp_mock, print_info_msg_mock, sls_mock, get_os_family_mock, get_pw_nam_mock, chown_mock, mkdir_mock, isdir_mock): gyni_mock.return_value = True -list_of_return_values = ["ambari-server", "ambari", "ambari", "1"] +list_of_return_values = ["ambari-server", "postgres", "ambari", "ambari", "1"] get_os_family_mock.return_value = OSConst.SUSE_FAMILY pw = MagicMock() pw.setattr('pw_uid', 0) @@ -3391,12 +3392,13 @@ class TestAmbariServer(TestCase): db_name = "db_ambari" postgres_schema = "sc_ambari" port = "1234" +local_admin_user = "postgres" oracle_service = "1" oracle_service_name = "ambari" user_name = "ambari" # Input values -postgres_embedded_values = [db_name, postgres_schema, hostname] +postgres_embedded_values = [local_admin_user, db_name, postgres_schema, hostname] oracle_values = [hostname, port, oracle_service, oracle_service_name, user_name] mysql_values = [hostname, port, db_name, user_name] postgres_external_values = [hostname, port, db_name, postgres_schema, user_name] @@ -3435,6 +3437,7 @@ class TestAmbariServer(TestCase): del args.dbms del args.database_host + del args.local_admin_user del args.database_port del args.database_name del args.database_username @@ -5218,7 +5221,8 @@ class TestAmbariServer(TestC
[1/3] ambari git commit: AMBARI-18226. Remove Redundant Embedded Postgres SQL (aonishuk)
Repository: ambari Updated Branches: refs/heads/branch-2.5 f31e76f5c -> 20eacc675 http://git-wip-us.apache.org/repos/asf/ambari/blob/20eacc67/ambari-server/src/main/resources/scripts/change_owner.sh -- diff --git a/ambari-server/src/main/resources/scripts/change_owner.sh b/ambari-server/src/main/resources/scripts/change_owner.sh deleted file mode 100755 index 6f0ac3d..000 --- a/ambari-server/src/main/resources/scripts/change_owner.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - -usage() -{ -cat << EOF -usage: $0 options - -This script set ownership for all table, sequence and views for a given database - -OPTIONS: - -h Show this message - -d Database name - -o Owner - -s Schema (defaults to public) -EOF -} - -DB_NAME=""; -NEW_OWNER=""; -SCHEMA="public"; -while getopts "hd:o:s:" OPTION; do -case $OPTION in -h) -usage; -exit 1; -;; -d) -DB_NAME=$OPTARG; -;; -o) -NEW_OWNER=$OPTARG; -;; -s) -SCHEMA=$OPTARG; -;; -esac -done - -if [[ -z $DB_NAME ]] || [[ -z $NEW_OWNER ]]; then - usage; - exit 1; -fi - -# Using the NULL byte as the separator as its the only character disallowed from PG table names -IFS=\0; -for tbl in `psql -qAt -R\0 -c "SELECT tablename FROM pg_tables WHERE schemaname = '${SCHEMA}';" ${DB_NAME}` \ - `psql -qAt -R\0 -c "SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = '${SCHEMA}';" ${DB_NAME}` \ - `psql -qAt -R\0 -c "SELECT table_name FROM information_schema.views WHERE table_schema = '${SCHEMA}';" ${DB_NAME}` ; -do -psql -c "ALTER TABLE \"${SCHEMA}\".\"$tbl\" OWNER TO ${NEW_OWNER}" ${DB_NAME}; -done -unset IFS; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/20eacc67/ambari-server/src/test/python/TestAmbariServer.py -- diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py index 9992eb3..cd1d294 100644 --- a/ambari-server/src/test/python/TestAmbariServer.py +++ b/ambari-server/src/test/python/TestAmbariServer.py @@ -1021,6 +1021,7 @@ class TestAmbariServer(TestCase): run_os_command_mock.return_value = (0, None, None) result = dbms._setup_db() self.assertTrue(run_os_command_mock.called) +self.assertEqual(run_os_command_mock.call_count, 2) self.assertEqual((0, None, None), result) pass @@ -3318,7 +3319,7 @@ class TestAmbariServer(TestCase): def test_prompt_db_properties_postgre_adv(self, gyni_mock, gvsi_mock, gvsi_2_mock, rp_mock, print_info_msg_mock, sls_mock, get_os_family_mock, get_pw_nam_mock, chown_mock, mkdir_mock, isdir_mock): gyni_mock.return_value = True -list_of_return_values = ["ambari-server", "ambari", "ambari", "1"] +list_of_return_values = ["ambari-server", "postgres", "ambari", "ambari", "1"] get_os_family_mock.return_value = OSConst.SUSE_FAMILY pw = MagicMock() pw.setattr('pw_uid', 0) @@ -3391,12 +3392,13 @@ class TestAmbariServer(TestCase): db_name = "db_ambari" postgres_schema = "sc_ambari" port = "1234" +local_admin_user = "postgres" oracle_service = "1" oracle_service_name = "ambari" user_name = "ambari" # Input values -postgres_embedded_values = [db_name, postgres_schema, hostname] +postgres_embedded_values = [local_admin_user, db_name, postgres_schema, hostname] oracle_values = [hostname, port, oracle_service, oracle_service_name, user_name] mysql_values = [hostname, port, db_name, user_name] postgres_external_values = [hostname, port, db_name, postgres_schema, user_name] @@ -3435,6 +3437,7 @@ class TestAmbariServer(TestCase): del args.dbms del args.database_host + del args.local_admin_user del args.database_port del args.database_name del args.database_username @@ -5218,7 +5221,8 @@ class TestAmbariServer(