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 }
def test_post_network_plug_with_host_routes(self): SUBNET_ID = 'SUBNET_ID' FIXED_IP1 = '192.0.2.2' FIXED_IP2 = '192.0.2.3' SUBNET_CIDR = '192.0.2.0/24' DEST1 = '198.51.100.0/24' DEST2 = '203.0.113.0/24' NEXTHOP = '192.0.2.1' host_routes = [ network_models.HostRoute(destination=DEST1, nexthop=NEXTHOP), network_models.HostRoute(destination=DEST2, nexthop=NEXTHOP) ] subnet = network_models.Subnet(id=SUBNET_ID, cidr=SUBNET_CIDR, ip_version=4, host_routes=host_routes) fixed_ips = [ network_models.FixedIP(subnet_id=subnet.id, ip_address=FIXED_IP1, subnet=subnet), network_models.FixedIP(subnet_id=subnet.id, ip_address=FIXED_IP2, subnet=subnet) ] port = network_models.Port(mac_address=FAKE_MAC_ADDRESS, fixed_ips=fixed_ips, network=self.network) self.driver.post_network_plug(self.amp, port) expected_fixed_ips = [{ 'ip_address': FIXED_IP1, 'subnet_cidr': SUBNET_CIDR, 'host_routes': [{ 'destination': DEST1, 'nexthop': NEXTHOP }, { 'destination': DEST2, 'nexthop': NEXTHOP }] }, { 'ip_address': FIXED_IP2, 'subnet_cidr': SUBNET_CIDR, 'host_routes': [{ 'destination': DEST1, 'nexthop': NEXTHOP }, { 'destination': DEST2, 'nexthop': NEXTHOP }] }] self.driver.client.plug_network.assert_called_once_with( self.amp, dict(mac_address=FAKE_MAC_ADDRESS, fixed_ips=expected_fixed_ips, mtu=FAKE_MTU))
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 }
def execute(self, amphora, loadbalancer, amphorae_network_config): """Execute post_vip_routine.""" db_amp = self.amphora_repo.get(db_apis.get_session(), id=amphora.get(constants.ID)) db_lb = self.loadbalancer_repo.get( db_apis.get_session(), id=loadbalancer[constants.LOADBALANCER_ID]) vrrp_port = data_models.Port( **amphorae_network_config[ amphora.get(constants.ID)][constants.VRRP_PORT]) # Required for noop-case vip_arg = amphorae_network_config[amphora.get( constants.ID)][constants.VIP_SUBNET] if vip_arg: host_routes = vip_arg.get('host_routes') if host_routes: vip_arg['host_routes'] = [ data_models.HostRoute(**hr) for hr in host_routes ] vip_subnet = data_models.Subnet(**vip_arg) else: vip_subnet = data_models.Subnet() self.amphora_driver.post_vip_plug( db_amp, db_lb, amphorae_network_config, vrrp_port=vrrp_port, vip_subnet=vip_subnet) LOG.debug("Notified amphora of vip plug")
def execute(self, amphora, ports): """Execute post_network_plug routine.""" db_amp = self.amphora_repo.get(db_apis.get_session(), id=amphora[constants.ID]) for port in ports: net = data_models.Network(**port.pop(constants.NETWORK)) ips = port.pop(constants.FIXED_IPS) fixed_ips = [] for ip in ips: subnet_arg = ip.pop(constants.SUBNET) host_routes = subnet_arg.get('host_routes') if host_routes: subnet_arg['host_routes'] = [ data_models.HostRoute(**hr) for hr in host_routes ] fixed_ips.append(data_models.FixedIP( subnet=data_models.Subnet(**subnet_arg), **ip)) self.amphora_driver.post_network_plug( db_amp, data_models.Port(network=net, fixed_ips=fixed_ips, **port)) LOG.debug("post_network_plug called on compute instance " "%(compute_id)s for port %(port_id)s", {"compute_id": amphora[constants.COMPUTE_ID], "port_id": port[constants.ID]})
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 }
def convert_subnet_dict_to_model(subnet_dict): subnet = subnet_dict.get('subnet', subnet_dict) subnet_hrs = subnet.get('host_routes', []) host_routes = [network_models.HostRoute(nexthop=hr.get('nexthop'), destination=hr.get('destination')) for hr in subnet_hrs] return network_models.Subnet(id=subnet.get('id'), name=subnet.get('name'), network_id=subnet.get('network_id'), project_id=subnet.get('tenant_id'), gateway_ip=subnet.get('gateway_ip'), cidr=subnet.get('cidr'), ip_version=subnet.get('ip_version'), host_routes=host_routes )