class TestHaproxyDriverRemoteSocketOperation(unittest.TestCase):
    def setUp(self):
        self.remote_socket = RemoteSocketOperation(device_fake, backend, rserver)
        self.remote_socket.ssh = Mock()
        file_channel = MagicMock(spec=file)
        self.remote_socket.ssh.exec_command.return_value = [file_channel, file_channel, file_channel]

    def test_suspend_server(self):
        self.assertTrue(self.remote_socket.suspend_server())

    def test_activate_server(self):
        self.assertTrue(self.remote_socket.activate_server())

    def test_get_statistics(self):
        self.assertTrue(self.remote_socket.get_statistics())
 def setUp(self):
     self.remote_socket = RemoteSocketOperation(device_fake,
                                             backend, rserver)
     self.remote_socket.ssh = Mock()
     file_channel = MagicMock(spec=file)
     self.remote_socket.ssh.exec_command.return_value = [file_channel,
                                             file_channel, file_channel]
 def operationWithRServer(self, serverfarm, rserver,
                          type_of_operation):
     haproxy_rserver = HaproxyRserver()
     haproxy_rserver.name = rserver['name']
     haproxy_serverfarm = HaproxyBackend()
     haproxy_serverfarm.name = serverfarm['name']
     config_file = HaproxyConfigFile('%s/%s' % (self.localpath,
                                     self.configfilename))
     remote_config = RemoteConfig(self.device_ref, self.localpath,
                                  self.remotepath, self.configfilename)
     remote_socket = RemoteSocketOperation(self.device_ref,
                                     haproxy_serverfarm, haproxy_rserver,
                                     self.interface, self.haproxy_socket)
     remote_config.get_config()
     if type_of_operation == 'suspend':
         config_file.enable_disable_reserver_in_backend_block(
                          haproxy_serverfarm, haproxy_rserver, 'disable')
         remote_socket.suspend_server()
     elif type_of_operation == 'activate':
         config_file.enable_disable_reserver_in_backend_block(
                          haproxy_serverfarm, haproxy_rserver, 'enable')
         remote_socket.activate_server()
     remote_config.put_config()
    def get_statistics(self, serverfarm, rserver):
        haproxy_rserver = HaproxyRserver()
        haproxy_rserver.name = rserver['name']
        haproxy_serverfarm = HaproxyBackend()
        haproxy_serverfarm.name = serverfarm['name']
        remote_socket = RemoteSocketOperation(self.device_ref,
                                        haproxy_serverfarm, haproxy_rserver,
                                        self.interface, self.haproxy_socket)
        out = remote_socket.get_statistics()
        statistics = {}
        if out:
            status_line = out.split(",")
            statistics['weight'] = status_line[18]
            statistics['state'] = status_line[17]
            statistics['connCurrent'] = [4]
            statistics['connTotal'] = [7]
            statistics['connFail'] = [13]
            statistics['connMax'] = [5]
            statistics['connRateLimit'] = [34]
            statistics['bandwRateLimit'] = [35]
# NOTE: broken because use indeterminate state variable
#        logger.debug('[HAPROXY] statistics rserver state is \'%s\'',
#                statistics.state)
        return statistics