utils.py (1740:53149d20bb97) utils.py (1772:03a6609f2c5e)
1import os
2import socket
1import os
2import socket
3import subprocess
3import time
4
5import pytest
6
7
8def public_dir(path):
9 os.chmod(path, 0o777)
10

--- 33 unchanged lines hidden (view full) ---

44 time.sleep(0.1)
45
46 except KeyboardInterrupt:
47 raise
48
49 pytest.fail('Can\'t connect to the 127.0.0.1:' + port)
50
51
4import time
5
6import pytest
7
8
9def public_dir(path):
10 os.chmod(path, 0o777)
11

--- 33 unchanged lines hidden (view full) ---

45 time.sleep(0.1)
46
47 except KeyboardInterrupt:
48 raise
49
50 pytest.fail('Can\'t connect to the 127.0.0.1:' + port)
51
52
53def findmnt():
54 try:
55 out = subprocess.check_output(
56 ['findmnt', '--raw'], stderr=subprocess.STDOUT
57 ).decode()
58 except FileNotFoundError:
59 pytest.skip('requires findmnt')
60
61 return out
62
63
64def waitformount(template, wait=50):
65 for i in range(wait):
66 if findmnt().find(template) != -1:
67 return True
68
69 time.sleep(0.1)
70
71 return False
72
73
74def waitforunmount(template, wait=50):
75 for i in range(wait):
76 if findmnt().find(template) == -1:
77 return True
78
79 time.sleep(0.1)
80
81 return False
82
83
52def getns(nstype):
53 # read namespace id from symlink file:
54 # it points to: '<nstype>:[<ns id>]'
55 # # eg.: 'pid:[4026531836]'
56 nspath = '/proc/self/ns/' + nstype
57 data = None
58
59 if os.path.exists(nspath):
60 data = int(os.readlink(nspath)[len(nstype) + 2 : -1])
61
62 return data
84def getns(nstype):
85 # read namespace id from symlink file:
86 # it points to: '<nstype>:[<ns id>]'
87 # # eg.: 'pid:[4026531836]'
88 nspath = '/proc/self/ns/' + nstype
89 data = None
90
91 if os.path.exists(nspath):
92 data = int(os.readlink(nspath)[len(nstype) + 2 : -1])
93
94 return data