Skip to content

Commit

Permalink
AMBARI-25116. Bug at AbstractProviderModule class (dlysnichenko) (apa…
Browse files Browse the repository at this point in the history
…che#2774)

* AMBARI-25116. Bug at AbstractProviderModule class (dlysnichenko)

* Fix mocks (test hangs on jenkins due to console input prompt) at TestSensitiveDataEncryption.py
  • Loading branch information
Dmitriusan authored Jan 22, 2019
1 parent 94067cb commit 10f955b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -968,13 +969,14 @@ private Map<String, Object> getConfigProperties(String clusterName, String versi
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,
Expand Down
16 changes: 7 additions & 9 deletions ambari-server/src/test/python/TestSensitiveDataEncryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,8 @@ def test_setup_sensitive_data_encryption_persist(self, sensitive_data_encryption
@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,
Expand All @@ -511,14 +512,14 @@ def test_reset_master_key_persisted(self, get_is_secure_method, sensitive_data_e

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
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"), call(options, "encryption")]
Expand Down Expand Up @@ -547,7 +548,6 @@ def test_reset_master_key_persisted(self, get_is_secure_method, sensitive_data_e
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")
Expand All @@ -559,13 +559,13 @@ def test_reset_master_key_persisted(self, get_is_secure_method, sensitive_data_e
@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
Expand All @@ -580,15 +580,13 @@ def test_decrypt_sensitive_data(self, get_is_secure_method, sensitive_data_encry
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")]
Expand Down

0 comments on commit 10f955b

Please sign in to comment.