You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2015/03/17 14:59:42 UTC

ambari git commit: AMBARI-10088. Technical debt: unit test coverage for Rolling Upgrade: Expose FinalizeUpgradeAction (dlysnichenko)

Repository: ambari
Updated Branches:
  refs/heads/trunk 966d39333 -> 9fe2741dc


AMBARI-10088. Technical debt: unit test coverage for Rolling Upgrade: Expose FinalizeUpgradeAction (dlysnichenko)


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

Branch: refs/heads/trunk
Commit: 9fe2741dcc5fbee571ca9fd67ca026c45a480433
Parents: 966d393
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Tue Mar 17 15:56:08 2015 +0200
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Tue Mar 17 15:56:08 2015 +0200

----------------------------------------------------------------------
 ambari-server/src/main/python/ambari-server.py  |   4 +-
 .../main/python/ambari_server/serverUtils.py    |   2 +-
 .../main/python/ambari_server/setupActions.py   |   2 +-
 .../src/test/python/TestServerUpgrade.py        | 100 +++++++++++++++++++
 .../src/test/python/TestServerUtils.py          |  49 +++++++++
 5 files changed, 153 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9fe2741d/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 9114abe..8b23d83 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -39,7 +39,7 @@ from ambari_server.setupHttps import setup_https
 
 from ambari_server.setupActions import BACKUP_ACTION, LDAP_SETUP_ACTION, LDAP_SYNC_ACTION, PSTART_ACTION, \
   REFRESH_STACK_HASH_ACTION, RESET_ACTION, RESTORE_ACTION, SETUP_ACTION, SETUP_SECURITY_ACTION, START_ACTION, \
-  STATUS_ACTION, STOP_ACTION, UPGRADE_ACTION, UPGRADE_STACK_ACTION, SETUP_JCE_ACTION, SET_CURRENT
+  STATUS_ACTION, STOP_ACTION, UPGRADE_ACTION, UPGRADE_STACK_ACTION, SETUP_JCE_ACTION, SET_CURRENT_ACTION
 from ambari_server.setupSecurity import setup_ldap, sync_ldap, setup_master_key, setup_ambari_krb5_jaas
 from ambari_server.userInput import get_validated_string_input
 
@@ -501,7 +501,7 @@ def create_user_action_map(args, options):
         UPGRADE_STACK_ACTION: UserActionPossibleArgs(upgrade_stack, [2, 4], args),
         LDAP_SETUP_ACTION: UserAction(setup_ldap),
         LDAP_SYNC_ACTION: UserAction(sync_ldap, options),
-        SET_CURRENT: UserAction(set_current, options),
+        SET_CURRENT_ACTION: UserAction(set_current, options),
         SETUP_SECURITY_ACTION: UserActionRestart(setup_security, options),
         REFRESH_STACK_HASH_ACTION: UserAction(refresh_stack_hash_action),
         BACKUP_ACTION: UserActionPossibleArgs(backup, [1, 2], args),

http://git-wip-us.apache.org/repos/asf/ambari/blob/9fe2741d/ambari-server/src/main/python/ambari_server/serverUtils.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/serverUtils.py b/ambari-server/src/main/python/ambari_server/serverUtils.py
index 7d76162..6466524 100644
--- a/ambari-server/src/main/python/ambari_server/serverUtils.py
+++ b/ambari-server/src/main/python/ambari_server/serverUtils.py
@@ -101,7 +101,7 @@ def refresh_stack_hash(properties):
 # Builds ambari-server API base url
 # Reads server protocol/port from configuration
 # And returns something like
-# http://127.0.0.1:8080:/api/v1/
+# http://127.0.0.1:8080/api/v1/
 #
 def get_ambari_server_api_base(properties):
   api_protocol = SERVER_API_PROTOCOL

http://git-wip-us.apache.org/repos/asf/ambari/blob/9fe2741d/ambari-server/src/main/python/ambari_server/setupActions.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/setupActions.py b/ambari-server/src/main/python/ambari_server/setupActions.py
index 0cfe1d9..6c6e7ea 100644
--- a/ambari-server/src/main/python/ambari_server/setupActions.py
+++ b/ambari-server/src/main/python/ambari_server/setupActions.py
@@ -31,7 +31,7 @@ STATUS_ACTION = "status"
 SETUP_HTTPS_ACTION = "setup-https"
 LDAP_SETUP_ACTION = "setup-ldap"
 LDAP_SYNC_ACTION = "sync-ldap"
-SET_CURRENT = "set-current"
+SET_CURRENT_ACTION = "set-current"
 SETUP_GANGLIA_HTTPS_ACTION = "setup-ganglia-https"
 ENCRYPT_PASSWORDS_ACTION = "encrypt-passwords"
 SETUP_SECURITY_ACTION = "setup-security"

