コード例 #1
0
ファイル: test_utils.py プロジェクト: sana-a10/a10-octavia
 def test_validate_vcs_device_info_valid(self):
     interface = utils.convert_interface_to_data_model(INTERFACE_CONF)
     device1_network_map = data_models.DeviceNetworkMap(vcs_device_id=1,
                                                        ethernet_interfaces=[interface])
     device2_network_map = data_models.DeviceNetworkMap(vcs_device_id=2,
                                                        mgmt_ip_address="10.0.0.2",
                                                        ethernet_interfaces=[interface])
     device_network_map = []
     self.assertEqual(utils.validate_vcs_device_info(device_network_map), None)
     device_network_map = [device1_network_map]
     self.assertEqual(utils.validate_vcs_device_info(device_network_map), None)
     device1_network_map.mgmt_ip_address = "10.0.0.1"
     self.assertEqual(utils.validate_vcs_device_info(device_network_map), None)
     device_network_map = [device1_network_map, device2_network_map]
     self.assertEqual(utils.validate_vcs_device_info(device_network_map), None)
コード例 #2
0
 def test_TagInterfaceForLB_create_trunk_vlan_ve_with_static_ip(self):
     intf = a10_utils.convert_interface_to_data_model(TRUNK_INTERFACE)
     device1_network_map = a10_data_models.DeviceNetworkMap(
         vcs_device_id=1, trunk_interfaces=[intf])
     mock_thunder = copy.deepcopy(VTHUNDER)
     mock_thunder.device_network_map = [device1_network_map]
     lb = self._mock_lb()
     mock_task = task.TagInterfaceForLB()
     self._mock_tag_task(mock_task)
     mock_task.get_vlan_id.return_value = VE_IP_VLAN_ID
     mock_task._subnet_ip = VE_IP_SUBNET_MASK[0]
     mock_task._subnet_mask = VE_IP_SUBNET_MASK[1]
     mock_task._subnet.cidr = VE_IP_SUBNET_MASK[2]
     self.client_mock.interface.ethernet.get.return_value = ETH_DATA
     self.client_mock.vlan.exists.return_value = False
     mock_task._network_driver.neutron_client.create_port = mock.Mock()
     mock_task._network_driver.get_network = mock.Mock()
     mock_task._network_driver.get_network.return_value = NETWORK_12
     mock_task._network_driver.list_networks = mock.Mock()
     mock_task._network_driver.list_networks.return_value = [NETWORK_12]
     mock_task.execute(lb, mock_thunder)
     self.client_mock.vlan.create.assert_called_with(
         VE_IP_VLAN_ID, tagged_trunks=[TAG_TRUNK_INTERFACE], veth=True)
     self.client_mock.interface.ve.create.assert_called_with(
         VE_IP_VLAN_ID,
         ip_address=STATIC_VE_IP,
         ip_netmask="255.255.255.0",
         enable=True)
コード例 #3
0
 def test_TagInterfaceForLB_create_vlan_ve_with_dhcp(self):
     intf = a10_utils.convert_interface_to_data_model(ETHERNET_INTERFACE)
     device1_network_map = a10_data_models.DeviceNetworkMap(
         vcs_device_id=1, ethernet_interfaces=[intf])
     mock_thunder = copy.deepcopy(VTHUNDER)
     mock_thunder.device_network_map = [device1_network_map]
     lb = self._mock_lb()
     mock_task = task.TagInterfaceForLB()
     self._mock_tag_task(mock_task)
     self.client_mock.interface.ethernet.get.return_value = ETH_DATA
     self.client_mock.vlan.exists.return_value = False
     mock_task._network_driver.neutron_client.create_port = mock.Mock()
     utils.convert_port_dict_to_model = mock.Mock()
     mock_task._network_driver.get_network = mock.Mock()
     mock_task._network_driver.get_network.return_value = NETWORK_11
     mock_task._network_driver.list_networks = mock.Mock()
     mock_task._network_driver.list_networks.return_value = [NETWORK_11]
     mock_task.execute(lb, mock_thunder)
     self.client_mock.vlan.create.assert_called_with(
         VLAN_ID, tagged_eths=[TAG_INTERFACE], veth=True)
     args, kwargs = mock_task._network_driver.neutron_client.create_port.call_args
     self.assertIn('port', args[0])
     port = args[0]['port']
     fixed_ip = port['fixed_ips'][0]
     self.assertEqual(VE_IP, fixed_ip['ip_address'])
