def test_deallocate_vip_when_port_not_found(self):
     lb = dmh.generate_load_balancer_tree()
     vip = data_models.Vip(port_id='1')
     vip.load_balancer = lb
     show_port = self.driver.neutron_client.show_port
     show_port.side_effect = neutron_exceptions.PortNotFoundClient
     self.driver.deallocate_vip(vip)
 def test_plug_vip(self):
     lb = dmh.generate_load_balancer_tree()
     show_subnet = self.driver.neutron_client.show_subnet
     show_subnet.return_value = {
         'subnet': {
             'id': lb.vip.subnet_id
         }
     }
     interface_attach = self.driver.nova_client.servers.interface_attach
     interface_attach.return_value = n_constants.MOCK_NOVA_INTERFACE
     list_security_groups = self.driver.neutron_client.list_security_groups
     list_security_groups.return_value = {
         'security_groups': [
             {'id': 'lb-sec-grp1'}
         ]
     }
     update_port = self.driver.neutron_client.update_port
     expected_aap = {'port': {'allowed_address_pairs':
                              [{'ip_address': lb.vip.ip_address}]}}
     interface_list = self.driver.nova_client.servers.interface_list
     if1 = n_constants.MOCK_NOVA_INTERFACE
     if2 = n_constants.MockNovaInterface()
     if2.net_id = '3'
     if2.port_id = '4'
     if2.fixed_ips = [{'ip_address': '10.0.0.2'}]
     if1.fixed_ips = [{'ip_address': n_constants.MOCK_IP_ADDRESS,
                       'subnet_id': lb.vip.subnet_id}]
     interface_list.return_value = [if1, if2]
     amps = self.driver.plug_vip(lb, lb.vip)
     self.assertEqual(5, update_port.call_count)
     update_port.assert_any_call(if1.port_id, expected_aap)
     for amp in amps:
         self.assertEqual(n_constants.MOCK_IP_ADDRESS, amp.vrrp_ip)
         self.assertEqual(lb.vip.ip_address, amp.ha_ip)
         self.assertIn(amp.id, [lb.amphorae[0].id, lb.amphorae[1].id])
 def test_deallocate_vip_when_port_not_found(self):
     lb = dmh.generate_load_balancer_tree()
     vip = data_models.Vip(port_id='1')
     vip.load_balancer = lb
     show_port = self.driver.neutron_client.show_port
     show_port.side_effect = neutron_exceptions.PortNotFoundClient
     self.driver.deallocate_vip(vip)
 def test_plug_aap_on_mgmt_net(self):
     lb = dmh.generate_load_balancer_tree()
     lb.vip.subnet_id = t_constants.MOCK_MANAGEMENT_SUBNET_ID
     subnet = network_models.Subnet(
         id=t_constants.MOCK_MANAGEMENT_SUBNET_ID,
         network_id=t_constants.MOCK_MANAGEMENT_NET_ID)
     list_ports = self.driver.neutron_client.list_ports
     port1 = t_constants.MOCK_MANAGEMENT_PORT1['port']
     port2 = t_constants.MOCK_MANAGEMENT_PORT2['port']
     self._set_safely(t_constants.MOCK_MANAGEMENT_FIXED_IPS1[0],
                      'ip_address', lb.amphorae[0].lb_network_ip)
     self._set_safely(t_constants.MOCK_MANAGEMENT_FIXED_IPS2[0],
                      'ip_address', lb.amphorae[1].lb_network_ip)
     list_ports.side_effect = [{'ports': [port1]}, {'ports': [port2]}]
     network_attach = self.driver.compute.attach_network_or_port
     self._set_safely(t_constants.MOCK_VRRP_INTERFACE1,
                      'net_id', t_constants.MOCK_MANAGEMENT_NET_ID)
     self._set_safely(t_constants.MOCK_VRRP_FIXED_IPS1[0],
                      'subnet_id', t_constants.MOCK_MANAGEMENT_SUBNET_ID)
     self._set_safely(t_constants.MOCK_VRRP_INTERFACE2,
                      'net_id', t_constants.MOCK_MANAGEMENT_NET_ID)
     self._set_safely(t_constants.MOCK_VRRP_FIXED_IPS2[0],
                      'subnet_id', t_constants.MOCK_MANAGEMENT_SUBNET_ID)
     network_attach.side_effect = [t_constants.MOCK_VRRP_INTERFACE1]
     update_port = self.driver.neutron_client.update_port
     expected_aap = {'port': {'allowed_address_pairs':
                              [{'ip_address': lb.vip.ip_address}]}}
     amp = self.driver.plug_aap_port(lb, lb.vip, lb.amphorae[0], subnet)
     update_port.assert_any_call(amp.vrrp_port_id, expected_aap)
     self.assertIn(amp.vrrp_ip, [t_constants.MOCK_VRRP_IP1,
                                 t_constants.MOCK_VRRP_IP2])
     self.assertEqual(lb.vip.ip_address, amp.ha_ip)
 def test_deallocate_vip_when_port_not_owned_by_octavia(self):
     lb = dmh.generate_load_balancer_tree()
     lb.vip.load_balancer = lb
     vip = lb.vip
     sec_grp_id = 'lb-sec-grp1'
     show_port = self.driver.neutron_client.show_port
     show_port.return_value = {'port': {
         'id': vip.port_id,
         'device_owner': 'neutron:LOADBALANCERV2',
         'security_groups': [sec_grp_id]}}
     delete_port = self.driver.neutron_client.delete_port
     update_port = self.driver.neutron_client.update_port
     delete_sec_grp = self.driver.neutron_client.delete_security_group
     list_security_groups = self.driver.neutron_client.list_security_groups
     security_groups = {
         'security_groups': [
             {'id': sec_grp_id}
         ]
     }
     list_security_groups.return_value = security_groups
     self.driver.deallocate_vip(vip)
     expected_port_update = {'port': {'security_groups': []}}
     update_port.assert_called_once_with(vip.port_id, expected_port_update)
     delete_sec_grp.assert_called_once_with(sec_grp_id)
     self.assertFalse(delete_port.called)
 def test_deallocate_vip_when_port_not_owned_by_octavia(self):
     lb = dmh.generate_load_balancer_tree()
     lb.vip.load_balancer = lb
     vip = lb.vip
     sec_grp_id = 'lb-sec-grp1'
     show_port = self.driver.neutron_client.show_port
     show_port.return_value = {'port': {
         'id': vip.port_id,
         'device_owner': 'neutron:LOADBALANCERV2',
         'security_groups': [sec_grp_id]}}
     delete_port = self.driver.neutron_client.delete_port
     update_port = self.driver.neutron_client.update_port
     delete_sec_grp = self.driver.neutron_client.delete_security_group
     list_security_groups = self.driver.neutron_client.list_security_groups
     security_groups = {
         'security_groups': [
             {'id': sec_grp_id}
         ]
     }
     list_security_groups.return_value = security_groups
     self.driver.deallocate_vip(vip)
     expected_port_update = {'port': {'security_groups': []}}
     update_port.assert_called_once_with(vip.port_id, expected_port_update)
     delete_sec_grp.assert_called_once_with(sec_grp_id)
     self.assertFalse(delete_port.called)
 def test_plug_vip(self):
     lb = dmh.generate_load_balancer_tree()
     show_subnet = self.driver.neutron_client.show_subnet
     show_subnet.return_value = {
         'subnet': {
             'id': lb.vip.subnet_id
         }
     }
     interface_attach = self.driver.nova_client.servers.interface_attach
     interface_attach.return_value = n_constants.MOCK_NOVA_INTERFACE
     list_security_groups = self.driver.neutron_client.list_security_groups
     list_security_groups.return_value = {
         'security_groups': [
             {'id': 'lb-sec-grp1'}
         ]
     }
     update_port = self.driver.neutron_client.update_port
     expected_aap = {'port': {'allowed_address_pairs':
                              [{'ip_address': lb.vip.ip_address}]}}
     interface_list = self.driver.nova_client.servers.interface_list
     if1 = n_constants.MOCK_NOVA_INTERFACE
     if2 = n_constants.MockNovaInterface()
     if2.net_id = '3'
     if2.port_id = '4'
     if2.fixed_ips = [{'ip_address': '10.0.0.2'}]
     if1.fixed_ips = [{'ip_address': n_constants.MOCK_IP_ADDRESS,
                       'subnet_id': lb.vip.subnet_id}]
     interface_list.return_value = [if1, if2]
     amps = self.driver.plug_vip(lb, lb.vip)
     self.assertEqual(5, update_port.call_count)
     update_port.assert_any_call(if1.port_id, expected_aap)
     for amp in amps:
         self.assertEqual(n_constants.MOCK_IP_ADDRESS, amp.vrrp_ip)
         self.assertEqual(lb.vip.ip_address, amp.ha_ip)
         self.assertIn(amp.id, [lb.amphorae[0].id, lb.amphorae[1].id])
 def test_plug_vip(self):
     lb = dmh.generate_load_balancer_tree()
     show_subnet = self.driver.neutron_client.show_subnet
     show_subnet.return_value = {
         'subnet': {
             'id': t_constants.MOCK_VIP_SUBNET_ID,
             'network_id': t_constants.MOCK_VIP_NET_ID
         }
     }
     list_ports = self.driver.neutron_client.list_ports
     port1 = t_constants.MOCK_MANAGEMENT_PORT1['port']
     port2 = t_constants.MOCK_MANAGEMENT_PORT2['port']
     list_ports.side_effect = [{'ports': [port1]}, {'ports': [port2]}]
     interface_attach = self.driver.nova_client.servers.interface_attach
     interface_attach.side_effect = [t_constants.MOCK_VRRP_INTERFACE1,
                                     t_constants.MOCK_VRRP_INTERFACE2]
     list_security_groups = self.driver.neutron_client.list_security_groups
     list_security_groups.return_value = {
         'security_groups': [
             {'id': 'lb-sec-grp1'}
         ]
     }
     update_port = self.driver.neutron_client.update_port
     expected_aap = {'port': {'allowed_address_pairs':
                              [{'ip_address': lb.vip.ip_address}]}}
     amps = self.driver.plug_vip(lb, lb.vip)
     self.assertEqual(5, update_port.call_count)
     for amp in amps:
         update_port.assert_any_call(amp.vrrp_port_id, expected_aap)
         self.assertIn(amp.vrrp_ip, [t_constants.MOCK_VRRP_IP1,
                                     t_constants.MOCK_VRRP_IP2])
         self.assertEqual(lb.vip.ip_address, amp.ha_ip)
 def test_update_vip_sg(self):
     lb = dmh.generate_load_balancer_tree()
     list_security_groups = self.driver.neutron_client.list_security_groups
     list_security_groups.return_value = {
         'security_groups': [
             {'id': 'lb-sec-grp1'}
         ]
     }
     self.driver.update_vip_sg(lb, lb.vip)
    def test_plug_aap_errors_when_nova_cant_find_network_to_attach(self):
        lb = dmh.generate_load_balancer_tree()
        subnet = network_models.Subnet(id=t_constants.MOCK_VIP_SUBNET_ID,
                                       network_id=t_constants.MOCK_VIP_NET_ID)

        network_attach = self.driver.compute.attach_network_or_port
        network_attach.side_effect = nova_exceptions.NotFound(404, "Network")
        self.assertRaises(network_base.PlugVIPException,
                          self.driver.plug_aap_port, lb, lb.vip,
                          lb.amphorae[0], subnet)
 def test_deallocate_vip_when_port_not_found_for_update(self):
     lb = dmh.generate_load_balancer_tree()
     vip = data_models.Vip(port_id='1')
     vip.load_balancer = lb
     show_port = self.driver.neutron_client.show_port
     show_port.return_value = {'port': {
         'device_owner': allowed_address_pairs.OCTAVIA_OWNER}}
     update_port = self.driver.neutron_client.update_port
     update_port.side_effect = neutron_exceptions.PortNotFoundClient
     self.driver.deallocate_vip(vip)
