小编san*_*dra的帖子

在 systemd 中停止服务之前卸载文件系统

我正在调试 systemd 关闭问题。这里的问题是一些文件系统在服务仍在运行时被卸载。

一般来说,我们希望systemd先关闭服务,然后卸载挂载点。

但在这里,卸载和停止服务是并行发生的。(见下文)。首先还要卸载根文件系统。

#        Unmounting /root...
         Unmounting /var/lib/ntp...
         Unmounting /etc/cron.d/local...
[  OK  ] Stopped Apply Kernel Variables.
         Unmounting /proc/fs/nfsd...
         Unmounting /tmp/rshell/trace...
         Stopping Availability of block devices...
         Unmounting /etc/timestamp...
         Unmounting /var/lib/nfs/rpc_pipefs...
         Unmounting /etc/sysconfig/clock...
[  OK  ] Removed slice system-getty.slice.
[  OK  ] Stopped Load Kernel Modules.
         Unmounting /etc/ssh/ssh_external_host_rsa_key...
[  OK  ] Stopped Create Static Device Nodes in /dev.
         Unmounting /mnt/log...
[  OK  ] Stopped Resets System Activity Logs.
         Stopping Crond Periodic Command Scheduler...
[  OK  ] Stopped Mount Restricted …
Run Code Online (Sandbox Code Playgroud)

linux system-dependent system-shutdown systemd

9
推荐指数
1
解决办法
6868
查看次数

如何在python中模拟依赖

我是 python 单元测试框架的新手,在模拟依赖方面有很多困惑。

我正在尝试为类的以下成员函数((check_something())编写单元测试:

class Validations:    
    def check_something(self):
        abc = os.environ['PLATFORM']
        xyz = Node()
        no_of_nodes = len(xyz.some_type_var)
        if abc != "X_PLATFORM" or no_of_nodes != 1:
            raise someException()
Run Code Online (Sandbox Code Playgroud)

我们如何消除依赖?

  1. 需要嘲笑Node()吗?
  2. 我们如何确保abc分配了X_PLATFORM
  3. 如何给1变量赋值no_of_nodes?这反过来又是从Node()对象派生的。

    class Node(object):
        def __init__(self):
            self.nodes = DEF()
            self.some_type_var = someclass().getType()
            self.localnode = os.environ['HOSTNAME']
            self.peertype = self.get_peer_type()
    
        def get_peer_type(self):
            return node
    
    Run Code Online (Sandbox Code Playgroud)

我试着在单元测试下面写。我无法检查失败和通过条件。我不确定它是否正确。

class TestValidation(unittest.TestCase):

    @mock.patch.object(Node, "get_peer_type")
    @mock.patch('somefile.Node', spec=True)
    def test_1(self, mock_object1, mock_object2):
        os.environ['PLATFORM'] = 'X_PLATFORM'
        obj …
Run Code Online (Sandbox Code Playgroud)

python unit-testing mocking

3
推荐指数
1
解决办法
4727
查看次数

shlex.split() 将整个命令作为单个字符串返回

shlex.split() 没有在输入字符串上提供正确的输出。

在 python 解释器中,将输入值存储在变量中会产生预期的输出。

但是如果我通过脚本执行,shlex.split()输出不正确,输入字符串没有在空格上拆分。

>>> import shlex

>>> var = "/usr/bin/ansible-playbook --timeout=60 --module-path /var/sandeep> /playbooks/ --extra-vars '{ \"text\": \"DUMMY\", \"addition\": [\"1\", \"2\", \"3\", ], \"deletion\": [], \"update\": \"update\", \"path\": \"/var/sandeep\", }' /tmp/sandeep//tmp/example.yaml"
>>>
>>>
>>> shlex.split(var)

['/usr/bin/ansible-playbook', '--timeout=60', '--module-path', '/var/sandeep/playbooks/', '--extra-vars', '{ "text": "DUMMY", "addition": ["1", "2", "3", ], "deletion": [], "update": "update", "path": "/var/sandeep", }', '/tmp/sandeep//tmp/example.yaml']
Run Code Online (Sandbox Code Playgroud)
def create_extra(text, extra_dict):
    extra = "'{{ \\\"text\\\": \\\"{}\\\", ".format(text)
    for key, value in extra_dict.items():
        if isinstance(value, list):
            extra += …
Run Code Online (Sandbox Code Playgroud)

python string shlex python-3.6

0
推荐指数
1
解决办法
972
查看次数

bash 中## 和 %% 的功能是什么

disk="/dev/sda"
local dev_node=${disk##*/}
Run Code Online (Sandbox Code Playgroud)

dev_node 被分配了“sda”。

还,

partition="/dev/sda3"
echo ${partition%%[0-9]*}
Run Code Online (Sandbox Code Playgroud)

它返回 /dev/sda 并删除 3。

我不明白上面命令中 ##*/ 和 %%[0-9]* 的功能。我尝试搜索但无法获得足够的信息。

请解释并提供与此相关的教程的任何链接。

linux string bash

-1
推荐指数
1
解决办法
3701
查看次数