本文整理汇总了Python中charms.layer.apache_bigtop_base.Bigtop.check_bigtop_repo_package方法的典型用法代码示例。如果您正苦于以下问题:Python Bigtop.check_bigtop_repo_package方法的具体用法?Python Bigtop.check_bigtop_repo_package怎么用?Python Bigtop.check_bigtop_repo_package使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类charms.layer.apache_bigtop_base.Bigtop
的用法示例。
在下文中一共展示了Bigtop.check_bigtop_repo_package方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestBigtopUnit
# 需要导入模块: from charms.layer.apache_bigtop_base import Bigtop [as 别名]
# 或者: from charms.layer.apache_bigtop_base.Bigtop import check_bigtop_repo_package [as 别名]
#.........这里部分代码省略.........
'DISTRIB_RELEASE': '7'}
self.bigtop.update_bigtop_repo()
mock_sub.check_call.assert_not_called()
# verify args when adding a repo on ubuntu
mock_apt.return_value = 'foo'
mock_lsb_release.return_value = {'DISTRIB_CODENAME': 'xenial',
'DISTRIB_ID': 'ubuntu',
'DISTRIB_RELEASE': '16.04'}
self.bigtop.update_bigtop_repo()
mock_sub.check_call.assert_called_with(
['add-apt-repository', '-yu', 'deb foo bigtop contrib'])
# verify args when removing a repo on ubuntu
self.bigtop.update_bigtop_repo(remove=True)
mock_sub.check_call.assert_called_with(
['add-apt-repository', '-yur', 'deb foo bigtop contrib'])
# verify we handle check_call errors
class MockException(Exception):
pass
mock_sub.CalledProcessError = MockException
def mock_raise(*args, **kwargs):
raise MockException('foo!')
mock_sub.check_call.side_effect = mock_raise
self.bigtop.update_bigtop_repo()
@mock.patch('charms.layer.apache_bigtop_base.get_package_version')
@mock.patch('charms.layer.apache_bigtop_base.hookenv')
@mock.patch('charms.layer.apache_bigtop_base.subprocess.Popen')
@mock.patch('charms.layer.apache_bigtop_base.lsb_release')
def test_check_bigtop_repo_package(self, mock_lsb_release, mock_sub,
mock_hookenv, mock_pkg_ver):
'''
Verify bigtop repo package queries.
'''
# non-ubuntu should raise an error
mock_lsb_release.return_value = {'DISTRIB_CODENAME': 'foo',
'DISTRIB_ID': 'centos',
'DISTRIB_RELEASE': '7'}
self.assertRaises(BigtopError,
self.bigtop.check_bigtop_repo_package,
'foo')
# reset with ubuntu
mock_lsb_release.return_value = {'DISTRIB_CODENAME': 'xenial',
'DISTRIB_ID': 'ubuntu',
'DISTRIB_RELEASE': '16.04'}
madison_proc = mock.Mock()
grep_proc = mock.Mock()
# simulate a missing repo pkg
grep_attrs = {'communicate.return_value': (b'', 'stderr')}
grep_proc.configure_mock(**grep_attrs)
# test a missing repo pkg (message should be logged)
mock_sub.return_value = madison_proc
mock_sub.return_value = grep_proc
mock_pkg_ver.return_value = ''
self.assertEqual(None, self.bigtop.check_bigtop_repo_package('foo'))
mock_hookenv.log.assert_called_once()
mock_hookenv.reset_mock()