Esempio n. 12
0
 def test__port_to_vip(self):
     lb = dmh.generate_load_balancer_tree()
     lb.vip.subnet_id = n_constants.MOCK_SUBNET_ID
     port = utils.convert_port_dict_to_model(n_constants.MOCK_NEUTRON_PORT)
     vip = self.driver._port_to_vip(port, lb)
     self.assertIsInstance(vip, data_models.Vip)
     self.assertEqual(n_constants.MOCK_IP_ADDRESS, vip.ip_address)
     self.assertEqual(n_constants.MOCK_SUBNET_ID, vip.subnet_id)
     self.assertEqual(n_constants.MOCK_PORT_ID, vip.port_id)
     self.assertEqual(lb.id, vip.load_balancer_id)
Esempio n. 13
0
 def test__port_to_vip(self):
     lb = dmh.generate_load_balancer_tree()
     lb.vip.subnet_id = t_constants.MOCK_SUBNET_ID
     port = utils.convert_port_dict_to_model(t_constants.MOCK_NEUTRON_PORT)
     vip = self.driver._port_to_vip(port, lb)
     self.assertIsInstance(vip, data_models.Vip)
     self.assertEqual(t_constants.MOCK_IP_ADDRESS, vip.ip_address)
     self.assertEqual(t_constants.MOCK_SUBNET_ID, vip.subnet_id)
     self.assertEqual(t_constants.MOCK_PORT_ID, vip.port_id)
     self.assertEqual(lb.id, vip.load_balancer_id)