コード例 #4
0
 def test_TagInterfaceForLB_create_vlan_ve_with_axapi_exception(self):
     intf = a10_utils.convert_interface_to_data_model(ETHERNET_INTERFACE)
     device1_network_map = a10_data_models.DeviceNetworkMap(
         vcs_device_id=1, ethernet_interfaces=[intf])
     mock_thunder = copy.deepcopy(VTHUNDER)
     mock_thunder.device_network_map = [device1_network_map]
     lb = self._mock_lb()
     mock_task = task.TagInterfaceForLB()
     self._mock_tag_task(mock_task)
     self.client_mock.interface.ethernet.get.return_value = ETH_DATA
     self.client_mock.vlan.exists.side_effect = Exception
     self.assertRaises(Exception,
                       lambda: mock_task.execute(lb, mock_thunder))
コード例 #5
0
ファイル: test_utils.py プロジェクト: ytsai-a10/a10-octavia
 def test_validate_vcs_device_info_invalid(self):
     interface = utils.convert_interface_to_data_model(INTERFACE_CONF)
     device1_network_map = data_models.DeviceNetworkMap(
         mgmt_ip_address="10.0.0.1", ethernet_interfaces=[interface])
     device2_network_map = data_models.DeviceNetworkMap(
         mgmt_ip_address="10.0.0.2", ethernet_interfaces=[interface])
     device1_network_map.vcs_device_id = 3
     device_network_map = [device1_network_map]
     self.assertRaises(exceptions.InvalidVcsDeviceIdConfigError,
                       utils.validate_vcs_device_info, device_network_map)
     device1_network_map.vcs_device_id = 0
     device_network_map = [device1_network_map]
     self.assertRaises(exceptions.InvalidVcsDeviceIdConfigError,
                       utils.validate_vcs_device_info, device_network_map)
     device1_network_map.vcs_device_id = 1
     device2_network_map.vcs_device_id = 3
     device_network_map = [device1_network_map, device2_network_map]
     self.assertRaises(exceptions.InvalidVcsDeviceIdConfigError,
                       utils.validate_vcs_device_info, device_network_map)
     device1_network_map.vcs_device_id = 0
     device2_network_map.vcs_device_id = 2
     device_network_map = [device1_network_map, device2_network_map]
     self.assertRaises(exceptions.InvalidVcsDeviceIdConfigError,
                       utils.validate_vcs_device_info, device_network_map)
     device1_network_map.vcs_device_id = 1
     device2_network_map.vcs_device_id = None
     device_network_map = [device1_network_map, device2_network_map]
     self.assertRaises(exceptions.InvalidVcsDeviceIdConfigError,
                       utils.validate_vcs_device_info, device_network_map)
     device_network_map = [
         device1_network_map, device2_network_map, device2_network_map
     ]
     self.assertRaises(exceptions.VcsDevicesNumberExceedsConfigError,
                       utils.validate_vcs_device_info, device_network_map)
     device2_network_map.vcs_device_id = 2
     device2_network_map.mgmt_ip_address = None
     device_network_map = [device1_network_map, device2_network_map]
     self.assertRaises(exceptions.MissingMgmtIpConfigError,
                       utils.validate_vcs_device_info, device_network_map)
コード例 #6
0
 def test_TagInterfaceForMember_create_vlan_ve_with_neutron_exception(self):
     intf = a10_utils.convert_interface_to_data_model(ETHERNET_INTERFACE)
     device1_network_map = a10_data_models.DeviceNetworkMap(
         vcs_device_id=1, ethernet_interfaces=[intf])
     mock_thunder = copy.deepcopy(VTHUNDER)
     mock_thunder.device_network_map = [device1_network_map]
     member = self._mock_member()
     mock_task = task.TagInterfaceForMember()
     self._mock_tag_task(mock_task)
     self.client_mock.interface.ethernet.get.return_value = ETH_DATA
     self.client_mock.vlan.exists.return_value = False
     mock_task._network_driver.neutron_client.create_port = mock.Mock()
     mock_task._network_driver.neutron_client.create_port.side_effect = Exception
     self.assertRaises(Exception,
                       lambda: mock_task.execute(member, mock_thunder))
