class TestHaproxyDriverRemoteConfig(unittest.TestCase):
    def setUp(self):
        self.remote_config = RemoteConfig(device_fake, "/tmp", "/etc/haproxy", "haproxy.conf")
        self.remote_config.ssh = Mock()

    def test_get_config(self):
        self.assertTrue(self.remote_config.get_config())

    def test_put_config(self):
        self.assertTrue(self.remote_config.put_config())

    def test_validate_config_bad(self):
        file_channel = MagicMock(spec=file)
        self.remote_config.ssh.exec_command.return_value = [file_channel, file_channel, file_channel]
        self.assertFalse(self.remote_config.validate_config())
 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()