当前位置: 首页>>代码示例>>Python>>正文


Python Bigtop.check_bigtop_repo_package方法代码示例

本文整理汇总了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()
开发者ID:juju-solutions,项目名称:layer-apache-bigtop-base,代码行数:70,代码来源:test_bigtop.py


注:本文中的charms.layer.apache_bigtop_base.Bigtop.check_bigtop_repo_package方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。