def test_get(self): subnet = network_models.Subnet(id=uuidutils.generate_uuid()) network = network_models.Network(id=uuidutils.generate_uuid(), subnets=[subnet]) port = network_models.Port(id=uuidutils.generate_uuid(), network_id=network.id) vip = { 'ip_address': '10.0.0.1', 'subnet_id': subnet.id, 'network_id': network.id, 'port_id': port.id } with mock.patch("octavia.network.drivers.noop_driver.driver" ".NoopManager.get_network") as mock_get_network, \ mock.patch("octavia.network.drivers.noop_driver.driver" ".NoopManager.get_port") as mock_get_port: mock_get_network.return_value = network mock_get_port.return_value = port lb = self.create_load_balancer(vip, name='lb1', description='test1_desc', enabled=False) response = self.get(self.LB_PATH.format(lb_id=lb.get('id'))) self.assertEqual('lb1', response.json.get('name')) self.assertEqual('test1_desc', response.json.get('description')) self.assertFalse(response.json.get('enabled')) self.assertEqual(vip, response.json.get('vip'))
def test_get(self): project_id = uuidutils.generate_uuid() subnet = network_models.Subnet(id=uuidutils.generate_uuid()) network = network_models.Network(id=uuidutils.generate_uuid(), subnets=[subnet]) port = network_models.Port(id=uuidutils.generate_uuid(), network_id=network.id) with mock.patch("octavia.network.drivers.noop_driver.driver" ".NoopManager.get_network") as mock_get_network, \ mock.patch("octavia.network.drivers.noop_driver.driver" ".NoopManager.get_port") as mock_get_port: mock_get_network.return_value = network mock_get_port.return_value = port lb = self.create_load_balancer(subnet.id, vip_address='10.0.0.1', vip_network_id=network.id, vip_port_id=port.id, name='lb1', project_id=project_id, description='desc1', admin_state_up=False) lb_dict = lb.get(self.root_tag) response = self.get( self.LB_PATH.format( lb_id=lb_dict.get('id'))).json.get(self.root_tag) self.assertEqual('lb1', response.get('name')) self.assertEqual(project_id, response.get('project_id')) self.assertEqual('desc1', response.get('description')) self.assertFalse(response.get('admin_state_up')) self.assertEqual('10.0.0.1', response.get('vip_address')) self.assertEqual(subnet.id, response.get('vip_subnet_id')) self.assertEqual(network.id, response.get('vip_network_id')) self.assertEqual(port.id, response.get('vip_port_id'))
def setUp(self): super(TestNoopAmphoraLoadBalancerDriver, self).setUp() self.driver = driver.NoopAmphoraLoadBalancerDriver() self.listener = data_models.Listener() self.listener.id = uuidutils.generate_uuid() self.listener.protocol_port = 80 self.vip = data_models.Vip() self.vip.ip_address = "10.0.0.1" self.amphora = data_models.Amphora() self.amphora.id = self.FAKE_UUID_1 self.load_balancer = data_models.LoadBalancer( id=FAKE_UUID_1, amphorae=[self.amphora], vip=self.vip, listeners=[self.listener]) self.listener.load_balancer = self.load_balancer self.network = network_models.Network(id=self.FAKE_UUID_1) self.port = network_models.Port(id=uuidutils.generate_uuid()) self.amphorae_net_configs = { self.amphora.id: network_models.AmphoraNetworkConfig( amphora=self.amphora, vip_subnet=network_models.Subnet(id=self.FAKE_UUID_1)) } self.pem_file = 'test_pem_file' self.agent_config = 'test agent config' 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_create_with_vip_network_picks_subnet_ipv4(self): network_id = uuidutils.generate_uuid() subnet1 = network_models.Subnet(id=uuidutils.generate_uuid(), network_id=network_id, ip_version=6) subnet2 = network_models.Subnet(id=uuidutils.generate_uuid(), network_id=network_id, ip_version=4) network = network_models.Network(id=network_id, subnets=[subnet1.id, subnet2.id]) vip = {'network_id': network.id} lb_json = {'vip': vip, 'project_id': self.project_id} with mock.patch( "octavia.network.drivers.noop_driver.driver.NoopManager" ".get_network") as mock_get_network, mock.patch( "octavia.network.drivers.noop_driver.driver.NoopManager" ".get_subnet") as mock_get_subnet: mock_get_network.return_value = network mock_get_subnet.side_effect = [subnet1, subnet2] response = self.post(self.LBS_PATH, lb_json) api_lb = response.json self._assert_request_matches_response(lb_json, api_lb) self.assertEqual(subnet2.id, api_lb.get('vip', {}).get('subnet_id')) self.assertEqual(network_id, api_lb.get('vip', {}).get('network_id'))
def test_create_with_vip_full(self): subnet = network_models.Subnet(id=uuidutils.generate_uuid()) network = network_models.Network(id=uuidutils.generate_uuid(), subnets=[subnet]) port = network_models.Port(id=uuidutils.generate_uuid(), network_id=network.id) lb_json = { 'name': 'test1', 'description': 'test1_desc', 'vip_address': '10.0.0.1', 'vip_subnet_id': subnet.id, 'vip_network_id': network.id, 'vip_port_id': port.id, 'admin_state_up': False, 'project_id': self.project_id} body = self._build_body(lb_json) with mock.patch("octavia.network.drivers.noop_driver.driver" ".NoopManager.get_network") as mock_get_network, \ mock.patch("octavia.network.drivers.noop_driver.driver" ".NoopManager.get_port") as mock_get_port: mock_get_network.return_value = network mock_get_port.return_value = port response = self.post(self.LBS_PATH, body) api_lb = response.json.get(self.root_tag) self._assert_request_matches_response(lb_json, api_lb) self.assertEqual('10.0.0.1', api_lb.get('vip_address')) self.assertEqual(subnet.id, api_lb.get('vip_subnet_id')) self.assertEqual(network.id, api_lb.get('vip_network_id')) self.assertEqual(port.id, api_lb.get('vip_port_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() 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 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 test_create_with_vip_full(self): subnet = network_models.Subnet(id=uuidutils.generate_uuid()) network = network_models.Network(id=uuidutils.generate_uuid(), subnets=[subnet]) port = network_models.Port(id=uuidutils.generate_uuid(), network_id=network.id) vip = { 'ip_address': '10.0.0.1', 'subnet_id': subnet.id, 'network_id': network.id, 'port_id': port.id } lb_json = { 'name': 'test1', 'description': 'test1_desc', 'vip': vip, 'enabled': False, 'project_id': self.project_id } with mock.patch("octavia.network.drivers.noop_driver.driver" ".NoopManager.get_network") as mock_get_network, \ mock.patch("octavia.network.drivers.noop_driver.driver" ".NoopManager.get_port") as mock_get_port: mock_get_network.return_value = network mock_get_port.return_value = port response = self.post(self.LBS_PATH, lb_json) api_lb = response.json self._assert_request_matches_response(lb_json, api_lb) self.assertEqual(vip, api_lb.get('vip'))
def test_network_exists_with_valid_network(self): network_id = uuidutils.generate_uuid() network = network_models.Network(id=network_id) with mock.patch('octavia.common.utils.get_network_driver') as net_mock: net_mock.return_value.get_network.return_value = network self.assertEqual( validate.network_exists_optionally_contains_subnet(network_id), network)
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 test_network_exists_with_bad_subnet(self): network_id = uuidutils.generate_uuid() subnet_id = uuidutils.generate_uuid() network = network_models.Network(id=network_id) with mock.patch('octavia.common.utils.get_network_driver') as net_mock: net_mock.return_value.get_network.return_value = network self.assertRaises( exceptions.InvalidSubresource, validate.network_exists_optionally_contains_subnet, network_id, subnet_id)
def test_network_exists_with_valid_subnet(self): vip = lb_types.VIP() vip.network_id = uuidutils.generate_uuid() vip.subnet_id = uuidutils.generate_uuid() network = network_models.Network(id=vip.network_id, subnets=[vip.subnet_id]) with mock.patch('octavia.common.utils.get_network_driver') as net_mock: net_mock.return_value.get_network.return_value = network self.assertEqual( validate.network_exists_optionally_contains_subnet(vip), network)
def test_create_with_vip_network_has_no_subnet(self): network = network_models.Network(id=uuidutils.generate_uuid(), subnets=[]) lb_json = {'vip_network_id': network.id, 'project_id': self.project_id} body = self._build_body(lb_json) with mock.patch("octavia.network.drivers.noop_driver.driver" ".NoopManager.get_network") as mock_get_network: mock_get_network.return_value = network response = self.post(self.LBS_PATH, body, status=400) err_msg = ("Validation failure: " "Supplied network does not contain a subnet.") self.assertEqual(err_msg, response.json.get('faultstring'))
def convert_network_dict_to_model(network_dict): nw = network_dict.get('network', network_dict) return network_models.Network( id=nw.get(constants.ID), name=nw.get(constants.NAME), subnets=nw.get('subnets'), project_id=nw.get(constants.TENANT_ID), admin_state_up=nw.get('admin_state_up'), mtu=nw.get('mtu'), provider_network_type=nw.get('provider:network_type'), provider_physical_network=nw.get('provider:physical_network'), provider_segmentation_id=nw.get('provider:segmentation_id'), router_external=nw.get('router:external'))
def test_get_network_ip_availability(self): show_network_ip_availability = ( self.driver.neutron_client.show_network_ip_availability) show_network_ip_availability.return_value = ( {'network_ip_availability': { 'network_id': t_constants.MOCK_NETWORK_ID, 'subnet_ip_availability': t_constants.MOCK_SUBNET_IP_AVAILABILITY }}) ip_avail = self.driver.get_network_ip_availability( network_models.Network(t_constants.MOCK_NETWORK_ID)) self.assertIsInstance(ip_avail, network_models.Network_IP_Availability) self.assertEqual(t_constants.MOCK_NETWORK_ID, ip_avail.network_id) self.assertEqual(t_constants.MOCK_SUBNET_IP_AVAILABILITY, ip_avail.subnet_ip_availability)
def test_create_with_invalid_vip_network_subnet(self): network = network_models.Network(id=uuidutils.generate_uuid(), subnets=[]) subnet_id = uuidutils.generate_uuid() lb_json = { 'vip_subnet_id': subnet_id, 'vip_network_id': network.id, 'project_id': self.project_id} body = self._build_body(lb_json) with mock.patch("octavia.network.drivers.noop_driver.driver" ".NoopManager.get_network") as mock_get_network: mock_get_network.return_value = network response = self.post(self.LBS_PATH, body, status=400) err_msg = 'Subnet {} not found.'.format(subnet_id) self.assertEqual(err_msg, response.json.get('faultstring'))
def get_network(self, network_id): LOG.debug("Network %s no-op, get_network network_id %s", self.__class__.__name__, network_id) self.networkconfigconfig[network_id] = (network_id, 'get_network') network = network_models.Network(id=uuidutils.generate_uuid()) class ItIsInsideMe(object): def __contains__(self, item): return True def __iter__(self): yield uuidutils.generate_uuid() network.subnets = ItIsInsideMe() return network
def list_networks(self): network_list = self.neutron_client.list_networks() network_list_datamodel = [] for network in network_list.get('networks'): network_list_datamodel.append(n_data_models.Network( id=network.get('id'), name=network.get('name'), subnets=network.get('subnets'), project_id=network.get('project_id'), admin_state_up=network.get('admin_state_up'), mtu=network.get('mtu'), provider_network_type=network.get('provider:network_type'), provider_physical_network=network.get('provider:physical_network'), provider_segmentation_id=network.get('provider:segmentation_id'), router_external=network.get('router:external'))) return network_list_datamodel
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 test_create_with_vip_network_picks_subnet_ipv6(self): network_id = uuidutils.generate_uuid() subnet = network_models.Subnet(id=uuidutils.generate_uuid(), network_id=network_id, ip_version=6) network = network_models.Network(id=network_id, subnets=[subnet.id]) lb_json = {'vip_network_id': network_id, 'project_id': self.project_id} body = self._build_body(lb_json) with mock.patch("octavia.network.drivers.noop_driver.driver" ".NoopManager.get_network") as mock_get_network, \ mock.patch("octavia.network.drivers.noop_driver.driver" ".NoopManager.get_subnet") as mock_get_subnet: mock_get_network.return_value = network mock_get_subnet.return_value = subnet response = self.post(self.LBS_PATH, body) api_lb = response.json.get(self.root_tag) self._assert_request_matches_response(lb_json, api_lb) self.assertEqual(subnet.id, api_lb.get('vip_subnet_id')) self.assertEqual(network_id, api_lb.get('vip_network_id'))
def setUp(self): super(TestNoopAmphoraLoadBalancerDriver, self).setUp() self.driver = driver.NoopAmphoraLoadBalancerDriver() self.listener = data_models.Listener() self.listener.protocol_port = 80 self.vip = data_models.Vip() self.vip.ip_address = "10.0.0.1" self.amphora = data_models.Amphora() self.amphora.id = self.FAKE_UUID_1 self.load_balancer = data_models.LoadBalancer( id=FAKE_UUID_1, amphorae=[self.amphora], vip=self.vip, listeners=[self.listener]) self.network = network_models.Network(id=self.FAKE_UUID_1) self.port = network_models.Port(id=uuidutils.generate_uuid()) self.amphorae_net_configs = { self.amphora.id: network_models.AmphoraNetworkConfig( amphora=self.amphora, vip_subnet=network_models.Subnet(id=self.FAKE_UUID_1)) }
def get_network_by_name(self, network_name): LOG.debug("Network %s no-op, get_network_by_name network_name %s", self.__class__.__name__, network_name) self.networkconfigconfig[network_name] = (network_name, 'get_network_by_name') return network_models.Network(id=uuidutils.generate_uuid())
def get_network(self, network_id): LOG.debug("Network %s no-op, get_network network_id %s", self.__class__.__name__, network_id) self.networkconfigconfig[network_id] = (network_id, 'get_network') return network_models.Network(id=uuidutils.generate_uuid())
"ethernet_interfaces": [ETHERNET_INTERFACE] }, "device_2": { "vcs_device_id": 2, "mgmt_ip_address": DEVICE2_MGMT_IP, "ethernet_interfaces": [ETHERNET_INTERFACE] } } } DEL_VS_LIST = {"virtual-server-list": [{"ip-address": "10.0.1.1"}]} DEL_SERVER_LIST = {"server-list": [{"host": "10.0.2.1"}]} DEL_PORT_ID = "mock-port-id" VE_IP = "10.0.11.10" STATIC_VE_IP = "10.0.12.10" NETWORK_11 = n_data_models.Network(id="mock-network-1", subnets=["mock-subnet-1"], provider_segmentation_id=11) NETWORK_12 = n_data_models.Network(id="mock-network-2", subnets=["mock-subnet-2"], provider_segmentation_id=12) VCS_DISABLED = {"vcs-summary": {"oper": {"vcs-enabled": "Invalid"}}} VCS_MASTER_VBLADE = { "vcs-summary": { "oper": { "vcs-enabled": "Yes", "member-list": [{ "port": 41216, "priority": 125, "state": "vMaster(*)", "ip-list": [{
from octavia.tests.common import constants as t_constants from acos_client import errors as acos_errors from a10_octavia.common import config_options from a10_octavia.common import data_models as a10_data_models from a10_octavia.common import exceptions as a10_ex from a10_octavia.controller.worker.tasks import glm_tasks as task from a10_octavia.tests.common import a10constants from a10_octavia.tests.unit import base VTHUNDER = a10_data_models.VThunder(id=a10constants.MOCK_VTHUNDER_ID) AMPHORA = o_data_models.Amphora(id=t_constants.MOCK_AMP_ID1) DNS_SUBNET = n_data_models.Subnet(id=a10constants.MOCK_SUBNET_ID) DNS_NETWORK = n_data_models.Network(id=a10constants.MOCK_NETWORK_ID, subnets=[DNS_SUBNET.id]) PRIMARY_DNS = '1.3.3.7' SECONDARY_DNS = '1.0.0.7' PROXY_HOST = '10.10.10.10' PROXY_PORT = 1111 PROXY_USERNAME = '******' PROXY_PASSWORD = True PROXY_PASSWORD_VALUE = 'password' class TestGLMTasks(base.BaseTaskTestCase): def setUp(self): super(TestGLMTasks, self).setUp() self.conf = self.useFixture(oslo_fixture.Config(cfg.CONF)) self.conf.register_opts(config_options.A10_GLM_LICENSE_OPTS,