incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject git commit: AMBARI-3020. Running ambari-server setup more than once to reconfigure postgres settings fails. (Artem Baranchuk via swagle)
Date Fri, 23 Aug 2013 21:57:10 GMT
Updated Branches:
  refs/heads/branch-1.4 c93e211e3 -> ec6e76fe3


AMBARI-3020. Running ambari-server setup more than once to reconfigure postgres settings fails.
(Artem Baranchuk via swagle)


Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/ec6e76fe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/ec6e76fe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/ec6e76fe

Branch: refs/heads/branch-1.4
Commit: ec6e76fe3aa40711ce24cdc6abb72c6728aaeaa6
Parents: c93e211
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Fri Aug 23 14:56:52 2013 -0700
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Fri Aug 23 14:56:52 2013 -0700

----------------------------------------------------------------------
 .../server/configuration/Configuration.java     |   6 +-
 .../server/controller/ControllerModule.java     |   2 +-
 ambari-server/src/main/python/ambari-server.py  |  58 +++--
 .../resources/Ambari-DDL-Postgres-CREATE.sql    | 229 +++++++++----------
 .../main/resources/Ambari-DDL-Postgres-DROP.sql |   4 +-
 .../Ambari-DDL-Postgres-UPGRADE-1.3.0.Check.sql |   2 +-
 .../Ambari-DDL-Postgres-UPGRADE-1.3.0.Fix.sql   |   2 +-
 .../ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql   |   2 +-
 .../dml/Ambari-DML-Postgres-UPGRADE_STACK.sql   |   2 +-
 .../server/configuration/ConfigurationTest.java |   8 +
 .../src/test/python/TestAmbaryServer.py         |  54 ++++-
 11 files changed, 215 insertions(+), 154 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/ec6e76fe/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index f3e2b25..18bbe19 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -146,7 +146,7 @@ public class Configuration {
 
   public static final String JDBC_UNIT_NAME = "ambari-server";
 
-  public static final String JDBC_LOCAL_URL = "jdbc:postgresql://localhost/ambari";
+  public static final String JDBC_LOCAL_URL = "jdbc:postgresql://localhost/";
   public static final String JDBC_LOCAL_DRIVER = "org.postgresql.Driver";
 
   public static final String JDBC_IN_MEMORY_URL = "jdbc:derby:memory:myDB/ambari;create=true";
@@ -571,6 +571,10 @@ public class Configuration {
     return properties.getProperty(SERVER_JDBC_URL_KEY);
   }
 
+  public String getLocalDatabaseUrl() {
+    return JDBC_LOCAL_URL + properties.getProperty(SERVER_DB_NAME_KEY);
+  }
+
   public String getDatabaseUser() {
     return properties.getProperty(SERVER_JDBC_USER_NAME_KEY, SERVER_JDBC_USER_NAME_DEFAULT);
   }

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/ec6e76fe/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
index 5f325b5..7479cc9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
@@ -114,7 +114,7 @@ public class ControllerModule extends AbstractModule {
         properties.put("javax.persistence.jdbc.driver", configuration.getDatabaseDriver());
         break;
       case LOCAL:
-        properties.put("javax.persistence.jdbc.url", Configuration.JDBC_LOCAL_URL);
+        properties.put("javax.persistence.jdbc.url", configuration.getLocalDatabaseUrl());
         properties.put("javax.persistence.jdbc.driver", Configuration.JDBC_LOCAL_DRIVER);
         break;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/ec6e76fe/ambari-server/src/main/python/ambari-server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py
index a686dd6..9b6bc97 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -215,9 +215,9 @@ AMBARI_PROPERTIES_RPMSAVE_FILE="ambari.properties.rpmsave"
 RESOURCES_DIR_PROPERTY="resources.dir"
 
 SETUP_DB_CMD = ['su', '-', 'postgres',
-        '--command=psql -f {0} -v username=\'"{1}"\' -v password="\'{2}\'"']
+        '--command=psql -f {0} -v username=\'"{1}"\' -v password="\'{2}\'" -v dbname="{3}"']
 UPGRADE_STACK_CMD = ['su', 'postgres',
-        '--command=psql -f {0} -v stack_name="\'{1}\'"  -v stack_version="\'{2}\'"']
+        '--command=psql -f {0} -v stack_name="\'{1}\'"  -v stack_version="\'{2}\'" -v dbname="{3}']
 UPDATE_METAINFO_CMD = 'curl -X PUT "http://{0}:{1}/api/v1/stacks2" -u "{2}":"{3}"'
 PG_ST_CMD = "/sbin/service postgresql status"
 PG_INITDB_CMD = "/sbin/service postgresql initdb"
@@ -872,8 +872,11 @@ def setup_db(args):
   scriptFile = args.init_script_file
   username = args.database_username
   password = args.database_password
+
+  #setup DB
   command = SETUP_DB_CMD[:]
-  command[-1] = command[-1].format(scriptFile, username, password)
+  command[-1] = command[-1].format(scriptFile, username, password, dbname)
+
   retcode, outdata, errdata = run_os_command(command)
   if not retcode == 0:
     print errdata
@@ -914,7 +917,7 @@ def execute_db_script(args, file):
   username = args.database_username
   password = args.database_password
   command = SETUP_DB_CMD[:]
-  command[-1] = command[-1].format(file, username, password)
+  command[-1] = command[-1].format(file, username, password, dbname)
   retcode, outdata, errdata = run_os_command(command)
   if not retcode == 0:
     print errdata
