Skip to content

Commit 9a3b85f

Browse files
committed
Clean useless class attributes out of VPN model
1 parent 747cff5 commit 9a3b85f

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

openvpn_api/vpn.py

+2-12
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,6 @@ class VPNType:
1919

2020

2121
class VPN:
22-
_mgmt_host = None # Management interface host
23-
_mgmt_port = None # Management interface port
24-
_mgmt_socket = None # Management interface UNIX socket
25-
_type: Optional[str] = None # VPNType object to choose between IP (host:port) and socket
26-
_socket = None
27-
28-
_release = None # OpenVPN release string
29-
_state = None # State object
30-
stats = ServerStats() # Stats object
31-
sessions = [] # Client sessions
32-
3322
def __init__(self, host: Optional[str] = None, port: Optional[int] = None, socket: Optional[str] = None):
3423
if (socket and host) or (socket and port) or (not socket and not host and not port):
3524
raise errors.VPNError("Must specify either socket or host and port")
@@ -40,6 +29,8 @@ def __init__(self, host: Optional[str] = None, port: Optional[int] = None, socke
4029
self._mgmt_host = host
4130
self._mgmt_port = port
4231
self._type = VPNType.IP
32+
self._socket = None
33+
self.clear_cache() # Initialise release info and daemon state caches
4334

4435
@property
4536
def type(self) -> Optional[str]:
@@ -62,7 +53,6 @@ def connect(self) -> Optional[bool]:
6253
try:
6354
if self.type == VPNType.IP:
6455
self._socket = socket.create_connection((self._mgmt_host, self._mgmt_port), timeout=3)
65-
6656
else:
6757
self._socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
6858
self._socket.connect(self._mgmt_socket)

tests/test_vpn_model.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,21 @@ def test_host_port(self):
3535
vpn = VPN(host="localhost", port=1234)
3636
self.assertEqual(vpn._mgmt_host, "localhost")
3737
self.assertEqual(vpn._mgmt_port, 1234)
38-
self.assertIsNone(vpn._mgmt_socket)
3938
self.assertEqual(vpn.type, VPNType.IP)
4039
self.assertEqual(vpn.mgmt_address, "localhost:1234")
4140

4241
def test_socket(self):
4342
vpn = VPN(socket="file.sock")
4443
self.assertEqual(vpn._mgmt_socket, "file.sock")
45-
self.assertIsNone(vpn._mgmt_host)
46-
self.assertIsNone(vpn._mgmt_port)
4744
self.assertEqual(vpn.type, VPNType.UNIX_SOCKET)
4845
self.assertEqual(vpn.mgmt_address, "file.sock")
4946

47+
def test_initialisation(self):
48+
vpn = VPN(socket="file.sock")
49+
self.assertIsNone(vpn._release)
50+
self.assertIsNone(vpn._state)
51+
self.assertIsNone(vpn._socket)
52+
5053
@patch("openvpn_api.vpn.socket.create_connection")
5154
def test_connect_ip_failure(self, mock_create_connection):
5255
vpn = VPN(host="localhost", port=1234)

0 commit comments

Comments
 (0)