Esempio n. 14
0
 def test_deallocate_vip_when_port_not_found_for_update(self):
     lb = dmh.generate_load_balancer_tree()
     vip = data_models.Vip(port_id='1')
     vip.load_balancer = lb
     show_port = self.driver.neutron_client.show_port
     show_port.return_value = {'port': {
         'device_owner': allowed_address_pairs.OCTAVIA_OWNER}}
     update_port = self.driver.neutron_client.update_port
     update_port.side_effect = neutron_exceptions.PortNotFoundClient
     self.driver.deallocate_vip(vip)
 def test_deallocate_vip_when_delete_port_fails(self):
     lb = dmh.generate_load_balancer_tree()
     vip = data_models.Vip(port_id='1')
     vip.load_balancer = lb
     show_port = self.driver.neutron_client.show_port
     show_port.return_value = {'port': {
         'device_owner': allowed_address_pairs.OCTAVIA_OWNER}}
     delete_port = self.driver.neutron_client.delete_port
     delete_port.side_effect = [None, None, TypeError]
     self.assertRaises(network_base.DeallocateVIPException,
                       self.driver.deallocate_vip, vip)
 def test_deallocate_vip_when_vip_port_not_found(self):
     lb = dmh.generate_load_balancer_tree()
     vip = data_models.Vip(port_id='1')
     vip.load_balancer = lb
     admin_project_id = 'octavia'
     session_mock = mock.MagicMock()
     session_mock.get_project_id.return_value = admin_project_id
     self.k_session.return_value = session_mock
     show_port = self.driver.neutron_client.show_port
     show_port.side_effect = neutron_exceptions.PortNotFoundClient
     self.driver.deallocate_vip(vip)
 def test_deallocate_vip_when_delete_port_fails(self):
     lb = dmh.generate_load_balancer_tree()
     vip = data_models.Vip(port_id='1')
     vip.load_balancer = lb
     show_port = self.driver.neutron_client.show_port
     show_port.return_value = {'port': {
         'device_owner': allowed_address_pairs.OCTAVIA_OWNER}}
     delete_port = self.driver.neutron_client.delete_port
     delete_port.side_effect = [None, None, TypeError]
     self.assertRaises(network_base.DeallocateVIPException,
                       self.driver.deallocate_vip, vip)
 def test_deallocate_vip_when_vip_port_not_found(self):
     lb = dmh.generate_load_balancer_tree()
     vip = data_models.Vip(port_id='1')
     vip.load_balancer = lb
     admin_project_id = 'octavia'
     session_mock = mock.MagicMock()
     session_mock.get_project_id.return_value = admin_project_id
     self.k_session.return_value = session_mock
     show_port = self.driver.neutron_client.show_port
     show_port.side_effect = neutron_exceptions.PortNotFoundClient
     self.driver.deallocate_vip(vip)
    def test_plug_vip_errors_when_nova_cant_find_network_to_attach(self):
        lb = dmh.generate_load_balancer_tree()
        show_subnet = self.driver.neutron_client.show_subnet
        show_subnet.return_value = {'subnet': {'id': lb.vip.subnet_id}}
        list_security_groups = self.driver.neutron_client.list_security_groups
        lsc_side_effect = [None, {'security_groups': [{'id': 'lb-sec-grp1'}]}]
        list_security_groups.side_effect = lsc_side_effect

        interface_attach = self.driver.nova_client.servers.interface_attach
        interface_attach.side_effect = nova_exceptions.NotFound(404, "Network")
        self.assertRaises(network_base.PlugVIPException, self.driver.plug_vip,
                          lb, lb.vip)
    def test_plug_aap_errors_when_neutron_cant_find_port_to_update(self):
        lb = dmh.generate_load_balancer_tree()
        subnet = network_models.Subnet(id=t_constants.MOCK_VIP_SUBNET_ID,
                                       network_id=t_constants.MOCK_VIP_NET_ID)
        network_attach = self.driver.compute.attach_network_or_port
        network_attach.return_value = t_constants.MOCK_NOVA_INTERFACE

        update_port = self.driver.neutron_client.update_port
        update_port.side_effect = neutron_exceptions.PortNotFoundClient
        self.assertRaises(network_base.PortNotFound,
                          self.driver.plug_aap_port, lb, lb.vip,
                          lb.amphorae[0], subnet)
    def test_plug_vip(self, mock_plug_aap, mock_get_subnet,
                      mock_update_vip_sg):
        lb = dmh.generate_load_balancer_tree()
        subnet = mock.MagicMock()
        mock_get_subnet.return_value = subnet
        mock_plug_aap.side_effect = lb.amphorae
        amps = self.driver.plug_vip(lb, lb.vip)

        mock_update_vip_sg.assert_called_with(lb, lb.vip)
        mock_get_subnet.assert_called_with(lb.vip.subnet_id)
        for amp in amps:
            mock_plug_aap.assert_any_call(lb, lb.vip, amp, subnet)
