This is an automated email from the ASF dual-hosted git repository.
dmitriusan pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push:
new 10f955b AMBARI-25116. Bug at AbstractProviderModule class
(dlysnichenko) (#2774)
10f955b is described below
commit 10f955b8da9283a41deceb34387dbb7b71bc46e2
Author: Lisnichenko Dmitro <[email protected]>
AuthorDate: Tue Jan 22 17:43:34 2019 +0200
AMBARI-25116. Bug at AbstractProviderModule class (dlysnichenko) (#2774)
* AMBARI-25116. Bug at AbstractProviderModule class (dlysnichenko)
* Fix mocks (test hangs on jenkins due to console input prompt) at
TestSensitiveDataEncryption.py
---
.../controller/internal/AbstractProviderModule.java | 14 ++++++++------
.../src/test/python/TestSensitiveDataEncryption.py | 16 +++++++---------
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
index cbafea7..90c0616 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
@@ -18,6 +18,7 @@
package org.apache.ambari.server.controller.internal;
+import static java.util.Collections.emptyMap;
import static
org.apache.ambari.server.controller.metrics.MetricsServiceProvider.MetricsService.GANGLIA;
import static
org.apache.ambari.server.controller.metrics.MetricsServiceProvider.MetricsService.TIMELINE_METRICS;
@@ -968,13 +969,14 @@ public abstract class AbstractProviderModule implements
ProviderModule,
ConfigurationResourceProvider.TYPE,
ConfigurationResourceProvider.TAG), configPredicate);
} catch (NoSuchResourceException e) {
- LOG.info("Resource for the desired config not found. " + e);
- return Collections.emptyMap();
+ LOG.info("Resource for the desired config not found.", e);
+ return emptyMap();
}
- for (Resource res : configResources) {
- return res.getPropertiesMap().get(PROPERTIES_CATEGORY);
- }
- return Collections.emptyMap();
+ return configResources.stream()
+ .findFirst()
+ .map(res -> res.getPropertiesMap()
+ .get(PROPERTIES_CATEGORY))
+ .orElse(emptyMap());
}
private Map<String, String> getDesiredConfigMap(String clusterName, String
versionTag,
diff --git a/ambari-server/src/test/python/TestSensitiveDataEncryption.py
b/ambari-server/src/test/python/TestSensitiveDataEncryption.py
index 4e839c4..8ff6588 100644
--- a/ambari-server/src/test/python/TestSensitiveDataEncryption.py
+++ b/ambari-server/src/test/python/TestSensitiveDataEncryption.py
@@ -488,7 +488,8 @@ class TestSensitiveDataEncryption(TestCase):
@patch("ambari_server.setupSecurity.is_root")
@patch("ambari_server.setupSecurity.sensitive_data_encryption")
@patch("ambari_server.setupSecurity.get_is_secure")
- def test_reset_master_key_persisted(self, get_is_secure_method,
sensitive_data_encryption_metod, is_root_method,
+ @patch("ambari_server.setupSecurity.get_is_persisted")
+ def test_reset_master_key_persisted(self, get_is_persisted_method,
get_is_secure_method, sensitive_data_encryption_metod, is_root_method,
get_ambari_properties_method,
search_file_message,
get_YN_input_method,
save_master_key_method,
update_properties_method,
@@ -511,6 +512,7 @@ class TestSensitiveDataEncryption(TestCase):
master_key = "aaa"
+ get_is_persisted_method.return_value = (True, "filepath")
get_is_secure_method.return_value = True
get_YN_input_method.side_effect = [False, True, True]
read_master_key_method.return_value = master_key
@@ -518,7 +520,6 @@ class TestSensitiveDataEncryption(TestCase):
save_passwd_for_alias_method.return_value = 0
exists_mock.return_value = False
-
options = self._create_empty_options_mock()
setup_sensitive_data_encryption(options)
calls = [call(options, "decryption"), call(options, "encryption")]
@@ -547,7 +548,6 @@ class TestSensitiveDataEncryption(TestCase):
self.assertEquals(sorted_x, sorted_y)
pass
- @patch("ambari_server.setupSecurity.read_master_key")
@patch("os.path.exists")
@patch("ambari_server.setupSecurity.read_ambari_user")
@patch("ambari_server.setupSecurity.save_passwd_for_alias")
@@ -559,13 +559,13 @@ class TestSensitiveDataEncryption(TestCase):
@patch("ambari_server.setupSecurity.is_root")
@patch("ambari_server.setupSecurity.sensitive_data_encryption")
@patch("ambari_server.setupSecurity.get_is_secure")
- def test_decrypt_sensitive_data(self, get_is_secure_method,
sensitive_data_encryption_metod, is_root_method,
+ @patch("ambari_server.setupSecurity.get_is_persisted")
+ def test_decrypt_sensitive_data_persister(self, get_is_persisted_method,
get_is_secure_method, sensitive_data_encryption_metod, is_root_method,
get_ambari_properties_method,
search_file_message,
get_YN_input_method,
update_properties_method,
read_passwd_for_alias_method,
save_passwd_for_alias_method,
- read_ambari_user_method, exists_mock,
- read_master_key_method):
+ read_ambari_user_method, exists_mock):
# Testing call under root
is_root_method.return_value = True
@@ -580,15 +580,13 @@ class TestSensitiveDataEncryption(TestCase):
p.process_pair(JDBC_RCA_PASSWORD_FILE_PROPERTY, FAKE_PWD_STRING)
get_ambari_properties_method.return_value = p
- master_key = "aaa"
+ get_is_persisted_method.return_value = (True, "filepath")
get_is_secure_method.return_value = True
get_YN_input_method.side_effect = [True, False]
- read_master_key_method.return_value = master_key
read_passwd_for_alias_method.return_value = "fakepassword"
save_passwd_for_alias_method.return_value = 0
exists_mock.return_value = False
-
options = self._create_empty_options_mock()
setup_sensitive_data_encryption(options)
calls = [call(options, "decryption")]