예제 #1
0
class TestHaproxyDriverRemoteInterface(unittest.TestCase):
    def setUp(self):
        self.remote_interface = RemoteInterface(device_fake, frontend)
        self.remote_interface.ssh = Mock()
        file_channel = MagicMock(spec=file)
        self.remote_interface.ssh.exec_command.return_value = [file_channel, file_channel, file_channel]

    def test_add_ip(self):
        self.assertTrue(self.remote_interface.add_ip())

    def test_del_ip(self):
        self.assertTrue(self.remote_interface.del_ip())
예제 #2
0
 def delete_virtual_ip(self, virtualserver):
     logger.debug('[HAPROXY] delete VIP')
     if not bool(virtualserver['name']):
         logger.error('[HAPROXY] Virtualserver name is empty')
         return 'VIRTUALSERVER NAME ERROR'
     haproxy_virtualserver = HaproxyFronted()
     haproxy_virtualserver.name = virtualserver['name']
     haproxy_virtualserver.bind_address = virtualserver['address']
     config_file = HaproxyConfigFile('%s/%s' % (self.localpath,
                                     self.configfilename))
     remote = RemoteConfig(self.device_ref, self.localpath,
                           self.remotepath, self.configfilename)
     #Check ip for using in the another frontend
     if not config_file.find_string_in_the_block('frontend',
         haproxy_virtualserver.bind_address):
         logger.debug('[HAPROXY] ip %s does not using in the other '
                              'frontend, delete it from remote interface' %
                               haproxy_virtualserver.bind_address)
         remote_interface = RemoteInterface(self.device_ref,
                                            haproxy_virtualserver)
         remote_interface.del_ip()
     remote.get_config()
     config_file.delete_block(haproxy_virtualserver)
     remote.put_config()
예제 #3
0
 def create_virtual_ip(self, virtualserver, serverfarm):
     if not bool(virtualserver['name']):
         logger.error('[HAPROXY] Virtualserver name is empty')
         return 'VIRTUALSERVER NAME ERROR'
     haproxy_virtualserver = HaproxyFronted()
     haproxy_virtualserver.name = virtualserver['name']
     haproxy_virtualserver.bind_address = virtualserver['address']
     haproxy_virtualserver.bind_port = virtualserver['port']
     haproxy_serverfarm = HaproxyBackend()
     haproxy_serverfarm.name = serverfarm['name']
     logger.debug('[HAPROXY] create VIP %s' % haproxy_serverfarm.name)
     #Add new IP address
     remote_interface = RemoteInterface(self.device_ref,
                                        haproxy_virtualserver)
     remote_interface.add_ip()
     #Modify remote config file, check and restart remote haproxy
     config_file = HaproxyConfigFile('%s/%s' % (self.localpath,
                                     self.configfilename))
     remote = RemoteConfig(self.device_ref, self.localpath,
                           self.remotepath, self.configfilename)
     remote.get_config()
     config_file.add_frontend(haproxy_virtualserver, haproxy_serverfarm)
     remote.put_config()
     remote.validate_config()
예제 #4
0
 def setUp(self):
     self.remote_interface = RemoteInterface(device_fake, frontend)
     self.remote_interface.ssh = Mock()
     file_channel = MagicMock(spec=file)
     self.remote_interface.ssh.exec_command.return_value = [file_channel, file_channel, file_channel]