示例#1
0
    def setUp(self):
        super(TestHaproxyAmphoraLoadBalancerDriverTest, self).setUp()

        DEST1 = '198.51.100.0/24'
        DEST2 = '203.0.113.0/24'
        NEXTHOP = '192.0.2.1'

        self.driver = driver.HaproxyAmphoraLoadBalancerDriver()

        self.driver.cert_manager = mock.MagicMock()
        self.driver.cert_parser = mock.MagicMock()
        self.driver.client = mock.MagicMock()
        self.driver.jinja = mock.MagicMock()
        self.driver.udp_jinja = mock.MagicMock()

        # Build sample Listener and VIP configs
        self.sl = sample_configs.sample_listener_tuple(tls=True, sni=True)
        self.sl_udp = sample_configs.sample_listener_tuple(
            proto=constants.PROTOCOL_UDP,
            persistence_type=constants.SESSION_PERSISTENCE_SOURCE_IP,
            persistence_timeout=33,
            persistence_granularity='255.255.0.0',
            monitor_proto=constants.HEALTH_MONITOR_UDP_CONNECT)
        self.amp = self.sl.load_balancer.amphorae[0]
        self.sv = sample_configs.sample_vip_tuple()
        self.lb = self.sl.load_balancer
        self.fixed_ip = mock.MagicMock()
        self.fixed_ip.ip_address = '198.51.100.5'
        self.fixed_ip.subnet.cidr = '198.51.100.0/24'
        self.network = network_models.Network(mtu=FAKE_MTU)
        self.port = network_models.Port(mac_address=FAKE_MAC_ADDRESS,
                                        fixed_ips=[self.fixed_ip],
                                        network=self.network)

        self.host_routes = [
            network_models.HostRoute(destination=DEST1, nexthop=NEXTHOP),
            network_models.HostRoute(destination=DEST2, nexthop=NEXTHOP)
        ]
        host_routes_data = [{
            'destination': DEST1,
            'nexthop': NEXTHOP
        }, {
            'destination': DEST2,
            'nexthop': NEXTHOP
        }]
        self.subnet_info = {
            'subnet_cidr': FAKE_CIDR,
            'gateway': FAKE_GATEWAY,
            'mac_address': FAKE_MAC_ADDRESS,
            'vrrp_ip': self.amp.vrrp_ip,
            'mtu': FAKE_MTU,
            'host_routes': host_routes_data
        }

        self.timeout_dict = {
            constants.REQ_CONN_TIMEOUT: 1,
            constants.REQ_READ_TIMEOUT: 2,
            constants.CONN_MAX_RETRIES: 3,
            constants.CONN_RETRY_INTERVAL: 4
        }
示例#2
0
    def test_update(self):
        with mock.patch.object(self.driver, "_process_tls_certificates") as process_tls_patch:
            with mock.patch.object(jinja_cfg.JinjaTemplater, "build_config") as build_conf:
                # Build sample Listener and VIP configs
                listener = sample_configs.sample_listener_tuple(tls=True, sni=True)
                vip = sample_configs.sample_vip_tuple()

                process_tls_patch.return_value = {
                    "tls_cert": listener.default_tls_container,
                    "sni_certs": listener.sni_containers,
                }
                build_conf.return_value = "sampleConfig"

                # Execute driver method
                self.driver.update(listener, vip)

                # Verify calls
                process_tls_patch.assert_called_once_with(listener)
                build_conf.assert_called_once_with(listener, listener.default_tls_container)
                self.driver.client.connect.assert_called_once_with(
                    hostname=listener.load_balancer.amphorae[0].lb_network_ip,
                    key_filename=self.driver.amp_config.key_path,
                    username=self.driver.amp_config.username,
                )
                self.driver.client.open_sftp.assert_called_once_with()
                self.driver.client.open_sftp().put.assert_called_once_with(mock.ANY, mock.ANY)
                self.driver.client.exec_command.assert_has_calls(
                    [mock.call(mock.ANY), mock.call(mock.ANY), mock.call(mock.ANY), mock.call(mock.ANY)]
                )
                self.driver.client.close.assert_called_once_with()