@@ -928,7 +931,7 @@ def check_db_consistency(args, file):
   username = args.database_username
   password = args.database_password
   command = SETUP_DB_CMD[:]
-  command[-1] = command[-1].format(file, username, password)
+  command[-1] = command[-1].format(file, username, password, dbname)
   retcode, outdata, errdata = run_os_command(command)
   if not retcode == 0:
     print errdata
@@ -1329,6 +1332,25 @@ def configure_database_username_password(args):
   else:
     print_error_msg("Connection properties not set in config file.")
 
+# Check if jdbc user is changed
+def is_jdbc_user_changed(args):
+  properties = get_ambari_properties()
+  if properties == -1:
+    print_error_msg ("Error getting ambari properties")
+    return None
+
+  previos_user = properties[JDBC_USER_NAME_PROPERTY]
+  new_user = args.database_username
+
+  if previos_user and new_user:
+    if previos_user != new_user:
+      return True
+  else:
+    print_error_msg("Connection properties not set in config file.")
+    return None
+
+  return False
+
 # Store local database connection properties
 def store_local_properties(args):
   properties = get_ambari_properties()
@@ -1340,15 +1362,14 @@ def store_local_properties(args):
 
   properties.removeOldProp(JDBC_SCHEMA_PROPERTY)
   properties.removeOldProp(JDBC_HOSTNAME_PROPERTY)
-  properties.removeOldProp(JDBC_DATABASE_PROPERTY)
   properties.removeOldProp(JDBC_RCA_DRIVER_PROPERTY)
   properties.removeOldProp(JDBC_RCA_URL_PROPERTY)
   properties.removeOldProp(JDBC_PORT_PROPERTY)
-  properties.removeOldProp(JDBC_PORT_PROPERTY)
   properties.removeOldProp(JDBC_DRIVER_PROPERTY)
   properties.removeOldProp(JDBC_URL_PROPERTY)
-  properties.removeOldProp(JDBC_DATABASE_PROPERTY)
+  #properties.removeOldProp(JDBC_DATABASE_PROPERTY)
   properties.process_pair(PERSISTENCE_TYPE_PROPERTY, "local")
+  properties.process_pair(JDBC_DATABASE_PROPERTY, args.database_name)
   properties.process_pair(JDBC_USER_NAME_PROPERTY, args.database_username)
   properties.process_pair(JDBC_PASSWORD_PROPERTY,
       store_password_file(args.database_password, JDBC_PASSWORD_FILENAME))
@@ -1408,7 +1429,7 @@ def parse_properties_file(args):
       pass
 
   args.database_username = properties[JDBC_USER_NAME_PROPERTY]
-
+  args.database_name = properties[JDBC_DATABASE_PROPERTY]
   args.database_password_file = properties[JDBC_PASSWORD_PROPERTY]
   if args.database_password_file:
     if not is_alias_string(args.database_password_file):
@@ -1727,9 +1748,6 @@ def install_jdk(dest_file):
     raise FatalException(retcode, err)
   return out, ok
 
-
-
-
 #
 # Configures the OS settings in ambari properties.
 #
@@ -1799,8 +1817,7 @@ def find_jdk():
 def is_local_database(options):
   if options.database == DATABASE_NAMES[0] \
     and options.database_host == "localhost" \
-    and options.database_port == DATABASE_PORTS[0] \
-    and options.database_name == "ambari":
+    and options.database_port == DATABASE_PORTS[0]:
     return True
   return False
 
@@ -1948,6 +1965,9 @@ def setup(args):
   #DB setup should be done last after doing any setup.
   
   if is_local_database(args):
+    #check if jdbc user is changed
+    is_user_changed = is_jdbc_user_changed(args)
+
     print 'Default properties detected. Using built-in database.'
     store_local_properties(args)
 
@@ -1963,6 +1983,10 @@ def setup(args):
       err = 'Running database init script was failed. Exiting.'
       raise FatalException(retcode, err)
 
+    if is_user_changed:
+      #remove backup for pg_hba in order to reconfigure postgres
+      remove_file(PG_HBA_CONF_FILE_BACKUP)
+
     print 'Configuring PostgreSQL...'
     retcode = configure_postgres()
     if not retcode == 0:
@@ -1988,8 +2012,6 @@ def setup(args):
       raise FatalException(retcode, err)
     check_jdbc_drivers(args)
 
-
-
 #
 # Resets the Ambari Server.
 #
@@ -2070,7 +2092,7 @@ def reset(args):
     username = args.database_username
     password = args.database_password
     command = SETUP_DB_CMD[:]
-    command[-1] = command[-1].format(filename, username, password)
+    command[-1] = command[-1].format(filename, username, password, dbname)
     retcode, outdata, errdata = run_os_command(command)
     if not retcode == 0:
       raise FatalException(1, errdata)
@@ -2238,7 +2260,7 @@ def upgrade_stack(args, stack_id):
   file = args.upgrade_stack_script_file
   stack_name, stack_version = stack_id.split(STACK_NAME_VER_SEP)
   command = UPGRADE_STACK_CMD[:]
-  command[-1] = command[-1].format(file, stack_name, stack_version)
+  command[-1] = command[-1].format(file, stack_name, stack_version, dbname)
   retcode, outdata, errdata = run_os_command(command)
   if not retcode == 0:
     raise FatalException(retcode, errdata)

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/ec6e76fe/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index 471e385..551827f 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -15,90 +15,74 @@
 -- See the License for the specific language governing permissions and
 -- limitations under the License.
 --
