本文整理汇总了Python中jnpr.junos.utils.fs.FS.storage_cleanup方法的典型用法代码示例。如果您正苦于以下问题:Python FS.storage_cleanup方法的具体用法?Python FS.storage_cleanup怎么用?Python FS.storage_cleanup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jnpr.junos.utils.fs.FS
的用法示例。
在下文中一共展示了FS.storage_cleanup方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestFS
# 需要导入模块: from jnpr.junos.utils.fs import FS [as 别名]
# 或者: from jnpr.junos.utils.fs.FS import storage_cleanup [as 别名]
#.........这里部分代码省略.........
@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())
elif (
fname == "show-configuration.xml"
or fname == "show-system-alarms.xml"
or fname == "set-cli-working-directory.xml"
):
rpc_reply = NCElement(foo, self.dev._conn._device_handler.transform_reply())._NCElement__doc
else:
rpc_reply = NCElement(foo, self.dev._conn._device_handler.transform_reply())._NCElement__doc[0]
return rpc_reply
def _mock_manager(self, *args, **kwargs):
if kwargs:
# if 'path' in kwargs and 'detail' in kwargs:
# return self._read_file('dir_list_detail.xml')
if "path" in kwargs:
if kwargs["path"] == "test/stat/decode_dir":
return self._read_file("file-list_dir.xml")
elif kwargs["path"] == "test/stat/decode_file":
return self._read_file("file-list_file.xml")
elif kwargs["path"] == "test/checksum":
return self._read_file("checksum.xml")
elif kwargs["path"] == "test/stat/decode_symbolic_link":
return self._read_file("file-list_symlink.xml")
if "directory" in kwargs:
if kwargs["directory"] == "change/directory":
return self._read_file("set-cli-working-directory.xml")
if "filename" in kwargs:
if kwargs["filename"] == "test/cat.txt":
return self._read_file("file-show.xml")
device_params = kwargs["device_params"]
device_handler = make_device_handler(device_params)
session = SSHSession(device_handler)
return Manager(session, device_handler)
elif args:
if args[0].tag == "command":
if args[0].text == "show cli directory":
return self._read_file("show-cli-directory.xml")
elif args[0].tag == "get-system-storage":
return self._read_file("get-system-storage.xml")
elif args[0].tag == "get-directory-usage-information":
return self._read_file("get-directory-usage-information.xml")
elif args[0].tag == "request-system-storage-cleanup":
return self._read_file("request-system-storage-cleanup.xml")
elif args[0].tag == "file-archive":
return self._read_file("file-archive.xml")
示例2: TestFS
# 需要导入模块: from jnpr.junos.utils.fs import FS [as 别名]
# 或者: from jnpr.junos.utils.fs.FS import storage_cleanup [as 别名]
#.........这里部分代码省略.........
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",
depth=1)
@patch('jnpr.junos.Device.execute')
def test_directory_usage_no_directory(self, mock_execute):
mock_execute.side_effect = self._mock_manager_error1
self.assertRaises(
RpcError,
self.fs.directory_usage,
path="/var/tmp",
depth="1")
@patch('jnpr.junos.Device.execute')
def test_directory_usage_no_dir_name(self, mock_execute):
mock_execute.side_effect = self._mock_manager_error2
self.assertRaises(
RpcError,
self.fs.directory_usage,
path="/var/tmp",
depth="1")
@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())
elif (fname == 'show-configuration.xml' or
fname == 'show-system-alarms.xml' or
fname == 'set-cli-working-directory.xml'):
rpc_reply = NCElement(foo, self.dev._conn._device_handler
.transform_reply())._NCElement__doc
else:
rpc_reply = NCElement(foo, self.dev._conn._device_handler
.transform_reply())._NCElement__doc[0]
return rpc_reply