本文整理汇总了Python中charms.layer.apache_bigtop_base.Bigtop.reinstall_repo_packages方法的典型用法代码示例。如果您正苦于以下问题:Python Bigtop.reinstall_repo_packages方法的具体用法?Python Bigtop.reinstall_repo_packages怎么用?Python Bigtop.reinstall_repo_packages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类charms.layer.apache_bigtop_base.Bigtop
的用法示例。
在下文中一共展示了Bigtop.reinstall_repo_packages方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestBigtopUnit
# 需要导入模块: from charms.layer.apache_bigtop_base import Bigtop [as 别名]
# 或者: from charms.layer.apache_bigtop_base.Bigtop import reinstall_repo_packages [as 别名]
#.........这里部分代码省略.........
'''
Verify that we attempt to run smoke tests correctly, and handle
exceptions as expected.
'''
mock_options.return_value = {}
# Returns None if bigtop isn't available.
remove_state('bigtop.available')
self.assertEqual(None, self.bigtop.run_smoke_tests())
# Returns None if we don't pass in a 'smoke_components' arg
set_state('bigtop.available')
self.assertEqual(None, self.bigtop.run_smoke_tests())
# Should return 'success' if all went well.
self.assertEqual(
self.bigtop.run_smoke_tests(smoke_components=['foo', 'bar']),
'success'
)
# Should return error message if subprocess raised an Exception.
class MockException(Exception):
pass
MockException.output = "test output"
mock_sub.CalledProcessError = MockException
def mock_raise(*args, **kwargs):
raise MockException('foo!')
mock_run.side_effect = mock_raise
self.assertEqual(
self.bigtop.run_smoke_tests(smoke_components=['foo', 'bar']),
"test output"
)
@mock.patch('charms.layer.apache_bigtop_base.Bigtop.update_bigtop_repo')
@mock.patch('charms.layer.apache_bigtop_base.Bigtop.render_hiera_yaml')
@mock.patch('charms.layer.apache_bigtop_base.Path')
@mock.patch('charms.layer.apache_bigtop_base.Bigtop.pin_bigtop_packages')
@mock.patch('charms.layer.apache_bigtop_base.Bigtop.trigger_puppet')
@mock.patch('charms.layer.apache_bigtop_base.subprocess')
def test_reinstall_repo_packages(self, mock_sub, mock_trigger, mock_pin,
mock_path, mock_hiera, mock_update):
'''
Verify that we attempt to trigger puppet during a reinstall, and handle
exceptions as expected.
'''
class MockException(Exception):
pass
MockException.output = "test output"
mock_sub.CalledProcessError = MockException
def mock_raise(*args, **kwargs):
raise MockException('foo!')
# Should return error message if apt-get remove raised an Exception.
mock_sub.check_call.side_effect = mock_raise
self.assertEqual(
self.bigtop.reinstall_repo_packages(remove_pkgs='foo bar-*'),
"test output"
)
# Should call pin twice if trigger puppet fails (once to raise prio,
# once again to drop it back down)
mock_trigger.side_effect = mock_raise
self.assertEqual(self.bigtop.reinstall_repo_packages(), 'failed')
self.assertEqual(mock_pin.call_count, 2)
# Should return 'success' if all went well.
mock_trigger.side_effect = None
self.assertEqual(self.bigtop.reinstall_repo_packages(), 'success')
def test_get_ip_for_interface(self):
'''
Test to verify that our get_ip_for_interface method does sensible
things.
'''
ip = self.bigtop.get_ip_for_interface('lo')
self.assertEqual(ip, '127.0.0.1')
ip = self.bigtop.get_ip_for_interface('127.0.0.0/24')
self.assertEqual(ip, '127.0.0.1')
# If passed 0.0.0.0, or something similar, the function should
# treat it as a special case, and return what it was passed.
for i in ['0.0.0.0', '0.0.0.0/0', '0/0', '::']:
ip = self.bigtop.get_ip_for_interface(i)
self.assertEqual(ip, i)
self.assertRaises(
BigtopError,
self.bigtop.get_ip_for_interface,
'2.2.2.0/24')
self.assertRaises(
BigtopError,
self.bigtop.get_ip_for_interface,
'foo')