http://git-wip-us.apache.org/repos/asf/ambari/blob/9fe2741d/ambari-server/src/test/python/TestServerUpgrade.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestServerUpgrade.py b/ambari-server/src/test/python/TestServerUpgrade.py
new file mode 100644
index 0000000..05b48fa
--- /dev/null
+++ b/ambari-server/src/test/python/TestServerUpgrade.py
@@ -0,0 +1,100 @@
+'''
+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.
+'''
+
+import StringIO
+import sys
+from ambari_commons.exceptions import FatalException
+from unittest import TestCase
+from mock.mock import patch, MagicMock
+from ambari_server.serverUpgrade import set_current, SetCurrentVersionOptions
+
+
+class TestServerUpgrade(TestCase):
+
+  @patch("ambari_server.serverUpgrade.is_server_runing")
+  @patch('ambari_server.serverUpgrade.SetCurrentVersionOptions.no_finalize_options_set')
+  @patch('ambari_server.serverUpgrade.get_validated_string_input')
+  @patch('ambari_server.serverUpgrade.get_ambari_properties')
+  @patch('ambari_server.serverUtils.get_ambari_server_api_base')
+  @patch('ambari_commons.logging_utils.get_verbose')
+  @patch('urllib2.urlopen')
+  def test_set_current(self, urlopen_mock, get_verbose_mock, get_ambari_server_api_base_mock,
+                       get_ambari_properties_mock, get_validated_string_input_mock,
+                       no_finalize_options_set_mock, is_server_runing_mock):
+    options = MagicMock()
+    options.cluster_name = 'cc'
+    options.desired_repo_version = 'HDP-2.2.2.0-2561'
+
+    # Case when server is not running
+    is_server_runing_mock.return_value = False, None
+    try:
+      set_current(options)
+      self.fail("Server is not running - should error out")
+    except FatalException:
+      pass  # expected
+
+
+    is_server_runing_mock.return_value = True, 11111
+
+    # Test insufficient options case
+    no_finalize_options_set_mock.return_value = True
+    try:
+      set_current(options)
+      self.fail("Should error out")
+    except FatalException:
+      pass  # expected
+
+    no_finalize_options_set_mock.return_value = False
+
+    # Test normal flow
+    get_validated_string_input_mock.return_value = 'dummy_string'
+    get_ambari_properties_mock.return_value = MagicMock()
+    get_ambari_server_api_base_mock.return_value = 'http://127.0.0.1:8080/api/v1/'
+    get_verbose_mock.retun_value = False
+
+    set_current(options)
+
+    self.assertTrue(urlopen_mock.called)
+    request = urlopen_mock.call_args_list[0][0][0]
+    self.assertEquals(request._Request__original, 'http://127.0.0.1:8080/api/v1/clusters/cc/stack_versions')
+    self.assertEquals(request.data, '{"ClusterStackVersions": {"state": "CURRENT", "repository_version": "HDP-2.2.2.0-2561"}}')
+    self.assertEquals(request.origin_req_host, '127.0.0.1')
+    self.assertEquals(request.headers, {'X-requested-by': 'ambari', 'Authorization': 'Basic ZHVtbXlfc3RyaW5nOmR1bW15X3N0cmluZw=='})
+
+
+
+  def testCurrentVersionOptions(self):
+    # Negative test cases
+    options = MagicMock()
+    options.cluster_name = None
+    options.desired_repo_version = 'HDP-2.2.2.0-2561'
+    cvo = SetCurrentVersionOptions(options)
+    self.assertTrue(cvo.no_finalize_options_set())
+
+    options = MagicMock()
+    options.cluster_name = 'cc'
+    options.desired_repo_version = None
+    cvo = SetCurrentVersionOptions(options)
+    self.assertTrue(cvo.no_finalize_options_set())
+
+    # Positive test case
+    options = MagicMock()
+    options.cluster_name = 'cc'
+    options.desired_repo_version = 'HDP-2.2.2.0-2561'
+    cvo = SetCurrentVersionOptions(options)
+    self.assertFalse(cvo.no_finalize_options_set())
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/9fe2741d/ambari-server/src/test/python/TestServerUtils.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestServerUtils.py b/ambari-server/src/test/python/TestServerUtils.py
new file mode 100644
index 0000000..a1a9ef3
--- /dev/null
+++ b/ambari-server/src/test/python/TestServerUtils.py
@@ -0,0 +1,49 @@
+'''
+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.
+'''
+
+from unittest import TestCase
+from ambari_server.serverUtils import get_ambari_server_api_base
+from ambari_server.serverConfiguration import CLIENT_API_PORT, SSL_API, DEFAULT_SSL_API_PORT, SSL_API_PORT
+
+class TestServerUtils(TestCase):
+
+  def test_get_ambari_server_api_base(self):
+
+    # Test case of using http protocol
+    properties = FakeProperties({
+      SSL_API: "false",
+    })
+    result = get_ambari_server_api_base(properties)
+    self.assertEquals(result, 'http://127.0.0.1:8080/api/v1/')
+
+    # Test case of using https protocol (and ssl port)
+    properties = FakeProperties({
+      SSL_API: "true",
+      SSL_API_PORT : "8443"
+    })
+    result = get_ambari_server_api_base(properties)
+    self.assertEquals(result, 'https://127.0.0.1:8443/api/v1/')
+
+
+
+class FakeProperties(object):
+  def __init__(self, prop_map):
+    self.prop_map = prop_map
+
+  def get_property(self, prop_name):
+    return self.prop_map[prop_name]
\ No newline at end of file