Esempio n. 22
0
 def test_deallocate_vip_no_port(self):
     lb = dmh.generate_load_balancer_tree()
     lb.vip.load_balancer = lb
     vip = lb.vip
     sec_grp_id = 'lb-sec-grp1'
     show_port = self.driver.neutron_client.show_port
     port = {'port': {'device_owner': allowed_address_pairs.OCTAVIA_OWNER}}
     show_port.side_effect = [port, Exception]
     list_security_groups = self.driver.neutron_client.list_security_groups
     security_groups = {'security_groups': [{'id': sec_grp_id}]}
     list_security_groups.return_value = security_groups
     self.driver.deallocate_vip(vip)
     self.driver.neutron_client.update_port.assert_not_called()
    def test_plug_vip_errors_when_neutron_cant_find_port_to_update(self):
        lb = dmh.generate_load_balancer_tree()
        show_subnet = self.driver.neutron_client.show_subnet
        show_subnet.return_value = {'subnet': {'id': lb.vip.subnet_id}}
        list_security_groups = self.driver.neutron_client.list_security_groups
        lsc_side_effect = [None, {'security_groups': [{'id': 'lb-sec-grp1'}]}]
        list_security_groups.side_effect = lsc_side_effect
        interface_attach = self.driver.nova_client.servers.interface_attach
        interface_attach.return_value = t_constants.MOCK_NOVA_INTERFACE

        update_port = self.driver.neutron_client.update_port
        update_port.side_effect = neutron_exceptions.PortNotFoundClient
        self.assertRaises(network_base.PortNotFound, self.driver.plug_vip, lb,
                          lb.vip)
