def test_reply_message(self): network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api)) network_id = network.create() subnet = self.store( objects.SubnetTestObj(self.neutron, self.nb_api, network_id)) subnet_body = { 'network_id': network_id, 'cidr': '10.20.0.0/24', 'gateway_ip': '10.20.0.1', 'ip_version': 4, 'name': 'private', 'enable_dhcp': True } subnet.create(subnet=subnet_body) self.assertTrue(network.exists()) self.assertTrue(subnet.exists()) vm1 = self.store(objects.VMTestObj(self, self.neutron)) vm1.create(network=network) self.assertIsNotNone(vm1.server.addresses['mynetwork']) mac1 = vm1.server.addresses['mynetwork'][0]['OS-EXT-IPS-MAC:mac_addr'] self.assertIsNotNone(mac1) vm2 = self.store(objects.VMTestObj(self, self.neutron)) vm2.create(network=network) self.assertIsNotNone(vm2.server.addresses['mynetwork']) mac2 = vm2.server.addresses['mynetwork'][0]['OS-EXT-IPS-MAC:mac_addr'] self.assertIsNotNone(mac2) # wait util get the message we want self.set_wanted_vms.clear() utils.wait_until_true( lambda: self._get_all_wanted_vms_online(mac1, mac2), timeout=const.DEFAULT_RESOURCE_READY_TIMEOUT, sleep=1, exception=Exception('Could not get wanted online vm')) vm1.close() vm2.close() utils.wait_until_none( lambda: utils.get_vm_port(self.nb_api, ip=None, mac=mac1), timeout=const.DEFAULT_RESOURCE_READY_TIMEOUT, sleep=1, exception=Exception('Port was not deleted')) utils.wait_until_none( lambda: utils.get_vm_port(self.nb_api, ip=None, mac=mac2), timeout=const.DEFAULT_RESOURCE_READY_TIMEOUT, sleep=1, exception=Exception('Port was not deleted'))
def test_vm_multicast(self): network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api)) network_id = network.create() subnet = { 'network_id': network_id, 'cidr': '10.200.0.0/24', 'gateway_ip': '10.200.0.1', 'ip_version': 4, 'name': 'private', 'enable_dhcp': True } subnet = self.neutron.create_subnet({'subnet': subnet}) ovs = utils.OvsFlowsParser() vm = self.store(objects.VMTestObj(self, self.neutron)) vm.create(network=network) ip = vm.get_first_ipv4() self.assertIsNotNone(ip) self.assertIsNotNone(vm.server.addresses['mynetwork']) mac = vm.server.addresses['mynetwork'][0]['OS-EXT-IPS-MAC:mac_addr'] self.assertIsNotNone(mac) metadataid = utils.wait_until_is_and_return( lambda: self._get_metadata_id(ovs.dump(self.integration_bridge), ip, mac), exception=Exception('Metadata id was not found in OpenFlow rules')) port = utils.wait_until_is_and_return( lambda: utils.get_vm_port(self.nb_api, ip, mac), exception=Exception('No port assigned to VM')) tunnel_key = port.unique_key tunnel_key_hex = hex(tunnel_key) r = self._check_multicast_rule(ovs.dump(self.integration_bridge), metadataid, tunnel_key_hex) self.assertIsNotNone(r) vm.close() network.close()
def test_flat_network_flows(self): if not self._check_providers_net_app_enable(): return physical_network = self._parse_flat_network() if not physical_network: self.assertIsNotNone(None) return # Create network network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api)) network_params = { "name": "flat_1", "provider:network_type": "flat", "provider:physical_network": physical_network } network_id = network.create(network=network_params) # Create subnet subnet_params = { 'network_id': network_id, 'cidr': '100.64.1.0/24', 'gateway_ip': '10.64.1.1', 'ip_version': 4, 'name': 'private', 'enable_dhcp': True } subnet = self.neutron.create_subnet({'subnet': subnet_params}) self.assertIsNotNone(subnet) # Create VM ovs = utils.OvsFlowsParser() vm = self.store(objects.VMTestObj(self, self.neutron)) vm.create(network=network) ip = vm.get_first_ipv4() self.assertIsNotNone(ip) mac = vm.get_first_mac() self.assertIsNotNone(mac) metadataid = utils.wait_until_is_and_return( lambda: self._get_metadata_id(ovs.dump(self.integration_bridge), ip, mac), exception=Exception('Metadata id was not found in OpenFlow rules')) port = utils.wait_until_is_and_return( lambda: utils.get_vm_port(self.nb_api, ip, mac), exception=Exception('No port assigned to VM')) port_key = port.unique_key port_key_hex = hex(port_key) r = self._check_flat_flows(ovs.dump(self.integration_bridge), metadataid, port_key_hex, mac) for key, value in r.items(): self.assertIsNotNone(value, key) vm.server.stop() vm.close() network.close() return None
def test_anti_spoof_flows(self): network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api)) network_id = network.create() self.assertTrue(network.exists()) subnet_info = { 'network_id': network_id, 'cidr': '192.168.130.0/24', 'gateway_ip': '192.168.130.1', 'ip_version': 4, 'name': 'test_subnet1', 'enable_dhcp': True } subnet = self.store( objects.SubnetTestObj(self.neutron, self.nb_api, network_id=network_id)) subnet.create(subnet_info) self.assertTrue(subnet.exists()) vm = self.store(objects.VMTestObj(self, self.neutron)) vm.create(network=network) addresses = vm.server.addresses['mynetwork'] self.assertIsNotNone(addresses) ip = addresses[0]['addr'] self.assertIsNotNone(ip) mac = addresses[0]['OS-EXT-IPS-MAC:mac_addr'] self.assertIsNotNone(mac) port = utils.wait_until_is_and_return( lambda: utils.get_vm_port(self.nb_api, ip, mac), exception=Exception('No port assigned to VM')) of_port = self.vswitch_api.get_port_ofport_by_id(port.id) self.assertIsNotNone(of_port) unique_key = port.unique_key # Check if the associating flows were installed. expected_flow_list = self._get_anti_spoof_expected_flows( ip, mac, unique_key) self._check_all_flows_existed(expected_flow_list) vm.close() time.sleep(test_const.DEFAULT_RESOURCE_READY_TIMEOUT) # Check if the associating flows were removed. expected_flow_list = self._get_anti_spoof_expected_flows( ip, mac, unique_key) self._check_not_flow_existed(expected_flow_list)
def test_port_based_flows(self): if not self._check_if_app_enabled(): return network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api)) network_id = network.create() subnet = {'network_id': network_id, 'cidr': '10.200.0.0/24', 'gateway_ip': '10.200.0.1', 'ip_version': 4, 'name': 'private', 'enable_dhcp': True} external_host_ip = cfg.CONF.df.external_host_ip self.assertIsNotNone(external_host_ip) split_ip = external_host_ip.split('.') ip2mac = '{:02x}:{:02x}:{:02x}:{:02x}'.format(*map(int, split_ip)) external_host_mac = const.CHASSIS_MAC_PREFIX + ip2mac subnet = self.neutron.create_subnet({'subnet': subnet}) self.assertIsNotNone(subnet) # Create VM ovs = utils.OvsFlowsParser() vm = self.store(objects.VMTestObj(self, self.neutron)) vm.create(network=network) ip = vm.get_first_ipv4() self.assertIsNotNone(ip) mac = vm.get_first_mac() self.assertIsNotNone(mac) port = utils.wait_until_is_and_return( lambda: utils.get_vm_port(self.nb_api, ip, mac), exception=Exception('No port assigned to VM') ) port_key = port.unique_key r = self._check_port_based_flows( ovs.dump(self.integration_bridge), hex(port_key), external_host_mac, mac) for key, value in r.items(): self.assertIsNotNone(value, key) vm.server.stop() vm.close() network.close() return None
def test_tunnel_network_flows(self): if self._check_tunneling_app_enable() is False: return network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api)) network_id = network.create() network_params = network.get_network() segmentation_id = network_params['network']['provider:segmentation_id'] subnet = { 'network_id': network_id, 'cidr': '10.200.0.0/24', 'gateway_ip': '10.200.0.1', 'ip_version': 4, 'name': 'private', 'enable_dhcp': True } subnet = self.neutron.create_subnet({'subnet': subnet}) self.assertIsNotNone(subnet) ovs = utils.OvsFlowsParser() vm = self.store(objects.VMTestObj(self, self.neutron)) vm.create(network=network) ip = vm.get_first_ipv4() self.assertIsNotNone(ip) self.assertIsNotNone(vm.server.addresses['mynetwork']) mac = vm.server.addresses['mynetwork'][0]['OS-EXT-IPS-MAC:mac_addr'] self.assertIsNotNone(mac) metadataid = utils.wait_until_is_and_return( lambda: self._get_metadata_id(ovs.dump(self.integration_bridge), ip, mac), exception=Exception('Metadata id was not found in OpenFlow rules')) port = utils.wait_until_is_and_return( lambda: utils.get_vm_port(self.nb_api, ip, mac), exception=Exception('No port assigned to VM')) tunnel_key = port.unique_key tunnel_key_hex = hex(tunnel_key) n_type = network.get_network()['network']['provider:network_type'] ofport = self.vswitch_api.get_vtp_ofport(n_type) r = self._check_tunnel_flows(ovs.dump(self.integration_bridge), metadataid, hex(segmentation_id), tunnel_key_hex, mac, ofport) for key, value in r.items(): self.assertIsNotNone(value, key) vm.close() network.close()
def _test_associating_flows(self, subnet_info): network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api)) network_id = network.create() self.assertTrue(network.exists()) subnet_info['network_id'] = network_id subnet = self.store( objects.SubnetTestObj(self.neutron, self.nb_api, network_id=network_id)) subnet.create(subnet_info) self.assertTrue(subnet.exists()) security_group = self.store( objects.SecGroupTestObj(self.neutron, self.nb_api)) security_group_id = security_group.create() self.assertTrue(security_group.exists()) vm = self.store(objects.VMTestObj(self, self.neutron)) vm.create(network=network, security_groups=[security_group_id]) addresses = vm.server.addresses['mynetwork'] self.assertIsNotNone(addresses) ip = addresses[0]['addr'] self.assertIsNotNone(ip) mac = addresses[0]['OS-EXT-IPS-MAC:mac_addr'] self.assertIsNotNone(mac) port = utils.wait_until_is_and_return( lambda: utils.get_vm_port(self.nb_api, ip, mac), exception=Exception('No port assigned to VM')) tunnel_key = port.unique_key tunnel_key_hex = hex(tunnel_key) of_port = self.vswitch_api.get_port_ofport_by_id(port.id) self.assertIsNotNone(of_port) ovs = utils.OvsFlowsParser() flows_after_change = ovs.dump(self.integration_bridge) # Check if the associating flows were installed. ingress_associating_flow, egress_associating_flow = \ self._find_associating_flows(flows_after_change, tunnel_key_hex) LOG.info( "flows after associating a port and a security group" " are: %s", ovs.get_ovs_flows(self.integration_bridge)) self.assertIsNotNone(ingress_associating_flow) self.assertIsNotNone(egress_associating_flow) vm.close() time.sleep(test_const.DEFAULT_RESOURCE_READY_TIMEOUT) flows_after_update = ovs.dump(self.integration_bridge) # Check if the associating flows were removed. ingress_associating_flow, egress_associating_flow = \ self._find_associating_flows(flows_after_update, tunnel_key_hex) self.assertIsNone(ingress_associating_flow) self.assertIsNone(egress_associating_flow)