ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [15/21] ambari git commit: AMBARI-21398 Backend need to distinguish repo_version records by using the Stack Name (dgrinenko)
Date Thu, 17 Aug 2017 18:59:04 GMT
http://git-wip-us.apache.org/repos/asf/ambari/blob/33879743/ambari-server/src/test/python/custom_actions/TestRemoveStackVersion.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/custom_actions/TestRemoveStackVersion.py b/ambari-server/src/test/python/custom_actions/TestRemoveStackVersion.py
index 5a05cc2..55bf9b5 100644
--- a/ambari-server/src/test/python/custom_actions/TestRemoveStackVersion.py
+++ b/ambari-server/src/test/python/custom_actions/TestRemoveStackVersion.py
@@ -28,17 +28,20 @@ from stacks.utils.RMFTestCase import *
 OLD_VERSION_STUB = '2.1.0.0-400'
 VERSION_STUB = '2.2.0.1-885'
 
+
 @patch.object(Logger, 'logger', new=MagicMock())
 class TestRemoveStackVersion(RMFTestCase):
 
   @staticmethod
-  def _add_packages(arg):
-    arg.append(["pkg12_1_0_0_400", "1.0", "repo"])
-    arg.append(["pkg22_1_0_1_885", "2.0", "repo2"])
-    arg.append(["hdp-select2_1_0_1_885", "2.0", "repo2"])
+  def _add_packages():
+    return [
+      ["pkg12_1_0_0_400", "1.0", "repo"],
+      ["pkg22_1_0_1_885", "2.0", "repo2"],
+      ["hdp-select2_1_0_1_885", "2.0", "repo2"]
+    ]
 
   @patch("resource_management.libraries.functions.list_ambari_managed_repos.list_ambari_managed_repos")
-  @patch("resource_management.libraries.functions.packages_analyzer.allInstalledPackages")
+  @patch("resource_management.core.providers.get_provider")
   @patch("resource_management.libraries.script.Script.put_structured_out")
   @patch("resource_management.libraries.functions.stack_select.get_stack_versions")
   @patch("resource_management.libraries.functions.repo_version_history.read_actual_version_from_history_file")
@@ -49,10 +52,11 @@ class TestRemoveStackVersion(RMFTestCase):
                        write_actual_version_to_history_file_mock,
                        read_actual_version_from_history_file_mock,
                        stack_versions_mock,
-                       put_structured_out_mock, allInstalledPackages_mock, list_ambari_managed_repos_mock,
):
-
+                       put_structured_out_mock, get_provider_mock, list_ambari_managed_repos_mock):
+    m = MagicMock()
+    m.all_installed_packages.side_effect = TestRemoveStackVersion._add_packages
+    get_provider_mock.return_value = m
     stack_versions_mock.return_value = [VERSION_STUB, OLD_VERSION_STUB]
-    allInstalledPackages_mock.side_effect = TestRemoveStackVersion._add_packages
     list_ambari_managed_repos_mock.return_value = []
 
     self.executeScript("scripts/remove_previous_stacks.py",
@@ -76,7 +80,7 @@ class TestRemoveStackVersion(RMFTestCase):
     self.assertNoMoreResources()
 
   @patch("resource_management.libraries.functions.list_ambari_managed_repos.list_ambari_managed_repos")
-  @patch("resource_management.libraries.functions.packages_analyzer.allInstalledPackages")
+  @patch("resource_management.core.providers.get_provider")
   @patch("resource_management.libraries.script.Script.put_structured_out")
   @patch("resource_management.libraries.functions.stack_select.get_stack_versions")
   @patch("resource_management.libraries.functions.repo_version_history.read_actual_version_from_history_file")
@@ -87,10 +91,14 @@ class TestRemoveStackVersion(RMFTestCase):
                        write_actual_version_to_history_file_mock,
                        read_actual_version_from_history_file_mock,
                        stack_versions_mock,
-                       put_structured_out_mock, allInstalledPackages_mock, list_ambari_managed_repos_mock
):
+                       put_structured_out_mock, get_provider_mock, list_ambari_managed_repos_mock
):
 
     stack_versions_mock.return_value = [VERSION_STUB]
-    allInstalledPackages_mock.side_effect = TestRemoveStackVersion._add_packages
+
+    m = MagicMock()
+    m.all_installed_packages.side_effect = TestRemoveStackVersion._add_packages
+    get_provider_mock.return_value = m
+
     list_ambari_managed_repos_mock.return_value = []
 
     self.executeScript("scripts/remove_previous_stacks.py",
@@ -105,7 +113,7 @@ class TestRemoveStackVersion(RMFTestCase):
     self.assertNoMoreResources()
 
   @patch("resource_management.libraries.functions.list_ambari_managed_repos.list_ambari_managed_repos")
-  @patch("resource_management.libraries.functions.packages_analyzer.allInstalledPackages")
+  @patch("resource_management.core.providers.get_provider")
   @patch("resource_management.libraries.script.Script.put_structured_out")
   @patch("resource_management.libraries.functions.stack_select.get_stack_versions")
   @patch("resource_management.libraries.functions.repo_version_history.read_actual_version_from_history_file")
@@ -116,10 +124,14 @@ class TestRemoveStackVersion(RMFTestCase):
                        write_actual_version_to_history_file_mock,
                        read_actual_version_from_history_file_mock,
                        stack_versions_mock,
-                       put_structured_out_mock, allInstalledPackages_mock, list_ambari_managed_repos_mock,
):
+                       put_structured_out_mock, get_provider_mock, list_ambari_managed_repos_mock,
):
 
     stack_versions_mock.return_value = [VERSION_STUB, OLD_VERSION_STUB]