-CREATE DATABASE ambari;
-
-\connect ambari;
-
-ALTER USER :username WITH ENCRYPTED PASSWORD :password;
+CREATE DATABASE :dbname;
+\connect :dbname;
 
+ALTER ROLE :username LOGIN ENCRYPTED PASSWORD :password;
 CREATE ROLE :username LOGIN ENCRYPTED PASSWORD :password;
 
-CREATE SCHEMA ambari
-  AUTHORIZATION :username;
+GRANT ALL PRIVILEGES ON DATABASE :dbname TO :username;
 
-ALTER ROLE :username SET search_path to 'ambari';
+CREATE SCHEMA ambari AUTHORIZATION :username;
+ALTER SCHEMA ambari OWNER TO :username;
+ALTER ROLE :username SET search_path TO 'ambari';
 
+------create tables ang grant privileges to db user---------
 CREATE TABLE ambari.clusters (cluster_id BIGINT NOT NULL, cluster_info VARCHAR(255) NOT NULL,
cluster_name VARCHAR(100) NOT NULL UNIQUE, desired_cluster_state VARCHAR(255) NOT NULL, desired_stack_version
VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id));
-
 GRANT ALL PRIVILEGES ON TABLE ambari.clusters TO :username;
 
 CREATE TABLE ambari.clusterconfig (version_tag VARCHAR(255) NOT NULL, type_name VARCHAR(255)
NOT NULL, cluster_id BIGINT NOT NULL, config_data VARCHAR(32000) NOT NULL, create_timestamp
BIGINT NOT NULL, PRIMARY KEY (cluster_id, type_name, version_tag));
-
 GRANT ALL PRIVILEGES ON TABLE ambari.clusterconfig TO :username;
 
-CREATE TABLE ambari.clusterconfigmapping (cluster_id bigint NOT NULL, type_name VARCHAR(255)
NOT NULL, version_tag VARCHAR(255) NOT NULL, create_timestamp BIGINT NOT NULL, selected INTEGER
NOT NULL DEFAULT 0, user_name VARCHAR(255) NOT NULL DEFAULT '_db', PRIMARY KEY (cluster_id,
type_name, create_timestamp));
-
+CREATE TABLE ambari.clusterconfigmapping (cluster_id BIGINT NOT NULL, type_name VARCHAR(255)
NOT NULL, version_tag VARCHAR(255) NOT NULL, create_timestamp BIGINT NOT NULL, selected INTEGER
NOT NULL DEFAULT 0, user_name VARCHAR(255) NOT NULL DEFAULT '_db', PRIMARY KEY (cluster_id,
type_name, create_timestamp));
 GRANT ALL PRIVILEGES ON TABLE ambari.clusterconfigmapping TO :username;
 
 CREATE TABLE ambari.clusterservices (service_name VARCHAR(255) NOT NULL, cluster_id BIGINT
NOT NULL, service_enabled INTEGER NOT NULL, PRIMARY KEY (service_name, cluster_id));
-
 GRANT ALL PRIVILEGES ON TABLE ambari.clusterservices TO :username;
 
 CREATE TABLE ambari.clusterstate (cluster_id BIGINT NOT NULL, current_cluster_state VARCHAR(255)
NOT NULL, current_stack_version VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id));
-
 GRANT ALL PRIVILEGES ON TABLE ambari.clusterstate TO :username;
 
 CREATE TABLE ambari.componentconfigmapping (cluster_id BIGINT NOT NULL, component_name VARCHAR(255)
NOT NULL, service_name VARCHAR(255) NOT NULL, config_type VARCHAR(255) NOT NULL, timestamp
BIGINT NOT NULL, config_tag VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, component_name,
service_name, config_type));
-
 GRANT ALL PRIVILEGES ON TABLE ambari.componentconfigmapping TO :username;
 
 CREATE TABLE ambari.hostcomponentconfigmapping (cluster_id BIGINT NOT NULL, component_name
VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL,
config_type VARCHAR(255) NOT NULL, timestamp BIGINT NOT NULL, config_tag VARCHAR(255) NOT
NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name, config_type));
-
 GRANT ALL PRIVILEGES ON TABLE ambari.hostcomponentconfigmapping TO :username;
 
 CREATE TABLE ambari.hcdesiredconfigmapping (cluster_id BIGINT NOT NULL, component_name VARCHAR(255)
NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, config_type
VARCHAR(255) NOT NULL, timestamp BIGINT NOT NULL, config_tag VARCHAR(255) NOT NULL, PRIMARY
KEY (cluster_id, component_name, host_name, service_name, config_type));
-
 GRANT ALL PRIVILEGES ON TABLE ambari.hcdesiredconfigmapping TO :username;
 
 CREATE TABLE ambari.hostcomponentdesiredstate (cluster_id BIGINT NOT NULL, component_name
VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255)
NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY
(cluster_id, component_name, host_name, service_name));
-
 GRANT ALL PRIVILEGES ON TABLE ambari.hostcomponentdesiredstate TO :username;
 
 CREATE TABLE ambari.hostcomponentstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255)
