Exemple #1
0
 def _calculate_message(self, value):
     formatted_value = self._format(value)
     data_length = len(formatted_value)
     response = struct.pack(
         self.RESPONSE_FORMAT.format(data_length=data_length), self.HEADER,
         data_length, b(formatted_value))
     return response
Exemple #2
0
 def _calculate_message(self, value):
     formatted_value = self._format(value)
     data_length = len(formatted_value)
     response = struct.pack(
         self.RESPONSE_FORMAT.format(data_length=data_length),
         self.HEADER,
         data_length,
         b(formatted_value)
     )
     return response
Exemple #3
0
 def test_receive_key_zbxd(self):
     sent_key = KEY
     self.client.recv.side_effect = [
         self.protocol.HEADER,
         struct.pack('q', len(sent_key)),
         b(sent_key)
     ]
     received_key = self.protocol.receive_value(self.client)
     assert_is_instance(received_key, string_types)
     assert_equal(u(sent_key), received_key)
Exemple #4
0
 def test_not_running_if_server_message_does_not_match_expectations(self):
     self.mock_tcp_communication.return_value = [b('SSH\n')]
     running = bool(tcp.service(self.service_name))
     assert_false(running)
Exemple #5
0
 def test_running_if_server_message_matches_expectations(self):
     self.mock_tcp_communication.return_value = [
         b('SSH-2.0-OpenSSH_6.0p1 Debian-4\n')]
     running = bool(tcp.service(self.service_name))
     assert_true(running)
Exemple #6
0
 def _passwd(self, username):
     pointer_to_passwd = _libc.getpwnam(b(username))
     if pointer_to_passwd:
         return pointer_to_passwd[0]
     else:
         raise OperatingSystemError('Invalid name: {0}'.format(username))
Exemple #7
0
        f = sh(COMMAND, raise_on_nonempty_err=True)
        assert_raises(OperatingSystemError, f)

    def test_communicate_with_completed_process(self):
        sh(COMMAND)()
        self.process.communicate.assert_called_once_with()

    def test_communicate_with_timed_out_process(self):
        self.process.poll.return_value = None
        command = sh(COMMAND, timeout=10.0)
        assert_raises(OperatingSystemError, command)
        self.process.communicate.assert_called_once_with()


PORT = 8080
REQUEST = b('')


class TestTcpCommunication():
    def setup(self):
        self._patcher_socket = patch('zabby.core.utils.socket')

        self.conn = Mock()
        self.mock_socket = self._patcher_socket.start()
        self.mock_socket.create_connection.return_value = self.conn

    def teardown(self):
        self._patcher_socket.stop()

    def test_raises_exception_for_non_binary_requests(self):
        assert_raises(WrongArgumentError,
Exemple #8
0
        self.process.poll.return_value = None

        command = sh(COMMAND, timeout=10.0)
        assert_raises(OperatingSystemError, command)

    def test_does_not_raise_exception_if_poll_eventually_succeed(self):
        self.process.poll.side_effect = [None, 0]

        wait_step = 0.1
        sh(COMMAND, timeout=10.0, wait_step=wait_step)()

        self.mock_time.sleep.assert_called_with(wait_step)


PORT = 8080
REQUEST = b('')


class TestTcpCommunication():
    def setup(self):
        self._patcher_socket = patch('zabby.core.utils.socket')

        self.conn = Mock()
        self.mock_socket = self._patcher_socket.start()
        self.mock_socket.create_connection.return_value = self.conn

    def teardown(self):
        self._patcher_socket.stop()

    def test_raises_exception_for_non_binary_requests(self):
        assert_raises(WrongArgumentError, tcp_communication, PORT,
Exemple #9
0
 def _passwd(self, username):
     pointer_to_passwd = _libc.getpwnam(b(username))
     if pointer_to_passwd:
         return pointer_to_passwd[0]
     else:
         raise OperatingSystemError('Invalid name: {0}'.format(username))