-    allInstalledPackages_mock.side_effect = TestRemoveStackVersion._add_packages
+
+    m = MagicMock()
+    m.all_installed_packages.side_effect = TestRemoveStackVersion._add_packages
+    get_provider_mock.return_value = m
+
     list_ambari_managed_repos_mock.return_value = []
 
     try:

http://git-wip-us.apache.org/repos/asf/ambari/blob/33879743/ambari-server/src/test/python/stacks/2.0.6/HBASE/test_hbase_master.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.0.6/HBASE/test_hbase_master.py b/ambari-server/src/test/python/stacks/2.0.6/HBASE/test_hbase_master.py
index c3cc8f0..4ade11a 100644
--- a/ambari-server/src/test/python/stacks/2.0.6/HBASE/test_hbase_master.py
+++ b/ambari-server/src/test/python/stacks/2.0.6/HBASE/test_hbase_master.py
@@ -48,11 +48,7 @@ class TestHBaseMaster(RMFTestCase):
     self.assertNoMoreResources()
 
 
-  #@patch('resource_management.libraries.functions.packages_analyzer.rmf_shell.checked_call',
new=('','',''))
   def test_install_hbase_master_default_with_phx(self):
-    #import resource_management
-    import itertools
-    #resource_management.libraries.functions.packages_analyzer.rmf_shell.checked_call = lambda
a, b: '','',''
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/hbase_master.py",
                        classname = "HbaseMaster",
                        command = "install",
@@ -71,50 +67,53 @@ class TestHBaseMaster(RMFTestCase):
 
     self.assertNoMoreResources()
 
-  @patch("resource_management.libraries.functions.packages_analyzer._lookUpYumPackages")
-  def test_install_hbase_master_with_version(self, lookUpYumPackages):
-    def _add_packages_available(command, key, arg):
-      arg.append(["hbase_2_3_0_1_1234", "1.0", "testrepo"])
-
-    config_file = self.get_src_folder()+"/test/python/stacks/2.0.6/configs/hbase_with_phx.json"
-    with open(config_file, "r") as f:
-      json_content = json.load(f)
-    version = '2.3.0.1-1234'
-
-    lookUpYumPackages.side_effect = _add_packages_available
-    # the json file is not a "well formed" install command
-    json_content['roleCommand'] = 'INSTALL'
-    json_content['commandParams']['version'] = version
-    json_content['hostLevelParams']['package_list'] = "[{\"name\":\"hbase_${stack_version}\",\"condition\":\"\",\"skipUpgrade\":false}]"
-
-    self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/hbase_master.py",
-                       classname = "HbaseMaster",
-                       command = "install",
-                       config_dict = json_content,
-                       stack_version = self.STACK_VERSION,
-                       target = RMFTestCase.TARGET_COMMON_SERVICES,
-                       try_install=True,
-                       os_type=('Redhat', '6.4', 'Final'),
-                       checked_call_mocks = [(0, "OK.", "")],
-                       )
-
-    # only assert that the correct package is trying to be installed
-    self.assertResourceCalled('Package', 'hbase_2_3_0_1_1234',
-                              retry_count=5,
-                              retry_on_repo_unavailability=False)
-
-
-  def test_configure_default(self):
-    self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/hbase_master.py",
-                   classname = "HbaseMaster",
-                   command = "configure",
-                   config_file="default.json",
-                   stack_version = self.STACK_VERSION,
-                   target = RMFTestCase.TARGET_COMMON_SERVICES
-    )
+  @patch("resource_management.libraries.script.get_provider")
+  def test_install_hbase_master_with_version(self, get_provider):
+    from resource_management.core.providers.package.yumrpm import YumProvider
+    provider = YumProvider(None)
+    with patch.object(provider, "_lookup_packages") as lookup_packages:
+      lookup_packages.return_value = [["hbase_2_3_0_1_1234", "1.0", "testrepo"]]
+
+      get_provider.return_value = provider
+
+      config_file = self.get_src_folder()+"/test/python/stacks/2.0.6/configs/hbase_with_phx.json"
+      with open(config_file, "r") as f:
+        json_content = json.load(f)
+      version = '2.3.0.1-1234'
+
+      # the json file is not a "well formed" install command
+      json_content['roleCommand'] = 'INSTALL'
+      json_content['commandParams']['version'] = version
+      json_content['hostLevelParams']['package_list'] = "[{\"name\":\"hbase_${stack_version}\",\"condition\":\"\",\"skipUpgrade\":false}]"
+
+      self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/hbase_master.py",
+                         classname = "HbaseMaster",
+                         command = "install",
+                         config_dict = json_content,
+                         stack_version = self.STACK_VERSION,
+                         target = RMFTestCase.TARGET_COMMON_SERVICES,
+                         try_install=True,
+                         os_type=('Redhat', '6.4', 'Final'),
+                         checked_call_mocks = [(0, "OK.", "")],
+                         )
+
+      # only assert that the correct package is trying to be installed
+      self.assertResourceCalled('Package', 'hbase_2_3_0_1_1234',
+                                retry_count=5,
+                                retry_on_repo_unavailability=False)
+
+
+    def test_configure_default(self):
+      self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/hbase_master.py",
+                     classname = "HbaseMaster",
+                     command = "configure",
+                     config_file="default.json",
+                     stack_version = self.STACK_VERSION,
+                     target = RMFTestCase.TARGET_COMMON_SERVICES
+      )
 
-    self.assert_configure_default()
-    self.assertNoMoreResources()
+      self.assert_configure_default()
+      self.assertNoMoreResources()
 
   def test_start_default(self):
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/hbase_master.py",


Mime
View raw message