示例#3
0
    def setUp(self):
        super(TestHaproxyAmphoraLoadBalancerDriverTest, self).setUp()

        conf = oslo_fixture.Config(cfg.CONF)
        conf.config(group="haproxy_amphora", user_group="everyone")

        DEST1 = '198.51.100.0/24'
        DEST2 = '203.0.113.0/24'
        NEXTHOP = '192.0.2.1'

        self.driver = driver.HaproxyAmphoraLoadBalancerDriver()

        self.driver.cert_manager = mock.MagicMock()
        self.driver.cert_parser = mock.MagicMock()
        self.driver.client = mock.MagicMock()
        self.driver.jinja = mock.MagicMock()

        # Build sample Listener and VIP configs
        self.sl = sample_configs.sample_listener_tuple(tls=True, sni=True)
        self.amp = self.sl.load_balancer.amphorae[0]
        self.sv = sample_configs.sample_vip_tuple()
        self.lb = self.sl.load_balancer
        self.fixed_ip = mock.MagicMock()
        self.fixed_ip.ip_address = '198.51.100.5'
        self.fixed_ip.subnet.cidr = '198.51.100.0/24'
        self.network = network_models.Network(mtu=FAKE_MTU)
        self.port = network_models.Port(mac_address=FAKE_MAC_ADDRESS,
                                        fixed_ips=[self.fixed_ip],
                                        network=self.network)

        self.host_routes = [
            network_models.HostRoute(destination=DEST1, nexthop=NEXTHOP),
            network_models.HostRoute(destination=DEST2, nexthop=NEXTHOP)
        ]
        host_routes_data = [{
            'destination': DEST1,
            'nexthop': NEXTHOP
        }, {
            'destination': DEST2,
            'nexthop': NEXTHOP
        }]
        self.subnet_info = {
            'subnet_cidr': FAKE_CIDR,
            'gateway': FAKE_GATEWAY,
            'mac_address': FAKE_MAC_ADDRESS,
            'vrrp_ip': self.amp.vrrp_ip,
            'mtu': FAKE_MTU,
            'host_routes': host_routes_data
        }

        self.timeout_dict = {
            constants.REQ_CONN_TIMEOUT: 1,
            constants.REQ_READ_TIMEOUT: 2,
            constants.CONN_MAX_RETRIES: 3,
            constants.CONN_RETRY_INTERVAL: 4
        }
示例#4
0
 def setUp(self, mock_session):
     super(TestSshDriver, self).setUp()
     mock.MagicMock(keystone.get_session())
     self.driver = ssh_driver.HaproxyManager()
     self.listener = sample_configs.sample_listener_tuple()
     self.vip = sample_configs.sample_vip_tuple()
     self.amphora = models.Amphora()
     self.amphora.id = self.FAKE_UUID_1
     self.driver.cert_manager = mock.Mock(spec=cert_mgr.CertManager)
     self.driver.client = mock.Mock(spec=paramiko.SSHClient)
     self.driver.client.exec_command.return_value = (mock.Mock(), mock.Mock(), mock.Mock())
     self.driver.amp_config = mock.MagicMock()
     self.port = network_models.Port(mac_address="123")
示例#5
0
    def setUp(self):
        super(HaproxyAmphoraLoadBalancerDriverTest, self).setUp()
        self.driver = driver.HaproxyAmphoraLoadBalancerDriver()

        self.driver.cert_manager = mock.MagicMock()
        self.driver.client = mock.MagicMock()
        self.driver.jinja = mock.MagicMock()

        # Build sample Listener and VIP configs
        self.sl = sample_configs.sample_listener_tuple(tls=True, sni=True)
        self.amp = self.sl.load_balancer.amphorae[0]
        self.sv = sample_configs.sample_vip_tuple()
        self.lb = self.sl.load_balancer
        self.port = network_models.Port(mac_address='123')
示例#6
0
    def setUp(self):
        super(HaproxyAmphoraLoadBalancerDriverTest, self).setUp()
        self.driver = driver.HaproxyAmphoraLoadBalancerDriver()

        self.driver.cert_manager = mock.MagicMock()
        self.driver.cert_parser = mock.MagicMock()
        self.driver.client = mock.MagicMock()
        self.driver.jinja = mock.MagicMock()

        # Build sample Listener and VIP configs
        self.sl = sample_configs.sample_listener_tuple(tls=True, sni=True)
        self.amp = self.sl.load_balancer.amphorae[0]
        self.sv = sample_configs.sample_vip_tuple()
        self.lb = self.sl.load_balancer
        self.port = network_models.Port(mac_address='123')
示例#7
0
 def setUp(self, mock_session):
     super(TestSshDriver, self).setUp()
     mock.MagicMock(keystone.get_session())
     self.driver = ssh_driver.HaproxyManager()
     self.listener = sample_configs.sample_listener_tuple()
     self.vip = sample_configs.sample_vip_tuple()
     self.amphora = models.Amphora()
     self.amphora.id = self.FAKE_UUID_1
     self.driver.cert_manager = mock.Mock(
         spec=cert_mgr.CertManager)
     self.driver.client = mock.Mock(spec=paramiko.SSHClient)
     self.driver.client.exec_command.return_value = (
         mock.Mock(), mock.Mock(), mock.Mock())
     self.driver.amp_config = mock.MagicMock()
     self.port = network_models.Port(mac_address='123')