Esempio n. 24
0
    def test_deallocate_vip_when_secgrp_has_allocated_ports(self):
        max_retries = 1
        conf = oslo_fixture.Config(cfg.CONF)
        conf.config(group="networking", max_retries=max_retries)

        lb = dmh.generate_load_balancer_tree()
        lb.vip.load_balancer = lb
        vip = lb.vip
        show_port = self.driver.neutron_client.show_port
        show_port.return_value = {
            'port': {
                'device_owner': allowed_address_pairs.OCTAVIA_OWNER
            }
        }
        delete_port = self.driver.neutron_client.delete_port
        list_ports = self.driver.neutron_client.list_ports
        list_security_groups = self.driver.neutron_client.list_security_groups
        delete_sec_grp = self.driver.neutron_client.delete_security_group
        security_groups = {
            'security_groups': [{
                'id': t_constants.MOCK_SECURITY_GROUP_ID
            }]
        }
        list_security_groups.return_value = security_groups
        delete_grp_results = [
            network_base.DeallocateVIPException for _ in range(max_retries + 1)
        ]  # Total tries = max_retries + 1
        delete_grp_results.append(None)
        delete_sec_grp.side_effect = delete_grp_results
        list_ports.side_effect = [{
            "ports": [
                t_constants.MOCK_NEUTRON_PORT['port'],
                t_constants.MOCK_NEUTRON_PORT2['port']
            ]
        }]
        self.driver.deallocate_vip(vip)
        # First we expect the amp's ports to be deleted
        dp_calls = [mock.call(amp.vrrp_port_id) for amp in lb.amphorae]
        # Then after the SG delete fails, extra hanging-on ports are removed
        dp_calls.append(mock.call(t_constants.MOCK_PORT_ID))
        # Lastly we remove the vip port
        dp_calls.append(mock.call(vip.port_id))
        self.assertEqual(len(dp_calls), delete_port.call_count)
        delete_port.assert_has_calls(dp_calls)
        dsg_calls = [
            mock.call(t_constants.MOCK_SECURITY_GROUP_ID)
            for _ in range(max_retries + 2)
        ]  # Max fail + one success
        self.assertEqual(len(dsg_calls), delete_sec_grp.call_count)
        delete_sec_grp.assert_has_calls(dsg_calls)
 def test_unplug_vip_errors_when_update_port_cant_find_port(self):
     lb = dmh.generate_load_balancer_tree()
     list_ports = self.driver.neutron_client.list_ports
     show_subnet = self.driver.neutron_client.show_subnet
     show_subnet.return_value = n_constants.MOCK_SUBNET
     port1 = n_constants.MOCK_NEUTRON_PORT['port']
     port2 = {
         'id': '4', 'network_id': '3', 'fixed_ips':
         [{'ip_address': '10.0.0.2'}]
     }
     list_ports.return_value = {'ports': [port1, port2]}
     update_port = self.driver.neutron_client.update_port
     update_port.side_effect = neutron_exceptions.PortNotFoundClient
     self.assertRaises(network_base.UnplugVIPException,
                       self.driver.unplug_vip, lb, lb.vip)
 def test_unplug_vip_errors_when_update_port_cant_find_port(self):
     lb = dmh.generate_load_balancer_tree()
     list_ports = self.driver.neutron_client.list_ports
     show_subnet = self.driver.neutron_client.show_subnet
     show_subnet.return_value = t_constants.MOCK_SUBNET
     port1 = t_constants.MOCK_NEUTRON_PORT['port']
     port2 = {
         'id': '4', 'network_id': '3', 'fixed_ips':
         [{'ip_address': '10.0.0.2'}]
     }
     list_ports.return_value = {'ports': [port1, port2]}
     update_port = self.driver.neutron_client.update_port
     update_port.side_effect = neutron_exceptions.PortNotFoundClient
     self.assertRaises(network_base.UnplugVIPException,
                       self.driver.unplug_vip, lb, lb.vip)
 def test_unplug_vip(self):
     lb = dmh.generate_load_balancer_tree()
     show_subnet = self.driver.neutron_client.show_subnet
     show_subnet.return_value = n_constants.MOCK_SUBNET
     update_port = self.driver.neutron_client.update_port
     port1 = n_constants.MOCK_NEUTRON_PORT['port']
     port2 = {
         'id': '4', 'network_id': '3', 'fixed_ips':
         [{'ip_address': '10.0.0.2'}]
     }
     list_ports = self.driver.neutron_client.list_ports
     list_ports.return_value = {'ports': [port1, port2]}
     self.driver.unplug_vip(lb, lb.vip)
     self.assertEqual(len(lb.amphorae), update_port.call_count)
     clear_aap = {'port': {'allowed_address_pairs': []}}
     update_port.assert_has_calls([mock.call(port1.get('id'), clear_aap),
                                   mock.call(port1.get('id'), clear_aap)])
 def test_deallocate_vip_no_sec_group(self):
     lb = dmh.generate_load_balancer_tree()
     lb.vip.load_balancer = lb
     vip = lb.vip
     show_port = self.driver.neutron_client.show_port
     show_port.return_value = {'port': {
         'device_owner': allowed_address_pairs.OCTAVIA_OWNER}}
     delete_port = self.driver.neutron_client.delete_port
     delete_sec_grp = self.driver.neutron_client.delete_security_group
     list_security_groups = self.driver.neutron_client.list_security_groups
     security_groups = {
         'security_groups': []
     }
     list_security_groups.return_value = security_groups
     self.driver.deallocate_vip(vip)
     delete_port.assert_called_with(vip.port_id)
     delete_sec_grp.assert_not_called()
 def test_unplug_aap_port_errors_when_update_port_cant_find_port(self):
     lb = dmh.generate_load_balancer_tree()
     list_ports = self.driver.neutron_client.list_ports
     port1 = t_constants.MOCK_NEUTRON_PORT['port']
     port2 = {
         'id': '4', 'network_id': '3', 'fixed_ips':
         [{'ip_address': '10.0.0.2'}]
     }
     subnet = network_models.Subnet(
         id=t_constants.MOCK_MANAGEMENT_SUBNET_ID,
         network_id='3')
     list_ports.return_value = {'ports': [port1, port2]}
     update_port = self.driver.neutron_client.update_port
     update_port.side_effect = neutron_exceptions.PortNotFoundClient
     self.assertRaises(network_base.UnplugVIPException,
                       self.driver.unplug_aap_port, lb.vip, lb.amphorae[0],
                       subnet)
 def test_unplug_vip(self):
     lb = dmh.generate_load_balancer_tree()
     show_subnet = self.driver.neutron_client.show_subnet
     show_subnet.return_value = n_constants.MOCK_SUBNET
     update_port = self.driver.neutron_client.update_port
     port1 = n_constants.MOCK_NEUTRON_PORT['port']
     port2 = {
         'id': '4', 'network_id': '3', 'fixed_ips':
         [{'ip_address': '10.0.0.2'}]
     }
     list_ports = self.driver.neutron_client.list_ports
     list_ports.return_value = {'ports': [port1, port2]}
     self.driver.unplug_vip(lb, lb.vip)
     self.assertEqual(len(lb.amphorae), update_port.call_count)
     clear_aap = {'port': {'allowed_address_pairs': []}}
     update_port.assert_has_calls([mock.call(port1.get('id'), clear_aap),
                                   mock.call(port1.get('id'), clear_aap)])
 def test_deallocate_vip_no_sec_group(self):
     lb = dmh.generate_load_balancer_tree()
     lb.vip.load_balancer = lb
     vip = lb.vip
     show_port = self.driver.neutron_client.show_port
     show_port.return_value = {'port': {
         'device_owner': allowed_address_pairs.OCTAVIA_OWNER}}
     delete_port = self.driver.neutron_client.delete_port
     delete_sec_grp = self.driver.neutron_client.delete_security_group
     list_security_groups = self.driver.neutron_client.list_security_groups
     security_groups = {
         'security_groups': []
     }
     list_security_groups.return_value = security_groups
     self.driver.deallocate_vip(vip)
     delete_port.assert_called_with(vip.port_id)
     delete_sec_grp.assert_not_called()
 def test_deallocate_vip_no_port(self):
     lb = dmh.generate_load_balancer_tree()
     lb.vip.load_balancer = lb
     vip = lb.vip
     sec_grp_id = 'lb-sec-grp1'
     show_port = self.driver.neutron_client.show_port
     port = {'port': {
         'device_owner': allowed_address_pairs.OCTAVIA_OWNER}}
     show_port.side_effect = [port, Exception]
     list_security_groups = self.driver.neutron_client.list_security_groups
     security_groups = {
         'security_groups': [
             {'id': sec_grp_id}
         ]
     }
     list_security_groups.return_value = security_groups
     self.driver.deallocate_vip(vip)
     self.driver.neutron_client.update_port.assert_not_called()
 def test_unplug_aap_port(self):
     lb = dmh.generate_load_balancer_tree()
     update_port = self.driver.neutron_client.update_port
     port1 = t_constants.MOCK_NEUTRON_PORT['port']
     port2 = {
         'id': '4', 'network_id': '3', 'fixed_ips':
         [{'ip_address': '10.0.0.2'}]
     }
     subnet = network_models.Subnet(
         id=t_constants.MOCK_MANAGEMENT_SUBNET_ID,
         network_id='3')
     list_ports = self.driver.neutron_client.list_ports
     list_ports.return_value = {'ports': [port1, port2]}
     get_port = self.driver.neutron_client.get_port
     get_port.side_effect = neutron_exceptions.NotFound
     self.driver.unplug_aap_port(lb.vip, lb.amphorae[0], subnet)
     clear_aap = {'port': {'allowed_address_pairs': []}}
     update_port.assert_called_once_with(port2.get('id'), clear_aap)
    def test_deallocate_vip_when_secgrp_has_allocated_ports(self):
        max_retries = 1
        conf = oslo_fixture.Config(cfg.CONF)
        conf.config(group="networking", max_retries=max_retries)

        lb = dmh.generate_load_balancer_tree()
        lb.vip.load_balancer = lb
        vip = lb.vip
        show_port = self.driver.neutron_client.show_port
        show_port.return_value = {'port': {
            'device_owner': allowed_address_pairs.OCTAVIA_OWNER}}
        delete_port = self.driver.neutron_client.delete_port
        list_ports = self.driver.neutron_client.list_ports
        list_security_groups = self.driver.neutron_client.list_security_groups
        delete_sec_grp = self.driver.neutron_client.delete_security_group
        security_groups = {
            'security_groups': [
                {'id': t_constants.MOCK_SECURITY_GROUP_ID}
            ]
        }
        list_security_groups.return_value = security_groups
        delete_grp_results = [
            network_base.DeallocateVIPException
            for _ in range(max_retries + 1)]  # Total tries = max_retries + 1
        delete_grp_results.append(None)
        delete_sec_grp.side_effect = delete_grp_results
        list_ports.side_effect = [{
            "ports": [t_constants.MOCK_NEUTRON_PORT['port'],
                      t_constants.MOCK_NEUTRON_PORT2['port']]}]
        self.driver.deallocate_vip(vip)
        # First we expect the amp's ports to be deleted
        dp_calls = [mock.call(amp.vrrp_port_id) for amp in lb.amphorae]
        # Then after the SG delete fails, extra hanging-on ports are removed
        dp_calls.append(mock.call(t_constants.MOCK_PORT_ID))
        # Lastly we remove the vip port
        dp_calls.append(mock.call(vip.port_id))
        self.assertEqual(len(dp_calls), delete_port.call_count)
        delete_port.assert_has_calls(dp_calls)
        dsg_calls = [mock.call(t_constants.MOCK_SECURITY_GROUP_ID)
                     for _ in range(max_retries + 2)]  # Max fail + one success
        self.assertEqual(len(dsg_calls), delete_sec_grp.call_count)
        delete_sec_grp.assert_has_calls(dsg_calls)
 def test_deallocate_vip(self):
     lb = dmh.generate_load_balancer_tree()
     lb.vip.load_balancer = lb
     vip = lb.vip
     sec_grp_id = 'lb-sec-grp1'
     show_port = self.driver.neutron_client.show_port
     show_port.return_value = {
         'port': {
             'device_owner': allowed_address_pairs.OCTAVIA_OWNER
         }
     }
     delete_port = self.driver.neutron_client.delete_port
     delete_sec_grp = self.driver.neutron_client.delete_security_group
     list_security_groups = self.driver.neutron_client.list_security_groups
     security_groups = {'security_groups': [{'id': sec_grp_id}]}
     list_security_groups.return_value = security_groups
     self.driver.deallocate_vip(vip)
     calls = [mock.call(vip.port_id)]
     for amp in lb.amphorae:
         calls.append(mock.call(amp.vrrp_port_id))
     delete_port.assert_has_calls(calls, any_order=True)
     delete_sec_grp.assert_called_once_with(sec_grp_id)
    def test_plug_vip_errors_when_nova_cant_find_network_to_attach(self):
        lb = dmh.generate_load_balancer_tree()
        show_subnet = self.driver.neutron_client.show_subnet
        show_subnet.return_value = {
            'subnet': {
                'id': lb.vip.subnet_id
            }
        }
        list_security_groups = self.driver.neutron_client.list_security_groups
        lsc_side_effect = [
            None, {
                'security_groups': [
                    {'id': 'lb-sec-grp1'}
                ]
            }
        ]
        list_security_groups.side_effect = lsc_side_effect

        interface_attach = self.driver.nova_client.servers.interface_attach
        interface_attach.side_effect = nova_exceptions.NotFound(404, "Network")
        self.assertRaises(network_base.PlugVIPException,
                          self.driver.plug_vip, lb, lb.vip)
 def test_deallocate_vip(self):
     lb = dmh.generate_load_balancer_tree()
     lb.vip.load_balancer = lb
     vip = lb.vip
     sec_grp_id = 'lb-sec-grp1'
     show_port = self.driver.neutron_client.show_port
     show_port.return_value = {'port': {
         'device_owner': allowed_address_pairs.OCTAVIA_OWNER}}
     delete_port = self.driver.neutron_client.delete_port
     delete_sec_grp = self.driver.neutron_client.delete_security_group
     list_security_groups = self.driver.neutron_client.list_security_groups
     security_groups = {
         'security_groups': [
             {'id': sec_grp_id}
         ]
     }
     list_security_groups.return_value = security_groups
     self.driver.deallocate_vip(vip)
     calls = [mock.call(vip.port_id)]
     for amp in lb.amphorae:
         calls.append(mock.call(amp.vrrp_port_id))
     delete_port.assert_has_calls(calls, any_order=True)
     delete_sec_grp.assert_called_once_with(sec_grp_id)
    def test_plug_vip_errors_when_neutron_cant_find_port_to_update(self):
        lb = dmh.generate_load_balancer_tree()
        show_subnet = self.driver.neutron_client.show_subnet
        show_subnet.return_value = {
            'subnet': {
                'id': lb.vip.subnet_id
            }
        }
        list_security_groups = self.driver.neutron_client.list_security_groups
        lsc_side_effect = [
            None, {
                'security_groups': [
                    {'id': 'lb-sec-grp1'}
                ]
            }
        ]
        list_security_groups.side_effect = lsc_side_effect
        interface_attach = self.driver.nova_client.servers.interface_attach
        interface_attach.return_value = n_constants.MOCK_NOVA_INTERFACE

        update_port = self.driver.neutron_client.update_port
        update_port.side_effect = neutron_exceptions.PortNotFoundClient
        self.assertRaises(network_base.PortNotFound,
                          self.driver.plug_vip, lb, lb.vip)
 def test_unplug_vip(self, mock):
     lb = dmh.generate_load_balancer_tree()
     show_subnet = self.driver.neutron_client.show_subnet
     show_subnet.return_value = t_constants.MOCK_SUBNET
     self.driver.unplug_vip(lb, lb.vip)
     self.assertEqual(len(lb.amphorae), mock.call_count)
 def test_unplug_vip_errors_when_vip_subnet_not_found(self):
     lb = dmh.generate_load_balancer_tree()
     show_subnet = self.driver.neutron_client.show_subnet
     show_subnet.side_effect = neutron_exceptions.NotFound
     self.assertRaises(network_base.PluggedVIPNotFound,
                       self.driver.unplug_vip, lb, lb.vip)
 def test_unplug_vip_errors_when_vip_subnet_not_found(self):
     lb = dmh.generate_load_balancer_tree()
     show_subnet = self.driver.neutron_client.show_subnet
     show_subnet.side_effect = neutron_exceptions.NotFound
     self.assertRaises(network_base.PluggedVIPNotFound,
                       self.driver.unplug_vip, lb, lb.vip)
Esempio n. 42
0
 def _generate_lb(self):
     lb = dmh.generate_load_balancer_tree()
     lb.vip.load_balancer = lb
     return lb