Beispiel #1
0
 def test_state_listener(self):
     proto = ManagementProtocol()
     listener = StateListener()
     proto.addStateListener(listener)
     feed_the_protocol(proto, session1)
     states = [st.state for st in listener.states]
     assert states == ['AUTH', 'GET_CONFIG', 'ASSIGN_IP', 'CONNECTED']
Beispiel #2
0
 def test_parse_version_string(self):
     proto = ManagementProtocol()
     proto.transport = StringIO.StringIO()
     assert proto.openvpn_version == ''
     feed_the_protocol(proto, session1[2:4])
     proto.getVersion()
     feed_the_protocol(proto, ['END'])
     assert proto.openvpn_version.startswith('OpenVPN 2.4.0')
Beispiel #3
0
 def test_get_pid(self):
     proto = ManagementProtocol()
     proto.transport = StringIO.StringIO()
     assert proto.pid is None
     proto.getPid()
     pid_lines = ['SUCCESS: pid=99999']
     feed_the_protocol(proto, pid_lines)
     assert proto.pid == 99999
Beispiel #4
0
 def test_get_state_history(self):
     proto = ManagementProtocol()
     listener = StateListener()
     proto.addStateListener(listener)
     feed_the_protocol(proto, session1)
     log = listener.getStateHistory()
     states = [st.state for st in log]
     assert len(states) == 4
     assert states == ['AUTH', 'GET_CONFIG', 'ASSIGN_IP', 'CONNECTED']
Beispiel #5
0
 def test_bytecount_rate(self):
     proto = ManagementProtocol()
     proto.traffic.update(1024, 512, 1)
     proto.traffic.update(2048, 1024, 2)
     print proto.traffic._buf
     assert proto.traffic.down == 2048
     assert proto.traffic.up == 1024
     assert proto.traffic.get_rate() == ['1.0 K', '512.0 B']
Beispiel #6
0
 def connect_to_management(path):
     # XXX this has a problem with connections to different
     # remotes. So the reconnection will only work when we are
     # terminating instances left running for the same provider.
     # If we are killing an openvpn instance configured for another
     # provider, we will get:
     # TLS Error: local/remote TLS keys are out of sync
     # However, that should be a rare case right now.
     endpoint = clientFromString(reactor, path)
     d = connectProtocol(endpoint, ManagementProtocol(verbose=False))
     d.addCallback(gotProtocol)
     return d
Beispiel #7
0
    def test_get_info(self):
        proto = ManagementProtocol()
        proto.transport = StringIO.StringIO()
        feed_the_protocol(proto, session1)

        feed_the_protocol(proto, session1[2:4])
        proto.getVersion()
        feed_the_protocol(proto, ['END'])
        proto.getPid()
        pid_lines = ['SUCCESS: pid=23783']
        feed_the_protocol(proto, pid_lines)

        info = proto.getInfo()
        assert info['remote'] == '46.165.242.169'
        assert info['rport'] == '443'
        assert info['openvpn_version'].startswith('OpenVPN 2.4.0')
        assert info['pid'] == 23783
Beispiel #8
0
    def _connect_to_management(self, retries=30):
        if retries == 0:
            self.log.error('Timeout while connecting to management')
            self.failed = True
            return

        def retry(retries):
            ctr = retries - 1
            self.log.warn('Error connecting to management, retrying. '
                          'Retries left:  %s' % ctr)
            reactor.callLater(0.1, self._connect_to_management, ctr)

        self._d = connectProtocol(self._management_endpoint,
                                  ManagementProtocol(verbose=True))
        self._d.addCallbacks(self._got_management_protocol,
                             lambda f: retry(retries))
Beispiel #9
0
 def test_bytecount(self):
     proto = ManagementProtocol()
     feed_the_protocol(proto, session1)
     assert proto.traffic.down == 17168
     assert proto.traffic.up == 7657
Beispiel #10
0
 def test_final_state_stopping(self):
     proto = ManagementProtocol()
     feed_the_protocol(proto, session2)
     assert proto.state.state == 'EXITING'
     assert proto.state.simple == 'STOPPING'
Beispiel #11
0
 def test_final_state_is_connected(self):
     proto = ManagementProtocol()
     feed_the_protocol(proto, session1)
     assert proto.state.state == 'CONNECTED'
     assert proto.state.simple == 'ON'
     assert proto.remote == '46.165.242.169'