示例#8
0
    def test_start(self):
        # Build sample Listener and VIP configs
        listener = sample_configs.sample_listener_tuple(
            tls=True, sni=True)
        vip = sample_configs.sample_vip_tuple()

        # Execute driver method
        self.driver.start(listener, vip)
        self.driver.client.connect.assert_called_once_with(
            hostname=listener.load_balancer.amphorae[0].lb_network_ip,
            key_filename=self.driver.amp_config.key_path,
            username=self.driver.amp_config.username)
        self.driver.client.exec_command.assert_called_once_with(
            'sudo haproxy -f {0}/{1}/haproxy.cfg -p {0}/{1}/{1}.pid'.format(
                self.driver.amp_config.base_path, listener.id))
        self.driver.client.close.assert_called_once_with()
示例#9
0
    def test_start(self):
        # Build sample Listener and VIP configs
        listener = sample_configs.sample_listener_tuple(
            tls=True, sni=True)
        vip = sample_configs.sample_vip_tuple()

        # Execute driver method
        self.driver.start(listener, vip)
        self.driver.client.connect.assert_called_once_with(
            hostname=listener.load_balancer.amphorae[0].lb_network_ip,
            key_filename=self.driver.amp_config.key_path,
            username=self.driver.amp_config.username)
        self.driver.client.exec_command.assert_called_once_with(
            'sudo haproxy -f {0}/{1}/haproxy.cfg -p {0}/{1}/{1}.pid'.format(
                self.driver.amp_config.base_path, listener.id))
        self.driver.client.close.assert_called_once_with()
示例#10
0
    def setUp(self):
        super(TestHaproxyAmphoraLoadBalancerDriverTest, self).setUp()

        DEST1 = '198.51.100.0/24'
        DEST2 = '203.0.113.0/24'
        NEXTHOP = '192.0.2.1'

        self.driver = driver.HaproxyAmphoraLoadBalancerDriver()

        self.driver.cert_manager = mock.MagicMock()
        self.driver.cert_parser = mock.MagicMock()
        self.driver.client = mock.MagicMock()
        self.driver.jinja = mock.MagicMock()

        # Build sample Listener and VIP configs
        self.sl = sample_configs.sample_listener_tuple(tls=True, sni=True)
        self.amp = self.sl.load_balancer.amphorae[0]
        self.sv = sample_configs.sample_vip_tuple()
        self.lb = self.sl.load_balancer
        self.fixed_ip = mock.MagicMock()
        self.fixed_ip.ip_address = '198.51.100.5'
        self.fixed_ip.subnet.cidr = '198.51.100.0/24'
        self.network = network_models.Network(mtu=FAKE_MTU)
        self.port = network_models.Port(mac_address=FAKE_MAC_ADDRESS,
                                        fixed_ips=[self.fixed_ip],
                                        network=self.network)

        self.host_routes = [
            network_models.HostRoute(destination=DEST1, nexthop=NEXTHOP),
            network_models.HostRoute(destination=DEST2, nexthop=NEXTHOP)
        ]
        host_routes_data = [{
            'destination': DEST1,
            'nexthop': NEXTHOP
        }, {
            'destination': DEST2,
            'nexthop': NEXTHOP
        }]
        self.subnet_info = {
            'subnet_cidr': FAKE_CIDR,
            'gateway': FAKE_GATEWAY,
            'mac_address': FAKE_MAC_ADDRESS,
            'vrrp_ip': self.amp.vrrp_ip,
            'mtu': FAKE_MTU,
            'host_routes': host_routes_data
        }
