本文整理汇总了Python中ambari_agent.AmbariConfig.AmbariConfig.get方法的典型用法代码示例。如果您正苦于以下问题:Python AmbariConfig.get方法的具体用法?Python AmbariConfig.get怎么用?Python AmbariConfig.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ambari_agent.AmbariConfig.AmbariConfig
的用法示例。
在下文中一共展示了AmbariConfig.get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ambari_config_get
# 需要导入模块: from ambari_agent.AmbariConfig import AmbariConfig [as 别名]
# 或者: from ambari_agent.AmbariConfig.AmbariConfig import get [as 别名]
def test_ambari_config_get(self):
config = AmbariConfig()
#default
self.assertEqual(config.get("security", "keysdir"), "/tmp/ambari-agent")
#non-default
config.set("security", "keysdir", "/tmp/non-default-path")
self.assertEqual(config.get("security", "keysdir"), "/tmp/non-default-path")
#whitespace handling
config.set("security", "keysdir", " /tmp/non-stripped")
self.assertEqual(config.get("security", "keysdir"), "/tmp/non-stripped")
示例2: test_registration_build
# 需要导入模块: from ambari_agent.AmbariConfig import AmbariConfig [as 别名]
# 或者: from ambari_agent.AmbariConfig.AmbariConfig import get [as 别名]
def test_registration_build(self, get_os_version_mock, get_os_type_mock, run_os_cmd_mock):
config = AmbariConfig().getConfig()
tmpdir = tempfile.gettempdir()
config.set('agent', 'prefix', tmpdir)
config.set('agent', 'current_ping_port', '33777')
get_os_type_mock.return_value = "suse"
get_os_version_mock.return_value = "11"
run_os_cmd_mock.return_value = (3, "", "")
ver_file = os.path.join(tmpdir, "version")
with open(ver_file, "w") as text_file:
text_file.write("1.3.0")
register = Register(config)
data = register.build(1)
#print ("Register: " + pprint.pformat(data))
self.assertEquals(len(data['hardwareProfile']) > 0, True, "hardwareProfile should contain content")
self.assertEquals(data['hostname'] != "", True, "hostname should not be empty")
self.assertEquals(data['publicHostname'] != "", True, "publicHostname should not be empty")
self.assertEquals(data['responseId'], 1)
self.assertEquals(data['timestamp'] > 1353678475465L, True, "timestamp should not be empty")
self.assertEquals(len(data['agentEnv']) > 0, True, "agentEnv should not be empty")
self.assertEquals(data['agentVersion'], '1.3.0', "agentVersion should not be empty")
print data['agentEnv']['umask']
self.assertEquals(not data['agentEnv']['umask']== "", True, "agents umask should not be empty")
self.assertEquals(data['currentPingPort'] == 33777, True, "current ping port should be 33777")
self.assertEquals(data['prefix'], config.get('agent', 'prefix'), 'The prefix path does not match')
self.assertEquals(len(data), 9)
os.remove(ver_file)
示例3: test_RetryAction
# 需要导入模块: from ambari_agent.AmbariConfig import AmbariConfig [as 别名]
# 或者: from ambari_agent.AmbariConfig.AmbariConfig import get [as 别名]
def test_RetryAction(self):
action={'id' : 'tttt'}
config = AmbariConfig().getConfig()
actionQueue = ActionQueue(config)
path = actionQueue.getInstallFilename(action['id'])
configFile = {
"data" : "test",
"owner" : os.getuid(),
"group" : os.getgid() ,
"permission" : 0700,
"path" : path,
"umask" : 022
}
#note that the command in the action is just a listing of the path created
#we just want to ensure that 'ls' can run on the data file (in the actual world
#this 'ls' would be a puppet or a chef command that would work on a data
#file
badAction = {
'id' : 'tttt',
'kind' : 'INSTALL_AND_CONFIG_ACTION',
'workDirComponent' : 'abc-hdfs',
'file' : configFile,
'clusterDefinitionRevision' : 12,
'command' : ['/bin/ls',"/foo/bar/badPath1234"]
}
path=getFilePath(action,path)
goodAction = {
'id' : 'tttt',
'kind' : 'INSTALL_AND_CONFIG_ACTION',
'workDirComponent' : 'abc-hdfs',
'file' : configFile,
'clusterDefinitionRevision' : 12,
'command' : ['/bin/ls',path]
}
actionQueue.start()
response = {'actions' : [badAction,goodAction]}
actionQueue.maxRetries = 2
actionQueue.sleepInterval = 1
result = actionQueue.put(response)
results = actionQueue.result()
sleptCount = 1
while (len(results) < 2 and sleptCount < 15):
time.sleep(1)
sleptCount += 1
results = actionQueue.result()
actionQueue.stop()
actionQueue.join()
self.assertEqual(len(results), 2, 'Number of results is not 2.')
result = results[0]
maxretries = config.get('command', 'maxretries')
self.assertEqual(int(result['retryActionCount']),
int(maxretries),
"Number of retries is %d and not %d" %
(int(result['retryActionCount']), int(str(maxretries))))
result = results[1]
self.assertEqual(int(result['retryActionCount']),
1,
"Number of retries is %d and not %d" %
(int(result['retryActionCount']), 1))
示例4: test_server_hostname
# 需要导入模块: from ambari_agent.AmbariConfig import AmbariConfig [as 别名]
# 或者: from ambari_agent.AmbariConfig.AmbariConfig import get [as 别名]
def test_server_hostname(self):
hostname.cached_server_hostname = None
config = AmbariConfig()
default_server_hostname = config.get('server', 'hostname')
config.set('server', 'hostname', 'ambari-host')
self.assertEquals('ambari-host', hostname.server_hostname(config),
"hostname should equal the socket-based hostname")
config.set('server', 'hostname', default_server_hostname)
pass
示例5: test_server_hostnames
# 需要导入模块: from ambari_agent.AmbariConfig import AmbariConfig [as 别名]
# 或者: from ambari_agent.AmbariConfig.AmbariConfig import get [as 别名]
def test_server_hostnames(self):
hostname.cached_server_hostnames = []
config = AmbariConfig()
default_server_hostname = config.get('server', 'hostname')
config.set('server', 'hostname', 'ambari-host')
server_hostnames = hostname.server_hostnames(config)
self.assertEquals(['ambari-host'], server_hostnames,
"expected host name ['ambari-host']; got {0}".format(server_hostnames))
config.set('server', 'hostname', default_server_hostname)
pass
示例6: test_registration_build
# 需要导入模块: from ambari_agent.AmbariConfig import AmbariConfig [as 别名]
# 或者: from ambari_agent.AmbariConfig.AmbariConfig import get [as 别名]
def test_registration_build(self, get_os_version_mock, get_os_type_mock, run_os_cmd_mock, Popen_mock):
config = AmbariConfig().getConfig()
tmpdir = tempfile.gettempdir()
config.set('agent', 'prefix', tmpdir)
config.set('agent', 'current_ping_port', '33777')
get_os_type_mock.return_value = "suse"
get_os_version_mock.return_value = "11"
run_os_cmd_mock.return_value = (3, "", "")
register = Register(config)
reference_version = '2.1.0'
data = register.build(reference_version, 1)
self.assertEquals(len(data['hardwareProfile']) > 0, True, "hardwareProfile should contain content")
self.assertEquals(data['hostname'] != "", True, "hostname should not be empty")
self.assertEquals(data['publicHostname'] != "", True, "publicHostname should not be empty")
self.assertEquals(data['responseId'], 1)
self.assertEquals(data['timestamp'] > 1353678475465L, True, "timestamp should not be empty")
self.assertEquals(len(data['agentEnv']) > 0, True, "agentEnv should not be empty")
self.assertEquals(data['agentVersion'], reference_version, "agentVersion should not be empty")
print data['agentEnv']['umask']
self.assertEquals(not data['agentEnv']['umask']== "", True, "agents umask should not be empty")
self.assertEquals(data['currentPingPort'] == 33777, True, "current ping port should be 33777")
self.assertEquals(data['prefix'], config.get('agent', 'prefix'), 'The prefix path does not match')
self.assertEquals(len(data), 9)
示例7: TestSecurity
# 需要导入模块: from ambari_agent.AmbariConfig import AmbariConfig [as 别名]
# 或者: from ambari_agent.AmbariConfig.AmbariConfig import get [as 别名]
class TestSecurity(unittest.TestCase):
def setUp(self):
# disable stdout
out = StringIO.StringIO()
sys.stdout = out
# Create config
self.config = AmbariConfig().getConfig()
# Instantiate CachedHTTPSConnection (skip connect() call)
with patch.object(security.VerifiedHTTPSConnection, "connect"):
self.cachedHTTPSConnection = security.CachedHTTPSConnection(self.config)
def tearDown(self):
# enable stdout
sys.stdout = sys.__stdout__
### VerifiedHTTPSConnection ###
@patch.object(security.CertificateManager, "initSecurity")
@patch("socket.create_connection")
@patch("ssl.wrap_socket")
def test_VerifiedHTTPSConnection_connect(self, wrap_socket_mock,
create_connection_mock,
init_security_mock):
init_security_mock.return_value = None
self.config.set('security', 'keysdir', '/dummy-keysdir')
connection = security.VerifiedHTTPSConnection("example.com",
self.config.get('server', 'secured_url_port'), self.config)
connection._tunnel_host = False
connection.sock = None
connection.connect()
self.assertTrue(wrap_socket_mock.called)
### VerifiedHTTPSConnection with no certificates creation
@patch.object(security.CertificateManager, "initSecurity")
@patch("socket.create_connection")
@patch("ssl.wrap_socket")
def test_Verified_HTTPSConnection_non_secure_connect(self, wrap_socket_mock,
create_connection_mock,
init_security_mock):
connection = security.VerifiedHTTPSConnection("example.com",
self.config.get('server', 'secured_url_port'), self.config)
connection._tunnel_host = False
connection.sock = None
connection.connect()
self.assertFalse(init_security_mock.called)
### VerifiedHTTPSConnection with two-way SSL authentication enabled
@patch.object(security.CertificateManager, "initSecurity")
@patch("socket.create_connection")
@patch("ssl.wrap_socket")
def test_Verified_HTTPSConnection_two_way_ssl_connect(self, wrap_socket_mock,
create_connection_mock,
init_security_mock):
wrap_socket_mock.side_effect=ssl.SSLError()
connection = security.VerifiedHTTPSConnection("example.com",
self.config.get('server', 'secured_url_port'), self.config)
connection._tunnel_host = False
connection.sock = None
try:
connection.connect()
except ssl.SSLError:
pass
self.assertTrue(init_security_mock.called)
### CachedHTTPSConnection ###
@patch.object(security.VerifiedHTTPSConnection, "connect")
def test_CachedHTTPSConnection_connect(self, vhc_connect_mock):
self.config.set('server', 'hostname', 'dummy.server.hostname')
self.config.set('server', 'secured_url_port', '443')
# Testing not connected case
self.cachedHTTPSConnection.connected = False
self.cachedHTTPSConnection.connect()
self.assertTrue(vhc_connect_mock.called)
vhc_connect_mock.reset_mock()
# Testing already connected case
self.cachedHTTPSConnection.connect()
self.assertFalse(vhc_connect_mock.called)
@patch.object(security.CachedHTTPSConnection, "connect")
def test_forceClear(self, connect_mock):
# Testing if httpsconn instance changed
old = self.cachedHTTPSConnection.httpsconn
self.cachedHTTPSConnection.forceClear()
self.assertNotEqual(old, self.cachedHTTPSConnection.httpsconn)
@patch.object(security.CachedHTTPSConnection, "connect")
def test_request(self, connect_mock):
httpsconn_mock = MagicMock(create = True)
self.cachedHTTPSConnection.httpsconn = httpsconn_mock
dummy_request = MagicMock(create = True)
dummy_request.get_method.return_value = "dummy_get_method"
dummy_request.get_full_url.return_value = "dummy_full_url"
dummy_request.get_data.return_value = "dummy_get_data"
#.........这里部分代码省略.........