NOT NULL, current_stack_version VARCHAR(255) NOT NULL, current_state VARCHAR(255) NOT NULL,
host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id,
component_name, host_name, service_name));
-
 GRANT ALL PRIVILEGES ON TABLE ambari.hostcomponentstate TO :username;
 
 CREATE TABLE ambari.hosts (host_name VARCHAR(255) NOT NULL, cpu_count INTEGER NOT NULL, ph_cpu_count
INTEGER, cpu_info VARCHAR(255) NOT NULL, discovery_status VARCHAR(2000) NOT NULL, disks_info
VARCHAR(10000) NOT NULL, host_attributes VARCHAR(20000) NOT NULL, ipv4 VARCHAR(255), ipv6
VARCHAR(255), public_host_name VARCHAR(255), last_registration_time BIGINT NOT NULL, os_arch
VARCHAR(255) NOT NULL, os_info VARCHAR(1000) NOT NULL, os_type VARCHAR(255) NOT NULL, rack_info
VARCHAR(255) NOT NULL, total_mem BIGINT NOT NULL, PRIMARY KEY (host_name));
-
 GRANT ALL PRIVILEGES ON TABLE ambari.hosts TO :username;
 
-CREATE TABLE ambari.hoststate (agent_version VARCHAR(255) NOT NULL, available_mem BIGINT
NOT NULL, current_state VARCHAR(255) NOT NULL, health_status VARCHAR(255), host_name VARCHAR(255)
NOT NULL, time_in_state BIGINT NOT NULL,  PRIMARY KEY (host_name));
-
+CREATE TABLE ambari.hoststate (agent_version VARCHAR(255) NOT NULL, available_mem BIGINT
NOT NULL, current_state VARCHAR(255) NOT NULL, health_status VARCHAR(255), host_name VARCHAR(255)
NOT NULL, time_in_state BIGINT NOT NULL, PRIMARY KEY (host_name));
 GRANT ALL PRIVILEGES ON TABLE ambari.hoststate TO :username;
 
 CREATE TABLE ambari.servicecomponentdesiredstate (component_name VARCHAR(255) NOT NULL, cluster_id
BIGINT NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT
NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (component_name, cluster_id, service_name));
-
 GRANT ALL PRIVILEGES ON TABLE ambari.servicecomponentdesiredstate TO :username;
 
 CREATE TABLE ambari.serviceconfigmapping (cluster_id BIGINT NOT NULL, service_name VARCHAR(255)
NOT NULL, config_type VARCHAR(255) NOT NULL, timestamp BIGINT NOT NULL, config_tag VARCHAR(255)
NOT NULL, PRIMARY KEY (cluster_id, service_name, config_type));
-
 GRANT ALL PRIVILEGES ON TABLE ambari.serviceconfigmapping TO :username;
 
 CREATE TABLE ambari.servicedesiredstate (cluster_id BIGINT NOT NULL, desired_host_role_mapping
INTEGER NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255)
NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, service_name));
-
 GRANT ALL PRIVILEGES ON TABLE ambari.servicedesiredstate TO :username;
 
 CREATE TABLE ambari.roles (role_name VARCHAR(255) NOT NULL, PRIMARY KEY (role_name));
-
 GRANT ALL PRIVILEGES ON TABLE ambari.roles TO :username;
 
 CREATE TABLE ambari.users (user_id INTEGER, ldap_user INTEGER NOT NULL DEFAULT 0, user_name
VARCHAR(255) NOT NULL, create_time TIMESTAMP DEFAULT NOW(), user_password VARCHAR(255), PRIMARY
KEY (user_id), UNIQUE (ldap_user, user_name));
 GRANT ALL PRIVILEGES ON TABLE ambari.users TO :username;
 
-CREATE TABLE ambari.execution_command (command bytea, task_id BIGINT NOT NULL, PRIMARY KEY
(task_id));
+CREATE TABLE ambari.execution_command (command BYTEA, task_id BIGINT NOT NULL, PRIMARY KEY
(task_id));
 GRANT ALL PRIVILEGES ON TABLE ambari.execution_command TO :username;
 
-CREATE TABLE ambari.host_role_command (task_id BIGINT NOT NULL, attempt_count SMALLINT NOT
NULL, event VARCHAR(32000) NOT NULL, exitcode INTEGER NOT NULL, host_name VARCHAR(255) NOT
NULL, last_attempt_time BIGINT NOT NULL, request_id BIGINT NOT NULL, role VARCHAR(255), stage_id
BIGINT NOT NULL, start_time BIGINT NOT NULL, status VARCHAR(255), std_error bytea, std_out
bytea, role_command VARCHAR(255), PRIMARY KEY (task_id));
+CREATE TABLE ambari.host_role_command (task_id BIGINT NOT NULL, attempt_count SMALLINT NOT
NULL, event VARCHAR(32000) NOT NULL, exitcode INTEGER NOT NULL, host_name VARCHAR(255) NOT
NULL, last_attempt_time BIGINT NOT NULL, request_id BIGINT NOT NULL, role VARCHAR(255), stage_id
BIGINT NOT NULL, start_time BIGINT NOT NULL, status VARCHAR(255), std_error BYTEA, std_out
BYTEA, role_command VARCHAR(255), PRIMARY KEY (task_id));
 GRANT ALL PRIVILEGES ON TABLE ambari.host_role_command TO :username;
 
 CREATE TABLE ambari.role_success_criteria (role VARCHAR(255) NOT NULL, request_id BIGINT
NOT NULL, stage_id BIGINT NOT NULL, success_factor FLOAT NOT NULL, PRIMARY KEY (role, request_id,
stage_id));
@@ -113,20 +97,19 @@ GRANT ALL PRIVILEGES ON TABLE ambari.ClusterHostMapping TO :username;
 CREATE TABLE ambari.user_roles (role_name VARCHAR(255) NOT NULL, user_id INTEGER NOT NULL,
PRIMARY KEY (role_name, user_id));
 GRANT ALL PRIVILEGES ON TABLE ambari.user_roles TO :username;
 
