當前位置: 首頁>>代碼示例>>Python>>正文


Python FS.directory_usage方法代碼示例

本文整理匯總了Python中jnpr.junos.utils.fs.FS.directory_usage方法的典型用法代碼示例。如果您正苦於以下問題:Python FS.directory_usage方法的具體用法?Python FS.directory_usage怎麽用?Python FS.directory_usage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在jnpr.junos.utils.fs.FS的用法示例。


在下文中一共展示了FS.directory_usage方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestFS

# 需要導入模塊: from jnpr.junos.utils.fs import FS [as 別名]
# 或者: from jnpr.junos.utils.fs.FS import directory_usage [as 別名]

#.........這裏部分代碼省略.........

    @patch("jnpr.junos.utils.fs.StartShell")
    def test_symlink(self, mock_StartShell):
        src = "test/tgz.txt"
        dst = "test/xyz"
        print(self.fs.symlink(src, dst))
        calls = [
            call().__enter__(),
            call().__enter__().run("ln -sf test/tgz.txt test/xyz"),
            call().__exit__(None, None, None),
        ]
        mock_StartShell.assert_has_calls(calls)

    @patch("jnpr.junos.Device.execute")
    def test_storage_usage(self, mock_execute):
        mock_execute.side_effect = self._mock_manager
        self.assertEqual(
            self.fs.storage_usage(),
            {
                "/dev/abc": {
                    "avail_block": 234234,
                    "used_blocks": 2346455,
                    "used_pct": "1",
                    "mount": "/",
                    "total_blocks": 567431,
                    "avail": "2F",
                    "used": "481M",
                    "total": "4F",
                }
            },
        )

    @patch("jnpr.junos.Device.execute")
    def test_directory_usage(self, mock_execute):
        mock_execute.side_effect = self._mock_manager
        self.assertEqual(
            self.fs.directory_usage(path="/var/tmp", depth=1),
            {
                "/var/tmp": {"blocks": 456076, "bytes": 233510912, "size": "223M"},
                "/var/tmp/gres-tp": {"blocks": 68, "bytes": 34816, "size": "34K"},
                "/var/tmp/install": {"blocks": 4, "bytes": 2048, "size": "2.0K"},
                "/var/tmp/pics": {"blocks": 4, "bytes": 2048, "size": "2.0K"},
                "/var/tmp/rtsdb": {"blocks": 4, "bytes": 2048, "size": "2.0K"},
                "/var/tmp/sec-download": {"blocks": 8, "bytes": 4096, "size": "4.0K"},
                "/var/tmp/vi.recover": {"blocks": 4, "bytes": 2048, "size": "2.0K"},
            },
        )

    @patch("jnpr.junos.Device.execute")
    def test_storage_cleanup(self, mock_execute):
        mock_execute.side_effect = self._mock_manager
        self.assertEqual(self.fs.storage_cleanup(), {"/var/abc.txt": {"ts_date": "Apr 25 10:38", "size": 11}})

    @patch("jnpr.junos.Device.execute")
    def test_storage_cleanup_check(self, mock_execute):
        mock_execute.side_effect = self._mock_manager
        self.assertEqual(self.fs.storage_cleanup_check(), {"/var/abc.txt": {"ts_date": "Apr 25 10:38", "size": 11}})

    def _read_file(self, fname):
        from ncclient.xml_ import NCElement

        fpath = os.path.join(os.path.dirname(__file__), "rpc-reply", fname)
        foo = open(fpath).read()

        if fname == "get-rpc-error.xml" or fname == "get-index-error.xml" or fname == "get-system-core-dumps.xml":
            rpc_reply = NCElement(foo, self.dev._conn._device_handler.transform_reply())
開發者ID:pklimai,項目名稱:py-junos-eznc,代碼行數:70,代碼來源:test_fs.py

示例2: TestFS

# 需要導入模塊: from jnpr.junos.utils.fs import FS [as 別名]
# 或者: from jnpr.junos.utils.fs.FS import directory_usage [as 別名]

#.........這裏部分代碼省略.........
    @patch('jnpr.junos.utils.fs.StartShell')
    def test_mkdir(self, mock_StartShell):
        path = 'test/mkdir'
        print(self.fs.mkdir(path))
        calls = [
            call().__enter__(),
            call().__enter__().run('mkdir -p test/mkdir'),
            call().__exit__(None, None, None)]
        mock_StartShell.assert_has_calls(calls)

    @patch('jnpr.junos.utils.fs.StartShell')
    def test_symlink(self, mock_StartShell):
        src = 'test/tgz.txt'
        dst = 'test/xyz'
        print(self.fs.symlink(src, dst))
        calls = [
            call().__enter__(),
            call().__enter__().run('ln -sf test/tgz.txt test/xyz'),
            call().__exit__(None, None, None)]
        mock_StartShell.assert_has_calls(calls)

    @patch('jnpr.junos.Device.execute')
    def test_storage_usage(self, mock_execute):
        mock_execute.side_effect = self._mock_manager
        self.assertEqual(self.fs.storage_usage(),
                         {'/dev/abc':
                          {'avail_block': 234234,
                           'used_blocks': 2346455, 'used_pct': '1',
                           'mount': '/', 'total_blocks': 567431,
                           'avail': '2F', 'used': '481M',
                           'total': '4F'}})

    @patch('jnpr.junos.Device.execute')
    def test_directory_usage(self, mock_execute):
        mock_execute.side_effect = self._mock_manager
        self.assertEqual(self.fs.directory_usage(path="/var/tmp", depth=1),
                         {'/var/tmp': {'blocks': 456076, 'bytes': 233510912,
                                       'size': '223M'},
                          '/var/tmp/gres-tp': {'blocks': 68, 'bytes': 34816,
                                               'size': '34K'},
                          '/var/tmp/install': {'blocks': 4, 'bytes': 2048,
                                               'size': '2.0K'},
                          '/var/tmp/pics': {'blocks': 4, 'bytes': 2048,
                                            'size': '2.0K'},
                          '/var/tmp/rtsdb': {'blocks': 4, 'bytes': 2048,
                                             'size': '2.0K'},
                          '/var/tmp/sec-download': {'blocks': 8, 'bytes': 4096,
                                                    'size': '4.0K'},
                          '/var/tmp/vi.recover': {'blocks': 4, 'bytes': 2048,
                                                  'size': '2.0K'}}
                         )

    @patch('jnpr.junos.Device.execute')
    def test_directory_usage_error(self, mock_execute):
        mock_execute.return_value = etree.fromstring("""
            <directory-usage-information>
                <directory>
                    <used-space used-blocks="456076">
                        223M
                    </used-space>
                </directory>
            </directory-usage-information>""")
        self.assertRaises(
            RpcError,
            self.fs.directory_usage,
            path="/var/tmp",
開發者ID:ydnath,項目名稱:py-junos-eznc,代碼行數:70,代碼來源:test_fs.py


注:本文中的jnpr.junos.utils.fs.FS.directory_usage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。