コード例 #7
0
 def test_DeleteInterfaceTagIfNotInUseForMember_execute_delete_vlan(self):
     intf = a10_utils.convert_interface_to_data_model(ETHERNET_INTERFACE)
     device1_network_map = a10_data_models.DeviceNetworkMap(
         vcs_device_id=1, ethernet_interfaces=[intf])
     mock_thunder = copy.deepcopy(VTHUNDER)
     mock_thunder.device_network_map = [device1_network_map]
     member = self._mock_member()
     mock_task = task.DeleteInterfaceTagIfNotInUseForMember()
     self._mock_tag_task(mock_task)
     mock_task.axapi_client.slb.virtual_server.get.return_value = DEL_VS_LIST
     mock_task.axapi_client.slb.server.get.return_value = DEL_SERVER_LIST
     mock_task._network_driver.get_port_id_from_ip = mock.Mock()
     mock_task._network_driver.neutron_client.delete_port = mock.Mock()
     mock_task._network_driver.get_port_id_from_ip.return_value = DEL_PORT_ID
     mock_task.execute(member, mock_thunder)
     self.client_mock.vlan.delete.assert_called_with(VLAN_ID)
     mock_task._network_driver.neutron_client.delete_port.assert_called_with(
         DEL_PORT_ID)
コード例 #8
0
ファイル: utils.py プロジェクト: sana-a10/a10-octavia
def validate_interface_vlan_map(hardware_device):
    device_network_map = []
    for device_id, device_obj in hardware_device.get(
            'interface_vlan_map').items():
        device_map = data_models.DeviceNetworkMap(
            device_obj.get('vcs_device_id'))
        if device_obj.get('ethernet_interfaces'):
            for eth in device_obj.get('ethernet_interfaces'):
                device_map.ethernet_interfaces.append(
                    convert_interface_to_data_model(eth))
        if device_obj.get('trunk_interfaces'):
            for trunk in device_obj.get('trunk_interfaces'):
                device_map.trunk_interfaces.append(
                    convert_interface_to_data_model(trunk))
        if device_obj.get('mgmt_ip_address'):
            device_map.mgmt_ip_address = device_obj.get('mgmt_ip_address')
        device_network_map.append(device_map)
    validate_vcs_device_info(device_network_map)
    return device_network_map
コード例 #9
0
ファイル: test_utils.py プロジェクト: sana-a10/a10-octavia
DEVICE_FLAVOR_KEY = '[dev]rack_thunder_3'
RESULT_HMT_HARDWARE_DEVICE_LIST = {
    DEVICE_FLAVOR_KEY: VTHUNDER_3_DEV,
    a10constants.MOCK_CHILD_PROJECT_ID: VTHUNDER_3
}

INTERFACE_CONF = {"interface_num": 1,
                  "vlan_map": [
                      {"vlan_id": 11, "ve_ip": "10.20"},
                      {"vlan_id": 12, "use_dhcp": "True"},
                      {"vlan_id": 13, "ve_ip": "10.30"}]
                  }
INTERFACE = data_models.Interface(interface_num=1, tags=[11, 12, 13], ve_ips=[
                                  "10.20", "dhcp", "10.30"])
DEVICE_NETWORK_MAP = [data_models.DeviceNetworkMap(
    vcs_device_id=1, ethernet_interfaces=[INTERFACE])]
HARDWARE_VLAN_INFO = {
    "interface_vlan_map": {
        "device_1": {
            "vcs_device_id": 1,
            "ethernet_interfaces": [INTERFACE_CONF]
        }
    }
}

NAT_FLAVOR = {"pool_name": "p1", "start_address": "1.1.1.1", "end_address": "1.1.1.3"}


class FakeProject(object):
    def __init__(self, parent_id='default'):
        self.parent_id = parent_id
コード例 #10
0
ファイル: test_utils.py プロジェクト: ytsai-a10/a10-octavia
    "vlan_map": [{
        "vlan_id": 11,
        "ve_ip": "10.20"
    }, {
        "vlan_id": 12,
        "use_dhcp": "True"
    }, {
        "vlan_id": 13,
        "ve_ip": "10.30"
    }]
}
INTERFACE = data_models.Interface(interface_num=1,
                                  tags=[11, 12, 13],
                                  ve_ips=["10.20", "dhcp", "10.30"])
DEVICE_NETWORK_MAP = [
    data_models.DeviceNetworkMap(vcs_device_id=1,
                                 ethernet_interfaces=[INTERFACE])
]
HARDWARE_VLAN_INFO = {
    "interface_vlan_map": {
        "device_1": {
            "vcs_device_id": 1,
            "ethernet_interfaces": [INTERFACE_CONF]
        }
    }
}


class FakeProject(object):
    def __init__(self, parent_id='default'):
        self.parent_id = parent_id