-CREATE TABLE ambari.key_value_store ("key" VARCHAR(255), "value" VARCHAR, PRIMARY KEY("key"));
+CREATE TABLE ambari.key_value_store ("key" VARCHAR(255), "value" VARCHAR, PRIMARY KEY ("key"));
 GRANT ALL PRIVILEGES ON TABLE ambari.key_value_store TO :username;
 
-CREATE TABLE ambari.hostconfigmapping (cluster_id bigint NOT NULL, host_name VARCHAR(255)
NOT NULL, type_name VARCHAR(255) NOT NULL, version_tag VARCHAR(255) NOT NULL, service_name
VARCHAR(255), create_timestamp BIGINT NOT NULL, selected INTEGER NOT NULL DEFAULT 0, user_name
VARCHAR(255) NOT NULL DEFAULT '_db', PRIMARY KEY (cluster_id, host_name, type_name, create_timestamp));
-
+CREATE TABLE ambari.hostconfigmapping (cluster_id BIGINT NOT NULL, host_name VARCHAR(255)
NOT NULL, type_name VARCHAR(255) NOT NULL, version_tag VARCHAR(255) NOT NULL, service_name
VARCHAR(255), create_timestamp BIGINT NOT NULL, selected INTEGER NOT NULL DEFAULT 0, user_name
VARCHAR(255) NOT NULL DEFAULT '_db', PRIMARY KEY (cluster_id, host_name, type_name, create_timestamp));
 GRANT ALL PRIVILEGES ON TABLE ambari.hostconfigmapping TO :username;
 
-CREATE TABLE ambari.metainfo ("metainfo_key" VARCHAR(255), "metainfo_value" VARCHAR, PRIMARY
KEY("metainfo_key"));
+CREATE TABLE ambari.metainfo ("metainfo_key" VARCHAR(255), "metainfo_value" VARCHAR, PRIMARY
KEY ("metainfo_key"));
 GRANT ALL PRIVILEGES ON TABLE ambari.metainfo TO :username;
 
 CREATE TABLE ambari.ambari_sequences (sequence_name VARCHAR(255) PRIMARY KEY, "value" BIGINT
NOT NULL);
 GRANT ALL PRIVILEGES ON TABLE ambari.ambari_sequences TO :username;
 
-
+--------altering tables by creating foreign keys----------
 ALTER TABLE ambari.clusterconfig ADD CONSTRAINT FK_clusterconfig_cluster_id FOREIGN KEY (cluster_id)
REFERENCES ambari.clusters (cluster_id);
 ALTER TABLE ambari.clusterservices ADD CONSTRAINT FK_clusterservices_cluster_id FOREIGN KEY
(cluster_id) REFERENCES ambari.clusters (cluster_id);
 ALTER TABLE ambari.clusterconfigmapping ADD CONSTRAINT FK_clusterconfigmapping_cluster_id
FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id);
@@ -158,141 +141,135 @@ ALTER TABLE ambari.user_roles ADD CONSTRAINT FK_user_roles_role_name
FOREIGN KEY
 ALTER TABLE ambari.hostconfigmapping ADD CONSTRAINT FK_hostconfigmapping_cluster_id FOREIGN
KEY (cluster_id) REFERENCES ambari.clusters (cluster_id);
 ALTER TABLE ambari.hostconfigmapping ADD CONSTRAINT FK_hostconfigmapping_host_name FOREIGN
KEY (host_name) REFERENCES ambari.hosts (host_name);
 
+---------inserting some data-----------
 BEGIN;
-
-insert into ambari.ambari_sequences(sequence_name, "value")
-select 'cluster_id_seq', 1
-union all
-select 'user_id_seq', 2
-union all
-select 'host_role_command_id_seq', 1;
-
-insert into ambari.Roles(role_name)
-select 'admin'
-union all
-select 'user';
-
-insert into ambari.Users(user_id, user_name, user_password)
-select 1,'admin','538916f8943ec225d97a9a86a2c6ec0818c1cd400e09e03b660fdaaec4af29ddbb6f2b1033b81b00';
-
-insert into ambari.user_roles(role_name, user_id)
-select 'admin',1;
-
-insert into ambari.metainfo(metainfo_key, metainfo_value)
-select 'version','${ambariVersion}';
-
+  INSERT INTO ambari.ambari_sequences (sequence_name, "value")
+  SELECT 'cluster_id_seq', 1
+  UNION ALL
+  SELECT 'user_id_seq', 2
+  UNION ALL
+  SELECT 'host_role_command_id_seq', 1;
+
+  INSERT INTO ambari.Roles (role_name)
+  SELECT 'admin'
+  UNION ALL
+  SELECT 'user';
+
+  INSERT INTO ambari.Users (user_id, user_name, user_password)
+  SELECT 1, 'admin', '538916f8943ec225d97a9a86a2c6ec0818c1cd400e09e03b660fdaaec4af29ddbb6f2b1033b81b00';
+
+  INSERT INTO ambari.user_roles (role_name, user_id)
+  SELECT 'admin', 1;
+
+  INSERT INTO ambari.metainfo (metainfo_key, metainfo_value)
+  SELECT 'version', '${ambariVersion}';
 COMMIT;
 
