本文整理汇总了Python中charmhelpers.contrib.network.ip.ns_query方法的典型用法代码示例。如果您正苦于以下问题:Python ip.ns_query方法的具体用法?Python ip.ns_query怎么用?Python ip.ns_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类charmhelpers.contrib.network.ip
的用法示例。
在下文中一共展示了ip.ns_query方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_host_ip_with_hostname_no_dns
# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import ns_query [as 别名]
def test_get_host_ip_with_hostname_no_dns(self, apt_install, socket,
ns_query):
ns_query.return_value = []
fake_dns = FakeDNS(None)
socket.return_value = '10.0.0.1'
with patch(builtin_import, side_effect=[fake_dns]):
ip = net_ip.get_host_ip('www.ubuntu.com')
self.assertEquals(ip, '10.0.0.1')
示例2: test_get_host_ip_with_hostname_fallback
# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import ns_query [as 别名]
def test_get_host_ip_with_hostname_fallback(self, apt_install, socket,
ns_query, *args):
ns_query.return_value = []
fake_dns = FakeDNS(None)
def r():
raise Exception()
socket.side_effect = r
with patch(builtin_import, side_effect=[fake_dns]):
ip = net_ip.get_host_ip('www.ubuntu.com', fallback='127.0.0.1')
self.assertEquals(ip, '127.0.0.1')
示例3: test_ns_query_trigger_apt_install
# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import ns_query [as 别名]
def test_ns_query_trigger_apt_install(self, apt_install):
fake_dns = FakeDNS('5.5.5.5')
with patch(builtin_import, side_effect=[ImportError, fake_dns]):
nsq = net_ip.ns_query('5.5.5.5')
if six.PY2:
apt_install.assert_called_with('python-dnspython', fatal=True)
else:
apt_install.assert_called_with('python3-dnspython', fatal=True)
self.assertEquals(nsq, '5.5.5.5')
示例4: test_ns_query_ptr_record
# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import ns_query [as 别名]
def test_ns_query_ptr_record(self, apt_install):
fake_dns = FakeDNS('127.0.0.1')
with patch(builtin_import, side_effect=[fake_dns]):
nsq = net_ip.ns_query('127.0.0.1')
self.assertEquals(nsq, '127.0.0.1')
示例5: test_ns_query_a_record
# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import ns_query [as 别名]
def test_ns_query_a_record(self, apt_install):
fake_dns = FakeDNS('127.0.0.1')
fake_dns_name = FakeDNSName('www.somedomain.tld')
with patch(builtin_import, side_effect=[fake_dns]):
nsq = net_ip.ns_query(fake_dns_name)
self.assertEquals(nsq, '127.0.0.1')
示例6: test_ns_query_lookup_fail
# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import ns_query [as 别名]
def test_ns_query_lookup_fail(self, apt_install):
fake_dns = FakeDNS('')
with patch(builtin_import, side_effect=[fake_dns, fake_dns]):
nsq = net_ip.ns_query('nonexistant')
self.assertEquals(nsq, None)
示例7: test_get_hostname_lookup_fail
# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import ns_query [as 别名]
def test_get_hostname_lookup_fail(self, apt_install, ns_query, socket):
fake_dns = FakeDNS('www.ubuntu.com')
ns_query.return_value = []
socket.return_value = ()
with patch(builtin_import, side_effect=[fake_dns, fake_dns]):
hn = net_ip.get_hostname('4.2.2.1')
self.assertEquals(hn, None)
示例8: test_get_hostname_lookup_fail_gethostbyaddr_fallback
# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import ns_query [as 别名]
def test_get_hostname_lookup_fail_gethostbyaddr_fallback(
self, apt_install, ns_query, socket):
fake_dns = FakeDNS('www.ubuntu.com')
ns_query.return_value = []
socket.return_value = ("www.ubuntu.com", "", "")
with patch(builtin_import, side_effect=[fake_dns]):
hn = net_ip.get_hostname('4.2.2.1')
self.assertEquals(hn, "www.ubuntu.com")