示例#11
0
    def setUp(self):
        super(TestHaproxyAmphoraLoadBalancerDriverTest, self).setUp()

        DEST1 = '198.51.100.0/24'
        DEST2 = '203.0.113.0/24'
        NEXTHOP = '192.0.2.1'

        self.driver = driver.HaproxyAmphoraLoadBalancerDriver()

        self.driver.cert_manager = mock.MagicMock()
        self.driver.cert_parser = mock.MagicMock()
        self.driver.client = mock.MagicMock()
        self.driver.jinja = mock.MagicMock()

        # Build sample Listener and VIP configs
        self.sl = sample_configs.sample_listener_tuple(tls=True, sni=True)
        self.amp = self.sl.load_balancer.amphorae[0]
        self.sv = sample_configs.sample_vip_tuple()
        self.lb = self.sl.load_balancer
        self.fixed_ip = mock.MagicMock()
        self.fixed_ip.ip_address = '198.51.100.5'
        self.fixed_ip.subnet.cidr = '198.51.100.0/24'
        self.network = network_models.Network(mtu=FAKE_MTU)
        self.port = network_models.Port(mac_address=FAKE_MAC_ADDRESS,
                                        fixed_ips=[self.fixed_ip],
                                        network=self.network)

        self.host_routes = [network_models.HostRoute(destination=DEST1,
                                                     nexthop=NEXTHOP),
                            network_models.HostRoute(destination=DEST2,
                                                     nexthop=NEXTHOP)]
        host_routes_data = [{'destination': DEST1, 'nexthop': NEXTHOP},
                            {'destination': DEST2, 'nexthop': NEXTHOP}]
        self.subnet_info = {'subnet_cidr': FAKE_CIDR,
                            'gateway': FAKE_GATEWAY,
                            'mac_address': FAKE_MAC_ADDRESS,
                            'vrrp_ip': self.amp.vrrp_ip,
                            'mtu': FAKE_MTU,
                            'host_routes': host_routes_data}
示例#12
0
    def test_update(self):
        with mock.patch.object(
                self.driver, '_process_tls_certificates') as process_tls_patch:
            with mock.patch.object(jinja_cfg.JinjaTemplater,
                                   'build_config') as build_conf:
                # Build sample Listener and VIP configs
                listener = sample_configs.sample_listener_tuple(tls=True,
                                                                sni=True)
                vip = sample_configs.sample_vip_tuple()

                process_tls_patch.return_value = {
                    'tls_cert': listener.default_tls_container,
                    'sni_certs': listener.sni_containers
                }
                build_conf.return_value = 'sampleConfig'

                # Execute driver method
                self.driver.update(listener, vip)

                # Verify calls
                process_tls_patch.assert_called_once_with(listener)
                build_conf.assert_called_once_with(
                    listener, listener.default_tls_container)
                self.driver.client.connect.assert_called_once_with(
                    hostname=listener.load_balancer.amphorae[0].lb_network_ip,
                    key_filename=self.driver.amp_config.key_path,
                    username=self.driver.amp_config.username)
                self.driver.client.open_sftp.assert_called_once_with()
                self.driver.client.open_sftp().put.assert_called_once_with(
                    mock.ANY, mock.ANY
                )
                self.driver.client.exec_command.assert_has_calls([
                    mock.call(mock.ANY),
                    mock.call(mock.ANY),
                    mock.call(mock.ANY),
                    mock.call(mock.ANY)
                ])
                self.driver.client.close.assert_called_once_with()
示例#13
0
    def test_delete(self):

        # Build sample Listener and VIP configs
        listener = sample_configs.sample_listener_tuple(
            tls=True, sni=True)
        vip = sample_configs.sample_vip_tuple()

        # Execute driver method
        self.driver.delete(listener, vip)

        # Verify call
        self.driver.client.connect.assert_called_once_with(
            hostname=listener.load_balancer.amphorae[0].lb_network_ip,
            key_filename=self.driver.amp_config.key_path,
            username=self.driver.amp_config.username)
        exec_command_calls = [
            mock.call('sudo kill -9 $(cat {0}/sample_listener_id_1'
                      '/sample_listener_id_1.pid)'
                      .format(self.driver.amp_config.base_path)),
            mock.call('sudo rm -rf {0}/sample_listener_id_1'.format(
                      self.driver.amp_config.base_path))]
        self.driver.client.exec_command.assert_has_calls(exec_command_calls)
        self.driver.client.close.assert_called_once_with()
示例#14
0
    def test_delete(self):

        # Build sample Listener and VIP configs
        listener = sample_configs.sample_listener_tuple(
            tls=True, sni=True)
        vip = sample_configs.sample_vip_tuple()

        # Execute driver method
        self.driver.delete(listener, vip)

        # Verify call
        self.driver.client.connect.assert_called_once_with(
            hostname=listener.load_balancer.amphorae[0].lb_network_ip,
            key_filename=self.driver.amp_config.key_path,
            username=self.driver.amp_config.username)
        exec_command_calls = [
            mock.call('sudo kill -9 $(cat {0}/sample_listener_id_1'
                      '/sample_listener_id_1.pid)'
                      .format(self.driver.amp_config.base_path)),
            mock.call('sudo rm -rf {0}/sample_listener_id_1'.format(
                      self.driver.amp_config.base_path))]
        self.driver.client.exec_command.assert_has_calls(exec_command_calls)
        self.driver.client.close.assert_called_once_with()