+
 -- ambari log4j DDL
 
+--------------------------------------------------
+----------initialisation of mapred db-------------
+--------------------------------------------------
 CREATE DATABASE ambarirca;
-
 \connect ambarirca;
 
+--CREATE ROLE "mapred" LOGIN ENCRYPTED PASSWORD 'mapred';
 CREATE USER "mapred" WITH PASSWORD 'mapred';
-
 GRANT ALL PRIVILEGES ON DATABASE ambarirca TO "mapred";
 
+------create tables ang grant privileges to db user---------
 CREATE TABLE workflow (
-  workflowId TEXT, workflowName TEXT,
-  parentWorkflowId TEXT,  
-  workflowContext TEXT, userName TEXT,
-  startTime BIGINT, lastUpdateTime BIGINT,
-  numJobsTotal INTEGER, numJobsCompleted INTEGER,
-  inputBytes BIGINT, outputBytes BIGINT,
-  duration BIGINT, workflowTags TEXT,
+  workflowId       TEXT, workflowName TEXT,
+  parentWorkflowId TEXT,
+  workflowContext  TEXT, userName TEXT,
+  startTime        BIGINT, lastUpdateTime BIGINT,
+  numJobsTotal     INTEGER, numJobsCompleted INTEGER,
+  inputBytes       BIGINT, outputBytes BIGINT,
+  duration         BIGINT, workflowTags TEXT,
   PRIMARY KEY (workflowId),
-  FOREIGN KEY (parentWorkflowId) REFERENCES workflow(workflowId)
+  FOREIGN KEY (parentWorkflowId) REFERENCES workflow (workflowId)
 );
-
 GRANT ALL PRIVILEGES ON TABLE workflow TO "mapred";
 
 CREATE TABLE application (
-  appId TEXT,
-  workflowId TEXT,
-  appName TEXT,
+  appId              TEXT,
+  workflowId         TEXT,
+  appName            TEXT,
   workflowEntityName TEXT,
-  userName TEXT, queue TEXT,
-  submitTime BIGINT, launchTime BIGINT, finishTime BIGINT,
-  appType TEXT,
-  status TEXT,
-  appInfo TEXT,
-  PRIMARY KEY(appId), FOREIGN KEY(workflowId) REFERENCES workflow(workflowId)
+  userName           TEXT, queue TEXT,
+  submitTime         BIGINT, launchTime BIGINT, finishTime BIGINT,
+  appType            TEXT,
+  status             TEXT,
+  appInfo            TEXT,
+  PRIMARY KEY (appId), FOREIGN KEY (workflowId) REFERENCES workflow (workflowId)
 );
-
 GRANT ALL PRIVILEGES ON TABLE application TO "mapred";
 
 CREATE TABLE job (
-  jobId TEXT, workflowId TEXT, jobName TEXT, workflowEntityName TEXT,
-  userName TEXT, queue TEXT, acls TEXT, confPath TEXT, 
-  submitTime BIGINT, launchTime BIGINT, finishTime BIGINT, 
-  maps INTEGER, reduces INTEGER, status TEXT, priority TEXT, 
-  finishedMaps INTEGER, finishedReduces INTEGER, 
-  failedMaps INTEGER, failedReduces INTEGER, 
-  mapsRuntime BIGINT, reducesRuntime BIGINT,
-  mapCounters TEXT, reduceCounters TEXT, jobCounters TEXT, 
-  inputBytes BIGINT, outputBytes BIGINT,
-  PRIMARY KEY(jobId),
-  FOREIGN KEY(workflowId) REFERENCES workflow(workflowId)
+  jobId        TEXT, workflowId TEXT, jobName TEXT, workflowEntityName TEXT,
+  userName     TEXT, queue TEXT, acls TEXT, confPath TEXT,
+  submitTime   BIGINT, launchTime BIGINT, finishTime BIGINT,
+  maps         INTEGER, reduces INTEGER, status TEXT, priority TEXT,
+  finishedMaps INTEGER, finishedReduces INTEGER,
+  failedMaps   INTEGER, failedReduces INTEGER,
+  mapsRuntime  BIGINT, reducesRuntime BIGINT,
+  mapCounters  TEXT, reduceCounters TEXT, jobCounters TEXT,
+  inputBytes   BIGINT, outputBytes BIGINT,
+  PRIMARY KEY (jobId),
+  FOREIGN KEY (workflowId) REFERENCES workflow (workflowId)
 );
-
 GRANT ALL PRIVILEGES ON TABLE job TO "mapred";
 
 CREATE TABLE task (
-  taskId TEXT, jobId TEXT, taskType TEXT, splits TEXT, 
-  startTime BIGINT, finishTime BIGINT, status TEXT, error TEXT, counters TEXT, 
-  failedAttempt TEXT, 
-  PRIMARY KEY(taskId), 
-  FOREIGN KEY(jobId) REFERENCES job(jobId)
+  taskId        TEXT, jobId TEXT, taskType TEXT, splits TEXT,
+  startTime     BIGINT, finishTime BIGINT, status TEXT, error TEXT, counters TEXT,
+  failedAttempt TEXT,
+  PRIMARY KEY (taskId),
+  FOREIGN KEY (jobId) REFERENCES job (jobId)
 );
-
 GRANT ALL PRIVILEGES ON TABLE task TO "mapred";
 
 CREATE TABLE taskAttempt (
-  taskAttemptId TEXT, taskId TEXT, jobId TEXT, taskType TEXT, taskTracker TEXT, 
-  startTime BIGINT, finishTime BIGINT, 
-  mapFinishTime BIGINT, shuffleFinishTime BIGINT, sortFinishTime BIGINT, 
-  locality TEXT, avataar TEXT, 
-  status TEXT, error TEXT, counters TEXT, 
-  inputBytes BIGINT, outputBytes BIGINT,
-  PRIMARY KEY(taskAttemptId), 
-  FOREIGN KEY(jobId) REFERENCES job(jobId), 
-  FOREIGN KEY(taskId) REFERENCES task(taskId)
-); 
-
+  taskAttemptId TEXT, taskId TEXT, jobId TEXT, taskType TEXT, taskTracker TEXT,
+  startTime     BIGINT, finishTime BIGINT,
+  mapFinishTime BIGINT, shuffleFinishTime BIGINT, sortFinishTime BIGINT,
+  locality      TEXT, avataar TEXT,
+  status        TEXT, error TEXT, counters TEXT,
+  inputBytes    BIGINT, outputBytes BIGINT,
+  PRIMARY KEY (taskAttemptId),
+  FOREIGN KEY (jobId) REFERENCES job (jobId),
+  FOREIGN KEY (taskId) REFERENCES task (taskId)
+);
 GRANT ALL PRIVILEGES ON TABLE taskAttempt TO "mapred";
 
 CREATE TABLE hdfsEvent (
-  timestamp BIGINT,
-  userName TEXT,
-  clientIP TEXT,
-  operation TEXT,
-  srcPath TEXT,
-  dstPath TEXT,
+  timestamp   BIGINT,
+  userName    TEXT,
+  clientIP    TEXT,
+  operation   TEXT,
+  srcPath     TEXT,
+  dstPath     TEXT,
   permissions TEXT
 );
-
 GRANT ALL PRIVILEGES ON TABLE hdfsEvent TO "mapred";
 
 CREATE TABLE mapreduceEvent (
-  timestamp BIGINT,
-  userName TEXT,
-  clientIP TEXT,
-  operation TEXT,
-  target TEXT,
-  result TEXT,
+  timestamp   BIGINT,
+  userName    TEXT,
+  clientIP    TEXT,
+  operation   TEXT,
+  target      TEXT,
+  result      TEXT,
   description TEXT,
   permissions TEXT
 );
-
 GRANT ALL PRIVILEGES ON TABLE mapreduceEvent TO "mapred";
 
 CREATE TABLE clusterEvent (
-  timestamp BIGINT, 
-  service TEXT, status TEXT, 
-  error TEXT, data TEXT , 
-  host TEXT, rack TEXT
+  timestamp BIGINT,
+  service   TEXT, status TEXT,
+  error     TEXT, data TEXT,
+  host      TEXT, rack TEXT
 );
-
-GRANT ALL PRIVILEGES ON TABLE clusterEvent TO "mapred";
-
+GRANT ALL PRIVILEGES ON TABLE clusterEvent TO "mapred";
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/ec6e76fe/ambari-server/src/main/resources/Ambari-DDL-Postgres-DROP.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-DROP.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-DROP.sql
index da7ed92..ffd942a 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-DROP.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-DROP.sql
@@ -15,5 +15,5 @@
 -- See the License for the specific language governing permissions and
 -- limitations under the License.
 --
-drop database ambari;
-drop database ambarirca;
+DROP DATABASE IF EXISTS :dbname;
+DROP DATABASE IF EXISTS ambarirca;

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/ec6e76fe/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.Check.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.Check.sql
b/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.Check.sql
index 185810a..4065f01 100644
--- a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.Check.sql
+++ b/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.Check.sql
@@ -15,6 +15,6 @@
 -- See the License for the specific language governing permissions and
 -- limitations under the License.
 --
-\connect ambari;
+\connect :dbname;
 
 COPY (SELECT count(*) FROM ambari.serviceconfigmapping WHERE service_name = 'MAPREDUCE')
TO STDOUT WITH CSV;

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/ec6e76fe/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.Fix.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.Fix.sql
b/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.Fix.sql
index 61677b2..6d4d4e6 100644
--- a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.Fix.sql
+++ b/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.Fix.sql
@@ -15,7 +15,7 @@
 -- See the License for the specific language governing permissions and
 -- limitations under the License.
 --
-\connect ambari;
+\connect :dbname;
 
 INSERT INTO ambari.serviceconfigmapping (cluster_id, service_name, config_type, config_tag,
timestamp)
     SELECT cluster_id, 'MAPREDUCE', type_name, version_tag, create_timestamp from ambari.clusterconfig


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/ec6e76fe/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
b/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
index 431a6a3..9d1277c 100644
--- a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
+++ b/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
@@ -15,7 +15,7 @@
 -- See the License for the specific language governing permissions and
 -- limitations under the License.
 --
-\connect ambari;
+\connect :dbname;
 
 -- Upgrade from 1.2.0
 ALTER TABLE ambari.hosts

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/ec6e76fe/ambari-server/src/main/resources/upgrade/dml/Ambari-DML-Postgres-UPGRADE_STACK.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/upgrade/dml/Ambari-DML-Postgres-UPGRADE_STACK.sql
b/ambari-server/src/main/resources/upgrade/dml/Ambari-DML-Postgres-UPGRADE_STACK.sql
index 5e00413..ce131c8 100644
--- a/ambari-server/src/main/resources/upgrade/dml/Ambari-DML-Postgres-UPGRADE_STACK.sql
+++ b/ambari-server/src/main/resources/upgrade/dml/Ambari-DML-Postgres-UPGRADE_STACK.sql
@@ -15,7 +15,7 @@
 -- See the License for the specific language governing permissions and
 -- limitations under the License.
 --
-\connect ambari;
+\connect :dbname;
 
 PREPARE clusters (text, text) AS
   UPDATE ambari.clusters

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/ec6e76fe/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
index e5d5bfb..a46ec25 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
@@ -184,4 +184,12 @@ public class ConfigurationTest {
     Assert.assertEquals("mapred", conf.getRcaDatabasePassword());
   }
 
+  @Test
+  public void testGetLocalDatabaseUrl() {
+    Properties ambariProperties = new Properties();
+    ambariProperties.setProperty("server.jdbc.database", "ambaritestdatabase");
+    Configuration conf = new Configuration(ambariProperties);
+    Assert.assertEquals(conf.getLocalDatabaseUrl(), Configuration.JDBC_LOCAL_URL.concat("ambaritestdatabase"));
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/ec6e76fe/ambari-server/src/test/python/TestAmbaryServer.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestAmbaryServer.py b/ambari-server/src/test/python/TestAmbaryServer.py
index 345f034..5fb83f0 100644
--- a/ambari-server/src/test/python/TestAmbaryServer.py
+++ b/ambari-server/src/test/python/TestAmbaryServer.py
@@ -1774,6 +1774,8 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     self.assertNotEqual(None, result)
 
   @patch("os.path.exists")
+  @patch.object(ambari_server, "remove_file")
+  @patch.object(ambari_server, "is_jdbc_user_changed")
   @patch.object(ambari_server, 'verify_setup_allowed')
   @patch.object(ambari_server, "get_YN_input")
   @patch.object(ambari_server, "configure_os_settings")
@@ -1794,13 +1796,16 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
                  setup_remote_db_mock, check_selinux_mock, check_jdbc_drivers_mock, check_ambari_user_mock,
                  check_iptables_mock, check_postgre_up_mock, setup_db_mock, configure_postgres_mock,
                  download_jdk_mock, configure_os_settings_mock,get_YN_input,
-                 verify_setup_allowed_method, exists_mock):
+                 verify_setup_allowed_method, is_jdbc_user_changed_mock, remove_file_mock,
exists_mock):
     args = MagicMock()
     failed = False
     get_YN_input.return_value = False
     verify_setup_allowed_method.return_value = 0
     exists_mock.return_value = False
+    remove_file_mock.return_value = 0
+
     def reset_mocks():
+      is_jdbc_user_changed_mock.reset_mock()
       is_root_mock.reset_mock()
       store_local_properties_mock.reset_mock()
       store_remote_properties_mock.reset_mock()
@@ -1813,7 +1818,6 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
       check_postgre_up_mock.reset_mock()
       setup_db_mock.reset_mock()
       configure_postgres_mock.reset_mock()
-      download_jdk_mock.reset_mock()
       configure_os_settings_mock.reset_mock()
       pass
 
@@ -1856,6 +1860,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     #Local case
     reset_mocks()
     is_local_database_mock.return_value = True
+    is_jdbc_user_changed_mock.return_value = False
 
     try:
       result = ambari_server.setup(args)
@@ -1864,6 +1869,23 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     self.assertEqual(None, result)
     self.assertEquals(True, store_local_properties_mock.called)
     self.assertEquals(False, store_remote_properties_mock.called)
+    self.assertEquals(True, is_jdbc_user_changed_mock.called)
+    self.assertEquals(False, remove_file_mock.called)
+
+    #if DB user name was changed
+    reset_mocks()
+    is_local_database_mock.return_value = True
+    is_jdbc_user_changed_mock.return_value = True
+
+    try:
+      result = ambari_server.setup(args)
+    except FatalException:
+      self.fail("Setup should be successful")
+    self.assertEqual(None, result)
+    self.assertEquals(True, store_local_properties_mock.called)
+    self.assertEquals(False, store_remote_properties_mock.called)
+    self.assertEquals(True, is_jdbc_user_changed_mock.called)
+    self.assertEquals(True, remove_file_mock.called)
 
     #negative case
     reset_mocks()
@@ -3863,3 +3885,31 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     testdir = os.path.dirname(__file__)
     return os.path.dirname(testdir) + os.sep + "resources" + os.sep \
            + 'TestAmbaryServer.samples/' + sample
+
+
+  @patch.object(ambari_server, "get_ambari_properties")
+  def test_is_jdbc_user_changed(self, get_ambari_properties_mock):
+    previous_user = "previous_user"
+    new_user = "new_user"
+    get_ambari_properties_mock.return_value = {ambari_server.JDBC_USER_NAME_PROPERTY : previous_user}
+
+    args = MagicMock()
+
+    #check if users are different
+    args.database_username = new_user
+    result = ambari_server.is_jdbc_user_changed(args)
+    self.assertEqual(args.database_username, new_user)
+    self.assertTrue(result)
+
+    #check if users are equal
+    args.database_username = previous_user
+    result = ambari_server.is_jdbc_user_changed(args)
+    self.assertEqual(args.database_username, previous_user)
+    self.assertFalse(result)
+
+    #check if one of users is None
+    args.database_username = None
+    result = ambari_server.is_jdbc_user_changed(args)
+    self.assertEqual(None, args.database_username)
+    self.assertEqual(None, result)
+


Mime
View raw message