From ff34dae544f744507fbeb7edb63e91bf5f9dca2b Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Thu, 26 Jun 2014 16:03:19 +0900 Subject: [PATCH] remove unnecessary neutron files under neutron/tests Change-Id: Id1f4ed4a5752a6622cb59a4836cd4189d7ee615c --- neutron/tests/functional/agent/linux/base.py | 74 - .../agent/linux/test_async_process.py | 71 - .../agent/linux/test_ovsdb_monitor.py | 108 - neutron/tests/functional/sanity/__init__.py | 0 .../functional/sanity/test_ovs_sanity.py | 46 - .../unit/_test_extension_portbindings.py | 377 -- .../tests/unit/agent/linux/test_ovs_lib.py | 967 ---- .../unit/agent/linux/test_ovsdb_monitor.py | 105 - .../tests/unit/agent/linux/test_polling.py | 116 - neutron/tests/unit/api/__init__.py | 0 neutron/tests/unit/api/rpc/__init__.py | 0 .../unit/api/rpc/agentnotifiers/__init__.py | 0 .../agentnotifiers/test_dhcp_rpc_agent_api.py | 154 - neutron/tests/unit/bigswitch/__init__.py | 16 - .../unit/bigswitch/etc/restproxy.ini.test | 44 - .../unit/bigswitch/etc/ssl/ca_certs/README | 2 - .../unit/bigswitch/etc/ssl/combined/README | 2 - .../unit/bigswitch/etc/ssl/host_certs/README | 2 - neutron/tests/unit/bigswitch/fake_server.py | 185 - .../unit/bigswitch/test_agent_scheduler.py | 33 - neutron/tests/unit/bigswitch/test_base.py | 74 - .../tests/unit/bigswitch/test_capabilities.py | 84 - .../unit/bigswitch/test_restproxy_agent.py | 188 - .../unit/bigswitch/test_restproxy_plugin.py | 316 -- .../tests/unit/bigswitch/test_router_db.py | 554 --- .../unit/bigswitch/test_security_groups.py | 47 - .../unit/bigswitch/test_servermanager.py | 467 -- neutron/tests/unit/bigswitch/test_ssl.py | 250 -- neutron/tests/unit/brocade/__init__.py | 17 - neutron/tests/unit/brocade/test_brocade_db.py | 100 - .../tests/unit/brocade/test_brocade_plugin.py | 74 - .../tests/unit/brocade/test_brocade_vlan.py | 73 - neutron/tests/unit/cisco/__init__.py | 16 - neutron/tests/unit/cisco/n1kv/__init__.py | 18 - neutron/tests/unit/cisco/n1kv/fake_client.py | 119 - neutron/tests/unit/cisco/n1kv/test_n1kv_db.py | 870 ---- .../tests/unit/cisco/n1kv/test_n1kv_plugin.py | 709 --- neutron/tests/unit/cisco/test_config.py | 72 - neutron/tests/unit/cisco/test_network_db.py | 291 -- .../tests/unit/cisco/test_network_plugin.py | 1186 ----- neutron/tests/unit/cisco/test_nexus_db.py | 239 - neutron/tests/unit/cisco/test_nexus_plugin.py | 301 -- neutron/tests/unit/cisco/test_plugin_model.py | 63 - neutron/tests/unit/db/firewall/__init__.py | 15 - .../unit/db/firewall/test_db_firewall.py | 1055 ----- .../tests/unit/db/loadbalancer/__init__.py | 15 - .../db/loadbalancer/test_db_loadbalancer.py | 1572 ------- neutron/tests/unit/db/metering/__init__.py | 15 - .../unit/db/metering/test_db_metering.py | 291 -- neutron/tests/unit/db/test_agent_db.py | 86 - neutron/tests/unit/db/test_quota_db.py | 143 - neutron/tests/unit/db/vpn/__init__.py | 17 - neutron/tests/unit/db/vpn/test_db_vpnaas.py | 1670 ------- neutron/tests/unit/dummy_plugin.py | 139 - neutron/tests/unit/embrane/__init__.py | 18 - .../unit/embrane/test_embrane_defaults.py | 31 - .../unit/embrane/test_embrane_l3_plugin.py | 41 - .../embrane/test_embrane_neutron_plugin.py | 82 - neutron/tests/unit/hyperv/__init__.py | 16 - .../unit/hyperv/test_hyperv_neutron_agent.py | 221 - .../unit/hyperv/test_hyperv_neutron_plugin.py | 69 - .../tests/unit/hyperv/test_hyperv_rpcapi.py | 125 - .../test_hyperv_security_groups_driver.py | 189 - .../unit/hyperv/test_hyperv_utilsfactory.py | 54 - .../tests/unit/hyperv/test_hyperv_utilsv2.py | 519 --- neutron/tests/unit/ibm/__init__.py | 0 neutron/tests/unit/ibm/test_sdnve_agent.py | 118 - neutron/tests/unit/ibm/test_sdnve_api.py | 145 - neutron/tests/unit/ibm/test_sdnve_plugin.py | 126 - neutron/tests/unit/linuxbridge/__init__.py | 16 - .../unit/linuxbridge/test_agent_scheduler.py | 34 - .../tests/unit/linuxbridge/test_defaults.py | 42 - neutron/tests/unit/linuxbridge/test_lb_db.py | 172 - .../unit/linuxbridge/test_lb_neutron_agent.py | 1054 ----- .../linuxbridge/test_lb_security_group.py | 99 - .../linuxbridge/test_linuxbridge_plugin.py | 132 - neutron/tests/unit/linuxbridge/test_rpcapi.py | 132 - neutron/tests/unit/metaplugin/__init__.py | 16 - neutron/tests/unit/metaplugin/fake_plugin.py | 79 - neutron/tests/unit/metaplugin/test_basic.py | 78 - .../tests/unit/metaplugin/test_metaplugin.py | 404 -- neutron/tests/unit/midonet/__init__.py | 17 - .../tests/unit/midonet/etc/midonet.ini.test | 16 - neutron/tests/unit/midonet/mock_lib.py | 265 -- .../tests/unit/midonet/test_midonet_driver.py | 55 - .../tests/unit/midonet/test_midonet_lib.py | 189 - .../tests/unit/midonet/test_midonet_plugin.py | 218 - neutron/tests/unit/ml2/__init__.py | 14 - neutron/tests/unit/ml2/_test_mech_agent.py | 218 - neutron/tests/unit/ml2/drivers/__init__.py | 14 - .../unit/ml2/drivers/brocade/__init__.py | 0 .../brocade/test_brocade_mechanism_driver.py | 69 - .../tests/unit/ml2/drivers/cisco/__init__.py | 0 .../unit/ml2/drivers/cisco/apic/__init__.py | 0 .../cisco/apic/test_cisco_apic_client.py | 272 -- .../cisco/apic/test_cisco_apic_common.py | 225 - .../cisco/apic/test_cisco_apic_manager.py | 698 --- .../apic/test_cisco_apic_mechanism_driver.py | 226 - .../unit/ml2/drivers/cisco/nexus/__init__.py | 0 .../drivers/cisco/nexus/test_cisco_config.py | 71 - .../drivers/cisco/nexus/test_cisco_mech.py | 715 --- .../drivers/cisco/nexus/test_cisco_nexus.py | 201 - .../cisco/nexus/test_cisco_nexus_db.py | 206 - .../unit/ml2/drivers/mechanism_bulkless.py | 23 - .../unit/ml2/drivers/mechanism_logger.py | 120 - .../tests/unit/ml2/drivers/mechanism_test.py | 171 - .../drivers/test_arista_mechanism_driver.py | 726 --- .../unit/ml2/drivers/test_bigswitch_mech.py | 144 - .../unit/ml2/drivers/test_l2population.py | 724 --- .../tests/unit/ml2/drivers/test_mech_mlnx.py | 139 - .../unit/ml2/drivers/test_ofagent_mech.py | 74 - .../tests/unit/ml2/test_agent_scheduler.py | 36 - neutron/tests/unit/ml2/test_mech_hyperv.py | 65 - .../tests/unit/ml2/test_mech_linuxbridge.py | 74 - .../tests/unit/ml2/test_mech_openvswitch.py | 74 - .../tests/unit/ml2/test_mechanism_fslsdn.py | 293 -- neutron/tests/unit/ml2/test_mechanism_ncs.py | 50 - neutron/tests/unit/ml2/test_mechanism_odl.py | 117 - neutron/tests/unit/ml2/test_ml2_plugin.py | 477 -- neutron/tests/unit/ml2/test_port_binding.py | 136 - neutron/tests/unit/ml2/test_rpcapi.py | 109 - neutron/tests/unit/ml2/test_security_group.py | 106 - neutron/tests/unit/ml2/test_type_flat.py | 98 - neutron/tests/unit/ml2/test_type_gre.py | 208 - neutron/tests/unit/ml2/test_type_local.py | 56 - neutron/tests/unit/ml2/test_type_vlan.py | 187 - neutron/tests/unit/ml2/test_type_vxlan.py | 227 - neutron/tests/unit/mlnx/__init__.py | 16 - .../tests/unit/mlnx/test_agent_scheduler.py | 34 - neutron/tests/unit/mlnx/test_defaults.py | 39 - .../tests/unit/mlnx/test_mlnx_comm_utils.py | 139 - neutron/tests/unit/mlnx/test_mlnx_db.py | 181 - .../unit/mlnx/test_mlnx_neutron_agent.py | 156 - neutron/tests/unit/mlnx/test_mlnx_plugin.py | 116 - .../unit/mlnx/test_mlnx_plugin_config.py | 89 - .../unit/mlnx/test_mlnx_security_group.py | 100 - neutron/tests/unit/mlnx/test_rpcapi.py | 155 - neutron/tests/unit/nec/__init__.py | 15 - neutron/tests/unit/nec/fake_ofc_manager.py | 106 - neutron/tests/unit/nec/stub_ofc_driver.py | 293 -- .../tests/unit/nec/test_agent_scheduler.py | 118 - neutron/tests/unit/nec/test_config.py | 44 - neutron/tests/unit/nec/test_db.py | 176 - neutron/tests/unit/nec/test_nec_agent.py | 366 -- neutron/tests/unit/nec/test_nec_plugin.py | 930 ---- neutron/tests/unit/nec/test_ofc_client.py | 179 - neutron/tests/unit/nec/test_ofc_manager.py | 297 -- neutron/tests/unit/nec/test_packet_filter.py | 714 --- neutron/tests/unit/nec/test_pfc_driver.py | 705 --- neutron/tests/unit/nec/test_portbindings.py | 350 -- neutron/tests/unit/nec/test_router.py | 45 - neutron/tests/unit/nec/test_security_group.py | 101 - neutron/tests/unit/nec/test_trema_driver.py | 353 -- neutron/tests/unit/nec/test_utils.py | 31 - neutron/tests/unit/notifiers/__init__.py | 0 .../unit/notifiers/test_notifiers_nova.py | 305 -- neutron/tests/unit/nuage/__init__.py | 0 neutron/tests/unit/nuage/fake_nuageclient.py | 115 - neutron/tests/unit/nuage/test_netpartition.py | 100 - neutron/tests/unit/nuage/test_nuage_plugin.py | 283 -- neutron/tests/unit/ofagent/__init__.py | 0 neutron/tests/unit/ofagent/fake_oflib.py | 113 - .../tests/unit/ofagent/test_ofa_defaults.py | 25 - .../unit/ofagent/test_ofa_neutron_agent.py | 1023 ----- neutron/tests/unit/oneconvergence/__init__.py | 0 .../unit/oneconvergence/test_nvsd_agent.py | 177 - .../unit/oneconvergence/test_nvsd_plugin.py | 152 - .../tests/unit/oneconvergence/test_nvsdlib.py | 261 -- .../unit/oneconvergence/test_plugin_helper.py | 60 - .../oneconvergence/test_security_group.py | 157 - neutron/tests/unit/openvswitch/__init__.py | 16 - .../unit/openvswitch/test_agent_scheduler.py | 1245 ------ .../openvswitch/test_openvswitch_plugin.py | 88 - neutron/tests/unit/openvswitch/test_ovs_db.py | 322 -- .../unit/openvswitch/test_ovs_defaults.py | 35 - .../openvswitch/test_ovs_neutron_agent.py | 954 ---- .../tests/unit/openvswitch/test_ovs_rpcapi.py | 123 - .../openvswitch/test_ovs_security_group.py | 104 - .../tests/unit/openvswitch/test_ovs_tunnel.py | 603 --- neutron/tests/unit/plumgrid/__init__.py | 17 - .../unit/plumgrid/test_plumgrid_plugin.py | 171 - neutron/tests/unit/ryu/__init__.py | 16 - neutron/tests/unit/ryu/fake_ryu.py | 42 - neutron/tests/unit/ryu/test_defaults.py | 33 - neutron/tests/unit/ryu/test_ryu_agent.py | 651 --- neutron/tests/unit/ryu/test_ryu_db.py | 57 - neutron/tests/unit/ryu/test_ryu_plugin.py | 51 - .../tests/unit/ryu/test_ryu_security_group.py | 92 - .../tests/unit/services/firewall/__init__.py | 15 - .../unit/services/firewall/agents/__init__.py | 15 - .../firewall/agents/l3reference/__init__.py | 15 - .../l3reference/test_firewall_l3_agent.py | 391 -- .../agents/test_firewall_agent_api.py | 105 - .../firewall/agents/varmour/__init__.py | 16 - .../agents/varmour/test_varmour_router.py | 322 -- .../services/firewall/drivers/__init__.py | 15 - .../firewall/drivers/linux/__init__.py | 15 - .../drivers/linux/test_iptables_fwaas.py | 218 - .../firewall/drivers/varmour/__init__.py | 16 - .../drivers/varmour/test_varmour_fwaas.py | 290 -- .../services/firewall/test_fwaas_plugin.py | 401 -- .../tests/unit/services/l3_router/__init__.py | 0 .../services/l3_router/test_l3_apic_plugin.py | 134 - .../unit/services/loadbalancer/__init__.py | 17 - .../services/loadbalancer/agent/__init__.py | 0 .../services/loadbalancer/agent/test_agent.py | 51 - .../loadbalancer/agent/test_agent_manager.py | 371 -- .../services/loadbalancer/agent/test_api.py | 166 - .../services/loadbalancer/drivers/__init__.py | 17 - .../loadbalancer/drivers/embrane/__init__.py | 0 .../drivers/embrane/test_embrane_defaults.py | 30 - .../drivers/embrane/test_plugin_driver.py | 93 - .../loadbalancer/drivers/haproxy/__init__.py | 17 - .../loadbalancer/drivers/haproxy/test_cfg.py | 228 - .../drivers/haproxy/test_namespace_driver.py | 550 --- .../drivers/netscaler/__init__.py | 0 .../drivers/netscaler/test_ncc_client.py | 204 - .../netscaler/test_netscaler_driver.py | 802 ---- .../loadbalancer/drivers/radware/__init__.py | 15 - .../drivers/radware/test_plugin_driver.py | 961 ---- .../drivers/test_agent_driver_base.py | 753 ---- .../loadbalancer/test_agent_scheduler.py | 222 - .../loadbalancer/test_loadbalancer_plugin.py | 464 -- .../test_loadbalancer_quota_ext.py | 168 - .../tests/unit/services/metering/__init__.py | 15 - .../services/metering/drivers/__init__.py | 15 - .../metering/drivers/test_iptables_driver.py | 408 -- .../services/metering/test_metering_agent.py | 160 - .../services/metering/test_metering_plugin.py | 448 -- neutron/tests/unit/services/vpn/__init__.py | 17 - .../services/vpn/device_drivers/__init__.py | 16 - .../vpn/device_drivers/cisco_csr_mock.py | 579 --- .../device_drivers/notest_cisco_csr_rest.py | 1346 ------ .../vpn/device_drivers/test_cisco_ipsec.py | 1709 ------- .../services/vpn/device_drivers/test_ipsec.py | 258 -- .../services/vpn/service_drivers/__init__.py | 16 - .../vpn/service_drivers/test_cisco_ipsec.py | 365 -- .../vpn/service_drivers/test_ipsec.py | 91 - .../tests/unit/services/vpn/test_vpn_agent.py | 196 - .../services/vpn/test_vpnaas_driver_plugin.py | 160 - .../services/vpn/test_vpnaas_extension.py | 530 --- neutron/tests/unit/test_agent_config.py | 44 - neutron/tests/unit/test_agent_ext_plugin.py | 259 -- neutron/tests/unit/test_agent_linux_utils.py | 162 - .../tests/unit/test_agent_netns_cleanup.py | 258 -- neutron/tests/unit/test_agent_ovs_cleanup.py | 93 - neutron/tests/unit/test_db_plugin.py | 3982 ----------------- neutron/tests/unit/test_db_rpc_base.py | 233 - neutron/tests/unit/test_debug_commands.py | 363 -- neutron/tests/unit/test_dhcp_agent.py | 1466 ------ neutron/tests/unit/test_dhcp_scheduler.py | 90 - .../test_extension_allowedaddresspairs.py | 262 -- .../tests/unit/test_extension_ext_gw_mode.py | 421 -- neutron/tests/unit/test_extension_ext_net.py | 176 - .../unit/test_extension_extradhcpopts.py | 266 -- .../tests/unit/test_extension_extraroute.py | 500 --- neutron/tests/unit/test_extension_firewall.py | 495 -- neutron/tests/unit/test_extension_pnet.py | 161 - .../tests/unit/test_extension_portsecurity.py | 392 -- .../unit/test_extension_security_group.py | 1431 ------ neutron/tests/unit/test_iptables_firewall.py | 1225 ----- neutron/tests/unit/test_iptables_manager.py | 705 --- neutron/tests/unit/test_ipv6.py | 50 - neutron/tests/unit/test_l3_agent.py | 1379 ------ neutron/tests/unit/test_l3_plugin.py | 2070 --------- neutron/tests/unit/test_l3_schedulers.py | 206 - neutron/tests/unit/test_linux_daemon.py | 211 - neutron/tests/unit/test_linux_dhcp.py | 1252 ------ .../tests/unit/test_linux_external_process.py | 202 - neutron/tests/unit/test_linux_interface.py | 620 --- neutron/tests/unit/test_linux_ip_lib.py | 860 ---- neutron/tests/unit/test_metadata_agent.py | 581 --- .../unit/test_metadata_namespace_proxy.py | 353 -- neutron/tests/unit/test_neutron_manager.py | 146 - .../tests/unit/test_provider_configuration.py | 201 - neutron/tests/unit/test_quota_ext.py | 432 -- .../tests/unit/test_routerserviceinsertion.py | 490 -- .../tests/unit/test_security_groups_rpc.py | 2047 --------- neutron/tests/unit/test_servicetype.py | 241 - neutron/tests/unit/vmware/__init__.py | 53 - .../tests/unit/vmware/apiclient/__init__.py | 0 neutron/tests/unit/vmware/apiclient/fake.py | 660 --- .../unit/vmware/apiclient/test_api_common.py | 35 - .../apiclient/test_api_eventlet_request.py | 331 -- neutron/tests/unit/vmware/db/__init__.py | 0 neutron/tests/unit/vmware/db/test_lsn_db.py | 103 - neutron/tests/unit/vmware/db/test_nsx_db.py | 86 - .../unit/vmware/etc/fake_get_gwservice.json | 15 - .../unit/vmware/etc/fake_get_lqueue.json | 11 - .../unit/vmware/etc/fake_get_lrouter.json | 29 - .../vmware/etc/fake_get_lrouter_lport.json | 12 - .../etc/fake_get_lrouter_lport_att.json | 11 - .../unit/vmware/etc/fake_get_lrouter_nat.json | 6 - .../unit/vmware/etc/fake_get_lswitch.json | 12 - .../vmware/etc/fake_get_lswitch_lport.json | 28 - .../etc/fake_get_lswitch_lport_att.json | 7 - .../etc/fake_get_lswitch_lport_status.json | 23 - .../vmware/etc/fake_get_security_profile.json | 10 - .../unit/vmware/etc/fake_post_gwservice.json | 13 - .../unit/vmware/etc/fake_post_lqueue.json | 11 - .../unit/vmware/etc/fake_post_lrouter.json | 23 - .../vmware/etc/fake_post_lrouter_lport.json | 10 - .../vmware/etc/fake_post_lrouter_nat.json | 6 - .../unit/vmware/etc/fake_post_lswitch.json | 12 - .../vmware/etc/fake_post_lswitch_lport.json | 17 - .../etc/fake_post_security_profile.json | 10 - .../etc/fake_put_lrouter_lport_att.json | 12 - .../etc/fake_put_lswitch_lport_att.json | 11 - .../tests/unit/vmware/etc/neutron.conf.test | 26 - .../unit/vmware/etc/nsx.ini.agentless.test | 17 - .../tests/unit/vmware/etc/nsx.ini.basic.test | 5 - .../unit/vmware/etc/nsx.ini.combined.test | 17 - .../tests/unit/vmware/etc/nsx.ini.full.test | 13 - neutron/tests/unit/vmware/etc/nsx.ini.test | 7 - .../tests/unit/vmware/etc/nvp.ini.full.test | 13 - neutron/tests/unit/vmware/etc/vcns.ini.test | 9 - .../tests/unit/vmware/extensions/__init__.py | 0 .../vmware/extensions/test_addresspairs.py | 22 - .../vmware/extensions/test_maclearning.py | 139 - .../unit/vmware/extensions/test_networkgw.py | 1074 ----- .../vmware/extensions/test_portsecurity.py | 47 - .../vmware/extensions/test_providernet.py | 163 - .../unit/vmware/extensions/test_qosqueues.py | 273 -- neutron/tests/unit/vmware/nsxlib/__init__.py | 0 neutron/tests/unit/vmware/nsxlib/base.py | 88 - .../unit/vmware/nsxlib/test_l2gateway.py | 296 -- neutron/tests/unit/vmware/nsxlib/test_lsn.py | 370 -- .../tests/unit/vmware/nsxlib/test_queue.py | 69 - .../tests/unit/vmware/nsxlib/test_router.py | 922 ---- .../tests/unit/vmware/nsxlib/test_secgroup.py | 140 - .../tests/unit/vmware/nsxlib/test_switch.py | 314 -- .../unit/vmware/nsxlib/test_versioning.py | 58 - .../tests/unit/vmware/test_agent_scheduler.py | 65 - neutron/tests/unit/vmware/test_dhcpmeta.py | 1429 ------ neutron/tests/unit/vmware/test_nsx_opts.py | 253 -- neutron/tests/unit/vmware/test_nsx_plugin.py | 1181 ----- neutron/tests/unit/vmware/test_nsx_sync.py | 712 --- neutron/tests/unit/vmware/test_nsx_utils.py | 325 -- neutron/tests/unit/vmware/vshield/__init__.py | 0 .../tests/unit/vmware/vshield/fake_vcns.py | 600 --- .../unit/vmware/vshield/test_edge_router.py | 308 -- .../vmware/vshield/test_firewall_driver.py | 375 -- .../unit/vmware/vshield/test_fwaas_plugin.py | 697 --- .../unit/vmware/vshield/test_lbaas_plugin.py | 532 --- .../vshield/test_loadbalancer_driver.py | 340 -- .../unit/vmware/vshield/test_vcns_driver.py | 587 --- .../unit/vmware/vshield/test_vpnaas_plugin.py | 417 -- 347 files changed, 90033 deletions(-) delete mode 100644 neutron/tests/functional/agent/linux/base.py delete mode 100644 neutron/tests/functional/agent/linux/test_async_process.py delete mode 100644 neutron/tests/functional/agent/linux/test_ovsdb_monitor.py delete mode 100644 neutron/tests/functional/sanity/__init__.py delete mode 100644 neutron/tests/functional/sanity/test_ovs_sanity.py delete mode 100644 neutron/tests/unit/_test_extension_portbindings.py delete mode 100644 neutron/tests/unit/agent/linux/test_ovs_lib.py delete mode 100644 neutron/tests/unit/agent/linux/test_ovsdb_monitor.py delete mode 100644 neutron/tests/unit/agent/linux/test_polling.py delete mode 100644 neutron/tests/unit/api/__init__.py delete mode 100644 neutron/tests/unit/api/rpc/__init__.py delete mode 100644 neutron/tests/unit/api/rpc/agentnotifiers/__init__.py delete mode 100644 neutron/tests/unit/api/rpc/agentnotifiers/test_dhcp_rpc_agent_api.py delete mode 100644 neutron/tests/unit/bigswitch/__init__.py delete mode 100644 neutron/tests/unit/bigswitch/etc/restproxy.ini.test delete mode 100644 neutron/tests/unit/bigswitch/etc/ssl/ca_certs/README delete mode 100644 neutron/tests/unit/bigswitch/etc/ssl/combined/README delete mode 100644 neutron/tests/unit/bigswitch/etc/ssl/host_certs/README delete mode 100644 neutron/tests/unit/bigswitch/fake_server.py delete mode 100644 neutron/tests/unit/bigswitch/test_agent_scheduler.py delete mode 100644 neutron/tests/unit/bigswitch/test_base.py delete mode 100644 neutron/tests/unit/bigswitch/test_capabilities.py delete mode 100644 neutron/tests/unit/bigswitch/test_restproxy_agent.py delete mode 100644 neutron/tests/unit/bigswitch/test_restproxy_plugin.py delete mode 100644 neutron/tests/unit/bigswitch/test_router_db.py delete mode 100644 neutron/tests/unit/bigswitch/test_security_groups.py delete mode 100644 neutron/tests/unit/bigswitch/test_servermanager.py delete mode 100644 neutron/tests/unit/bigswitch/test_ssl.py delete mode 100644 neutron/tests/unit/brocade/__init__.py delete mode 100644 neutron/tests/unit/brocade/test_brocade_db.py delete mode 100644 neutron/tests/unit/brocade/test_brocade_plugin.py delete mode 100644 neutron/tests/unit/brocade/test_brocade_vlan.py delete mode 100644 neutron/tests/unit/cisco/__init__.py delete mode 100644 neutron/tests/unit/cisco/n1kv/__init__.py delete mode 100755 neutron/tests/unit/cisco/n1kv/fake_client.py delete mode 100644 neutron/tests/unit/cisco/n1kv/test_n1kv_db.py delete mode 100644 neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py delete mode 100644 neutron/tests/unit/cisco/test_config.py delete mode 100644 neutron/tests/unit/cisco/test_network_db.py delete mode 100644 neutron/tests/unit/cisco/test_network_plugin.py delete mode 100644 neutron/tests/unit/cisco/test_nexus_db.py delete mode 100644 neutron/tests/unit/cisco/test_nexus_plugin.py delete mode 100755 neutron/tests/unit/cisco/test_plugin_model.py delete mode 100644 neutron/tests/unit/db/firewall/__init__.py delete mode 100644 neutron/tests/unit/db/firewall/test_db_firewall.py delete mode 100644 neutron/tests/unit/db/loadbalancer/__init__.py delete mode 100644 neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py delete mode 100644 neutron/tests/unit/db/metering/__init__.py delete mode 100644 neutron/tests/unit/db/metering/test_db_metering.py delete mode 100644 neutron/tests/unit/db/test_agent_db.py delete mode 100644 neutron/tests/unit/db/test_quota_db.py delete mode 100644 neutron/tests/unit/db/vpn/__init__.py delete mode 100644 neutron/tests/unit/db/vpn/test_db_vpnaas.py delete mode 100644 neutron/tests/unit/dummy_plugin.py delete mode 100644 neutron/tests/unit/embrane/__init__.py delete mode 100644 neutron/tests/unit/embrane/test_embrane_defaults.py delete mode 100644 neutron/tests/unit/embrane/test_embrane_l3_plugin.py delete mode 100644 neutron/tests/unit/embrane/test_embrane_neutron_plugin.py delete mode 100644 neutron/tests/unit/hyperv/__init__.py delete mode 100644 neutron/tests/unit/hyperv/test_hyperv_neutron_agent.py delete mode 100644 neutron/tests/unit/hyperv/test_hyperv_neutron_plugin.py delete mode 100644 neutron/tests/unit/hyperv/test_hyperv_rpcapi.py delete mode 100644 neutron/tests/unit/hyperv/test_hyperv_security_groups_driver.py delete mode 100644 neutron/tests/unit/hyperv/test_hyperv_utilsfactory.py delete mode 100644 neutron/tests/unit/hyperv/test_hyperv_utilsv2.py delete mode 100644 neutron/tests/unit/ibm/__init__.py delete mode 100644 neutron/tests/unit/ibm/test_sdnve_agent.py delete mode 100644 neutron/tests/unit/ibm/test_sdnve_api.py delete mode 100644 neutron/tests/unit/ibm/test_sdnve_plugin.py delete mode 100644 neutron/tests/unit/linuxbridge/__init__.py delete mode 100644 neutron/tests/unit/linuxbridge/test_agent_scheduler.py delete mode 100644 neutron/tests/unit/linuxbridge/test_defaults.py delete mode 100644 neutron/tests/unit/linuxbridge/test_lb_db.py delete mode 100644 neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py delete mode 100644 neutron/tests/unit/linuxbridge/test_lb_security_group.py delete mode 100644 neutron/tests/unit/linuxbridge/test_linuxbridge_plugin.py delete mode 100644 neutron/tests/unit/linuxbridge/test_rpcapi.py delete mode 100644 neutron/tests/unit/metaplugin/__init__.py delete mode 100644 neutron/tests/unit/metaplugin/fake_plugin.py delete mode 100644 neutron/tests/unit/metaplugin/test_basic.py delete mode 100644 neutron/tests/unit/metaplugin/test_metaplugin.py delete mode 100644 neutron/tests/unit/midonet/__init__.py delete mode 100644 neutron/tests/unit/midonet/etc/midonet.ini.test delete mode 100644 neutron/tests/unit/midonet/mock_lib.py delete mode 100644 neutron/tests/unit/midonet/test_midonet_driver.py delete mode 100644 neutron/tests/unit/midonet/test_midonet_lib.py delete mode 100644 neutron/tests/unit/midonet/test_midonet_plugin.py delete mode 100644 neutron/tests/unit/ml2/__init__.py delete mode 100644 neutron/tests/unit/ml2/_test_mech_agent.py delete mode 100644 neutron/tests/unit/ml2/drivers/__init__.py delete mode 100644 neutron/tests/unit/ml2/drivers/brocade/__init__.py delete mode 100644 neutron/tests/unit/ml2/drivers/brocade/test_brocade_mechanism_driver.py delete mode 100644 neutron/tests/unit/ml2/drivers/cisco/__init__.py delete mode 100644 neutron/tests/unit/ml2/drivers/cisco/apic/__init__.py delete mode 100644 neutron/tests/unit/ml2/drivers/cisco/apic/test_cisco_apic_client.py delete mode 100644 neutron/tests/unit/ml2/drivers/cisco/apic/test_cisco_apic_common.py delete mode 100644 neutron/tests/unit/ml2/drivers/cisco/apic/test_cisco_apic_manager.py delete mode 100644 neutron/tests/unit/ml2/drivers/cisco/apic/test_cisco_apic_mechanism_driver.py delete mode 100644 neutron/tests/unit/ml2/drivers/cisco/nexus/__init__.py delete mode 100644 neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_config.py delete mode 100644 neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_mech.py delete mode 100644 neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_nexus.py delete mode 100644 neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_nexus_db.py delete mode 100644 neutron/tests/unit/ml2/drivers/mechanism_bulkless.py delete mode 100644 neutron/tests/unit/ml2/drivers/mechanism_logger.py delete mode 100644 neutron/tests/unit/ml2/drivers/mechanism_test.py delete mode 100644 neutron/tests/unit/ml2/drivers/test_arista_mechanism_driver.py delete mode 100644 neutron/tests/unit/ml2/drivers/test_bigswitch_mech.py delete mode 100644 neutron/tests/unit/ml2/drivers/test_l2population.py delete mode 100644 neutron/tests/unit/ml2/drivers/test_mech_mlnx.py delete mode 100644 neutron/tests/unit/ml2/drivers/test_ofagent_mech.py delete mode 100644 neutron/tests/unit/ml2/test_agent_scheduler.py delete mode 100644 neutron/tests/unit/ml2/test_mech_hyperv.py delete mode 100644 neutron/tests/unit/ml2/test_mech_linuxbridge.py delete mode 100644 neutron/tests/unit/ml2/test_mech_openvswitch.py delete mode 100644 neutron/tests/unit/ml2/test_mechanism_fslsdn.py delete mode 100644 neutron/tests/unit/ml2/test_mechanism_ncs.py delete mode 100644 neutron/tests/unit/ml2/test_mechanism_odl.py delete mode 100644 neutron/tests/unit/ml2/test_ml2_plugin.py delete mode 100644 neutron/tests/unit/ml2/test_port_binding.py delete mode 100644 neutron/tests/unit/ml2/test_rpcapi.py delete mode 100644 neutron/tests/unit/ml2/test_security_group.py delete mode 100644 neutron/tests/unit/ml2/test_type_flat.py delete mode 100644 neutron/tests/unit/ml2/test_type_gre.py delete mode 100644 neutron/tests/unit/ml2/test_type_local.py delete mode 100644 neutron/tests/unit/ml2/test_type_vlan.py delete mode 100644 neutron/tests/unit/ml2/test_type_vxlan.py delete mode 100644 neutron/tests/unit/mlnx/__init__.py delete mode 100644 neutron/tests/unit/mlnx/test_agent_scheduler.py delete mode 100644 neutron/tests/unit/mlnx/test_defaults.py delete mode 100644 neutron/tests/unit/mlnx/test_mlnx_comm_utils.py delete mode 100644 neutron/tests/unit/mlnx/test_mlnx_db.py delete mode 100644 neutron/tests/unit/mlnx/test_mlnx_neutron_agent.py delete mode 100644 neutron/tests/unit/mlnx/test_mlnx_plugin.py delete mode 100644 neutron/tests/unit/mlnx/test_mlnx_plugin_config.py delete mode 100644 neutron/tests/unit/mlnx/test_mlnx_security_group.py delete mode 100644 neutron/tests/unit/mlnx/test_rpcapi.py delete mode 100644 neutron/tests/unit/nec/__init__.py delete mode 100644 neutron/tests/unit/nec/fake_ofc_manager.py delete mode 100644 neutron/tests/unit/nec/stub_ofc_driver.py delete mode 100644 neutron/tests/unit/nec/test_agent_scheduler.py delete mode 100644 neutron/tests/unit/nec/test_config.py delete mode 100644 neutron/tests/unit/nec/test_db.py delete mode 100644 neutron/tests/unit/nec/test_nec_agent.py delete mode 100644 neutron/tests/unit/nec/test_nec_plugin.py delete mode 100644 neutron/tests/unit/nec/test_ofc_client.py delete mode 100644 neutron/tests/unit/nec/test_ofc_manager.py delete mode 100644 neutron/tests/unit/nec/test_packet_filter.py delete mode 100644 neutron/tests/unit/nec/test_pfc_driver.py delete mode 100644 neutron/tests/unit/nec/test_portbindings.py delete mode 100644 neutron/tests/unit/nec/test_router.py delete mode 100644 neutron/tests/unit/nec/test_security_group.py delete mode 100644 neutron/tests/unit/nec/test_trema_driver.py delete mode 100644 neutron/tests/unit/nec/test_utils.py delete mode 100644 neutron/tests/unit/notifiers/__init__.py delete mode 100644 neutron/tests/unit/notifiers/test_notifiers_nova.py delete mode 100644 neutron/tests/unit/nuage/__init__.py delete mode 100644 neutron/tests/unit/nuage/fake_nuageclient.py delete mode 100644 neutron/tests/unit/nuage/test_netpartition.py delete mode 100644 neutron/tests/unit/nuage/test_nuage_plugin.py delete mode 100644 neutron/tests/unit/ofagent/__init__.py delete mode 100644 neutron/tests/unit/ofagent/fake_oflib.py delete mode 100644 neutron/tests/unit/ofagent/test_ofa_defaults.py delete mode 100644 neutron/tests/unit/ofagent/test_ofa_neutron_agent.py delete mode 100644 neutron/tests/unit/oneconvergence/__init__.py delete mode 100644 neutron/tests/unit/oneconvergence/test_nvsd_agent.py delete mode 100644 neutron/tests/unit/oneconvergence/test_nvsd_plugin.py delete mode 100644 neutron/tests/unit/oneconvergence/test_nvsdlib.py delete mode 100644 neutron/tests/unit/oneconvergence/test_plugin_helper.py delete mode 100644 neutron/tests/unit/oneconvergence/test_security_group.py delete mode 100644 neutron/tests/unit/openvswitch/__init__.py delete mode 100644 neutron/tests/unit/openvswitch/test_agent_scheduler.py delete mode 100644 neutron/tests/unit/openvswitch/test_openvswitch_plugin.py delete mode 100644 neutron/tests/unit/openvswitch/test_ovs_db.py delete mode 100644 neutron/tests/unit/openvswitch/test_ovs_defaults.py delete mode 100644 neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py delete mode 100644 neutron/tests/unit/openvswitch/test_ovs_rpcapi.py delete mode 100644 neutron/tests/unit/openvswitch/test_ovs_security_group.py delete mode 100644 neutron/tests/unit/openvswitch/test_ovs_tunnel.py delete mode 100644 neutron/tests/unit/plumgrid/__init__.py delete mode 100644 neutron/tests/unit/plumgrid/test_plumgrid_plugin.py delete mode 100644 neutron/tests/unit/ryu/__init__.py delete mode 100644 neutron/tests/unit/ryu/fake_ryu.py delete mode 100644 neutron/tests/unit/ryu/test_defaults.py delete mode 100644 neutron/tests/unit/ryu/test_ryu_agent.py delete mode 100644 neutron/tests/unit/ryu/test_ryu_db.py delete mode 100644 neutron/tests/unit/ryu/test_ryu_plugin.py delete mode 100644 neutron/tests/unit/ryu/test_ryu_security_group.py delete mode 100644 neutron/tests/unit/services/firewall/__init__.py delete mode 100644 neutron/tests/unit/services/firewall/agents/__init__.py delete mode 100644 neutron/tests/unit/services/firewall/agents/l3reference/__init__.py delete mode 100644 neutron/tests/unit/services/firewall/agents/l3reference/test_firewall_l3_agent.py delete mode 100644 neutron/tests/unit/services/firewall/agents/test_firewall_agent_api.py delete mode 100755 neutron/tests/unit/services/firewall/agents/varmour/__init__.py delete mode 100644 neutron/tests/unit/services/firewall/agents/varmour/test_varmour_router.py delete mode 100644 neutron/tests/unit/services/firewall/drivers/__init__.py delete mode 100644 neutron/tests/unit/services/firewall/drivers/linux/__init__.py delete mode 100644 neutron/tests/unit/services/firewall/drivers/linux/test_iptables_fwaas.py delete mode 100755 neutron/tests/unit/services/firewall/drivers/varmour/__init__.py delete mode 100644 neutron/tests/unit/services/firewall/drivers/varmour/test_varmour_fwaas.py delete mode 100644 neutron/tests/unit/services/firewall/test_fwaas_plugin.py delete mode 100644 neutron/tests/unit/services/l3_router/__init__.py delete mode 100644 neutron/tests/unit/services/l3_router/test_l3_apic_plugin.py delete mode 100644 neutron/tests/unit/services/loadbalancer/__init__.py delete mode 100644 neutron/tests/unit/services/loadbalancer/agent/__init__.py delete mode 100644 neutron/tests/unit/services/loadbalancer/agent/test_agent.py delete mode 100644 neutron/tests/unit/services/loadbalancer/agent/test_agent_manager.py delete mode 100644 neutron/tests/unit/services/loadbalancer/agent/test_api.py delete mode 100644 neutron/tests/unit/services/loadbalancer/drivers/__init__.py delete mode 100644 neutron/tests/unit/services/loadbalancer/drivers/embrane/__init__.py delete mode 100644 neutron/tests/unit/services/loadbalancer/drivers/embrane/test_embrane_defaults.py delete mode 100644 neutron/tests/unit/services/loadbalancer/drivers/embrane/test_plugin_driver.py delete mode 100644 neutron/tests/unit/services/loadbalancer/drivers/haproxy/__init__.py delete mode 100644 neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_cfg.py delete mode 100644 neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_namespace_driver.py delete mode 100644 neutron/tests/unit/services/loadbalancer/drivers/netscaler/__init__.py delete mode 100644 neutron/tests/unit/services/loadbalancer/drivers/netscaler/test_ncc_client.py delete mode 100644 neutron/tests/unit/services/loadbalancer/drivers/netscaler/test_netscaler_driver.py delete mode 100644 neutron/tests/unit/services/loadbalancer/drivers/radware/__init__.py delete mode 100644 neutron/tests/unit/services/loadbalancer/drivers/radware/test_plugin_driver.py delete mode 100644 neutron/tests/unit/services/loadbalancer/drivers/test_agent_driver_base.py delete mode 100644 neutron/tests/unit/services/loadbalancer/test_agent_scheduler.py delete mode 100644 neutron/tests/unit/services/loadbalancer/test_loadbalancer_plugin.py delete mode 100644 neutron/tests/unit/services/loadbalancer/test_loadbalancer_quota_ext.py delete mode 100644 neutron/tests/unit/services/metering/__init__.py delete mode 100644 neutron/tests/unit/services/metering/drivers/__init__.py delete mode 100644 neutron/tests/unit/services/metering/drivers/test_iptables_driver.py delete mode 100644 neutron/tests/unit/services/metering/test_metering_agent.py delete mode 100644 neutron/tests/unit/services/metering/test_metering_plugin.py delete mode 100644 neutron/tests/unit/services/vpn/__init__.py delete mode 100644 neutron/tests/unit/services/vpn/device_drivers/__init__.py delete mode 100644 neutron/tests/unit/services/vpn/device_drivers/cisco_csr_mock.py delete mode 100644 neutron/tests/unit/services/vpn/device_drivers/notest_cisco_csr_rest.py delete mode 100644 neutron/tests/unit/services/vpn/device_drivers/test_cisco_ipsec.py delete mode 100644 neutron/tests/unit/services/vpn/device_drivers/test_ipsec.py delete mode 100644 neutron/tests/unit/services/vpn/service_drivers/__init__.py delete mode 100644 neutron/tests/unit/services/vpn/service_drivers/test_cisco_ipsec.py delete mode 100644 neutron/tests/unit/services/vpn/service_drivers/test_ipsec.py delete mode 100644 neutron/tests/unit/services/vpn/test_vpn_agent.py delete mode 100644 neutron/tests/unit/services/vpn/test_vpnaas_driver_plugin.py delete mode 100644 neutron/tests/unit/services/vpn/test_vpnaas_extension.py delete mode 100644 neutron/tests/unit/test_agent_config.py delete mode 100644 neutron/tests/unit/test_agent_ext_plugin.py delete mode 100644 neutron/tests/unit/test_agent_linux_utils.py delete mode 100644 neutron/tests/unit/test_agent_netns_cleanup.py delete mode 100644 neutron/tests/unit/test_agent_ovs_cleanup.py delete mode 100644 neutron/tests/unit/test_db_plugin.py delete mode 100644 neutron/tests/unit/test_db_rpc_base.py delete mode 100644 neutron/tests/unit/test_debug_commands.py delete mode 100644 neutron/tests/unit/test_dhcp_agent.py delete mode 100644 neutron/tests/unit/test_dhcp_scheduler.py delete mode 100644 neutron/tests/unit/test_extension_allowedaddresspairs.py delete mode 100644 neutron/tests/unit/test_extension_ext_gw_mode.py delete mode 100644 neutron/tests/unit/test_extension_ext_net.py delete mode 100644 neutron/tests/unit/test_extension_extradhcpopts.py delete mode 100644 neutron/tests/unit/test_extension_extraroute.py delete mode 100644 neutron/tests/unit/test_extension_firewall.py delete mode 100644 neutron/tests/unit/test_extension_pnet.py delete mode 100644 neutron/tests/unit/test_extension_portsecurity.py delete mode 100644 neutron/tests/unit/test_extension_security_group.py delete mode 100644 neutron/tests/unit/test_iptables_firewall.py delete mode 100644 neutron/tests/unit/test_iptables_manager.py delete mode 100644 neutron/tests/unit/test_ipv6.py delete mode 100644 neutron/tests/unit/test_l3_agent.py delete mode 100644 neutron/tests/unit/test_l3_plugin.py delete mode 100644 neutron/tests/unit/test_l3_schedulers.py delete mode 100644 neutron/tests/unit/test_linux_daemon.py delete mode 100644 neutron/tests/unit/test_linux_dhcp.py delete mode 100644 neutron/tests/unit/test_linux_external_process.py delete mode 100644 neutron/tests/unit/test_linux_interface.py delete mode 100644 neutron/tests/unit/test_linux_ip_lib.py delete mode 100644 neutron/tests/unit/test_metadata_agent.py delete mode 100644 neutron/tests/unit/test_metadata_namespace_proxy.py delete mode 100644 neutron/tests/unit/test_neutron_manager.py delete mode 100644 neutron/tests/unit/test_provider_configuration.py delete mode 100644 neutron/tests/unit/test_quota_ext.py delete mode 100644 neutron/tests/unit/test_routerserviceinsertion.py delete mode 100644 neutron/tests/unit/test_security_groups_rpc.py delete mode 100644 neutron/tests/unit/test_servicetype.py delete mode 100644 neutron/tests/unit/vmware/__init__.py delete mode 100644 neutron/tests/unit/vmware/apiclient/__init__.py delete mode 100644 neutron/tests/unit/vmware/apiclient/fake.py delete mode 100644 neutron/tests/unit/vmware/apiclient/test_api_common.py delete mode 100644 neutron/tests/unit/vmware/apiclient/test_api_eventlet_request.py delete mode 100644 neutron/tests/unit/vmware/db/__init__.py delete mode 100644 neutron/tests/unit/vmware/db/test_lsn_db.py delete mode 100644 neutron/tests/unit/vmware/db/test_nsx_db.py delete mode 100644 neutron/tests/unit/vmware/etc/fake_get_gwservice.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_get_lqueue.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_get_lrouter.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_get_lrouter_lport.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_get_lrouter_lport_att.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_get_lrouter_nat.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_get_lswitch.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_get_lswitch_lport.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_get_lswitch_lport_att.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_get_lswitch_lport_status.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_get_security_profile.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_post_gwservice.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_post_lqueue.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_post_lrouter.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_post_lrouter_lport.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_post_lrouter_nat.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_post_lswitch.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_post_lswitch_lport.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_post_security_profile.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_put_lrouter_lport_att.json delete mode 100644 neutron/tests/unit/vmware/etc/fake_put_lswitch_lport_att.json delete mode 100644 neutron/tests/unit/vmware/etc/neutron.conf.test delete mode 100644 neutron/tests/unit/vmware/etc/nsx.ini.agentless.test delete mode 100644 neutron/tests/unit/vmware/etc/nsx.ini.basic.test delete mode 100644 neutron/tests/unit/vmware/etc/nsx.ini.combined.test delete mode 100644 neutron/tests/unit/vmware/etc/nsx.ini.full.test delete mode 100644 neutron/tests/unit/vmware/etc/nsx.ini.test delete mode 100644 neutron/tests/unit/vmware/etc/nvp.ini.full.test delete mode 100644 neutron/tests/unit/vmware/etc/vcns.ini.test delete mode 100644 neutron/tests/unit/vmware/extensions/__init__.py delete mode 100644 neutron/tests/unit/vmware/extensions/test_addresspairs.py delete mode 100644 neutron/tests/unit/vmware/extensions/test_maclearning.py delete mode 100644 neutron/tests/unit/vmware/extensions/test_networkgw.py delete mode 100644 neutron/tests/unit/vmware/extensions/test_portsecurity.py delete mode 100644 neutron/tests/unit/vmware/extensions/test_providernet.py delete mode 100644 neutron/tests/unit/vmware/extensions/test_qosqueues.py delete mode 100644 neutron/tests/unit/vmware/nsxlib/__init__.py delete mode 100644 neutron/tests/unit/vmware/nsxlib/base.py delete mode 100644 neutron/tests/unit/vmware/nsxlib/test_l2gateway.py delete mode 100644 neutron/tests/unit/vmware/nsxlib/test_lsn.py delete mode 100644 neutron/tests/unit/vmware/nsxlib/test_queue.py delete mode 100644 neutron/tests/unit/vmware/nsxlib/test_router.py delete mode 100644 neutron/tests/unit/vmware/nsxlib/test_secgroup.py delete mode 100644 neutron/tests/unit/vmware/nsxlib/test_switch.py delete mode 100644 neutron/tests/unit/vmware/nsxlib/test_versioning.py delete mode 100644 neutron/tests/unit/vmware/test_agent_scheduler.py delete mode 100644 neutron/tests/unit/vmware/test_dhcpmeta.py delete mode 100644 neutron/tests/unit/vmware/test_nsx_opts.py delete mode 100644 neutron/tests/unit/vmware/test_nsx_plugin.py delete mode 100644 neutron/tests/unit/vmware/test_nsx_sync.py delete mode 100644 neutron/tests/unit/vmware/test_nsx_utils.py delete mode 100644 neutron/tests/unit/vmware/vshield/__init__.py delete mode 100644 neutron/tests/unit/vmware/vshield/fake_vcns.py delete mode 100644 neutron/tests/unit/vmware/vshield/test_edge_router.py delete mode 100644 neutron/tests/unit/vmware/vshield/test_firewall_driver.py delete mode 100644 neutron/tests/unit/vmware/vshield/test_fwaas_plugin.py delete mode 100644 neutron/tests/unit/vmware/vshield/test_lbaas_plugin.py delete mode 100644 neutron/tests/unit/vmware/vshield/test_loadbalancer_driver.py delete mode 100644 neutron/tests/unit/vmware/vshield/test_vcns_driver.py delete mode 100644 neutron/tests/unit/vmware/vshield/test_vpnaas_plugin.py diff --git a/neutron/tests/functional/agent/linux/base.py b/neutron/tests/functional/agent/linux/base.py deleted file mode 100644 index c5ea717f7..000000000 --- a/neutron/tests/functional/agent/linux/base.py +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright 2014 Cisco Systems, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import os -import random - -from neutron.agent.linux import ovs_lib -from neutron.agent.linux import utils -from neutron.plugins.common import constants as q_const -from neutron.tests import base - - -BR_PREFIX = 'test-br' - - -class BaseLinuxTestCase(base.BaseTestCase): - def setUp(self, root_helper='sudo'): - super(BaseLinuxTestCase, self).setUp() - - self.root_helper = root_helper - - def check_command(self, cmd, error_text, skip_msg): - try: - utils.execute(cmd) - except RuntimeError as e: - if error_text in str(e): - self.skipTest(skip_msg) - raise - - def check_sudo_enabled(self): - if os.environ.get('OS_SUDO_TESTING') not in base.TRUE_STRING: - self.skipTest('testing with sudo is not enabled') - - def get_rand_name(self, max_length, prefix='test'): - name = prefix + str(random.randint(1, 0x7fffffff)) - return name[:max_length] - - def create_resource(self, name_prefix, creation_func, *args, **kwargs): - """Create a new resource that does not already exist. - - :param name_prefix: The prefix for a randomly generated name - :param creation_func: A function taking the name of the resource - to be created as it's first argument. An error is assumed - to indicate a name collision. - :param *args *kwargs: These will be passed to the create function. - """ - while True: - name = self.get_rand_name(q_const.MAX_DEV_NAME_LEN, name_prefix) - try: - return creation_func(name, *args, **kwargs) - except RuntimeError: - continue - - -class BaseOVSLinuxTestCase(BaseLinuxTestCase): - def setUp(self, root_helper='sudo'): - super(BaseOVSLinuxTestCase, self).setUp(root_helper) - self.ovs = ovs_lib.BaseOVS(self.root_helper) - - def create_ovs_bridge(self, br_prefix=BR_PREFIX): - br = self.create_resource(br_prefix, self.ovs.add_bridge) - self.addCleanup(br.destroy) - return br diff --git a/neutron/tests/functional/agent/linux/test_async_process.py b/neutron/tests/functional/agent/linux/test_async_process.py deleted file mode 100644 index dd2ebb889..000000000 --- a/neutron/tests/functional/agent/linux/test_async_process.py +++ /dev/null @@ -1,71 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import eventlet -import fixtures - -from six import moves - -from neutron.agent.linux import async_process -from neutron.tests import base - - -class TestAsyncProcess(base.BaseTestCase): - - def setUp(self): - super(TestAsyncProcess, self).setUp() - self.test_file_path = self.useFixture( - fixtures.TempDir()).join("test_async_process.tmp") - self.data = [str(x) for x in moves.xrange(4)] - with file(self.test_file_path, 'w') as f: - f.writelines('%s\n' % item for item in self.data) - - def _check_stdout(self, proc): - # Ensure that all the output from the file is read - output = [] - while output != self.data: - new_output = list(proc.iter_stdout()) - if new_output: - output += new_output - eventlet.sleep(0.01) - - def test_stopping_async_process_lifecycle(self): - with self.assert_max_execution_time(): - proc = async_process.AsyncProcess(['tail', '-f', - self.test_file_path]) - proc.start() - self._check_stdout(proc) - proc.stop() - - # Ensure that the process and greenthreads have stopped - proc._process.wait() - self.assertEqual(proc._process.returncode, -9) - for watcher in proc._watchers: - watcher.wait() - - def test_async_process_respawns(self): - with self.assert_max_execution_time(): - proc = async_process.AsyncProcess(['tail', '-f', - self.test_file_path], - respawn_interval=0) - proc.start() - - # Ensure that the same output is read twice - self._check_stdout(proc) - pid = proc._get_pid_to_kill() - proc._kill_process(pid) - self._check_stdout(proc) - proc.stop() diff --git a/neutron/tests/functional/agent/linux/test_ovsdb_monitor.py b/neutron/tests/functional/agent/linux/test_ovsdb_monitor.py deleted file mode 100644 index 3ef5f9411..000000000 --- a/neutron/tests/functional/agent/linux/test_ovsdb_monitor.py +++ /dev/null @@ -1,108 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -Tests in this module will be skipped unless: - - - ovsdb-client is installed - - - ovsdb-client can be invoked via password-less sudo - - - OS_SUDO_TESTING is set to '1' or 'True' in the test execution - environment - - -The jenkins gate does not allow direct sudo invocation during test -runs, but configuring OS_SUDO_TESTING ensures that developers are -still able to execute tests that require the capability. -""" - -import eventlet - -from neutron.agent.linux import ovsdb_monitor -from neutron.tests.functional.agent.linux import base as base_agent - - -class BaseMonitorTest(base_agent.BaseOVSLinuxTestCase): - - def setUp(self): - # Emulate using a rootwrap script with sudo - super(BaseMonitorTest, self).setUp(root_helper='sudo sudo') - - self._check_test_requirements() - self.bridge = self.create_ovs_bridge() - - def _check_test_requirements(self): - self.check_sudo_enabled() - self.check_command(['which', 'ovsdb-client'], - 'Exit code: 1', 'ovsdb-client is not installed') - self.check_command(['sudo', '-n', 'ovsdb-client', 'list-dbs'], - 'Exit code: 1', - 'password-less sudo not granted for ovsdb-client') - - -class TestOvsdbMonitor(BaseMonitorTest): - - def setUp(self): - super(TestOvsdbMonitor, self).setUp() - - self.monitor = ovsdb_monitor.OvsdbMonitor('Bridge', - root_helper=self.root_helper) - self.addCleanup(self.monitor.stop) - self.monitor.start() - - def collect_initial_output(self): - while True: - output = list(self.monitor.iter_stdout()) - if output: - return output[0] - eventlet.sleep(0.01) - - def test_killed_monitor_respawns(self): - with self.assert_max_execution_time(): - self.monitor.respawn_interval = 0 - old_pid = self.monitor._process.pid - output1 = self.collect_initial_output() - pid = self.monitor._get_pid_to_kill() - self.monitor._kill_process(pid) - self.monitor._reset_queues() - while (self.monitor._process.pid == old_pid): - eventlet.sleep(0.01) - output2 = self.collect_initial_output() - # Initial output should appear twice - self.assertEqual(output1, output2) - - -class TestSimpleInterfaceMonitor(BaseMonitorTest): - - def setUp(self): - super(TestSimpleInterfaceMonitor, self).setUp() - - self.monitor = ovsdb_monitor.SimpleInterfaceMonitor( - root_helper=self.root_helper) - self.addCleanup(self.monitor.stop) - self.monitor.start(block=True) - - def test_has_updates(self): - self.assertTrue(self.monitor.has_updates, - 'Initial call should always be true') - self.assertFalse(self.monitor.has_updates, - 'has_updates without port addition should be False') - self.create_resource('test-port-', self.bridge.add_port) - with self.assert_max_execution_time(): - # has_updates after port addition should become True - while not self.monitor.has_updates: - eventlet.sleep(0.01) diff --git a/neutron/tests/functional/sanity/__init__.py b/neutron/tests/functional/sanity/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/neutron/tests/functional/sanity/test_ovs_sanity.py b/neutron/tests/functional/sanity/test_ovs_sanity.py deleted file mode 100644 index fa63300fe..000000000 --- a/neutron/tests/functional/sanity/test_ovs_sanity.py +++ /dev/null @@ -1,46 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright (c) 2014 OpenStack Foundation. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import os - -from neutron.cmd.sanity import checks -from neutron.tests import base - - -class OVSSanityTestCase(base.BaseTestCase): - def setUp(self): - super(OVSSanityTestCase, self).setUp() - - self.root_helper = 'sudo' - - def check_sudo_enabled(self): - if os.environ.get('OS_SUDO_TESTING') not in base.TRUE_STRING: - self.skipTest('testing with sudo is not enabled') - - def test_ovs_vxlan_support_runs(self): - """This test just ensures that the test in neutron-sanity-check - can run through without error, without mocking anything out - """ - self.check_sudo_enabled() - checks.vxlan_supported(self.root_helper) - - def test_ovs_patch_support_runs(self): - """This test just ensures that the test in neutron-sanity-check - can run through without error, without mocking anything out - """ - self.check_sudo_enabled() - checks.patch_supported(self.root_helper) diff --git a/neutron/tests/unit/_test_extension_portbindings.py b/neutron/tests/unit/_test_extension_portbindings.py deleted file mode 100644 index 3a78b8d8f..000000000 --- a/neutron/tests/unit/_test_extension_portbindings.py +++ /dev/null @@ -1,377 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 NEC Corporation -# All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Akihiro Motoki, NEC Corporation -# - -import contextlib -import httplib - -from oslo.config import cfg -from webob import exc - -from neutron import context -from neutron.extensions import portbindings -from neutron import manager -from neutron.tests.unit import test_db_plugin - - -class PortBindingsTestCase(test_db_plugin.NeutronDbPluginV2TestCase): - - # VIF_TYPE must be overridden according to plugin vif_type - VIF_TYPE = portbindings.VIF_TYPE_OTHER - # The plugin supports the port security feature such as - # security groups and anti spoofing. - HAS_PORT_FILTER = False - - def _check_response_portbindings(self, port): - self.assertEqual(port[portbindings.VIF_TYPE], self.VIF_TYPE) - vif_details = port[portbindings.VIF_DETAILS] - # REVISIT(rkukura): Consider reworking tests to enable ML2 to bind - if self.VIF_TYPE not in [portbindings.VIF_TYPE_UNBOUND, - portbindings.VIF_TYPE_BINDING_FAILED]: - # TODO(rkukura): Replace with new VIF security details - self.assertEqual(vif_details[portbindings.CAP_PORT_FILTER], - self.HAS_PORT_FILTER) - - def _check_response_no_portbindings(self, port): - self.assertIn('status', port) - self.assertNotIn(portbindings.VIF_TYPE, port) - self.assertNotIn(portbindings.VIF_DETAILS, port) - - def _get_non_admin_context(self): - return context.Context(user_id=None, - tenant_id=self._tenant_id, - is_admin=False, - read_deleted="no") - - def test_port_vif_details(self): - with self.port(name='name') as port: - port_id = port['port']['id'] - # Check a response of create_port - self._check_response_portbindings(port['port']) - # Check a response of get_port - ctx = context.get_admin_context() - port = self._show('ports', port_id, neutron_context=ctx)['port'] - self._check_response_portbindings(port) - # By default user is admin - now test non admin user - ctx = self._get_non_admin_context() - non_admin_port = self._show( - 'ports', port_id, neutron_context=ctx)['port'] - self._check_response_no_portbindings(non_admin_port) - - def test_ports_vif_details(self): - plugin = manager.NeutronManager.get_plugin() - cfg.CONF.set_default('allow_overlapping_ips', True) - with contextlib.nested(self.port(), self.port()): - ctx = context.get_admin_context() - ports = plugin.get_ports(ctx) - self.assertEqual(len(ports), 2) - for port in ports: - self._check_response_portbindings(port) - # By default user is admin - now test non admin user - ctx = self._get_non_admin_context() - ports = self._list('ports', neutron_context=ctx)['ports'] - self.assertEqual(len(ports), 2) - for non_admin_port in ports: - self._check_response_no_portbindings(non_admin_port) - - def _check_port_binding_profile(self, port, profile=None): - # For plugins which does not use binding:profile attr - # we just check an operation for the port succeed. - self.assertIn('id', port) - - def _test_create_port_binding_profile(self, profile): - profile_arg = {portbindings.PROFILE: profile} - with self.port(arg_list=(portbindings.PROFILE,), - **profile_arg) as port: - port_id = port['port']['id'] - self._check_port_binding_profile(port['port'], profile) - port = self._show('ports', port_id) - self._check_port_binding_profile(port['port'], profile) - - def test_create_port_binding_profile_none(self): - self._test_create_port_binding_profile(None) - - def test_create_port_binding_profile_with_empty_dict(self): - self._test_create_port_binding_profile({}) - - def _test_update_port_binding_profile(self, profile): - profile_arg = {portbindings.PROFILE: profile} - with self.port() as port: - # print "(1) %s" % port - self._check_port_binding_profile(port['port']) - port_id = port['port']['id'] - ctx = context.get_admin_context() - port = self._update('ports', port_id, {'port': profile_arg}, - neutron_context=ctx)['port'] - self._check_port_binding_profile(port, profile) - port = self._show('ports', port_id)['port'] - self._check_port_binding_profile(port, profile) - - def test_update_port_binding_profile_none(self): - self._test_update_port_binding_profile(None) - - def test_update_port_binding_profile_with_empty_dict(self): - self._test_update_port_binding_profile({}) - - def test_port_create_portinfo_non_admin(self): - profile_arg = {portbindings.PROFILE: {'dummy': 'dummy'}} - with self.network(set_context=True, tenant_id='test') as net1: - with self.subnet(network=net1) as subnet1: - # succeed without binding:profile - with self.port(subnet=subnet1, - set_context=True, tenant_id='test'): - pass - # fail with binding:profile - try: - with self.port(subnet=subnet1, - expected_res_status=403, - arg_list=(portbindings.PROFILE,), - set_context=True, tenant_id='test', - **profile_arg): - pass - except exc.HTTPClientError: - pass - - def test_port_update_portinfo_non_admin(self): - profile_arg = {portbindings.PROFILE: {'dummy': 'dummy'}} - with self.network() as net1: - with self.subnet(network=net1) as subnet1: - with self.port(subnet=subnet1) as port: - # By default user is admin - now test non admin user - # Note that 404 is returned when prohibit by policy. - # See comment for PolicyNotAuthorized except clause - # in update() in neutron.api.v2.base.Controller. - port_id = port['port']['id'] - ctx = self._get_non_admin_context() - port = self._update('ports', port_id, - {'port': profile_arg}, - expected_code=404, - neutron_context=ctx) - - -class PortBindingsHostTestCaseMixin(object): - fmt = 'json' - hostname = 'testhost' - - def _check_response_portbindings_host(self, port): - self.assertEqual(port[portbindings.HOST_ID], self.hostname) - - def _check_response_no_portbindings_host(self, port): - self.assertIn('status', port) - self.assertNotIn(portbindings.HOST_ID, port) - - def test_port_vif_non_admin(self): - with self.network(set_context=True, - tenant_id='test') as net1: - with self.subnet(network=net1) as subnet1: - host_arg = {portbindings.HOST_ID: self.hostname} - try: - with self.port(subnet=subnet1, - expected_res_status=403, - arg_list=(portbindings.HOST_ID,), - set_context=True, - tenant_id='test', - **host_arg): - pass - except exc.HTTPClientError: - pass - - def test_port_vif_host(self): - host_arg = {portbindings.HOST_ID: self.hostname} - with self.port(name='name', arg_list=(portbindings.HOST_ID,), - **host_arg) as port: - port_id = port['port']['id'] - # Check a response of create_port - self._check_response_portbindings_host(port['port']) - # Check a response of get_port - ctx = context.get_admin_context() - port = self._show('ports', port_id, neutron_context=ctx)['port'] - self._check_response_portbindings_host(port) - # By default user is admin - now test non admin user - ctx = context.Context(user_id=None, - tenant_id=self._tenant_id, - is_admin=False, - read_deleted="no") - non_admin_port = self._show( - 'ports', port_id, neutron_context=ctx)['port'] - self._check_response_no_portbindings_host(non_admin_port) - - def test_ports_vif_host(self): - cfg.CONF.set_default('allow_overlapping_ips', True) - host_arg = {portbindings.HOST_ID: self.hostname} - with contextlib.nested( - self.port(name='name1', - arg_list=(portbindings.HOST_ID,), - **host_arg), - self.port(name='name2')): - ctx = context.get_admin_context() - ports = self._list('ports', neutron_context=ctx)['ports'] - self.assertEqual(2, len(ports)) - for port in ports: - if port['name'] == 'name1': - self._check_response_portbindings_host(port) - else: - self.assertFalse(port[portbindings.HOST_ID]) - # By default user is admin - now test non admin user - ctx = context.Context(user_id=None, - tenant_id=self._tenant_id, - is_admin=False, - read_deleted="no") - ports = self._list('ports', neutron_context=ctx)['ports'] - self.assertEqual(2, len(ports)) - for non_admin_port in ports: - self._check_response_no_portbindings_host(non_admin_port) - - def test_ports_vif_host_update(self): - cfg.CONF.set_default('allow_overlapping_ips', True) - host_arg = {portbindings.HOST_ID: self.hostname} - with contextlib.nested( - self.port(name='name1', - arg_list=(portbindings.HOST_ID,), - **host_arg), - self.port(name='name2')) as (port1, port2): - data = {'port': {portbindings.HOST_ID: 'testhosttemp'}} - req = self.new_update_request('ports', data, port1['port']['id']) - req.get_response(self.api) - req = self.new_update_request('ports', data, port2['port']['id']) - ctx = context.get_admin_context() - req.get_response(self.api) - ports = self._list('ports', neutron_context=ctx)['ports'] - self.assertEqual(2, len(ports)) - for port in ports: - self.assertEqual('testhosttemp', port[portbindings.HOST_ID]) - - def test_ports_vif_non_host_update(self): - host_arg = {portbindings.HOST_ID: self.hostname} - with self.port(name='name', arg_list=(portbindings.HOST_ID,), - **host_arg) as port: - data = {'port': {'admin_state_up': False}} - req = self.new_update_request('ports', data, port['port']['id']) - res = self.deserialize(self.fmt, req.get_response(self.api)) - self.assertEqual(port['port'][portbindings.HOST_ID], - res['port'][portbindings.HOST_ID]) - - def test_ports_vif_non_host_update_when_host_null(self): - with self.port() as port: - data = {'port': {'admin_state_up': False}} - req = self.new_update_request('ports', data, port['port']['id']) - res = self.deserialize(self.fmt, req.get_response(self.api)) - self.assertEqual(port['port'][portbindings.HOST_ID], - res['port'][portbindings.HOST_ID]) - - def test_ports_vif_host_list(self): - cfg.CONF.set_default('allow_overlapping_ips', True) - host_arg = {portbindings.HOST_ID: self.hostname} - with contextlib.nested( - self.port(name='name1', - arg_list=(portbindings.HOST_ID,), - **host_arg), - self.port(name='name2'), - self.port(name='name3', - arg_list=(portbindings.HOST_ID,), - **host_arg),) as (port1, _port2, port3): - self._test_list_resources( - 'port', (port1, port3), - query_params='%s=%s' % (portbindings.HOST_ID, self.hostname)) - - -class PortBindingsVnicTestCaseMixin(object): - fmt = 'json' - vnic_type = portbindings.VNIC_NORMAL - - def _check_response_portbindings_vnic_type(self, port): - self.assertIn('status', port) - self.assertEqual(port[portbindings.VNIC_TYPE], self.vnic_type) - - def test_port_vnic_type_non_admin(self): - with self.network(set_context=True, - tenant_id='test') as net1: - with self.subnet(network=net1) as subnet1: - vnic_arg = {portbindings.VNIC_TYPE: self.vnic_type} - with self.port(subnet=subnet1, - expected_res_status=httplib.CREATED, - arg_list=(portbindings.VNIC_TYPE,), - set_context=True, - tenant_id='test', - **vnic_arg) as port: - # Check a response of create_port - self._check_response_portbindings_vnic_type(port['port']) - - def test_port_vnic_type(self): - vnic_arg = {portbindings.VNIC_TYPE: self.vnic_type} - with self.port(name='name', arg_list=(portbindings.VNIC_TYPE,), - **vnic_arg) as port: - port_id = port['port']['id'] - # Check a response of create_port - self._check_response_portbindings_vnic_type(port['port']) - # Check a response of get_port - ctx = context.get_admin_context() - port = self._show('ports', port_id, neutron_context=ctx)['port'] - self._check_response_portbindings_vnic_type(port) - # By default user is admin - now test non admin user - ctx = context.Context(user_id=None, - tenant_id=self._tenant_id, - is_admin=False, - read_deleted="no") - non_admin_port = self._show( - 'ports', port_id, neutron_context=ctx)['port'] - self._check_response_portbindings_vnic_type(non_admin_port) - - def test_ports_vnic_type(self): - cfg.CONF.set_default('allow_overlapping_ips', True) - vnic_arg = {portbindings.VNIC_TYPE: self.vnic_type} - with contextlib.nested( - self.port(name='name1', - arg_list=(portbindings.VNIC_TYPE,), - **vnic_arg), - self.port(name='name2')): - ctx = context.get_admin_context() - ports = self._list('ports', neutron_context=ctx)['ports'] - self.assertEqual(2, len(ports)) - for port in ports: - if port['name'] == 'name1': - self._check_response_portbindings_vnic_type(port) - else: - self.assertEqual(portbindings.VNIC_NORMAL, - port[portbindings.VNIC_TYPE]) - # By default user is admin - now test non admin user - ctx = context.Context(user_id=None, - tenant_id=self._tenant_id, - is_admin=False, - read_deleted="no") - ports = self._list('ports', neutron_context=ctx)['ports'] - self.assertEqual(2, len(ports)) - for non_admin_port in ports: - self._check_response_portbindings_vnic_type(non_admin_port) - - def test_ports_vnic_type_list(self): - cfg.CONF.set_default('allow_overlapping_ips', True) - vnic_arg = {portbindings.VNIC_TYPE: self.vnic_type} - with contextlib.nested( - self.port(name='name1', - arg_list=(portbindings.VNIC_TYPE,), - **vnic_arg), - self.port(name='name2'), - self.port(name='name3', - arg_list=(portbindings.VNIC_TYPE,), - **vnic_arg),) as (port1, port2, port3): - self._test_list_resources( - 'port', (port1, port2, port3), - query_params='%s=%s' % (portbindings.VNIC_TYPE, - self.vnic_type)) diff --git a/neutron/tests/unit/agent/linux/test_ovs_lib.py b/neutron/tests/unit/agent/linux/test_ovs_lib.py deleted file mode 100644 index 8a19ed39a..000000000 --- a/neutron/tests/unit/agent/linux/test_ovs_lib.py +++ /dev/null @@ -1,967 +0,0 @@ -# Copyright 2012, VMware, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import collections -import mock -from oslo.config import cfg -import testtools - -from neutron.agent.linux import ovs_lib -from neutron.agent.linux import utils -from neutron.common import exceptions -from neutron.openstack.common import jsonutils -from neutron.openstack.common import uuidutils -from neutron.plugins.common import constants as p_const -from neutron.plugins.openvswitch.common import constants as const -from neutron.tests import base -from neutron.tests import tools - -try: - OrderedDict = collections.OrderedDict -except AttributeError: - import ordereddict - OrderedDict = ordereddict.OrderedDict - -OVS_LINUX_KERN_VERS_WITHOUT_VXLAN = "3.12.0" - - -class TestBaseOVS(base.BaseTestCase): - - def setUp(self): - super(TestBaseOVS, self).setUp() - self.root_helper = 'sudo' - self.ovs = ovs_lib.BaseOVS(self.root_helper) - self.br_name = 'bridge1' - - def test_add_bridge(self): - with mock.patch.object(self.ovs, 'run_vsctl') as mock_vsctl: - bridge = self.ovs.add_bridge(self.br_name) - - mock_vsctl.assert_called_with(["--", "--may-exist", - "add-br", self.br_name]) - self.assertEqual(bridge.br_name, self.br_name) - self.assertEqual(bridge.root_helper, self.ovs.root_helper) - - def test_delete_bridge(self): - with mock.patch.object(self.ovs, 'run_vsctl') as mock_vsctl: - self.ovs.delete_bridge(self.br_name) - mock_vsctl.assert_called_with(["--", "--if-exists", "del-br", - self.br_name]) - - def test_bridge_exists_returns_true(self): - with mock.patch.object(self.ovs, 'run_vsctl') as mock_vsctl: - self.assertTrue(self.ovs.bridge_exists(self.br_name)) - mock_vsctl.assert_called_with(['br-exists', self.br_name], - check_error=True) - - def test_bridge_exists_returns_false_for_exit_code_2(self): - with mock.patch.object(self.ovs, 'run_vsctl', - side_effect=RuntimeError('Exit code: 2\n')): - self.assertFalse(self.ovs.bridge_exists('bridge1')) - - def test_bridge_exists_raises_unknown_exception(self): - with mock.patch.object(self.ovs, 'run_vsctl', - side_effect=RuntimeError()): - with testtools.ExpectedException(RuntimeError): - self.ovs.bridge_exists('bridge1') - - def test_get_bridge_name_for_port_name_returns_bridge_for_valid_port(self): - port_name = 'bar' - with mock.patch.object(self.ovs, 'run_vsctl', - return_value=self.br_name) as mock_vsctl: - bridge = self.ovs.get_bridge_name_for_port_name(port_name) - self.assertEqual(bridge, self.br_name) - mock_vsctl.assert_called_with(['port-to-br', port_name], - check_error=True) - - def test_get_bridge_name_for_port_name_returns_none_for_exit_code_1(self): - with mock.patch.object(self.ovs, 'run_vsctl', - side_effect=RuntimeError('Exit code: 1\n')): - self.assertFalse(self.ovs.get_bridge_name_for_port_name('bridge1')) - - def test_get_bridge_name_for_port_name_raises_unknown_exception(self): - with mock.patch.object(self.ovs, 'run_vsctl', - side_effect=RuntimeError()): - with testtools.ExpectedException(RuntimeError): - self.ovs.get_bridge_name_for_port_name('bridge1') - - def _test_port_exists(self, br_name, result): - with mock.patch.object(self.ovs, - 'get_bridge_name_for_port_name', - return_value=br_name): - self.assertEqual(self.ovs.port_exists('bar'), result) - - def test_port_exists_returns_true_for_bridge_name(self): - self._test_port_exists(self.br_name, True) - - def test_port_exists_returns_false_for_none(self): - self._test_port_exists(None, False) - - -class OVS_Lib_Test(base.BaseTestCase): - """A test suite to exercise the OVS libraries shared by Neutron agents. - - Note: these tests do not actually execute ovs-* utilities, and thus - can run on any system. That does, however, limit their scope. - """ - - def setUp(self): - super(OVS_Lib_Test, self).setUp() - self.BR_NAME = "br-int" - self.TO = "--timeout=10" - - self.root_helper = 'sudo' - self.br = ovs_lib.OVSBridge(self.BR_NAME, self.root_helper) - self.execute = mock.patch.object( - utils, "execute", spec=utils.execute).start() - - def test_vifport(self): - """Create and stringify vif port, confirm no exceptions.""" - - pname = "vif1.0" - ofport = 5 - vif_id = uuidutils.generate_uuid() - mac = "ca:fe:de:ad:be:ef" - - # test __init__ - port = ovs_lib.VifPort(pname, ofport, vif_id, mac, self.br) - self.assertEqual(port.port_name, pname) - self.assertEqual(port.ofport, ofport) - self.assertEqual(port.vif_id, vif_id) - self.assertEqual(port.vif_mac, mac) - self.assertEqual(port.switch.br_name, self.BR_NAME) - - # test __str__ - str(port) - - def test_set_controller(self): - controller_names = ['tcp:127.0.0.1:6633', 'tcp:172.17.16.10:5555'] - self.br.set_controller(controller_names) - self.execute.assert_called_once_with( - ['ovs-vsctl', self.TO, '--', 'set-controller', self.BR_NAME, - 'tcp:127.0.0.1:6633', 'tcp:172.17.16.10:5555'], - root_helper=self.root_helper) - - def test_del_controller(self): - self.br.del_controller() - self.execute.assert_called_once_with( - ['ovs-vsctl', self.TO, '--', 'del-controller', self.BR_NAME], - root_helper=self.root_helper) - - def test_get_controller(self): - self.execute.return_value = 'tcp:127.0.0.1:6633\ntcp:172.17.16.10:5555' - names = self.br.get_controller() - self.assertEqual(names, - ['tcp:127.0.0.1:6633', 'tcp:172.17.16.10:5555']) - self.execute.assert_called_once_with( - ['ovs-vsctl', self.TO, '--', 'get-controller', self.BR_NAME], - root_helper=self.root_helper) - - def test_set_secure_mode(self): - self.br.set_secure_mode() - self.execute.assert_called_once_with( - ['ovs-vsctl', self.TO, '--', 'set-fail-mode', self.BR_NAME, - 'secure'], root_helper=self.root_helper) - - def test_set_protocols(self): - protocols = 'OpenFlow13' - self.br.set_protocols(protocols) - self.execute.assert_called_once_with( - ['ovs-vsctl', self.TO, '--', 'set', 'bridge', self.BR_NAME, - "protocols=%s" % protocols], - root_helper=self.root_helper) - - def test_create(self): - self.br.add_bridge(self.BR_NAME) - - self.br.create() - - def test_destroy(self): - self.br.delete_bridge(self.BR_NAME) - - self.br.destroy() - - def test_reset_bridge(self): - self.br.destroy() - self.br.create() - - self.br.reset_bridge() - - def _build_timeout_opt(self, exp_timeout): - return "--timeout=%d" % exp_timeout if exp_timeout else self.TO - - def _test_delete_port(self, exp_timeout=None): - exp_timeout_str = self._build_timeout_opt(exp_timeout) - pname = "tap5" - self.br.delete_port(pname) - self.execute.assert_called_once_with( - ["ovs-vsctl", exp_timeout_str, "--", "--if-exists", - "del-port", self.BR_NAME, pname], - root_helper=self.root_helper) - - def test_delete_port(self): - self._test_delete_port() - - def test_call_command_non_default_timeput(self): - # This test is only for verifying a non-default timeout - # is correctly applied. Does not need to be repeated for - # every ovs_lib method - new_timeout = 5 - self.br.vsctl_timeout = new_timeout - self._test_delete_port(new_timeout) - - def test_add_flow(self): - ofport = "99" - vid = 4000 - lsw_id = 18 - cidr = '192.168.1.0/24' - - flow_dict_1 = OrderedDict([('priority', 2), - ('dl_src', 'ca:fe:de:ad:be:ef'), - ('actions', 'strip_vlan,output:0')]) - flow_dict_2 = OrderedDict([('priority', 1), - ('actions', 'normal')]) - flow_dict_3 = OrderedDict([('priority', 2), - ('actions', 'drop')]) - flow_dict_4 = OrderedDict([('priority', 2), - ('in_port', ofport), - ('actions', 'drop')]) - flow_dict_5 = OrderedDict([ - ('priority', 4), - ('in_port', ofport), - ('dl_vlan', vid), - ('actions', "strip_vlan,set_tunnel:%s,normal" % (lsw_id))]) - flow_dict_6 = OrderedDict([ - ('priority', 3), - ('tun_id', lsw_id), - ('actions', "mod_vlan_vid:%s,output:%s" % (vid, ofport))]) - flow_dict_7 = OrderedDict([ - ('priority', 4), - ('nw_src', cidr), - ('proto', 'arp'), - ('actions', 'drop')]) - - self.br.add_flow(**flow_dict_1) - self.br.add_flow(**flow_dict_2) - self.br.add_flow(**flow_dict_3) - self.br.add_flow(**flow_dict_4) - self.br.add_flow(**flow_dict_5) - self.br.add_flow(**flow_dict_6) - self.br.add_flow(**flow_dict_7) - expected_calls = [ - mock.call(["ovs-ofctl", "add-flow", self.BR_NAME, - "hard_timeout=0,idle_timeout=0," - "priority=2,dl_src=ca:fe:de:ad:be:ef" - ",actions=strip_vlan,output:0"], - process_input=None, root_helper=self.root_helper), - mock.call(["ovs-ofctl", "add-flow", self.BR_NAME, - "hard_timeout=0,idle_timeout=0," - "priority=1,actions=normal"], - process_input=None, root_helper=self.root_helper), - mock.call(["ovs-ofctl", "add-flow", self.BR_NAME, - "hard_timeout=0,idle_timeout=0," - "priority=2,actions=drop"], - process_input=None, root_helper=self.root_helper), - mock.call(["ovs-ofctl", "add-flow", self.BR_NAME, - "hard_timeout=0,idle_timeout=0," - "priority=2,in_port=%s,actions=drop" % ofport], - process_input=None, root_helper=self.root_helper), - mock.call(["ovs-ofctl", "add-flow", self.BR_NAME, - "hard_timeout=0,idle_timeout=0," - "priority=4,dl_vlan=%s,in_port=%s," - "actions=strip_vlan,set_tunnel:%s,normal" - % (vid, ofport, lsw_id)], - process_input=None, root_helper=self.root_helper), - mock.call(["ovs-ofctl", "add-flow", self.BR_NAME, - "hard_timeout=0,idle_timeout=0," - "priority=3,tun_id=%s,actions=" - "mod_vlan_vid:%s,output:%s" - % (lsw_id, vid, ofport)], - process_input=None, root_helper=self.root_helper), - mock.call(["ovs-ofctl", "add-flow", self.BR_NAME, - "hard_timeout=0,idle_timeout=0," - "priority=4,nw_src=%s,arp,actions=drop" % cidr], - process_input=None, root_helper=self.root_helper), - ] - self.execute.assert_has_calls(expected_calls) - - def test_add_flow_timeout_set(self): - flow_dict = OrderedDict([('priority', 1), - ('hard_timeout', 1000), - ('idle_timeout', 2000), - ('actions', 'normal')]) - - self.br.add_flow(**flow_dict) - self.execute.assert_called_once_with( - ["ovs-ofctl", "add-flow", self.BR_NAME, - "hard_timeout=1000,idle_timeout=2000,priority=1,actions=normal"], - process_input=None, - root_helper=self.root_helper) - - def test_add_flow_default_priority(self): - flow_dict = OrderedDict([('actions', 'normal')]) - - self.br.add_flow(**flow_dict) - self.execute.assert_called_once_with( - ["ovs-ofctl", "add-flow", self.BR_NAME, - "hard_timeout=0,idle_timeout=0,priority=1,actions=normal"], - process_input=None, - root_helper=self.root_helper) - - def test_get_port_ofport(self): - pname = "tap99" - ofport = "6" - self.execute.return_value = ofport - self.assertEqual(self.br.get_port_ofport(pname), ofport) - self.execute.assert_called_once_with( - ["ovs-vsctl", self.TO, "get", "Interface", pname, "ofport"], - root_helper=self.root_helper) - - def test_get_port_ofport_non_int(self): - pname = "tap99" - ofport = "[]" - self.execute.return_value = ofport - self.assertEqual(self.br.get_port_ofport(pname), const.INVALID_OFPORT) - self.execute.assert_called_once_with( - ["ovs-vsctl", self.TO, "get", "Interface", pname, "ofport"], - root_helper=self.root_helper) - - def test_get_datapath_id(self): - datapath_id = '"0000b67f4fbcc149"' - self.execute.return_value = datapath_id - self.assertEqual(self.br.get_datapath_id(), datapath_id.strip('"')) - self.execute.assert_called_once_with( - ["ovs-vsctl", self.TO, "get", - "Bridge", self.BR_NAME, "datapath_id"], - root_helper=self.root_helper) - - def test_count_flows(self): - self.execute.return_value = 'ignore\nflow-1\n' - # counts the number of flows as total lines of output - 2 - self.assertEqual(self.br.count_flows(), 1) - self.execute.assert_called_once_with( - ["ovs-ofctl", "dump-flows", self.BR_NAME], - root_helper=self.root_helper, - process_input=None) - - def test_delete_flow(self): - ofport = "5" - lsw_id = 40 - vid = 39 - self.br.delete_flows(in_port=ofport) - self.br.delete_flows(tun_id=lsw_id) - self.br.delete_flows(dl_vlan=vid) - expected_calls = [ - mock.call(["ovs-ofctl", "del-flows", self.BR_NAME, - "in_port=" + ofport], - process_input=None, root_helper=self.root_helper), - mock.call(["ovs-ofctl", "del-flows", self.BR_NAME, - "tun_id=%s" % lsw_id], - process_input=None, root_helper=self.root_helper), - mock.call(["ovs-ofctl", "del-flows", self.BR_NAME, - "dl_vlan=%s" % vid], - process_input=None, root_helper=self.root_helper), - ] - self.execute.assert_has_calls(expected_calls) - - def test_delete_flow_with_priority_set(self): - params = {'in_port': '1', - 'priority': '1'} - - self.assertRaises(exceptions.InvalidInput, - self.br.delete_flows, - **params) - - def test_dump_flows(self): - table = 23 - nxst_flow = "NXST_FLOW reply (xid=0x4):" - flows = "\n".join([" cookie=0x0, duration=18042.514s, table=0, " - "n_packets=6, n_bytes=468, " - "priority=2,in_port=1 actions=drop", - " cookie=0x0, duration=18027.562s, table=0, " - "n_packets=0, n_bytes=0, " - "priority=3,in_port=1,dl_vlan=100 " - "actions=mod_vlan_vid:1,NORMAL", - " cookie=0x0, duration=18044.351s, table=0, " - "n_packets=9, n_bytes=594, priority=1 " - "actions=NORMAL", " cookie=0x0, " - "duration=18044.211s, table=23, n_packets=0, " - "n_bytes=0, priority=0 actions=drop"]) - flow_args = '\n'.join([nxst_flow, flows]) - run_ofctl = mock.patch.object(self.br, 'run_ofctl').start() - run_ofctl.side_effect = [flow_args] - retflows = self.br.dump_flows_for_table(table) - self.assertEqual(flows, retflows) - - def test_dump_flows_ovs_dead(self): - table = 23 - run_ofctl = mock.patch.object(self.br, 'run_ofctl').start() - run_ofctl.side_effect = [''] - retflows = self.br.dump_flows_for_table(table) - self.assertEqual(None, retflows) - - def test_mod_flow_with_priority_set(self): - params = {'in_port': '1', - 'priority': '1'} - - self.assertRaises(exceptions.InvalidInput, - self.br.mod_flow, - **params) - - def test_mod_flow_no_actions_set(self): - params = {'in_port': '1'} - - self.assertRaises(exceptions.InvalidInput, - self.br.mod_flow, - **params) - - def test_defer_apply_flows(self): - - flow_expr = mock.patch.object(ovs_lib, '_build_flow_expr_str').start() - flow_expr.side_effect = ['added_flow_1', 'added_flow_2', - 'deleted_flow_1'] - run_ofctl = mock.patch.object(self.br, 'run_ofctl').start() - - self.br.defer_apply_on() - self.br.add_flow(flow='add_flow_1') - self.br.defer_apply_on() - self.br.add_flow(flow='add_flow_2') - self.br.delete_flows(flow='delete_flow_1') - self.br.defer_apply_off() - - flow_expr.assert_has_calls([ - mock.call({'flow': 'add_flow_1'}, 'add'), - mock.call({'flow': 'add_flow_2'}, 'add'), - mock.call({'flow': 'delete_flow_1'}, 'del') - ]) - - run_ofctl.assert_has_calls([ - mock.call('add-flows', ['-'], 'added_flow_1\nadded_flow_2\n'), - mock.call('del-flows', ['-'], 'deleted_flow_1\n') - ]) - - def test_defer_apply_flows_concurrently(self): - flow_expr = mock.patch.object(ovs_lib, '_build_flow_expr_str').start() - flow_expr.side_effect = ['added_flow_1', 'deleted_flow_1', - 'modified_flow_1', 'added_flow_2', - 'deleted_flow_2', 'modified_flow_2'] - - run_ofctl = mock.patch.object(self.br, 'run_ofctl').start() - - def run_ofctl_fake(cmd, args, process_input=None): - self.br.defer_apply_on() - if cmd == 'add-flows': - self.br.add_flow(flow='added_flow_2') - elif cmd == 'del-flows': - self.br.delete_flows(flow='deleted_flow_2') - elif cmd == 'mod-flows': - self.br.mod_flow(flow='modified_flow_2') - run_ofctl.side_effect = run_ofctl_fake - - self.br.defer_apply_on() - self.br.add_flow(flow='added_flow_1') - self.br.delete_flows(flow='deleted_flow_1') - self.br.mod_flow(flow='modified_flow_1') - self.br.defer_apply_off() - - run_ofctl.side_effect = None - self.br.defer_apply_off() - - flow_expr.assert_has_calls([ - mock.call({'flow': 'added_flow_1'}, 'add'), - mock.call({'flow': 'deleted_flow_1'}, 'del'), - mock.call({'flow': 'modified_flow_1'}, 'mod'), - mock.call({'flow': 'added_flow_2'}, 'add'), - mock.call({'flow': 'deleted_flow_2'}, 'del'), - mock.call({'flow': 'modified_flow_2'}, 'mod') - ]) - run_ofctl.assert_has_calls([ - mock.call('add-flows', ['-'], 'added_flow_1\n'), - mock.call('del-flows', ['-'], 'deleted_flow_1\n'), - mock.call('mod-flows', ['-'], 'modified_flow_1\n'), - mock.call('add-flows', ['-'], 'added_flow_2\n'), - mock.call('del-flows', ['-'], 'deleted_flow_2\n'), - mock.call('mod-flows', ['-'], 'modified_flow_2\n') - ]) - - def test_add_tunnel_port(self): - pname = "tap99" - local_ip = "1.1.1.1" - remote_ip = "9.9.9.9" - ofport = "6" - command = ["ovs-vsctl", self.TO, '--', "--may-exist", "add-port", - self.BR_NAME, pname] - command.extend(["--", "set", "Interface", pname]) - command.extend(["type=gre", "options:df_default=true", - "options:remote_ip=" + remote_ip, - "options:local_ip=" + local_ip, - "options:in_key=flow", - "options:out_key=flow"]) - # Each element is a tuple of (expected mock call, return_value) - expected_calls_and_values = [ - (mock.call(command, root_helper=self.root_helper), None), - (mock.call(["ovs-vsctl", self.TO, "get", - "Interface", pname, "ofport"], - root_helper=self.root_helper), - ofport), - ] - tools.setup_mock_calls(self.execute, expected_calls_and_values) - - self.assertEqual( - self.br.add_tunnel_port(pname, remote_ip, local_ip), - ofport) - - tools.verify_mock_calls(self.execute, expected_calls_and_values) - - def test_add_vxlan_fragmented_tunnel_port(self): - pname = "tap99" - local_ip = "1.1.1.1" - remote_ip = "9.9.9.9" - ofport = "6" - vxlan_udp_port = "9999" - dont_fragment = False - command = ["ovs-vsctl", self.TO, '--', "--may-exist", "add-port", - self.BR_NAME, pname] - command.extend(["--", "set", "Interface", pname]) - command.extend(["type=" + p_const.TYPE_VXLAN, - "options:dst_port=" + vxlan_udp_port, - "options:df_default=false", - "options:remote_ip=" + remote_ip, - "options:local_ip=" + local_ip, - "options:in_key=flow", - "options:out_key=flow"]) - # Each element is a tuple of (expected mock call, return_value) - expected_calls_and_values = [ - (mock.call(command, root_helper=self.root_helper), None), - (mock.call(["ovs-vsctl", self.TO, "get", - "Interface", pname, "ofport"], - root_helper=self.root_helper), - ofport), - ] - tools.setup_mock_calls(self.execute, expected_calls_and_values) - - self.assertEqual( - self.br.add_tunnel_port(pname, remote_ip, local_ip, - p_const.TYPE_VXLAN, vxlan_udp_port, - dont_fragment), - ofport) - - tools.verify_mock_calls(self.execute, expected_calls_and_values) - - def test_add_patch_port(self): - pname = "tap99" - peer = "bar10" - ofport = "6" - - # Each element is a tuple of (expected mock call, return_value) - command = ["ovs-vsctl", self.TO, "add-port", self.BR_NAME, pname] - command.extend(["--", "set", "Interface", pname]) - command.extend(["type=patch", "options:peer=" + peer]) - expected_calls_and_values = [ - (mock.call(command, root_helper=self.root_helper), - None), - (mock.call(["ovs-vsctl", self.TO, "get", - "Interface", pname, "ofport"], - root_helper=self.root_helper), - ofport) - ] - tools.setup_mock_calls(self.execute, expected_calls_and_values) - - self.assertEqual(self.br.add_patch_port(pname, peer), ofport) - tools.verify_mock_calls(self.execute, expected_calls_and_values) - - def _test_get_vif_ports(self, is_xen=False): - pname = "tap99" - ofport = "6" - vif_id = uuidutils.generate_uuid() - mac = "ca:fe:de:ad:be:ef" - - if is_xen: - external_ids = ('{xs-vif-uuid="%s", attached-mac="%s"}' - % (vif_id, mac)) - else: - external_ids = ('{iface-id="%s", attached-mac="%s"}' - % (vif_id, mac)) - - # Each element is a tuple of (expected mock call, return_value) - expected_calls_and_values = [ - (mock.call(["ovs-vsctl", self.TO, "list-ports", self.BR_NAME], - root_helper=self.root_helper), - "%s\n" % pname), - (mock.call(["ovs-vsctl", self.TO, "get", - "Interface", pname, "external_ids"], - root_helper=self.root_helper), - external_ids), - (mock.call(["ovs-vsctl", self.TO, "get", - "Interface", pname, "ofport"], - root_helper=self.root_helper), - ofport), - ] - if is_xen: - expected_calls_and_values.append( - (mock.call(["xe", "vif-param-get", "param-name=other-config", - "param-key=nicira-iface-id", "uuid=" + vif_id], - root_helper=self.root_helper), - vif_id) - ) - tools.setup_mock_calls(self.execute, expected_calls_and_values) - - ports = self.br.get_vif_ports() - self.assertEqual(1, len(ports)) - self.assertEqual(ports[0].port_name, pname) - self.assertEqual(ports[0].ofport, ofport) - self.assertEqual(ports[0].vif_id, vif_id) - self.assertEqual(ports[0].vif_mac, mac) - self.assertEqual(ports[0].switch.br_name, self.BR_NAME) - tools.verify_mock_calls(self.execute, expected_calls_and_values) - - def _encode_ovs_json(self, headings, data): - # See man ovs-vsctl(8) for the encoding details. - r = {"data": [], - "headings": headings} - for row in data: - ovs_row = [] - r["data"].append(ovs_row) - for cell in row: - if isinstance(cell, (str, int, list)): - ovs_row.append(cell) - elif isinstance(cell, dict): - ovs_row.append(["map", cell.items()]) - elif isinstance(cell, set): - ovs_row.append(["set", cell]) - else: - raise TypeError('%r not int, str, list, set or dict' % - type(cell)) - return jsonutils.dumps(r) - - def _test_get_vif_port_set(self, is_xen): - if is_xen: - id_key = 'xs-vif-uuid' - else: - id_key = 'iface-id' - - headings = ['name', 'external_ids'] - data = [ - # A vif port on this bridge: - ['tap99', {id_key: 'tap99id', 'attached-mac': 'tap99mac'}, 1], - # A vif port on this bridge not yet configured - ['tap98', {id_key: 'tap98id', 'attached-mac': 'tap98mac'}, []], - # Another vif port on this bridge not yet configured - ['tap97', {id_key: 'tap97id', 'attached-mac': 'tap97mac'}, - ['set', []]], - - # A vif port on another bridge: - ['tap88', {id_key: 'tap88id', 'attached-mac': 'tap88id'}, 1], - # Non-vif port on this bridge: - ['tun22', {}, 2], - ] - - # Each element is a tuple of (expected mock call, return_value) - expected_calls_and_values = [ - (mock.call(["ovs-vsctl", self.TO, "list-ports", self.BR_NAME], - root_helper=self.root_helper), - 'tap99\ntun22'), - (mock.call(["ovs-vsctl", self.TO, "--format=json", - "--", "--columns=name,external_ids,ofport", - "list", "Interface"], - root_helper=self.root_helper), - self._encode_ovs_json(headings, data)), - ] - tools.setup_mock_calls(self.execute, expected_calls_and_values) - - if is_xen: - get_xapi_iface_id = mock.patch.object(self.br, - 'get_xapi_iface_id').start() - get_xapi_iface_id.return_value = 'tap99id' - - port_set = self.br.get_vif_port_set() - self.assertEqual(set(['tap99id']), port_set) - tools.verify_mock_calls(self.execute, expected_calls_and_values) - if is_xen: - get_xapi_iface_id.assert_called_once_with('tap99id') - - def test_get_vif_ports_nonxen(self): - self._test_get_vif_ports(is_xen=False) - - def test_get_vif_ports_xen(self): - self._test_get_vif_ports(is_xen=True) - - def test_get_vif_port_set_nonxen(self): - self._test_get_vif_port_set(False) - - def test_get_vif_port_set_xen(self): - self._test_get_vif_port_set(True) - - def test_get_vif_ports_list_ports_error(self): - expected_calls_and_values = [ - (mock.call(["ovs-vsctl", self.TO, "list-ports", self.BR_NAME], - root_helper=self.root_helper), - RuntimeError()), - ] - tools.setup_mock_calls(self.execute, expected_calls_and_values) - self.assertRaises(RuntimeError, self.br.get_vif_ports) - tools.verify_mock_calls(self.execute, expected_calls_and_values) - - def test_get_vif_port_set_list_ports_error(self): - expected_calls_and_values = [ - (mock.call(["ovs-vsctl", self.TO, "list-ports", self.BR_NAME], - root_helper=self.root_helper), - RuntimeError()), - ] - tools.setup_mock_calls(self.execute, expected_calls_and_values) - self.assertRaises(RuntimeError, self.br.get_vif_port_set) - tools.verify_mock_calls(self.execute, expected_calls_and_values) - - def test_get_vif_port_set_list_interface_error(self): - expected_calls_and_values = [ - (mock.call(["ovs-vsctl", self.TO, "list-ports", self.BR_NAME], - root_helper=self.root_helper), - 'tap99\n'), - (mock.call(["ovs-vsctl", self.TO, "--format=json", - "--", "--columns=name,external_ids,ofport", - "list", "Interface"], - root_helper=self.root_helper), - RuntimeError()), - ] - tools.setup_mock_calls(self.execute, expected_calls_and_values) - self.assertRaises(RuntimeError, self.br.get_vif_port_set) - tools.verify_mock_calls(self.execute, expected_calls_and_values) - - def test_get_port_tag_dict(self): - headings = ['name', 'tag'] - data = [ - ['int-br-eth2', set()], - ['patch-tun', set()], - ['qr-76d9e6b6-21', 1], - ['tapce5318ff-78', 1], - ['tape1400310-e6', 1], - ] - - # Each element is a tuple of (expected mock call, return_value) - expected_calls_and_values = [ - (mock.call(["ovs-vsctl", self.TO, "list-ports", self.BR_NAME], - root_helper=self.root_helper), - '\n'.join((iface for iface, tag in data))), - (mock.call(["ovs-vsctl", self.TO, "--format=json", - "--", "--columns=name,tag", - "list", "Port"], - root_helper=self.root_helper), - self._encode_ovs_json(headings, data)), - ] - tools.setup_mock_calls(self.execute, expected_calls_and_values) - - port_tags = self.br.get_port_tag_dict() - self.assertEqual( - port_tags, - {u'int-br-eth2': [], - u'patch-tun': [], - u'qr-76d9e6b6-21': 1, - u'tapce5318ff-78': 1, - u'tape1400310-e6': 1} - ) - - def test_clear_db_attribute(self): - pname = "tap77" - self.br.clear_db_attribute("Port", pname, "tag") - self.execute.assert_called_once_with( - ["ovs-vsctl", self.TO, "clear", "Port", pname, "tag"], - root_helper=self.root_helper) - - def _test_iface_to_br(self, exp_timeout=None): - iface = 'tap0' - br = 'br-int' - root_helper = 'sudo' - self.execute.return_value = 'br-int' - exp_timeout_str = self._build_timeout_opt(exp_timeout) - self.assertEqual(ovs_lib.get_bridge_for_iface(root_helper, iface), br) - self.execute.assert_called_once_with( - ["ovs-vsctl", exp_timeout_str, "iface-to-br", iface], - root_helper=root_helper) - - def test_iface_to_br(self): - self._test_iface_to_br() - - def test_iface_to_br_non_default_timeout(self): - new_timeout = 5 - cfg.CONF.set_override('ovs_vsctl_timeout', new_timeout) - self._test_iface_to_br(new_timeout) - - def test_iface_to_br_handles_ovs_vsctl_exception(self): - iface = 'tap0' - root_helper = 'sudo' - self.execute.side_effect = Exception - - self.assertIsNone(ovs_lib.get_bridge_for_iface(root_helper, iface)) - self.execute.assert_called_once_with( - ["ovs-vsctl", self.TO, "iface-to-br", iface], - root_helper=root_helper) - - def test_delete_all_ports(self): - with mock.patch.object(self.br, 'get_port_name_list', - return_value=['port1']) as get_port: - with mock.patch.object(self.br, 'delete_port') as delete_port: - self.br.delete_ports(all_ports=True) - get_port.assert_called_once_with() - delete_port.assert_called_once_with('port1') - - def test_delete_neutron_ports(self): - port1 = ovs_lib.VifPort('tap1234', 1, uuidutils.generate_uuid(), - 'ca:fe:de:ad:be:ef', 'br') - port2 = ovs_lib.VifPort('tap5678', 2, uuidutils.generate_uuid(), - 'ca:ee:de:ad:be:ef', 'br') - with mock.patch.object(self.br, 'get_vif_ports', - return_value=[port1, port2]) as get_ports: - with mock.patch.object(self.br, 'delete_port') as delete_port: - self.br.delete_ports(all_ports=False) - get_ports.assert_called_once_with() - delete_port.assert_has_calls([ - mock.call('tap1234'), - mock.call('tap5678') - ]) - - def test_delete_neutron_ports_list_error(self): - expected_calls_and_values = [ - (mock.call(["ovs-vsctl", self.TO, "list-ports", self.BR_NAME], - root_helper=self.root_helper), - RuntimeError()), - ] - tools.setup_mock_calls(self.execute, expected_calls_and_values) - self.assertRaises(RuntimeError, self.br.delete_ports, all_ports=False) - tools.verify_mock_calls(self.execute, expected_calls_and_values) - - def _test_get_bridges(self, exp_timeout=None): - bridges = ['br-int', 'br-ex'] - root_helper = 'sudo' - self.execute.return_value = 'br-int\nbr-ex\n' - timeout_str = self._build_timeout_opt(exp_timeout) - self.assertEqual(ovs_lib.get_bridges(root_helper), bridges) - self.execute.assert_called_once_with( - ["ovs-vsctl", timeout_str, "list-br"], - root_helper=root_helper) - - def test_get_bridges(self): - self._test_get_bridges() - - def test_get_bridges_not_default_timeout(self): - new_timeout = 5 - cfg.CONF.set_override('ovs_vsctl_timeout', new_timeout) - self._test_get_bridges(new_timeout) - - def test_get_local_port_mac_succeeds(self): - with mock.patch('neutron.agent.linux.ip_lib.IpLinkCommand', - return_value=mock.Mock(address='foo')): - self.assertEqual('foo', self.br.get_local_port_mac()) - - def test_get_local_port_mac_raises_exception_for_missing_mac(self): - with mock.patch('neutron.agent.linux.ip_lib.IpLinkCommand', - return_value=mock.Mock(address=None)): - with testtools.ExpectedException(Exception): - self.br.get_local_port_mac() - - def _test_get_vif_port_by_id(self, iface_id, data, br_name=None): - headings = ['external_ids', 'name', 'ofport'] - # Each element is a tuple of (expected mock call, return_value) - expected_calls_and_values = [ - (mock.call(["ovs-vsctl", self.TO, "--format=json", - "--", "--columns=external_ids,name,ofport", - "find", "Interface", - 'external_ids:iface-id="%s"' % iface_id], - root_helper=self.root_helper), - self._encode_ovs_json(headings, data))] - if data: - if not br_name: - br_name = self.BR_NAME - - expected_calls_and_values.append( - (mock.call(["ovs-vsctl", self.TO, - "iface-to-br", data[0][headings.index('name')]], - root_helper=self.root_helper), - br_name)) - tools.setup_mock_calls(self.execute, expected_calls_and_values) - vif_port = self.br.get_vif_port_by_id(iface_id) - - tools.verify_mock_calls(self.execute, expected_calls_and_values) - return vif_port - - def _test_get_vif_port_by_id_with_data(self, ofport=None, mac=None): - external_ids = [["iface-id", "tap99id"], - ["iface-status", "active"]] - if mac: - external_ids.append(["attached-mac", mac]) - data = [[["map", external_ids], "tap99", - ofport if ofport else '["set",[]]']] - vif_port = self._test_get_vif_port_by_id('tap99id', data) - if not ofport or ofport == -1 or not mac: - self.assertIsNone(vif_port) - return - self.assertEqual(vif_port.vif_id, 'tap99id') - self.assertEqual(vif_port.vif_mac, 'aa:bb:cc:dd:ee:ff') - self.assertEqual(vif_port.port_name, 'tap99') - self.assertEqual(vif_port.ofport, ofport) - - def test_get_vif_by_port_id_with_ofport(self): - self._test_get_vif_port_by_id_with_data( - ofport=1, mac="aa:bb:cc:dd:ee:ff") - - def test_get_vif_by_port_id_without_ofport(self): - self._test_get_vif_port_by_id_with_data(mac="aa:bb:cc:dd:ee:ff") - - def test_get_vif_by_port_id_with_invalid_ofport(self): - self._test_get_vif_port_by_id_with_data( - ofport=-1, mac="aa:bb:cc:dd:ee:ff") - - def test_get_vif_by_port_id_without_mac(self): - self._test_get_vif_port_by_id_with_data(ofport=1) - - def test_get_vif_by_port_id_with_no_data(self): - self.assertIsNone(self._test_get_vif_port_by_id('whatever', [])) - - def test_get_vif_by_port_id_different_bridge(self): - external_ids = [["iface-id", "tap99id"], - ["iface-status", "active"]] - data = [[["map", external_ids], "tap99", 1]] - self.assertIsNone(self._test_get_vif_port_by_id('tap99id', data, - "br-ext")) - - def test_ofctl_arg_supported(self): - with mock.patch('neutron.common.utils.get_random_string') as utils: - utils.return_value = 'test' - supported = ovs_lib.ofctl_arg_supported(self.root_helper, 'cmd', - ['args']) - self.execute.assert_has_calls([ - mock.call(['ovs-vsctl', self.TO, '--', '--if-exists', 'del-br', - 'br-test-test'], root_helper=self.root_helper), - mock.call(['ovs-vsctl', self.TO, '--', '--may-exist', 'add-br', - 'br-test-test'], root_helper=self.root_helper), - mock.call(['ovs-ofctl', 'cmd', 'br-test-test', 'args'], - root_helper=self.root_helper), - mock.call(['ovs-vsctl', self.TO, '--', '--if-exists', 'del-br', - 'br-test-test'], root_helper=self.root_helper) - ]) - self.assertTrue(supported) - - self.execute.side_effect = Exception - supported = ovs_lib.ofctl_arg_supported(self.root_helper, 'cmd', - ['args']) - self.execute.assert_has_calls([ - mock.call(['ovs-vsctl', self.TO, '--', '--if-exists', 'del-br', - 'br-test-test'], root_helper=self.root_helper), - mock.call(['ovs-vsctl', self.TO, '--', '--may-exist', 'add-br', - 'br-test-test'], root_helper=self.root_helper), - mock.call(['ovs-ofctl', 'cmd', 'br-test-test', 'args'], - root_helper=self.root_helper), - mock.call(['ovs-vsctl', self.TO, '--', '--if-exists', 'del-br', - 'br-test-test'], root_helper=self.root_helper) - ]) - self.assertFalse(supported) diff --git a/neutron/tests/unit/agent/linux/test_ovsdb_monitor.py b/neutron/tests/unit/agent/linux/test_ovsdb_monitor.py deleted file mode 100644 index ec37f83aa..000000000 --- a/neutron/tests/unit/agent/linux/test_ovsdb_monitor.py +++ /dev/null @@ -1,105 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import eventlet.event -import mock - -from neutron.agent.linux import ovsdb_monitor -from neutron.tests import base - - -class TestOvsdbMonitor(base.BaseTestCase): - - def setUp(self): - super(TestOvsdbMonitor, self).setUp() - self.root_helper = 'sudo' - self.monitor = ovsdb_monitor.OvsdbMonitor('Interface', - root_helper=self.root_helper) - - def read_output_queues_and_returns_result(self, output_type, output): - with mock.patch.object(self.monitor, '_process') as mock_process: - with mock.patch.object(mock_process, output_type) as mock_file: - with mock.patch.object(mock_file, 'readline') as mock_readline: - mock_readline.return_value = output - func = getattr(self.monitor, - '_read_%s' % output_type, - None) - return func() - - def test__read_stdout_returns_none_for_empty_read(self): - result = self.read_output_queues_and_returns_result('stdout', '') - self.assertIsNone(result) - - def test__read_stdout_queues_normal_output_to_stdout_queue(self): - output = 'foo' - result = self.read_output_queues_and_returns_result('stdout', output) - self.assertEqual(result, output) - self.assertEqual(self.monitor._stdout_lines.get_nowait(), output) - - def test__read_stderr_returns_none(self): - result = self.read_output_queues_and_returns_result('stderr', '') - self.assertIsNone(result) - - -class TestSimpleInterfaceMonitor(base.BaseTestCase): - - def setUp(self): - super(TestSimpleInterfaceMonitor, self).setUp() - self.root_helper = 'sudo' - self.monitor = ovsdb_monitor.SimpleInterfaceMonitor( - root_helper=self.root_helper) - - def test_is_active_is_false_by_default(self): - self.assertFalse(self.monitor.is_active) - - def test_is_active_can_be_true(self): - self.monitor.data_received = True - self.monitor._kill_event = eventlet.event.Event() - self.assertTrue(self.monitor.is_active) - - def test_has_updates_is_true_by_default(self): - self.assertTrue(self.monitor.has_updates) - - def test_has_updates_is_false_if_active_with_no_output(self): - target = ('neutron.agent.linux.ovsdb_monitor.SimpleInterfaceMonitor' - '.is_active') - with mock.patch(target, - new_callable=mock.PropertyMock(return_value=True)): - self.assertFalse(self.monitor.has_updates) - - def test__kill_sets_data_received_to_false(self): - self.monitor.data_received = True - with mock.patch( - 'neutron.agent.linux.ovsdb_monitor.OvsdbMonitor._kill'): - self.monitor._kill() - self.assertFalse(self.monitor.data_received) - - def test__read_stdout_sets_data_received_and_returns_output(self): - output = 'foo' - with mock.patch( - 'neutron.agent.linux.ovsdb_monitor.OvsdbMonitor._read_stdout', - return_value=output): - result = self.monitor._read_stdout() - self.assertTrue(self.monitor.data_received) - self.assertEqual(result, output) - - def test__read_stdout_does_not_set_data_received_for_empty_ouput(self): - output = None - with mock.patch( - 'neutron.agent.linux.ovsdb_monitor.OvsdbMonitor._read_stdout', - return_value=output): - self.monitor._read_stdout() - self.assertFalse(self.monitor.data_received) diff --git a/neutron/tests/unit/agent/linux/test_polling.py b/neutron/tests/unit/agent/linux/test_polling.py deleted file mode 100644 index e288654c2..000000000 --- a/neutron/tests/unit/agent/linux/test_polling.py +++ /dev/null @@ -1,116 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock - -from neutron.agent.linux import polling -from neutron.tests import base - - -class TestGetPollingManager(base.BaseTestCase): - - def test_return_always_poll_by_default(self): - with polling.get_polling_manager() as pm: - self.assertEqual(pm.__class__, polling.AlwaysPoll) - - def test_manage_polling_minimizer(self): - mock_target = 'neutron.agent.linux.polling.InterfacePollingMinimizer' - with mock.patch('%s.start' % mock_target) as mock_start: - with mock.patch('%s.stop' % mock_target) as mock_stop: - with polling.get_polling_manager(minimize_polling=True, - root_helper='test') as pm: - self.assertEqual(pm._monitor.root_helper, 'test') - self.assertEqual(pm.__class__, - polling.InterfacePollingMinimizer) - mock_stop.assert_has_calls(mock.call()) - mock_start.assert_has_calls(mock.call()) - - -class TestBasePollingManager(base.BaseTestCase): - - def setUp(self): - super(TestBasePollingManager, self).setUp() - self.pm = polling.BasePollingManager() - - def test_force_polling_sets_interval_attribute(self): - self.assertFalse(self.pm._force_polling) - self.pm.force_polling() - self.assertTrue(self.pm._force_polling) - - def test_polling_completed_sets_interval_attribute(self): - self.pm._polling_completed = False - self.pm.polling_completed() - self.assertTrue(self.pm._polling_completed) - - def mock_is_polling_required(self, return_value): - return mock.patch.object(self.pm, '_is_polling_required', - return_value=return_value) - - def test_is_polling_required_returns_true_when_forced(self): - with self.mock_is_polling_required(False): - self.pm.force_polling() - self.assertTrue(self.pm.is_polling_required) - self.assertFalse(self.pm._force_polling) - - def test_is_polling_required_returns_true_when_polling_not_completed(self): - with self.mock_is_polling_required(False): - self.pm._polling_completed = False - self.assertTrue(self.pm.is_polling_required) - - def test_is_polling_required_returns_true_when_updates_are_present(self): - with self.mock_is_polling_required(True): - self.assertTrue(self.pm.is_polling_required) - self.assertFalse(self.pm._polling_completed) - - def test_is_polling_required_returns_false_for_no_updates(self): - with self.mock_is_polling_required(False): - self.assertFalse(self.pm.is_polling_required) - - -class TestAlwaysPoll(base.BaseTestCase): - - def test_is_polling_required_always_returns_true(self): - pm = polling.AlwaysPoll() - self.assertTrue(pm.is_polling_required) - - -class TestInterfacePollingMinimizer(base.BaseTestCase): - - def setUp(self): - super(TestInterfacePollingMinimizer, self).setUp() - self.pm = polling.InterfacePollingMinimizer() - - def test_start_calls_monitor_start(self): - with mock.patch.object(self.pm._monitor, 'start') as mock_start: - self.pm.start() - mock_start.assert_called_with() - - def test_stop_calls_monitor_stop(self): - with mock.patch.object(self.pm._monitor, 'stop') as mock_stop: - self.pm.stop() - mock_stop.assert_called_with() - - def mock_has_updates(self, return_value): - target = ('neutron.agent.linux.ovsdb_monitor.SimpleInterfaceMonitor' - '.has_updates') - return mock.patch( - target, - new_callable=mock.PropertyMock(return_value=return_value), - ) - - def test__is_polling_required_returns_when_updates_are_present(self): - with self.mock_has_updates(True): - self.assertTrue(self.pm._is_polling_required()) diff --git a/neutron/tests/unit/api/__init__.py b/neutron/tests/unit/api/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/neutron/tests/unit/api/rpc/__init__.py b/neutron/tests/unit/api/rpc/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/neutron/tests/unit/api/rpc/agentnotifiers/__init__.py b/neutron/tests/unit/api/rpc/agentnotifiers/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/neutron/tests/unit/api/rpc/agentnotifiers/test_dhcp_rpc_agent_api.py b/neutron/tests/unit/api/rpc/agentnotifiers/test_dhcp_rpc_agent_api.py deleted file mode 100644 index 5d29f6cbd..000000000 --- a/neutron/tests/unit/api/rpc/agentnotifiers/test_dhcp_rpc_agent_api.py +++ /dev/null @@ -1,154 +0,0 @@ -# Copyright (c) 2013 Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import datetime -import mock - -from neutron.api.rpc.agentnotifiers import dhcp_rpc_agent_api -from neutron.common import utils -from neutron.db import agents_db -from neutron.openstack.common import timeutils -from neutron.tests import base - - -class TestDhcpAgentNotifyAPI(base.BaseTestCase): - - def setUp(self): - super(TestDhcpAgentNotifyAPI, self).setUp() - self.notifier = ( - dhcp_rpc_agent_api.DhcpAgentNotifyAPI(plugin=mock.Mock())) - - mock_util_p = mock.patch.object(utils, 'is_extension_supported') - mock_log_p = mock.patch.object(dhcp_rpc_agent_api, 'LOG') - mock_fanout_p = mock.patch.object(self.notifier, '_fanout_message') - mock_cast_p = mock.patch.object(self.notifier, '_cast_message') - self.mock_util = mock_util_p.start() - self.mock_log = mock_log_p.start() - self.mock_fanout = mock_fanout_p.start() - self.mock_cast = mock_cast_p.start() - - def _test__schedule_network(self, network, - new_agents=None, existing_agents=None, - expected_casts=0, expected_warnings=0): - self.notifier.plugin.schedule_network.return_value = new_agents - agents = self.notifier._schedule_network( - mock.ANY, network, existing_agents) - if new_agents is None: - new_agents = [] - self.assertEqual(new_agents + existing_agents, agents) - self.assertEqual(expected_casts, self.mock_cast.call_count) - self.assertEqual(expected_warnings, self.mock_log.warn.call_count) - - def test__schedule_network(self): - agent = agents_db.Agent() - agent.admin_state_up = True - agent.heartbeat_timestamp = timeutils.utcnow() - network = {'id': 'foo_net_id'} - self._test__schedule_network(network, - new_agents=[agent], existing_agents=[], - expected_casts=1, expected_warnings=0) - - def test__schedule_network_no_existing_agents(self): - agent = agents_db.Agent() - agent.admin_state_up = True - agent.heartbeat_timestamp = timeutils.utcnow() - network = {'id': 'foo_net_id'} - self._test__schedule_network(network, - new_agents=None, existing_agents=[agent], - expected_casts=0, expected_warnings=0) - - def test__schedule_network_no_new_agents(self): - network = {'id': 'foo_net_id'} - self._test__schedule_network(network, - new_agents=None, existing_agents=[], - expected_casts=0, expected_warnings=1) - - def _test__get_enabled_agents(self, network, - agents=None, port_count=0, - expected_warnings=0, expected_errors=0): - self.notifier.plugin.get_ports_count.return_value = port_count - enabled_agents = self.notifier._get_enabled_agents( - mock.ANY, network, agents, mock.ANY, mock.ANY) - self.assertEqual(agents, enabled_agents) - self.assertEqual(expected_warnings, self.mock_log.warn.call_count) - self.assertEqual(expected_errors, self.mock_log.error.call_count) - - def test__get_enabled_agents(self): - agent = agents_db.Agent() - agent.admin_state_up = True - agent.heartbeat_timestamp = timeutils.utcnow() - network = {'id': 'foo_network_id'} - self._test__get_enabled_agents(network, agents=[agent]) - - def test__get_enabled_agents_with_inactive_ones(self): - agent1 = agents_db.Agent() - agent1.admin_state_up = True - agent1.heartbeat_timestamp = timeutils.utcnow() - agent2 = agents_db.Agent() - agent2.admin_state_up = True - # This is effectively an inactive agent - agent2.heartbeat_timestamp = datetime.datetime(2000, 1, 1, 0, 0) - network = {'id': 'foo_network_id'} - self._test__get_enabled_agents(network, - agents=[agent1, agent2], - expected_warnings=1, expected_errors=0) - - def test__get_enabled_agents_with_notification_required(self): - network = {'id': 'foo_network_id', 'subnets': ['foo_subnet_id']} - self._test__get_enabled_agents(network, [], port_count=20, - expected_warnings=0, expected_errors=1) - - def test__notify_agents_fanout_required(self): - self.notifier._notify_agents(mock.ANY, - 'network_delete_end', - mock.ANY, 'foo_network_id') - self.assertEqual(1, self.mock_fanout.call_count) - - def _test__notify_agents(self, method, - expected_scheduling=0, expected_casts=0): - with mock.patch.object(self.notifier, '_schedule_network') as f: - with mock.patch.object(self.notifier, '_get_enabled_agents') as g: - agent = agents_db.Agent() - agent.admin_state_up = True - agent.heartbeat_timestamp = timeutils.utcnow() - g.return_value = [agent] - self.notifier._notify_agents(mock.Mock(), method, - mock.ANY, 'foo_network_id') - self.assertEqual(expected_scheduling, f.call_count) - self.assertEqual(expected_casts, self.mock_cast.call_count) - - def test__notify_agents_cast_required_with_scheduling(self): - self._test__notify_agents('port_create_end', - expected_scheduling=1, expected_casts=1) - - def test__notify_agents_cast_required_wo_scheduling_on_port_update(self): - self._test__notify_agents('port_update_end', - expected_scheduling=0, expected_casts=1) - - def test__notify_agents_cast_required_wo_scheduling_on_subnet_create(self): - self._test__notify_agents('subnet_create_end', - expected_scheduling=0, expected_casts=1) - - def test__notify_agents_no_action(self): - self._test__notify_agents('network_create_end', - expected_scheduling=0, expected_casts=0) - - def test__fanout_message(self): - self.notifier._fanout_message(mock.ANY, mock.ANY, mock.ANY) - self.assertEqual(1, self.mock_fanout.call_count) - - def test__cast_message(self): - self.notifier._cast_message(mock.ANY, mock.ANY, mock.ANY) - self.assertEqual(1, self.mock_cast.call_count) diff --git a/neutron/tests/unit/bigswitch/__init__.py b/neutron/tests/unit/bigswitch/__init__.py deleted file mode 100644 index 7e503debd..000000000 --- a/neutron/tests/unit/bigswitch/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2012 OpenStack Foundation. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. diff --git a/neutron/tests/unit/bigswitch/etc/restproxy.ini.test b/neutron/tests/unit/bigswitch/etc/restproxy.ini.test deleted file mode 100644 index 8df78a6eb..000000000 --- a/neutron/tests/unit/bigswitch/etc/restproxy.ini.test +++ /dev/null @@ -1,44 +0,0 @@ -# Test config file for quantum-proxy-plugin. - -[database] -# This line MUST be changed to actually run the plugin. -# Example: -# connection = mysql://root:pass@127.0.0.1:3306/restproxy_quantum -# Replace 127.0.0.1 above with the IP address of the database used by the -# main quantum server. (Leave it as is if the database runs on this host.) -connection = sqlite:// -# Database reconnection retry times - in event connectivity is lost -# set to -1 implies an infinite retry count -# max_retries = 10 -# Database reconnection interval in seconds - in event connectivity is lost -retry_interval = 2 - -[restproxy] -# All configuration for this plugin is in section '[restproxy]' -# -# The following parameters are supported: -# servers : [,]* (Error if not set) -# serverauth : (default: no auth) -# serverssl : True | False (default: False) -# -servers=localhost:9000,localhost:8899 -serverssl=False -#serverauth=username:password - -[nova] -# Specify the VIF_TYPE that will be controlled on the Nova compute instances -# options: ivs or ovs -# default: ovs -vif_type = ovs -# Overrides for vif types based on nova compute node host IDs -# Comma separated list of host IDs to fix to a specific VIF type -node_override_vif_ivs = ivshost - -[router] -# Specify the default router rules installed in newly created tenant routers -# Specify multiple times for multiple rules -# Use an * to specify default for all tenants -# Default is any any allow for all tenants -#tenant_default_router_rule=*:any:any:permit -# Maximum number of rules that a single router may have -max_router_rules=200 diff --git a/neutron/tests/unit/bigswitch/etc/ssl/ca_certs/README b/neutron/tests/unit/bigswitch/etc/ssl/ca_certs/README deleted file mode 100644 index 91779e39d..000000000 --- a/neutron/tests/unit/bigswitch/etc/ssl/ca_certs/README +++ /dev/null @@ -1,2 +0,0 @@ -ca_certs directory for SSL unit tests -No files will be generated here, but it should exist for the tests diff --git a/neutron/tests/unit/bigswitch/etc/ssl/combined/README b/neutron/tests/unit/bigswitch/etc/ssl/combined/README deleted file mode 100644 index 9f9922fd5..000000000 --- a/neutron/tests/unit/bigswitch/etc/ssl/combined/README +++ /dev/null @@ -1,2 +0,0 @@ -combined certificates directory for SSL unit tests -No files will be created here, but it should exist for the tests diff --git a/neutron/tests/unit/bigswitch/etc/ssl/host_certs/README b/neutron/tests/unit/bigswitch/etc/ssl/host_certs/README deleted file mode 100644 index 0eaec67ce..000000000 --- a/neutron/tests/unit/bigswitch/etc/ssl/host_certs/README +++ /dev/null @@ -1,2 +0,0 @@ -host_certs directory for SSL unit tests -No files will be created here, but it should exist for the tests diff --git a/neutron/tests/unit/bigswitch/fake_server.py b/neutron/tests/unit/bigswitch/fake_server.py deleted file mode 100644 index 3db3cc3ed..000000000 --- a/neutron/tests/unit/bigswitch/fake_server.py +++ /dev/null @@ -1,185 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Big Switch Networks, Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Kevin Benton, -# - -from neutron.openstack.common import jsonutils as json -from neutron.openstack.common import log as logging -from neutron.plugins.bigswitch import servermanager - -LOG = logging.getLogger(__name__) - - -class HTTPResponseMock(): - status = 200 - reason = 'OK' - - def __init__(self, sock, debuglevel=0, strict=0, method=None, - buffering=False): - pass - - def read(self): - return "{'status': '200 OK'}" - - def getheader(self, header): - return None - - -class HTTPResponseMock404(HTTPResponseMock): - status = 404 - reason = 'Not Found' - - def read(self): - return "{'status': '%s 404 Not Found'}" % servermanager.NXNETWORK - - -class HTTPResponseMock500(HTTPResponseMock): - status = 500 - reason = 'Internal Server Error' - - def __init__(self, sock, debuglevel=0, strict=0, method=None, - buffering=False, errmsg='500 Internal Server Error'): - self.errmsg = errmsg - - def read(self): - return "{'status': '%s'}" % self.errmsg - - -class HTTPConnectionMock(object): - - def __init__(self, server, port, timeout): - self.response = None - self.broken = False - # Port 9000 is the broken server - if port == 9000: - self.broken = True - errmsg = "This server is broken, please try another" - self.response = HTTPResponseMock500(None, errmsg=errmsg) - - def request(self, action, uri, body, headers): - LOG.debug(_("Request: action=%(action)s, uri=%(uri)r, " - "body=%(body)s, headers=%(headers)s"), - {'action': action, 'uri': uri, - 'body': body, 'headers': headers}) - if self.broken and "ExceptOnBadServer" in uri: - raise Exception("Broken server got an unexpected request") - if self.response: - return - - # detachment may return 404 and plugin shouldn't die - if uri.endswith('attachment') and action == 'DELETE': - self.response = HTTPResponseMock404(None) - else: - self.response = HTTPResponseMock(None) - - # Port creations/updates must contain binding information - if ('port' in uri and 'attachment' not in uri - and 'binding' not in body and action in ('POST', 'PUT')): - errmsg = "Port binding info missing in port request '%s'" % body - self.response = HTTPResponseMock500(None, errmsg=errmsg) - return - - return - - def getresponse(self): - return self.response - - def close(self): - pass - - -class HTTPConnectionMock404(HTTPConnectionMock): - - def __init__(self, server, port, timeout): - self.response = HTTPResponseMock404(None) - self.broken = True - - -class HTTPConnectionMock500(HTTPConnectionMock): - - def __init__(self, server, port, timeout): - self.response = HTTPResponseMock500(None) - self.broken = True - - -class VerifyMultiTenantFloatingIP(HTTPConnectionMock): - - def request(self, action, uri, body, headers): - # Only handle network update requests - if 'network' in uri and 'tenant' in uri and 'ports' not in uri: - req = json.loads(body) - if 'network' not in req or 'floatingips' not in req['network']: - msg = _("No floating IPs in request" - "uri=%(uri)s, body=%(body)s") % {'uri': uri, - 'body': body} - raise Exception(msg) - distinct_tenants = [] - for flip in req['network']['floatingips']: - if flip['tenant_id'] not in distinct_tenants: - distinct_tenants.append(flip['tenant_id']) - if len(distinct_tenants) < 2: - msg = _("Expected floating IPs from multiple tenants." - "uri=%(uri)s, body=%(body)s") % {'uri': uri, - 'body': body} - raise Exception(msg) - super(VerifyMultiTenantFloatingIP, - self).request(action, uri, body, headers) - - -class HTTPSMockBase(HTTPConnectionMock): - expected_cert = '' - combined_cert = None - - def __init__(self, host, port=None, key_file=None, cert_file=None, - strict=None, timeout=None, source_address=None): - self.host = host - super(HTTPSMockBase, self).__init__(host, port, timeout) - - def request(self, method, url, body=None, headers={}): - self.connect() - super(HTTPSMockBase, self).request(method, url, body, headers) - - -class HTTPSNoValidation(HTTPSMockBase): - - def connect(self): - if self.combined_cert: - raise Exception('combined_cert set on NoValidation') - - -class HTTPSCAValidation(HTTPSMockBase): - expected_cert = 'DUMMYCERTIFICATEAUTHORITY' - - def connect(self): - contents = get_cert_contents(self.combined_cert) - if self.expected_cert not in contents: - raise Exception('No dummy CA cert in cert_file') - - -class HTTPSHostValidation(HTTPSMockBase): - expected_cert = 'DUMMYCERTFORHOST%s' - - def connect(self): - contents = get_cert_contents(self.combined_cert) - expected = self.expected_cert % self.host - if expected not in contents: - raise Exception(_('No host cert for %(server)s in cert %(cert)s'), - {'server': self.host, 'cert': contents}) - - -def get_cert_contents(path): - raise Exception('METHOD MUST BE MOCKED FOR TEST') diff --git a/neutron/tests/unit/bigswitch/test_agent_scheduler.py b/neutron/tests/unit/bigswitch/test_agent_scheduler.py deleted file mode 100644 index b8d5e3aae..000000000 --- a/neutron/tests/unit/bigswitch/test_agent_scheduler.py +++ /dev/null @@ -1,33 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2013 Big Switch Networks, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -from neutron.tests.unit.bigswitch import test_base -from neutron.tests.unit.openvswitch import test_agent_scheduler - - -class BigSwitchDhcpAgentNotifierTestCase( - test_agent_scheduler.OvsDhcpAgentNotifierTestCase, - test_base.BigSwitchTestBase): - - plugin_str = ('%s.NeutronRestProxyV2' % - test_base.RESTPROXY_PKG_PATH) - - def setUp(self): - self.setup_config_files() - self.setup_patches() - super(BigSwitchDhcpAgentNotifierTestCase, self).setUp() - self.startHttpPatch() diff --git a/neutron/tests/unit/bigswitch/test_base.py b/neutron/tests/unit/bigswitch/test_base.py deleted file mode 100644 index 6fc5580eb..000000000 --- a/neutron/tests/unit/bigswitch/test_base.py +++ /dev/null @@ -1,74 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2013 Big Switch Networks, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os - -import mock -from oslo.config import cfg - -import neutron.common.test_lib as test_lib -from neutron.db import api as db -from neutron.plugins.bigswitch import config -from neutron.tests.unit.bigswitch import fake_server - -# REVISIT(kevinbenton): This needs to be imported here to create the -# portbindings table since it's not imported until function call time -# in the porttracker_db module, which will cause unit test failures when -# the unit tests are being run by testtools -from neutron.db import portbindings_db # noqa - -RESTPROXY_PKG_PATH = 'neutron.plugins.bigswitch.plugin' -NOTIFIER = 'neutron.plugins.bigswitch.plugin.AgentNotifierApi' -CERTFETCH = 'neutron.plugins.bigswitch.servermanager.ServerPool._fetch_cert' -SERVER_MANAGER = 'neutron.plugins.bigswitch.servermanager' -HTTPCON = 'neutron.plugins.bigswitch.servermanager.httplib.HTTPConnection' -SPAWN = 'neutron.plugins.bigswitch.plugin.eventlet.GreenPool.spawn_n' -CWATCH = SERVER_MANAGER + '.ServerPool._consistency_watchdog' - - -class BigSwitchTestBase(object): - - _plugin_name = ('%s.NeutronRestProxyV2' % RESTPROXY_PKG_PATH) - - def setup_config_files(self): - etc_path = os.path.join(os.path.dirname(__file__), 'etc') - test_lib.test_config['config_files'] = [os.path.join(etc_path, - 'restproxy.ini.test')] - self.addCleanup(cfg.CONF.reset) - config.register_config() - # Only try SSL on SSL tests - cfg.CONF.set_override('server_ssl', False, 'RESTPROXY') - cfg.CONF.set_override('ssl_cert_directory', - os.path.join(etc_path, 'ssl'), 'RESTPROXY') - # The mock interferes with HTTP(S) connection caching - cfg.CONF.set_override('cache_connections', False, 'RESTPROXY') - - def setup_patches(self): - self.plugin_notifier_p = mock.patch(NOTIFIER) - # prevent any greenthreads from spawning - self.spawn_p = mock.patch(SPAWN, new=lambda *args, **kwargs: None) - # prevent the consistency watchdog from starting - self.watch_p = mock.patch(CWATCH, new=lambda *args, **kwargs: None) - self.addCleanup(db.clear_db) - self.plugin_notifier_p.start() - self.spawn_p.start() - self.watch_p.start() - - def startHttpPatch(self): - self.httpPatch = mock.patch(HTTPCON, - new=fake_server.HTTPConnectionMock) - self.httpPatch.start() diff --git a/neutron/tests/unit/bigswitch/test_capabilities.py b/neutron/tests/unit/bigswitch/test_capabilities.py deleted file mode 100644 index 89e4c5b72..000000000 --- a/neutron/tests/unit/bigswitch/test_capabilities.py +++ /dev/null @@ -1,84 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2014 Big Switch Networks, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# @author Kevin Benton - -import contextlib -import mock - -from neutron.tests.unit.bigswitch import test_router_db - -PLUGIN = 'neutron.plugins.bigswitch.plugin' -SERVERMANAGER = PLUGIN + '.servermanager' -SERVERPOOL = SERVERMANAGER + '.ServerPool' -SERVERRESTCALL = SERVERMANAGER + '.ServerProxy.rest_call' -HTTPCON = SERVERMANAGER + '.httplib.HTTPConnection' - - -class CapabilitiesTests(test_router_db.RouterDBTestBase): - - def test_floating_ip_capability(self): - with contextlib.nested( - mock.patch(SERVERRESTCALL, - return_value=(200, None, '["floatingip"]', None)), - mock.patch(SERVERPOOL + '.rest_create_floatingip', - return_value=(200, None, None, None)), - mock.patch(SERVERPOOL + '.rest_delete_floatingip', - return_value=(200, None, None, None)) - ) as (mock_rest, mock_create, mock_delete): - with self.floatingip_with_assoc() as fip: - pass - mock_create.assert_has_calls( - [mock.call(fip['floatingip']['tenant_id'], fip['floatingip'])] - ) - mock_delete.assert_has_calls( - [mock.call(fip['floatingip']['tenant_id'], - fip['floatingip']['id'])] - ) - - def test_floating_ip_capability_neg(self): - with contextlib.nested( - mock.patch(SERVERRESTCALL, - return_value=(200, None, '[""]', None)), - mock.patch(SERVERPOOL + '.rest_update_network', - return_value=(200, None, None, None)) - ) as (mock_rest, mock_netupdate): - with self.floatingip_with_assoc() as fip: - pass - updates = [call[0][2]['floatingips'] - for call in mock_netupdate.call_args_list] - all_floats = [f['floating_ip_address'] - for floats in updates for f in floats] - self.assertIn(fip['floatingip']['floating_ip_address'], all_floats) - - def test_keep_alive_capability(self): - with mock.patch( - SERVERRESTCALL, return_value=(200, None, '["keep-alive"]', None) - ): - # perform a task to cause capabilities to be retrieved - with self.floatingip_with_assoc(): - pass - # stop default HTTP patch since we need a magicmock - self.httpPatch.stop() - # now mock HTTP class instead of REST so we can see headers - conmock = mock.patch(HTTPCON).start() - instance = conmock.return_value - instance.getresponse.return_value.getheader.return_value = 'HASHHEADER' - with self.network(): - callheaders = instance.request.mock_calls[0][1][3] - self.assertIn('Connection', callheaders) - self.assertEqual(callheaders['Connection'], 'keep-alive') diff --git a/neutron/tests/unit/bigswitch/test_restproxy_agent.py b/neutron/tests/unit/bigswitch/test_restproxy_agent.py deleted file mode 100644 index 4c961df7d..000000000 --- a/neutron/tests/unit/bigswitch/test_restproxy_agent.py +++ /dev/null @@ -1,188 +0,0 @@ -# Copyright 2014 Big Switch Networks, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Kevin Benton, Big Switch Networks - -import contextlib - -import mock - -from neutron.openstack.common import importutils -from neutron.tests import base - -OVSBRIDGE = 'neutron.agent.linux.ovs_lib.OVSBridge' -PLUGINAPI = 'neutron.plugins.bigswitch.agent.restproxy_agent.PluginApi' -CONTEXT = 'neutron.context' -CONSUMERCREATE = 'neutron.agent.rpc.create_consumers' -SGRPC = 'neutron.agent.securitygroups_rpc' -SGAGENT = 'neutron.plugins.bigswitch.agent.restproxy_agent.SecurityGroupAgent' -AGENTMOD = 'neutron.plugins.bigswitch.agent.restproxy_agent' -NEUTRONCFG = 'neutron.common.config' -PLCONFIG = 'neutron.plugins.bigswitch.config' - - -class BaseAgentTestCase(base.BaseTestCase): - - def setUp(self): - super(BaseAgentTestCase, self).setUp() - self.mod_agent = importutils.import_module(AGENTMOD) - - -class TestRestProxyAgentOVS(BaseAgentTestCase): - def setUp(self): - super(TestRestProxyAgentOVS, self).setUp() - self.plapi = mock.patch(PLUGINAPI).start() - self.ovsbridge = mock.patch(OVSBRIDGE).start() - self.context = mock.patch(CONTEXT).start() - self.rpc = mock.patch(CONSUMERCREATE).start() - self.sg_rpc = mock.patch(SGRPC).start() - self.sg_agent = mock.patch(SGAGENT).start() - - def mock_agent(self): - mock_context = mock.Mock(return_value='abc') - self.context.get_admin_context_without_session = mock_context - return self.mod_agent.RestProxyAgent('int-br', 2, 'helper') - - def mock_port_update(self, **kwargs): - agent = self.mock_agent() - agent.port_update(mock.Mock(), **kwargs) - - def test_port_update(self): - port = {'id': 1, 'security_groups': 'default'} - - with mock.patch.object(self.ovsbridge.return_value, - 'get_vif_port_by_id', - return_value=1) as get_vif: - self.mock_port_update(port=port) - - get_vif.assert_called_once_with(1) - self.sg_agent.assert_has_calls([ - mock.call().refresh_firewall() - ]) - - def test_port_update_not_vifport(self): - port = {'id': 1, 'security_groups': 'default'} - - with mock.patch.object(self.ovsbridge.return_value, - 'get_vif_port_by_id', - return_value=0) as get_vif: - self.mock_port_update(port=port) - - get_vif.assert_called_once_with(1) - self.assertFalse(self.sg_agent.return_value.refresh_firewall.called) - - def test_port_update_without_secgroup(self): - port = {'id': 1} - - with mock.patch.object(self.ovsbridge.return_value, - 'get_vif_port_by_id', - return_value=1) as get_vif: - self.mock_port_update(port=port) - - get_vif.assert_called_once_with(1) - self.assertFalse(self.sg_agent.return_value.refresh_firewall.called) - - def mock_update_ports(self, vif_port_set=None, registered_ports=None): - with mock.patch.object(self.ovsbridge.return_value, - 'get_vif_port_set', - return_value=vif_port_set): - agent = self.mock_agent() - return agent._update_ports(registered_ports) - - def test_update_ports_unchanged(self): - self.assertIsNone(self.mock_update_ports()) - - def test_update_ports_changed(self): - vif_port_set = set([1, 3]) - registered_ports = set([1, 2]) - expected = dict(current=vif_port_set, - added=set([3]), - removed=set([2])) - - actual = self.mock_update_ports(vif_port_set, registered_ports) - - self.assertEqual(expected, actual) - - def mock_process_devices_filter(self, port_info): - agent = self.mock_agent() - agent._process_devices_filter(port_info) - - def test_process_devices_filter_add(self): - port_info = {'added': 1} - - self.mock_process_devices_filter(port_info) - - self.sg_agent.assert_has_calls([ - mock.call().prepare_devices_filter(1) - ]) - - def test_process_devices_filter_remove(self): - port_info = {'removed': 2} - - self.mock_process_devices_filter(port_info) - - self.sg_agent.assert_has_calls([ - mock.call().remove_devices_filter(2) - ]) - - def test_process_devices_filter_both(self): - port_info = {'added': 1, 'removed': 2} - - self.mock_process_devices_filter(port_info) - - self.sg_agent.assert_has_calls([ - mock.call().prepare_devices_filter(1), - mock.call().remove_devices_filter(2) - ]) - - def test_process_devices_filter_none(self): - port_info = {} - - self.mock_process_devices_filter(port_info) - - self.assertFalse( - self.sg_agent.return_value.prepare_devices_filter.called) - self.assertFalse( - self.sg_agent.return_value.remove_devices_filter.called) - - -class TestRestProxyAgent(BaseAgentTestCase): - def mock_main(self): - cfg_attrs = {'CONF.RESTPROXYAGENT.integration_bridge': 'integ_br', - 'CONF.RESTPROXYAGENT.polling_interval': 5, - 'CONF.RESTPROXYAGENT.virtual_switch_type': 'ovs', - 'CONF.AGENT.root_helper': 'helper'} - with contextlib.nested( - mock.patch(AGENTMOD + '.cfg', **cfg_attrs), - mock.patch(AGENTMOD + '.config.init'), - mock.patch(NEUTRONCFG), - mock.patch(PLCONFIG), - ) as (mock_conf, mock_init, mock_log_conf, mock_pluginconf): - self.mod_agent.main() - - mock_log_conf.assert_has_calls([ - mock.call(mock_conf), - ]) - - def test_main(self): - agent_attrs = {'daemon_loop.side_effect': SystemExit(0)} - with mock.patch(AGENTMOD + '.RestProxyAgent', - **agent_attrs) as mock_agent: - self.assertRaises(SystemExit, self.mock_main) - - mock_agent.assert_has_calls([ - mock.call('integ_br', 5, 'helper', 'ovs'), - mock.call().daemon_loop() - ]) diff --git a/neutron/tests/unit/bigswitch/test_restproxy_plugin.py b/neutron/tests/unit/bigswitch/test_restproxy_plugin.py deleted file mode 100644 index df3aeb030..000000000 --- a/neutron/tests/unit/bigswitch/test_restproxy_plugin.py +++ /dev/null @@ -1,316 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2012 Big Switch Networks, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import contextlib -import mock -from oslo.config import cfg -import webob.exc - -from neutron.common import constants -from neutron import context -from neutron.extensions import portbindings -from neutron import manager -from neutron.tests.unit import _test_extension_portbindings as test_bindings -from neutron.tests.unit.bigswitch import fake_server -from neutron.tests.unit.bigswitch import test_base -from neutron.tests.unit import test_api_v2 -import neutron.tests.unit.test_db_plugin as test_plugin -import neutron.tests.unit.test_extension_allowedaddresspairs as test_addr_pair - -patch = mock.patch -HTTPCON = 'neutron.plugins.bigswitch.servermanager.httplib.HTTPConnection' - - -class BigSwitchProxyPluginV2TestCase(test_base.BigSwitchTestBase, - test_plugin.NeutronDbPluginV2TestCase): - - def setUp(self, plugin_name=None): - if hasattr(self, 'HAS_PORT_FILTER'): - cfg.CONF.set_override( - 'enable_security_group', self.HAS_PORT_FILTER, 'SECURITYGROUP') - self.setup_config_files() - self.setup_patches() - if plugin_name: - self._plugin_name = plugin_name - super(BigSwitchProxyPluginV2TestCase, - self).setUp(self._plugin_name) - self.port_create_status = 'BUILD' - self.startHttpPatch() - - -class TestBigSwitchProxyBasicGet(test_plugin.TestBasicGet, - BigSwitchProxyPluginV2TestCase): - - pass - - -class TestBigSwitchProxyV2HTTPResponse(test_plugin.TestV2HTTPResponse, - BigSwitchProxyPluginV2TestCase): - - def test_failover_memory(self): - # first request causes failover so next shouldn't hit bad server - with self.network() as net: - kwargs = {'tenant_id': 'ExceptOnBadServer'} - with self.network(**kwargs) as net: - req = self.new_show_request('networks', net['network']['id']) - res = req.get_response(self.api) - self.assertEqual(res.status_int, 200) - - -class TestBigSwitchProxyPortsV2(test_plugin.TestPortsV2, - BigSwitchProxyPluginV2TestCase, - test_bindings.PortBindingsTestCase): - - VIF_TYPE = portbindings.VIF_TYPE_OVS - HAS_PORT_FILTER = False - - def setUp(self, plugin_name=None): - super(TestBigSwitchProxyPortsV2, - self).setUp(self._plugin_name) - - def test_router_port_status_active(self): - # router ports screw up port auto-deletion so it has to be - # disabled for this test - with self.network(do_delete=False) as net: - with self.subnet(network=net, do_delete=False) as sub: - with self.port( - subnet=sub, - no_delete=True, - device_owner=constants.DEVICE_OWNER_ROUTER_INTF - ) as port: - # router ports should be immediately active - self.assertEqual(port['port']['status'], 'ACTIVE') - - def test_update_port_status_build(self): - # normal ports go into the pending build state for async creation - with self.port() as port: - self.assertEqual(port['port']['status'], 'BUILD') - self.assertEqual(self.port_create_status, 'BUILD') - - def _get_ports(self, netid): - return self.deserialize('json', - self._list_ports('json', netid=netid))['ports'] - - def test_rollback_for_port_create(self): - plugin = manager.NeutronManager.get_plugin() - with self.subnet() as s: - # stop normal patch - self.httpPatch.stop() - # allow thread spawns for this test - self.spawn_p.stop() - kwargs = {'device_id': 'somedevid'} - # put in a broken 'server' - httpPatch = patch(HTTPCON, new=fake_server.HTTPConnectionMock500) - httpPatch.start() - with self.port(subnet=s, **kwargs): - # wait for async port create request to finish - plugin.evpool.waitall() - # put good 'server' back in - httpPatch.stop() - self.httpPatch.start() - ports = self._get_ports(s['subnet']['network_id']) - #failure to create should result in port in error state - self.assertEqual(ports[0]['status'], 'ERROR') - - def test_rollback_for_port_update(self): - with self.network() as n: - with self.port(network_id=n['network']['id'], - device_id='66') as port: - port = self._get_ports(n['network']['id'])[0] - data = {'port': {'name': 'aNewName', 'device_id': '99'}} - # stop normal patch - self.httpPatch.stop() - with patch(HTTPCON, new=fake_server.HTTPConnectionMock500): - self.new_update_request( - 'ports', data, port['id']).get_response(self.api) - self.httpPatch.start() - uport = self._get_ports(n['network']['id'])[0] - # name should have stayed the same - self.assertEqual(port['name'], uport['name']) - - def test_rollback_for_port_delete(self): - with self.network() as n: - with self.port(network_id=n['network']['id'], - device_id='somedevid') as port: - # stop normal patch - self.httpPatch.stop() - with patch(HTTPCON, new=fake_server.HTTPConnectionMock500): - self._delete('ports', port['port']['id'], - expected_code= - webob.exc.HTTPInternalServerError.code) - self.httpPatch.start() - port = self._get_ports(n['network']['id'])[0] - self.assertEqual('BUILD', port['status']) - - def test_correct_shared_net_tenant_id(self): - # tenant_id in port requests should match network tenant_id instead - # of port tenant_id - def rest_port_op(self, ten_id, netid, port): - if ten_id != 'SHARED': - raise Exception('expecting tenant_id SHARED. got %s' % ten_id) - with self.network(tenant_id='SHARED', shared=True) as net: - with self.subnet(network=net) as sub: - pref = 'neutron.plugins.bigswitch.servermanager.ServerPool.%s' - tomock = [pref % 'rest_create_port', - pref % 'rest_update_port', - pref % 'rest_delete_port'] - patches = [patch(f, create=True, new=rest_port_op) - for f in tomock] - for restp in patches: - restp.start() - with self.port(subnet=sub, tenant_id='port-owner') as port: - data = {'port': {'binding:host_id': 'someotherhost', - 'device_id': 'override_dev'}} - req = self.new_update_request('ports', data, - port['port']['id']) - res = req.get_response(self.api) - self.assertEqual(res.status_int, 200) - - def test_create404_triggers_sync(self): - # allow async port thread for this patch - self.spawn_p.stop() - with contextlib.nested( - self.subnet(), - patch(HTTPCON, create=True, - new=fake_server.HTTPConnectionMock404), - patch(test_base.RESTPROXY_PKG_PATH - + '.NeutronRestProxyV2._send_all_data') - ) as (s, mock_http, mock_send_all): - with self.port(subnet=s, device_id='somedevid') as p: - # wait for the async port thread to finish - plugin = manager.NeutronManager.get_plugin() - plugin.evpool.waitall() - call = mock.call( - send_routers=True, send_ports=True, send_floating_ips=True, - triggered_by_tenant=p['port']['tenant_id'] - ) - mock_send_all.assert_has_calls([call]) - self.spawn_p.start() - - def test_port_vif_details_default(self): - kwargs = {'name': 'name', 'device_id': 'override_dev'} - with self.port(**kwargs) as port: - self.assertEqual(port['port']['binding:vif_type'], - portbindings.VIF_TYPE_OVS) - - def test_port_vif_details_override(self): - # ivshost is in the test config to override to IVS - kwargs = {'name': 'name', 'binding:host_id': 'ivshost', - 'device_id': 'override_dev'} - with self.port(**kwargs) as port: - self.assertEqual(port['port']['binding:vif_type'], - portbindings.VIF_TYPE_IVS) - kwargs = {'name': 'name2', 'binding:host_id': 'someotherhost', - 'device_id': 'other_dev'} - with self.port(**kwargs) as port: - self.assertEqual(port['port']['binding:vif_type'], self.VIF_TYPE) - - def test_port_move(self): - # ivshost is in the test config to override to IVS - kwargs = {'name': 'name', 'binding:host_id': 'ivshost', - 'device_id': 'override_dev'} - with self.port(**kwargs) as port: - data = {'port': {'binding:host_id': 'someotherhost', - 'device_id': 'override_dev'}} - req = self.new_update_request('ports', data, port['port']['id']) - res = self.deserialize(self.fmt, req.get_response(self.api)) - self.assertEqual(res['port']['binding:vif_type'], self.VIF_TYPE) - - def _make_port(self, fmt, net_id, expected_res_status=None, arg_list=None, - **kwargs): - arg_list = arg_list or () - arg_list += ('binding:host_id', ) - res = self._create_port(fmt, net_id, expected_res_status, - arg_list, **kwargs) - # Things can go wrong - raise HTTP exc with res code only - # so it can be caught by unit tests - if res.status_int >= 400: - raise webob.exc.HTTPClientError(code=res.status_int) - return self.deserialize(fmt, res) - - -class TestVifDifferentDefault(BigSwitchProxyPluginV2TestCase): - - def setup_config_files(self): - super(TestVifDifferentDefault, self).setup_config_files() - cfg.CONF.set_override('vif_type', 'ivs', 'NOVA') - - def test_default_viftype(self): - with self.port() as port: - self.assertEqual(port['port']['binding:vif_type'], 'ivs') - - -class TestBigSwitchProxyNetworksV2(test_plugin.TestNetworksV2, - BigSwitchProxyPluginV2TestCase): - - def _get_networks(self, tenant_id): - ctx = context.Context('', tenant_id) - return manager.NeutronManager.get_plugin().get_networks(ctx) - - def test_rollback_on_network_create(self): - tid = test_api_v2._uuid() - kwargs = {'tenant_id': tid} - self.httpPatch.stop() - with patch(HTTPCON, new=fake_server.HTTPConnectionMock500): - self._create_network('json', 'netname', True, **kwargs) - self.httpPatch.start() - self.assertFalse(self._get_networks(tid)) - - def test_rollback_on_network_update(self): - with self.network() as n: - data = {'network': {'name': 'aNewName'}} - self.httpPatch.stop() - with patch(HTTPCON, new=fake_server.HTTPConnectionMock500): - self.new_update_request( - 'networks', data, n['network']['id'] - ).get_response(self.api) - self.httpPatch.start() - updatedn = self._get_networks(n['network']['tenant_id'])[0] - # name should have stayed the same due to failure - self.assertEqual(n['network']['name'], updatedn['name']) - - def test_rollback_on_network_delete(self): - with self.network() as n: - self.httpPatch.stop() - with patch(HTTPCON, new=fake_server.HTTPConnectionMock500): - self._delete( - 'networks', n['network']['id'], - expected_code=webob.exc.HTTPInternalServerError.code) - self.httpPatch.start() - # network should still exist in db - self.assertEqual(n['network']['id'], - self._get_networks(n['network']['tenant_id'] - )[0]['id']) - - -class TestBigSwitchProxySubnetsV2(test_plugin.TestSubnetsV2, - BigSwitchProxyPluginV2TestCase): - - pass - - -class TestBigSwitchProxySync(BigSwitchProxyPluginV2TestCase): - - def test_send_data(self): - plugin_obj = manager.NeutronManager.get_plugin() - result = plugin_obj._send_all_data() - self.assertEqual(result[0], 200) - - -class TestBigSwitchAddressPairs(BigSwitchProxyPluginV2TestCase, - test_addr_pair.TestAllowedAddressPairs): - pass diff --git a/neutron/tests/unit/bigswitch/test_router_db.py b/neutron/tests/unit/bigswitch/test_router_db.py deleted file mode 100644 index fc82b727c..000000000 --- a/neutron/tests/unit/bigswitch/test_router_db.py +++ /dev/null @@ -1,554 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Big Switch Networks, Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# Adapted from neutron.tests.unit.test_l3_plugin -# @author: Sumit Naiksatam, sumitnaiksatam@gmail.com -# - -import contextlib -import copy - -import mock -from oslo.config import cfg -from six import moves -from webob import exc - -from neutron.common import test_lib -from neutron import context -from neutron.extensions import l3 -from neutron import manager -from neutron.openstack.common import uuidutils -from neutron.plugins.bigswitch.extensions import routerrule -from neutron.tests.unit.bigswitch import fake_server -from neutron.tests.unit.bigswitch import test_base -from neutron.tests.unit import test_api_v2 -from neutron.tests.unit import test_extension_extradhcpopts as test_extradhcp -from neutron.tests.unit import test_l3_plugin - - -HTTPCON = 'neutron.plugins.bigswitch.servermanager.httplib.HTTPConnection' -_uuid = uuidutils.generate_uuid - - -class RouterRulesTestExtensionManager(object): - - def get_resources(self): - l3.RESOURCE_ATTRIBUTE_MAP['routers'].update( - routerrule.EXTENDED_ATTRIBUTES_2_0['routers']) - return l3.L3.get_resources() - - def get_actions(self): - return [] - - def get_request_extensions(self): - return [] - - -class DHCPOptsTestCase(test_base.BigSwitchTestBase, - test_extradhcp.TestExtraDhcpOpt): - - def setUp(self, plugin=None): - self.setup_patches() - self.setup_config_files() - super(test_extradhcp.ExtraDhcpOptDBTestCase, - self).setUp(plugin=self._plugin_name) - self.startHttpPatch() - - -class RouterDBTestBase(test_base.BigSwitchTestBase, - test_l3_plugin.L3BaseForIntTests, - test_l3_plugin.L3NatTestCaseMixin): - - def setUp(self): - self.setup_patches() - self.setup_config_files() - ext_mgr = RouterRulesTestExtensionManager() - super(RouterDBTestBase, self).setUp(plugin=self._plugin_name, - ext_mgr=ext_mgr) - cfg.CONF.set_default('allow_overlapping_ips', False) - self.plugin_obj = manager.NeutronManager.get_plugin() - self.startHttpPatch() - - def tearDown(self): - super(RouterDBTestBase, self).tearDown() - del test_lib.test_config['config_files'] - - -class RouterDBTestCase(RouterDBTestBase, - test_l3_plugin.L3NatDBIntTestCase): - - def test_router_remove_router_interface_wrong_subnet_returns_400(self): - with self.router() as r: - with self.subnet() as s: - with self.subnet(cidr='10.0.10.0/24') as s1: - with self.port(subnet=s1, no_delete=True) as p: - self._router_interface_action('add', - r['router']['id'], - None, - p['port']['id']) - self._router_interface_action('remove', - r['router']['id'], - s['subnet']['id'], - p['port']['id'], - exc.HTTPBadRequest.code) - #remove properly to clean-up - self._router_interface_action('remove', - r['router']['id'], - None, - p['port']['id']) - - def test_router_remove_router_interface_wrong_port_returns_404(self): - with self.router() as r: - with self.subnet() as s: - with self.port(subnet=s, no_delete=True) as p: - self._router_interface_action('add', - r['router']['id'], - None, - p['port']['id']) - # create another port for testing failure case - res = self._create_port('json', p['port']['network_id']) - p2 = self.deserialize('json', res) - self._router_interface_action('remove', - r['router']['id'], - None, - p2['port']['id'], - exc.HTTPNotFound.code) - # remove correct interface to cleanup - self._router_interface_action('remove', - r['router']['id'], - None, - p['port']['id']) - # remove extra port created - self._delete('ports', p2['port']['id']) - - def test_multi_tenant_flip_alllocation(self): - tenant1_id = _uuid() - tenant2_id = _uuid() - with contextlib.nested( - self.network(tenant_id=tenant1_id), - self.network(tenant_id=tenant2_id)) as (n1, n2): - with contextlib.nested( - self.subnet(network=n1, cidr='11.0.0.0/24'), - self.subnet(network=n2, cidr='12.0.0.0/24'), - self.subnet(cidr='13.0.0.0/24')) as (s1, s2, psub): - with contextlib.nested( - self.router(tenant_id=tenant1_id), - self.router(tenant_id=tenant2_id), - self.port(subnet=s1, tenant_id=tenant1_id), - self.port(subnet=s2, tenant_id=tenant2_id)) as (r1, r2, - p1, p2): - self._set_net_external(psub['subnet']['network_id']) - s1id = p1['port']['fixed_ips'][0]['subnet_id'] - s2id = p2['port']['fixed_ips'][0]['subnet_id'] - s1 = {'subnet': {'id': s1id}} - s2 = {'subnet': {'id': s2id}} - self._add_external_gateway_to_router( - r1['router']['id'], - psub['subnet']['network_id']) - self._add_external_gateway_to_router( - r2['router']['id'], - psub['subnet']['network_id']) - self._router_interface_action( - 'add', r1['router']['id'], - s1['subnet']['id'], None) - self._router_interface_action( - 'add', r2['router']['id'], - s2['subnet']['id'], None) - fl1 = self._make_floatingip_for_tenant_port( - net_id=psub['subnet']['network_id'], - port_id=p1['port']['id'], - tenant_id=tenant1_id) - self.httpPatch.stop() - multiFloatPatch = mock.patch( - HTTPCON, - new=fake_server.VerifyMultiTenantFloatingIP) - multiFloatPatch.start() - fl2 = self._make_floatingip_for_tenant_port( - net_id=psub['subnet']['network_id'], - port_id=p2['port']['id'], - tenant_id=tenant2_id) - multiFloatPatch.stop() - self.httpPatch.start() - self._delete('floatingips', fl1['floatingip']['id']) - self._delete('floatingips', fl2['floatingip']['id']) - self._router_interface_action( - 'remove', r1['router']['id'], - s1['subnet']['id'], None) - self._router_interface_action( - 'remove', r2['router']['id'], - s2['subnet']['id'], None) - - def _make_floatingip_for_tenant_port(self, net_id, port_id, tenant_id): - data = {'floatingip': {'floating_network_id': net_id, - 'tenant_id': tenant_id, - 'port_id': port_id}} - floatingip_req = self.new_create_request('floatingips', data, self.fmt) - res = floatingip_req.get_response(self.ext_api) - return self.deserialize(self.fmt, res) - - def test_floatingip_with_invalid_create_port(self): - self._test_floatingip_with_invalid_create_port( - 'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2') - - def test_create_floatingip_no_ext_gateway_return_404(self): - with self.subnet(cidr='10.0.10.0/24') as public_sub: - self._set_net_external(public_sub['subnet']['network_id']) - with self.port() as private_port: - with self.router(): - res = self._create_floatingip( - 'json', - public_sub['subnet']['network_id'], - port_id=private_port['port']['id']) - self.assertEqual(res.status_int, exc.HTTPNotFound.code) - - def test_router_update_gateway(self): - with self.router() as r: - with self.subnet() as s1: - with self.subnet(cidr='10.0.10.0/24') as s2: - self._set_net_external(s1['subnet']['network_id']) - self._add_external_gateway_to_router( - r['router']['id'], - s1['subnet']['network_id']) - body = self._show('routers', r['router']['id']) - net_id = (body['router'] - ['external_gateway_info']['network_id']) - self.assertEqual(net_id, s1['subnet']['network_id']) - self._set_net_external(s2['subnet']['network_id']) - self._add_external_gateway_to_router( - r['router']['id'], - s2['subnet']['network_id']) - body = self._show('routers', r['router']['id']) - net_id = (body['router'] - ['external_gateway_info']['network_id']) - self.assertEqual(net_id, s2['subnet']['network_id']) - self._remove_external_gateway_from_router( - r['router']['id'], - s2['subnet']['network_id']) - - def test_router_add_interface_overlapped_cidr(self): - self.skipTest("Plugin does not support") - - def test_router_add_interface_overlapped_cidr_returns_400(self): - self.skipTest("Plugin does not support") - - def test_list_nets_external(self): - self.skipTest("Plugin does not support") - - def test_router_update_gateway_with_existed_floatingip(self): - with self.subnet(cidr='10.0.10.0/24') as subnet: - self._set_net_external(subnet['subnet']['network_id']) - with self.floatingip_with_assoc() as fip: - self._add_external_gateway_to_router( - fip['floatingip']['router_id'], - subnet['subnet']['network_id'], - expected_code=exc.HTTPConflict.code) - - def test_router_remove_interface_wrong_subnet_returns_400(self): - with self.router() as r: - with self.subnet(cidr='10.0.10.0/24') as s: - with self.port(no_delete=True) as p: - self._router_interface_action('add', - r['router']['id'], - None, - p['port']['id']) - self._router_interface_action('remove', - r['router']['id'], - s['subnet']['id'], - p['port']['id'], - exc.HTTPBadRequest.code) - #remove properly to clean-up - self._router_interface_action('remove', - r['router']['id'], - None, - p['port']['id']) - - def test_router_remove_interface_wrong_port_returns_404(self): - with self.router() as r: - with self.subnet(cidr='10.0.10.0/24'): - with self.port(no_delete=True) as p: - self._router_interface_action('add', - r['router']['id'], - None, - p['port']['id']) - # create another port for testing failure case - res = self._create_port('json', p['port']['network_id']) - p2 = self.deserialize('json', res) - self._router_interface_action('remove', - r['router']['id'], - None, - p2['port']['id'], - exc.HTTPNotFound.code) - # remove correct interface to cleanup - self._router_interface_action('remove', - r['router']['id'], - None, - p['port']['id']) - # remove extra port created - self._delete('ports', p2['port']['id']) - - def test_send_data(self): - fmt = 'json' - plugin_obj = manager.NeutronManager.get_plugin() - - with self.router() as r: - r_id = r['router']['id'] - - with self.subnet(cidr='10.0.10.0/24') as s: - s_id = s['subnet']['id'] - - with self.router() as r1: - r1_id = r1['router']['id'] - body = self._router_interface_action('add', r_id, s_id, - None) - self.assertIn('port_id', body) - r_port_id = body['port_id'] - body = self._show('ports', r_port_id) - self.assertEqual(body['port']['device_id'], r_id) - - with self.subnet(cidr='10.0.20.0/24') as s1: - s1_id = s1['subnet']['id'] - body = self._router_interface_action('add', r1_id, - s1_id, None) - self.assertIn('port_id', body) - r1_port_id = body['port_id'] - body = self._show('ports', r1_port_id) - self.assertEqual(body['port']['device_id'], r1_id) - - with self.subnet(cidr='11.0.0.0/24') as public_sub: - public_net_id = public_sub['subnet']['network_id'] - self._set_net_external(public_net_id) - - with self.port() as prv_port: - prv_fixed_ip = prv_port['port']['fixed_ips'][0] - priv_sub_id = prv_fixed_ip['subnet_id'] - self._add_external_gateway_to_router( - r_id, public_net_id) - self._router_interface_action('add', r_id, - priv_sub_id, - None) - - priv_port_id = prv_port['port']['id'] - res = self._create_floatingip( - fmt, public_net_id, - port_id=priv_port_id) - self.assertEqual(res.status_int, - exc.HTTPCreated.code) - floatingip = self.deserialize(fmt, res) - - result = plugin_obj._send_all_data() - self.assertEqual(result[0], 200) - - self._delete('floatingips', - floatingip['floatingip']['id']) - self._remove_external_gateway_from_router( - r_id, public_net_id) - self._router_interface_action('remove', r_id, - priv_sub_id, - None) - self._router_interface_action('remove', r_id, s_id, - None) - self._show('ports', r_port_id, - expected_code=exc.HTTPNotFound.code) - self._router_interface_action('remove', r1_id, s1_id, - None) - self._show('ports', r1_port_id, - expected_code=exc.HTTPNotFound.code) - - def test_router_rules_update(self): - with self.router() as r: - r_id = r['router']['id'] - router_rules = [{'destination': '1.2.3.4/32', - 'source': '4.3.2.1/32', - 'action': 'permit', - 'nexthops': ['4.4.4.4', '4.4.4.5']}] - body = self._update('routers', r_id, - {'router': {'router_rules': router_rules}}) - - body = self._show('routers', r['router']['id']) - self.assertIn('router_rules', body['router']) - rules = body['router']['router_rules'] - self.assertEqual(_strip_rule_ids(rules), router_rules) - # Try after adding another rule - router_rules.append({'source': 'external', - 'destination': '8.8.8.8/32', - 'action': 'permit', 'nexthops': []}) - body = self._update('routers', r['router']['id'], - {'router': {'router_rules': router_rules}}) - - body = self._show('routers', r['router']['id']) - self.assertIn('router_rules', body['router']) - rules = body['router']['router_rules'] - self.assertEqual(_strip_rule_ids(rules), router_rules) - - def test_router_rules_separation(self): - with self.router() as r1: - with self.router() as r2: - r1_id = r1['router']['id'] - r2_id = r2['router']['id'] - router1_rules = [{'destination': '5.6.7.8/32', - 'source': '8.7.6.5/32', - 'action': 'permit', - 'nexthops': ['8.8.8.8', '9.9.9.9']}] - router2_rules = [{'destination': '1.2.3.4/32', - 'source': '4.3.2.1/32', - 'action': 'permit', - 'nexthops': ['4.4.4.4', '4.4.4.5']}] - body1 = self._update('routers', r1_id, - {'router': - {'router_rules': router1_rules}}) - body2 = self._update('routers', r2_id, - {'router': - {'router_rules': router2_rules}}) - - body1 = self._show('routers', r1_id) - body2 = self._show('routers', r2_id) - rules1 = body1['router']['router_rules'] - rules2 = body2['router']['router_rules'] - self.assertEqual(_strip_rule_ids(rules1), router1_rules) - self.assertEqual(_strip_rule_ids(rules2), router2_rules) - - def test_router_rules_validation(self): - with self.router() as r: - r_id = r['router']['id'] - good_rules = [{'destination': '1.2.3.4/32', - 'source': '4.3.2.1/32', - 'action': 'permit', - 'nexthops': ['4.4.4.4', '4.4.4.5']}] - - body = self._update('routers', r_id, - {'router': {'router_rules': good_rules}}) - body = self._show('routers', r_id) - self.assertIn('router_rules', body['router']) - self.assertEqual(good_rules, - _strip_rule_ids(body['router']['router_rules'])) - - # Missing nexthops should be populated with an empty list - light_rules = copy.deepcopy(good_rules) - del light_rules[0]['nexthops'] - body = self._update('routers', r_id, - {'router': {'router_rules': light_rules}}) - body = self._show('routers', r_id) - self.assertIn('router_rules', body['router']) - light_rules[0]['nexthops'] = [] - self.assertEqual(light_rules, - _strip_rule_ids(body['router']['router_rules'])) - # bad CIDR - bad_rules = copy.deepcopy(good_rules) - bad_rules[0]['destination'] = '1.1.1.1' - body = self._update('routers', r_id, - {'router': {'router_rules': bad_rules}}, - expected_code=exc.HTTPBadRequest.code) - # bad next hop - bad_rules = copy.deepcopy(good_rules) - bad_rules[0]['nexthops'] = ['1.1.1.1', 'f2'] - body = self._update('routers', r_id, - {'router': {'router_rules': bad_rules}}, - expected_code=exc.HTTPBadRequest.code) - # bad action - bad_rules = copy.deepcopy(good_rules) - bad_rules[0]['action'] = 'dance' - body = self._update('routers', r_id, - {'router': {'router_rules': bad_rules}}, - expected_code=exc.HTTPBadRequest.code) - # duplicate rule with opposite action - bad_rules = copy.deepcopy(good_rules) - bad_rules.append(copy.deepcopy(bad_rules[0])) - bad_rules.append(copy.deepcopy(bad_rules[0])) - bad_rules[1]['source'] = 'any' - bad_rules[2]['action'] = 'deny' - body = self._update('routers', r_id, - {'router': {'router_rules': bad_rules}}, - expected_code=exc.HTTPBadRequest.code) - # duplicate nexthop - bad_rules = copy.deepcopy(good_rules) - bad_rules[0]['nexthops'] = ['1.1.1.1', '1.1.1.1'] - body = self._update('routers', r_id, - {'router': {'router_rules': bad_rules}}, - expected_code=exc.HTTPBadRequest.code) - # make sure light rules persisted during bad updates - body = self._show('routers', r_id) - self.assertIn('router_rules', body['router']) - self.assertEqual(light_rules, - _strip_rule_ids(body['router']['router_rules'])) - - def test_router_rules_config_change(self): - cfg.CONF.set_override('tenant_default_router_rule', - ['*:any:any:deny', - '*:8.8.8.8/32:any:permit:1.2.3.4'], - 'ROUTER') - with self.router() as r: - body = self._show('routers', r['router']['id']) - expected_rules = [{'source': 'any', 'destination': 'any', - 'nexthops': [], 'action': 'deny'}, - {'source': '8.8.8.8/32', 'destination': 'any', - 'nexthops': ['1.2.3.4'], 'action': 'permit'}] - self.assertEqual(expected_rules, - _strip_rule_ids(body['router']['router_rules'])) - - def test_rule_exhaustion(self): - cfg.CONF.set_override('max_router_rules', 10, 'ROUTER') - with self.router() as r: - rules = [] - for i in moves.xrange(1, 12): - rule = {'source': 'any', 'nexthops': [], - 'destination': '1.1.1.' + str(i) + '/32', - 'action': 'permit'} - rules.append(rule) - self._update('routers', r['router']['id'], - {'router': {'router_rules': rules}}, - expected_code=exc.HTTPBadRequest.code) - - def test_rollback_on_router_create(self): - tid = test_api_v2._uuid() - self.httpPatch.stop() - with mock.patch(HTTPCON, new=fake_server.HTTPConnectionMock500): - self._create_router('json', tid) - self.assertTrue(len(self._get_routers(tid)) == 0) - - def test_rollback_on_router_update(self): - with self.router() as r: - data = {'router': {'name': 'aNewName'}} - self.httpPatch.stop() - with mock.patch(HTTPCON, new=fake_server.HTTPConnectionMock500): - self.new_update_request( - 'routers', data, r['router']['id']).get_response(self.api) - self.httpPatch.start() - updatedr = self._get_routers(r['router']['tenant_id'])[0] - # name should have stayed the same due to failure - self.assertEqual(r['router']['name'], updatedr['name']) - - def test_rollback_on_router_delete(self): - with self.router() as r: - self.httpPatch.stop() - with mock.patch(HTTPCON, new=fake_server.HTTPConnectionMock500): - self._delete('routers', r['router']['id'], - expected_code=exc.HTTPInternalServerError.code) - self.httpPatch.start() - self.assertEqual(r['router']['id'], - self._get_routers(r['router']['tenant_id'] - )[0]['id']) - - def _get_routers(self, tenant_id): - ctx = context.Context('', tenant_id) - return self.plugin_obj.get_routers(ctx) - - -def _strip_rule_ids(rules): - cleaned = [] - for rule in rules: - del rule['id'] - cleaned.append(rule) - return cleaned diff --git a/neutron/tests/unit/bigswitch/test_security_groups.py b/neutron/tests/unit/bigswitch/test_security_groups.py deleted file mode 100644 index 1e3a7aa56..000000000 --- a/neutron/tests/unit/bigswitch/test_security_groups.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 2014, Big Switch Networks -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron import manager -from neutron.tests.unit.bigswitch import test_base -from neutron.tests.unit import test_extension_security_group as test_sg -from neutron.tests.unit import test_security_groups_rpc as test_sg_rpc - - -class RestProxySecurityGroupsTestCase(test_sg.SecurityGroupDBTestCase, - test_base.BigSwitchTestBase): - plugin_str = ('%s.NeutronRestProxyV2' % - test_base.RESTPROXY_PKG_PATH) - - def setUp(self, plugin=None): - test_sg_rpc.set_firewall_driver(test_sg_rpc.FIREWALL_HYBRID_DRIVER) - self.setup_config_files() - self.setup_patches() - self._attribute_map_bk_ = {} - super(RestProxySecurityGroupsTestCase, self).setUp(self.plugin_str) - plugin = manager.NeutronManager.get_plugin() - self.notifier = plugin.notifier - self.rpc = plugin.endpoints[0] - self.startHttpPatch() - - -class TestSecServerRpcCallBack(test_sg_rpc.SGServerRpcCallBackMixinTestCase, - RestProxySecurityGroupsTestCase): - pass - - -class TestSecurityGroupsMixin(test_sg.TestSecurityGroups, - test_sg_rpc.SGNotificationTestMixin, - RestProxySecurityGroupsTestCase): - pass diff --git a/neutron/tests/unit/bigswitch/test_servermanager.py b/neutron/tests/unit/bigswitch/test_servermanager.py deleted file mode 100644 index 7523b9a4d..000000000 --- a/neutron/tests/unit/bigswitch/test_servermanager.py +++ /dev/null @@ -1,467 +0,0 @@ -# Copyright 2014 Big Switch Networks, Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Kevin Benton, kevin.benton@bigswitch.com -# -import contextlib -import httplib -import socket -import ssl - -import mock -from oslo.config import cfg - -from neutron import manager -from neutron.openstack.common import importutils -from neutron.plugins.bigswitch import servermanager -from neutron.tests.unit.bigswitch import test_restproxy_plugin as test_rp - -SERVERMANAGER = 'neutron.plugins.bigswitch.servermanager' -HTTPCON = SERVERMANAGER + '.httplib.HTTPConnection' -HTTPSCON = SERVERMANAGER + '.HTTPSConnectionWithValidation' - - -class ServerManagerTests(test_rp.BigSwitchProxyPluginV2TestCase): - - def setUp(self): - self.socket_mock = mock.patch( - SERVERMANAGER + '.socket.create_connection').start() - self.wrap_mock = mock.patch(SERVERMANAGER + '.ssl.wrap_socket').start() - super(ServerManagerTests, self).setUp() - # http patch must not be running or it will mangle the servermanager - # import where the https connection classes are defined - self.httpPatch.stop() - self.sm = importutils.import_module(SERVERMANAGER) - - def test_no_servers(self): - cfg.CONF.set_override('servers', [], 'RESTPROXY') - self.assertRaises(cfg.Error, servermanager.ServerPool) - - def test_malformed_servers(self): - cfg.CONF.set_override('servers', ['1.2.3.4', '1.1.1.1:a'], 'RESTPROXY') - self.assertRaises(cfg.Error, servermanager.ServerPool) - - def test_ipv6_server_address(self): - cfg.CONF.set_override( - 'servers', ['[ABCD:EF01:2345:6789:ABCD:EF01:2345:6789]:80'], - 'RESTPROXY') - s = servermanager.ServerPool() - self.assertEqual(s.servers[0].server, - '[ABCD:EF01:2345:6789:ABCD:EF01:2345:6789]') - - def test_sticky_cert_fetch_fail(self): - pl = manager.NeutronManager.get_plugin() - pl.servers.ssl = True - with mock.patch( - 'ssl.get_server_certificate', - side_effect=Exception('There is no more entropy in the universe') - ) as sslgetmock: - self.assertRaises( - cfg.Error, - pl.servers._get_combined_cert_for_server, - *('example.org', 443) - ) - sslgetmock.assert_has_calls([mock.call(('example.org', 443))]) - - def test_consistency_watchdog_stops_with_0_polling_interval(self): - pl = manager.NeutronManager.get_plugin() - pl.servers.capabilities = ['consistency'] - self.watch_p.stop() - with mock.patch('eventlet.sleep') as smock: - # should return immediately a polling interval of 0 - pl.servers._consistency_watchdog(0) - self.assertFalse(smock.called) - - def test_consistency_watchdog(self): - pl = manager.NeutronManager.get_plugin() - pl.servers.capabilities = [] - self.watch_p.stop() - with contextlib.nested( - mock.patch('eventlet.sleep'), - mock.patch( - SERVERMANAGER + '.ServerPool.rest_call', - side_effect=servermanager.RemoteRestError( - reason='Failure to trigger except clause.' - ) - ), - mock.patch( - SERVERMANAGER + '.LOG.exception', - side_effect=KeyError('Failure to break loop') - ) - ) as (smock, rmock, lmock): - # should return immediately without consistency capability - pl.servers._consistency_watchdog() - self.assertFalse(smock.called) - pl.servers.capabilities = ['consistency'] - self.assertRaises(KeyError, - pl.servers._consistency_watchdog) - rmock.assert_called_with('GET', '/health', '', {}, [], False) - self.assertEqual(1, len(lmock.mock_calls)) - - def test_consistency_hash_header(self): - # mock HTTP class instead of rest_call so we can see headers - with mock.patch(HTTPCON) as conmock: - rv = conmock.return_value - rv.getresponse.return_value.getheader.return_value = 'HASHHEADER' - with self.network(): - callheaders = rv.request.mock_calls[0][1][3] - self.assertIn('X-BSN-BVS-HASH-MATCH', callheaders) - # first call will be empty to indicate no previous state hash - self.assertEqual(callheaders['X-BSN-BVS-HASH-MATCH'], '') - # change the header that will be received on delete call - rv.getresponse.return_value.getheader.return_value = 'HASH2' - - # net delete should have used header received on create - callheaders = rv.request.mock_calls[1][1][3] - self.assertEqual(callheaders['X-BSN-BVS-HASH-MATCH'], 'HASHHEADER') - - # create again should now use header received from prev delete - with self.network(): - callheaders = rv.request.mock_calls[2][1][3] - self.assertIn('X-BSN-BVS-HASH-MATCH', callheaders) - self.assertEqual(callheaders['X-BSN-BVS-HASH-MATCH'], - 'HASH2') - - def test_file_put_contents(self): - pl = manager.NeutronManager.get_plugin() - with mock.patch(SERVERMANAGER + '.open', create=True) as omock: - pl.servers._file_put_contents('somepath', 'contents') - omock.assert_has_calls([mock.call('somepath', 'w')]) - omock.return_value.__enter__.return_value.assert_has_calls([ - mock.call.write('contents') - ]) - - def test_combine_certs_to_file(self): - pl = manager.NeutronManager.get_plugin() - with mock.patch(SERVERMANAGER + '.open', create=True) as omock: - omock.return_value.__enter__().read.return_value = 'certdata' - pl.servers._combine_certs_to_file(['cert1.pem', 'cert2.pem'], - 'combined.pem') - # mock shared between read and write file handles so the calls - # are mixed together - omock.assert_has_calls([ - mock.call('combined.pem', 'w'), - mock.call('cert1.pem', 'r'), - mock.call('cert2.pem', 'r'), - ], any_order=True) - omock.return_value.__enter__.return_value.assert_has_calls([ - mock.call.read(), - mock.call.write('certdata'), - mock.call.read(), - mock.call.write('certdata') - ]) - - def test_auth_header(self): - cfg.CONF.set_override('server_auth', 'username:pass', 'RESTPROXY') - sp = servermanager.ServerPool() - with mock.patch(HTTPCON) as conmock: - rv = conmock.return_value - rv.getresponse.return_value.getheader.return_value = 'HASHHEADER' - sp.rest_create_network('tenant', 'network') - callheaders = rv.request.mock_calls[0][1][3] - self.assertIn('Authorization', callheaders) - self.assertEqual(callheaders['Authorization'], - 'Basic dXNlcm5hbWU6cGFzcw==') - - def test_header_add(self): - sp = servermanager.ServerPool() - with mock.patch(HTTPCON) as conmock: - rv = conmock.return_value - rv.getresponse.return_value.getheader.return_value = 'HASHHEADER' - sp.servers[0].rest_call('GET', '/', headers={'EXTRA-HEADER': 'HI'}) - callheaders = rv.request.mock_calls[0][1][3] - # verify normal headers weren't mangled - self.assertIn('Content-type', callheaders) - self.assertEqual(callheaders['Content-type'], - 'application/json') - # verify new header made it in - self.assertIn('EXTRA-HEADER', callheaders) - self.assertEqual(callheaders['EXTRA-HEADER'], 'HI') - - def test_capabilities_retrieval(self): - sp = servermanager.ServerPool() - with mock.patch(HTTPCON) as conmock: - rv = conmock.return_value.getresponse.return_value - rv.getheader.return_value = 'HASHHEADER' - - # each server will get different capabilities - rv.read.side_effect = ['["a","b","c"]', '["b","c","d"]'] - # pool capabilities is intersection between both - self.assertEqual(set(['b', 'c']), sp.get_capabilities()) - self.assertEqual(2, rv.read.call_count) - - # the pool should cache after the first call so no more - # HTTP calls should be made - rv.read.side_effect = ['["w","x","y"]', '["x","y","z"]'] - self.assertEqual(set(['b', 'c']), sp.get_capabilities()) - self.assertEqual(2, rv.read.call_count) - - def test_capabilities_retrieval_failure(self): - sp = servermanager.ServerPool() - with mock.patch(HTTPCON) as conmock: - rv = conmock.return_value.getresponse.return_value - rv.getheader.return_value = 'HASHHEADER' - # a failure to parse should result in an empty capability set - rv.read.return_value = 'XXXXX' - self.assertEqual([], sp.servers[0].get_capabilities()) - - # One broken server should affect all capabilities - rv.read.side_effect = ['{"a": "b"}', '["b","c","d"]'] - self.assertEqual(set(), sp.get_capabilities()) - - def test_reconnect_on_timeout_change(self): - sp = servermanager.ServerPool() - with mock.patch(HTTPCON) as conmock: - rv = conmock.return_value - rv.getresponse.return_value.getheader.return_value = 'HASHHEADER' - sp.servers[0].capabilities = ['keep-alive'] - sp.servers[0].rest_call('GET', '/', timeout=10) - # even with keep-alive enabled, a change in timeout will trigger - # a reconnect - sp.servers[0].rest_call('GET', '/', timeout=75) - conmock.assert_has_calls([ - mock.call('localhost', 9000, timeout=10), - mock.call('localhost', 9000, timeout=75), - ], any_order=True) - - def test_connect_failures(self): - sp = servermanager.ServerPool() - with mock.patch(HTTPCON, return_value=None): - resp = sp.servers[0].rest_call('GET', '/') - self.assertEqual(resp, (0, None, None, None)) - # verify same behavior on ssl class - sp.servers[0].currentcon = False - sp.servers[0].ssl = True - with mock.patch(HTTPSCON, return_value=None): - resp = sp.servers[0].rest_call('GET', '/') - self.assertEqual(resp, (0, None, None, None)) - - def test_reconnect_cached_connection(self): - sp = servermanager.ServerPool() - with mock.patch(HTTPCON) as conmock: - rv = conmock.return_value - rv.getresponse.return_value.getheader.return_value = 'HASH' - sp.servers[0].capabilities = ['keep-alive'] - sp.servers[0].rest_call('GET', '/first') - # raise an error on re-use to verify reconnect - # return okay the second time so the reconnect works - rv.request.side_effect = [httplib.ImproperConnectionState(), - mock.MagicMock()] - sp.servers[0].rest_call('GET', '/second') - uris = [c[1][1] for c in rv.request.mock_calls] - expected = [ - sp.base_uri + '/first', - sp.base_uri + '/second', - sp.base_uri + '/second', - ] - self.assertEqual(uris, expected) - - def test_no_reconnect_recurse_to_infinity(self): - # retry uses recursion when a reconnect is necessary - # this test makes sure it stops after 1 recursive call - sp = servermanager.ServerPool() - with mock.patch(HTTPCON) as conmock: - rv = conmock.return_value - # hash header must be string instead of mock object - rv.getresponse.return_value.getheader.return_value = 'HASH' - sp.servers[0].capabilities = ['keep-alive'] - sp.servers[0].rest_call('GET', '/first') - # after retrying once, the rest call should raise the - # exception up - rv.request.side_effect = httplib.ImproperConnectionState() - self.assertRaises(httplib.ImproperConnectionState, - sp.servers[0].rest_call, - *('GET', '/second')) - # 1 for the first call, 2 for the second with retry - self.assertEqual(rv.request.call_count, 3) - - def test_socket_error(self): - sp = servermanager.ServerPool() - with mock.patch(HTTPCON) as conmock: - conmock.return_value.request.side_effect = socket.timeout() - resp = sp.servers[0].rest_call('GET', '/') - self.assertEqual(resp, (0, None, None, None)) - - def test_cert_get_fail(self): - pl = manager.NeutronManager.get_plugin() - pl.servers.ssl = True - with mock.patch('os.path.exists', return_value=False): - self.assertRaises(cfg.Error, - pl.servers._get_combined_cert_for_server, - *('example.org', 443)) - - def test_cert_make_dirs(self): - pl = manager.NeutronManager.get_plugin() - pl.servers.ssl = True - cfg.CONF.set_override('ssl_sticky', False, 'RESTPROXY') - # pretend base dir exists, 3 children don't, and host cert does - with contextlib.nested( - mock.patch('os.path.exists', side_effect=[True, False, False, - False, True]), - mock.patch('os.makedirs'), - mock.patch(SERVERMANAGER + '.ServerPool._combine_certs_to_file') - ) as (exmock, makemock, combmock): - # will raise error because no certs found - self.assertIn( - 'example.org', - pl.servers._get_combined_cert_for_server('example.org', 443) - ) - base = cfg.CONF.RESTPROXY.ssl_cert_directory - hpath = base + '/host_certs/example.org.pem' - combpath = base + '/combined/example.org.pem' - combmock.assert_has_calls([mock.call([hpath], combpath)]) - self.assertEqual(exmock.call_count, 5) - self.assertEqual(makemock.call_count, 3) - - def test_no_cert_error(self): - pl = manager.NeutronManager.get_plugin() - pl.servers.ssl = True - cfg.CONF.set_override('ssl_sticky', False, 'RESTPROXY') - # pretend base dir exists and 3 children do, but host cert doesn't - with mock.patch( - 'os.path.exists', - side_effect=[True, True, True, True, False] - ) as exmock: - # will raise error because no certs found - self.assertRaises( - cfg.Error, - pl.servers._get_combined_cert_for_server, - *('example.org', 443) - ) - self.assertEqual(exmock.call_count, 5) - - def test_action_success(self): - pl = manager.NeutronManager.get_plugin() - self.assertTrue(pl.servers.action_success((200,))) - - def test_server_failure(self): - pl = manager.NeutronManager.get_plugin() - self.assertTrue(pl.servers.server_failure((404,))) - # server failure has an ignore codes option - self.assertFalse(pl.servers.server_failure((404,), - ignore_codes=[404])) - - def test_conflict_triggers_sync(self): - pl = manager.NeutronManager.get_plugin() - with mock.patch( - SERVERMANAGER + '.ServerProxy.rest_call', - return_value=(httplib.CONFLICT, 0, 0, 0) - ) as srestmock: - # making a call should trigger a conflict sync - pl.servers.rest_call('GET', '/', '', None, []) - srestmock.assert_has_calls([ - mock.call('GET', '/', '', None, False, reconnect=True), - mock.call('PUT', '/topology', - {'routers': [], 'networks': []}, - timeout=None) - ]) - - def test_conflict_sync_raises_error_without_topology(self): - pl = manager.NeutronManager.get_plugin() - pl.servers.get_topo_function = None - with mock.patch( - SERVERMANAGER + '.ServerProxy.rest_call', - return_value=(httplib.CONFLICT, 0, 0, 0) - ): - # making a call should trigger a conflict sync that will - # error without the topology function set - self.assertRaises( - cfg.Error, - pl.servers.rest_call, - *('GET', '/', '', None, []) - ) - - def test_floating_calls(self): - pl = manager.NeutronManager.get_plugin() - with mock.patch(SERVERMANAGER + '.ServerPool.rest_action') as ramock: - pl.servers.rest_create_floatingip('tenant', {'id': 'somefloat'}) - pl.servers.rest_update_floatingip('tenant', {'name': 'myfl'}, 'id') - pl.servers.rest_delete_floatingip('tenant', 'oldid') - ramock.assert_has_calls([ - mock.call('PUT', '/tenants/tenant/floatingips/somefloat', - errstr=u'Unable to create floating IP: %s'), - mock.call('PUT', '/tenants/tenant/floatingips/id', - errstr=u'Unable to update floating IP: %s'), - mock.call('DELETE', '/tenants/tenant/floatingips/oldid', - errstr=u'Unable to delete floating IP: %s') - ]) - - def test_HTTPSConnectionWithValidation_without_cert(self): - con = self.sm.HTTPSConnectionWithValidation( - 'www.example.org', 443, timeout=90) - con.source_address = '127.0.0.1' - con.request("GET", "/") - self.socket_mock.assert_has_calls([mock.call( - ('www.example.org', 443), 90, '127.0.0.1' - )]) - self.wrap_mock.assert_has_calls([mock.call( - self.socket_mock(), None, None, cert_reqs=ssl.CERT_NONE - )]) - self.assertEqual(con.sock, self.wrap_mock()) - - def test_HTTPSConnectionWithValidation_with_cert(self): - con = self.sm.HTTPSConnectionWithValidation( - 'www.example.org', 443, timeout=90) - con.combined_cert = 'SOMECERTS.pem' - con.source_address = '127.0.0.1' - con.request("GET", "/") - self.socket_mock.assert_has_calls([mock.call( - ('www.example.org', 443), 90, '127.0.0.1' - )]) - self.wrap_mock.assert_has_calls([mock.call( - self.socket_mock(), None, None, ca_certs='SOMECERTS.pem', - cert_reqs=ssl.CERT_REQUIRED - )]) - self.assertEqual(con.sock, self.wrap_mock()) - - def test_HTTPSConnectionWithValidation_tunnel(self): - tunnel_mock = mock.patch.object( - self.sm.HTTPSConnectionWithValidation, - '_tunnel').start() - con = self.sm.HTTPSConnectionWithValidation( - 'www.example.org', 443, timeout=90) - con.source_address = '127.0.0.1' - if not hasattr(con, 'set_tunnel'): - # no tunnel support in py26 - return - con.set_tunnel('myproxy.local', 3128) - con.request("GET", "/") - self.socket_mock.assert_has_calls([mock.call( - ('www.example.org', 443), 90, '127.0.0.1' - )]) - self.wrap_mock.assert_has_calls([mock.call( - self.socket_mock(), None, None, cert_reqs=ssl.CERT_NONE - )]) - # _tunnel() doesn't take any args - tunnel_mock.assert_has_calls([mock.call()]) - self.assertEqual(con._tunnel_host, 'myproxy.local') - self.assertEqual(con._tunnel_port, 3128) - self.assertEqual(con.sock, self.wrap_mock()) - - -class TestSockets(test_rp.BigSwitchProxyPluginV2TestCase): - - def setUp(self): - super(TestSockets, self).setUp() - # http patch must not be running or it will mangle the servermanager - # import where the https connection classes are defined - self.httpPatch.stop() - self.sm = importutils.import_module(SERVERMANAGER) - - def test_socket_create_attempt(self): - # exercise the socket creation to make sure it works on both python - # versions - con = self.sm.HTTPSConnectionWithValidation('127.0.0.1', 0, timeout=1) - # if httpcon was created, a connect attempt should raise a socket error - self.assertRaises(socket.error, con.connect) diff --git a/neutron/tests/unit/bigswitch/test_ssl.py b/neutron/tests/unit/bigswitch/test_ssl.py deleted file mode 100644 index 551f9cc53..000000000 --- a/neutron/tests/unit/bigswitch/test_ssl.py +++ /dev/null @@ -1,250 +0,0 @@ -# Copyright 2014 Big Switch Networks, Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Kevin Benton, kevin.benton@bigswitch.com -# -import contextlib -import os - -import mock -from oslo.config import cfg -import webob.exc - -from neutron.openstack.common import log as logging -from neutron.tests.unit.bigswitch import fake_server -from neutron.tests.unit.bigswitch import test_base -from neutron.tests.unit import test_api_v2 -from neutron.tests.unit import test_db_plugin as test_plugin - -LOG = logging.getLogger(__name__) - -SERVERMANAGER = 'neutron.plugins.bigswitch.servermanager' -HTTPS = SERVERMANAGER + '.HTTPSConnectionWithValidation' -CERTCOMBINER = SERVERMANAGER + '.ServerPool._combine_certs_to_file' -FILEPUT = SERVERMANAGER + '.ServerPool._file_put_contents' -GETCACERTS = SERVERMANAGER + '.ServerPool._get_ca_cert_paths' -GETHOSTCERT = SERVERMANAGER + '.ServerPool._get_host_cert_path' -SSLGETCERT = SERVERMANAGER + '.ssl.get_server_certificate' -FAKECERTGET = 'neutron.tests.unit.bigswitch.fake_server.get_cert_contents' - - -class test_ssl_certificate_base(test_plugin.NeutronDbPluginV2TestCase, - test_base.BigSwitchTestBase): - - plugin_str = ('%s.NeutronRestProxyV2' % - test_base.RESTPROXY_PKG_PATH) - servername = None - cert_base = None - - def _setUp(self): - self.servername = test_api_v2._uuid() - self.cert_base = cfg.CONF.RESTPROXY.ssl_cert_directory - self.host_cert_val = 'DUMMYCERTFORHOST%s' % self.servername - self.host_cert_path = os.path.join( - self.cert_base, - 'host_certs', - '%s.pem' % self.servername - ) - self.comb_cert_path = os.path.join( - self.cert_base, - 'combined', - '%s.pem' % self.servername - ) - self.ca_certs_path = os.path.join( - self.cert_base, - 'ca_certs' - ) - cfg.CONF.set_override('servers', ["%s:443" % self.servername], - 'RESTPROXY') - self.setup_patches() - - # Mock method SSL lib uses to grab cert from server - self.sslgetcert_m = mock.patch(SSLGETCERT, create=True).start() - self.sslgetcert_m.return_value = self.host_cert_val - - # Mock methods that write and read certs from the file-system - self.fileput_m = mock.patch(FILEPUT, create=True).start() - self.certcomb_m = mock.patch(CERTCOMBINER, create=True).start() - self.getcacerts_m = mock.patch(GETCACERTS, create=True).start() - - # this is used to configure what certificate contents the fake HTTPS - # lib should expect to receive - self.fake_certget_m = mock.patch(FAKECERTGET, create=True).start() - - def setUp(self): - super(test_ssl_certificate_base, self).setUp(self.plugin_str) - - -class TestSslSticky(test_ssl_certificate_base): - - def setUp(self): - self.setup_config_files() - cfg.CONF.set_override('server_ssl', True, 'RESTPROXY') - cfg.CONF.set_override('ssl_sticky', True, 'RESTPROXY') - self._setUp() - # Set fake HTTPS connection's expectation - self.fake_certget_m.return_value = self.host_cert_val - # No CA certs for this test - self.getcacerts_m.return_value = [] - super(TestSslSticky, self).setUp() - - def test_sticky_cert(self): - # SSL connection should be successful and cert should be cached - with contextlib.nested( - mock.patch(HTTPS, new=fake_server.HTTPSHostValidation), - self.network() - ): - # CA certs should have been checked for - self.getcacerts_m.assert_has_calls([mock.call(self.ca_certs_path)]) - # cert should have been fetched via SSL lib - self.sslgetcert_m.assert_has_calls( - [mock.call((self.servername, 443))] - ) - - # cert should have been recorded - self.fileput_m.assert_has_calls([mock.call(self.host_cert_path, - self.host_cert_val)]) - # no ca certs, so host cert only for this combined cert - self.certcomb_m.assert_has_calls([mock.call([self.host_cert_path], - self.comb_cert_path)]) - - -class TestSslHostCert(test_ssl_certificate_base): - - def setUp(self): - self.setup_config_files() - cfg.CONF.set_override('server_ssl', True, 'RESTPROXY') - cfg.CONF.set_override('ssl_sticky', False, 'RESTPROXY') - self.httpsPatch = mock.patch(HTTPS, create=True, - new=fake_server.HTTPSHostValidation) - self.httpsPatch.start() - self._setUp() - # Set fake HTTPS connection's expectation - self.fake_certget_m.return_value = self.host_cert_val - # No CA certs for this test - self.getcacerts_m.return_value = [] - # Pretend host cert exists - self.hcertpath_p = mock.patch(GETHOSTCERT, - return_value=(self.host_cert_path, True), - create=True).start() - super(TestSslHostCert, self).setUp() - - def test_host_cert(self): - # SSL connection should be successful because of pre-configured cert - with self.network(): - self.hcertpath_p.assert_has_calls([ - mock.call(os.path.join(self.cert_base, 'host_certs'), - self.servername) - ]) - # sticky is disabled, no fetching allowed - self.assertFalse(self.sslgetcert_m.call_count) - # no ca certs, so host cert is only for this combined cert - self.certcomb_m.assert_has_calls([mock.call([self.host_cert_path], - self.comb_cert_path)]) - - -class TestSslCaCert(test_ssl_certificate_base): - - def setUp(self): - self.setup_config_files() - cfg.CONF.set_override('server_ssl', True, 'RESTPROXY') - cfg.CONF.set_override('ssl_sticky', False, 'RESTPROXY') - self.httpsPatch = mock.patch(HTTPS, create=True, - new=fake_server.HTTPSCAValidation) - self.httpsPatch.start() - self._setUp() - - # pretend to have a few ca certs - self.getcacerts_m.return_value = ['ca1.pem', 'ca2.pem'] - - # Set fake HTTPS connection's expectation - self.fake_certget_m.return_value = 'DUMMYCERTIFICATEAUTHORITY' - - super(TestSslCaCert, self).setUp() - - def test_ca_cert(self): - # SSL connection should be successful because CA cert was present - # If not, attempting to create a network would raise an exception - with self.network(): - # sticky is disabled, no fetching allowed - self.assertFalse(self.sslgetcert_m.call_count) - # 2 CAs and no host cert so combined should only contain both CAs - self.certcomb_m.assert_has_calls([mock.call(['ca1.pem', 'ca2.pem'], - self.comb_cert_path)]) - - -class TestSslWrongHostCert(test_ssl_certificate_base): - - def setUp(self): - self.setup_config_files() - cfg.CONF.set_override('server_ssl', True, 'RESTPROXY') - cfg.CONF.set_override('ssl_sticky', True, 'RESTPROXY') - self._setUp() - - # Set fake HTTPS connection's expectation to something wrong - self.fake_certget_m.return_value = 'OTHERCERT' - - # No CA certs for this test - self.getcacerts_m.return_value = [] - - # Pretend host cert exists - self.hcertpath_p = mock.patch(GETHOSTCERT, - return_value=(self.host_cert_path, True), - create=True).start() - super(TestSslWrongHostCert, self).setUp() - - def test_error_no_cert(self): - # since there will already be a host cert, sticky should not take - # effect and there will be an error because the host cert's contents - # will be incorrect - tid = test_api_v2._uuid() - data = {} - data['network'] = {'tenant_id': tid, 'name': 'name', - 'admin_state_up': True} - with mock.patch(HTTPS, new=fake_server.HTTPSHostValidation): - req = self.new_create_request('networks', data, 'json') - res = req.get_response(self.api) - self.assertEqual(res.status_int, - webob.exc.HTTPInternalServerError.code) - self.hcertpath_p.assert_has_calls([ - mock.call(os.path.join(self.cert_base, 'host_certs'), - self.servername) - ]) - # sticky is enabled, but a host cert already exists so it shant fetch - self.assertFalse(self.sslgetcert_m.call_count) - # no ca certs, so host cert only for this combined cert - self.certcomb_m.assert_has_calls([mock.call([self.host_cert_path], - self.comb_cert_path)]) - - -class TestSslNoValidation(test_ssl_certificate_base): - - def setUp(self): - self.setup_config_files() - cfg.CONF.set_override('server_ssl', True, 'RESTPROXY') - cfg.CONF.set_override('ssl_sticky', False, 'RESTPROXY') - cfg.CONF.set_override('no_ssl_validation', True, 'RESTPROXY') - self._setUp() - super(TestSslNoValidation, self).setUp() - - def test_validation_disabled(self): - # SSL connection should be successful without any certificates - # If not, attempting to create a network will raise an exception - with contextlib.nested( - mock.patch(HTTPS, new=fake_server.HTTPSNoValidation), - self.network() - ): - # no sticky grabbing and no cert combining with no enforcement - self.assertFalse(self.sslgetcert_m.call_count) - self.assertFalse(self.certcomb_m.call_count) diff --git a/neutron/tests/unit/brocade/__init__.py b/neutron/tests/unit/brocade/__init__.py deleted file mode 100644 index d1af8c59e..000000000 --- a/neutron/tests/unit/brocade/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 OpenStack Foundation. -# -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. diff --git a/neutron/tests/unit/brocade/test_brocade_db.py b/neutron/tests/unit/brocade/test_brocade_db.py deleted file mode 100644 index 127b516be..000000000 --- a/neutron/tests/unit/brocade/test_brocade_db.py +++ /dev/null @@ -1,100 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright (c) 2013 OpenStack Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -""" -Unit test brocade db. -""" -import uuid - -from neutron import context -from neutron.plugins.brocade.db import models as brocade_db -from neutron.tests.unit import test_db_plugin as test_plugin - -TEST_VLAN = 1000 - - -class TestBrocadeDb(test_plugin.NeutronDbPluginV2TestCase): - """Test brocade db functionality.""" - - def test_create_network(self): - """Test brocade specific network db.""" - - net_id = str(uuid.uuid4()) - - # Create a network - self.context = context.get_admin_context() - brocade_db.create_network(self.context, net_id, TEST_VLAN) - - # Get the network and verify - net = brocade_db.get_network(self.context, net_id) - self.assertEqual(net['id'], net_id) - self.assertEqual(int(net['vlan']), TEST_VLAN) - - # Delete the network - brocade_db.delete_network(self.context, net['id']) - self.assertFalse(brocade_db.get_networks(self.context)) - - def test_create_port(self): - """Test brocade specific port db.""" - - net_id = str(uuid.uuid4()) - port_id = str(uuid.uuid4()) - # port_id is truncated: since the linux-bridge tap device names are - # based on truncated port id, this enables port lookups using - # tap devices - port_id = port_id[0:11] - tenant_id = str(uuid.uuid4()) - admin_state_up = True - - # Create Port - - # To create a port a network must exists, Create a network - self.context = context.get_admin_context() - brocade_db.create_network(self.context, net_id, TEST_VLAN) - - physical_interface = "em1" - brocade_db.create_port(self.context, port_id, net_id, - physical_interface, - TEST_VLAN, tenant_id, admin_state_up) - - port = brocade_db.get_port(self.context, port_id) - self.assertEqual(port['port_id'], port_id) - self.assertEqual(port['network_id'], net_id) - self.assertEqual(port['physical_interface'], physical_interface) - self.assertEqual(int(port['vlan_id']), TEST_VLAN) - self.assertEqual(port['tenant_id'], tenant_id) - self.assertEqual(port['admin_state_up'], admin_state_up) - - admin_state_up = True - brocade_db.update_port_state(self.context, port_id, admin_state_up) - port = brocade_db.get_port(self.context, port_id) - self.assertEqual(port['admin_state_up'], admin_state_up) - - admin_state_up = False - brocade_db.update_port_state(self.context, port_id, admin_state_up) - port = brocade_db.get_port(self.context, port_id) - self.assertEqual(port['admin_state_up'], admin_state_up) - - admin_state_up = True - brocade_db.update_port_state(self.context, port_id, admin_state_up) - port = brocade_db.get_port(self.context, port_id) - self.assertEqual(port['admin_state_up'], admin_state_up) - - # Delete Port - brocade_db.delete_port(self.context, port_id) - self.assertFalse(brocade_db.get_ports(self.context)) diff --git a/neutron/tests/unit/brocade/test_brocade_plugin.py b/neutron/tests/unit/brocade/test_brocade_plugin.py deleted file mode 100644 index 0e3a6ef69..000000000 --- a/neutron/tests/unit/brocade/test_brocade_plugin.py +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright (c) 2012 OpenStack Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import mock - -from neutron.extensions import portbindings -from neutron.openstack.common import importutils -from neutron.plugins.brocade import NeutronPlugin as brocade_plugin -from neutron.tests.unit import _test_extension_portbindings as test_bindings -from neutron.tests.unit import test_db_plugin as test_plugin - - -PLUGIN_NAME = ('neutron.plugins.brocade.' - 'NeutronPlugin.BrocadePluginV2') -NOS_DRIVER = ('neutron.plugins.brocade.' - 'nos.fake_nosdriver.NOSdriver') -FAKE_IPADDRESS = '2.2.2.2' -FAKE_USERNAME = 'user' -FAKE_PASSWORD = 'password' -FAKE_PHYSICAL_INTERFACE = 'em1' - - -class BrocadePluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase): - _plugin_name = PLUGIN_NAME - - def setUp(self): - - def mocked_brocade_init(self): - - self._switch = {'address': FAKE_IPADDRESS, - 'username': FAKE_USERNAME, - 'password': FAKE_PASSWORD - } - self._driver = importutils.import_object(NOS_DRIVER) - - with mock.patch.object(brocade_plugin.BrocadePluginV2, - 'brocade_init', new=mocked_brocade_init): - super(BrocadePluginV2TestCase, self).setUp(self._plugin_name) - - -class TestBrocadeBasicGet(test_plugin.TestBasicGet, - BrocadePluginV2TestCase): - pass - - -class TestBrocadeV2HTTPResponse(test_plugin.TestV2HTTPResponse, - BrocadePluginV2TestCase): - pass - - -class TestBrocadePortsV2(test_plugin.TestPortsV2, - BrocadePluginV2TestCase, - test_bindings.PortBindingsTestCase): - - VIF_TYPE = portbindings.VIF_TYPE_BRIDGE - HAS_PORT_FILTER = True - - -class TestBrocadeNetworksV2(test_plugin.TestNetworksV2, - BrocadePluginV2TestCase): - pass diff --git a/neutron/tests/unit/brocade/test_brocade_vlan.py b/neutron/tests/unit/brocade/test_brocade_vlan.py deleted file mode 100644 index b5a0c33f6..000000000 --- a/neutron/tests/unit/brocade/test_brocade_vlan.py +++ /dev/null @@ -1,73 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright (c) 2013 OpenStack Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -""" -Test vlans alloc/dealloc. -""" - -from neutron.db import api as db -from neutron.openstack.common import context -from neutron.plugins.brocade import vlanbm as vlan_bitmap -from neutron.tests import base - - -class TestVlanBitmap(base.BaseTestCase): - """exercise Vlan bitmap .""" - - def setUp(self): - super(TestVlanBitmap, self).setUp() - db.configure_db() - self.addCleanup(db.clear_db) - self.context = context.get_admin_context() - self.context.session = db.get_session() - - def test_vlan(self): - """test vlan allocation/de-alloc.""" - - self.vbm_ = vlan_bitmap.VlanBitmap(self.context) - vlan_id = self.vbm_.get_next_vlan(None) - - # First vlan is always 2 - self.assertEqual(vlan_id, 2) - - # next vlan is always 3 - vlan_id = self.vbm_.get_next_vlan(None) - self.assertEqual(vlan_id, 3) - - # get a specific vlan i.e. 4 - vlan_id = self.vbm_.get_next_vlan(4) - self.assertEqual(vlan_id, 4) - - # get a specific vlan i.e. 5 - vlan_id = self.vbm_.get_next_vlan(5) - self.assertEqual(vlan_id, 5) - - # Skip 6 - - # get a specific vlan i.e. 7 - vlan_id = self.vbm_.get_next_vlan(7) - self.assertEqual(vlan_id, 7) - - # get a specific vlan i.e. 1900 - vlan_id = self.vbm_.get_next_vlan(1900) - self.assertEqual(vlan_id, 1900) - - # Release 4 and get next again - self.vbm_.release_vlan(4) - vlan_id = self.vbm_.get_next_vlan(None) - self.assertEqual(vlan_id, 4) diff --git a/neutron/tests/unit/cisco/__init__.py b/neutron/tests/unit/cisco/__init__.py deleted file mode 100644 index 7e503debd..000000000 --- a/neutron/tests/unit/cisco/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2012 OpenStack Foundation. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. diff --git a/neutron/tests/unit/cisco/n1kv/__init__.py b/neutron/tests/unit/cisco/n1kv/__init__.py deleted file mode 100644 index 59a411933..000000000 --- a/neutron/tests/unit/cisco/n1kv/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Cisco Systems, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Abhishek Raut, Cisco Systems, Inc. -# diff --git a/neutron/tests/unit/cisco/n1kv/fake_client.py b/neutron/tests/unit/cisco/n1kv/fake_client.py deleted file mode 100755 index 2d1f0780e..000000000 --- a/neutron/tests/unit/cisco/n1kv/fake_client.py +++ /dev/null @@ -1,119 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2014 Cisco Systems, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Abhishek Raut, Cisco Systems Inc. -# @author: Sourabh Patwardhan, Cisco Systems Inc. - -from neutron.openstack.common import log as logging -from neutron.plugins.cisco.common import cisco_exceptions as c_exc -from neutron.plugins.cisco.n1kv import n1kv_client - -LOG = logging.getLogger(__name__) - -_resource_metadata = {'port': ['id', 'macAddress', 'ipAddress', 'subnetId'], - 'vmnetwork': ['name', 'networkSegmentId', - 'networkSegment', 'portProfile', - 'portProfileId', 'tenantId', - 'portId', 'macAddress', - 'ipAddress', 'subnetId']} - - -class TestClient(n1kv_client.Client): - - def __init__(self, **kwargs): - self.broken = False - self.inject_params = False - self.total_profiles = 2 - super(TestClient, self).__init__() - - def _get_total_profiles(self): - return self.total_profiles - - def _do_request(self, method, action, body=None, headers=None): - if self.broken: - raise c_exc.VSMError(reason='VSM:Internal Server Error') - if self.inject_params and body: - body['invalidKey'] = 'catchMeIfYouCan' - if method == 'POST': - return _validate_resource(action, body) - elif method == 'GET': - if 'virtual-port-profile' in action: - return _policy_profile_generator( - self._get_total_profiles()) - else: - raise c_exc.VSMError(reason='VSM:Internal Server Error') - - -class TestClientInvalidRequest(TestClient): - - def __init__(self, **kwargs): - super(TestClientInvalidRequest, self).__init__() - self.inject_params = True - - -def _validate_resource(action, body=None): - if body: - body_set = set(body.keys()) - else: - return - if 'vm-network' in action and 'port' not in action: - vmnetwork_set = set(_resource_metadata['vmnetwork']) - if body_set - vmnetwork_set: - raise c_exc.VSMError(reason='Invalid Request') - elif 'port' in action: - port_set = set(_resource_metadata['port']) - if body_set - port_set: - raise c_exc.VSMError(reason='Invalid Request') - else: - return - - -def _policy_profile_generator(total_profiles): - """ - Generate policy profile response and return a dictionary. - - :param total_profiles: integer representing total number of profiles to - return - """ - profiles = {} - for num in range(1, total_profiles + 1): - name = "pp-%s" % num - profile_id = "00000000-0000-0000-0000-00000000000%s" % num - profiles[name] = {"properties": {"name": name, "id": profile_id}} - return profiles - - -def _policy_profile_generator_xml(total_profiles): - """ - Generate policy profile response in XML format. - - :param total_profiles: integer representing total number of profiles to - return - """ - xml = [""" - """] - template = ( - '' - '' - '00000000-0000-0000-0000-00000000000%(num)s' - 'pp-%(num)s' - '' - '' - ) - xml.extend(template % {'num': n} for n in range(1, total_profiles + 1)) - xml.append("") - return ''.join(xml) diff --git a/neutron/tests/unit/cisco/n1kv/test_n1kv_db.py b/neutron/tests/unit/cisco/n1kv/test_n1kv_db.py deleted file mode 100644 index e806944e0..000000000 --- a/neutron/tests/unit/cisco/n1kv/test_n1kv_db.py +++ /dev/null @@ -1,870 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Cisco Systems, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Juergen Brendel, Cisco Systems Inc. -# @author: Abhishek Raut, Cisco Systems Inc. -# @author: Rudrajit Tapadar, Cisco Systems Inc. - -from six import moves -from sqlalchemy.orm import exc as s_exc -from testtools import matchers - -from neutron.common import exceptions as n_exc -from neutron import context -from neutron.db import api as db -from neutron.db import db_base_plugin_v2 -from neutron.plugins.cisco.common import cisco_constants -from neutron.plugins.cisco.common import cisco_exceptions as c_exc -from neutron.plugins.cisco.db import n1kv_db_v2 -from neutron.plugins.cisco.db import n1kv_models_v2 -from neutron.tests import base -from neutron.tests.unit import test_db_plugin as test_plugin - - -PHYS_NET = 'physnet1' -PHYS_NET_2 = 'physnet2' -VLAN_MIN = 10 -VLAN_MAX = 19 -VXLAN_MIN = 5000 -VXLAN_MAX = 5009 -SEGMENT_RANGE = '200-220' -SEGMENT_RANGE_MIN_OVERLAP = '210-230' -SEGMENT_RANGE_MAX_OVERLAP = '190-209' -SEGMENT_RANGE_OVERLAP = '190-230' -TEST_NETWORK_ID = 'abcdefghijklmnopqrstuvwxyz' -TEST_NETWORK_ID2 = 'abcdefghijklmnopqrstuvwxy2' -TEST_NETWORK_ID3 = 'abcdefghijklmnopqrstuvwxy3' -TEST_NETWORK_PROFILE = {'name': 'test_profile', - 'segment_type': 'vlan', - 'physical_network': 'physnet1', - 'segment_range': '10-19'} -TEST_NETWORK_PROFILE_2 = {'name': 'test_profile_2', - 'segment_type': 'vlan', - 'physical_network': 'physnet1', - 'segment_range': SEGMENT_RANGE} -TEST_NETWORK_PROFILE_VXLAN = {'name': 'test_profile', - 'segment_type': 'overlay', - 'sub_type': 'native_vxlan', - 'segment_range': '5000-5009', - 'multicast_ip_range': '239.0.0.70-239.0.0.80'} -TEST_POLICY_PROFILE = {'id': '4a417990-76fb-11e2-bcfd-0800200c9a66', - 'name': 'test_policy_profile'} -TEST_NETWORK_PROFILE_MULTI_SEGMENT = {'name': 'test_profile', - 'segment_type': 'multi-segment'} -TEST_NETWORK_PROFILE_VLAN_TRUNK = {'name': 'test_profile', - 'segment_type': 'trunk', - 'sub_type': 'vlan'} -TEST_NETWORK_PROFILE_VXLAN_TRUNK = {'name': 'test_profile', - 'segment_type': 'trunk', - 'sub_type': 'overlay'} - - -def _create_test_network_profile_if_not_there(session, - profile=TEST_NETWORK_PROFILE): - try: - _profile = session.query(n1kv_models_v2.NetworkProfile).filter_by( - name=profile['name']).one() - except s_exc.NoResultFound: - _profile = n1kv_db_v2.create_network_profile(session, profile) - return _profile - - -def _create_test_policy_profile_if_not_there(session, - profile=TEST_POLICY_PROFILE): - try: - _profile = session.query(n1kv_models_v2.PolicyProfile).filter_by( - name=profile['name']).one() - except s_exc.NoResultFound: - _profile = n1kv_db_v2.create_policy_profile(profile) - return _profile - - -class VlanAllocationsTest(base.BaseTestCase): - - def setUp(self): - super(VlanAllocationsTest, self).setUp() - db.configure_db() - self.session = db.get_session() - self.net_p = _create_test_network_profile_if_not_there(self.session) - n1kv_db_v2.sync_vlan_allocations(self.session, self.net_p) - self.addCleanup(db.clear_db) - - def test_sync_vlan_allocations_outside_segment_range(self): - self.assertRaises(c_exc.VlanIDNotFound, - n1kv_db_v2.get_vlan_allocation, - self.session, - PHYS_NET, - VLAN_MIN - 1) - self.assertRaises(c_exc.VlanIDNotFound, - n1kv_db_v2.get_vlan_allocation, - self.session, - PHYS_NET, - VLAN_MAX + 1) - self.assertRaises(c_exc.VlanIDNotFound, - n1kv_db_v2.get_vlan_allocation, - self.session, - PHYS_NET_2, - VLAN_MIN + 20) - self.assertRaises(c_exc.VlanIDNotFound, - n1kv_db_v2.get_vlan_allocation, - self.session, - PHYS_NET_2, - VLAN_MIN + 20) - self.assertRaises(c_exc.VlanIDNotFound, - n1kv_db_v2.get_vlan_allocation, - self.session, - PHYS_NET_2, - VLAN_MAX + 20) - - def test_sync_vlan_allocations_unallocated_vlans(self): - self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, - PHYS_NET, - VLAN_MIN).allocated) - self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, - PHYS_NET, - VLAN_MIN + 1). - allocated) - self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, - PHYS_NET, - VLAN_MAX - 1). - allocated) - self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, - PHYS_NET, - VLAN_MAX).allocated) - - def test_vlan_pool(self): - vlan_ids = set() - for x in moves.xrange(VLAN_MIN, VLAN_MAX + 1): - (physical_network, seg_type, - vlan_id, m_ip) = n1kv_db_v2.reserve_vlan(self.session, self.net_p) - self.assertEqual(physical_network, PHYS_NET) - self.assertThat(vlan_id, matchers.GreaterThan(VLAN_MIN - 1)) - self.assertThat(vlan_id, matchers.LessThan(VLAN_MAX + 1)) - vlan_ids.add(vlan_id) - - self.assertRaises(n_exc.NoNetworkAvailable, - n1kv_db_v2.reserve_vlan, - self.session, - self.net_p) - - n1kv_db_v2.release_vlan(self.session, PHYS_NET, vlan_ids.pop()) - physical_network, seg_type, vlan_id, m_ip = (n1kv_db_v2.reserve_vlan( - self.session, self.net_p)) - self.assertEqual(physical_network, PHYS_NET) - self.assertThat(vlan_id, matchers.GreaterThan(VLAN_MIN - 1)) - self.assertThat(vlan_id, matchers.LessThan(VLAN_MAX + 1)) - vlan_ids.add(vlan_id) - - for vlan_id in vlan_ids: - n1kv_db_v2.release_vlan(self.session, PHYS_NET, vlan_id) - - def test_specific_vlan_inside_pool(self): - vlan_id = VLAN_MIN + 5 - self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, - PHYS_NET, - vlan_id).allocated) - n1kv_db_v2.reserve_specific_vlan(self.session, PHYS_NET, vlan_id) - self.assertTrue(n1kv_db_v2.get_vlan_allocation(self.session, - PHYS_NET, - vlan_id).allocated) - - self.assertRaises(n_exc.VlanIdInUse, - n1kv_db_v2.reserve_specific_vlan, - self.session, - PHYS_NET, - vlan_id) - - n1kv_db_v2.release_vlan(self.session, PHYS_NET, vlan_id) - self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, - PHYS_NET, - vlan_id).allocated) - - def test_specific_vlan_outside_pool(self): - vlan_id = VLAN_MAX + 5 - self.assertRaises(c_exc.VlanIDNotFound, - n1kv_db_v2.get_vlan_allocation, - self.session, - PHYS_NET, - vlan_id) - self.assertRaises(c_exc.VlanIDOutsidePool, - n1kv_db_v2.reserve_specific_vlan, - self.session, - PHYS_NET, - vlan_id) - - -class VxlanAllocationsTest(base.BaseTestCase, - n1kv_db_v2.NetworkProfile_db_mixin): - - def setUp(self): - super(VxlanAllocationsTest, self).setUp() - db.configure_db() - self.session = db.get_session() - self.net_p = _create_test_network_profile_if_not_there( - self.session, TEST_NETWORK_PROFILE_VXLAN) - n1kv_db_v2.sync_vxlan_allocations(self.session, self.net_p) - self.addCleanup(db.clear_db) - - def test_sync_vxlan_allocations_outside_segment_range(self): - self.assertRaises(c_exc.VxlanIDNotFound, - n1kv_db_v2.get_vxlan_allocation, - self.session, - VXLAN_MIN - 1) - self.assertRaises(c_exc.VxlanIDNotFound, - n1kv_db_v2.get_vxlan_allocation, - self.session, - VXLAN_MAX + 1) - - def test_sync_vxlan_allocations_unallocated_vxlans(self): - self.assertFalse(n1kv_db_v2.get_vxlan_allocation(self.session, - VXLAN_MIN).allocated) - self.assertFalse(n1kv_db_v2.get_vxlan_allocation(self.session, - VXLAN_MIN + 1). - allocated) - self.assertFalse(n1kv_db_v2.get_vxlan_allocation(self.session, - VXLAN_MAX - 1). - allocated) - self.assertFalse(n1kv_db_v2.get_vxlan_allocation(self.session, - VXLAN_MAX).allocated) - - def test_vxlan_pool(self): - vxlan_ids = set() - for x in moves.xrange(VXLAN_MIN, VXLAN_MAX + 1): - vxlan = n1kv_db_v2.reserve_vxlan(self.session, self.net_p) - vxlan_id = vxlan[2] - self.assertThat(vxlan_id, matchers.GreaterThan(VXLAN_MIN - 1)) - self.assertThat(vxlan_id, matchers.LessThan(VXLAN_MAX + 1)) - vxlan_ids.add(vxlan_id) - - self.assertRaises(n_exc.NoNetworkAvailable, - n1kv_db_v2.reserve_vxlan, - self.session, - self.net_p) - n1kv_db_v2.release_vxlan(self.session, vxlan_ids.pop()) - vxlan = n1kv_db_v2.reserve_vxlan(self.session, self.net_p) - vxlan_id = vxlan[2] - self.assertThat(vxlan_id, matchers.GreaterThan(VXLAN_MIN - 1)) - self.assertThat(vxlan_id, matchers.LessThan(VXLAN_MAX + 1)) - vxlan_ids.add(vxlan_id) - - for vxlan_id in vxlan_ids: - n1kv_db_v2.release_vxlan(self.session, vxlan_id) - n1kv_db_v2.delete_network_profile(self.session, self.net_p.id) - - def test_specific_vxlan_inside_pool(self): - vxlan_id = VXLAN_MIN + 5 - self.assertFalse(n1kv_db_v2.get_vxlan_allocation(self.session, - vxlan_id).allocated) - n1kv_db_v2.reserve_specific_vxlan(self.session, vxlan_id) - self.assertTrue(n1kv_db_v2.get_vxlan_allocation(self.session, - vxlan_id).allocated) - - self.assertRaises(c_exc.VxlanIDInUse, - n1kv_db_v2.reserve_specific_vxlan, - self.session, - vxlan_id) - - n1kv_db_v2.release_vxlan(self.session, vxlan_id) - self.assertFalse(n1kv_db_v2.get_vxlan_allocation(self.session, - vxlan_id).allocated) - - def test_specific_vxlan_outside_pool(self): - vxlan_id = VXLAN_MAX + 5 - self.assertRaises(c_exc.VxlanIDNotFound, - n1kv_db_v2.get_vxlan_allocation, - self.session, - vxlan_id) - self.assertRaises(c_exc.VxlanIDOutsidePool, - n1kv_db_v2.reserve_specific_vxlan, - self.session, - vxlan_id) - - -class NetworkBindingsTest(test_plugin.NeutronDbPluginV2TestCase): - - def setUp(self): - super(NetworkBindingsTest, self).setUp() - db.configure_db() - self.session = db.get_session() - self.addCleanup(db.clear_db) - - def test_add_network_binding(self): - with self.network() as network: - TEST_NETWORK_ID = network['network']['id'] - - self.assertRaises(c_exc.NetworkBindingNotFound, - n1kv_db_v2.get_network_binding, - self.session, - TEST_NETWORK_ID) - - p = _create_test_network_profile_if_not_there(self.session) - n1kv_db_v2.add_network_binding( - self.session, TEST_NETWORK_ID, 'vlan', - PHYS_NET, 1234, '0.0.0.0', p.id, None) - binding = n1kv_db_v2.get_network_binding( - self.session, TEST_NETWORK_ID) - self.assertIsNotNone(binding) - self.assertEqual(binding.network_id, TEST_NETWORK_ID) - self.assertEqual(binding.network_type, 'vlan') - self.assertEqual(binding.physical_network, PHYS_NET) - self.assertEqual(binding.segmentation_id, 1234) - - def test_create_multi_segment_network(self): - with self.network() as network: - TEST_NETWORK_ID = network['network']['id'] - - self.assertRaises(c_exc.NetworkBindingNotFound, - n1kv_db_v2.get_network_binding, - self.session, - TEST_NETWORK_ID) - - p = _create_test_network_profile_if_not_there( - self.session, - TEST_NETWORK_PROFILE_MULTI_SEGMENT) - n1kv_db_v2.add_network_binding( - self.session, TEST_NETWORK_ID, 'multi-segment', - None, 0, '0.0.0.0', p.id, None) - binding = n1kv_db_v2.get_network_binding( - self.session, TEST_NETWORK_ID) - self.assertIsNotNone(binding) - self.assertEqual(binding.network_id, TEST_NETWORK_ID) - self.assertEqual(binding.network_type, 'multi-segment') - self.assertIsNone(binding.physical_network) - self.assertEqual(binding.segmentation_id, 0) - - def test_add_multi_segment_binding(self): - with self.network() as network: - TEST_NETWORK_ID = network['network']['id'] - - self.assertRaises(c_exc.NetworkBindingNotFound, - n1kv_db_v2.get_network_binding, - self.session, - TEST_NETWORK_ID) - - p = _create_test_network_profile_if_not_there( - self.session, - TEST_NETWORK_PROFILE_MULTI_SEGMENT) - n1kv_db_v2.add_network_binding( - self.session, TEST_NETWORK_ID, 'multi-segment', - None, 0, '0.0.0.0', p.id, - [(TEST_NETWORK_ID2, TEST_NETWORK_ID3)]) - binding = n1kv_db_v2.get_network_binding( - self.session, TEST_NETWORK_ID) - self.assertIsNotNone(binding) - self.assertEqual(binding.network_id, TEST_NETWORK_ID) - self.assertEqual(binding.network_type, 'multi-segment') - self.assertIsNone(binding.physical_network) - self.assertEqual(binding.segmentation_id, 0) - ms_binding = (n1kv_db_v2.get_multi_segment_network_binding( - self.session, TEST_NETWORK_ID, - (TEST_NETWORK_ID2, TEST_NETWORK_ID3))) - self.assertIsNotNone(ms_binding) - self.assertEqual(ms_binding.multi_segment_id, TEST_NETWORK_ID) - self.assertEqual(ms_binding.segment1_id, TEST_NETWORK_ID2) - self.assertEqual(ms_binding.segment2_id, TEST_NETWORK_ID3) - ms_members = (n1kv_db_v2.get_multi_segment_members( - self.session, TEST_NETWORK_ID)) - self.assertEqual(ms_members, - [(TEST_NETWORK_ID2, TEST_NETWORK_ID3)]) - self.assertTrue(n1kv_db_v2.is_multi_segment_member( - self.session, TEST_NETWORK_ID2)) - self.assertTrue(n1kv_db_v2.is_multi_segment_member( - self.session, TEST_NETWORK_ID3)) - n1kv_db_v2.del_multi_segment_binding( - self.session, TEST_NETWORK_ID, - [(TEST_NETWORK_ID2, TEST_NETWORK_ID3)]) - ms_members = (n1kv_db_v2.get_multi_segment_members( - self.session, TEST_NETWORK_ID)) - self.assertEqual(ms_members, []) - - def test_create_vlan_trunk_network(self): - with self.network() as network: - TEST_NETWORK_ID = network['network']['id'] - - self.assertRaises(c_exc.NetworkBindingNotFound, - n1kv_db_v2.get_network_binding, - self.session, - TEST_NETWORK_ID) - - p = _create_test_network_profile_if_not_there( - self.session, - TEST_NETWORK_PROFILE_VLAN_TRUNK) - n1kv_db_v2.add_network_binding( - self.session, TEST_NETWORK_ID, 'trunk', - None, 0, '0.0.0.0', p.id, None) - binding = n1kv_db_v2.get_network_binding( - self.session, TEST_NETWORK_ID) - self.assertIsNotNone(binding) - self.assertEqual(binding.network_id, TEST_NETWORK_ID) - self.assertEqual(binding.network_type, 'trunk') - self.assertIsNone(binding.physical_network) - self.assertEqual(binding.segmentation_id, 0) - - def test_create_vxlan_trunk_network(self): - with self.network() as network: - TEST_NETWORK_ID = network['network']['id'] - - self.assertRaises(c_exc.NetworkBindingNotFound, - n1kv_db_v2.get_network_binding, - self.session, - TEST_NETWORK_ID) - - p = _create_test_network_profile_if_not_there( - self.session, - TEST_NETWORK_PROFILE_VXLAN_TRUNK) - n1kv_db_v2.add_network_binding( - self.session, TEST_NETWORK_ID, 'trunk', - None, 0, '0.0.0.0', p.id, None) - binding = n1kv_db_v2.get_network_binding( - self.session, TEST_NETWORK_ID) - self.assertIsNotNone(binding) - self.assertEqual(binding.network_id, TEST_NETWORK_ID) - self.assertEqual(binding.network_type, 'trunk') - self.assertIsNone(binding.physical_network) - self.assertEqual(binding.segmentation_id, 0) - - def test_add_vlan_trunk_binding(self): - with self.network() as network1: - with self.network() as network2: - TEST_NETWORK_ID = network1['network']['id'] - - self.assertRaises(c_exc.NetworkBindingNotFound, - n1kv_db_v2.get_network_binding, - self.session, - TEST_NETWORK_ID) - TEST_NETWORK_ID2 = network2['network']['id'] - self.assertRaises(c_exc.NetworkBindingNotFound, - n1kv_db_v2.get_network_binding, - self.session, - TEST_NETWORK_ID2) - p_v = _create_test_network_profile_if_not_there(self.session) - n1kv_db_v2.add_network_binding( - self.session, TEST_NETWORK_ID2, 'vlan', - PHYS_NET, 1234, '0.0.0.0', p_v.id, None) - p = _create_test_network_profile_if_not_there( - self.session, - TEST_NETWORK_PROFILE_VLAN_TRUNK) - n1kv_db_v2.add_network_binding( - self.session, TEST_NETWORK_ID, 'trunk', - None, 0, '0.0.0.0', p.id, [(TEST_NETWORK_ID2, 0)]) - binding = n1kv_db_v2.get_network_binding( - self.session, TEST_NETWORK_ID) - self.assertIsNotNone(binding) - self.assertEqual(binding.network_id, TEST_NETWORK_ID) - self.assertEqual(binding.network_type, 'trunk') - self.assertEqual(binding.physical_network, PHYS_NET) - self.assertEqual(binding.segmentation_id, 0) - t_binding = (n1kv_db_v2.get_trunk_network_binding( - self.session, TEST_NETWORK_ID, - (TEST_NETWORK_ID2, 0))) - self.assertIsNotNone(t_binding) - self.assertEqual(t_binding.trunk_segment_id, TEST_NETWORK_ID) - self.assertEqual(t_binding.segment_id, TEST_NETWORK_ID2) - self.assertEqual(t_binding.dot1qtag, '0') - t_members = (n1kv_db_v2.get_trunk_members( - self.session, TEST_NETWORK_ID)) - self.assertEqual(t_members, - [(TEST_NETWORK_ID2, '0')]) - self.assertTrue(n1kv_db_v2.is_trunk_member( - self.session, TEST_NETWORK_ID2)) - n1kv_db_v2.del_trunk_segment_binding( - self.session, TEST_NETWORK_ID, - [(TEST_NETWORK_ID2, '0')]) - t_members = (n1kv_db_v2.get_multi_segment_members( - self.session, TEST_NETWORK_ID)) - self.assertEqual(t_members, []) - - def test_add_vxlan_trunk_binding(self): - with self.network() as network1: - with self.network() as network2: - TEST_NETWORK_ID = network1['network']['id'] - - self.assertRaises(c_exc.NetworkBindingNotFound, - n1kv_db_v2.get_network_binding, - self.session, - TEST_NETWORK_ID) - TEST_NETWORK_ID2 = network2['network']['id'] - self.assertRaises(c_exc.NetworkBindingNotFound, - n1kv_db_v2.get_network_binding, - self.session, - TEST_NETWORK_ID2) - p_v = _create_test_network_profile_if_not_there( - self.session, TEST_NETWORK_PROFILE_VXLAN_TRUNK) - n1kv_db_v2.add_network_binding( - self.session, TEST_NETWORK_ID2, 'overlay', - None, 5100, '224.10.10.10', p_v.id, None) - p = _create_test_network_profile_if_not_there( - self.session, - TEST_NETWORK_PROFILE_VXLAN_TRUNK) - n1kv_db_v2.add_network_binding( - self.session, TEST_NETWORK_ID, 'trunk', - None, 0, '0.0.0.0', p.id, - [(TEST_NETWORK_ID2, 5)]) - binding = n1kv_db_v2.get_network_binding( - self.session, TEST_NETWORK_ID) - self.assertIsNotNone(binding) - self.assertEqual(binding.network_id, TEST_NETWORK_ID) - self.assertEqual(binding.network_type, 'trunk') - self.assertIsNone(binding.physical_network) - self.assertEqual(binding.segmentation_id, 0) - t_binding = (n1kv_db_v2.get_trunk_network_binding( - self.session, TEST_NETWORK_ID, - (TEST_NETWORK_ID2, '5'))) - self.assertIsNotNone(t_binding) - self.assertEqual(t_binding.trunk_segment_id, TEST_NETWORK_ID) - self.assertEqual(t_binding.segment_id, TEST_NETWORK_ID2) - self.assertEqual(t_binding.dot1qtag, '5') - t_members = (n1kv_db_v2.get_trunk_members( - self.session, TEST_NETWORK_ID)) - self.assertEqual(t_members, - [(TEST_NETWORK_ID2, '5')]) - self.assertTrue(n1kv_db_v2.is_trunk_member( - self.session, TEST_NETWORK_ID2)) - n1kv_db_v2.del_trunk_segment_binding( - self.session, TEST_NETWORK_ID, - [(TEST_NETWORK_ID2, '5')]) - t_members = (n1kv_db_v2.get_multi_segment_members( - self.session, TEST_NETWORK_ID)) - self.assertEqual(t_members, []) - - -class NetworkProfileTests(base.BaseTestCase, - n1kv_db_v2.NetworkProfile_db_mixin): - - def setUp(self): - super(NetworkProfileTests, self).setUp() - db.configure_db() - self.session = db.get_session() - self.addCleanup(db.clear_db) - - def test_create_network_profile(self): - _db_profile = n1kv_db_v2.create_network_profile(self.session, - TEST_NETWORK_PROFILE) - self.assertIsNotNone(_db_profile) - db_profile = (self.session.query(n1kv_models_v2.NetworkProfile). - filter_by(name=TEST_NETWORK_PROFILE['name']).one()) - self.assertIsNotNone(db_profile) - self.assertEqual(_db_profile.id, db_profile.id) - self.assertEqual(_db_profile.name, db_profile.name) - self.assertEqual(_db_profile.segment_type, db_profile.segment_type) - self.assertEqual(_db_profile.segment_range, db_profile.segment_range) - self.assertEqual(_db_profile.multicast_ip_index, - db_profile.multicast_ip_index) - self.assertEqual(_db_profile.multicast_ip_range, - db_profile.multicast_ip_range) - n1kv_db_v2.delete_network_profile(self.session, _db_profile.id) - - def test_create_multi_segment_network_profile(self): - _db_profile = (n1kv_db_v2.create_network_profile( - self.session, TEST_NETWORK_PROFILE_MULTI_SEGMENT)) - self.assertIsNotNone(_db_profile) - db_profile = ( - self.session.query( - n1kv_models_v2.NetworkProfile).filter_by( - name=TEST_NETWORK_PROFILE_MULTI_SEGMENT['name']) - .one()) - self.assertIsNotNone(db_profile) - self.assertEqual(_db_profile.id, db_profile.id) - self.assertEqual(_db_profile.name, db_profile.name) - self.assertEqual(_db_profile.segment_type, db_profile.segment_type) - self.assertEqual(_db_profile.segment_range, db_profile.segment_range) - self.assertEqual(_db_profile.multicast_ip_index, - db_profile.multicast_ip_index) - self.assertEqual(_db_profile.multicast_ip_range, - db_profile.multicast_ip_range) - n1kv_db_v2.delete_network_profile(self.session, _db_profile.id) - - def test_create_vlan_trunk_network_profile(self): - _db_profile = (n1kv_db_v2.create_network_profile( - self.session, TEST_NETWORK_PROFILE_VLAN_TRUNK)) - self.assertIsNotNone(_db_profile) - db_profile = (self.session.query(n1kv_models_v2.NetworkProfile). - filter_by(name=TEST_NETWORK_PROFILE_VLAN_TRUNK['name']). - one()) - self.assertIsNotNone(db_profile) - self.assertEqual(_db_profile.id, db_profile.id) - self.assertEqual(_db_profile.name, db_profile.name) - self.assertEqual(_db_profile.segment_type, db_profile.segment_type) - self.assertEqual(_db_profile.segment_range, db_profile.segment_range) - self.assertEqual(_db_profile.multicast_ip_index, - db_profile.multicast_ip_index) - self.assertEqual(_db_profile.multicast_ip_range, - db_profile.multicast_ip_range) - self.assertEqual(_db_profile.sub_type, db_profile.sub_type) - n1kv_db_v2.delete_network_profile(self.session, _db_profile.id) - - def test_create_vxlan_trunk_network_profile(self): - _db_profile = (n1kv_db_v2.create_network_profile( - self.session, TEST_NETWORK_PROFILE_VXLAN_TRUNK)) - self.assertIsNotNone(_db_profile) - db_profile = (self.session.query(n1kv_models_v2.NetworkProfile). - filter_by(name=TEST_NETWORK_PROFILE_VXLAN_TRUNK['name']). - one()) - self.assertIsNotNone(db_profile) - self.assertEqual(_db_profile.id, db_profile.id) - self.assertEqual(_db_profile.name, db_profile.name) - self.assertEqual(_db_profile.segment_type, db_profile.segment_type) - self.assertEqual(_db_profile.segment_range, db_profile.segment_range) - self.assertEqual(_db_profile.multicast_ip_index, - db_profile.multicast_ip_index) - self.assertEqual(_db_profile.multicast_ip_range, - db_profile.multicast_ip_range) - self.assertEqual(_db_profile.sub_type, db_profile.sub_type) - n1kv_db_v2.delete_network_profile(self.session, _db_profile.id) - - def test_create_network_profile_overlap(self): - _db_profile = n1kv_db_v2.create_network_profile(self.session, - TEST_NETWORK_PROFILE_2) - ctx = context.get_admin_context() - TEST_NETWORK_PROFILE_2['name'] = 'net-profile-min-overlap' - TEST_NETWORK_PROFILE_2['segment_range'] = SEGMENT_RANGE_MIN_OVERLAP - test_net_profile = {'network_profile': TEST_NETWORK_PROFILE_2} - self.assertRaises(n_exc.InvalidInput, - self.create_network_profile, - ctx, - test_net_profile) - - TEST_NETWORK_PROFILE_2['name'] = 'net-profile-max-overlap' - TEST_NETWORK_PROFILE_2['segment_range'] = SEGMENT_RANGE_MAX_OVERLAP - test_net_profile = {'network_profile': TEST_NETWORK_PROFILE_2} - self.assertRaises(n_exc.InvalidInput, - self.create_network_profile, - ctx, - test_net_profile) - - TEST_NETWORK_PROFILE_2['name'] = 'net-profile-overlap' - TEST_NETWORK_PROFILE_2['segment_range'] = SEGMENT_RANGE_OVERLAP - test_net_profile = {'network_profile': TEST_NETWORK_PROFILE_2} - self.assertRaises(n_exc.InvalidInput, - self.create_network_profile, - ctx, - test_net_profile) - n1kv_db_v2.delete_network_profile(self.session, _db_profile.id) - - def test_delete_network_profile(self): - try: - profile = (self.session.query(n1kv_models_v2.NetworkProfile). - filter_by(name=TEST_NETWORK_PROFILE['name']).one()) - except s_exc.NoResultFound: - profile = n1kv_db_v2.create_network_profile(self.session, - TEST_NETWORK_PROFILE) - - n1kv_db_v2.delete_network_profile(self.session, profile.id) - try: - self.session.query(n1kv_models_v2.NetworkProfile).filter_by( - name=TEST_NETWORK_PROFILE['name']).one() - except s_exc.NoResultFound: - pass - else: - self.fail("Network Profile (%s) was not deleted" % - TEST_NETWORK_PROFILE['name']) - - def test_update_network_profile(self): - TEST_PROFILE_1 = {'name': 'test_profile_1'} - profile = _create_test_network_profile_if_not_there(self.session) - updated_profile = n1kv_db_v2.update_network_profile(self.session, - profile.id, - TEST_PROFILE_1) - self.assertEqual(updated_profile.name, TEST_PROFILE_1['name']) - n1kv_db_v2.delete_network_profile(self.session, profile.id) - - def test_get_network_profile(self): - profile = n1kv_db_v2.create_network_profile(self.session, - TEST_NETWORK_PROFILE) - got_profile = n1kv_db_v2.get_network_profile(self.session, profile.id) - self.assertEqual(profile.id, got_profile.id) - self.assertEqual(profile.name, got_profile.name) - n1kv_db_v2.delete_network_profile(self.session, profile.id) - - def test_get_network_profiles(self): - test_profiles = [{'name': 'test_profile1', - 'segment_type': 'vlan', - 'physical_network': 'phys1', - 'segment_range': '200-210'}, - {'name': 'test_profile2', - 'segment_type': 'vlan', - 'physical_network': 'phys1', - 'segment_range': '211-220'}, - {'name': 'test_profile3', - 'segment_type': 'vlan', - 'physical_network': 'phys1', - 'segment_range': '221-230'}, - {'name': 'test_profile4', - 'segment_type': 'vlan', - 'physical_network': 'phys1', - 'segment_range': '231-240'}, - {'name': 'test_profile5', - 'segment_type': 'vlan', - 'physical_network': 'phys1', - 'segment_range': '241-250'}, - {'name': 'test_profile6', - 'segment_type': 'vlan', - 'physical_network': 'phys1', - 'segment_range': '251-260'}, - {'name': 'test_profile7', - 'segment_type': 'vlan', - 'physical_network': 'phys1', - 'segment_range': '261-270'}] - [n1kv_db_v2.create_network_profile(self.session, p) - for p in test_profiles] - # TODO(abhraut): Fix this test to work with real tenant_td - profiles = n1kv_db_v2._get_network_profiles(db_session=self.session) - self.assertEqual(len(test_profiles), len(list(profiles))) - - -class PolicyProfileTests(base.BaseTestCase): - - def setUp(self): - super(PolicyProfileTests, self).setUp() - db.configure_db() - self.session = db.get_session() - self.addCleanup(db.clear_db) - - def test_create_policy_profile(self): - _db_profile = n1kv_db_v2.create_policy_profile(TEST_POLICY_PROFILE) - self.assertIsNotNone(_db_profile) - db_profile = (self.session.query(n1kv_models_v2.PolicyProfile). - filter_by(name=TEST_POLICY_PROFILE['name']).one)() - self.assertIsNotNone(db_profile) - self.assertTrue(_db_profile.id == db_profile.id) - self.assertTrue(_db_profile.name == db_profile.name) - - def test_delete_policy_profile(self): - profile = _create_test_policy_profile_if_not_there(self.session) - n1kv_db_v2.delete_policy_profile(profile.id) - try: - self.session.query(n1kv_models_v2.PolicyProfile).filter_by( - name=TEST_POLICY_PROFILE['name']).one() - except s_exc.NoResultFound: - pass - else: - self.fail("Policy Profile (%s) was not deleted" % - TEST_POLICY_PROFILE['name']) - - def test_update_policy_profile(self): - TEST_PROFILE_1 = {'name': 'test_profile_1'} - profile = _create_test_policy_profile_if_not_there(self.session) - updated_profile = n1kv_db_v2.update_policy_profile(self.session, - profile.id, - TEST_PROFILE_1) - self.assertEqual(updated_profile.name, TEST_PROFILE_1['name']) - - def test_get_policy_profile(self): - profile = _create_test_policy_profile_if_not_there(self.session) - got_profile = n1kv_db_v2.get_policy_profile(self.session, profile.id) - self.assertEqual(profile.id, got_profile.id) - self.assertEqual(profile.name, got_profile.name) - - -class ProfileBindingTests(base.BaseTestCase, - n1kv_db_v2.NetworkProfile_db_mixin, - db_base_plugin_v2.CommonDbMixin): - - def setUp(self): - super(ProfileBindingTests, self).setUp() - db.configure_db() - self.session = db.get_session() - self.addCleanup(db.clear_db) - - def _create_test_binding_if_not_there(self, tenant_id, profile_id, - profile_type): - try: - _binding = (self.session.query(n1kv_models_v2.ProfileBinding). - filter_by(profile_type=profile_type, - tenant_id=tenant_id, - profile_id=profile_id).one()) - except s_exc.NoResultFound: - _binding = n1kv_db_v2.create_profile_binding(self.session, - tenant_id, - profile_id, - profile_type) - return _binding - - def test_create_profile_binding(self): - test_tenant_id = "d434dd90-76ec-11e2-bcfd-0800200c9a66" - test_profile_id = "dd7b9741-76ec-11e2-bcfd-0800200c9a66" - test_profile_type = "network" - n1kv_db_v2.create_profile_binding(self.session, - test_tenant_id, - test_profile_id, - test_profile_type) - try: - self.session.query(n1kv_models_v2.ProfileBinding).filter_by( - profile_type=test_profile_type, - tenant_id=test_tenant_id, - profile_id=test_profile_id).one() - except s_exc.MultipleResultsFound: - self.fail("Bindings must be unique") - except s_exc.NoResultFound: - self.fail("Could not create Profile Binding") - - def test_get_profile_binding(self): - test_tenant_id = "d434dd90-76ec-11e2-bcfd-0800200c9a66" - test_profile_id = "dd7b9741-76ec-11e2-bcfd-0800200c9a66" - test_profile_type = "network" - self._create_test_binding_if_not_there(test_tenant_id, - test_profile_id, - test_profile_type) - binding = n1kv_db_v2.get_profile_binding(self.session, - test_tenant_id, - test_profile_id) - self.assertEqual(binding.tenant_id, test_tenant_id) - self.assertEqual(binding.profile_id, test_profile_id) - self.assertEqual(binding.profile_type, test_profile_type) - - def test_get_profile_binding_not_found(self): - self.assertRaises( - c_exc.ProfileTenantBindingNotFound, - n1kv_db_v2.get_profile_binding, self.session, "123", "456") - - def test_delete_profile_binding(self): - test_tenant_id = "d434dd90-76ec-11e2-bcfd-0800200c9a66" - test_profile_id = "dd7b9741-76ec-11e2-bcfd-0800200c9a66" - test_profile_type = "network" - self._create_test_binding_if_not_there(test_tenant_id, - test_profile_id, - test_profile_type) - n1kv_db_v2.delete_profile_binding(self.session, - test_tenant_id, - test_profile_id) - q = (self.session.query(n1kv_models_v2.ProfileBinding).filter_by( - profile_type=test_profile_type, - tenant_id=test_tenant_id, - profile_id=test_profile_id)) - self.assertFalse(q.count()) - - def test_default_tenant_replace(self): - ctx = context.get_admin_context() - ctx.tenant_id = "d434dd90-76ec-11e2-bcfd-0800200c9a66" - test_profile_id = "AAAAAAAA-76ec-11e2-bcfd-0800200c9a66" - test_profile_type = "policy" - n1kv_db_v2.create_profile_binding(self.session, - cisco_constants.TENANT_ID_NOT_SET, - test_profile_id, - test_profile_type) - network_profile = {"network_profile": TEST_NETWORK_PROFILE} - self.create_network_profile(ctx, network_profile) - binding = n1kv_db_v2.get_profile_binding(self.session, - ctx.tenant_id, - test_profile_id) - self.assertRaises( - c_exc.ProfileTenantBindingNotFound, - n1kv_db_v2.get_profile_binding, - self.session, - cisco_constants.TENANT_ID_NOT_SET, - test_profile_id) - self.assertNotEqual(binding.tenant_id, - cisco_constants.TENANT_ID_NOT_SET) diff --git a/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py b/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py deleted file mode 100644 index b2d29de61..000000000 --- a/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py +++ /dev/null @@ -1,709 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Cisco Systems, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Juergen Brendel, Cisco Systems Inc. -# @author: Abhishek Raut, Cisco Systems Inc. -# @author: Sourabh Patwardhan, Cisco Systems Inc. - -import mock - -from neutron.api import extensions as neutron_extensions -from neutron.api.v2 import attributes -from neutron import context -import neutron.db.api as db -from neutron.extensions import portbindings -from neutron import manager -from neutron.plugins.cisco.common import cisco_exceptions as c_exc -from neutron.plugins.cisco.db import n1kv_db_v2 -from neutron.plugins.cisco.db import network_db_v2 as cdb -from neutron.plugins.cisco import extensions -from neutron.plugins.cisco.extensions import n1kv -from neutron.plugins.cisco.extensions import network_profile -from neutron.plugins.cisco.n1kv import n1kv_client -from neutron.plugins.cisco.n1kv import n1kv_neutron_plugin -from neutron.tests.unit import _test_extension_portbindings as test_bindings -from neutron.tests.unit.cisco.n1kv import fake_client -from neutron.tests.unit import test_api_v2 -from neutron.tests.unit import test_db_plugin as test_plugin -from neutron.tests.unit import test_l3_plugin -from neutron.tests.unit import test_l3_schedulers - - -PHYS_NET = 'some-phys-net' -VLAN_MIN = 100 -VLAN_MAX = 110 - - -class FakeResponse(object): - - """ - This object is returned by mocked requests lib instead of normal response. - - Initialize it with the status code, header and buffer contents you wish to - return. - - """ - def __init__(self, status, response_text, headers): - self.buffer = response_text - self.status_code = status - self.headers = headers - - def json(self, *args, **kwargs): - return self.buffer - - -def _fake_setup_vsm(self): - """Fake establish Communication with Cisco Nexus1000V VSM.""" - self.agent_vsm = True - self._populate_policy_profiles() - - -class NetworkProfileTestExtensionManager(object): - - def get_resources(self): - # Add the resources to the global attribute map - # This is done here as the setup process won't - # initialize the main API router which extends - # the global attribute map - attributes.RESOURCE_ATTRIBUTE_MAP.update( - network_profile.RESOURCE_ATTRIBUTE_MAP) - return network_profile.Network_profile.get_resources() - - def get_actions(self): - return [] - - def get_request_extensions(self): - return [] - - -class N1kvPluginTestCase(test_plugin.NeutronDbPluginV2TestCase): - - _plugin_name = ('neutron.plugins.cisco.n1kv.' - 'n1kv_neutron_plugin.N1kvNeutronPluginV2') - - tenant_id = "some_tenant" - - DEFAULT_RESP_BODY = "" - DEFAULT_RESP_CODE = 200 - DEFAULT_CONTENT_TYPE = "" - fmt = "json" - - def _make_test_policy_profile(self, name='service_profile'): - """ - Create a policy profile record for testing purpose. - - :param name: string representing the name of the policy profile to - create. Default argument value chosen to correspond to the - default name specified in config.py file. - """ - uuid = test_api_v2._uuid() - profile = {'id': uuid, - 'name': name} - return n1kv_db_v2.create_policy_profile(profile) - - def _make_test_profile(self, - name='default_network_profile', - segment_range='386-400'): - """ - Create a profile record for testing purposes. - - :param name: string representing the name of the network profile to - create. Default argument value chosen to correspond to the - default name specified in config.py file. - :param segment_range: string representing the segment range for network - profile. - """ - db_session = db.get_session() - profile = {'name': name, - 'segment_type': 'vlan', - 'physical_network': PHYS_NET, - 'tenant_id': self.tenant_id, - 'segment_range': segment_range} - net_p = n1kv_db_v2.create_network_profile(db_session, profile) - n1kv_db_v2.sync_vlan_allocations(db_session, net_p) - return net_p - - def setUp(self): - """ - Setup method for n1kv plugin tests. - - First step is to define an acceptable response from the VSM to - our requests. This needs to be done BEFORE the setUp() function - of the super-class is called. - - This default here works for many cases. If you need something - extra, please define your own setUp() function in your test class, - and set your DEFAULT_RESPONSE value also BEFORE calling the - setUp() of the super-function (this one here). If you have set - a value already, it will not be overwritten by this code. - - """ - if not self.DEFAULT_RESP_BODY: - self.DEFAULT_RESP_BODY = { - "icehouse-pp": {"properties": {"name": "icehouse-pp", - "id": "some-uuid-1"}}, - "havana_pp": {"properties": {"name": "havana_pp", - "id": "some-uuid-2"}}, - "dhcp_pp": {"properties": {"name": "dhcp_pp", - "id": "some-uuid-3"}}, - } - # Creating a mock HTTP connection object for requests lib. The N1KV - # client interacts with the VSM via HTTP. Since we don't have a VSM - # running in the unit tests, we need to 'fake' it by patching the HTTP - # library itself. We install a patch for a fake HTTP connection class. - # Using __name__ to avoid having to enter the full module path. - http_patcher = mock.patch(n1kv_client.requests.__name__ + ".request") - FakeHttpConnection = http_patcher.start() - # Now define the return values for a few functions that may be called - # on any instance of the fake HTTP connection class. - self.resp_headers = {"content-type": "application/json"} - FakeHttpConnection.return_value = (FakeResponse( - self.DEFAULT_RESP_CODE, - self.DEFAULT_RESP_BODY, - self.resp_headers)) - - # Patch some internal functions in a few other parts of the system. - # These help us move along, without having to mock up even more systems - # in the background. - - # Return a dummy VSM IP address - mock.patch(n1kv_client.__name__ + ".Client._get_vsm_hosts", - new=lambda self: "127.0.0.1").start() - - # Return dummy user profiles - mock.patch(cdb.__name__ + ".get_credential_name", - new=lambda self: {"user_name": "admin", - "password": "admin_password"}).start() - - n1kv_neutron_plugin.N1kvNeutronPluginV2._setup_vsm = _fake_setup_vsm - - neutron_extensions.append_api_extensions_path(extensions.__path__) - ext_mgr = NetworkProfileTestExtensionManager() - - # Save the original RESOURCE_ATTRIBUTE_MAP - self.saved_attr_map = {} - for resource, attrs in attributes.RESOURCE_ATTRIBUTE_MAP.items(): - self.saved_attr_map[resource] = attrs.copy() - # Update the RESOURCE_ATTRIBUTE_MAP with n1kv specific extended attrs. - attributes.RESOURCE_ATTRIBUTE_MAP["networks"].update( - n1kv.EXTENDED_ATTRIBUTES_2_0["networks"]) - attributes.RESOURCE_ATTRIBUTE_MAP["ports"].update( - n1kv.EXTENDED_ATTRIBUTES_2_0["ports"]) - self.addCleanup(self.restore_resource_attribute_map) - self.addCleanup(db.clear_db) - super(N1kvPluginTestCase, self).setUp(self._plugin_name, - ext_mgr=ext_mgr) - # Create some of the database entries that we require. - self._make_test_profile() - self._make_test_policy_profile() - - def restore_resource_attribute_map(self): - # Restore the original RESOURCE_ATTRIBUTE_MAP - attributes.RESOURCE_ATTRIBUTE_MAP = self.saved_attr_map - - def test_plugin(self): - self._make_network('json', - 'some_net', - True, - tenant_id=self.tenant_id, - set_context=True) - - req = self.new_list_request('networks', params="fields=tenant_id") - req.environ['neutron.context'] = context.Context('', self.tenant_id) - res = req.get_response(self.api) - self.assertEqual(res.status_int, 200) - body = self.deserialize('json', res) - self.assertIn('tenant_id', body['networks'][0]) - - -class TestN1kvNetworkProfiles(N1kvPluginTestCase): - def _prepare_net_profile_data(self, segment_type): - netp = {'network_profile': {'name': 'netp1', - 'segment_type': segment_type, - 'tenant_id': self.tenant_id}} - if segment_type == 'vlan': - netp['network_profile']['segment_range'] = '100-110' - netp['network_profile']['physical_network'] = PHYS_NET - elif segment_type == 'overlay': - netp['network_profile']['segment_range'] = '10000-10010' - netp['network_profile']['sub_type'] = 'enhanced' or 'native_vxlan' - netp['network_profile']['multicast_ip_range'] = ("224.1.1.1-" - "224.1.1.10") - elif segment_type == 'trunk': - netp['network_profile']['sub_type'] = 'vlan' - return netp - - def test_create_network_profile_vlan(self): - data = self._prepare_net_profile_data('vlan') - net_p_req = self.new_create_request('network_profiles', data) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 201) - - def test_create_network_profile_overlay(self): - data = self._prepare_net_profile_data('overlay') - net_p_req = self.new_create_request('network_profiles', data) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 201) - - def test_create_network_profile_trunk(self): - data = self._prepare_net_profile_data('trunk') - net_p_req = self.new_create_request('network_profiles', data) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 201) - - def test_create_network_profile_trunk_missing_subtype(self): - data = self._prepare_net_profile_data('trunk') - data['network_profile'].pop('sub_type') - net_p_req = self.new_create_request('network_profiles', data) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 400) - - def test_create_network_profile_overlay_unreasonable_seg_range(self): - data = self._prepare_net_profile_data('overlay') - data['network_profile']['segment_range'] = '10000-100000000001' - net_p_req = self.new_create_request('network_profiles', data) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 400) - - def test_update_network_profile_plugin(self): - net_p_dict = self._prepare_net_profile_data('overlay') - net_p_req = self.new_create_request('network_profiles', net_p_dict) - net_p = self.deserialize(self.fmt, - net_p_req.get_response(self.ext_api)) - data = {'network_profile': {'name': 'netp2'}} - update_req = self.new_update_request('network_profiles', - data, - net_p['network_profile']['id']) - update_res = update_req.get_response(self.ext_api) - self.assertEqual(update_res.status_int, 200) - - def test_update_network_profile_physical_network_fail(self): - net_p = self._make_test_profile(name='netp1') - data = {'network_profile': {'physical_network': PHYS_NET}} - net_p_req = self.new_update_request('network_profiles', - data, - net_p['id']) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 400) - - def test_update_network_profile_segment_type_fail(self): - net_p = self._make_test_profile(name='netp1') - data = {'network_profile': {'segment_type': 'overlay'}} - net_p_req = self.new_update_request('network_profiles', - data, - net_p['id']) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 400) - - def test_update_network_profile_sub_type_fail(self): - net_p_dict = self._prepare_net_profile_data('overlay') - net_p_req = self.new_create_request('network_profiles', net_p_dict) - net_p = self.deserialize(self.fmt, - net_p_req.get_response(self.ext_api)) - data = {'network_profile': {'sub_type': 'vlan'}} - update_req = self.new_update_request('network_profiles', - data, - net_p['network_profile']['id']) - update_res = update_req.get_response(self.ext_api) - self.assertEqual(update_res.status_int, 400) - - def test_update_network_profiles_with_networks_fail(self): - net_p = self._make_test_profile(name='netp1') - data = {'network_profile': {'segment_range': '200-210'}} - update_req = self.new_update_request('network_profiles', - data, - net_p['id']) - update_res = update_req.get_response(self.ext_api) - self.assertEqual(update_res.status_int, 200) - net_data = {'network': {'name': 'net1', - n1kv.PROFILE_ID: net_p['id'], - 'tenant_id': 'some_tenant'}} - network_req = self.new_create_request('networks', net_data) - network_res = network_req.get_response(self.api) - self.assertEqual(network_res.status_int, 201) - data = {'network_profile': {'segment_range': '300-310'}} - update_req = self.new_update_request('network_profiles', - data, - net_p['id']) - update_res = update_req.get_response(self.ext_api) - self.assertEqual(update_res.status_int, 409) - - def test_create_overlay_network_profile_invalid_multicast_fail(self): - net_p_dict = self._prepare_net_profile_data('overlay') - data = {'network_profile': {'sub_type': 'native_vxlan', - 'multicast_ip_range': '1.1.1.1'}} - net_p_req = self.new_create_request('network_profiles', data, - net_p_dict) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 400) - - def test_create_overlay_network_profile_no_multicast_fail(self): - net_p_dict = self._prepare_net_profile_data('overlay') - data = {'network_profile': {'sub_type': 'native_vxlan', - 'multicast_ip_range': ''}} - net_p_req = self.new_create_request('network_profiles', data, - net_p_dict) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 400) - - def test_create_overlay_network_profile_wrong_split_multicast_fail(self): - net_p_dict = self._prepare_net_profile_data('overlay') - data = {'network_profile': { - 'sub_type': 'native_vxlan', - 'multicast_ip_range': '224.1.1.1.224.1.1.3'}} - net_p_req = self.new_create_request('network_profiles', data, - net_p_dict) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 400) - - def test_create_overlay_network_profile_invalid_minip_multicast_fail(self): - net_p_dict = self._prepare_net_profile_data('overlay') - data = {'network_profile': { - 'sub_type': 'native_vxlan', - 'multicast_ip_range': '10.0.0.1-224.1.1.3'}} - net_p_req = self.new_create_request('network_profiles', data, - net_p_dict) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 400) - - def test_create_overlay_network_profile_invalid_maxip_multicast_fail(self): - net_p_dict = self._prepare_net_profile_data('overlay') - data = {'network_profile': { - 'sub_type': 'native_vxlan', - 'multicast_ip_range': '224.1.1.1-20.0.0.1'}} - net_p_req = self.new_create_request('network_profiles', data, - net_p_dict) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 400) - - def test_create_overlay_network_profile_correct_multicast_pass(self): - data = self._prepare_net_profile_data('overlay') - net_p_req = self.new_create_request('network_profiles', data) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 201) - - def test_update_overlay_network_profile_correct_multicast_pass(self): - data = self._prepare_net_profile_data('overlay') - net_p_req = self.new_create_request('network_profiles', data) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 201) - net_p = self.deserialize(self.fmt, res) - data = {'network_profile': {'multicast_ip_range': - '224.0.1.0-224.0.1.100'}} - update_req = self.new_update_request('network_profiles', - data, - net_p['network_profile']['id']) - update_res = update_req.get_response(self.ext_api) - self.assertEqual(update_res.status_int, 200) - - def test_create_overlay_network_profile_reservedip_multicast_fail(self): - net_p_dict = self._prepare_net_profile_data('overlay') - data = {'network_profile': {'multicast_ip_range': - '224.0.0.100-224.0.1.100'}} - net_p_req = self.new_create_request('network_profiles', data, - net_p_dict) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 400) - - def test_update_overlay_network_profile_reservedip_multicast_fail(self): - data = self._prepare_net_profile_data('overlay') - net_p_req = self.new_create_request('network_profiles', data) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 201) - net_p = self.deserialize(self.fmt, res) - data = {'network_profile': {'multicast_ip_range': - '224.0.0.11-224.0.0.111'}} - update_req = self.new_update_request('network_profiles', - data, - net_p['network_profile']['id']) - update_res = update_req.get_response(self.ext_api) - self.assertEqual(update_res.status_int, 400) - - def test_update_vlan_network_profile_multicast_fail(self): - net_p = self._make_test_profile(name='netp1') - data = {'network_profile': {'multicast_ip_range': - '224.0.1.0-224.0.1.100'}} - update_req = self.new_update_request('network_profiles', - data, - net_p['id']) - update_res = update_req.get_response(self.ext_api) - self.assertEqual(update_res.status_int, 400) - - def test_update_trunk_network_profile_segment_range_fail(self): - data = self._prepare_net_profile_data('trunk') - net_p_req = self.new_create_request('network_profiles', data) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 201) - net_p = self.deserialize(self.fmt, res) - data = {'network_profile': {'segment_range': - '100-200'}} - update_req = self.new_update_request('network_profiles', - data, - net_p['network_profile']['id']) - update_res = update_req.get_response(self.ext_api) - self.assertEqual(update_res.status_int, 400) - - def test_update_trunk_network_profile_multicast_fail(self): - data = self._prepare_net_profile_data('trunk') - net_p_req = self.new_create_request('network_profiles', data) - res = net_p_req.get_response(self.ext_api) - self.assertEqual(res.status_int, 201) - net_p = self.deserialize(self.fmt, res) - data = {'network_profile': {'multicast_ip_range': - '224.0.1.0-224.0.1.100'}} - update_req = self.new_update_request('network_profiles', - data, - net_p['network_profile']['id']) - update_res = update_req.get_response(self.ext_api) - self.assertEqual(update_res.status_int, 400) - - def test_create_network_profile_populate_vlan_segment_pool(self): - db_session = db.get_session() - net_p_dict = self._prepare_net_profile_data('vlan') - net_p_req = self.new_create_request('network_profiles', net_p_dict) - self.deserialize(self.fmt, - net_p_req.get_response(self.ext_api)) - for vlan in range(VLAN_MIN, VLAN_MAX + 1): - self.assertIsNotNone(n1kv_db_v2.get_vlan_allocation(db_session, - PHYS_NET, - vlan)) - self.assertFalse(n1kv_db_v2.get_vlan_allocation(db_session, - PHYS_NET, - vlan).allocated) - self.assertRaises(c_exc.VlanIDNotFound, - n1kv_db_v2.get_vlan_allocation, - db_session, - PHYS_NET, - VLAN_MIN - 1) - self.assertRaises(c_exc.VlanIDNotFound, - n1kv_db_v2.get_vlan_allocation, - db_session, - PHYS_NET, - VLAN_MAX + 1) - - def test_delete_network_profile_with_network_fail(self): - net_p = self._make_test_profile(name='netp1') - net_data = {'network': {'name': 'net1', - n1kv.PROFILE_ID: net_p['id'], - 'tenant_id': 'some_tenant'}} - network_req = self.new_create_request('networks', net_data) - network_res = network_req.get_response(self.api) - self.assertEqual(network_res.status_int, 201) - self._delete('network_profiles', net_p['id'], - expected_code=409) - - def test_delete_network_profile_deallocate_vlan_segment_pool(self): - db_session = db.get_session() - net_p_dict = self._prepare_net_profile_data('vlan') - net_p_req = self.new_create_request('network_profiles', net_p_dict) - net_p = self.deserialize(self.fmt, - net_p_req.get_response(self.ext_api)) - self.assertIsNotNone(n1kv_db_v2.get_vlan_allocation(db_session, - PHYS_NET, - VLAN_MIN)) - self._delete('network_profiles', net_p['network_profile']['id']) - for vlan in range(VLAN_MIN, VLAN_MAX + 1): - self.assertRaises(c_exc.VlanIDNotFound, - n1kv_db_v2.get_vlan_allocation, - db_session, - PHYS_NET, - vlan) - - -class TestN1kvBasicGet(test_plugin.TestBasicGet, - N1kvPluginTestCase): - - pass - - -class TestN1kvHTTPResponse(test_plugin.TestV2HTTPResponse, - N1kvPluginTestCase): - - pass - - -class TestN1kvPorts(test_plugin.TestPortsV2, - N1kvPluginTestCase, - test_bindings.PortBindingsTestCase): - VIF_TYPE = portbindings.VIF_TYPE_OVS - HAS_PORT_FILTER = False - - def test_create_port_with_default_n1kv_policy_profile_id(self): - """Test port create without passing policy profile id.""" - with self.port() as port: - db_session = db.get_session() - pp = n1kv_db_v2.get_policy_profile( - db_session, port['port'][n1kv.PROFILE_ID]) - self.assertEqual(pp['name'], 'service_profile') - - def test_create_port_with_n1kv_policy_profile_id(self): - """Test port create with policy profile id.""" - profile_obj = self._make_test_policy_profile(name='test_profile') - with self.network() as network: - data = {'port': {n1kv.PROFILE_ID: profile_obj.id, - 'tenant_id': self.tenant_id, - 'network_id': network['network']['id']}} - port_req = self.new_create_request('ports', data) - port = self.deserialize(self.fmt, - port_req.get_response(self.api)) - self.assertEqual(port['port'][n1kv.PROFILE_ID], - profile_obj.id) - self._delete('ports', port['port']['id']) - - def test_update_port_with_n1kv_policy_profile_id(self): - """Test port update failure while updating policy profile id.""" - with self.port() as port: - data = {'port': {n1kv.PROFILE_ID: 'some-profile-uuid'}} - port_req = self.new_update_request('ports', - data, - port['port']['id']) - res = port_req.get_response(self.api) - # Port update should fail to update policy profile id. - self.assertEqual(res.status_int, 400) - - def test_create_first_port_invalid_parameters_fail(self): - """Test parameters for first port create sent to the VSM.""" - profile_obj = self._make_test_policy_profile(name='test_profile') - with self.network() as network: - client_patch = mock.patch(n1kv_client.__name__ + ".Client", - new=fake_client.TestClientInvalidRequest) - client_patch.start() - data = {'port': {n1kv.PROFILE_ID: profile_obj.id, - 'tenant_id': self.tenant_id, - 'network_id': network['network']['id'], - }} - port_req = self.new_create_request('ports', data) - res = port_req.get_response(self.api) - self.assertEqual(res.status_int, 500) - client_patch.stop() - - def test_create_next_port_invalid_parameters_fail(self): - """Test parameters for subsequent port create sent to the VSM.""" - with self.port() as port: - client_patch = mock.patch(n1kv_client.__name__ + ".Client", - new=fake_client.TestClientInvalidRequest) - client_patch.start() - data = {'port': {n1kv.PROFILE_ID: port['port']['n1kv:profile_id'], - 'tenant_id': port['port']['tenant_id'], - 'network_id': port['port']['network_id']}} - port_req = self.new_create_request('ports', data) - res = port_req.get_response(self.api) - self.assertEqual(res.status_int, 500) - client_patch.stop() - - -class TestN1kvPolicyProfiles(N1kvPluginTestCase): - def test_populate_policy_profile(self): - client_patch = mock.patch(n1kv_client.__name__ + ".Client", - new=fake_client.TestClient) - client_patch.start() - instance = n1kv_neutron_plugin.N1kvNeutronPluginV2() - instance._populate_policy_profiles() - db_session = db.get_session() - profile = n1kv_db_v2.get_policy_profile( - db_session, '00000000-0000-0000-0000-000000000001') - self.assertEqual('pp-1', profile['name']) - client_patch.stop() - - def test_populate_policy_profile_delete(self): - # Patch the Client class with the TestClient class - with mock.patch(n1kv_client.__name__ + ".Client", - new=fake_client.TestClient): - # Patch the _get_total_profiles() method to return a custom value - with mock.patch(fake_client.__name__ + - '.TestClient._get_total_profiles') as obj_inst: - # Return 3 policy profiles - obj_inst.return_value = 3 - plugin = manager.NeutronManager.get_plugin() - plugin._populate_policy_profiles() - db_session = db.get_session() - profile = n1kv_db_v2.get_policy_profile( - db_session, '00000000-0000-0000-0000-000000000001') - # Verify that DB contains only 3 policy profiles - self.assertEqual('pp-1', profile['name']) - profile = n1kv_db_v2.get_policy_profile( - db_session, '00000000-0000-0000-0000-000000000002') - self.assertEqual('pp-2', profile['name']) - profile = n1kv_db_v2.get_policy_profile( - db_session, '00000000-0000-0000-0000-000000000003') - self.assertEqual('pp-3', profile['name']) - self.assertRaises(c_exc.PolicyProfileIdNotFound, - n1kv_db_v2.get_policy_profile, - db_session, - '00000000-0000-0000-0000-000000000004') - # Return 2 policy profiles - obj_inst.return_value = 2 - plugin._populate_policy_profiles() - # Verify that the third policy profile is deleted - self.assertRaises(c_exc.PolicyProfileIdNotFound, - n1kv_db_v2.get_policy_profile, - db_session, - '00000000-0000-0000-0000-000000000003') - - -class TestN1kvNetworks(test_plugin.TestNetworksV2, - N1kvPluginTestCase): - - def _prepare_net_data(self, net_profile_id): - return {'network': {'name': 'net1', - n1kv.PROFILE_ID: net_profile_id, - 'tenant_id': self.tenant_id}} - - def test_create_network_with_default_n1kv_network_profile_id(self): - """Test network create without passing network profile id.""" - with self.network() as network: - db_session = db.get_session() - np = n1kv_db_v2.get_network_profile( - db_session, network['network'][n1kv.PROFILE_ID]) - self.assertEqual(np['name'], 'default_network_profile') - - def test_create_network_with_n1kv_network_profile_id(self): - """Test network create with network profile id.""" - profile_obj = self._make_test_profile(name='test_profile') - data = self._prepare_net_data(profile_obj.id) - network_req = self.new_create_request('networks', data) - network = self.deserialize(self.fmt, - network_req.get_response(self.api)) - self.assertEqual(network['network'][n1kv.PROFILE_ID], - profile_obj.id) - - def test_update_network_with_n1kv_network_profile_id(self): - """Test network update failure while updating network profile id.""" - with self.network() as network: - data = {'network': {n1kv.PROFILE_ID: 'some-profile-uuid'}} - network_req = self.new_update_request('networks', - data, - network['network']['id']) - res = network_req.get_response(self.api) - # Network update should fail to update network profile id. - self.assertEqual(res.status_int, 400) - - -class TestN1kvSubnets(test_plugin.TestSubnetsV2, - N1kvPluginTestCase): - - def setUp(self): - super(TestN1kvSubnets, self).setUp() - - -class TestN1kvL3Test(test_l3_plugin.L3NatExtensionTestCase): - - pass - - -class TestN1kvL3SchedulersTest(test_l3_schedulers.L3SchedulerTestCase): - - pass diff --git a/neutron/tests/unit/cisco/test_config.py b/neutron/tests/unit/cisco/test_config.py deleted file mode 100644 index 7104ed06a..000000000 --- a/neutron/tests/unit/cisco/test_config.py +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (c) 2013 Cisco Systems Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import mock -from oslo.config import cfg - -from neutron.plugins.cisco.common import config as cisco_config -from neutron.tests import base - - -class TestCiscoNexusPluginConfig(base.BaseTestCase): - - def setUp(self): - # Point neutron config file to: neutron/tests/etc/neutron.conf.test - self.config_parse() - - super(TestCiscoNexusPluginConfig, self).setUp() - - def test_config_parse_error(self): - """Check that config error is raised upon config parser failure.""" - with mock.patch.object(cfg, 'MultiConfigParser') as parser: - parser.return_value.read.return_value = [] - self.assertRaises(cfg.Error, cisco_config.CiscoConfigOptions) - - def test_create_device_dictionary(self): - """Test creation of the device dictionary based on nexus config.""" - test_config = { - 'NEXUS_SWITCH:1.1.1.1': { - 'username': ['admin'], - 'password': ['mySecretPassword'], - 'ssh_port': [22], - 'compute1': ['1/1'], - 'compute2': ['1/2'], - }, - 'NEXUS_SWITCH:2.2.2.2': { - 'username': ['admin'], - 'password': ['mySecretPassword'], - 'ssh_port': [22], - 'compute3': ['1/1'], - 'compute4': ['1/2'], - }, - } - expected_dev_dict = { - ('NEXUS_SWITCH', '1.1.1.1', 'username'): 'admin', - ('NEXUS_SWITCH', '1.1.1.1', 'password'): 'mySecretPassword', - ('NEXUS_SWITCH', '1.1.1.1', 'ssh_port'): 22, - ('NEXUS_SWITCH', '1.1.1.1', 'compute1'): '1/1', - ('NEXUS_SWITCH', '1.1.1.1', 'compute2'): '1/2', - ('NEXUS_SWITCH', '2.2.2.2', 'username'): 'admin', - ('NEXUS_SWITCH', '2.2.2.2', 'password'): 'mySecretPassword', - ('NEXUS_SWITCH', '2.2.2.2', 'ssh_port'): 22, - ('NEXUS_SWITCH', '2.2.2.2', 'compute3'): '1/1', - ('NEXUS_SWITCH', '2.2.2.2', 'compute4'): '1/2', - } - with mock.patch.object(cfg, 'MultiConfigParser') as parser: - parser.return_value.read.return_value = cfg.CONF.config_file - parser.return_value.parsed = [test_config] - cisco_config.CiscoConfigOptions() - self.assertEqual(cisco_config.device_dictionary, - expected_dev_dict) diff --git a/neutron/tests/unit/cisco/test_network_db.py b/neutron/tests/unit/cisco/test_network_db.py deleted file mode 100644 index ef09c81c2..000000000 --- a/neutron/tests/unit/cisco/test_network_db.py +++ /dev/null @@ -1,291 +0,0 @@ -# Copyright (c) 2013 OpenStack Foundation -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import collections -import mock -import testtools - -from neutron.db import api as db -from neutron.plugins.cisco.common import cisco_constants -from neutron.plugins.cisco.common import cisco_credentials_v2 -from neutron.plugins.cisco.common import cisco_exceptions as c_exc -from neutron.plugins.cisco.common import config as config -from neutron.plugins.cisco.db import network_db_v2 as cdb -from neutron.plugins.cisco import network_plugin -from neutron.tests import base - - -class CiscoNetworkDbTest(base.BaseTestCase): - - """Base class for Cisco network database unit tests.""" - - def setUp(self): - super(CiscoNetworkDbTest, self).setUp() - db.configure_db() - - # The Cisco network plugin includes a thin layer of QoS and - # credential API methods which indirectly call Cisco QoS and - # credential database access methods. For better code coverage, - # this test suite will make calls to the QoS and credential database - # access methods indirectly through the network plugin. The network - # plugin's init function can be mocked out for this purpose. - def new_network_plugin_init(instance): - pass - with mock.patch.object(network_plugin.PluginV2, - '__init__', new=new_network_plugin_init): - self._network_plugin = network_plugin.PluginV2() - - self.addCleanup(db.clear_db) - - -class CiscoNetworkQosDbTest(CiscoNetworkDbTest): - - """Unit tests for Cisco network QoS database model.""" - - QosObj = collections.namedtuple('QosObj', 'tenant qname desc') - - def _qos_test_obj(self, tnum, qnum, desc=None): - """Create a Qos test object from a pair of numbers.""" - if desc is None: - desc = 'test qos %s-%s' % (str(tnum), str(qnum)) - tenant = 'tenant_%s' % str(tnum) - qname = 'qos_%s' % str(qnum) - return self.QosObj(tenant, qname, desc) - - def _assert_equal(self, qos, qos_obj): - self.assertEqual(qos.tenant_id, qos_obj.tenant) - self.assertEqual(qos.qos_name, qos_obj.qname) - self.assertEqual(qos.qos_desc, qos_obj.desc) - - def test_qos_add_remove(self): - qos11 = self._qos_test_obj(1, 1) - qos = self._network_plugin.create_qos(qos11.tenant, qos11.qname, - qos11.desc) - self._assert_equal(qos, qos11) - qos_id = qos.qos_id - qos = self._network_plugin.delete_qos(qos11.tenant, qos_id) - self._assert_equal(qos, qos11) - qos = self._network_plugin.delete_qos(qos11.tenant, qos_id) - self.assertIsNone(qos) - - def test_qos_add_dup(self): - qos22 = self._qos_test_obj(2, 2) - qos = self._network_plugin.create_qos(qos22.tenant, qos22.qname, - qos22.desc) - self._assert_equal(qos, qos22) - qos_id = qos.qos_id - with testtools.ExpectedException(c_exc.QosNameAlreadyExists): - self._network_plugin.create_qos(qos22.tenant, qos22.qname, - "duplicate 22") - qos = self._network_plugin.delete_qos(qos22.tenant, qos_id) - self._assert_equal(qos, qos22) - qos = self._network_plugin.delete_qos(qos22.tenant, qos_id) - self.assertIsNone(qos) - - def test_qos_get(self): - qos11 = self._qos_test_obj(1, 1) - qos11_id = self._network_plugin.create_qos(qos11.tenant, qos11.qname, - qos11.desc).qos_id - qos21 = self._qos_test_obj(2, 1) - qos21_id = self._network_plugin.create_qos(qos21.tenant, qos21.qname, - qos21.desc).qos_id - qos22 = self._qos_test_obj(2, 2) - qos22_id = self._network_plugin.create_qos(qos22.tenant, qos22.qname, - qos22.desc).qos_id - - qos = self._network_plugin.get_qos_details(qos11.tenant, qos11_id) - self._assert_equal(qos, qos11) - qos = self._network_plugin.get_qos_details(qos21.tenant, qos21_id) - self._assert_equal(qos, qos21) - qos = self._network_plugin.get_qos_details(qos21.tenant, qos22_id) - self._assert_equal(qos, qos22) - - with testtools.ExpectedException(c_exc.QosNotFound): - self._network_plugin.get_qos_details(qos11.tenant, "dummyQosId") - with testtools.ExpectedException(c_exc.QosNotFound): - self._network_plugin.get_qos_details(qos11.tenant, qos21_id) - with testtools.ExpectedException(c_exc.QosNotFound): - self._network_plugin.get_qos_details(qos21.tenant, qos11_id) - - qos_all_t1 = self._network_plugin.get_all_qoss(qos11.tenant) - self.assertEqual(len(qos_all_t1), 1) - qos_all_t2 = self._network_plugin.get_all_qoss(qos21.tenant) - self.assertEqual(len(qos_all_t2), 2) - qos_all_t3 = self._network_plugin.get_all_qoss("tenant3") - self.assertEqual(len(qos_all_t3), 0) - - def test_qos_update(self): - qos11 = self._qos_test_obj(1, 1) - qos11_id = self._network_plugin.create_qos(qos11.tenant, qos11.qname, - qos11.desc).qos_id - self._network_plugin.rename_qos(qos11.tenant, qos11_id, - new_name=None) - new_qname = "new qos name" - new_qos = self._network_plugin.rename_qos(qos11.tenant, qos11_id, - new_qname) - expected_qobj = self.QosObj(qos11.tenant, new_qname, qos11.desc) - self._assert_equal(new_qos, expected_qobj) - new_qos = self._network_plugin.get_qos_details(qos11.tenant, qos11_id) - self._assert_equal(new_qos, expected_qobj) - with testtools.ExpectedException(c_exc.QosNotFound): - self._network_plugin.rename_qos(qos11.tenant, "dummyQosId", - new_name=None) - - -class CiscoNetworkCredentialDbTest(CiscoNetworkDbTest): - - """Unit tests for Cisco network credentials database model.""" - - CredObj = collections.namedtuple('CredObj', 'cname usr pwd ctype') - - def _cred_test_obj(self, tnum, cnum): - """Create a Credential test object from a pair of numbers.""" - cname = 'credential_%s_%s' % (str(tnum), str(cnum)) - usr = 'User_%s_%s' % (str(tnum), str(cnum)) - pwd = 'Password_%s_%s' % (str(tnum), str(cnum)) - ctype = 'ctype_%s' % str(tnum) - return self.CredObj(cname, usr, pwd, ctype) - - def _assert_equal(self, credential, cred_obj): - self.assertEqual(credential.type, cred_obj.ctype) - self.assertEqual(credential.credential_name, cred_obj.cname) - self.assertEqual(credential.user_name, cred_obj.usr) - self.assertEqual(credential.password, cred_obj.pwd) - - def test_credential_add_remove(self): - cred11 = self._cred_test_obj(1, 1) - cred = cdb.add_credential( - cred11.cname, cred11.usr, cred11.pwd, cred11.ctype) - self._assert_equal(cred, cred11) - cred_id = cred.credential_id - cred = cdb.remove_credential(cred_id) - self._assert_equal(cred, cred11) - cred = cdb.remove_credential(cred_id) - self.assertIsNone(cred) - - def test_credential_add_dup(self): - cred22 = self._cred_test_obj(2, 2) - cred = cdb.add_credential( - cred22.cname, cred22.usr, cred22.pwd, cred22.ctype) - self._assert_equal(cred, cred22) - cred_id = cred.credential_id - with testtools.ExpectedException(c_exc.CredentialAlreadyExists): - cdb.add_credential( - cred22.cname, cred22.usr, cred22.pwd, cred22.ctype) - cred = cdb.remove_credential(cred_id) - self._assert_equal(cred, cred22) - cred = cdb.remove_credential(cred_id) - self.assertIsNone(cred) - - def test_credential_get_id(self): - cred11 = self._cred_test_obj(1, 1) - cred11_id = cdb.add_credential( - cred11.cname, cred11.usr, cred11.pwd, cred11.ctype).credential_id - cred21 = self._cred_test_obj(2, 1) - cred21_id = cdb.add_credential( - cred21.cname, cred21.usr, cred21.pwd, cred21.ctype).credential_id - cred22 = self._cred_test_obj(2, 2) - cred22_id = cdb.add_credential( - cred22.cname, cred22.usr, cred22.pwd, cred22.ctype).credential_id - - cred = self._network_plugin.get_credential_details(cred11_id) - self._assert_equal(cred, cred11) - cred = self._network_plugin.get_credential_details(cred21_id) - self._assert_equal(cred, cred21) - cred = self._network_plugin.get_credential_details(cred22_id) - self._assert_equal(cred, cred22) - - with testtools.ExpectedException(c_exc.CredentialNotFound): - self._network_plugin.get_credential_details("dummyCredentialId") - - cred_all_t1 = self._network_plugin.get_all_credentials() - self.assertEqual(len(cred_all_t1), 3) - - def test_credential_get_name(self): - cred11 = self._cred_test_obj(1, 1) - cred11_id = cdb.add_credential( - cred11.cname, cred11.usr, cred11.pwd, cred11.ctype).credential_id - cred21 = self._cred_test_obj(2, 1) - cred21_id = cdb.add_credential( - cred21.cname, cred21.usr, cred21.pwd, cred21.ctype).credential_id - cred22 = self._cred_test_obj(2, 2) - cred22_id = cdb.add_credential( - cred22.cname, cred22.usr, cred22.pwd, cred22.ctype).credential_id - self.assertNotEqual(cred11_id, cred21_id) - self.assertNotEqual(cred11_id, cred22_id) - self.assertNotEqual(cred21_id, cred22_id) - - cred = cdb.get_credential_name(cred11.cname) - self._assert_equal(cred, cred11) - cred = cdb.get_credential_name(cred21.cname) - self._assert_equal(cred, cred21) - cred = cdb.get_credential_name(cred22.cname) - self._assert_equal(cred, cred22) - - with testtools.ExpectedException(c_exc.CredentialNameNotFound): - cdb.get_credential_name("dummyCredentialName") - - def test_credential_update(self): - cred11 = self._cred_test_obj(1, 1) - cred11_id = cdb.add_credential( - cred11.cname, cred11.usr, cred11.pwd, cred11.ctype).credential_id - self._network_plugin.rename_credential(cred11_id, new_name=None, - new_password=None) - new_usr = "new user name" - new_pwd = "new password" - new_credential = self._network_plugin.rename_credential( - cred11_id, new_usr, new_pwd) - expected_cred = self.CredObj( - cred11.cname, new_usr, new_pwd, cred11.ctype) - self._assert_equal(new_credential, expected_cred) - new_credential = self._network_plugin.get_credential_details( - cred11_id) - self._assert_equal(new_credential, expected_cred) - with testtools.ExpectedException(c_exc.CredentialNotFound): - self._network_plugin.rename_credential( - "dummyCredentialId", new_usr, new_pwd) - - def test_get_credential_not_found_exception(self): - self.assertRaises(c_exc.CredentialNotFound, - self._network_plugin.get_credential_details, - "dummyCredentialId") - - -class CiscoCredentialStoreTest(base.BaseTestCase): - - """Cisco Credential Store unit tests.""" - - def setUp(self): - super(CiscoCredentialStoreTest, self).setUp() - db.configure_db() - self.addCleanup(db.clear_db) - - def test_cred_store_init_duplicate_creds_ignored(self): - """Check that with multi store instances, dup creds are ignored.""" - # Create a device dictionary containing credentials for 1 switch. - dev_dict = { - ('dev_id', '1.1.1.1', cisco_constants.USERNAME): 'user_1', - ('dev_id', '1.1.1.1', cisco_constants.PASSWORD): 'password_1', - ('dev_id', '1.1.1.1', 'host_a'): '1/1', - ('dev_id', '1.1.1.1', 'host_b'): '1/2', - ('dev_id', '1.1.1.1', 'host_c'): '1/3', - } - with mock.patch.object(config, 'get_device_dictionary', - return_value=dev_dict): - # Create and initialize 2 instances of credential store. - cisco_credentials_v2.Store().initialize() - cisco_credentials_v2.Store().initialize() - # There should be only 1 switch credential in the database. - self.assertEqual(len(cdb.get_all_credentials()), 1) diff --git a/neutron/tests/unit/cisco/test_network_plugin.py b/neutron/tests/unit/cisco/test_network_plugin.py deleted file mode 100644 index 4e7be3e87..000000000 --- a/neutron/tests/unit/cisco/test_network_plugin.py +++ /dev/null @@ -1,1186 +0,0 @@ -# Copyright (c) 2012 OpenStack Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import contextlib -import copy -import inspect -import logging -import mock - -import six -import webob.exc as wexc - -from neutron.api import extensions -from neutron.api.v2 import attributes -from neutron.api.v2 import base -from neutron.common import exceptions as n_exc -from neutron import context -from neutron.db import db_base_plugin_v2 as base_plugin -from neutron.db import l3_db -from neutron.extensions import portbindings -from neutron.extensions import providernet as provider -from neutron import manager -from neutron.openstack.common import gettextutils -from neutron.plugins.cisco.common import cisco_constants as const -from neutron.plugins.cisco.common import cisco_exceptions as c_exc -from neutron.plugins.cisco.common import config as cisco_config -from neutron.plugins.cisco.db import network_db_v2 -from neutron.plugins.cisco.db import nexus_db_v2 -from neutron.plugins.cisco.models import virt_phy_sw_v2 -from neutron.plugins.openvswitch.common import config as ovs_config -from neutron.plugins.openvswitch import ovs_db_v2 -from neutron.tests.unit import _test_extension_portbindings as test_bindings -from neutron.tests.unit import test_db_plugin -from neutron.tests.unit import test_extensions - -LOG = logging.getLogger(__name__) -CORE_PLUGIN = 'neutron.plugins.cisco.network_plugin.PluginV2' -NEXUS_PLUGIN = 'neutron.plugins.cisco.nexus.cisco_nexus_plugin_v2.NexusPlugin' -NEXUS_DRIVER = ('neutron.plugins.cisco.nexus.' - 'cisco_nexus_network_driver_v2.CiscoNEXUSDriver') -PHYS_NET = 'physnet1' -BRIDGE_NAME = 'br-eth1' -VLAN_START = 1000 -VLAN_END = 1100 -COMP_HOST_NAME = 'testhost' -COMP_HOST_NAME_2 = 'testhost_2' -NEXUS_IP_ADDR = '1.1.1.1' -NEXUS_DEV_ID = 'NEXUS_SWITCH' -NEXUS_USERNAME = 'admin' -NEXUS_PASSWORD = 'mySecretPassword' -NEXUS_SSH_PORT = 22 -NEXUS_INTERFACE = '1/1' -NEXUS_INTERFACE_2 = '1/2' -NEXUS_PORT_1 = 'ethernet:1/1' -NEXUS_PORT_2 = 'ethernet:1/2' -NETWORK_NAME = 'test_network' -CIDR_1 = '10.0.0.0/24' -CIDR_2 = '10.0.1.0/24' -DEVICE_ID_1 = '11111111-1111-1111-1111-111111111111' -DEVICE_ID_2 = '22222222-2222-2222-2222-222222222222' -DEVICE_OWNER = 'compute:None' - - -class CiscoNetworkPluginV2TestCase(test_db_plugin.NeutronDbPluginV2TestCase): - - def setUp(self): - """Configure for end-to-end neutron testing using a mock ncclient. - - This setup includes: - - Configure the OVS plugin to use VLANs in the range of - VLAN_START-VLAN_END. - - Configure the Cisco plugin model to use the Nexus driver. - - Configure the Nexus driver to use an imaginary switch - at NEXUS_IP_ADDR. - - """ - # Configure the OVS and Cisco plugins - phys_bridge = ':'.join([PHYS_NET, BRIDGE_NAME]) - phys_vlan_range = ':'.join([PHYS_NET, str(VLAN_START), str(VLAN_END)]) - config = { - ovs_config: { - 'OVS': {'bridge_mappings': phys_bridge, - 'network_vlan_ranges': [phys_vlan_range], - 'tenant_network_type': 'vlan'} - }, - cisco_config: { - 'CISCO': {'nexus_driver': NEXUS_DRIVER}, - 'CISCO_PLUGINS': {'nexus_plugin': NEXUS_PLUGIN}, - } - } - for module in config: - for group in config[module]: - for opt, val in config[module][group].items(): - module.cfg.CONF.set_override(opt, val, group) - - # Configure the Nexus switch dictionary - # TODO(Henry): add tests for other devices - nexus_config = { - (NEXUS_DEV_ID, NEXUS_IP_ADDR, 'username'): NEXUS_USERNAME, - (NEXUS_DEV_ID, NEXUS_IP_ADDR, 'password'): NEXUS_PASSWORD, - (NEXUS_DEV_ID, NEXUS_IP_ADDR, 'ssh_port'): NEXUS_SSH_PORT, - (NEXUS_DEV_ID, NEXUS_IP_ADDR, COMP_HOST_NAME): NEXUS_INTERFACE, - (NEXUS_DEV_ID, NEXUS_IP_ADDR, COMP_HOST_NAME_2): NEXUS_INTERFACE_2, - } - nexus_patch = mock.patch.dict(cisco_config.device_dictionary, - nexus_config) - nexus_patch.start() - self.addCleanup(nexus_patch.stop) - - # Use a mock netconf client - self.mock_ncclient = mock.Mock() - ncclient_patch = mock.patch.dict('sys.modules', - {'ncclient': self.mock_ncclient}) - ncclient_patch.start() - self.addCleanup(ncclient_patch.stop) - - # Call the parent setUp, start the core plugin - super(CiscoNetworkPluginV2TestCase, self).setUp(CORE_PLUGIN) - self.port_create_status = 'DOWN' - - # Set Cisco config module's first configured Nexus IP address. - # Used for SVI placement when round-robin placement is disabled. - mock.patch.object(cisco_config, 'first_device_ip', - new=NEXUS_IP_ADDR).start() - - def _get_plugin_ref(self): - return getattr(manager.NeutronManager.get_plugin(), - "_model")._plugins[const.VSWITCH_PLUGIN] - - @contextlib.contextmanager - def _patch_ncclient(self, attr, value): - """Configure an attribute on the mock ncclient module. - - This method can be used to inject errors by setting a side effect - or a return value for an ncclient method. - - :param attr: ncclient attribute (typically method) to be configured. - :param value: Value to be configured on the attribute. - - """ - # Configure attribute. - config = {attr: value} - self.mock_ncclient.configure_mock(**config) - # Continue testing - yield - # Unconfigure attribute - config = {attr: None} - self.mock_ncclient.configure_mock(**config) - - @staticmethod - def _config_dependent_side_effect(match_config, exc): - """Generates a config-dependent side effect for ncclient edit_config. - - This method generates a mock side-effect function which can be - configured on the mock ncclient module for the edit_config method. - This side effect will cause a given exception to be raised whenever - the XML config string that is passed to edit_config contains all - words in a given match config string. - - :param match_config: String containing keywords to be matched - :param exc: Exception to be raised when match is found - :return: Side effect function for the mock ncclient module's - edit_config method. - - """ - keywords = match_config.split() - - def _side_effect_function(target, config): - if all(word in config for word in keywords): - raise exc - return _side_effect_function - - def _is_in_nexus_cfg(self, words): - """Check if any config sent to Nexus contains all words in a list.""" - for call in (self.mock_ncclient.manager.connect.return_value. - edit_config.mock_calls): - configlet = call[2]['config'] - if all(word in configlet for word in words): - return True - return False - - def _is_in_last_nexus_cfg(self, words): - """Check if last config sent to Nexus contains all words in a list.""" - last_cfg = (self.mock_ncclient.manager.connect.return_value. - edit_config.mock_calls[-1][2]['config']) - return all(word in last_cfg for word in words) - - def _is_vlan_configured(self, vlan_creation_expected=True, - add_keyword_expected=False): - vlan_created = self._is_in_nexus_cfg(['vlan', 'vlan-name']) - add_appears = self._is_in_last_nexus_cfg(['add']) - return (self._is_in_last_nexus_cfg(['allowed', 'vlan']) and - vlan_created == vlan_creation_expected and - add_appears == add_keyword_expected) - - def _is_vlan_unconfigured(self, vlan_deletion_expected=True, - vlan_untrunk_expected=True): - vlan_deleted = self._is_in_nexus_cfg( - ['no', 'vlan', 'vlan-id-create-delete']) - vlan_untrunked = self._is_in_nexus_cfg(['allowed', 'vlan', 'remove']) - return (vlan_deleted == vlan_deletion_expected and - vlan_untrunked == vlan_untrunk_expected) - - def _assertExpectedHTTP(self, status, exc): - """Confirm that an HTTP status corresponds to an expected exception. - - Confirm that an HTTP status which has been returned for an - neutron API request matches the HTTP status corresponding - to an expected exception. - - :param status: HTTP status - :param exc: Expected exception - - """ - if exc in base.FAULT_MAP: - expected_http = base.FAULT_MAP[exc].code - else: - expected_http = wexc.HTTPInternalServerError.code - self.assertEqual(status, expected_http) - - -class TestCiscoGetAttribute(CiscoNetworkPluginV2TestCase): - - def test_get_unsupported_attr_in_lazy_gettext_mode(self): - """Test get of unsupported attribute in lazy gettext mode. - - This test also checks that this operation does not cause - excessive nesting of calls to deepcopy. - """ - plugin = manager.NeutronManager.get_plugin() - - def _lazy_gettext(msg): - return gettextutils.Message(msg, domain='neutron') - - with mock.patch.dict(six.moves.builtins.__dict__, - {'_': _lazy_gettext}): - self.nesting_count = 0 - - def _count_nesting(*args, **kwargs): - self.nesting_count += 1 - - with mock.patch.object(copy, 'deepcopy', - side_effect=_count_nesting, - wraps=copy.deepcopy): - self.assertRaises(AttributeError, getattr, plugin, - 'an_unsupported_attribute') - # If there were no nested calls to deepcopy, then the total - # number of calls to deepcopy should be 2 (1 call for - # each mod'd field in the AttributeError message raised - # by the plugin). - self.assertEqual(self.nesting_count, 2) - - -class TestCiscoBasicGet(CiscoNetworkPluginV2TestCase, - test_db_plugin.TestBasicGet): - pass - - -class TestCiscoV2HTTPResponse(CiscoNetworkPluginV2TestCase, - test_db_plugin.TestV2HTTPResponse): - pass - - -class TestCiscoPortsV2(CiscoNetworkPluginV2TestCase, - test_db_plugin.TestPortsV2, - test_bindings.PortBindingsHostTestCaseMixin): - - @contextlib.contextmanager - def _create_port_res(self, name=NETWORK_NAME, cidr=CIDR_1, - do_delete=True, host_id=COMP_HOST_NAME): - """Create a network, subnet, and port and yield the result. - - Create a network, subnet, and port, yield the result, - then delete the port, subnet, and network. - - :param name: Name of network to be created - :param cidr: cidr address of subnetwork to be created - :param do_delete: If set to True, delete the port at the - end of testing - :param host_id: Name of compute host to use for testing - - """ - ctx = context.get_admin_context() - with self.network(name=name) as network: - with self.subnet(network=network, cidr=cidr) as subnet: - net_id = subnet['subnet']['network_id'] - args = (portbindings.HOST_ID, 'device_id', 'device_owner') - port_dict = {portbindings.HOST_ID: host_id, - 'device_id': DEVICE_ID_1, - 'device_owner': DEVICE_OWNER} - res = self._create_port(self.fmt, net_id, arg_list=args, - context=ctx, **port_dict) - port = self.deserialize(self.fmt, res) - yield res - if do_delete: - self._delete('ports', port['port']['id']) - - def test_create_ports_bulk_emulated_plugin_failure(self): - real_has_attr = hasattr - - #ensures the API choose the emulation code path - def fakehasattr(item, attr): - if attr.endswith('__native_bulk_support'): - return False - return real_has_attr(item, attr) - - with mock.patch('__builtin__.hasattr', - new=fakehasattr): - plugin_ref = self._get_plugin_ref() - orig = plugin_ref.create_port - with mock.patch.object(plugin_ref, - 'create_port') as patched_plugin: - - def side_effect(*args, **kwargs): - return self._do_side_effect(patched_plugin, orig, - *args, **kwargs) - - patched_plugin.side_effect = side_effect - with self.network() as net: - res = self._create_port_bulk(self.fmt, 2, - net['network']['id'], - 'test', - True) - # Expect an internal server error as we injected a fault - self._validate_behavior_on_bulk_failure( - res, - 'ports', - wexc.HTTPInternalServerError.code) - - def test_create_ports_bulk_native(self): - if self._skip_native_bulk: - self.skipTest("Plugin does not support native bulk port create") - - def test_create_ports_bulk_emulated(self): - if self._skip_native_bulk: - self.skipTest("Plugin does not support native bulk port create") - - def test_create_ports_bulk_native_plugin_failure(self): - if self._skip_native_bulk: - self.skipTest("Plugin does not support native bulk port create") - ctx = context.get_admin_context() - with self.network() as net: - plugin_ref = self._get_plugin_ref() - orig = plugin_ref.create_port - with mock.patch.object(plugin_ref, - 'create_port') as patched_plugin: - - def side_effect(*args, **kwargs): - return self._do_side_effect(patched_plugin, orig, - *args, **kwargs) - - patched_plugin.side_effect = side_effect - res = self._create_port_bulk(self.fmt, 2, - net['network']['id'], - 'test', True, context=ctx) - # We expect an internal server error as we injected a fault - self._validate_behavior_on_bulk_failure( - res, - 'ports', - wexc.HTTPInternalServerError.code) - - def test_nexus_enable_vlan_cmd(self): - """Verify the syntax of the command to enable a vlan on an intf.""" - - # First vlan should be configured without 'add' keyword - with self._create_port_res(name='net1', cidr=CIDR_1): - self.assertTrue(self._is_vlan_configured( - vlan_creation_expected=True, - add_keyword_expected=False)) - self.mock_ncclient.reset_mock() - - # Second vlan should be configured with 'add' keyword - with self._create_port_res(name='net2', cidr=CIDR_2): - self.assertTrue(self._is_vlan_configured( - vlan_creation_expected=True, - add_keyword_expected=True)) - - def test_nexus_vlan_config_two_hosts(self): - """Verify config/unconfig of vlan on two compute hosts.""" - - @contextlib.contextmanager - def _create_port_check_vlan(comp_host_name, device_id, - vlan_creation_expected=True): - arg_list = (portbindings.HOST_ID,) - port_dict = {portbindings.HOST_ID: comp_host_name, - 'device_id': device_id, - 'device_owner': DEVICE_OWNER} - with self.port(subnet=subnet, fmt=self.fmt, - arg_list=arg_list, **port_dict): - self.assertTrue(self._is_vlan_configured( - vlan_creation_expected=vlan_creation_expected, - add_keyword_expected=False)) - self.mock_ncclient.reset_mock() - yield - - # Create network and subnet - with self.network(name=NETWORK_NAME) as network: - with self.subnet(network=network, cidr=CIDR_1) as subnet: - - # Create an instance on first compute host - with _create_port_check_vlan( - COMP_HOST_NAME, DEVICE_ID_1, vlan_creation_expected=True): - - # Create an instance on second compute host - with _create_port_check_vlan( - COMP_HOST_NAME_2, DEVICE_ID_2, - vlan_creation_expected=False): - pass - - # Instance on second host is now terminated. - # Vlan should be untrunked from port, but vlan should - # still exist on the switch. - self.assertTrue(self._is_vlan_unconfigured( - vlan_deletion_expected=False)) - self.mock_ncclient.reset_mock() - - # Instance on first host is now terminated. - # Vlan should be untrunked from port and vlan should have - # been deleted from the switch. - self.assertTrue(self._is_vlan_unconfigured( - vlan_deletion_expected=True)) - - def test_nexus_connect_fail(self): - """Test failure to connect to a Nexus switch. - - While creating a network, subnet, and port, simulate a connection - failure to a nexus switch. Confirm that the expected HTTP code - is returned for the create port operation. - - """ - with self._patch_ncclient('manager.connect.side_effect', - AttributeError): - with self._create_port_res(do_delete=False) as res: - self._assertExpectedHTTP(res.status_int, - c_exc.NexusConnectFailed) - - def test_nexus_config_fail(self): - """Test a Nexus switch configuration failure. - - While creating a network, subnet, and port, simulate a nexus - switch configuration error. Confirm that the expected HTTP code - is returned for the create port operation. - - """ - with self._patch_ncclient( - 'manager.connect.return_value.edit_config.side_effect', - AttributeError): - with self._create_port_res(do_delete=False) as res: - self._assertExpectedHTTP(res.status_int, - c_exc.NexusConfigFailed) - - def test_nexus_extended_vlan_range_failure(self): - """Test that extended VLAN range config errors are ignored. - - Some versions of Nexus switch do not allow state changes for - the extended VLAN range (1006-4094), but these errors can be - ignored (default values are appropriate). Test that such errors - are ignored by the Nexus plugin. - - """ - config_err_strings = { - "state active": "Can't modify state for extended", - "no shutdown": "Command is only allowed on VLAN", - } - for config, err_string in config_err_strings.items(): - with self._patch_ncclient( - 'manager.connect.return_value.edit_config.side_effect', - self._config_dependent_side_effect(config, - Exception(err_string))): - with self._create_port_res() as res: - self.assertEqual(res.status_int, wexc.HTTPCreated.code) - - def test_nexus_vlan_config_rollback(self): - """Test rollback following Nexus VLAN state config failure. - - Test that the Cisco Nexus plugin correctly deletes the VLAN - on the Nexus switch when the 'state active' command fails (for - a reason other than state configuration change is rejected - for the extended VLAN range). - - """ - vlan_state_configs = ['state active', 'no shutdown'] - for config in vlan_state_configs: - with self._patch_ncclient( - 'manager.connect.return_value.edit_config.side_effect', - self._config_dependent_side_effect(config, ValueError)): - with self._create_port_res(do_delete=False) as res: - # Confirm that the last configuration sent to the Nexus - # switch was deletion of the VLAN. - self.assertTrue( - self._is_in_last_nexus_cfg(['', '']) - ) - self._assertExpectedHTTP(res.status_int, - c_exc.NexusConfigFailed) - - def test_get_seg_id_fail(self): - """Test handling of a NetworkSegmentIDNotFound exception. - - Test the Cisco NetworkSegmentIDNotFound exception by simulating - a return of None by the OVS DB get_network_binding method - during port creation. - - """ - orig = ovs_db_v2.get_network_binding - - def _return_none_if_nexus_caller(self, *args, **kwargs): - def _calling_func_name(offset=0): - """Get name of the calling function 'offset' frames back.""" - return inspect.stack()[1 + offset][3] - if (_calling_func_name(1) == '_get_segmentation_id' and - _calling_func_name(2) == '_invoke_nexus_for_net_create'): - return None - else: - return orig(self, *args, **kwargs) - - with mock.patch.object(ovs_db_v2, 'get_network_binding', - new=_return_none_if_nexus_caller): - with self._create_port_res(do_delete=False) as res: - self._assertExpectedHTTP(res.status_int, - c_exc.NetworkSegmentIDNotFound) - - def test_nexus_host_non_configured(self): - """Test handling of a NexusComputeHostNotConfigured exception. - - Test the Cisco NexusComputeHostNotConfigured exception by using - a fictitious host name during port creation. - - """ - with self._create_port_res(do_delete=False, - host_id='fakehost') as res: - self._assertExpectedHTTP(res.status_int, - c_exc.NexusComputeHostNotConfigured) - - def _check_rollback_on_bind_failure(self, - vlan_deletion_expected, - vlan_untrunk_expected): - """Test for proper rollback following add Nexus DB binding failure. - - Test that the Cisco Nexus plugin correctly rolls back the vlan - configuration on the Nexus switch when add_nexusport_binding fails - within the plugin's create_port() method. - - """ - inserted_exc = KeyError - with mock.patch.object(nexus_db_v2, 'add_nexusport_binding', - side_effect=inserted_exc): - with self._create_port_res(do_delete=False) as res: - # Confirm that the configuration sent to the Nexus - # switch includes deletion of the vlan (if expected) - # and untrunking of the vlan from the ethernet interface - # (if expected). - self.assertTrue(self._is_vlan_unconfigured( - vlan_deletion_expected=vlan_deletion_expected, - vlan_untrunk_expected=vlan_untrunk_expected)) - self._assertExpectedHTTP(res.status_int, inserted_exc) - - def test_nexus_rollback_on_bind_failure_non_provider_vlan(self): - """Test rollback upon DB binding failure for non-provider vlan.""" - self._check_rollback_on_bind_failure(vlan_deletion_expected=True, - vlan_untrunk_expected=True) - - def test_nexus_rollback_on_bind_failure_prov_vlan_no_auto_create(self): - """Test rollback on bind fail for prov vlan w auto-create disabled.""" - with mock.patch.object(network_db_v2, 'is_provider_vlan', - return_value=True): - # Disable auto-create. This config change will be cleared based - # on cleanup scheduled in the CiscoNetworkPluginV2TestCase - # class' setUp() method. - cisco_config.CONF.set_override('provider_vlan_auto_create', - False, 'CISCO') - self._check_rollback_on_bind_failure(vlan_deletion_expected=False, - vlan_untrunk_expected=True) - - def test_nexus_rollback_on_bind_failure_prov_vlan_no_auto_trunk(self): - """Test rollback on bind fail for prov vlan w auto-trunk disabled.""" - with mock.patch.object(network_db_v2, 'is_provider_vlan', - return_value=True): - # Disable auto-trunk. This config change will be cleared - # based on post-test cleanup scheduled in the - # CiscoNetworkPluginV2TestCase class' setUp() method. - cisco_config.CONF.set_override('provider_vlan_auto_trunk', - False, 'CISCO') - self._check_rollback_on_bind_failure(vlan_deletion_expected=True, - vlan_untrunk_expected=False) - - def test_model_update_port_rollback(self): - """Test for proper rollback for Cisco model layer update port failure. - - Test that the vSwitch plugin port configuration is rolled back - (restored) by the Cisco plugin model layer when there is a - failure in the Nexus sub-plugin for an update port operation. - - The update port operation simulates a port attachment scenario: - first a port is created with no instance (null device_id), - and then a port update is requested with a non-null device_id - to simulate the port attachment. - - """ - with self.port(fmt=self.fmt, device_id='', - device_owner=DEVICE_OWNER) as orig_port: - - inserted_exc = ValueError - with mock.patch.object( - virt_phy_sw_v2.VirtualPhysicalSwitchModelV2, - '_invoke_nexus_for_net_create', - side_effect=inserted_exc): - - # Send an update port request including a non-null device ID - data = {'port': {'device_id': DEVICE_ID_2, - 'device_owner': DEVICE_OWNER, - portbindings.HOST_ID: COMP_HOST_NAME}} - port_id = orig_port['port']['id'] - req = self.new_update_request('ports', data, port_id) - res = req.get_response(self.api) - - # Sanity check failure result code - self._assertExpectedHTTP(res.status_int, inserted_exc) - - # Check that the port still has the original device ID - plugin = base_plugin.NeutronDbPluginV2() - ctx = context.get_admin_context() - db_port = plugin._get_port(ctx, port_id) - self.assertEqual(db_port['device_id'], - orig_port['port']['device_id']) - - def test_model_delete_port_rollback(self): - """Test for proper rollback for OVS plugin delete port failure. - - Test that the nexus port configuration is rolled back (restored) - by the Cisco model plugin when there is a failure in the OVS - plugin for a delete port operation. - - """ - with self._create_port_res() as res: - - # After port is created, we should have one binding for this - # vlan/nexus switch. - port = self.deserialize(self.fmt, res) - start_rows = nexus_db_v2.get_nexusvlan_binding(VLAN_START, - NEXUS_IP_ADDR) - self.assertEqual(len(start_rows), 1) - - # Inject an exception in the OVS plugin delete_port - # processing, and attempt a port deletion. - inserted_exc = n_exc.Conflict - expected_http = base.FAULT_MAP[inserted_exc].code - with mock.patch.object(l3_db.L3_NAT_db_mixin, - 'disassociate_floatingips', - side_effect=inserted_exc): - self._delete('ports', port['port']['id'], - expected_code=expected_http) - - # Confirm that the Cisco model plugin has restored - # the nexus configuration for this port after deletion failure. - end_rows = nexus_db_v2.get_nexusvlan_binding(VLAN_START, - NEXUS_IP_ADDR) - self.assertEqual(start_rows, end_rows) - - def test_nexus_delete_port_rollback(self): - """Test for proper rollback for nexus plugin delete port failure. - - Test for rollback (i.e. restoration) of a VLAN entry in the - nexus database whenever the nexus plugin fails to reconfigure the - nexus switch during a delete_port operation. - - """ - with self._create_port_res() as res: - - port = self.deserialize(self.fmt, res) - - # Check that there is only one binding in the nexus database - # for this VLAN/nexus switch. - start_rows = nexus_db_v2.get_nexusvlan_binding(VLAN_START, - NEXUS_IP_ADDR) - self.assertEqual(len(start_rows), 1) - - # Simulate a Nexus switch configuration error during - # port deletion. - with self._patch_ncclient( - 'manager.connect.return_value.edit_config.side_effect', - AttributeError): - self._delete('ports', port['port']['id'], - base.FAULT_MAP[c_exc.NexusConfigFailed].code) - - # Confirm that the binding has been restored (rolled back). - end_rows = nexus_db_v2.get_nexusvlan_binding(VLAN_START, - NEXUS_IP_ADDR) - self.assertEqual(start_rows, end_rows) - - def test_model_update_port_attach(self): - """Test the model for update_port in attaching to an instance. - - Mock the routines that call into the plugin code, and make sure they - are called with correct arguments. - - """ - with contextlib.nested( - self.port(), - mock.patch.object(virt_phy_sw_v2.VirtualPhysicalSwitchModelV2, - '_invoke_plugin_per_device'), - mock.patch.object(virt_phy_sw_v2.VirtualPhysicalSwitchModelV2, - '_invoke_nexus_for_net_create') - ) as (port, invoke_plugin_per_device, invoke_nexus_for_net_create): - data = {'port': {portbindings.HOST_ID: COMP_HOST_NAME, - 'device_id': DEVICE_ID_1, - 'device_owner': DEVICE_OWNER}} - - req = self.new_update_request('ports', data, port['port']['id']) - # Note, due to mocking out the two model routines, response won't - # contain any useful data - req.get_response(self.api) - - # Note that call_args_list is used instead of - # assert_called_once_with which requires exact match of arguments. - # This is because the mocked routines contain variable number of - # arguments and/or dynamic objects. - self.assertEqual(invoke_plugin_per_device.call_count, 1) - self.assertEqual( - invoke_plugin_per_device.call_args_list[0][0][0:2], - (const.VSWITCH_PLUGIN, 'update_port')) - self.assertEqual(invoke_nexus_for_net_create.call_count, 1) - self.assertEqual( - invoke_nexus_for_net_create.call_args_list[0][0][1:], - (port['port']['tenant_id'], port['port']['network_id'], - data['port']['device_id'], - data['port'][portbindings.HOST_ID],)) - - def test_model_update_port_migrate(self): - """Test the model for update_port in migrating an instance. - - Mock the routines that call into the plugin code, and make sure they - are called with correct arguments. - - """ - arg_list = (portbindings.HOST_ID,) - data = {portbindings.HOST_ID: COMP_HOST_NAME, - 'device_id': DEVICE_ID_1, - 'device_owner': DEVICE_OWNER} - - with contextlib.nested( - self.port(arg_list=arg_list, **data), - mock.patch.object(virt_phy_sw_v2.VirtualPhysicalSwitchModelV2, - '_invoke_plugin_per_device'), - mock.patch.object(virt_phy_sw_v2.VirtualPhysicalSwitchModelV2, - '_invoke_nexus_for_net_create') - ) as (port, invoke_plugin_per_device, invoke_nexus_for_net_create): - data = {'port': {portbindings.HOST_ID: COMP_HOST_NAME_2}} - req = self.new_update_request('ports', data, port['port']['id']) - # Note, due to mocking out the two model routines, response won't - # contain any useful data - req.get_response(self.api) - - # Note that call_args_list is used instead of - # assert_called_once_with which requires exact match of arguments. - # This is because the mocked routines contain variable number of - # arguments and/or dynamic objects. - self.assertEqual(invoke_plugin_per_device.call_count, 2) - self.assertEqual( - invoke_plugin_per_device.call_args_list[0][0][0:2], - (const.VSWITCH_PLUGIN, 'update_port')) - self.assertEqual( - invoke_plugin_per_device.call_args_list[1][0][0:2], - (const.NEXUS_PLUGIN, 'delete_port')) - self.assertEqual(invoke_nexus_for_net_create.call_count, 1) - self.assertEqual( - invoke_nexus_for_net_create.call_args_list[0][0][1:], - (port['port']['tenant_id'], port['port']['network_id'], - port['port']['device_id'], - data['port'][portbindings.HOST_ID],)) - - def test_model_update_port_net_create_not_needed(self): - """Test the model for update_port when no action is needed. - - Mock the routines that call into the plugin code, and make sure that - VSWITCH plugin is called with correct arguments, while NEXUS plugin is - not called at all. - - """ - arg_list = (portbindings.HOST_ID,) - data = {portbindings.HOST_ID: COMP_HOST_NAME, - 'device_id': DEVICE_ID_1, - 'device_owner': DEVICE_OWNER} - - with contextlib.nested( - self.port(arg_list=arg_list, **data), - mock.patch.object(virt_phy_sw_v2.VirtualPhysicalSwitchModelV2, - '_invoke_plugin_per_device'), - mock.patch.object(virt_phy_sw_v2.VirtualPhysicalSwitchModelV2, - '_invoke_nexus_for_net_create') - ) as (port, invoke_plugin_per_device, invoke_nexus_for_net_create): - data = {'port': {portbindings.HOST_ID: COMP_HOST_NAME, - 'device_id': DEVICE_ID_1, - 'device_owner': DEVICE_OWNER}} - req = self.new_update_request('ports', data, port['port']['id']) - # Note, due to mocking out the two model routines, response won't - # contain any useful data - req.get_response(self.api) - - # Note that call_args_list is used instead of - # assert_called_once_with which requires exact match of arguments. - # This is because the mocked routines contain variable number of - # arguments and/or dynamic objects. - self.assertEqual(invoke_plugin_per_device.call_count, 1) - self.assertEqual( - invoke_plugin_per_device.call_args_list[0][0][0:2], - (const.VSWITCH_PLUGIN, 'update_port')) - self.assertFalse(invoke_nexus_for_net_create.called) - - def verify_portbinding(self, host_id1, host_id2, - vlan, device_id, binding_port): - """Verify a port binding entry in the DB is correct.""" - self.assertEqual(host_id1, host_id2) - pb = nexus_db_v2.get_nexusvm_bindings(vlan, device_id) - self.assertEqual(len(pb), 1) - self.assertEqual(pb[0].port_id, binding_port) - self.assertEqual(pb[0].switch_ip, NEXUS_IP_ADDR) - - def test_db_update_port_attach(self): - """Test DB for update_port in attaching to an instance. - - Query DB for the port binding entry corresponding to the search key - (vlan, device_id), and make sure that it's bound to correct switch port - - """ - with self.port() as port: - data = {'port': {portbindings.HOST_ID: COMP_HOST_NAME, - 'device_id': DEVICE_ID_1, - 'device_owner': DEVICE_OWNER}} - - req = self.new_update_request('ports', data, port['port']['id']) - res = self.deserialize(self.fmt, req.get_response(self.api)) - ctx = context.get_admin_context() - net = self._show('networks', res['port']['network_id'], - neutron_context=ctx)['network'] - self.assertTrue(attributes.is_attr_set( - net.get(provider.SEGMENTATION_ID))) - vlan = net[provider.SEGMENTATION_ID] - self.assertEqual(vlan, VLAN_START) - self.verify_portbinding(res['port'][portbindings.HOST_ID], - data['port'][portbindings.HOST_ID], - vlan, - data['port']['device_id'], - NEXUS_PORT_1) - - def test_db_update_port_migrate(self): - """Test DB for update_port in migrating an instance. - - Query DB for the port binding entry corresponding to the search key - (vlan, device_id), and make sure that it's bound to correct switch port - before and after the migration. - - """ - arg_list = (portbindings.HOST_ID,) - data = {portbindings.HOST_ID: COMP_HOST_NAME, - 'device_id': DEVICE_ID_1, - 'device_owner': DEVICE_OWNER} - - with self.port(arg_list=arg_list, **data) as port: - ctx = context.get_admin_context() - net = self._show('networks', port['port']['network_id'], - neutron_context=ctx)['network'] - self.assertTrue(attributes.is_attr_set( - net.get(provider.SEGMENTATION_ID))) - vlan = net[provider.SEGMENTATION_ID] - self.assertEqual(vlan, VLAN_START) - self.verify_portbinding(port['port'][portbindings.HOST_ID], - data[portbindings.HOST_ID], - vlan, - data['device_id'], - NEXUS_PORT_1) - - new_data = {'port': {portbindings.HOST_ID: COMP_HOST_NAME_2}} - req = self.new_update_request('ports', - new_data, port['port']['id']) - res = self.deserialize(self.fmt, req.get_response(self.api)) - self.verify_portbinding(res['port'][portbindings.HOST_ID], - new_data['port'][portbindings.HOST_ID], - vlan, - data['device_id'], - NEXUS_PORT_2) - - def test_delete_ports_by_device_id_second_call_failure(self): - plugin_ref = self._get_plugin_ref() - self._test_delete_ports_by_device_id_second_call_failure(plugin_ref) - - def test_delete_ports_ignores_port_not_found(self): - plugin_ref = self._get_plugin_ref() - self._test_delete_ports_ignores_port_not_found(plugin_ref) - - -class TestCiscoNetworksV2(CiscoNetworkPluginV2TestCase, - test_db_plugin.TestNetworksV2): - - def test_create_networks_bulk_emulated_plugin_failure(self): - real_has_attr = hasattr - - def fakehasattr(item, attr): - if attr.endswith('__native_bulk_support'): - return False - return real_has_attr(item, attr) - - plugin_ref = self._get_plugin_ref() - orig = plugin_ref.create_network - #ensures the API choose the emulation code path - with mock.patch('__builtin__.hasattr', - new=fakehasattr): - with mock.patch.object(plugin_ref, - 'create_network') as patched_plugin: - def side_effect(*args, **kwargs): - return self._do_side_effect(patched_plugin, orig, - *args, **kwargs) - patched_plugin.side_effect = side_effect - res = self._create_network_bulk(self.fmt, 2, 'test', True) - LOG.debug("response is %s" % res) - # We expect an internal server error as we injected a fault - self._validate_behavior_on_bulk_failure( - res, - 'networks', - wexc.HTTPInternalServerError.code) - - def test_create_networks_bulk_native_plugin_failure(self): - if self._skip_native_bulk: - self.skipTest("Plugin does not support native bulk network create") - plugin_ref = self._get_plugin_ref() - orig = plugin_ref.create_network - with mock.patch.object(plugin_ref, - 'create_network') as patched_plugin: - - def side_effect(*args, **kwargs): - return self._do_side_effect(patched_plugin, orig, - *args, **kwargs) - - patched_plugin.side_effect = side_effect - res = self._create_network_bulk(self.fmt, 2, 'test', True) - # We expect an internal server error as we injected a fault - self._validate_behavior_on_bulk_failure( - res, - 'networks', - wexc.HTTPInternalServerError.code) - - @contextlib.contextmanager - def _provider_vlan_network(self, phys_net, segment_id, net_name): - provider_attrs = {provider.NETWORK_TYPE: 'vlan', - provider.PHYSICAL_NETWORK: phys_net, - provider.SEGMENTATION_ID: segment_id} - arg_list = tuple(provider_attrs.keys()) - res = self._create_network(self.fmt, net_name, True, - arg_list=arg_list, **provider_attrs) - network = self.deserialize(self.fmt, res)['network'] - yield network - req = self.new_delete_request('networks', network['id']) - req.get_response(self.api) - - def test_create_provider_vlan_network(self): - with self._provider_vlan_network(PHYS_NET, '1234', - 'pvnet1') as network: - expected = [('name', 'pvnet1'), - ('admin_state_up', True), - ('status', 'ACTIVE'), - ('shared', False), - (provider.NETWORK_TYPE, 'vlan'), - (provider.PHYSICAL_NETWORK, PHYS_NET), - (provider.SEGMENTATION_ID, 1234)] - for k, v in expected: - self.assertEqual(network[k], v) - self.assertTrue(network_db_v2.is_provider_network(network['id'])) - - def test_delete_provider_vlan_network(self): - with self._provider_vlan_network(PHYS_NET, '1234', - 'pvnet1') as network: - network_id = network['id'] - # Provider network should now be deleted - self.assertFalse(network_db_v2.is_provider_network(network_id)) - - -class TestCiscoSubnetsV2(CiscoNetworkPluginV2TestCase, - test_db_plugin.TestSubnetsV2): - - def test_create_subnets_bulk_emulated_plugin_failure(self): - real_has_attr = hasattr - - #ensures the API choose the emulation code path - def fakehasattr(item, attr): - if attr.endswith('__native_bulk_support'): - return False - return real_has_attr(item, attr) - - with mock.patch('__builtin__.hasattr', - new=fakehasattr): - plugin_ref = self._get_plugin_ref() - orig = plugin_ref.create_subnet - with mock.patch.object(plugin_ref, - 'create_subnet') as patched_plugin: - - def side_effect(*args, **kwargs): - self._do_side_effect(patched_plugin, orig, - *args, **kwargs) - - patched_plugin.side_effect = side_effect - with self.network() as net: - res = self._create_subnet_bulk(self.fmt, 2, - net['network']['id'], - 'test') - # We expect an internal server error as we injected a fault - self._validate_behavior_on_bulk_failure( - res, - 'subnets', - wexc.HTTPInternalServerError.code) - - def test_create_subnets_bulk_native_plugin_failure(self): - if self._skip_native_bulk: - self.skipTest("Plugin does not support native bulk subnet create") - plugin_ref = self._get_plugin_ref() - orig = plugin_ref.create_subnet - with mock.patch.object(plugin_ref, - 'create_subnet') as patched_plugin: - def side_effect(*args, **kwargs): - return self._do_side_effect(patched_plugin, orig, - *args, **kwargs) - - patched_plugin.side_effect = side_effect - with self.network() as net: - res = self._create_subnet_bulk(self.fmt, 2, - net['network']['id'], - 'test') - - # We expect an internal server error as we injected a fault - self._validate_behavior_on_bulk_failure( - res, - 'subnets', - wexc.HTTPInternalServerError.code) - - -class TestCiscoRouterInterfacesV2(CiscoNetworkPluginV2TestCase): - - def setUp(self): - """Configure a log exception counter and an API extension manager.""" - self.log_exc_count = 0 - - def _count_exception_logs(*args, **kwargs): - self.log_exc_count += 1 - - mock.patch.object(logging.LoggerAdapter, 'exception', - autospec=True, - side_effect=_count_exception_logs, - wraps=logging.LoggerAdapter.exception).start() - super(TestCiscoRouterInterfacesV2, self).setUp() - ext_mgr = extensions.PluginAwareExtensionManager.get_instance() - self.ext_api = test_extensions.setup_extensions_middleware(ext_mgr) - - @contextlib.contextmanager - def _network_subnet_router(self): - """Context mgr for creating/deleting a net, subnet, and router.""" - with self.network() as network: - with self.subnet(network=network) as subnet: - data = {'router': {'tenant_id': 'test_tenant_id'}} - request = self.new_create_request('routers', data, self.fmt) - response = request.get_response(self.ext_api) - router = self.deserialize(self.fmt, response) - yield network, subnet, router - self._delete('routers', router['router']['id']) - - @contextlib.contextmanager - def _router_interface(self, router, subnet, **kwargs): - """Create a router interface, yield the response, then delete it.""" - interface_data = {} - if subnet: - interface_data['subnet_id'] = subnet['subnet']['id'] - interface_data.update(kwargs) - request = self.new_action_request('routers', interface_data, - router['router']['id'], - 'add_router_interface') - response = request.get_response(self.ext_api) - - yield response - - # If router interface was created successfully, delete it now. - if response.status_int == wexc.HTTPOk.code: - request = self.new_action_request('routers', interface_data, - router['router']['id'], - 'remove_router_interface') - request.get_response(self.ext_api) - - @contextlib.contextmanager - def _network_subnet_router_interface(self, **kwargs): - """Context mgr for create/deleting a net, subnet, router and intf.""" - with self._network_subnet_router() as (network, subnet, router): - with self._router_interface(router, subnet, - **kwargs) as response: - yield response - - def test_port_list_filtered_by_router_id(self): - """Test port list command filtered by router ID.""" - with self._network_subnet_router() as (network, subnet, router): - with self._router_interface(router, subnet): - query_params = "device_id=%s" % router['router']['id'] - req = self.new_list_request('ports', self.fmt, query_params) - res = self.deserialize(self.fmt, req.get_response(self.api)) - self.assertEqual(len(res['ports']), 1) - self.assertEqual(res['ports'][0]['device_id'], - router['router']['id']) - self.assertFalse(self.log_exc_count) - - def test_add_remove_router_intf_with_nexus_l3_enabled(self): - """Verifies proper add/remove intf operation with Nexus L3 enabled. - - With 'nexus_l3_enable' configured to True, confirm that a switched - virtual interface (SVI) is created/deleted on the Nexus switch when - a virtual router interface is created/deleted. - """ - cisco_config.CONF.set_override('nexus_l3_enable', True, 'CISCO') - with self._network_subnet_router_interface(): - self.assertTrue(self._is_in_last_nexus_cfg( - ['interface', 'vlan', 'ip', 'address'])) - # Clear list of calls made to mock ncclient - self.mock_ncclient.reset() - # Router interface is now deleted. Confirm that SVI - # has been deleted from the Nexus switch. - self.assertTrue(self._is_in_nexus_cfg(['no', 'interface', 'vlan'])) - self.assertTrue(self._is_in_last_nexus_cfg(['no', 'vlan'])) - - def test_add_remove_router_intf_with_nexus_l3_disabled(self): - """Verifies proper add/remove intf operation with Nexus L3 disabled. - - With 'nexus_l3_enable' configured to False, confirm that no changes - are made to the Nexus switch running configuration when a virtual - router interface is created and then deleted. - """ - cisco_config.CONF.set_override('nexus_l3_enable', False, 'CISCO') - with self._network_subnet_router_interface(): - self.assertFalse(self.mock_ncclient.manager.connect. - return_value.edit_config.called) - - def test_create_svi_but_subnet_not_specified_exception(self): - """Tests raising of SubnetNotSpecified exception. - - Tests that a SubnetNotSpecified exception is raised when an - add_router_interface request is made for creating a switch virtual - interface (SVI), but the request does not specify a subnet. - """ - cisco_config.CONF.set_override('nexus_l3_enable', True, 'CISCO') - with self._network_subnet_router() as (network, subnet, router): - with self._router_interface(router, subnet=None) as response: - self._assertExpectedHTTP(response.status_int, - c_exc.SubnetNotSpecified) - - def test_create_svi_but_port_id_included_exception(self): - """Tests raising of PortIdForNexusSvi exception. - - Tests that a PortIdForNexusSvi exception is raised when an - add_router_interface request is made for creating a switch virtual - interface (SVI), but the request includes a virtual port ID. - """ - cisco_config.CONF.set_override('nexus_l3_enable', True, 'CISCO') - with self._network_subnet_router_interface( - port_id='my_port_id') as response: - self._assertExpectedHTTP(response.status_int, - c_exc.PortIdForNexusSvi) - - -class TestCiscoPortsV2XML(TestCiscoPortsV2): - fmt = 'xml' - - -class TestCiscoNetworksV2XML(TestCiscoNetworksV2): - fmt = 'xml' - - -class TestCiscoSubnetsV2XML(TestCiscoSubnetsV2): - fmt = 'xml' - - -class TestCiscoRouterInterfacesV2XML(TestCiscoRouterInterfacesV2): - fmt = 'xml' diff --git a/neutron/tests/unit/cisco/test_nexus_db.py b/neutron/tests/unit/cisco/test_nexus_db.py deleted file mode 100644 index 49b3dce50..000000000 --- a/neutron/tests/unit/cisco/test_nexus_db.py +++ /dev/null @@ -1,239 +0,0 @@ -# Copyright (c) 2013 OpenStack Foundation -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import collections -import mock -import testtools - -from neutron.db import api as db -from neutron.plugins.cisco.common import cisco_exceptions as c_exc -from neutron.plugins.cisco.common import config -from neutron.plugins.cisco.db import nexus_db_v2 as nxdb -from neutron.plugins.cisco.nexus import cisco_nexus_plugin_v2 -from neutron.tests import base - - -class CiscoNexusDbTest(base.BaseTestCase): - - """Unit tests for cisco.db.nexus_models_v2.NexusPortBinding model.""" - - NpbObj = collections.namedtuple('NpbObj', 'port vlan switch instance') - - def setUp(self): - super(CiscoNexusDbTest, self).setUp() - db.configure_db() - self.session = db.get_session() - self.addCleanup(db.clear_db) - - def _npb_test_obj(self, pnum, vnum, switch=None, instance=None): - """Create a Nexus port binding test object from a pair of numbers.""" - if pnum is 'router': - port = pnum - else: - port = '1/%s' % str(pnum) - vlan = str(vnum) - if switch is None: - switch = '10.9.8.7' - if instance is None: - instance = 'instance_%s_%s' % (str(pnum), str(vnum)) - return self.NpbObj(port, vlan, switch, instance) - - def _assert_equal(self, npb, npb_obj): - self.assertEqual(npb.port_id, npb_obj.port) - self.assertEqual(int(npb.vlan_id), int(npb_obj.vlan)) - self.assertEqual(npb.switch_ip, npb_obj.switch) - self.assertEqual(npb.instance_id, npb_obj.instance) - - def _add_to_db(self, npbs): - for npb in npbs: - nxdb.add_nexusport_binding( - npb.port, npb.vlan, npb.switch, npb.instance) - - def test_nexusportbinding_add_remove(self): - npb11 = self._npb_test_obj(10, 100) - npb = nxdb.add_nexusport_binding( - npb11.port, npb11.vlan, npb11.switch, npb11.instance) - self._assert_equal(npb, npb11) - npb = nxdb.remove_nexusport_binding( - npb11.port, npb11.vlan, npb11.switch, npb11.instance) - self.assertEqual(len(npb), 1) - self._assert_equal(npb[0], npb11) - with testtools.ExpectedException(c_exc.NexusPortBindingNotFound): - nxdb.remove_nexusport_binding( - npb11.port, npb11.vlan, npb11.switch, npb11.instance) - - def test_nexusportbinding_get(self): - npb11 = self._npb_test_obj(10, 100) - npb21 = self._npb_test_obj(20, 100) - npb22 = self._npb_test_obj(20, 200) - self._add_to_db([npb11, npb21, npb22]) - - npb = nxdb.get_nexusport_binding( - npb11.port, npb11.vlan, npb11.switch, npb11.instance) - self.assertEqual(len(npb), 1) - self._assert_equal(npb[0], npb11) - npb = nxdb.get_nexusport_binding( - npb21.port, npb21.vlan, npb21.switch, npb21.instance) - self.assertEqual(len(npb), 1) - self._assert_equal(npb[0], npb21) - npb = nxdb.get_nexusport_binding( - npb22.port, npb22.vlan, npb22.switch, npb22.instance) - self.assertEqual(len(npb), 1) - self._assert_equal(npb[0], npb22) - - with testtools.ExpectedException(c_exc.NexusPortBindingNotFound): - nxdb.get_nexusport_binding( - npb21.port, npb21.vlan, npb21.switch, "dummyInstance") - - def test_nexusvlanbinding_get(self): - npb11 = self._npb_test_obj(10, 100) - npb21 = self._npb_test_obj(20, 100) - npb22 = self._npb_test_obj(20, 200) - self._add_to_db([npb11, npb21, npb22]) - - npb_all_v100 = nxdb.get_nexusvlan_binding(npb11.vlan, npb11.switch) - self.assertEqual(len(npb_all_v100), 2) - npb_v200 = nxdb.get_nexusvlan_binding(npb22.vlan, npb22.switch) - self.assertEqual(len(npb_v200), 1) - self._assert_equal(npb_v200[0], npb22) - - with testtools.ExpectedException(c_exc.NexusPortBindingNotFound): - nxdb.get_nexusvlan_binding(npb21.vlan, "dummySwitch") - - def test_nexusvmbinding_get(self): - npb11 = self._npb_test_obj(10, 100) - npb21 = self._npb_test_obj(20, 100) - npb22 = self._npb_test_obj(20, 200) - self._add_to_db([npb11, npb21, npb22]) - - npb = nxdb.get_nexusvm_bindings(npb21.vlan, npb21.instance)[0] - self._assert_equal(npb, npb21) - npb = nxdb.get_nexusvm_bindings(npb22.vlan, npb22.instance)[0] - self._assert_equal(npb, npb22) - - with testtools.ExpectedException(c_exc.NexusPortBindingNotFound): - nxdb.get_nexusvm_bindings(npb21.vlan, "dummyInstance") - - def test_nexusportvlanswitchbinding_get(self): - npb11 = self._npb_test_obj(10, 100) - npb21 = self._npb_test_obj(20, 100) - self._add_to_db([npb11, npb21]) - - npb = nxdb.get_port_vlan_switch_binding( - npb11.port, npb11.vlan, npb11.switch) - self.assertEqual(len(npb), 1) - self._assert_equal(npb[0], npb11) - - with testtools.ExpectedException(c_exc.NexusPortBindingNotFound): - nxdb.get_port_vlan_switch_binding( - npb21.port, npb21.vlan, "dummySwitch") - - def test_nexusportswitchbinding_get(self): - npb11 = self._npb_test_obj(10, 100) - npb21 = self._npb_test_obj(20, 100, switch='2.2.2.2') - npb22 = self._npb_test_obj(20, 200, switch='2.2.2.2') - self._add_to_db([npb11, npb21, npb22]) - - npb = nxdb.get_port_switch_bindings(npb11.port, npb11.switch) - self.assertEqual(len(npb), 1) - self._assert_equal(npb[0], npb11) - npb_all_p20 = nxdb.get_port_switch_bindings(npb21.port, npb21.switch) - self.assertEqual(len(npb_all_p20), 2) - - npb = nxdb.get_port_switch_bindings(npb21.port, "dummySwitch") - self.assertIsNone(npb) - - def test_nexussvibinding_get(self): - npbr1 = self._npb_test_obj('router', 100) - npb21 = self._npb_test_obj(20, 100) - self._add_to_db([npbr1, npb21]) - - npb_svi = nxdb.get_nexussvi_bindings() - self.assertEqual(len(npb_svi), 1) - self._assert_equal(npb_svi[0], npbr1) - - npbr2 = self._npb_test_obj('router', 200) - self._add_to_db([npbr2]) - npb_svi = nxdb.get_nexussvi_bindings() - self.assertEqual(len(npb_svi), 2) - - def test_nexussviswitch_find(self): - """Test Nexus switch selection for SVI placement.""" - # Configure 2 Nexus switches - nexus_switches = { - ('1.1.1.1', 'username'): 'admin', - ('1.1.1.1', 'password'): 'password1', - ('1.1.1.1', 'host1'): '1/1', - ('2.2.2.2', 'username'): 'admin', - ('2.2.2.2', 'password'): 'password2', - ('2.2.2.2', 'host2'): '1/1', - } - nexus_plugin = cisco_nexus_plugin_v2.NexusPlugin() - nexus_plugin._client = mock.Mock() - nexus_plugin._client.nexus_switches = nexus_switches - - # Set the Cisco config module's first configured device IP address - # according to the preceding switch config - with mock.patch.object(config, 'first_device_ip', new='1.1.1.1'): - - # Enable round-robin mode with no SVIs configured on any of the - # Nexus switches (i.e. no entries in the SVI database). The - # plugin should select the first switch in the configuration. - config.CONF.set_override('svi_round_robin', True, 'CISCO') - switch_ip = nexus_plugin._find_switch_for_svi() - self.assertEqual(switch_ip, '1.1.1.1') - - # Keep round-robin mode enabled, and add entries to the SVI - # database. The plugin should select the switch with the least - # number of entries in the SVI database. - vlan = 100 - npbr11 = self._npb_test_obj('router', vlan, switch='1.1.1.1', - instance='instance11') - npbr12 = self._npb_test_obj('router', vlan, switch='1.1.1.1', - instance='instance12') - npbr21 = self._npb_test_obj('router', vlan, switch='2.2.2.2', - instance='instance21') - self._add_to_db([npbr11, npbr12, npbr21]) - switch_ip = nexus_plugin._find_switch_for_svi() - self.assertEqual(switch_ip, '2.2.2.2') - - # Disable round-robin mode. The plugin should select the - # first switch in the configuration. - config.CONF.clear_override('svi_round_robin', 'CISCO') - switch_ip = nexus_plugin._find_switch_for_svi() - self.assertEqual(switch_ip, '1.1.1.1') - - def test_nexusbinding_update(self): - npb11 = self._npb_test_obj(10, 100, switch='1.1.1.1', instance='test') - npb21 = self._npb_test_obj(20, 100, switch='1.1.1.1', instance='test') - self._add_to_db([npb11, npb21]) - - npb_all_v100 = nxdb.get_nexusvlan_binding(npb11.vlan, '1.1.1.1') - self.assertEqual(len(npb_all_v100), 2) - - npb22 = self._npb_test_obj(20, 200, switch='1.1.1.1', instance='test') - npb = nxdb.update_nexusport_binding(npb21.port, 200) - self._assert_equal(npb, npb22) - - npb_all_v100 = nxdb.get_nexusvlan_binding(npb11.vlan, '1.1.1.1') - self.assertEqual(len(npb_all_v100), 1) - self._assert_equal(npb_all_v100[0], npb11) - - npb = nxdb.update_nexusport_binding(npb21.port, 0) - self.assertIsNone(npb) - - npb33 = self._npb_test_obj(30, 300, switch='1.1.1.1', instance='test') - with testtools.ExpectedException(c_exc.NexusPortBindingNotFound): - nxdb.update_nexusport_binding(npb33.port, 200) diff --git a/neutron/tests/unit/cisco/test_nexus_plugin.py b/neutron/tests/unit/cisco/test_nexus_plugin.py deleted file mode 100644 index 6cf54ab84..000000000 --- a/neutron/tests/unit/cisco/test_nexus_plugin.py +++ /dev/null @@ -1,301 +0,0 @@ -# Copyright (c) 2012 OpenStack Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import contextlib -import mock - -from oslo.config import cfg - -from neutron.db import api as db -from neutron.extensions import providernet as provider -from neutron.openstack.common import importutils -from neutron.plugins.cisco.common import cisco_constants as const -from neutron.plugins.cisco.common import cisco_exceptions as cisco_exc -from neutron.plugins.cisco.common import config as cisco_config -from neutron.plugins.cisco.db import network_db_v2 as cdb -from neutron.plugins.cisco.nexus import cisco_nexus_plugin_v2 -from neutron.tests import base - - -NEXUS_IP_ADDRESS = '1.1.1.1' -HOSTNAME1 = 'testhost1' -HOSTNAME2 = 'testhost2' -HOSTNAME3 = 'testhost3' -INSTANCE1 = 'testvm1' -INSTANCE2 = 'testvm2' -INSTANCE3 = 'testvm3' -NEXUS_PORT1 = '1/10' -NEXUS_PORT2 = '1/20' -NEXUS_PC_IP_ADDRESS = '2.2.2.2' -NEXUS_PORTCHANNELS = 'portchannel:2' -PC_HOSTNAME = 'testpchost' -NEXUS_SSH_PORT = '22' -NEXUS_DRIVER = ('neutron.plugins.cisco.nexus.' - 'cisco_nexus_network_driver_v2.CiscoNEXUSDriver') -NET_ATTRS = [const.NET_ID, - const.NET_NAME, - const.NET_VLAN_NAME, - const.NET_VLAN_ID] - - -class TestCiscoNexusPlugin(base.BaseTestCase): - - def setUp(self): - """Set up function.""" - super(TestCiscoNexusPlugin, self).setUp() - self.tenant_id = "test_tenant_cisco1" - self.net_name = "test_network_cisco1" - self.net_id = 7 - self.vlan_name = "q-" + str(self.net_id) + "vlan" - self.vlan_id = 267 - self.second_tenant_id = "test_tenant_2" - self.second_net_name = "test_network_cisco2" - self.second_net_id = 5 - self.second_vlan_name = "q-" + str(self.second_net_id) + "vlan" - self.second_vlan_id = 265 - self._pchostname = PC_HOSTNAME - - self.attachment1 = { - const.TENANT_ID: self.tenant_id, - const.INSTANCE_ID: INSTANCE1, - const.HOST_NAME: HOSTNAME1, - } - self.attachment2 = { - const.TENANT_ID: self.second_tenant_id, - const.INSTANCE_ID: INSTANCE2, - const.HOST_NAME: HOSTNAME2, - } - self.attachment3 = { - const.TENANT_ID: self.second_tenant_id, - const.INSTANCE_ID: INSTANCE3, - const.HOST_NAME: HOSTNAME3, - } - self.network1 = { - const.NET_ID: self.net_id, - const.NET_NAME: self.net_name, - const.NET_VLAN_NAME: self.vlan_name, - const.NET_VLAN_ID: self.vlan_id, - } - self.network2 = { - const.NET_ID: self.second_net_id, - const.NET_NAME: self.second_net_name, - const.NET_VLAN_NAME: self.second_vlan_name, - const.NET_VLAN_ID: self.second_vlan_id, - } - self.network3 = { - const.NET_ID: 8, - const.NET_NAME: 'vpc_net', - const.NET_VLAN_NAME: 'q-268', - const.NET_VLAN_ID: '268', - } - self.delete_port_args_1 = [ - self.attachment1[const.INSTANCE_ID], - self.network1[const.NET_VLAN_ID], - ] - self.providernet = { - const.NET_ID: 9, - const.NET_NAME: 'pnet1', - const.NET_VLAN_NAME: 'p-300', - const.NET_VLAN_ID: 300, - provider.NETWORK_TYPE: 'vlan', - provider.PHYSICAL_NETWORK: self.net_name + '200:299', - provider.SEGMENTATION_ID: 300, - } - - def new_nexus_init(self): - self._client = importutils.import_object(NEXUS_DRIVER) - self._client.nexus_switches = { - (NEXUS_IP_ADDRESS, HOSTNAME1): NEXUS_PORT1, - (NEXUS_IP_ADDRESS, 'ssh_port'): NEXUS_SSH_PORT, - (NEXUS_IP_ADDRESS, HOSTNAME2): NEXUS_PORT2, - (NEXUS_IP_ADDRESS, 'ssh_port'): NEXUS_SSH_PORT, - (NEXUS_PC_IP_ADDRESS, 'ssh_port'): NEXUS_SSH_PORT, - } - self._nexus_switches = { - ('NEXUS_SWITCH', NEXUS_IP_ADDRESS, HOSTNAME1): NEXUS_PORT1, - ('NEXUS_SWITCH', NEXUS_IP_ADDRESS, HOSTNAME2): NEXUS_PORT2, - ('NEXUS_SWITCH', NEXUS_PC_IP_ADDRESS, HOSTNAME3): - NEXUS_PORTCHANNELS, - ('NEXUS_SWITCH', NEXUS_PC_IP_ADDRESS, 'ssh_port'): - NEXUS_SSH_PORT, - ('NEXUS_SWITCH', NEXUS_IP_ADDRESS, HOSTNAME3): - NEXUS_PORTCHANNELS, - ('NEXUS_SWITCH', NEXUS_IP_ADDRESS, 'ssh_port'): NEXUS_SSH_PORT, - } - self._client.credentials = { - NEXUS_IP_ADDRESS: { - 'username': 'admin', - 'password': 'pass1234' - }, - NEXUS_PC_IP_ADDRESS: { - 'username': 'admin', - 'password': 'password' - }, - } - db.configure_db() - - self.addCleanup(db.clear_db) - # Use a mock netconf client - self.mock_ncclient = mock.Mock() - - with contextlib.nested( - mock.patch.dict('sys.modules', {'ncclient': self.mock_ncclient}), - mock.patch.object(cisco_nexus_plugin_v2.NexusPlugin, - '__init__', new=new_nexus_init) - ): - self._cisco_nexus_plugin = cisco_nexus_plugin_v2.NexusPlugin() - - # Set the Cisco config module's first configured device IP address - # according to the preceding switch config. - mock.patch.object(cisco_config, 'first_device_ip', - new=NEXUS_IP_ADDRESS).start() - - def test_create_delete_networks(self): - """Tests creation of two new Virtual Networks.""" - new_net_dict = self._cisco_nexus_plugin.create_network( - self.network1, self.attachment1) - for attr in NET_ATTRS: - self.assertEqual(new_net_dict[attr], self.network1[attr]) - - expected_instance_id = self._cisco_nexus_plugin.delete_port( - INSTANCE1, self.vlan_id) - - self.assertEqual(expected_instance_id, INSTANCE1) - - new_net_dict = self._cisco_nexus_plugin.create_network( - self.network2, self.attachment1) - for attr in NET_ATTRS: - self.assertEqual(new_net_dict[attr], self.network2[attr]) - - expected_instance_id = self._cisco_nexus_plugin.delete_port( - INSTANCE1, self.second_vlan_id) - - self.assertEqual(expected_instance_id, INSTANCE1) - - def _create_delete_providernet(self, auto_create, auto_trunk): - cfg.CONF.set_override( - 'provider_vlan_auto_create', auto_create, 'CISCO') - cfg.CONF.set_override( - 'provider_vlan_auto_trunk', auto_trunk, 'CISCO') - with mock.patch.object(cdb, 'is_provider_vlan', - return_value=True) as mock_db: - # Create a provider network - new_net_dict = self._cisco_nexus_plugin.create_network( - self.providernet, self.attachment1) - self.assertEqual(mock_db.call_count, 1) - for attr in NET_ATTRS: - self.assertEqual(new_net_dict[attr], self.providernet[attr]) - # Delete the provider network - instance_id = self._cisco_nexus_plugin.delete_port( - self.attachment1[const.INSTANCE_ID], - self.providernet[const.NET_VLAN_ID]) - self.assertEqual(instance_id, - self.attachment1[const.INSTANCE_ID]) - - def test_create_delete_providernet(self): - self._create_delete_providernet(auto_create=True, auto_trunk=True) - - def test_create_delete_provider_vlan_network_cfg_auto_man(self): - self._create_delete_providernet(auto_create=True, auto_trunk=False) - - def test_create_delete_provider_vlan_network_cfg_man_auto(self): - self._create_delete_providernet(auto_create=False, auto_trunk=True) - - def test_create_delete_provider_vlan_network_cfg_man_man(self): - self._create_delete_providernet(auto_create=False, auto_trunk=False) - - def test_create_delete_network_portchannel(self): - """Tests creation of a network over a portchannel.""" - new_net_dict = self._cisco_nexus_plugin.create_network( - self.network3, self.attachment3) - self.assertEqual(new_net_dict[const.NET_ID], - self.network3[const.NET_ID]) - self.assertEqual(new_net_dict[const.NET_NAME], - self.network3[const.NET_NAME]) - self.assertEqual(new_net_dict[const.NET_VLAN_NAME], - self.network3[const.NET_VLAN_NAME]) - self.assertEqual(new_net_dict[const.NET_VLAN_ID], - self.network3[const.NET_VLAN_ID]) - - self._cisco_nexus_plugin.delete_port( - INSTANCE3, self.network3[const.NET_VLAN_ID] - ) - - def _add_router_interface(self): - """Add a router interface using fixed (canned) parameters.""" - vlan_name = self.vlan_name - vlan_id = self.vlan_id - gateway_ip = '10.0.0.1/24' - router_id = '00000R1' - subnet_id = '00001' - return self._cisco_nexus_plugin.add_router_interface( - vlan_name, vlan_id, subnet_id, gateway_ip, router_id) - - def _remove_router_interface(self): - """Remove a router interface created with _add_router_interface.""" - vlan_id = self.vlan_id - router_id = '00000R1' - return self._cisco_nexus_plugin.remove_router_interface(vlan_id, - router_id) - - def test_nexus_add_remove_router_interface(self): - """Tests addition of a router interface.""" - self.assertTrue(self._add_router_interface()) - self.assertEqual(self._remove_router_interface(), '00000R1') - - def test_nexus_dup_add_router_interface(self): - """Tests a duplicate add of a router interface.""" - self._add_router_interface() - try: - self.assertRaises( - cisco_exc.SubnetInterfacePresent, - self._add_router_interface) - finally: - self._remove_router_interface() - - def test_nexus_no_svi_switch_exception(self): - """Tests failure to find a Nexus switch for SVI placement.""" - # Clear the Nexus switches dictionary. - with mock.patch.dict(self._cisco_nexus_plugin._client.nexus_switches, - {}, clear=True): - # Clear the first Nexus IP address discovered in config - with mock.patch.object(cisco_config, 'first_device_ip', - new=None): - self.assertRaises(cisco_exc.NoNexusSviSwitch, - self._add_router_interface) - - def test_nexus_add_port_after_router_interface(self): - """Tests creating a port after a router interface. - - Test creating a port after an SVI router interface has - been created. Only a trunk call should be invoked and the - plugin should not attempt to recreate the vlan. - """ - self._add_router_interface() - # Create a network on the switch - self._cisco_nexus_plugin.create_network( - self.network1, self.attachment1) - - # Grab a list of all mock calls from ncclient - last_cfgs = (self.mock_ncclient.manager.connect.return_value. - edit_config.mock_calls) - - # The last ncclient call should be for trunking and the second - # to last call should be creating the SVI interface - last_cfg = last_cfgs[-1][2]['config'] - self.assertIn('allowed', last_cfg) - - slast_cfg = last_cfgs[-2][2]['config'] - self.assertIn('10.0.0.1/24', slast_cfg) diff --git a/neutron/tests/unit/cisco/test_plugin_model.py b/neutron/tests/unit/cisco/test_plugin_model.py deleted file mode 100755 index fa87a5010..000000000 --- a/neutron/tests/unit/cisco/test_plugin_model.py +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright 2014 Cisco Systems, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys - -import mock - -from neutron import context -from neutron.plugins.cisco.common import cisco_constants as const -from neutron.plugins.cisco.common import config as cisco_config -from neutron.plugins.cisco.models import virt_phy_sw_v2 -from neutron.plugins.cisco.nexus import cisco_nexus_plugin_v2 -from neutron.tests import base - - -class TestCiscoPluginModel(base.BaseTestCase): - - def setUp(self): - # Point config file to: neutron/tests/etc/neutron.conf.test - self.config_parse() - - super(TestCiscoPluginModel, self).setUp() - - def test_non_nexus_device_driver(self): - """Tests handling of an non-Nexus device driver being configured.""" - with mock.patch.dict(sys.modules, {'mock_driver': mock.Mock()}): - cisco_config.CONF.set_override('nexus_driver', - 'mock_driver.Non_Nexus_Driver', - 'CISCO') - # Plugin model instance should have is_nexus_plugin set to False - model = virt_phy_sw_v2.VirtualPhysicalSwitchModelV2() - self.assertFalse(model.is_nexus_plugin) - - # Model's _invoke_nexus_for_net_create should just return False - user_id = 'user_id' - tenant_id = 'tenant_id' - ctx = context.Context(user_id, tenant_id) - self.assertFalse(model._invoke_nexus_for_net_create( - ctx, tenant_id, net_id='net_id', - instance_id='instance_id', host_id='host_id')) - - def test_nexus_plugin_calls_ignored_if_plugin_not_loaded(self): - """Verifies Nexus plugin calls are ignored if plugin is not loaded.""" - cisco_config.CONF.set_override(const.NEXUS_PLUGIN, - None, 'CISCO_PLUGINS') - with mock.patch.object(cisco_nexus_plugin_v2.NexusPlugin, - 'create_network') as mock_create_network: - model = virt_phy_sw_v2.VirtualPhysicalSwitchModelV2() - model._invoke_plugin_per_device(model, const.NEXUS_PLUGIN, - 'create_network') - self.assertFalse(mock_create_network.called) diff --git a/neutron/tests/unit/db/firewall/__init__.py b/neutron/tests/unit/db/firewall/__init__.py deleted file mode 100644 index cae279d0a..000000000 --- a/neutron/tests/unit/db/firewall/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 OpenStack Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. diff --git a/neutron/tests/unit/db/firewall/test_db_firewall.py b/neutron/tests/unit/db/firewall/test_db_firewall.py deleted file mode 100644 index 69cf36483..000000000 --- a/neutron/tests/unit/db/firewall/test_db_firewall.py +++ /dev/null @@ -1,1055 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2013 Big Switch Networks, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Sumit Naiksatam, sumitnaiksatam@gmail.com, Big Switch Networks, Inc. - -import contextlib -import logging - -import mock -import webob.exc - -from neutron.api import extensions as api_ext -from neutron.common import config -from neutron import context -from neutron.db.firewall import firewall_db as fdb -import neutron.extensions -from neutron.extensions import firewall -from neutron import manager -from neutron.openstack.common import importutils -from neutron.openstack.common import uuidutils -from neutron.plugins.common import constants -from neutron.services.firewall import fwaas_plugin -from neutron.tests.unit import test_db_plugin - - -LOG = logging.getLogger(__name__) -DB_FW_PLUGIN_KLASS = ( - "neutron.db.firewall.firewall_db.Firewall_db_mixin" -) -FWAAS_PLUGIN = 'neutron.services.firewall.fwaas_plugin' -DELETEFW_PATH = FWAAS_PLUGIN + '.FirewallAgentApi.delete_firewall' -extensions_path = ':'.join(neutron.extensions.__path__) -DESCRIPTION = 'default description' -SHARED = True -PROTOCOL = 'tcp' -IP_VERSION = 4 -SOURCE_IP_ADDRESS_RAW = '1.1.1.1' -DESTINATION_IP_ADDRESS_RAW = '2.2.2.2' -SOURCE_PORT = '55000:56000' -DESTINATION_PORT = '56000:57000' -ACTION = 'allow' -AUDITED = True -ENABLED = True -ADMIN_STATE_UP = True - - -class FakeAgentApi(fwaas_plugin.FirewallCallbacks): - """ - This class used to mock the AgentAPI delete method inherits from - FirewallCallbacks because it needs access to the firewall_deleted method. - The delete_firewall method belongs to the FirewallAgentApi, which has - no access to the firewall_deleted method normally because it's not - responsible for deleting the firewall from the DB. However, it needs - to in the unit tests since there is no agent to call back. - """ - def __init__(self): - pass - - def delete_firewall(self, context, firewall, **kwargs): - self.plugin = manager.NeutronManager.get_service_plugins()['FIREWALL'] - self.firewall_deleted(context, firewall['id'], **kwargs) - - -class FirewallPluginDbTestCase(test_db_plugin.NeutronDbPluginV2TestCase): - resource_prefix_map = dict( - (k, constants.COMMON_PREFIXES[constants.FIREWALL]) - for k in firewall.RESOURCE_ATTRIBUTE_MAP.keys() - ) - - def setUp(self, core_plugin=None, fw_plugin=None, ext_mgr=None): - self.agentapi_delf_p = mock.patch(DELETEFW_PATH, create=True, - new=FakeAgentApi().delete_firewall) - self.agentapi_delf_p.start() - if not fw_plugin: - fw_plugin = DB_FW_PLUGIN_KLASS - service_plugins = {'fw_plugin_name': fw_plugin} - - fdb.Firewall_db_mixin.supported_extension_aliases = ["fwaas"] - super(FirewallPluginDbTestCase, self).setUp( - ext_mgr=ext_mgr, - service_plugins=service_plugins - ) - - if not ext_mgr: - self.plugin = importutils.import_object(fw_plugin) - ext_mgr = api_ext.PluginAwareExtensionManager( - extensions_path, - {constants.FIREWALL: self.plugin} - ) - app = config.load_paste_app('extensions_test_app') - self.ext_api = api_ext.ExtensionMiddleware(app, ext_mgr=ext_mgr) - - def _test_list_resources(self, resource, items, - neutron_context=None, - query_params=None): - if resource.endswith('y'): - resource_plural = resource.replace('y', 'ies') - else: - resource_plural = resource + 's' - - res = self._list(resource_plural, - neutron_context=neutron_context, - query_params=query_params) - resource = resource.replace('-', '_') - self.assertEqual(sorted([i['id'] for i in res[resource_plural]]), - sorted([i[resource]['id'] for i in items])) - - def _get_test_firewall_rule_attrs(self, name='firewall_rule1'): - attrs = {'name': name, - 'tenant_id': self._tenant_id, - 'shared': SHARED, - 'protocol': PROTOCOL, - 'ip_version': IP_VERSION, - 'source_ip_address': SOURCE_IP_ADDRESS_RAW, - 'destination_ip_address': DESTINATION_IP_ADDRESS_RAW, - 'source_port': SOURCE_PORT, - 'destination_port': DESTINATION_PORT, - 'action': ACTION, - 'enabled': ENABLED} - return attrs - - def _get_test_firewall_policy_attrs(self, name='firewall_policy1'): - attrs = {'name': name, - 'description': DESCRIPTION, - 'tenant_id': self._tenant_id, - 'shared': SHARED, - 'firewall_rules': [], - 'audited': AUDITED} - return attrs - - def _get_test_firewall_attrs(self, name='firewall_1'): - attrs = {'name': name, - 'tenant_id': self._tenant_id, - 'admin_state_up': ADMIN_STATE_UP, - 'status': 'PENDING_CREATE'} - - return attrs - - def _create_firewall_policy(self, fmt, name, description, shared, - firewall_rules, audited, - expected_res_status=None, **kwargs): - tenant_id = kwargs.get('tenant_id', self._tenant_id) - data = {'firewall_policy': {'name': name, - 'description': description, - 'tenant_id': tenant_id, - 'shared': shared, - 'firewall_rules': firewall_rules, - 'audited': audited}} - - fw_policy_req = self.new_create_request('firewall_policies', data, fmt) - fw_policy_res = fw_policy_req.get_response(self.ext_api) - if expected_res_status: - self.assertEqual(fw_policy_res.status_int, expected_res_status) - - return fw_policy_res - - def _replace_firewall_status(self, attrs, old_status, new_status): - if attrs['status'] is old_status: - attrs['status'] = new_status - return attrs - - @contextlib.contextmanager - def firewall_policy(self, fmt=None, name='firewall_policy1', - description=DESCRIPTION, shared=True, - firewall_rules=None, audited=True, - no_delete=False, **kwargs): - if firewall_rules is None: - firewall_rules = [] - if not fmt: - fmt = self.fmt - res = self._create_firewall_policy(fmt, name, description, shared, - firewall_rules, audited, - **kwargs) - if res.status_int >= 400: - raise webob.exc.HTTPClientError(code=res.status_int) - firewall_policy = self.deserialize(fmt or self.fmt, res) - yield firewall_policy - if not no_delete: - self._delete('firewall_policies', - firewall_policy['firewall_policy']['id']) - - def _create_firewall_rule(self, fmt, name, shared, protocol, - ip_version, source_ip_address, - destination_ip_address, source_port, - destination_port, action, enabled, - expected_res_status=None, **kwargs): - tenant_id = kwargs.get('tenant_id', self._tenant_id) - data = {'firewall_rule': {'name': name, - 'tenant_id': tenant_id, - 'shared': shared, - 'protocol': protocol, - 'ip_version': ip_version, - 'source_ip_address': source_ip_address, - 'destination_ip_address': - destination_ip_address, - 'source_port': source_port, - 'destination_port': destination_port, - 'action': action, - 'enabled': enabled}} - - fw_rule_req = self.new_create_request('firewall_rules', data, fmt) - fw_rule_res = fw_rule_req.get_response(self.ext_api) - if expected_res_status: - self.assertEqual(fw_rule_res.status_int, expected_res_status) - - return fw_rule_res - - @contextlib.contextmanager - def firewall_rule(self, fmt=None, name='firewall_rule1', - shared=SHARED, protocol=PROTOCOL, ip_version=IP_VERSION, - source_ip_address=SOURCE_IP_ADDRESS_RAW, - destination_ip_address=DESTINATION_IP_ADDRESS_RAW, - source_port=SOURCE_PORT, - destination_port=DESTINATION_PORT, - action=ACTION, enabled=ENABLED, - no_delete=False, **kwargs): - if not fmt: - fmt = self.fmt - res = self._create_firewall_rule(fmt, name, shared, protocol, - ip_version, source_ip_address, - destination_ip_address, - source_port, destination_port, - action, enabled, **kwargs) - if res.status_int >= 400: - raise webob.exc.HTTPClientError(code=res.status_int) - firewall_rule = self.deserialize(fmt or self.fmt, res) - yield firewall_rule - if not no_delete: - self._delete('firewall_rules', - firewall_rule['firewall_rule']['id']) - - def _create_firewall(self, fmt, name, description, firewall_policy_id, - admin_state_up=True, expected_res_status=None, - **kwargs): - tenant_id = kwargs.get('tenant_id', self._tenant_id) - data = {'firewall': {'name': name, - 'description': description, - 'firewall_policy_id': firewall_policy_id, - 'admin_state_up': admin_state_up, - 'tenant_id': tenant_id}} - - firewall_req = self.new_create_request('firewalls', data, fmt) - firewall_res = firewall_req.get_response(self.ext_api) - if expected_res_status: - self.assertEqual(firewall_res.status_int, expected_res_status) - - return firewall_res - - @contextlib.contextmanager - def firewall(self, fmt=None, name='firewall_1', description=DESCRIPTION, - firewall_policy_id=None, admin_state_up=True, - no_delete=False, **kwargs): - if not fmt: - fmt = self.fmt - res = self._create_firewall(fmt, name, description, firewall_policy_id, - admin_state_up, **kwargs) - if res.status_int >= 400: - raise webob.exc.HTTPClientError(code=res.status_int) - firewall = self.deserialize(fmt or self.fmt, res) - yield firewall - if not no_delete: - self._delete('firewalls', firewall['firewall']['id']) - - def _rule_action(self, action, id, firewall_rule_id, insert_before=None, - insert_after=None, expected_code=webob.exc.HTTPOk.code, - expected_body=None, body_data=None): - # We intentionally do this check for None since we want to distinguish - # from empty dictionary - if body_data is None: - if action == 'insert': - body_data = {'firewall_rule_id': firewall_rule_id, - 'insert_before': insert_before, - 'insert_after': insert_after} - else: - body_data = {'firewall_rule_id': firewall_rule_id} - - req = self.new_action_request('firewall_policies', - body_data, id, - "%s_rule" % action) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, expected_code) - response = self.deserialize(self.fmt, res) - if expected_body: - self.assertEqual(response, expected_body) - return response - - def _compare_firewall_rule_lists(self, firewall_policy_id, - list1, list2): - position = 0 - for r1, r2 in zip(list1, list2): - rule = r1['firewall_rule'] - rule['firewall_policy_id'] = firewall_policy_id - position += 1 - rule['position'] = position - for k in rule: - self.assertEqual(rule[k], r2[k]) - - -class TestFirewallDBPlugin(FirewallPluginDbTestCase): - - def test_create_firewall_policy(self): - name = "firewall_policy1" - attrs = self._get_test_firewall_policy_attrs(name) - - with self.firewall_policy(name=name, shared=SHARED, - firewall_rules=None, - audited=AUDITED) as firewall_policy: - for k, v in attrs.iteritems(): - self.assertEqual(firewall_policy['firewall_policy'][k], v) - - def test_create_firewall_policy_with_rules(self): - name = "firewall_policy1" - attrs = self._get_test_firewall_policy_attrs(name) - - with contextlib.nested(self.firewall_rule(name='fwr1'), - self.firewall_rule(name='fwr2'), - self.firewall_rule(name='fwr3')) as fr: - fw_rule_ids = [r['firewall_rule']['id'] for r in fr] - attrs['firewall_rules'] = fw_rule_ids - with self.firewall_policy(name=name, shared=SHARED, - firewall_rules=fw_rule_ids, - audited=AUDITED) as fwp: - for k, v in attrs.iteritems(): - self.assertEqual(fwp['firewall_policy'][k], v) - - def test_create_firewall_policy_with_previously_associated_rule(self): - with self.firewall_rule() as fwr: - fw_rule_ids = [fwr['firewall_rule']['id']] - with self.firewall_policy(firewall_rules=fw_rule_ids): - res = self._create_firewall_policy( - None, 'firewall_policy2', description=DESCRIPTION, - shared=SHARED, firewall_rules=fw_rule_ids, - audited=AUDITED) - self.assertEqual(res.status_int, 409) - - def test_show_firewall_policy(self): - name = "firewall_policy1" - attrs = self._get_test_firewall_policy_attrs(name) - - with self.firewall_policy(name=name, shared=SHARED, - firewall_rules=None, - audited=AUDITED) as fwp: - req = self.new_show_request('firewall_policies', - fwp['firewall_policy']['id'], - fmt=self.fmt) - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - for k, v in attrs.iteritems(): - self.assertEqual(res['firewall_policy'][k], v) - - def test_list_firewall_policies(self): - with contextlib.nested(self.firewall_policy(name='fwp1', - description='fwp'), - self.firewall_policy(name='fwp2', - description='fwp'), - self.firewall_policy(name='fwp3', - description='fwp') - ) as fw_policies: - self._test_list_resources('firewall_policy', - fw_policies, - query_params='description=fwp') - - def test_update_firewall_policy(self): - name = "new_firewall_policy1" - attrs = self._get_test_firewall_policy_attrs(name) - - with self.firewall_policy(shared=SHARED, - firewall_rules=None, - audited=AUDITED) as fwp: - data = {'firewall_policy': {'name': name}} - req = self.new_update_request('firewall_policies', data, - fwp['firewall_policy']['id']) - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - for k, v in attrs.iteritems(): - self.assertEqual(res['firewall_policy'][k], v) - - def test_update_firewall_policy_with_rules(self): - attrs = self._get_test_firewall_policy_attrs() - - with contextlib.nested(self.firewall_rule(name='fwr1'), - self.firewall_rule(name='fwr2'), - self.firewall_rule(name='fwr3')) as fr: - with self.firewall_policy() as fwp: - fw_rule_ids = [r['firewall_rule']['id'] for r in fr] - attrs['firewall_rules'] = fw_rule_ids - data = {'firewall_policy': - {'firewall_rules': fw_rule_ids}} - req = self.new_update_request('firewall_policies', data, - fwp['firewall_policy']['id']) - res = self.deserialize(self.fmt, - req.get_response(self.ext_api)) - attrs['audited'] = False - for k, v in attrs.iteritems(): - self.assertEqual(res['firewall_policy'][k], v) - - def test_update_firewall_policy_replace_rules(self): - attrs = self._get_test_firewall_policy_attrs() - - with contextlib.nested(self.firewall_rule(name='fwr1'), - self.firewall_rule(name='fwr2'), - self.firewall_rule(name='fwr3'), - self.firewall_rule(name='fwr4')) as frs: - fr1 = frs[0:2] - fr2 = frs[2:4] - with self.firewall_policy() as fwp: - fw_rule_ids = [r['firewall_rule']['id'] for r in fr1] - data = {'firewall_policy': - {'firewall_rules': fw_rule_ids}} - req = self.new_update_request('firewall_policies', data, - fwp['firewall_policy']['id']) - req.get_response(self.ext_api) - - fw_rule_ids = [r['firewall_rule']['id'] for r in fr2] - attrs['firewall_rules'] = fw_rule_ids - new_data = {'firewall_policy': - {'firewall_rules': fw_rule_ids}} - req = self.new_update_request('firewall_policies', new_data, - fwp['firewall_policy']['id']) - res = self.deserialize(self.fmt, - req.get_response(self.ext_api)) - attrs['audited'] = False - for k, v in attrs.iteritems(): - self.assertEqual(res['firewall_policy'][k], v) - - def test_update_firewall_policy_reorder_rules(self): - attrs = self._get_test_firewall_policy_attrs() - - with contextlib.nested(self.firewall_rule(name='fwr1'), - self.firewall_rule(name='fwr2'), - self.firewall_rule(name='fwr3'), - self.firewall_rule(name='fwr4')) as fr: - with self.firewall_policy() as fwp: - fw_rule_ids = [fr[2]['firewall_rule']['id'], - fr[3]['firewall_rule']['id']] - data = {'firewall_policy': - {'firewall_rules': fw_rule_ids}} - req = self.new_update_request('firewall_policies', data, - fwp['firewall_policy']['id']) - req.get_response(self.ext_api) - # shuffle the rules, add more rules - fw_rule_ids = [fr[1]['firewall_rule']['id'], - fr[3]['firewall_rule']['id'], - fr[2]['firewall_rule']['id'], - fr[0]['firewall_rule']['id']] - attrs['firewall_rules'] = fw_rule_ids - data = {'firewall_policy': - {'firewall_rules': fw_rule_ids}} - req = self.new_update_request('firewall_policies', data, - fwp['firewall_policy']['id']) - res = self.deserialize(self.fmt, - req.get_response(self.ext_api)) - rules = [] - for rule_id in fw_rule_ids: - req = self.new_show_request('firewall_rules', - rule_id, - fmt=self.fmt) - res = self.deserialize(self.fmt, - req.get_response(self.ext_api)) - rules.append(res['firewall_rule']) - self.assertEqual(rules[0]['position'], 1) - self.assertEqual(rules[0]['id'], fr[1]['firewall_rule']['id']) - self.assertEqual(rules[1]['position'], 2) - self.assertEqual(rules[1]['id'], fr[3]['firewall_rule']['id']) - self.assertEqual(rules[2]['position'], 3) - self.assertEqual(rules[2]['id'], fr[2]['firewall_rule']['id']) - self.assertEqual(rules[3]['position'], 4) - self.assertEqual(rules[3]['id'], fr[0]['firewall_rule']['id']) - - def test_update_firewall_policy_with_non_existing_rule(self): - attrs = self._get_test_firewall_policy_attrs() - - with contextlib.nested(self.firewall_rule(name='fwr1'), - self.firewall_rule(name='fwr2')) as fr: - with self.firewall_policy() as fwp: - fw_rule_ids = [r['firewall_rule']['id'] for r in fr] - # appending non-existent rule - fw_rule_ids.append(uuidutils.generate_uuid()) - data = {'firewall_policy': - {'firewall_rules': fw_rule_ids}} - req = self.new_update_request('firewall_policies', data, - fwp['firewall_policy']['id']) - res = req.get_response(self.ext_api) - #check that the firewall_rule was not found - self.assertEqual(res.status_int, 404) - #check if none of the rules got added to the policy - req = self.new_show_request('firewall_policies', - fwp['firewall_policy']['id'], - fmt=self.fmt) - res = self.deserialize(self.fmt, - req.get_response(self.ext_api)) - for k, v in attrs.iteritems(): - self.assertEqual(res['firewall_policy'][k], v) - - def test_delete_firewall_policy(self): - ctx = context.get_admin_context() - with self.firewall_policy(no_delete=True) as fwp: - fwp_id = fwp['firewall_policy']['id'] - req = self.new_delete_request('firewall_policies', fwp_id) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, 204) - self.assertRaises(firewall.FirewallPolicyNotFound, - self.plugin.get_firewall_policy, - ctx, fwp_id) - - def test_delete_firewall_policy_with_rule(self): - ctx = context.get_admin_context() - attrs = self._get_test_firewall_policy_attrs() - with self.firewall_policy(no_delete=True) as fwp: - fwp_id = fwp['firewall_policy']['id'] - with self.firewall_rule(name='fwr1') as fr: - fr_id = fr['firewall_rule']['id'] - fw_rule_ids = [fr_id] - attrs['firewall_rules'] = fw_rule_ids - data = {'firewall_policy': - {'firewall_rules': fw_rule_ids}} - req = self.new_update_request('firewall_policies', data, - fwp['firewall_policy']['id']) - req.get_response(self.ext_api) - fw_rule = self.plugin.get_firewall_rule(ctx, fr_id) - self.assertEqual(fw_rule['firewall_policy_id'], fwp_id) - req = self.new_delete_request('firewall_policies', fwp_id) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, 204) - self.assertRaises(firewall.FirewallPolicyNotFound, - self.plugin.get_firewall_policy, - ctx, fwp_id) - fw_rule = self.plugin.get_firewall_rule(ctx, fr_id) - self.assertIsNone(fw_rule['firewall_policy_id']) - - def test_delete_firewall_policy_with_firewall_association(self): - attrs = self._get_test_firewall_attrs() - with self.firewall_policy() as fwp: - fwp_id = fwp['firewall_policy']['id'] - attrs['firewall_policy_id'] = fwp_id - with self.firewall(firewall_policy_id=fwp_id, - admin_state_up= - ADMIN_STATE_UP): - req = self.new_delete_request('firewall_policies', fwp_id) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, 409) - - def test_create_firewall_rule(self): - attrs = self._get_test_firewall_rule_attrs() - - with self.firewall_rule() as firewall_rule: - for k, v in attrs.iteritems(): - self.assertEqual(firewall_rule['firewall_rule'][k], v) - - attrs['source_port'] = None - attrs['destination_port'] = None - with self.firewall_rule(source_port=None, - destination_port=None) as firewall_rule: - for k, v in attrs.iteritems(): - self.assertEqual(firewall_rule['firewall_rule'][k], v) - - attrs['source_port'] = '10000' - attrs['destination_port'] = '80' - with self.firewall_rule(source_port=10000, - destination_port=80) as firewall_rule: - for k, v in attrs.iteritems(): - self.assertEqual(firewall_rule['firewall_rule'][k], v) - - attrs['source_port'] = '10000' - attrs['destination_port'] = '80' - with self.firewall_rule(source_port='10000', - destination_port='80') as firewall_rule: - for k, v in attrs.iteritems(): - self.assertEqual(firewall_rule['firewall_rule'][k], v) - - def test_create_firewall_rule_icmp_with_port(self): - attrs = self._get_test_firewall_rule_attrs() - attrs['protocol'] = 'icmp' - res = self._create_firewall_rule(self.fmt, **attrs) - self.assertEqual(400, res.status_int) - - def test_create_firewall_rule_icmp_without_port(self): - attrs = self._get_test_firewall_rule_attrs() - - attrs['protocol'] = 'icmp' - attrs['source_port'] = None - attrs['destination_port'] = None - with self.firewall_rule(source_port=None, - destination_port=None, - protocol='icmp') as firewall_rule: - for k, v in attrs.iteritems(): - self.assertEqual(firewall_rule['firewall_rule'][k], v) - - def test_show_firewall_rule_with_fw_policy_not_associated(self): - attrs = self._get_test_firewall_rule_attrs() - with self.firewall_rule() as fw_rule: - req = self.new_show_request('firewall_rules', - fw_rule['firewall_rule']['id'], - fmt=self.fmt) - res = self.deserialize(self.fmt, - req.get_response(self.ext_api)) - for k, v in attrs.iteritems(): - self.assertEqual(res['firewall_rule'][k], v) - - def test_show_firewall_rule_with_fw_policy_associated(self): - attrs = self._get_test_firewall_rule_attrs() - with self.firewall_rule() as fw_rule: - with self.firewall_policy() as fwp: - fwp_id = fwp['firewall_policy']['id'] - attrs['firewall_policy_id'] = fwp_id - data = {'firewall_policy': - {'firewall_rules': - [fw_rule['firewall_rule']['id']]}} - req = self.new_update_request('firewall_policies', data, - fwp['firewall_policy']['id']) - req.get_response(self.ext_api) - req = self.new_show_request('firewall_rules', - fw_rule['firewall_rule']['id'], - fmt=self.fmt) - res = self.deserialize(self.fmt, - req.get_response(self.ext_api)) - for k, v in attrs.iteritems(): - self.assertEqual(res['firewall_rule'][k], v) - - def test_list_firewall_rules(self): - with contextlib.nested(self.firewall_rule(name='fwr1'), - self.firewall_rule(name='fwr2'), - self.firewall_rule(name='fwr3')) as fr: - query_params = 'protocol=tcp' - self._test_list_resources('firewall_rule', fr, - query_params=query_params) - - def test_update_firewall_rule(self): - name = "new_firewall_rule1" - attrs = self._get_test_firewall_rule_attrs(name) - - attrs['source_port'] = '10:20' - attrs['destination_port'] = '30:40' - with self.firewall_rule() as fwr: - data = {'firewall_rule': {'name': name, - 'source_port': '10:20', - 'destination_port': '30:40'}} - req = self.new_update_request('firewall_rules', data, - fwr['firewall_rule']['id']) - res = self.deserialize(self.fmt, - req.get_response(self.ext_api)) - for k, v in attrs.iteritems(): - self.assertEqual(res['firewall_rule'][k], v) - - attrs['source_port'] = '10000' - attrs['destination_port'] = '80' - with self.firewall_rule() as fwr: - data = {'firewall_rule': {'name': name, - 'source_port': 10000, - 'destination_port': 80}} - req = self.new_update_request('firewall_rules', data, - fwr['firewall_rule']['id']) - res = self.deserialize(self.fmt, - req.get_response(self.ext_api)) - for k, v in attrs.iteritems(): - self.assertEqual(res['firewall_rule'][k], v) - - attrs['source_port'] = '10000' - attrs['destination_port'] = '80' - with self.firewall_rule() as fwr: - data = {'firewall_rule': {'name': name, - 'source_port': '10000', - 'destination_port': '80'}} - req = self.new_update_request('firewall_rules', data, - fwr['firewall_rule']['id']) - res = self.deserialize(self.fmt, - req.get_response(self.ext_api)) - for k, v in attrs.iteritems(): - self.assertEqual(res['firewall_rule'][k], v) - - attrs['source_port'] = None - attrs['destination_port'] = None - with self.firewall_rule() as fwr: - data = {'firewall_rule': {'name': name, - 'source_port': None, - 'destination_port': None}} - req = self.new_update_request('firewall_rules', data, - fwr['firewall_rule']['id']) - res = self.deserialize(self.fmt, - req.get_response(self.ext_api)) - for k, v in attrs.iteritems(): - self.assertEqual(res['firewall_rule'][k], v) - - def test_update_firewall_rule_with_policy_associated(self): - name = "new_firewall_rule1" - attrs = self._get_test_firewall_rule_attrs(name) - with self.firewall_rule() as fwr: - with self.firewall_policy() as fwp: - fwp_id = fwp['firewall_policy']['id'] - attrs['firewall_policy_id'] = fwp_id - fwr_id = fwr['firewall_rule']['id'] - data = {'firewall_policy': {'firewall_rules': [fwr_id]}} - req = self.new_update_request('firewall_policies', data, - fwp['firewall_policy']['id']) - req.get_response(self.ext_api) - data = {'firewall_rule': {'name': name}} - req = self.new_update_request('firewall_rules', data, - fwr['firewall_rule']['id']) - res = self.deserialize(self.fmt, - req.get_response(self.ext_api)) - attrs['firewall_policy_id'] = fwp_id - for k, v in attrs.iteritems(): - self.assertEqual(res['firewall_rule'][k], v) - req = self.new_show_request('firewall_policies', - fwp['firewall_policy']['id'], - fmt=self.fmt) - res = self.deserialize(self.fmt, - req.get_response(self.ext_api)) - self.assertEqual(res['firewall_policy']['firewall_rules'], - [fwr_id]) - self.assertEqual(res['firewall_policy']['audited'], False) - - def test_delete_firewall_rule(self): - ctx = context.get_admin_context() - with self.firewall_rule(no_delete=True) as fwr: - fwr_id = fwr['firewall_rule']['id'] - req = self.new_delete_request('firewall_rules', fwr_id) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, 204) - self.assertRaises(firewall.FirewallRuleNotFound, - self.plugin.get_firewall_rule, - ctx, fwr_id) - - def test_delete_firewall_rule_with_policy_associated(self): - attrs = self._get_test_firewall_rule_attrs() - with self.firewall_rule() as fwr: - with self.firewall_policy() as fwp: - fwp_id = fwp['firewall_policy']['id'] - attrs['firewall_policy_id'] = fwp_id - fwr_id = fwr['firewall_rule']['id'] - data = {'firewall_policy': {'firewall_rules': [fwr_id]}} - req = self.new_update_request('firewall_policies', data, - fwp['firewall_policy']['id']) - req.get_response(self.ext_api) - req = self.new_delete_request('firewall_rules', fwr_id) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, 409) - - def test_create_firewall(self): - name = "firewall1" - attrs = self._get_test_firewall_attrs(name) - - with self.firewall_policy() as fwp: - fwp_id = fwp['firewall_policy']['id'] - attrs['firewall_policy_id'] = fwp_id - with self.firewall(name=name, - firewall_policy_id=fwp_id, - admin_state_up= - ADMIN_STATE_UP) as firewall: - for k, v in attrs.iteritems(): - self.assertEqual(firewall['firewall'][k], v) - - def test_show_firewall(self): - name = "firewall1" - attrs = self._get_test_firewall_attrs(name) - - with self.firewall_policy() as fwp: - fwp_id = fwp['firewall_policy']['id'] - attrs['firewall_policy_id'] = fwp_id - with self.firewall(name=name, - firewall_policy_id=fwp_id, - admin_state_up= - ADMIN_STATE_UP) as firewall: - req = self.new_show_request('firewalls', - firewall['firewall']['id'], - fmt=self.fmt) - res = self.deserialize(self.fmt, - req.get_response(self.ext_api)) - for k, v in attrs.iteritems(): - self.assertEqual(res['firewall'][k], v) - - def test_list_firewalls(self): - with self.firewall_policy() as fwp: - fwp_id = fwp['firewall_policy']['id'] - with contextlib.nested(self.firewall(name='fw1', - firewall_policy_id=fwp_id, - description='fw'), - self.firewall(name='fw2', - firewall_policy_id=fwp_id, - description='fw'), - self.firewall(name='fw3', - firewall_policy_id=fwp_id, - description='fw')) as fwalls: - self._test_list_resources('firewall', fwalls, - query_params='description=fw') - - def test_update_firewall(self): - name = "new_firewall1" - attrs = self._get_test_firewall_attrs(name) - - with self.firewall_policy() as fwp: - fwp_id = fwp['firewall_policy']['id'] - attrs['firewall_policy_id'] = fwp_id - with self.firewall(firewall_policy_id=fwp_id, - admin_state_up= - ADMIN_STATE_UP) as firewall: - data = {'firewall': {'name': name}} - req = self.new_update_request('firewalls', data, - firewall['firewall']['id']) - res = self.deserialize(self.fmt, - req.get_response(self.ext_api)) - for k, v in attrs.iteritems(): - self.assertEqual(res['firewall'][k], v) - - def test_delete_firewall(self): - ctx = context.get_admin_context() - with self.firewall_policy() as fwp: - fwp_id = fwp['firewall_policy']['id'] - with self.firewall(firewall_policy_id=fwp_id, - no_delete=True) as fw: - fw_id = fw['firewall']['id'] - req = self.new_delete_request('firewalls', fw_id) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, 204) - self.assertRaises(firewall.FirewallNotFound, - self.plugin.get_firewall, - ctx, fw_id) - - def test_insert_rule_in_policy_with_prior_rules_added_via_update(self): - attrs = self._get_test_firewall_policy_attrs() - attrs['audited'] = False - attrs['firewall_list'] = [] - with contextlib.nested(self.firewall_rule(name='fwr1'), - self.firewall_rule(name='fwr2'), - self.firewall_rule(name='fwr3')) as frs: - fr1 = frs[0:2] - fwr3 = frs[2] - with self.firewall_policy() as fwp: - fwp_id = fwp['firewall_policy']['id'] - attrs['id'] = fwp_id - fw_rule_ids = [r['firewall_rule']['id'] for r in fr1] - attrs['firewall_rules'] = fw_rule_ids[:] - data = {'firewall_policy': - {'firewall_rules': fw_rule_ids}} - req = self.new_update_request('firewall_policies', data, - fwp_id) - req.get_response(self.ext_api) - self._rule_action('insert', fwp_id, fw_rule_ids[0], - insert_before=fw_rule_ids[0], - insert_after=None, - expected_code=webob.exc.HTTPConflict.code, - expected_body=None) - fwr3_id = fwr3['firewall_rule']['id'] - attrs['firewall_rules'].insert(0, fwr3_id) - self._rule_action('insert', fwp_id, fwr3_id, - insert_before=fw_rule_ids[0], - insert_after=None, - expected_code=webob.exc.HTTPOk.code, - expected_body=attrs) - - def test_insert_rule_in_policy_failures(self): - with self.firewall_rule(name='fwr1') as fr1: - with self.firewall_policy() as fwp: - fwp_id = fwp['firewall_policy']['id'] - fr1_id = fr1['firewall_rule']['id'] - fw_rule_ids = [fr1_id] - data = {'firewall_policy': - {'firewall_rules': fw_rule_ids}} - req = self.new_update_request('firewall_policies', data, - fwp_id) - req.get_response(self.ext_api) - # test inserting with empty request body - self._rule_action('insert', fwp_id, '123', - expected_code=webob.exc.HTTPBadRequest.code, - expected_body=None, body_data={}) - # test inserting when firewall_rule_id is missing in - # request body - insert_data = {'insert_before': '123', - 'insert_after': '456'} - self._rule_action('insert', fwp_id, '123', - expected_code=webob.exc.HTTPBadRequest.code, - expected_body=None, - body_data=insert_data) - # test inserting when firewall_rule_id is None - insert_data = {'firewall_rule_id': None, - 'insert_before': '123', - 'insert_after': '456'} - self._rule_action('insert', fwp_id, '123', - expected_code=webob.exc.HTTPNotFound.code, - expected_body=None, - body_data=insert_data) - # test inserting when firewall_policy_id is incorrect - self._rule_action('insert', '123', fr1_id, - expected_code=webob.exc.HTTPNotFound.code, - expected_body=None) - # test inserting when firewall_policy_id is None - self._rule_action('insert', None, fr1_id, - expected_code=webob.exc.HTTPBadRequest.code, - expected_body=None) - - def test_insert_rule_for_previously_associated_rule(self): - with self.firewall_rule() as fwr: - fwr_id = fwr['firewall_rule']['id'] - fw_rule_ids = [fwr_id] - with self.firewall_policy(firewall_rules=fw_rule_ids): - with self.firewall_policy(name='firewall_policy2') as fwp: - fwp_id = fwp['firewall_policy']['id'] - insert_data = {'firewall_rule_id': fwr_id} - self._rule_action( - 'insert', fwp_id, fwr_id, insert_before=None, - insert_after=None, - expected_code=webob.exc.HTTPConflict.code, - expected_body=None, body_data=insert_data) - - def test_insert_rule_in_policy(self): - attrs = self._get_test_firewall_policy_attrs() - attrs['audited'] = False - attrs['firewall_list'] = [] - with contextlib.nested(self.firewall_rule(name='fwr0'), - self.firewall_rule(name='fwr1'), - self.firewall_rule(name='fwr2'), - self.firewall_rule(name='fwr3'), - self.firewall_rule(name='fwr4'), - self.firewall_rule(name='fwr5'), - self.firewall_rule(name='fwr6')) as fwr: - with self.firewall_policy() as fwp: - fwp_id = fwp['firewall_policy']['id'] - attrs['id'] = fwp_id - # test insert when rule list is empty - fwr0_id = fwr[0]['firewall_rule']['id'] - attrs['firewall_rules'].insert(0, fwr0_id) - self._rule_action('insert', fwp_id, fwr0_id, - insert_before=None, - insert_after=None, - expected_code=webob.exc.HTTPOk.code, - expected_body=attrs) - # test insert at top of rule list, insert_before and - # insert_after not provided - fwr1_id = fwr[1]['firewall_rule']['id'] - attrs['firewall_rules'].insert(0, fwr1_id) - insert_data = {'firewall_rule_id': fwr1_id} - self._rule_action('insert', fwp_id, fwr0_id, - expected_code=webob.exc.HTTPOk.code, - expected_body=attrs, body_data=insert_data) - # test insert at top of list above existing rule - fwr2_id = fwr[2]['firewall_rule']['id'] - attrs['firewall_rules'].insert(0, fwr2_id) - self._rule_action('insert', fwp_id, fwr2_id, - insert_before=fwr1_id, - insert_after=None, - expected_code=webob.exc.HTTPOk.code, - expected_body=attrs) - # test insert at bottom of list - fwr3_id = fwr[3]['firewall_rule']['id'] - attrs['firewall_rules'].append(fwr3_id) - self._rule_action('insert', fwp_id, fwr3_id, - insert_before=None, - insert_after=fwr0_id, - expected_code=webob.exc.HTTPOk.code, - expected_body=attrs) - # test insert in the middle of the list using - # insert_before - fwr4_id = fwr[4]['firewall_rule']['id'] - attrs['firewall_rules'].insert(1, fwr4_id) - self._rule_action('insert', fwp_id, fwr4_id, - insert_before=fwr1_id, - insert_after=None, - expected_code=webob.exc.HTTPOk.code, - expected_body=attrs) - # test insert in the middle of the list using - # insert_after - fwr5_id = fwr[5]['firewall_rule']['id'] - attrs['firewall_rules'].insert(1, fwr5_id) - self._rule_action('insert', fwp_id, fwr5_id, - insert_before=None, - insert_after=fwr2_id, - expected_code=webob.exc.HTTPOk.code, - expected_body=attrs) - # test insert when both insert_before and - # insert_after are set - fwr6_id = fwr[6]['firewall_rule']['id'] - attrs['firewall_rules'].insert(1, fwr6_id) - self._rule_action('insert', fwp_id, fwr6_id, - insert_before=fwr5_id, - insert_after=fwr5_id, - expected_code=webob.exc.HTTPOk.code, - expected_body=attrs) - - def test_remove_rule_from_policy(self): - attrs = self._get_test_firewall_policy_attrs() - attrs['audited'] = False - attrs['firewall_list'] = [] - with contextlib.nested(self.firewall_rule(name='fwr1'), - self.firewall_rule(name='fwr2'), - self.firewall_rule(name='fwr3')) as fr1: - with self.firewall_policy() as fwp: - fwp_id = fwp['firewall_policy']['id'] - attrs['id'] = fwp_id - fw_rule_ids = [r['firewall_rule']['id'] for r in fr1] - attrs['firewall_rules'] = fw_rule_ids[:] - data = {'firewall_policy': - {'firewall_rules': fw_rule_ids}} - req = self.new_update_request('firewall_policies', data, - fwp_id) - req.get_response(self.ext_api) - # test removing a rule from a policy that does not exist - self._rule_action('remove', '123', fw_rule_ids[1], - expected_code=webob.exc.HTTPNotFound.code, - expected_body=None) - # test removing a rule in the middle of the list - attrs['firewall_rules'].remove(fw_rule_ids[1]) - self._rule_action('remove', fwp_id, fw_rule_ids[1], - expected_body=attrs) - # test removing a rule at the top of the list - attrs['firewall_rules'].remove(fw_rule_ids[0]) - self._rule_action('remove', fwp_id, fw_rule_ids[0], - expected_body=attrs) - # test removing remaining rule in the list - attrs['firewall_rules'].remove(fw_rule_ids[2]) - self._rule_action('remove', fwp_id, fw_rule_ids[2], - expected_body=attrs) - # test removing rule that is not associated with the policy - self._rule_action('remove', fwp_id, fw_rule_ids[2], - expected_code=webob.exc.HTTPBadRequest.code, - expected_body=None) - - def test_remove_rule_from_policy_failures(self): - with self.firewall_rule(name='fwr1') as fr1: - with self.firewall_policy() as fwp: - fwp_id = fwp['firewall_policy']['id'] - fw_rule_ids = [fr1['firewall_rule']['id']] - data = {'firewall_policy': - {'firewall_rules': fw_rule_ids}} - req = self.new_update_request('firewall_policies', data, - fwp_id) - req.get_response(self.ext_api) - # test removing rule that does not exist - self._rule_action('remove', fwp_id, '123', - expected_code=webob.exc.HTTPNotFound.code, - expected_body=None) - # test removing rule with bad request - self._rule_action('remove', fwp_id, '123', - expected_code=webob.exc.HTTPBadRequest.code, - expected_body=None, body_data={}) - # test removing rule with firewall_rule_id set to None - self._rule_action('remove', fwp_id, '123', - expected_code=webob.exc.HTTPNotFound.code, - expected_body=None, - body_data={'firewall_rule_id': None}) - - -class TestFirewallDBPluginXML(TestFirewallDBPlugin): - fmt = 'xml' diff --git a/neutron/tests/unit/db/loadbalancer/__init__.py b/neutron/tests/unit/db/loadbalancer/__init__.py deleted file mode 100644 index cae279d0a..000000000 --- a/neutron/tests/unit/db/loadbalancer/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 OpenStack Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. diff --git a/neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py b/neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py deleted file mode 100644 index bc541c7c8..000000000 --- a/neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py +++ /dev/null @@ -1,1572 +0,0 @@ -# Copyright (c) 2012 OpenStack Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import contextlib -import logging - -import mock -from oslo.config import cfg -import testtools -import webob.exc - -from neutron.api import extensions -from neutron.common import config -from neutron import context -import neutron.db.l3_db # noqa -from neutron.db.loadbalancer import loadbalancer_db as ldb -from neutron.db import servicetype_db as sdb -import neutron.extensions -from neutron.extensions import loadbalancer -from neutron.plugins.common import constants -from neutron.services.loadbalancer import ( - plugin as loadbalancer_plugin -) -from neutron.services.loadbalancer.drivers import abstract_driver -from neutron.services import provider_configuration as pconf -from neutron.tests.unit import test_db_plugin - - -LOG = logging.getLogger(__name__) - -DB_CORE_PLUGIN_KLASS = 'neutron.db.db_base_plugin_v2.NeutronDbPluginV2' -DB_LB_PLUGIN_KLASS = ( - "neutron.services.loadbalancer." - "plugin.LoadBalancerPlugin" -) -NOOP_DRIVER_KLASS = ('neutron.tests.unit.db.loadbalancer.test_db_loadbalancer.' - 'NoopLbaaSDriver') - -extensions_path = ':'.join(neutron.extensions.__path__) - -_subnet_id = "0c798ed8-33ba-11e2-8b28-000c291c4d14" - - -class NoopLbaaSDriver(abstract_driver.LoadBalancerAbstractDriver): - """A dummy lbass driver that that only performs object deletion.""" - - def __init__(self, plugin): - self.plugin = plugin - - def create_vip(self, context, vip): - pass - - def update_vip(self, context, old_vip, vip): - pass - - def delete_vip(self, context, vip): - self.plugin._delete_db_vip(context, vip["id"]) - - def create_pool(self, context, pool): - pass - - def update_pool(self, context, old_pool, pool): - pass - - def delete_pool(self, context, pool): - self.plugin._delete_db_pool(context, pool["id"]) - - def stats(self, context, pool_id): - return {"bytes_in": 0, - "bytes_out": 0, - "active_connections": 0, - "total_connections": 0} - - def create_member(self, context, member): - pass - - def update_member(self, context, old_member, member): - pass - - def delete_member(self, context, member): - self.plugin._delete_db_member(context, member["id"]) - - def update_pool_health_monitor(self, context, old_health_monitor, - health_monitor, - pool_association): - pass - - def create_pool_health_monitor(self, context, - health_monitor, pool_id): - pass - - def delete_pool_health_monitor(self, context, health_monitor, pool_id): - self.plugin._delete_db_pool_health_monitor( - context, health_monitor["id"], - pool_id - ) - - -class LoadBalancerTestMixin(object): - resource_prefix_map = dict( - (k, constants.COMMON_PREFIXES[constants.LOADBALANCER]) - for k in loadbalancer.RESOURCE_ATTRIBUTE_MAP.keys() - ) - - def _get_vip_optional_args(self): - return ('description', 'subnet_id', 'address', - 'session_persistence', 'connection_limit') - - def _create_vip(self, fmt, name, pool_id, protocol, protocol_port, - admin_state_up, expected_res_status=None, **kwargs): - data = {'vip': {'name': name, - 'pool_id': pool_id, - 'protocol': protocol, - 'protocol_port': protocol_port, - 'admin_state_up': admin_state_up, - 'tenant_id': self._tenant_id}} - args = self._get_vip_optional_args() - for arg in args: - if arg in kwargs and kwargs[arg] is not None: - data['vip'][arg] = kwargs[arg] - - vip_req = self.new_create_request('vips', data, fmt) - vip_res = vip_req.get_response(self.ext_api) - if expected_res_status: - self.assertEqual(vip_res.status_int, expected_res_status) - - return vip_res - - def _create_pool(self, fmt, name, lb_method, protocol, admin_state_up, - expected_res_status=None, **kwargs): - data = {'pool': {'name': name, - 'subnet_id': _subnet_id, - 'lb_method': lb_method, - 'protocol': protocol, - 'admin_state_up': admin_state_up, - 'tenant_id': self._tenant_id}} - for arg in ('description', 'provider', 'subnet_id'): - if arg in kwargs and kwargs[arg] is not None: - data['pool'][arg] = kwargs[arg] - pool_req = self.new_create_request('pools', data, fmt) - pool_res = pool_req.get_response(self.ext_api) - if expected_res_status: - self.assertEqual(pool_res.status_int, expected_res_status) - - return pool_res - - def _create_member(self, fmt, address, protocol_port, admin_state_up, - expected_res_status=None, **kwargs): - data = {'member': {'address': address, - 'protocol_port': protocol_port, - 'admin_state_up': admin_state_up, - 'tenant_id': self._tenant_id}} - for arg in ('weight', 'pool_id'): - if arg in kwargs and kwargs[arg] is not None: - data['member'][arg] = kwargs[arg] - - member_req = self.new_create_request('members', data, fmt) - member_res = member_req.get_response(self.ext_api) - if expected_res_status: - self.assertEqual(member_res.status_int, expected_res_status) - - return member_res - - def _create_health_monitor(self, fmt, type, delay, timeout, max_retries, - admin_state_up, expected_res_status=None, - **kwargs): - data = {'health_monitor': {'type': type, - 'delay': delay, - 'timeout': timeout, - 'max_retries': max_retries, - 'admin_state_up': admin_state_up, - 'tenant_id': self._tenant_id}} - for arg in ('http_method', 'path', 'expected_code'): - if arg in kwargs and kwargs[arg] is not None: - data['health_monitor'][arg] = kwargs[arg] - - req = self.new_create_request('health_monitors', data, fmt) - - res = req.get_response(self.ext_api) - if expected_res_status: - self.assertEqual(res.status_int, expected_res_status) - - return res - - @contextlib.contextmanager - def vip(self, fmt=None, name='vip1', pool=None, subnet=None, - protocol='HTTP', protocol_port=80, admin_state_up=True, - no_delete=False, **kwargs): - if not fmt: - fmt = self.fmt - - with test_db_plugin.optional_ctx(subnet, self.subnet) as tmp_subnet: - with test_db_plugin.optional_ctx(pool, self.pool) as tmp_pool: - pool_id = tmp_pool['pool']['id'] - res = self._create_vip(fmt, - name, - pool_id, - protocol, - protocol_port, - admin_state_up, - subnet_id=tmp_subnet['subnet']['id'], - **kwargs) - if res.status_int >= webob.exc.HTTPClientError.code: - raise webob.exc.HTTPClientError( - explanation=_("Unexpected error code: %s") % - res.status_int - ) - vip = self.deserialize(fmt or self.fmt, res) - yield vip - if not no_delete: - self._delete('vips', vip['vip']['id']) - - @contextlib.contextmanager - def pool(self, fmt=None, name='pool1', lb_method='ROUND_ROBIN', - protocol='HTTP', admin_state_up=True, no_delete=False, - **kwargs): - if not fmt: - fmt = self.fmt - res = self._create_pool(fmt, - name, - lb_method, - protocol, - admin_state_up, - **kwargs) - if res.status_int >= webob.exc.HTTPClientError.code: - raise webob.exc.HTTPClientError( - explanation=_("Unexpected error code: %s") % res.status_int - ) - pool = self.deserialize(fmt or self.fmt, res) - yield pool - if not no_delete: - self._delete('pools', pool['pool']['id']) - - @contextlib.contextmanager - def member(self, fmt=None, address='192.168.1.100', protocol_port=80, - admin_state_up=True, no_delete=False, **kwargs): - if not fmt: - fmt = self.fmt - res = self._create_member(fmt, - address, - protocol_port, - admin_state_up, - **kwargs) - if res.status_int >= webob.exc.HTTPClientError.code: - raise webob.exc.HTTPClientError( - explanation=_("Unexpected error code: %s") % res.status_int - ) - member = self.deserialize(fmt or self.fmt, res) - yield member - if not no_delete: - self._delete('members', member['member']['id']) - - @contextlib.contextmanager - def health_monitor(self, fmt=None, type='TCP', - delay=30, timeout=10, max_retries=3, - admin_state_up=True, - no_delete=False, **kwargs): - if not fmt: - fmt = self.fmt - res = self._create_health_monitor(fmt, - type, - delay, - timeout, - max_retries, - admin_state_up, - **kwargs) - if res.status_int >= webob.exc.HTTPClientError.code: - raise webob.exc.HTTPClientError( - explanation=_("Unexpected error code: %s") % res.status_int - ) - health_monitor = self.deserialize(fmt or self.fmt, res) - the_health_monitor = health_monitor['health_monitor'] - # make sure: - # 1. When the type is HTTP/S we have HTTP related attributes in - # the result - # 2. When the type is not HTTP/S we do not have HTTP related - # attributes in the result - http_related_attributes = ('http_method', 'url_path', 'expected_codes') - if type in ['HTTP', 'HTTPS']: - for arg in http_related_attributes: - self.assertIsNotNone(the_health_monitor.get(arg)) - else: - for arg in http_related_attributes: - self.assertIsNone(the_health_monitor.get(arg)) - yield health_monitor - if not no_delete: - self._delete('health_monitors', the_health_monitor['id']) - - -class LoadBalancerPluginDbTestCase(LoadBalancerTestMixin, - test_db_plugin.NeutronDbPluginV2TestCase): - def setUp(self, core_plugin=None, lb_plugin=None, lbaas_provider=None, - ext_mgr=None): - service_plugins = {'lb_plugin_name': DB_LB_PLUGIN_KLASS} - if not lbaas_provider: - lbaas_provider = ( - constants.LOADBALANCER + - ':lbaas:' + NOOP_DRIVER_KLASS + ':default') - cfg.CONF.set_override('service_provider', - [lbaas_provider], - 'service_providers') - #force service type manager to reload configuration: - sdb.ServiceTypeManager._instance = None - - super(LoadBalancerPluginDbTestCase, self).setUp( - ext_mgr=ext_mgr, - service_plugins=service_plugins - ) - - if not ext_mgr: - self.plugin = loadbalancer_plugin.LoadBalancerPlugin() - ext_mgr = extensions.PluginAwareExtensionManager( - extensions_path, - {constants.LOADBALANCER: self.plugin} - ) - app = config.load_paste_app('extensions_test_app') - self.ext_api = extensions.ExtensionMiddleware(app, ext_mgr=ext_mgr) - - get_lbaas_agent_patcher = mock.patch( - 'neutron.services.loadbalancer.agent_scheduler' - '.LbaasAgentSchedulerDbMixin.get_lbaas_agent_hosting_pool') - mock_lbaas_agent = mock.MagicMock() - get_lbaas_agent_patcher.start().return_value = mock_lbaas_agent - mock_lbaas_agent.__getitem__.return_value = {'host': 'host'} - - self._subnet_id = _subnet_id - - -class TestLoadBalancer(LoadBalancerPluginDbTestCase): - - def test_create_vip(self, **extras): - expected = { - 'name': 'vip1', - 'description': '', - 'protocol_port': 80, - 'protocol': 'HTTP', - 'connection_limit': -1, - 'admin_state_up': True, - 'status': 'PENDING_CREATE', - 'tenant_id': self._tenant_id, - } - - expected.update(extras) - - with self.subnet() as subnet: - expected['subnet_id'] = subnet['subnet']['id'] - name = expected['name'] - - with self.vip(name=name, subnet=subnet, **extras) as vip: - for k in ('id', 'address', 'port_id', 'pool_id'): - self.assertTrue(vip['vip'].get(k, None)) - - self.assertEqual( - dict((k, v) - for k, v in vip['vip'].items() if k in expected), - expected - ) - return vip - - def test_create_vip_twice_for_same_pool(self): - """Test loadbalancer db plugin via extension and directly.""" - with self.subnet() as subnet: - with self.pool(name="pool1") as pool: - with self.vip(name='vip1', subnet=subnet, pool=pool): - vip_data = { - 'name': 'vip1', - 'pool_id': pool['pool']['id'], - 'description': '', - 'protocol_port': 80, - 'protocol': 'HTTP', - 'connection_limit': -1, - 'admin_state_up': True, - 'status': 'PENDING_CREATE', - 'tenant_id': self._tenant_id, - 'session_persistence': '' - } - self.assertRaises(loadbalancer.VipExists, - self.plugin.create_vip, - context.get_admin_context(), - {'vip': vip_data}) - - def test_update_vip_raises_vip_exists(self): - with self.subnet() as subnet: - with contextlib.nested( - self.pool(name="pool1"), - self.pool(name="pool2") - ) as (pool1, pool2): - with contextlib.nested( - self.vip(name='vip1', subnet=subnet, pool=pool1), - self.vip(name='vip2', subnet=subnet, pool=pool2) - ) as (vip1, vip2): - vip_data = { - 'id': vip2['vip']['id'], - 'name': 'vip1', - 'pool_id': pool1['pool']['id'], - } - self.assertRaises(loadbalancer.VipExists, - self.plugin.update_vip, - context.get_admin_context(), - vip2['vip']['id'], - {'vip': vip_data}) - - def test_update_vip_change_pool(self): - with self.subnet() as subnet: - with contextlib.nested( - self.pool(name="pool1"), - self.pool(name="pool2") - ) as (pool1, pool2): - with self.vip(name='vip1', subnet=subnet, pool=pool1) as vip: - # change vip from pool1 to pool2 - vip_data = { - 'id': vip['vip']['id'], - 'name': 'vip1', - 'pool_id': pool2['pool']['id'], - } - ctx = context.get_admin_context() - self.plugin.update_vip(ctx, - vip['vip']['id'], - {'vip': vip_data}) - db_pool2 = (ctx.session.query(ldb.Pool). - filter_by(id=pool2['pool']['id']).one()) - db_pool1 = (ctx.session.query(ldb.Pool). - filter_by(id=pool1['pool']['id']).one()) - # check that pool1.vip became None - self.assertIsNone(db_pool1.vip) - # and pool2 got vip - self.assertEqual(db_pool2.vip.id, vip['vip']['id']) - - def test_create_vip_with_invalid_values(self): - invalid = { - 'protocol': 'UNSUPPORTED', - 'protocol_port': 'NOT_AN_INT', - 'protocol_port': 1000500, - 'subnet': {'subnet': {'id': 'invalid-subnet'}} - } - - for param, value in invalid.items(): - kwargs = {'name': 'the-vip', param: value} - with testtools.ExpectedException(webob.exc.HTTPClientError): - with self.vip(**kwargs): - pass - - def test_create_vip_with_address(self): - self.test_create_vip(address='10.0.0.7') - - def test_create_vip_with_address_outside_subnet(self): - with testtools.ExpectedException(webob.exc.HTTPClientError): - self.test_create_vip(address='9.9.9.9') - - def test_create_vip_with_session_persistence(self): - self.test_create_vip(session_persistence={'type': 'HTTP_COOKIE'}) - - def test_create_vip_with_session_persistence_with_app_cookie(self): - sp = {'type': 'APP_COOKIE', 'cookie_name': 'sessionId'} - self.test_create_vip(session_persistence=sp) - - def test_create_vip_with_session_persistence_unsupported_type(self): - with testtools.ExpectedException(webob.exc.HTTPClientError): - self.test_create_vip(session_persistence={'type': 'UNSUPPORTED'}) - - def test_create_vip_with_unnecessary_cookie_name(self): - sp = {'type': "SOURCE_IP", 'cookie_name': 'sessionId'} - with testtools.ExpectedException(webob.exc.HTTPClientError): - self.test_create_vip(session_persistence=sp) - - def test_create_vip_with_session_persistence_without_cookie_name(self): - sp = {'type': "APP_COOKIE"} - with testtools.ExpectedException(webob.exc.HTTPClientError): - self.test_create_vip(session_persistence=sp) - - def test_create_vip_with_protocol_mismatch(self): - with self.pool(protocol='TCP') as pool: - with testtools.ExpectedException(webob.exc.HTTPClientError): - self.test_create_vip(pool=pool, protocol='HTTP') - - def test_update_vip_with_protocol_mismatch(self): - with self.pool(protocol='TCP') as pool: - with self.vip(protocol='HTTP') as vip: - data = {'vip': {'pool_id': pool['pool']['id']}} - req = self.new_update_request('vips', data, vip['vip']['id']) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, - webob.exc.HTTPClientError.code) - - def test_reset_session_persistence(self): - name = 'vip4' - session_persistence = {'type': "HTTP_COOKIE"} - - update_info = {'vip': {'session_persistence': None}} - - with self.vip(name=name, session_persistence=session_persistence) as v: - # Ensure that vip has been created properly - self.assertEqual(v['vip']['session_persistence'], - session_persistence) - - # Try resetting session_persistence - req = self.new_update_request('vips', update_info, v['vip']['id']) - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - - self.assertIsNone(res['vip']['session_persistence']) - - def test_update_vip(self): - name = 'new_vip' - keys = [('name', name), - ('address', "10.0.0.2"), - ('protocol_port', 80), - ('connection_limit', 100), - ('admin_state_up', False), - ('status', 'PENDING_UPDATE')] - - with self.vip(name=name) as vip: - keys.append(('subnet_id', vip['vip']['subnet_id'])) - data = {'vip': {'name': name, - 'connection_limit': 100, - 'session_persistence': - {'type': "APP_COOKIE", - 'cookie_name': "jesssionId"}, - 'admin_state_up': False}} - req = self.new_update_request('vips', data, vip['vip']['id']) - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - for k, v in keys: - self.assertEqual(res['vip'][k], v) - - def test_delete_vip(self): - with self.pool(): - with self.vip(no_delete=True) as vip: - req = self.new_delete_request('vips', - vip['vip']['id']) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, webob.exc.HTTPNoContent.code) - - def test_show_vip(self): - name = "vip_show" - keys = [('name', name), - ('address', "10.0.0.10"), - ('protocol_port', 80), - ('protocol', 'HTTP'), - ('connection_limit', -1), - ('admin_state_up', True), - ('status', 'PENDING_CREATE')] - with self.vip(name=name, address='10.0.0.10') as vip: - req = self.new_show_request('vips', - vip['vip']['id']) - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - for k, v in keys: - self.assertEqual(res['vip'][k], v) - - def test_list_vips(self): - name = "vips_list" - keys = [('name', name), - ('address', "10.0.0.2"), - ('protocol_port', 80), - ('protocol', 'HTTP'), - ('connection_limit', -1), - ('admin_state_up', True), - ('status', 'PENDING_CREATE')] - with self.vip(name=name) as vip: - keys.append(('subnet_id', vip['vip']['subnet_id'])) - req = self.new_list_request('vips') - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - self.assertEqual(len(res['vips']), 1) - for k, v in keys: - self.assertEqual(res['vips'][0][k], v) - - def test_list_vips_with_sort_emulated(self): - with self.subnet() as subnet: - with contextlib.nested( - self.vip(name='vip1', subnet=subnet, protocol_port=81), - self.vip(name='vip2', subnet=subnet, protocol_port=82), - self.vip(name='vip3', subnet=subnet, protocol_port=82) - ) as (vip1, vip2, vip3): - self._test_list_with_sort( - 'vip', - (vip1, vip3, vip2), - [('protocol_port', 'asc'), ('name', 'desc')] - ) - - def test_list_vips_with_pagination_emulated(self): - with self.subnet() as subnet: - with contextlib.nested(self.vip(name='vip1', subnet=subnet), - self.vip(name='vip2', subnet=subnet), - self.vip(name='vip3', subnet=subnet) - ) as (vip1, vip2, vip3): - self._test_list_with_pagination('vip', - (vip1, vip2, vip3), - ('name', 'asc'), 2, 2) - - def test_list_vips_with_pagination_reverse_emulated(self): - with self.subnet() as subnet: - with contextlib.nested(self.vip(name='vip1', subnet=subnet), - self.vip(name='vip2', subnet=subnet), - self.vip(name='vip3', subnet=subnet) - ) as (vip1, vip2, vip3): - self._test_list_with_pagination_reverse('vip', - (vip1, vip2, vip3), - ('name', 'asc'), 2, 2) - - def test_create_pool_with_invalid_values(self): - name = 'pool3' - - pool = self.pool(name=name, protocol='UNSUPPORTED') - self.assertRaises(webob.exc.HTTPClientError, pool.__enter__) - - pool = self.pool(name=name, lb_method='UNSUPPORTED') - self.assertRaises(webob.exc.HTTPClientError, pool.__enter__) - - def _create_pool_directly_via_plugin(self, provider_name): - #default provider will be haproxy - prov1 = (constants.LOADBALANCER + - ':lbaas:' + NOOP_DRIVER_KLASS) - prov2 = (constants.LOADBALANCER + - ':haproxy:neutron.services.loadbalancer.' - 'drivers.haproxy.plugin_driver.HaproxyOnHostPluginDriver' - ':default') - cfg.CONF.set_override('service_provider', - [prov1, prov2], - 'service_providers') - sdb.ServiceTypeManager._instance = None - self.plugin = loadbalancer_plugin.LoadBalancerPlugin() - with self.subnet() as subnet: - ctx = context.get_admin_context() - #create pool with another provider - lbaas - #which is noop driver - pool = {'name': 'pool1', - 'subnet_id': subnet['subnet']['id'], - 'lb_method': 'ROUND_ROBIN', - 'protocol': 'HTTP', - 'admin_state_up': True, - 'tenant_id': self._tenant_id, - 'provider': provider_name, - 'description': ''} - self.plugin.create_pool(ctx, {'pool': pool}) - assoc = ctx.session.query(sdb.ProviderResourceAssociation).one() - self.assertEqual(assoc.provider_name, - pconf.normalize_provider_name(provider_name)) - - def test_create_pool_another_provider(self): - self._create_pool_directly_via_plugin('lbaas') - - def test_create_pool_unnormalized_provider_name(self): - self._create_pool_directly_via_plugin('LBAAS') - - def test_create_pool_unexisting_provider(self): - self.assertRaises( - pconf.ServiceProviderNotFound, - self._create_pool_directly_via_plugin, 'unexisting') - - def test_create_pool(self): - name = "pool1" - keys = [('name', name), - ('subnet_id', self._subnet_id), - ('tenant_id', self._tenant_id), - ('protocol', 'HTTP'), - ('lb_method', 'ROUND_ROBIN'), - ('admin_state_up', True), - ('status', 'PENDING_CREATE')] - - with self.pool(name=name) as pool: - for k, v in keys: - self.assertEqual(pool['pool'][k], v) - - def test_create_pool_with_members(self): - name = "pool2" - with self.pool(name=name) as pool: - pool_id = pool['pool']['id'] - res1 = self._create_member(self.fmt, - '192.168.1.100', - '80', - True, - pool_id=pool_id, - weight=1) - req = self.new_show_request('pools', - pool_id, - fmt=self.fmt) - pool_updated = self.deserialize( - self.fmt, - req.get_response(self.ext_api) - ) - - member1 = self.deserialize(self.fmt, res1) - self.assertEqual(member1['member']['id'], - pool_updated['pool']['members'][0]) - self.assertEqual(len(pool_updated['pool']['members']), 1) - - keys = [('address', '192.168.1.100'), - ('protocol_port', 80), - ('weight', 1), - ('pool_id', pool_id), - ('admin_state_up', True), - ('status', 'PENDING_CREATE')] - for k, v in keys: - self.assertEqual(member1['member'][k], v) - self._delete('members', member1['member']['id']) - - def test_delete_pool(self): - with self.pool(no_delete=True) as pool: - with self.member(no_delete=True, - pool_id=pool['pool']['id']): - req = self.new_delete_request('pools', - pool['pool']['id']) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, webob.exc.HTTPNoContent.code) - - def test_delete_pool_preserve_state(self): - with self.pool(no_delete=True) as pool: - with self.vip(pool=pool): - req = self.new_delete_request('pools', - pool['pool']['id']) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, webob.exc.HTTPConflict.code) - req = self.new_show_request('pools', - pool['pool']['id'], - fmt=self.fmt) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, webob.exc.HTTPOk.code) - res = self.deserialize(self.fmt, - req.get_response(self.ext_api)) - self.assertEqual(res['pool']['status'], - constants.PENDING_CREATE) - req = self.new_delete_request('pools', - pool['pool']['id']) - - def test_show_pool(self): - name = "pool1" - keys = [('name', name), - ('subnet_id', self._subnet_id), - ('tenant_id', self._tenant_id), - ('protocol', 'HTTP'), - ('lb_method', 'ROUND_ROBIN'), - ('admin_state_up', True), - ('status', 'PENDING_CREATE')] - with self.pool(name=name) as pool: - req = self.new_show_request('pools', - pool['pool']['id'], - fmt=self.fmt) - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - for k, v in keys: - self.assertEqual(res['pool'][k], v) - - def test_list_pools_with_sort_emulated(self): - with contextlib.nested(self.pool(name='p1'), - self.pool(name='p2'), - self.pool(name='p3') - ) as (p1, p2, p3): - self._test_list_with_sort('pool', (p3, p2, p1), - [('name', 'desc')]) - - def test_list_pools_with_pagination_emulated(self): - with contextlib.nested(self.pool(name='p1'), - self.pool(name='p2'), - self.pool(name='p3') - ) as (p1, p2, p3): - self._test_list_with_pagination('pool', - (p1, p2, p3), - ('name', 'asc'), 2, 2) - - def test_list_pools_with_pagination_reverse_emulated(self): - with contextlib.nested(self.pool(name='p1'), - self.pool(name='p2'), - self.pool(name='p3') - ) as (p1, p2, p3): - self._test_list_with_pagination_reverse('pool', - (p1, p2, p3), - ('name', 'asc'), 2, 2) - - def test_create_member(self): - with self.pool() as pool: - pool_id = pool['pool']['id'] - with self.member(address='192.168.1.100', - protocol_port=80, - pool_id=pool_id) as member1: - with self.member(address='192.168.1.101', - protocol_port=80, - pool_id=pool_id) as member2: - req = self.new_show_request('pools', - pool_id, - fmt=self.fmt) - pool_update = self.deserialize( - self.fmt, - req.get_response(self.ext_api) - ) - self.assertIn(member1['member']['id'], - pool_update['pool']['members']) - self.assertIn(member2['member']['id'], - pool_update['pool']['members']) - - def test_create_same_member_in_same_pool_raises_member_exists(self): - with self.subnet(): - with self.pool(name="pool1") as pool: - pool_id = pool['pool']['id'] - with self.member(address='192.168.1.100', - protocol_port=80, - pool_id=pool_id): - member_data = { - 'address': '192.168.1.100', - 'protocol_port': 80, - 'weight': 1, - 'admin_state_up': True, - 'pool_id': pool_id - } - self.assertRaises(loadbalancer.MemberExists, - self.plugin.create_member, - context.get_admin_context(), - {'member': member_data}) - - def test_update_member(self): - with self.pool(name="pool1") as pool1: - with self.pool(name="pool2") as pool2: - keys = [('address', "192.168.1.100"), - ('tenant_id', self._tenant_id), - ('protocol_port', 80), - ('weight', 10), - ('pool_id', pool2['pool']['id']), - ('admin_state_up', False), - ('status', 'PENDING_UPDATE')] - with self.member(pool_id=pool1['pool']['id']) as member: - req = self.new_show_request('pools', - pool1['pool']['id'], - fmt=self.fmt) - pool1_update = self.deserialize( - self.fmt, - req.get_response(self.ext_api) - ) - self.assertEqual(len(pool1_update['pool']['members']), 1) - - req = self.new_show_request('pools', - pool2['pool']['id'], - fmt=self.fmt) - pool2_update = self.deserialize( - self.fmt, - req.get_response(self.ext_api) - ) - self.assertEqual(len(pool1_update['pool']['members']), 1) - self.assertEqual(len(pool2_update['pool']['members']), 0) - - data = {'member': {'pool_id': pool2['pool']['id'], - 'weight': 10, - 'admin_state_up': False}} - req = self.new_update_request('members', - data, - member['member']['id']) - res = self.deserialize( - self.fmt, - req.get_response(self.ext_api) - ) - for k, v in keys: - self.assertEqual(res['member'][k], v) - - req = self.new_show_request('pools', - pool1['pool']['id'], - fmt=self.fmt) - pool1_update = self.deserialize( - self.fmt, - req.get_response(self.ext_api) - ) - - req = self.new_show_request('pools', - pool2['pool']['id'], - fmt=self.fmt) - pool2_update = self.deserialize( - self.fmt, - req.get_response(self.ext_api) - ) - - self.assertEqual(len(pool2_update['pool']['members']), 1) - self.assertEqual(len(pool1_update['pool']['members']), 0) - - def test_delete_member(self): - with self.pool() as pool: - pool_id = pool['pool']['id'] - with self.member(pool_id=pool_id, - no_delete=True) as member: - req = self.new_delete_request('members', - member['member']['id']) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, webob.exc.HTTPNoContent.code) - - req = self.new_show_request('pools', - pool_id, - fmt=self.fmt) - pool_update = self.deserialize( - self.fmt, - req.get_response(self.ext_api) - ) - self.assertEqual(len(pool_update['pool']['members']), 0) - - def test_show_member(self): - with self.pool() as pool: - keys = [('address', "192.168.1.100"), - ('tenant_id', self._tenant_id), - ('protocol_port', 80), - ('weight', 1), - ('pool_id', pool['pool']['id']), - ('admin_state_up', True), - ('status', 'PENDING_CREATE')] - with self.member(pool_id=pool['pool']['id']) as member: - req = self.new_show_request('members', - member['member']['id'], - fmt=self.fmt) - res = self.deserialize( - self.fmt, - req.get_response(self.ext_api) - ) - for k, v in keys: - self.assertEqual(res['member'][k], v) - - def test_list_members_with_sort_emulated(self): - with self.pool() as pool: - with contextlib.nested(self.member(pool_id=pool['pool']['id'], - protocol_port=81), - self.member(pool_id=pool['pool']['id'], - protocol_port=82), - self.member(pool_id=pool['pool']['id'], - protocol_port=83) - ) as (m1, m2, m3): - self._test_list_with_sort('member', (m3, m2, m1), - [('protocol_port', 'desc')]) - - def test_list_members_with_pagination_emulated(self): - with self.pool() as pool: - with contextlib.nested(self.member(pool_id=pool['pool']['id'], - protocol_port=81), - self.member(pool_id=pool['pool']['id'], - protocol_port=82), - self.member(pool_id=pool['pool']['id'], - protocol_port=83) - ) as (m1, m2, m3): - self._test_list_with_pagination( - 'member', (m1, m2, m3), ('protocol_port', 'asc'), 2, 2 - ) - - def test_list_members_with_pagination_reverse_emulated(self): - with self.pool() as pool: - with contextlib.nested(self.member(pool_id=pool['pool']['id'], - protocol_port=81), - self.member(pool_id=pool['pool']['id'], - protocol_port=82), - self.member(pool_id=pool['pool']['id'], - protocol_port=83) - ) as (m1, m2, m3): - self._test_list_with_pagination_reverse( - 'member', (m1, m2, m3), ('protocol_port', 'asc'), 2, 2 - ) - - def test_create_healthmonitor(self): - keys = [('type', "TCP"), - ('tenant_id', self._tenant_id), - ('delay', 30), - ('timeout', 10), - ('max_retries', 3), - ('admin_state_up', True)] - with self.health_monitor() as monitor: - for k, v in keys: - self.assertEqual(monitor['health_monitor'][k], v) - - def test_create_health_monitor_with_timeout_delay_invalid(self): - data = {'health_monitor': {'type': type, - 'delay': 3, - 'timeout': 6, - 'max_retries': 2, - 'admin_state_up': True, - 'tenant_id': self._tenant_id}} - req = self.new_create_request('health_monitors', data, self.fmt) - res = req.get_response(self.ext_api) - self.assertEqual(webob.exc.HTTPBadRequest.code, res.status_int) - - def test_update_health_monitor_with_timeout_delay_invalid(self): - with self.health_monitor() as monitor: - data = {'health_monitor': {'delay': 10, - 'timeout': 20, - 'max_retries': 2, - 'admin_state_up': False}} - req = self.new_update_request("health_monitors", - data, - monitor['health_monitor']['id']) - res = req.get_response(self.ext_api) - self.assertEqual(webob.exc.HTTPBadRequest.code, res.status_int) - - def test_update_healthmonitor(self): - keys = [('type', "TCP"), - ('tenant_id', self._tenant_id), - ('delay', 20), - ('timeout', 20), - ('max_retries', 2), - ('admin_state_up', False)] - with self.health_monitor() as monitor: - data = {'health_monitor': {'delay': 20, - 'timeout': 20, - 'max_retries': 2, - 'admin_state_up': False}} - req = self.new_update_request("health_monitors", - data, - monitor['health_monitor']['id']) - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - for k, v in keys: - self.assertEqual(res['health_monitor'][k], v) - - def test_delete_healthmonitor(self): - with self.health_monitor(no_delete=True) as monitor: - ctx = context.get_admin_context() - qry = ctx.session.query(ldb.HealthMonitor) - qry = qry.filter_by(id=monitor['health_monitor']['id']) - self.assertIsNotNone(qry.first()) - - req = self.new_delete_request('health_monitors', - monitor['health_monitor']['id']) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, webob.exc.HTTPNoContent.code) - qry = ctx.session.query(ldb.HealthMonitor) - qry = qry.filter_by(id=monitor['health_monitor']['id']) - self.assertIsNone(qry.first()) - - def test_delete_healthmonitor_with_associations_raises(self): - with self.health_monitor(type='HTTP') as monitor: - with self.pool() as pool: - data = { - 'health_monitor': { - 'id': monitor['health_monitor']['id'], - 'tenant_id': self._tenant_id - } - } - req = self.new_create_request( - 'pools', - data, - fmt=self.fmt, - id=pool['pool']['id'], - subresource='health_monitors') - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, webob.exc.HTTPCreated.code) - - ctx = context.get_admin_context() - - # check if we actually have corresponding Pool associations - qry = ctx.session.query(ldb.PoolMonitorAssociation) - qry = qry.filter_by(monitor_id=monitor['health_monitor']['id']) - self.assertTrue(qry.all()) - # try to delete the HealthMonitor instance - req = self.new_delete_request( - 'health_monitors', - monitor['health_monitor']['id'] - ) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, webob.exc.HTTPConflict.code) - - qry = ctx.session.query(ldb.HealthMonitor) - qry = qry.filter_by(id=monitor['health_monitor']['id']) - self.assertIsNotNone(qry.first()) - # check if all corresponding Pool associations are not deleted - qry = ctx.session.query(ldb.PoolMonitorAssociation) - qry = qry.filter_by(monitor_id=monitor['health_monitor']['id']) - self.assertTrue(qry.all()) - - def test_show_healthmonitor(self): - with self.health_monitor() as monitor: - keys = [('type', "TCP"), - ('tenant_id', self._tenant_id), - ('delay', 30), - ('timeout', 10), - ('max_retries', 3), - ('admin_state_up', True)] - req = self.new_show_request('health_monitors', - monitor['health_monitor']['id'], - fmt=self.fmt) - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - for k, v in keys: - self.assertEqual(res['health_monitor'][k], v) - - def test_list_healthmonitors_with_sort_emulated(self): - with contextlib.nested(self.health_monitor(delay=30), - self.health_monitor(delay=31), - self.health_monitor(delay=32) - ) as (m1, m2, m3): - self._test_list_with_sort('health_monitor', (m3, m2, m1), - [('delay', 'desc')]) - - def test_list_healthmonitors_with_pagination_emulated(self): - with contextlib.nested(self.health_monitor(delay=30), - self.health_monitor(delay=31), - self.health_monitor(delay=32) - ) as (m1, m2, m3): - self._test_list_with_pagination('health_monitor', - (m1, m2, m3), - ('delay', 'asc'), 2, 2) - - def test_list_healthmonitors_with_pagination_reverse_emulated(self): - with contextlib.nested(self.health_monitor(delay=30), - self.health_monitor(delay=31), - self.health_monitor(delay=32) - ) as (m1, m2, m3): - self._test_list_with_pagination_reverse('health_monitor', - (m1, m2, m3), - ('delay', 'asc'), 2, 2) - - def test_update_pool_stats_with_no_stats(self): - keys = ["bytes_in", "bytes_out", - "active_connections", - "total_connections"] - with self.pool() as pool: - pool_id = pool['pool']['id'] - ctx = context.get_admin_context() - self.plugin.update_pool_stats(ctx, pool_id) - pool_obj = ctx.session.query(ldb.Pool).filter_by(id=pool_id).one() - for key in keys: - self.assertEqual(pool_obj.stats.__dict__[key], 0) - - def test_update_pool_stats_with_negative_values(self): - stats_data = {"bytes_in": -1, - "bytes_out": -2, - "active_connections": -3, - "total_connections": -4} - for k, v in stats_data.items(): - self._test_update_pool_stats_with_negative_value(k, v) - - def _test_update_pool_stats_with_negative_value(self, k, v): - with self.pool() as pool: - pool_id = pool['pool']['id'] - ctx = context.get_admin_context() - self.assertRaises(ValueError, self.plugin.update_pool_stats, - ctx, pool_id, {k: v}) - - def test_update_pool_stats(self): - stats_data = {"bytes_in": 1, - "bytes_out": 2, - "active_connections": 3, - "total_connections": 4} - with self.pool() as pool: - pool_id = pool['pool']['id'] - ctx = context.get_admin_context() - self.plugin.update_pool_stats(ctx, pool_id, stats_data) - pool_obj = ctx.session.query(ldb.Pool).filter_by(id=pool_id).one() - for k, v in stats_data.items(): - self.assertEqual(pool_obj.stats.__dict__[k], v) - - def test_update_pool_stats_members_statuses(self): - with self.pool() as pool: - pool_id = pool['pool']['id'] - with self.member(pool_id=pool_id) as member: - member_id = member['member']['id'] - stats_data = {'members': { - member_id: { - 'status': 'INACTIVE' - } - }} - ctx = context.get_admin_context() - member = self.plugin.get_member(ctx, member_id) - self.assertEqual('PENDING_CREATE', member['status']) - self.plugin.update_pool_stats(ctx, pool_id, stats_data) - member = self.plugin.get_member(ctx, member_id) - self.assertEqual('INACTIVE', member['status']) - - def test_get_pool_stats(self): - keys = [("bytes_in", 0), - ("bytes_out", 0), - ("active_connections", 0), - ("total_connections", 0)] - with self.pool() as pool: - req = self.new_show_request("pools", - pool['pool']['id'], - subresource="stats", - fmt=self.fmt) - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - for k, v in keys: - self.assertEqual(res['stats'][k], v) - - def test_create_healthmonitor_of_pool(self): - with self.health_monitor(type="TCP") as monitor1: - with self.health_monitor(type="HTTP") as monitor2: - with self.pool() as pool: - data = {"health_monitor": { - "id": monitor1['health_monitor']['id'], - 'tenant_id': self._tenant_id}} - req = self.new_create_request( - "pools", - data, - fmt=self.fmt, - id=pool['pool']['id'], - subresource="health_monitors") - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, - webob.exc.HTTPCreated.code) - - data = {"health_monitor": { - "id": monitor2['health_monitor']['id'], - 'tenant_id': self._tenant_id}} - req = self.new_create_request( - "pools", - data, - fmt=self.fmt, - id=pool['pool']['id'], - subresource="health_monitors") - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, - webob.exc.HTTPCreated.code) - - req = self.new_show_request( - 'pools', - pool['pool']['id'], - fmt=self.fmt) - res = self.deserialize( - self.fmt, - req.get_response(self.ext_api) - ) - self.assertIn(monitor1['health_monitor']['id'], - res['pool']['health_monitors']) - self.assertIn(monitor2['health_monitor']['id'], - res['pool']['health_monitors']) - expected = [ - {'monitor_id': monitor1['health_monitor']['id'], - 'status': 'PENDING_CREATE', - 'status_description': None}, - {'monitor_id': monitor2['health_monitor']['id'], - 'status': 'PENDING_CREATE', - 'status_description': None}] - self.assertEqual( - sorted(expected), - sorted(res['pool']['health_monitors_status'])) - - def test_delete_healthmonitor_of_pool(self): - with self.health_monitor(type="TCP") as monitor1: - with self.health_monitor(type="HTTP") as monitor2: - with self.pool() as pool: - # add the monitors to the pool - data = {"health_monitor": { - "id": monitor1['health_monitor']['id'], - 'tenant_id': self._tenant_id}} - req = self.new_create_request( - "pools", - data, - fmt=self.fmt, - id=pool['pool']['id'], - subresource="health_monitors") - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, - webob.exc.HTTPCreated.code) - - data = {"health_monitor": { - "id": monitor2['health_monitor']['id'], - 'tenant_id': self._tenant_id}} - req = self.new_create_request( - "pools", - data, - fmt=self.fmt, - id=pool['pool']['id'], - subresource="health_monitors") - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, - webob.exc.HTTPCreated.code) - - # remove one of healthmonitor from the pool - req = self.new_delete_request( - "pools", - fmt=self.fmt, - id=pool['pool']['id'], - sub_id=monitor1['health_monitor']['id'], - subresource="health_monitors") - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, - webob.exc.HTTPNoContent.code) - - req = self.new_show_request( - 'pools', - pool['pool']['id'], - fmt=self.fmt) - res = self.deserialize( - self.fmt, - req.get_response(self.ext_api) - ) - self.assertNotIn(monitor1['health_monitor']['id'], - res['pool']['health_monitors']) - self.assertIn(monitor2['health_monitor']['id'], - res['pool']['health_monitors']) - expected = [ - {'monitor_id': monitor2['health_monitor']['id'], - 'status': 'PENDING_CREATE', - 'status_description': None} - ] - self.assertEqual(expected, - res['pool']['health_monitors_status']) - - def test_create_loadbalancer(self): - vip_name = "vip3" - pool_name = "pool3" - - with self.pool(name=pool_name) as pool: - with self.vip(name=vip_name, pool=pool) as vip: - pool_id = pool['pool']['id'] - vip_id = vip['vip']['id'] - # Add two members - res1 = self._create_member(self.fmt, - '192.168.1.100', - '80', - True, - pool_id=pool_id, - weight=1) - res2 = self._create_member(self.fmt, - '192.168.1.101', - '80', - True, - pool_id=pool_id, - weight=2) - # Add a health_monitor - req = self._create_health_monitor(self.fmt, - 'HTTP', - '10', - '10', - '3', - True) - health_monitor = self.deserialize(self.fmt, req) - self.assertEqual(req.status_int, webob.exc.HTTPCreated.code) - - # Associate the health_monitor to the pool - data = {"health_monitor": { - "id": health_monitor['health_monitor']['id'], - 'tenant_id': self._tenant_id}} - req = self.new_create_request("pools", - data, - fmt=self.fmt, - id=pool['pool']['id'], - subresource="health_monitors") - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, webob.exc.HTTPCreated.code) - - # Get pool and vip - req = self.new_show_request('pools', - pool_id, - fmt=self.fmt) - pool_updated = self.deserialize( - self.fmt, - req.get_response(self.ext_api) - ) - member1 = self.deserialize(self.fmt, res1) - member2 = self.deserialize(self.fmt, res2) - self.assertIn(member1['member']['id'], - pool_updated['pool']['members']) - self.assertIn(member2['member']['id'], - pool_updated['pool']['members']) - self.assertIn(health_monitor['health_monitor']['id'], - pool_updated['pool']['health_monitors']) - expected = [ - {'monitor_id': health_monitor['health_monitor']['id'], - 'status': 'PENDING_CREATE', - 'status_description': None} - ] - self.assertEqual( - expected, pool_updated['pool']['health_monitors_status']) - - req = self.new_show_request('vips', - vip_id, - fmt=self.fmt) - vip_updated = self.deserialize( - self.fmt, - req.get_response(self.ext_api) - ) - self.assertEqual(vip_updated['vip']['pool_id'], - pool_updated['pool']['id']) - - # clean up - # disassociate the health_monitor from the pool first - req = self.new_delete_request( - "pools", - fmt=self.fmt, - id=pool['pool']['id'], - subresource="health_monitors", - sub_id=health_monitor['health_monitor']['id']) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, webob.exc.HTTPNoContent.code) - self._delete('health_monitors', - health_monitor['health_monitor']['id']) - self._delete('members', member1['member']['id']) - self._delete('members', member2['member']['id']) - - def test_create_pool_health_monitor(self): - with contextlib.nested( - self.health_monitor(), - self.health_monitor(), - self.pool(name="pool") - ) as (health_mon1, health_mon2, pool): - res = self.plugin.create_pool_health_monitor( - context.get_admin_context(), - health_mon1, pool['pool']['id'] - ) - self.assertEqual({'health_monitor': - [health_mon1['health_monitor']['id']]}, - res) - - res = self.plugin.create_pool_health_monitor( - context.get_admin_context(), - health_mon2, pool['pool']['id'] - ) - self.assertEqual({'health_monitor': - [health_mon1['health_monitor']['id'], - health_mon2['health_monitor']['id']]}, - res) - - res = self.plugin.get_pool_health_monitor( - context.get_admin_context(), - health_mon2['health_monitor']['id'], pool['pool']['id']) - self.assertEqual(res['tenant_id'], - health_mon1['health_monitor']['tenant_id']) - - def test_driver_call_create_pool_health_monitor(self): - with mock.patch.object(self.plugin.drivers['lbaas'], - 'create_pool_health_monitor') as driver_call: - with contextlib.nested( - self.health_monitor(), - self.pool() - ) as (hm, pool): - data = {'health_monitor': { - 'id': hm['health_monitor']['id'], - 'tenant_id': self._tenant_id}} - self.plugin.create_pool_health_monitor( - context.get_admin_context(), - data, pool['pool']['id'] - ) - hm['health_monitor']['pools'] = [ - {'pool_id': pool['pool']['id'], - 'status': 'PENDING_CREATE', - 'status_description': None}] - driver_call.assert_called_once_with( - mock.ANY, hm['health_monitor'], pool['pool']['id']) - - def test_pool_monitor_list_of_pools(self): - with contextlib.nested( - self.health_monitor(), - self.pool(), - self.pool() - ) as (hm, p1, p2): - ctx = context.get_admin_context() - data = {'health_monitor': { - 'id': hm['health_monitor']['id'], - 'tenant_id': self._tenant_id}} - self.plugin.create_pool_health_monitor( - ctx, data, p1['pool']['id']) - self.plugin.create_pool_health_monitor( - ctx, data, p2['pool']['id']) - healthmon = self.plugin.get_health_monitor( - ctx, hm['health_monitor']['id']) - pool_data = [{'pool_id': p1['pool']['id'], - 'status': 'PENDING_CREATE', - 'status_description': None}, - {'pool_id': p2['pool']['id'], - 'status': 'PENDING_CREATE', - 'status_description': None}] - self.assertEqual(sorted(healthmon['pools']), - sorted(pool_data)) - req = self.new_show_request( - 'health_monitors', - hm['health_monitor']['id'], - fmt=self.fmt) - hm = self.deserialize( - self.fmt, - req.get_response(self.ext_api) - ) - self.assertEqual(sorted(hm['health_monitor']['pools']), - sorted(pool_data)) - - def test_create_pool_health_monitor_already_associated(self): - with contextlib.nested( - self.health_monitor(), - self.pool(name="pool") - ) as (hm, pool): - res = self.plugin.create_pool_health_monitor( - context.get_admin_context(), - hm, pool['pool']['id'] - ) - self.assertEqual({'health_monitor': - [hm['health_monitor']['id']]}, - res) - self.assertRaises(loadbalancer.PoolMonitorAssociationExists, - self.plugin.create_pool_health_monitor, - context.get_admin_context(), - hm, - pool['pool']['id']) - - def test_create_pool_healthmon_invalid_pool_id(self): - with self.health_monitor() as healthmon: - self.assertRaises(loadbalancer.PoolNotFound, - self.plugin.create_pool_health_monitor, - context.get_admin_context(), - healthmon, - "123-456-789" - ) - - def test_update_status(self): - with self.pool() as pool: - self.assertEqual(pool['pool']['status'], 'PENDING_CREATE') - self.assertFalse(pool['pool']['status_description']) - - self.plugin.update_status(context.get_admin_context(), ldb.Pool, - pool['pool']['id'], 'ERROR', 'unknown') - updated_pool = self.plugin.get_pool(context.get_admin_context(), - pool['pool']['id']) - self.assertEqual(updated_pool['status'], 'ERROR') - self.assertEqual(updated_pool['status_description'], 'unknown') - - # update status to ACTIVE, status_description should be cleared - self.plugin.update_status(context.get_admin_context(), ldb.Pool, - pool['pool']['id'], 'ACTIVE') - updated_pool = self.plugin.get_pool(context.get_admin_context(), - pool['pool']['id']) - self.assertEqual(updated_pool['status'], 'ACTIVE') - self.assertFalse(updated_pool['status_description']) - - def test_update_pool_health_monitor(self): - with contextlib.nested( - self.health_monitor(), - self.pool(name="pool") - ) as (hm, pool): - res = self.plugin.create_pool_health_monitor( - context.get_admin_context(), - hm, pool['pool']['id']) - self.assertEqual({'health_monitor': - [hm['health_monitor']['id']]}, - res) - - assoc = self.plugin.get_pool_health_monitor( - context.get_admin_context(), - hm['health_monitor']['id'], - pool['pool']['id']) - self.assertEqual(assoc['status'], 'PENDING_CREATE') - self.assertIsNone(assoc['status_description']) - - self.plugin.update_pool_health_monitor( - context.get_admin_context(), - hm['health_monitor']['id'], - pool['pool']['id'], - 'ACTIVE', 'ok') - assoc = self.plugin.get_pool_health_monitor( - context.get_admin_context(), - hm['health_monitor']['id'], - pool['pool']['id']) - self.assertEqual(assoc['status'], 'ACTIVE') - self.assertEqual(assoc['status_description'], 'ok') - - def test_check_orphan_pool_associations(self): - with contextlib.nested( - #creating pools with default noop driver - self.pool(), - self.pool() - ) as (p1, p2): - #checking that 3 associations exist - ctx = context.get_admin_context() - qry = ctx.session.query(sdb.ProviderResourceAssociation) - self.assertEqual(qry.count(), 2) - #removing driver - cfg.CONF.set_override('service_provider', - [constants.LOADBALANCER + - ':lbaas1:' + NOOP_DRIVER_KLASS + - ':default'], - 'service_providers') - sdb.ServiceTypeManager._instance = None - # calling _remove_orphan... in constructor - self.assertRaises( - SystemExit, - loadbalancer_plugin.LoadBalancerPlugin - ) - - -class TestLoadBalancerXML(TestLoadBalancer): - fmt = 'xml' diff --git a/neutron/tests/unit/db/metering/__init__.py b/neutron/tests/unit/db/metering/__init__.py deleted file mode 100644 index 82a447213..000000000 --- a/neutron/tests/unit/db/metering/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright (C) 2013 eNovance SAS -# -# Author: Sylvain Afchain -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. diff --git a/neutron/tests/unit/db/metering/test_db_metering.py b/neutron/tests/unit/db/metering/test_db_metering.py deleted file mode 100644 index 83e4996af..000000000 --- a/neutron/tests/unit/db/metering/test_db_metering.py +++ /dev/null @@ -1,291 +0,0 @@ -# Copyright (C) 2013 eNovance SAS -# -# Author: Sylvain Afchain -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import contextlib -import logging - -import webob.exc - -from neutron.api import extensions -from neutron.common import config -from neutron import context -import neutron.extensions -from neutron.extensions import metering -from neutron.plugins.common import constants -from neutron.services.metering import metering_plugin -from neutron.tests.unit import test_db_plugin - -LOG = logging.getLogger(__name__) - -DB_METERING_PLUGIN_KLASS = ( - "neutron.services.metering." - "metering_plugin.MeteringPlugin" -) - -extensions_path = ':'.join(neutron.extensions.__path__) - - -class MeteringPluginDbTestCaseMixin(object): - def _create_metering_label(self, fmt, name, description, **kwargs): - data = {'metering_label': {'name': name, - 'tenant_id': kwargs.get('tenant_id', - 'test_tenant'), - 'description': description}} - req = self.new_create_request('metering-labels', data, - fmt) - - if kwargs.get('set_context') and 'tenant_id' in kwargs: - # create a specific auth context for this request - req.environ['neutron.context'] = ( - context.Context('', kwargs['tenant_id'], - is_admin=kwargs.get('is_admin', True))) - - return req.get_response(self.ext_api) - - def _make_metering_label(self, fmt, name, description, **kwargs): - res = self._create_metering_label(fmt, name, description, **kwargs) - if res.status_int >= 400: - raise webob.exc.HTTPClientError(code=res.status_int) - return self.deserialize(fmt, res) - - def _create_metering_label_rule(self, fmt, metering_label_id, direction, - remote_ip_prefix, excluded, **kwargs): - data = {'metering_label_rule': - {'metering_label_id': metering_label_id, - 'tenant_id': kwargs.get('tenant_id', 'test_tenant'), - 'direction': direction, - 'excluded': excluded, - 'remote_ip_prefix': remote_ip_prefix}} - req = self.new_create_request('metering-label-rules', - data, fmt) - - if kwargs.get('set_context') and 'tenant_id' in kwargs: - # create a specific auth context for this request - req.environ['neutron.context'] = ( - context.Context('', kwargs['tenant_id'])) - - return req.get_response(self.ext_api) - - def _make_metering_label_rule(self, fmt, metering_label_id, direction, - remote_ip_prefix, excluded, **kwargs): - res = self._create_metering_label_rule(fmt, metering_label_id, - direction, remote_ip_prefix, - excluded, **kwargs) - if res.status_int >= 400: - raise webob.exc.HTTPClientError(code=res.status_int) - return self.deserialize(fmt, res) - - @contextlib.contextmanager - def metering_label(self, name='label', description='desc', - fmt=None, no_delete=False, **kwargs): - if not fmt: - fmt = self.fmt - metering_label = self._make_metering_label(fmt, name, - description, **kwargs) - yield metering_label - if not no_delete: - self._delete('metering-labels', - metering_label['metering_label']['id']) - - @contextlib.contextmanager - def metering_label_rule(self, metering_label_id=None, direction='ingress', - remote_ip_prefix='10.0.0.0/24', - excluded='false', fmt=None, no_delete=False): - if not fmt: - fmt = self.fmt - metering_label_rule = self._make_metering_label_rule(fmt, - metering_label_id, - direction, - remote_ip_prefix, - excluded) - yield metering_label_rule - if not no_delete: - self._delete('metering-label-rules', - metering_label_rule['metering_label_rule']['id']) - - -class MeteringPluginDbTestCase(test_db_plugin.NeutronDbPluginV2TestCase, - MeteringPluginDbTestCaseMixin): - fmt = 'json' - - resource_prefix_map = dict( - (k.replace('_', '-'), constants.COMMON_PREFIXES[constants.METERING]) - for k in metering.RESOURCE_ATTRIBUTE_MAP.keys() - ) - - def setUp(self, plugin=None): - service_plugins = {'metering_plugin_name': DB_METERING_PLUGIN_KLASS} - - super(MeteringPluginDbTestCase, self).setUp( - plugin=plugin, - service_plugins=service_plugins - ) - - self.plugin = metering_plugin.MeteringPlugin() - ext_mgr = extensions.PluginAwareExtensionManager( - extensions_path, - {constants.METERING: self.plugin} - ) - app = config.load_paste_app('extensions_test_app') - self.ext_api = extensions.ExtensionMiddleware(app, ext_mgr=ext_mgr) - - def test_create_metering_label(self): - name = 'my label' - description = 'my metering label' - keys = [('name', name,), ('description', description)] - with self.metering_label(name, description) as metering_label: - for k, v, in keys: - self.assertEqual(metering_label['metering_label'][k], v) - - def test_delete_metering_label(self): - name = 'my label' - description = 'my metering label' - - with self.metering_label(name, description, - no_delete=True) as metering_label: - metering_label_id = metering_label['metering_label']['id'] - self._delete('metering-labels', metering_label_id, 204) - - def test_list_metering_label(self): - name = 'my label' - description = 'my metering label' - - with contextlib.nested( - self.metering_label(name, description), - self.metering_label(name, description)) as metering_label: - - self._test_list_resources('metering-label', metering_label) - - def test_create_metering_label_rule(self): - name = 'my label' - description = 'my metering label' - - with self.metering_label(name, description) as metering_label: - metering_label_id = metering_label['metering_label']['id'] - - direction = 'egress' - remote_ip_prefix = '192.168.0.0/24' - excluded = True - - keys = [('metering_label_id', metering_label_id), - ('direction', direction), - ('excluded', excluded), - ('remote_ip_prefix', remote_ip_prefix)] - with self.metering_label_rule(metering_label_id, - direction, - remote_ip_prefix, - excluded) as label_rule: - for k, v, in keys: - self.assertEqual(label_rule['metering_label_rule'][k], v) - - def test_delete_metering_label_rule(self): - name = 'my label' - description = 'my metering label' - - with self.metering_label(name, description) as metering_label: - metering_label_id = metering_label['metering_label']['id'] - - direction = 'egress' - remote_ip_prefix = '192.168.0.0/24' - excluded = True - - with self.metering_label_rule(metering_label_id, - direction, - remote_ip_prefix, - excluded, - no_delete=True) as label_rule: - rule_id = label_rule['metering_label_rule']['id'] - self._delete('metering-label-rules', rule_id, 204) - - def test_list_metering_label_rule(self): - name = 'my label' - description = 'my metering label' - - with self.metering_label(name, description) as metering_label: - metering_label_id = metering_label['metering_label']['id'] - - direction = 'egress' - remote_ip_prefix = '192.168.0.0/24' - excluded = True - - with contextlib.nested( - self.metering_label_rule(metering_label_id, - direction, - remote_ip_prefix, - excluded), - self.metering_label_rule(metering_label_id, - 'ingress', - remote_ip_prefix, - excluded)) as metering_label_rule: - - self._test_list_resources('metering-label-rule', - metering_label_rule) - - def test_create_metering_label_rules(self): - name = 'my label' - description = 'my metering label' - - with self.metering_label(name, description) as metering_label: - metering_label_id = metering_label['metering_label']['id'] - - direction = 'egress' - remote_ip_prefix = '192.168.0.0/24' - excluded = True - - with contextlib.nested( - self.metering_label_rule(metering_label_id, - direction, - remote_ip_prefix, - excluded), - self.metering_label_rule(metering_label_id, - direction, - '0.0.0.0/0', - False)) as metering_label_rule: - - self._test_list_resources('metering-label-rule', - metering_label_rule) - - def test_create_metering_label_rule_two_labels(self): - name1 = 'my label 1' - name2 = 'my label 2' - description = 'my metering label' - - with self.metering_label(name1, description) as metering_label1: - metering_label_id1 = metering_label1['metering_label']['id'] - - with self.metering_label(name2, description) as metering_label2: - metering_label_id2 = metering_label2['metering_label']['id'] - - direction = 'egress' - remote_ip_prefix = '192.168.0.0/24' - excluded = True - - with contextlib.nested( - self.metering_label_rule(metering_label_id1, - direction, - remote_ip_prefix, - excluded), - self.metering_label_rule(metering_label_id2, - direction, - remote_ip_prefix, - excluded)) as metering_label_rule: - - self._test_list_resources('metering-label-rule', - metering_label_rule) - - -class TestMeteringDbXML(MeteringPluginDbTestCase): - fmt = 'xml' diff --git a/neutron/tests/unit/db/test_agent_db.py b/neutron/tests/unit/db/test_agent_db.py deleted file mode 100644 index e3dc5ee8f..000000000 --- a/neutron/tests/unit/db/test_agent_db.py +++ /dev/null @@ -1,86 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright (c) 2013 OpenStack Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import mock - -from neutron import context -from neutron.db import agents_db -from neutron.db import api as db -from neutron.db import db_base_plugin_v2 as base_plugin -from neutron.openstack.common.db import exception as exc -from neutron.tests import base - - -class FakePlugin(base_plugin.NeutronDbPluginV2, agents_db.AgentDbMixin): - """A fake plugin class containing all DB methods.""" - - -class TestAgentsDbMixin(base.BaseTestCase): - def setUp(self): - super(TestAgentsDbMixin, self).setUp() - - self.context = context.get_admin_context() - self.plugin = FakePlugin() - self.addCleanup(db.clear_db) - - self.agent_status = { - 'agent_type': 'Open vSwitch agent', - 'binary': 'neutron-openvswitch-agent', - 'host': 'overcloud-notcompute', - 'topic': 'N/A' - } - - def _assert_ref_fields_are_equal(self, reference, result): - """Compare (key, value) pairs of a reference dict with the result - - Note: the result MAY have additional keys - """ - - for field, value in reference.items(): - self.assertEqual(value, result[field], field) - - def test_create_or_update_agent_new_entry(self): - self.plugin.create_or_update_agent(self.context, self.agent_status) - - agent = self.plugin.get_agents(self.context)[0] - self._assert_ref_fields_are_equal(self.agent_status, agent) - - def test_create_or_update_agent_existing_entry(self): - self.plugin.create_or_update_agent(self.context, self.agent_status) - self.plugin.create_or_update_agent(self.context, self.agent_status) - self.plugin.create_or_update_agent(self.context, self.agent_status) - - agents = self.plugin.get_agents(self.context) - self.assertEqual(len(agents), 1) - - agent = agents[0] - self._assert_ref_fields_are_equal(self.agent_status, agent) - - def test_create_or_update_agent_concurrent_insert(self): - # NOTE(rpodolyaka): emulate violation of the unique constraint caused - # by a concurrent insert. Ensure we make another - # attempt on fail - with mock.patch('sqlalchemy.orm.Session.add') as add_mock: - add_mock.side_effect = [ - exc.DBDuplicateEntry(columns=['agent_type', 'host']), - None - ] - - self.plugin.create_or_update_agent(self.context, self.agent_status) - - self.assertEqual(add_mock.call_count, 2, - "Agent entry creation hasn't been retried") diff --git a/neutron/tests/unit/db/test_quota_db.py b/neutron/tests/unit/db/test_quota_db.py deleted file mode 100644 index 813f0166a..000000000 --- a/neutron/tests/unit/db/test_quota_db.py +++ /dev/null @@ -1,143 +0,0 @@ -# Copyright (c) 2014 OpenStack Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# @author: Sergio Cazzolato, Intel - -from neutron.common import exceptions -from neutron import context -from neutron.db import api as db -from neutron.db import db_base_plugin_v2 as base_plugin -from neutron.db import quota_db -from neutron.tests import base - - -class FakePlugin(base_plugin.NeutronDbPluginV2, quota_db.DbQuotaDriver): - """A fake plugin class containing all DB methods.""" - - -class TestResource(object): - """Describe a test resource for quota checking.""" - - def __init__(self, name, default): - self.name = name - self.quota = default - - @property - def default(self): - return self.quota - -PROJECT = 'prj_test' -RESOURCE = 'res_test' - - -class TestDbQuotaDriver(base.BaseTestCase): - def setUp(self): - super(TestDbQuotaDriver, self).setUp() - self.plugin = FakePlugin() - self.context = context.get_admin_context() - self.addCleanup(db.clear_db) - - def test_create_quota_limit(self): - defaults = {RESOURCE: TestResource(RESOURCE, 4)} - - self.plugin.update_quota_limit(self.context, PROJECT, RESOURCE, 2) - quotas = self.plugin.get_tenant_quotas(self.context, defaults, PROJECT) - self.assertEqual(2, quotas[RESOURCE]) - - def test_update_quota_limit(self): - defaults = {RESOURCE: TestResource(RESOURCE, 4)} - - self.plugin.update_quota_limit(self.context, PROJECT, RESOURCE, 2) - self.plugin.update_quota_limit(self.context, PROJECT, RESOURCE, 3) - quotas = self.plugin.get_tenant_quotas(self.context, defaults, PROJECT) - self.assertEqual(3, quotas[RESOURCE]) - - def test_delete_tenant_quota_restores_default_limit(self): - defaults = {RESOURCE: TestResource(RESOURCE, 4)} - - self.plugin.update_quota_limit(self.context, PROJECT, RESOURCE, 2) - self.plugin.delete_tenant_quota(self.context, PROJECT) - quotas = self.plugin.get_tenant_quotas(self.context, defaults, PROJECT) - self.assertEqual(4, quotas[RESOURCE]) - - def test_get_all_quotas(self): - project_1 = 'prj_test_1' - project_2 = 'prj_test_2' - resource_1 = 'res_test_1' - resource_2 = 'res_test_2' - - resources = {resource_1: TestResource(resource_1, 1), - resource_2: TestResource(resource_2, 1)} - - self.plugin.update_quota_limit(self.context, project_1, resource_1, 2) - self.plugin.update_quota_limit(self.context, project_2, resource_2, 2) - quotas = self.plugin.get_all_quotas(self.context, resources) - - self.assertEqual(2, len(quotas)) - - self.assertEqual(3, len(quotas[0])) - self.assertEqual(project_1, quotas[0]['tenant_id']) - self.assertEqual(2, quotas[0][resource_1]) - self.assertEqual(1, quotas[0][resource_2]) - - self.assertEqual(3, len(quotas[1])) - self.assertEqual(project_2, quotas[1]['tenant_id']) - self.assertEqual(1, quotas[1][resource_1]) - self.assertEqual(2, quotas[1][resource_2]) - - def test_limit_check(self): - resources = {RESOURCE: TestResource(RESOURCE, 2)} - values = {RESOURCE: 1} - - self.plugin.update_quota_limit(self.context, PROJECT, RESOURCE, 2) - self.plugin.limit_check(self.context, PROJECT, resources, values) - - def test_limit_check_over_quota(self): - resources = {RESOURCE: TestResource(RESOURCE, 2)} - values = {RESOURCE: 3} - - self.plugin.update_quota_limit(self.context, PROJECT, RESOURCE, 2) - - self.assertRaises(exceptions.OverQuota, self.plugin.limit_check, - context.get_admin_context(), PROJECT, resources, - values) - - def test_limit_check_equals_to_quota(self): - resources = {RESOURCE: TestResource(RESOURCE, 2)} - values = {RESOURCE: 2} - - self.plugin.update_quota_limit(self.context, PROJECT, RESOURCE, 2) - self.plugin.limit_check(self.context, PROJECT, resources, values) - - def test_limit_check_value_lower_than_zero(self): - resources = {RESOURCE: TestResource(RESOURCE, 2)} - values = {RESOURCE: -1} - - self.plugin.update_quota_limit(self.context, PROJECT, RESOURCE, 2) - self.assertRaises(exceptions.InvalidQuotaValue, - self.plugin.limit_check, context.get_admin_context(), - PROJECT, resources, values) - - def test_limit_check_wrong_values_size(self): - resource_1 = 'res_test_1' - resource_2 = 'res_test_2' - - resources = {resource_1: TestResource(resource_1, 2)} - values = {resource_1: 1, resource_2: 1} - - self.plugin.update_quota_limit(self.context, PROJECT, resource_1, 2) - self.assertRaises(exceptions.QuotaResourceUnknown, - self.plugin.limit_check, context.get_admin_context(), - PROJECT, resources, values) diff --git a/neutron/tests/unit/db/vpn/__init__.py b/neutron/tests/unit/db/vpn/__init__.py deleted file mode 100644 index b936bbcb8..000000000 --- a/neutron/tests/unit/db/vpn/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# (c) Copyright 2013 Hewlett-Packard Development Company, L.P. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# @author: Swaminathan Vasudevan, Hewlett-Packard. diff --git a/neutron/tests/unit/db/vpn/test_db_vpnaas.py b/neutron/tests/unit/db/vpn/test_db_vpnaas.py deleted file mode 100644 index d685df96c..000000000 --- a/neutron/tests/unit/db/vpn/test_db_vpnaas.py +++ /dev/null @@ -1,1670 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# (c) Copyright 2013 Hewlett-Packard Development Company, L.P. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Swaminathan Vasudevan, Hewlett-Packard. - -import contextlib -import os - -from oslo.config import cfg -import webob.exc - -from neutron.api import extensions as api_extensions -from neutron.common import config -from neutron import context -from neutron.db import agentschedulers_db -from neutron.db import l3_agentschedulers_db -from neutron.db import servicetype_db as sdb -from neutron.db.vpn import vpn_db -from neutron import extensions -from neutron.extensions import vpnaas -from neutron import manager -from neutron.openstack.common import uuidutils -from neutron.plugins.common import constants -from neutron.scheduler import l3_agent_scheduler -from neutron.services.vpn import plugin as vpn_plugin -from neutron.tests.unit import test_db_plugin -from neutron.tests.unit import test_l3_plugin - -DB_CORE_PLUGIN_KLASS = 'neutron.db.db_base_plugin_v2.NeutronDbPluginV2' -DB_VPN_PLUGIN_KLASS = "neutron.services.vpn.plugin.VPNPlugin" -ROOTDIR = os.path.normpath(os.path.join( - os.path.dirname(__file__), - '..', '..', '..', '..')) - -extensions_path = ':'.join(extensions.__path__) - - -class TestVpnCorePlugin(test_l3_plugin.TestL3NatIntPlugin, - l3_agentschedulers_db.L3AgentSchedulerDbMixin, - agentschedulers_db.DhcpAgentSchedulerDbMixin): - def __init__(self, configfile=None): - super(TestVpnCorePlugin, self).__init__() - self.router_scheduler = l3_agent_scheduler.ChanceScheduler() - - -class VPNTestMixin(object): - resource_prefix_map = dict( - (k.replace('_', '-'), - constants.COMMON_PREFIXES[constants.VPN]) - for k in vpnaas.RESOURCE_ATTRIBUTE_MAP - ) - - def _create_ikepolicy(self, fmt, - name='ikepolicy1', - auth_algorithm='sha1', - encryption_algorithm='aes-128', - phase1_negotiation_mode='main', - lifetime_units='seconds', - lifetime_value=3600, - ike_version='v1', - pfs='group5', - expected_res_status=None, **kwargs): - - data = {'ikepolicy': { - 'name': name, - 'auth_algorithm': auth_algorithm, - 'encryption_algorithm': encryption_algorithm, - 'phase1_negotiation_mode': phase1_negotiation_mode, - 'lifetime': { - 'units': lifetime_units, - 'value': lifetime_value}, - 'ike_version': ike_version, - 'pfs': pfs, - 'tenant_id': self._tenant_id - }} - for arg in ['description']: - if arg in kwargs and kwargs[arg] is not None: - data['ikepolicy'][arg] = kwargs[arg] - - ikepolicy_req = self.new_create_request('ikepolicies', data, fmt) - ikepolicy_res = ikepolicy_req.get_response(self.ext_api) - if expected_res_status: - self.assertEqual(ikepolicy_res.status_int, expected_res_status) - - return ikepolicy_res - - @contextlib.contextmanager - def ikepolicy(self, fmt=None, - name='ikepolicy1', - auth_algorithm='sha1', - encryption_algorithm='aes-128', - phase1_negotiation_mode='main', - lifetime_units='seconds', - lifetime_value=3600, - ike_version='v1', - pfs='group5', - no_delete=False, - **kwargs): - if not fmt: - fmt = self.fmt - res = self._create_ikepolicy(fmt, - name, - auth_algorithm, - encryption_algorithm, - phase1_negotiation_mode, - lifetime_units, - lifetime_value, - ike_version, - pfs, - **kwargs) - if res.status_int >= 400: - raise webob.exc.HTTPClientError(code=res.status_int) - ikepolicy = self.deserialize(fmt or self.fmt, res) - yield ikepolicy - if not no_delete: - self._delete('ikepolicies', ikepolicy['ikepolicy']['id']) - - def _create_ipsecpolicy(self, fmt, - name='ipsecpolicy1', - auth_algorithm='sha1', - encryption_algorithm='aes-128', - encapsulation_mode='tunnel', - transform_protocol='esp', - lifetime_units='seconds', - lifetime_value=3600, - pfs='group5', - expected_res_status=None, - **kwargs): - - data = {'ipsecpolicy': {'name': name, - 'auth_algorithm': auth_algorithm, - 'encryption_algorithm': encryption_algorithm, - 'encapsulation_mode': encapsulation_mode, - 'transform_protocol': transform_protocol, - 'lifetime': {'units': lifetime_units, - 'value': lifetime_value}, - 'pfs': pfs, - 'tenant_id': self._tenant_id}} - for arg in ['description']: - if arg in kwargs and kwargs[arg] is not None: - data['ipsecpolicy'][arg] = kwargs[arg] - ipsecpolicy_req = self.new_create_request('ipsecpolicies', data, fmt) - ipsecpolicy_res = ipsecpolicy_req.get_response(self.ext_api) - if expected_res_status: - self.assertEqual(ipsecpolicy_res.status_int, expected_res_status) - - return ipsecpolicy_res - - @contextlib.contextmanager - def ipsecpolicy(self, fmt=None, - name='ipsecpolicy1', - auth_algorithm='sha1', - encryption_algorithm='aes-128', - encapsulation_mode='tunnel', - transform_protocol='esp', - lifetime_units='seconds', - lifetime_value=3600, - pfs='group5', - no_delete=False, **kwargs): - if not fmt: - fmt = self.fmt - res = self._create_ipsecpolicy(fmt, - name, - auth_algorithm, - encryption_algorithm, - encapsulation_mode, - transform_protocol, - lifetime_units, - lifetime_value, - pfs, - **kwargs) - if res.status_int >= 400: - raise webob.exc.HTTPClientError(code=res.status_int) - ipsecpolicy = self.deserialize(fmt or self.fmt, res) - yield ipsecpolicy - if not no_delete: - self._delete('ipsecpolicies', ipsecpolicy['ipsecpolicy']['id']) - - def _create_vpnservice(self, fmt, name, - admin_state_up, - router_id, subnet_id, - expected_res_status=None, **kwargs): - tenant_id = kwargs.get('tenant_id', self._tenant_id) - data = {'vpnservice': {'name': name, - 'subnet_id': subnet_id, - 'router_id': router_id, - 'admin_state_up': admin_state_up, - 'tenant_id': tenant_id}} - for arg in ['description']: - if arg in kwargs and kwargs[arg] is not None: - data['vpnservice'][arg] = kwargs[arg] - vpnservice_req = self.new_create_request('vpnservices', data, fmt) - if (kwargs.get('set_context') and - 'tenant_id' in kwargs): - # create a specific auth context for this request - vpnservice_req.environ['neutron.context'] = context.Context( - '', kwargs['tenant_id']) - vpnservice_res = vpnservice_req.get_response(self.ext_api) - if expected_res_status: - self.assertEqual(vpnservice_res.status_int, expected_res_status) - return vpnservice_res - - @contextlib.contextmanager - def vpnservice(self, fmt=None, name='vpnservice1', - subnet=None, - router=None, - admin_state_up=True, - no_delete=False, - plug_subnet=True, - external_subnet_cidr='192.168.100.0/24', - external_router=True, - **kwargs): - if not fmt: - fmt = self.fmt - with contextlib.nested( - test_db_plugin.optional_ctx(subnet, self.subnet), - test_db_plugin.optional_ctx(router, self.router), - self.subnet(cidr=external_subnet_cidr)) as (tmp_subnet, - tmp_router, - public_sub): - if external_router: - self._set_net_external( - public_sub['subnet']['network_id']) - self._add_external_gateway_to_router( - tmp_router['router']['id'], - public_sub['subnet']['network_id']) - tmp_router['router']['external_gateway_info'] = { - 'network_id': public_sub['subnet']['network_id']} - if plug_subnet: - self._router_interface_action( - 'add', - tmp_router['router']['id'], - tmp_subnet['subnet']['id'], None) - - res = self._create_vpnservice(fmt, - name, - admin_state_up, - router_id=(tmp_router['router'] - ['id']), - subnet_id=(tmp_subnet['subnet'] - ['id']), - **kwargs) - vpnservice = self.deserialize(fmt or self.fmt, res) - if res.status_int < 400: - yield vpnservice - - if not no_delete and vpnservice.get('vpnservice'): - self._delete('vpnservices', - vpnservice['vpnservice']['id']) - if plug_subnet: - self._router_interface_action( - 'remove', - tmp_router['router']['id'], - tmp_subnet['subnet']['id'], None) - if external_router: - external_gateway = tmp_router['router'].get( - 'external_gateway_info') - if external_gateway: - network_id = external_gateway['network_id'] - self._remove_external_gateway_from_router( - tmp_router['router']['id'], network_id) - if res.status_int >= 400: - raise webob.exc.HTTPClientError( - code=res.status_int, detail=vpnservice) - - def _create_ipsec_site_connection(self, fmt, name='test', - peer_address='192.168.1.10', - peer_id='192.168.1.10', - peer_cidrs=None, - mtu=1500, - psk='abcdefg', - initiator='bi-directional', - dpd_action='hold', - dpd_interval=30, - dpd_timeout=120, - vpnservice_id='fake_id', - ikepolicy_id='fake_id', - ipsecpolicy_id='fake_id', - admin_state_up=True, - expected_res_status=None, **kwargs): - data = { - 'ipsec_site_connection': {'name': name, - 'peer_address': peer_address, - 'peer_id': peer_id, - 'peer_cidrs': peer_cidrs, - 'mtu': mtu, - 'psk': psk, - 'initiator': initiator, - 'dpd': { - 'action': dpd_action, - 'interval': dpd_interval, - 'timeout': dpd_timeout, - }, - 'vpnservice_id': vpnservice_id, - 'ikepolicy_id': ikepolicy_id, - 'ipsecpolicy_id': ipsecpolicy_id, - 'admin_state_up': admin_state_up, - 'tenant_id': self._tenant_id} - } - for arg in ['description']: - if arg in kwargs and kwargs[arg] is not None: - data['ipsec_site_connection'][arg] = kwargs[arg] - - ipsec_site_connection_req = self.new_create_request( - 'ipsec-site-connections', data, fmt - ) - ipsec_site_connection_res = ipsec_site_connection_req.get_response( - self.ext_api - ) - if expected_res_status: - self.assertEqual( - ipsec_site_connection_res.status_int, expected_res_status - ) - - return ipsec_site_connection_res - - @contextlib.contextmanager - def ipsec_site_connection(self, fmt=None, name='ipsec_site_connection1', - peer_address='192.168.1.10', - peer_id='192.168.1.10', - peer_cidrs=None, - mtu=1500, - psk='abcdefg', - initiator='bi-directional', - dpd_action='hold', - dpd_interval=30, - dpd_timeout=120, - vpnservice=None, - ikepolicy=None, - ipsecpolicy=None, - admin_state_up=True, no_delete=False, - **kwargs): - if not fmt: - fmt = self.fmt - with contextlib.nested( - test_db_plugin.optional_ctx(vpnservice, - self.vpnservice), - test_db_plugin.optional_ctx(ikepolicy, - self.ikepolicy), - test_db_plugin.optional_ctx(ipsecpolicy, - self.ipsecpolicy) - ) as (tmp_vpnservice, tmp_ikepolicy, tmp_ipsecpolicy): - vpnservice_id = tmp_vpnservice['vpnservice']['id'] - ikepolicy_id = tmp_ikepolicy['ikepolicy']['id'] - ipsecpolicy_id = tmp_ipsecpolicy['ipsecpolicy']['id'] - res = self._create_ipsec_site_connection(fmt, - name, - peer_address, - peer_id, - peer_cidrs, - mtu, - psk, - initiator, - dpd_action, - dpd_interval, - dpd_timeout, - vpnservice_id, - ikepolicy_id, - ipsecpolicy_id, - admin_state_up, - **kwargs) - if res.status_int >= 400: - raise webob.exc.HTTPClientError(code=res.status_int) - - ipsec_site_connection = self.deserialize( - fmt or self.fmt, res - ) - yield ipsec_site_connection - - if not no_delete: - self._delete( - 'ipsec-site-connections', - ipsec_site_connection[ - 'ipsec_site_connection']['id'] - ) - - def _check_ipsec_site_connection(self, ipsec_site_connection, keys, dpd): - self.assertEqual( - keys, - dict((k, v) for k, v - in ipsec_site_connection.items() - if k in keys)) - self.assertEqual( - dpd, - dict((k, v) for k, v - in ipsec_site_connection['dpd'].items() - if k in dpd)) - - def _set_active(self, model, resource_id): - service_plugin = manager.NeutronManager.get_service_plugins()[ - constants.VPN] - adminContext = context.get_admin_context() - with adminContext.session.begin(subtransactions=True): - resource_db = service_plugin._get_resource( - adminContext, - model, - resource_id) - resource_db.status = constants.ACTIVE - - -class VPNPluginDbTestCase(VPNTestMixin, - test_l3_plugin.L3NatTestCaseMixin, - test_db_plugin.NeutronDbPluginV2TestCase): - def setUp(self, core_plugin=None, vpnaas_plugin=DB_VPN_PLUGIN_KLASS, - vpnaas_provider=None): - if not vpnaas_provider: - vpnaas_provider = ( - constants.VPN + - ':vpnaas:neutron.services.vpn.' - 'service_drivers.ipsec.IPsecVPNDriver:default') - - cfg.CONF.set_override('service_provider', - [vpnaas_provider], - 'service_providers') - # force service type manager to reload configuration: - sdb.ServiceTypeManager._instance = None - - service_plugins = {'vpnaas_plugin': vpnaas_plugin} - plugin_str = ('neutron.tests.unit.db.vpn.' - 'test_db_vpnaas.TestVpnCorePlugin') - - super(VPNPluginDbTestCase, self).setUp( - plugin_str, - service_plugins=service_plugins - ) - self._subnet_id = uuidutils.generate_uuid() - self.core_plugin = TestVpnCorePlugin - self.plugin = vpn_plugin.VPNPlugin() - ext_mgr = api_extensions.PluginAwareExtensionManager( - extensions_path, - {constants.CORE: self.core_plugin, - constants.VPN: self.plugin} - ) - app = config.load_paste_app('extensions_test_app') - self.ext_api = api_extensions.ExtensionMiddleware(app, ext_mgr=ext_mgr) - - -class TestVpnaas(VPNPluginDbTestCase): - - def _check_policy(self, policy, keys, lifetime): - for k, v in keys: - self.assertEqual(policy[k], v) - for k, v in lifetime.iteritems(): - self.assertEqual(policy['lifetime'][k], v) - - def test_create_ikepolicy(self): - """Test case to create an ikepolicy.""" - name = "ikepolicy1" - description = 'ipsec-ikepolicy' - keys = [('name', name), - ('description', 'ipsec-ikepolicy'), - ('auth_algorithm', 'sha1'), - ('encryption_algorithm', 'aes-128'), - ('phase1_negotiation_mode', 'main'), - ('ike_version', 'v1'), - ('pfs', 'group5'), - ('tenant_id', self._tenant_id)] - lifetime = { - 'units': 'seconds', - 'value': 3600} - with self.ikepolicy(name=name, description=description) as ikepolicy: - self._check_policy(ikepolicy['ikepolicy'], keys, lifetime) - - def test_delete_ikepolicy(self): - """Test case to delete an ikepolicy.""" - with self.ikepolicy(no_delete=True) as ikepolicy: - req = self.new_delete_request('ikepolicies', - ikepolicy['ikepolicy']['id']) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, 204) - - def test_show_ikepolicy(self): - """Test case to show or get an ikepolicy.""" - name = "ikepolicy1" - description = 'ipsec-ikepolicy' - keys = [('name', name), - ('auth_algorithm', 'sha1'), - ('encryption_algorithm', 'aes-128'), - ('phase1_negotiation_mode', 'main'), - ('ike_version', 'v1'), - ('pfs', 'group5'), - ('tenant_id', self._tenant_id)] - lifetime = { - 'units': 'seconds', - 'value': 3600} - with self.ikepolicy(name=name, description=description) as ikepolicy: - req = self.new_show_request('ikepolicies', - ikepolicy['ikepolicy']['id'], - fmt=self.fmt) - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - self._check_policy(res['ikepolicy'], keys, lifetime) - - def test_list_ikepolicies(self): - """Test case to list all ikepolicies.""" - name = "ikepolicy_list" - keys = [('name', name), - ('auth_algorithm', 'sha1'), - ('encryption_algorithm', 'aes-128'), - ('phase1_negotiation_mode', 'main'), - ('ike_version', 'v1'), - ('pfs', 'group5'), - ('tenant_id', self._tenant_id)] - lifetime = { - 'units': 'seconds', - 'value': 3600} - with self.ikepolicy(name=name) as ikepolicy: - keys.append(('id', ikepolicy['ikepolicy']['id'])) - req = self.new_list_request('ikepolicies') - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - self.assertEqual(len(res), 1) - for k, v in keys: - self.assertEqual(res['ikepolicies'][0][k], v) - for k, v in lifetime.iteritems(): - self.assertEqual(res['ikepolicies'][0]['lifetime'][k], v) - - def test_list_ikepolicies_with_sort_emulated(self): - """Test case to list all ikepolicies.""" - with contextlib.nested(self.ikepolicy(name='ikepolicy1'), - self.ikepolicy(name='ikepolicy2'), - self.ikepolicy(name='ikepolicy3') - ) as (ikepolicy1, ikepolicy2, ikepolicy3): - self._test_list_with_sort('ikepolicy', (ikepolicy3, - ikepolicy2, - ikepolicy1), - [('name', 'desc')], - 'ikepolicies') - - def test_list_ikepolicies_with_pagination_emulated(self): - """Test case to list all ikepolicies with pagination.""" - with contextlib.nested(self.ikepolicy(name='ikepolicy1'), - self.ikepolicy(name='ikepolicy2'), - self.ikepolicy(name='ikepolicy3') - ) as (ikepolicy1, ikepolicy2, ikepolicy3): - self._test_list_with_pagination('ikepolicy', - (ikepolicy1, - ikepolicy2, - ikepolicy3), - ('name', 'asc'), 2, 2, - 'ikepolicies') - - def test_list_ikepolicies_with_pagination_reverse_emulated(self): - """Test case to list all ikepolicies with reverse pagination.""" - with contextlib.nested(self.ikepolicy(name='ikepolicy1'), - self.ikepolicy(name='ikepolicy2'), - self.ikepolicy(name='ikepolicy3') - ) as (ikepolicy1, ikepolicy2, ikepolicy3): - self._test_list_with_pagination_reverse('ikepolicy', - (ikepolicy1, - ikepolicy2, - ikepolicy3), - ('name', 'asc'), 2, 2, - 'ikepolicies') - - def test_update_ikepolicy(self): - """Test case to update an ikepolicy.""" - name = "new_ikepolicy1" - keys = [('name', name), - ('auth_algorithm', 'sha1'), - ('encryption_algorithm', 'aes-128'), - ('phase1_negotiation_mode', 'main'), - ('ike_version', 'v1'), - ('pfs', 'group5'), - ('tenant_id', self._tenant_id), - ('lifetime', {'units': 'seconds', - 'value': 60})] - with self.ikepolicy(name=name) as ikepolicy: - data = {'ikepolicy': {'name': name, - 'lifetime': {'units': 'seconds', - 'value': 60}}} - req = self.new_update_request("ikepolicies", - data, - ikepolicy['ikepolicy']['id']) - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - for k, v in keys: - self.assertEqual(res['ikepolicy'][k], v) - - def test_create_ikepolicy_with_invalid_values(self): - """Test case to test invalid values.""" - name = 'ikepolicy1' - self._create_ikepolicy(name=name, - fmt=self.fmt, - auth_algorithm='md5', - expected_res_status=400) - self._create_ikepolicy(name=name, - fmt=self.fmt, - auth_algorithm=200, - expected_res_status=400) - self._create_ikepolicy(name=name, - fmt=self.fmt, - encryption_algorithm='des', - expected_res_status=400) - self._create_ikepolicy(name=name, - fmt=self.fmt, - encryption_algorithm=100, - expected_res_status=400) - self._create_ikepolicy(name=name, - fmt=self.fmt, - phase1_negotiation_mode='aggressive', - expected_res_status=400) - self._create_ikepolicy(name=name, - fmt=self.fmt, - phase1_negotiation_mode=-100, - expected_res_status=400) - self._create_ikepolicy(name=name, - fmt=self.fmt, - ike_version='v6', - expected_res_status=400) - self._create_ikepolicy(name=name, - fmt=self.fmt, - ike_version=500, - expected_res_status=400) - self._create_ikepolicy(name=name, - fmt=self.fmt, - pfs='group1', - expected_res_status=400) - self._create_ikepolicy(name=name, - fmt=self.fmt, - pfs=120, - expected_res_status=400) - self._create_ikepolicy(name=name, - fmt=self.fmt, - lifetime_units='Megabytes', - expected_res_status=400) - self._create_ikepolicy(name=name, - fmt=self.fmt, - lifetime_units=20000, - expected_res_status=400) - self._create_ikepolicy(name=name, - fmt=self.fmt, - lifetime_value=-20, - expected_res_status=400) - self._create_ikepolicy(name=name, - fmt=self.fmt, - lifetime_value='Megabytes', - expected_res_status=400) - - def test_create_ipsecpolicy(self): - """Test case to create an ipsecpolicy.""" - name = "ipsecpolicy1" - description = 'my-ipsecpolicy' - keys = [('name', name), - ('description', 'my-ipsecpolicy'), - ('auth_algorithm', 'sha1'), - ('encryption_algorithm', 'aes-128'), - ('encapsulation_mode', 'tunnel'), - ('transform_protocol', 'esp'), - ('pfs', 'group5'), - ('tenant_id', self._tenant_id)] - lifetime = { - 'units': 'seconds', - 'value': 3600} - with self.ipsecpolicy(name=name, - description=description) as ipsecpolicy: - self._check_policy(ipsecpolicy['ipsecpolicy'], keys, lifetime) - - def test_delete_ipsecpolicy(self): - """Test case to delete an ipsecpolicy.""" - with self.ipsecpolicy(no_delete=True) as ipsecpolicy: - req = self.new_delete_request('ipsecpolicies', - ipsecpolicy['ipsecpolicy']['id']) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, 204) - - def test_show_ipsecpolicy(self): - """Test case to show or get an ipsecpolicy.""" - name = "ipsecpolicy1" - keys = [('name', name), - ('auth_algorithm', 'sha1'), - ('encryption_algorithm', 'aes-128'), - ('encapsulation_mode', 'tunnel'), - ('transform_protocol', 'esp'), - ('pfs', 'group5'), - ('tenant_id', self._tenant_id)] - lifetime = { - 'units': 'seconds', - 'value': 3600} - with self.ipsecpolicy(name=name) as ipsecpolicy: - req = self.new_show_request('ipsecpolicies', - ipsecpolicy['ipsecpolicy']['id'], - fmt=self.fmt) - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - self._check_policy(res['ipsecpolicy'], keys, lifetime) - - def test_list_ipsecpolicies(self): - """Test case to list all ipsecpolicies.""" - name = "ipsecpolicy_list" - keys = [('name', name), - ('auth_algorithm', 'sha1'), - ('encryption_algorithm', 'aes-128'), - ('encapsulation_mode', 'tunnel'), - ('transform_protocol', 'esp'), - ('pfs', 'group5'), - ('tenant_id', self._tenant_id)] - lifetime = { - 'units': 'seconds', - 'value': 3600} - with self.ipsecpolicy(name=name) as ipsecpolicy: - keys.append(('id', ipsecpolicy['ipsecpolicy']['id'])) - req = self.new_list_request('ipsecpolicies') - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - self.assertEqual(len(res), 1) - self._check_policy(res['ipsecpolicies'][0], keys, lifetime) - - def test_list_ipsecpolicies_with_sort_emulated(self): - """Test case to list all ipsecpolicies.""" - with contextlib.nested(self.ipsecpolicy(name='ipsecpolicy1'), - self.ipsecpolicy(name='ipsecpolicy2'), - self.ipsecpolicy(name='ipsecpolicy3') - ) as(ipsecpolicy1, ipsecpolicy2, ipsecpolicy3): - self._test_list_with_sort('ipsecpolicy', (ipsecpolicy3, - ipsecpolicy2, - ipsecpolicy1), - [('name', 'desc')], - 'ipsecpolicies') - - def test_list_ipsecpolicies_with_pagination_emulated(self): - """Test case to list all ipsecpolicies with pagination.""" - with contextlib.nested(self.ipsecpolicy(name='ipsecpolicy1'), - self.ipsecpolicy(name='ipsecpolicy2'), - self.ipsecpolicy(name='ipsecpolicy3') - ) as(ipsecpolicy1, ipsecpolicy2, ipsecpolicy3): - self._test_list_with_pagination('ipsecpolicy', - (ipsecpolicy1, - ipsecpolicy2, - ipsecpolicy3), - ('name', 'asc'), 2, 2, - 'ipsecpolicies') - - def test_list_ipsecpolicies_with_pagination_reverse_emulated(self): - """Test case to list all ipsecpolicies with reverse pagination.""" - with contextlib.nested(self.ipsecpolicy(name='ipsecpolicy1'), - self.ipsecpolicy(name='ipsecpolicy2'), - self.ipsecpolicy(name='ipsecpolicy3') - ) as(ipsecpolicy1, ipsecpolicy2, ipsecpolicy3): - self._test_list_with_pagination_reverse('ipsecpolicy', - (ipsecpolicy1, - ipsecpolicy2, - ipsecpolicy3), - ('name', 'asc'), 2, 2, - 'ipsecpolicies') - - def test_update_ipsecpolicy(self): - """Test case to update an ipsecpolicy.""" - name = "new_ipsecpolicy1" - keys = [('name', name), - ('auth_algorithm', 'sha1'), - ('encryption_algorithm', 'aes-128'), - ('encapsulation_mode', 'tunnel'), - ('transform_protocol', 'esp'), - ('pfs', 'group5'), - ('tenant_id', self._tenant_id), - ('lifetime', {'units': 'seconds', - 'value': 60})] - with self.ipsecpolicy(name=name) as ipsecpolicy: - data = {'ipsecpolicy': {'name': name, - 'lifetime': {'units': 'seconds', - 'value': 60}}} - req = self.new_update_request("ipsecpolicies", - data, - ipsecpolicy['ipsecpolicy']['id']) - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - for k, v in keys: - self.assertEqual(res['ipsecpolicy'][k], v) - - def test_update_ipsecpolicy_lifetime(self): - with self.ipsecpolicy() as ipsecpolicy: - data = {'ipsecpolicy': {'lifetime': {'units': 'seconds'}}} - req = self.new_update_request("ipsecpolicies", - data, - ipsecpolicy['ipsecpolicy']['id']) - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - self.assertEqual(res['ipsecpolicy']['lifetime']['units'], - 'seconds') - - data = {'ipsecpolicy': {'lifetime': {'value': 60}}} - req = self.new_update_request("ipsecpolicies", - data, - ipsecpolicy['ipsecpolicy']['id']) - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - self.assertEqual(res['ipsecpolicy']['lifetime']['value'], 60) - - def test_create_ipsecpolicy_with_invalid_values(self): - """Test case to test invalid values.""" - name = 'ipsecpolicy1' - - self._create_ipsecpolicy( - fmt=self.fmt, - name=name, auth_algorithm='md5', expected_res_status=400) - self._create_ipsecpolicy( - fmt=self.fmt, - name=name, auth_algorithm=100, expected_res_status=400) - - self._create_ipsecpolicy( - fmt=self.fmt, - name=name, encryption_algorithm='des', expected_res_status=400) - self._create_ipsecpolicy( - fmt=self.fmt, - name=name, encryption_algorithm=200, expected_res_status=400) - - self._create_ipsecpolicy( - fmt=self.fmt, - name=name, transform_protocol='abcd', expected_res_status=400) - self._create_ipsecpolicy( - fmt=self.fmt, - name=name, transform_protocol=500, expected_res_status=400) - - self._create_ipsecpolicy( - fmt=self.fmt, - name=name, - encapsulation_mode='unsupported', expected_res_status=400) - self._create_ipsecpolicy(name=name, - fmt=self.fmt, - encapsulation_mode=100, - expected_res_status=400) - - self._create_ipsecpolicy(name=name, - fmt=self.fmt, - pfs='group9', expected_res_status=400) - self._create_ipsecpolicy( - fmt=self.fmt, name=name, pfs=-1, expected_res_status=400) - - self._create_ipsecpolicy( - fmt=self.fmt, name=name, lifetime_units='minutes', - expected_res_status=400) - - self._create_ipsecpolicy(fmt=self.fmt, name=name, lifetime_units=100, - expected_res_status=400) - - self._create_ipsecpolicy(fmt=self.fmt, name=name, - lifetime_value=-800, expected_res_status=400) - self._create_ipsecpolicy(fmt=self.fmt, name=name, - lifetime_value='Megabytes', - expected_res_status=400) - - def test_create_vpnservice(self, **extras): - """Test case to create a vpnservice.""" - description = 'my-vpn-service' - expected = {'name': 'vpnservice1', - 'description': 'my-vpn-service', - 'admin_state_up': True, - 'status': 'PENDING_CREATE', - 'tenant_id': self._tenant_id, } - - expected.update(extras) - with self.subnet(cidr='10.2.0.0/24') as subnet: - with self.router() as router: - expected['router_id'] = router['router']['id'] - expected['subnet_id'] = subnet['subnet']['id'] - name = expected['name'] - with self.vpnservice(name=name, - subnet=subnet, - router=router, - description=description, - **extras) as vpnservice: - self.assertEqual(dict((k, v) for k, v in - vpnservice['vpnservice'].items() - if k in expected), - expected) - - def test_create_vpnservice_with_invalid_router(self): - """Test case to create a vpnservice with other tenant's router""" - with self.network( - set_context=True, - tenant_id='tenant_a') as network: - with self.subnet(network=network, - cidr='10.2.0.0/24') as subnet: - with self.router( - set_context=True, tenant_id='tenant_a') as router: - router_id = router['router']['id'] - subnet_id = subnet['subnet']['id'] - self._create_vpnservice( - self.fmt, 'fake', - True, router_id, subnet_id, - expected_res_status=webob.exc.HTTPNotFound.code, - set_context=True, tenant_id='tenant_b') - - def test_create_vpnservice_with_router_no_external_gateway(self): - """Test case to create a vpnservice with inner router""" - error_code = 0 - with self.subnet(cidr='10.2.0.0/24') as subnet: - with self.router() as router: - router_id = router['router']['id'] - try: - with self.vpnservice(subnet=subnet, - router=router, - external_router=False): - pass - except webob.exc.HTTPClientError as e: - error_code, error_detail = ( - e.status_code, e.detail['NeutronError']['message']) - self.assertEqual(400, error_code) - msg = str(vpnaas.RouterIsNotExternal(router_id=router_id)) - self.assertEqual(msg, error_detail) - - def test_create_vpnservice_with_nonconnected_subnet(self): - """Test case to create a vpnservice with nonconnected subnet.""" - with self.network() as network: - with self.subnet(network=network, - cidr='10.2.0.0/24') as subnet: - with self.router() as router: - router_id = router['router']['id'] - subnet_id = subnet['subnet']['id'] - self._create_vpnservice( - self.fmt, 'fake', - True, router_id, subnet_id, - expected_res_status=webob.exc.HTTPBadRequest.code) - - def test_delete_router_in_use_by_vpnservice(self): - """Test delete router in use by vpn service.""" - with self.subnet(cidr='10.2.0.0/24') as subnet: - with self.router() as router: - with self.vpnservice(subnet=subnet, - router=router): - self._delete('routers', router['router']['id'], - expected_code=webob.exc.HTTPConflict.code) - - def test_update_vpnservice(self): - """Test case to update a vpnservice.""" - name = 'new_vpnservice1' - keys = [('name', name)] - with contextlib.nested( - self.subnet(cidr='10.2.0.0/24'), - self.router()) as (subnet, router): - with self.vpnservice(name=name, - subnet=subnet, - router=router) as vpnservice: - keys.append(('subnet_id', - vpnservice['vpnservice']['subnet_id'])) - keys.append(('router_id', - vpnservice['vpnservice']['router_id'])) - data = {'vpnservice': {'name': name}} - self._set_active(vpn_db.VPNService, - vpnservice['vpnservice']['id']) - req = self.new_update_request( - 'vpnservices', - data, - vpnservice['vpnservice']['id']) - res = self.deserialize(self.fmt, - req.get_response(self.ext_api)) - for k, v in keys: - self.assertEqual(res['vpnservice'][k], v) - - def test_update_vpnservice_with_invalid_state(self): - """Test case to update a vpnservice in invalid state .""" - name = 'new_vpnservice1' - keys = [('name', name)] - with contextlib.nested( - self.subnet(cidr='10.2.0.0/24'), - self.router()) as (subnet, router): - with self.vpnservice(name=name, - subnet=subnet, - router=router) as vpnservice: - keys.append(('subnet_id', - vpnservice['vpnservice']['subnet_id'])) - keys.append(('router_id', - vpnservice['vpnservice']['router_id'])) - data = {'vpnservice': {'name': name}} - req = self.new_update_request( - 'vpnservices', - data, - vpnservice['vpnservice']['id']) - res = req.get_response(self.ext_api) - self.assertEqual(400, res.status_int) - res = self.deserialize(self.fmt, res) - self.assertIn(vpnservice['vpnservice']['id'], - res['NeutronError']['message']) - - def test_delete_vpnservice(self): - """Test case to delete a vpnservice.""" - with self.vpnservice(name='vpnserver', - no_delete=True) as vpnservice: - req = self.new_delete_request('vpnservices', - vpnservice['vpnservice']['id']) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, 204) - - def test_show_vpnservice(self): - """Test case to show or get a vpnservice.""" - name = "vpnservice1" - keys = [('name', name), - ('description', ''), - ('admin_state_up', True), - ('status', 'PENDING_CREATE')] - with self.vpnservice(name=name) as vpnservice: - req = self.new_show_request('vpnservices', - vpnservice['vpnservice']['id']) - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - for k, v in keys: - self.assertEqual(res['vpnservice'][k], v) - - def test_list_vpnservices(self): - """Test case to list all vpnservices.""" - name = "vpnservice_list" - keys = [('name', name), - ('description', ''), - ('admin_state_up', True), - ('status', 'PENDING_CREATE')] - with self.vpnservice(name=name) as vpnservice: - keys.append(('subnet_id', vpnservice['vpnservice']['subnet_id'])) - keys.append(('router_id', vpnservice['vpnservice']['router_id'])) - req = self.new_list_request('vpnservices') - res = self.deserialize(self.fmt, req.get_response(self.ext_api)) - self.assertEqual(len(res), 1) - for k, v in keys: - self.assertEqual(res['vpnservices'][0][k], v) - - def test_list_vpnservices_with_sort_emulated(self): - """Test case to list all vpnservices with sorting.""" - with self.subnet() as subnet: - with self.router() as router: - with contextlib.nested( - self.vpnservice(name='vpnservice1', - subnet=subnet, - router=router, - external_subnet_cidr='192.168.10.0/24',), - self.vpnservice(name='vpnservice2', - subnet=subnet, - router=router, - plug_subnet=False, - external_router=False, - external_subnet_cidr='192.168.11.0/24',), - self.vpnservice(name='vpnservice3', - subnet=subnet, - router=router, - plug_subnet=False, - external_router=False, - external_subnet_cidr='192.168.13.0/24',) - ) as(vpnservice1, vpnservice2, vpnservice3): - self._test_list_with_sort('vpnservice', (vpnservice3, - vpnservice2, - vpnservice1), - [('name', 'desc')]) - - def test_list_vpnservice_with_pagination_emulated(self): - """Test case to list all vpnservices with pagination.""" - with self.subnet() as subnet: - with self.router() as router: - with contextlib.nested( - self.vpnservice(name='vpnservice1', - subnet=subnet, - router=router, - external_subnet_cidr='192.168.10.0/24'), - self.vpnservice(name='vpnservice2', - subnet=subnet, - router=router, - plug_subnet=False, - external_subnet_cidr='192.168.20.0/24', - external_router=False), - self.vpnservice(name='vpnservice3', - subnet=subnet, - router=router, - plug_subnet=False, - external_subnet_cidr='192.168.30.0/24', - external_router=False) - ) as(vpnservice1, vpnservice2, vpnservice3): - self._test_list_with_pagination('vpnservice', - (vpnservice1, - vpnservice2, - vpnservice3), - ('name', 'asc'), 2, 2) - - def test_list_vpnservice_with_pagination_reverse_emulated(self): - """Test case to list all vpnservices with reverse pagination.""" - with self.subnet() as subnet: - with self.router() as router: - with contextlib.nested( - self.vpnservice(name='vpnservice1', - subnet=subnet, - router=router, - external_subnet_cidr='192.168.10.0/24'), - self.vpnservice(name='vpnservice2', - subnet=subnet, - router=router, - plug_subnet=False, - external_subnet_cidr='192.168.11.0/24', - external_router=False), - self.vpnservice(name='vpnservice3', - subnet=subnet, - router=router, - plug_subnet=False, - external_subnet_cidr='192.168.12.0/24', - external_router=False) - ) as(vpnservice1, vpnservice2, vpnservice3): - self._test_list_with_pagination_reverse('vpnservice', - (vpnservice1, - vpnservice2, - vpnservice3), - ('name', 'asc'), - 2, 2) - - def test_create_ipsec_site_connection_with_invalid_values(self): - """Test case to create an ipsec_site_connection with invalid values.""" - name = 'connection1' - self._create_ipsec_site_connection( - fmt=self.fmt, - name=name, peer_cidrs='myname', expected_status_int=400) - self._create_ipsec_site_connection( - fmt=self.fmt, - name=name, mtu=-100, expected_status_int=400) - self._create_ipsec_site_connection( - fmt=self.fmt, - name=name, dpd_action='unsupported', expected_status_int=400) - self._create_ipsec_site_connection( - fmt=self.fmt, - name=name, dpd_interval=-1, expected_status_int=400) - self._create_ipsec_site_connection( - fmt=self.fmt, - name=name, dpd_timeout=-200, expected_status_int=400) - self._create_ipsec_site_connection( - fmt=self.fmt, - name=name, initiator='unsupported', expected_status_int=400) - self._create_ipsec_site_connection( - fmt=self.fmt, - name=name, - dpd_interval=30, - dpd_timeout=20, expected_status_int=400) - self._create_ipsec_site_connection( - fmt=self.fmt, - name=name, - dpd_interval=100, - dpd_timeout=100, expected_status_int=400) - - def _test_create_ipsec_site_connection(self, key_overrides=None, - setup_overrides=None, - expected_status_int=200): - """Create ipsec_site_connection and check results.""" - params = {'ikename': 'ikepolicy1', - 'ipsecname': 'ipsecpolicy1', - 'vpnsname': 'vpnservice1', - 'subnet_cidr': '10.2.0.0/24', - 'subnet_version': 4} - if setup_overrides is not None: - params.update(setup_overrides) - keys = {'name': 'connection1', - 'description': 'my-ipsec-connection', - 'peer_address': '192.168.1.10', - 'peer_id': '192.168.1.10', - 'peer_cidrs': ['192.168.2.0/24', '192.168.3.0/24'], - 'initiator': 'bi-directional', - 'mtu': 1500, - 'tenant_id': self._tenant_id, - 'psk': 'abcd', - 'status': 'PENDING_CREATE', - 'admin_state_up': True} - if key_overrides is not None: - keys.update(key_overrides) - dpd = {'action': 'hold', - 'interval': 40, - 'timeout': 120} - with contextlib.nested( - self.ikepolicy(name=params['ikename']), - self.ipsecpolicy(name=params['ipsecname']), - self.subnet(cidr=params['subnet_cidr'], - ip_version=params['subnet_version']), - self.router()) as ( - ikepolicy, ipsecpolicy, subnet, router): - with self.vpnservice(name=params['vpnsname'], subnet=subnet, - router=router) as vpnservice1: - keys['ikepolicy_id'] = ikepolicy['ikepolicy']['id'] - keys['ipsecpolicy_id'] = ( - ipsecpolicy['ipsecpolicy']['id'] - ) - keys['vpnservice_id'] = ( - vpnservice1['vpnservice']['id'] - ) - try: - with self.ipsec_site_connection( - self.fmt, - keys['name'], - keys['peer_address'], - keys['peer_id'], - keys['peer_cidrs'], - keys['mtu'], - keys['psk'], - keys['initiator'], - dpd['action'], - dpd['interval'], - dpd['timeout'], - vpnservice1, - ikepolicy, - ipsecpolicy, - keys['admin_state_up'], - description=keys['description'] - ) as ipsec_site_connection: - if expected_status_int != 200: - self.fail("Expected failure on create") - self._check_ipsec_site_connection( - ipsec_site_connection['ipsec_site_connection'], - keys, - dpd) - except webob.exc.HTTPClientError as ce: - self.assertEqual(ce.code, expected_status_int) - - def test_create_ipsec_site_connection(self, **extras): - """Test case to create an ipsec_site_connection.""" - self._test_create_ipsec_site_connection(key_overrides=extras) - - def test_create_ipsec_site_connection_invalid_mtu(self): - """Test creating an ipsec_site_connection with invalid MTU.""" - self._test_create_ipsec_site_connection(key_overrides={'mtu': 67}, - expected_status_int=400) - ipv6_overrides = { - 'peer_address': 'fe80::c0a8:10a', - 'peer_id': 'fe80::c0a8:10a', - 'peer_cidrs': ['fe80::c0a8:200/120', 'fe80::c0a8:300/120'], - 'mtu': 1279} - ipv6_setup_params = {'subnet_cidr': 'fe80::a01:0/120', - 'subnet_version': 6} - self._test_create_ipsec_site_connection( - key_overrides=ipv6_overrides, - setup_overrides=ipv6_setup_params, - expected_status_int=400) - - def test_delete_ipsec_site_connection(self): - """Test case to delete a ipsec_site_connection.""" - with self.ipsec_site_connection( - no_delete=True) as ipsec_site_connection: - req = self.new_delete_request( - 'ipsec-site-connections', - ipsec_site_connection['ipsec_site_connection']['id'] - ) - res = req.get_response(self.ext_api) - self.assertEqual(res.status_int, 204) - - def test_update_ipsec_site_connection(self): - """Test case for valid updates to IPSec site connection.""" - dpd = {'action': 'hold', - 'interval': 40, - 'timeout': 120} - self._test_update_ipsec_site_connection(update={'dpd': dpd}) - self._test_update_ipsec_site_connection(update={'mtu': 2000}) - ipv6_settings = { - 'peer_address': 'fe80::c0a8:10a', - 'peer_id': 'fe80::c0a8:10a', - 'peer_cidrs': ['fe80::c0a8:200/120', 'fe80::c0a8:300/120'], - 'subnet_cidr': 'fe80::a02:0/120', - 'subnet_version': 6} - self._test_update_ipsec_site_connection(update={'mtu': 2000}, - overrides=ipv6_settings) - - def test_update_ipsec_site_connection_with_invalid_dpd(self): - """Test updates to ipsec_site_connection with invalid DPD settings.""" - dpd1 = {'action': 'hold', - 'interval': 100, - 'timeout': 100} - self._test_update_ipsec_site_connection( - update={'dpd': dpd1}, - expected_status_int=400) - dpd2 = {'action': 'hold', - 'interval': 100, - 'timeout': 60} - self._test_update_ipsec_site_connection( - update={'dpd': dpd2}, - expected_status_int=400) - dpd3 = {'action': 'hold', - 'interval': -50, - 'timeout': -100} - self._test_update_ipsec_site_connection( - update={'dpd': dpd3}, - expected_status_int=400) - - def test_update_ipsec_site_connection_with_invalid_mtu(self): - """Test updates to ipsec_site_connection with invalid MTU settings.""" - self._test_update_ipsec_site_connection( - update={'mtu': 67}, expected_status_int=400) - ipv6_settings = { - 'peer_address': 'fe80::c0a8:10a', - 'peer_id': 'fe80::c0a8:10a', - 'peer_cidrs': ['fe80::c0a8:200/120', 'fe80::c0a8:300/120'], - 'subnet_cidr': 'fe80::a02:0/120', - 'subnet_version': 6} - self._test_update_ipsec_site_connection( - update={'mtu': 1279}, - overrides=ipv6_settings, - expected_status_int=400) - - def test_update_ipsec_site_connection_with_invalid_state(self): - """Test updating an ipsec_site_connection in invalid state.""" - self._test_update_ipsec_site_connection( - overrides={'make_active': False}, - expected_status_int=400) - - def test_update_ipsec_site_connection_peer_cidrs(self): - """Test updating an ipsec_site_connection for peer_cidrs.""" - new_peers = {'peer_cidrs': ['192.168.4.0/24', - '192.168.5.0/24']} - self._test_update_ipsec_site_connection( - update=new_peers) - - def _test_update_ipsec_site_connection(self, - update={'name': 'new name'}, - overrides=None, - expected_status_int=200): - """Creates and then updates ipsec_site_connection.""" - keys = {'name': 'new_ipsec_site_connection', - 'ikename': 'ikepolicy1', - 'ipsecname': 'ipsecpolicy1', - 'vpnsname': 'vpnservice1', - 'description': 'my-ipsec-connection', - 'peer_address': '192.168.1.10', - 'peer_id': '192.168.1.10', - 'peer_cidrs': ['192.168.2.0/24', '192.168.3.0/24'], - 'initiator': 'bi-directional', - 'mtu': 1500, - 'tenant_id': self._tenant_id, - 'psk': 'abcd', - 'status': 'ACTIVE', - 'admin_state_up': True, - 'action': 'hold', - 'interval': 40, - 'timeout': 120, - 'subnet_cidr': '10.2.0.0/24', - 'subnet_version': 4, - 'make_active': True} - if overrides is not None: - keys.update(overrides) - - with contextlib.nested( - self.ikepolicy(name=keys['ikename']), - self.ipsecpolicy(name=keys['ipsecname']), - self.subnet(cidr=keys['subnet_cidr'], - ip_version=keys['subnet_version']), - self.router()) as ( - ikepolicy, ipsecpolicy, subnet, router): - with self.vpnservice(name=keys['vpnsname'], subnet=subnet, - router=router) as vpnservice1: - keys['vpnservice_id'] = vpnservice1['vpnservice']['id'] - keys['ikepolicy_id'] = ikepolicy['ikepolicy']['id'] - keys['ipsecpolicy_id'] = ipsecpolicy['ipsecpolicy']['id'] - with self.ipsec_site_connection( - self.fmt, - keys['name'], - keys['peer_address'], - keys['peer_id'], - keys['peer_cidrs'], - keys['mtu'], - keys['psk'], - keys['initiator'], - keys['action'], - keys['interval'], - keys['timeout'], - vpnservice1, - ikepolicy, - ipsecpolicy, - keys['admin_state_up'], - description=keys['description'] - ) as ipsec_site_connection: - data = {'ipsec_site_connection': update} - if keys.get('make_active', None): - self._set_active( - vpn_db.IPsecSiteConnection, - (ipsec_site_connection['ipsec_site_connection'] - ['id'])) - req = self.new_update_request( - 'ipsec-site-connections', - data, - ipsec_site_connection['ipsec_site_connection']['id']) - res = req.get_response(self.ext_api) - self.assertEqual(expected_status_int, res.status_int) - if expected_status_int == 200: - res_dict = self.deserialize(self.fmt, res) - for k, v in update.items(): - self.assertEqual( - res_dict['ipsec_site_connection'][k], v) - - def test_show_ipsec_site_connection(self): - """Test case to show a ipsec_site_connection.""" - ikename = "ikepolicy1" - ipsecname = "ipsecpolicy1" - vpnsname = "vpnservice1" - name = "connection1" - description = "my-ipsec-connection" - keys = {'name': name, - 'description': "my-ipsec-connection", - 'peer_address': '192.168.1.10', - 'peer_id': '192.168.1.10', - 'peer_cidrs': ['192.168.2.0/24', '192.168.3.0/24'], - 'initiator': 'bi-directional', - 'mtu': 1500, - 'tenant_id': self._tenant_id, - 'psk': 'abcd', - 'status': 'PENDING_CREATE', - 'admin_state_up': True} - dpd = {'action': 'hold', - 'interval': 40, - 'timeout': 120} - with contextlib.nested( - self.ikepolicy(name=ikename), - self.ipsecpolicy(name=ipsecname), - self.subnet(), - self.router()) as ( - ikepolicy, ipsecpolicy, subnet, router): - with self.vpnservice(name=vpnsname, subnet=subnet, - router=router) as vpnservice1: - keys['ikepolicy_id'] = ikepolicy['ikepolicy']['id'] - keys['ipsecpolicy_id'] = ipsecpolicy['ipsecpolicy']['id'] - keys['vpnservice_id'] = vpnservice1['vpnservice']['id'] - with self.ipsec_site_connection( - self.fmt, - name, - keys['peer_address'], - keys['peer_id'], - keys['peer_cidrs'], - keys['mtu'], - keys['psk'], - keys['initiator'], - dpd['action'], - dpd['interval'], - dpd['timeout'], - vpnservice1, - ikepolicy, - ipsecpolicy, - keys['admin_state_up'], - description=description, - ) as ipsec_site_connection: - - req = self.new_show_request( - 'ipsec-site-connections', - ipsec_site_connection[ - 'ipsec_site_connection']['id'], - fmt=self.fmt - ) - res = self.deserialize( - self.fmt, - req.get_response(self.ext_api) - ) - - self._check_ipsec_site_connection( - res['ipsec_site_connection'], - keys, - dpd) - - def test_list_ipsec_site_connections_with_sort_emulated(self): - """Test case to list all ipsec_site_connections with sort.""" - with self.subnet(cidr='10.2.0.0/24') as subnet: - with self.router() as router: - with self.vpnservice(subnet=subnet, - router=router - ) as vpnservice: - with contextlib.nested( - self.ipsec_site_connection( - name='connection1', vpnservice=vpnservice - ), - self.ipsec_site_connection( - name='connection2', vpnservice=vpnservice - ), - self.ipsec_site_connection( - name='connection3', vpnservice=vpnservice - ) - ) as(ipsec_site_connection1, - ipsec_site_connection2, - ipsec_site_connection3): - self._test_list_with_sort('ipsec-site-connection', - (ipsec_site_connection3, - ipsec_site_connection2, - ipsec_site_connection1), - [('name', 'desc')]) - - def test_list_ipsec_site_connections_with_pagination_emulated(self): - """Test case to list all ipsec_site_connections with pagination.""" - with self.subnet(cidr='10.2.0.0/24') as subnet: - with self.router() as router: - with self.vpnservice(subnet=subnet, - router=router - ) as vpnservice: - with contextlib.nested( - self.ipsec_site_connection( - name='ipsec_site_connection1', - vpnservice=vpnservice - ), - self.ipsec_site_connection( - name='ipsec_site_connection1', - vpnservice=vpnservice - ), - self.ipsec_site_connection( - name='ipsec_site_connection1', - vpnservice=vpnservice - ) - ) as(ipsec_site_connection1, - ipsec_site_connection2, - ipsec_site_connection3): - self._test_list_with_pagination( - 'ipsec-site-connection', - (ipsec_site_connection1, - ipsec_site_connection2, - ipsec_site_connection3), - ('name', 'asc'), 2, 2) - - def test_list_ipsec_site_conns_with_pagination_reverse_emulated(self): - """Test to list all ipsec_site_connections with reverse pagination.""" - with self.subnet(cidr='10.2.0.0/24') as subnet: - with self.router() as router: - with self.vpnservice(subnet=subnet, - router=router - ) as vpnservice: - with contextlib.nested( - self.ipsec_site_connection( - name='connection1', vpnservice=vpnservice - ), - self.ipsec_site_connection( - name='connection2', vpnservice=vpnservice - ), - self.ipsec_site_connection( - name='connection3', vpnservice=vpnservice - ) - ) as(ipsec_site_connection1, - ipsec_site_connection2, - ipsec_site_connection3): - self._test_list_with_pagination_reverse( - 'ipsec-site-connection', - (ipsec_site_connection1, - ipsec_site_connection2, - ipsec_site_connection3), - ('name', 'asc'), 2, 2 - ) - - def test_create_vpn(self): - """Test case to create a vpn.""" - vpns_name = "vpnservice1" - ike_name = "ikepolicy1" - ipsec_name = "ipsecpolicy1" - name1 = "ipsec_site_connection1" - with contextlib.nested( - self.ikepolicy(name=ike_name), - self.ipsecpolicy(name=ipsec_name), - self.vpnservice(name=vpns_name)) as ( - ikepolicy, ipsecpolicy, vpnservice): - vpnservice_id = vpnservice['vpnservice']['id'] - ikepolicy_id = ikepolicy['ikepolicy']['id'] - ipsecpolicy_id = ipsecpolicy['ipsecpolicy']['id'] - with self.ipsec_site_connection( - self.fmt, - name1, - '192.168.1.10', - '192.168.1.10', - ['192.168.2.0/24', - '192.168.3.0/24'], - 1500, - 'abcdef', - 'bi-directional', - 'hold', - 30, - 120, - vpnservice, - ikepolicy, - ipsecpolicy, - True - ) as vpnconn1: - - vpnservice_req = self.new_show_request( - 'vpnservices', - vpnservice_id, - fmt=self.fmt) - vpnservice_updated = self.deserialize( - self.fmt, - vpnservice_req.get_response(self.ext_api) - ) - self.assertEqual( - vpnservice_updated['vpnservice']['id'], - vpnconn1['ipsec_site_connection']['vpnservice_id'] - ) - ikepolicy_req = self.new_show_request('ikepolicies', - ikepolicy_id, - fmt=self.fmt) - ikepolicy_res = self.deserialize( - self.fmt, - ikepolicy_req.get_response(self.ext_api) - ) - self.assertEqual( - ikepolicy_res['ikepolicy']['id'], - vpnconn1['ipsec_site_connection']['ikepolicy_id']) - ipsecpolicy_req = self.new_show_request( - 'ipsecpolicies', - ipsecpolicy_id, - fmt=self.fmt) - ipsecpolicy_res = self.deserialize( - self.fmt, - ipsecpolicy_req.get_response(self.ext_api) - ) - self.assertEqual( - ipsecpolicy_res['ipsecpolicy']['id'], - vpnconn1['ipsec_site_connection']['ipsecpolicy_id'] - ) - - def test_delete_ikepolicy_inuse(self): - """Test case to delete an ikepolicy, that is in use.""" - vpns_name = "vpnservice1" - ike_name = "ikepolicy1" - ipsec_name = "ipsecpolicy1" - name1 = "ipsec_site_connection1" - with self.ikepolicy(name=ike_name) as ikepolicy: - with self.ipsecpolicy(name=ipsec_name) as ipsecpolicy: - with self.vpnservice(name=vpns_name) as vpnservice: - with self.ipsec_site_connection( - self.fmt, - name1, - '192.168.1.10', - '192.168.1.10', - ['192.168.2.0/24', - '192.168.3.0/24'], - 1500, - 'abcdef', - 'bi-directional', - 'hold', - 30, - 120, - vpnservice, - ikepolicy, - ipsecpolicy, - True - ): - delete_req = self.new_delete_request( - 'ikepolicies', - ikepolicy['ikepolicy']['id'] - ) - delete_res = delete_req.get_response(self.ext_api) - self.assertEqual(409, delete_res.status_int) - - def test_delete_ipsecpolicy_inuse(self): - """Test case to delete an ipsecpolicy, that is in use.""" - vpns_name = "vpnservice1" - ike_name = "ikepolicy1" - ipsec_name = "ipsecpolicy1" - name1 = "ipsec_site_connection1" - with self.ikepolicy(name=ike_name) as ikepolicy: - with self.ipsecpolicy(name=ipsec_name) as ipsecpolicy: - with self.vpnservice(name=vpns_name) as vpnservice: - with self.ipsec_site_connection( - self.fmt, - name1, - '192.168.1.10', - '192.168.1.10', - ['192.168.2.0/24', - '192.168.3.0/24'], - 1500, - 'abcdef', - 'bi-directional', - 'hold', - 30, - 120, - vpnservice, - ikepolicy, - ipsecpolicy, - True - ): - - delete_req = self.new_delete_request( - 'ipsecpolicies', - ipsecpolicy['ipsecpolicy']['id'] - ) - delete_res = delete_req.get_response(self.ext_api) - self.assertEqual(409, delete_res.status_int) - - -class TestVpnaasXML(TestVpnaas): - fmt = 'xml' diff --git a/neutron/tests/unit/dummy_plugin.py b/neutron/tests/unit/dummy_plugin.py deleted file mode 100644 index fc58a7e29..000000000 --- a/neutron/tests/unit/dummy_plugin.py +++ /dev/null @@ -1,139 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2012 OpenStack Foundation. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.api import extensions -from neutron.api.v2 import base -from neutron.common import exceptions -from neutron.db import servicetype_db -from neutron.extensions import servicetype -from neutron import manager -from neutron.openstack.common import uuidutils -from neutron.plugins.common import constants -from neutron.services import service_base - - -DUMMY_PLUGIN_NAME = "dummy_plugin" -RESOURCE_NAME = "dummy" -COLLECTION_NAME = "%ss" % RESOURCE_NAME - -# Attribute Map for dummy resource -RESOURCE_ATTRIBUTE_MAP = { - COLLECTION_NAME: { - 'id': {'allow_post': False, 'allow_put': False, - 'validate': {'type:uuid': None}, - 'is_visible': True}, - 'name': {'allow_post': True, 'allow_put': True, - 'validate': {'type:string': None}, - 'is_visible': True, 'default': ''}, - 'tenant_id': {'allow_post': True, 'allow_put': False, - 'required_by_policy': True, - 'is_visible': True}, - 'service_type': {'allow_post': True, - 'allow_put': False, - 'validate': {'type:servicetype_ref': None}, - 'is_visible': True, - 'default': None} - } -} - - -class Dummy(object): - - @classmethod - def get_name(cls): - return "dummy" - - @classmethod - def get_alias(cls): - return "dummy" - - @classmethod - def get_description(cls): - return "Dummy stuff" - - @classmethod - def get_namespace(cls): - return "http://docs.openstack.org/ext/neutron/dummy/api/v1.0" - - @classmethod - def get_updated(cls): - return "2012-11-20T10:00:00-00:00" - - @classmethod - def get_resources(cls): - """Returns Extended Resource for dummy management.""" - q_mgr = manager.NeutronManager.get_instance() - dummy_inst = q_mgr.get_service_plugins()['DUMMY'] - controller = base.create_resource( - COLLECTION_NAME, RESOURCE_NAME, dummy_inst, - RESOURCE_ATTRIBUTE_MAP[COLLECTION_NAME]) - return [extensions.ResourceExtension(COLLECTION_NAME, - controller)] - - -class DummyServicePlugin(service_base.ServicePluginBase): - """This is a simple plugin for managing instantes of a fictional 'dummy' - service. This plugin is provided as a proof-of-concept of how - advanced service might leverage the service type extension. - Ideally, instances of real advanced services, such as load balancing - or VPN will adopt a similar solution. - """ - - supported_extension_aliases = ['dummy', servicetype.EXT_ALIAS] - agent_notifiers = {'dummy': 'dummy_agent_notifier'} - - def __init__(self): - self.svctype_mgr = servicetype_db.ServiceTypeManager.get_instance() - self.dummys = {} - - def get_plugin_type(self): - return constants.DUMMY - - def get_plugin_name(self): - return DUMMY_PLUGIN_NAME - - def get_plugin_description(self): - return "Neutron Dummy Service Plugin" - - def get_dummys(self, context, filters, fields): - return self.dummys.values() - - def get_dummy(self, context, id, fields): - try: - return self.dummys[id] - except KeyError: - raise exceptions.NotFound() - - def create_dummy(self, context, dummy): - d = dummy['dummy'] - d['id'] = uuidutils.generate_uuid() - self.dummys[d['id']] = d - self.svctype_mgr.increase_service_type_refcount(context, - d['service_type']) - return d - - def update_dummy(self, context, id, dummy): - pass - - def delete_dummy(self, context, id): - try: - svc_type_id = self.dummys[id]['service_type'] - del self.dummys[id] - self.svctype_mgr.decrease_service_type_refcount(context, - svc_type_id) - except KeyError: - raise exceptions.NotFound() diff --git a/neutron/tests/unit/embrane/__init__.py b/neutron/tests/unit/embrane/__init__.py deleted file mode 100644 index bb81770cd..000000000 --- a/neutron/tests/unit/embrane/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Embrane, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Ivar Lazzaro, Embrane, Inc. diff --git a/neutron/tests/unit/embrane/test_embrane_defaults.py b/neutron/tests/unit/embrane/test_embrane_defaults.py deleted file mode 100644 index ea84d63ab..000000000 --- a/neutron/tests/unit/embrane/test_embrane_defaults.py +++ /dev/null @@ -1,31 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Embrane, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Ivar Lazzaro, Embrane, Inc. - -from oslo.config import cfg - -from neutron.plugins.embrane.common import config # noqa -from neutron.tests import base - - -class ConfigurationTest(base.BaseTestCase): - - def test_defaults(self): - self.assertEqual('admin', cfg.CONF.heleos.admin_username) - self.assertEqual('default', cfg.CONF.heleos.resource_pool_id) - self.assertTrue(cfg.CONF.heleos.async_requests) diff --git a/neutron/tests/unit/embrane/test_embrane_l3_plugin.py b/neutron/tests/unit/embrane/test_embrane_l3_plugin.py deleted file mode 100644 index 548a1d432..000000000 --- a/neutron/tests/unit/embrane/test_embrane_l3_plugin.py +++ /dev/null @@ -1,41 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Embrane, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Ivar Lazzaro, Embrane, Inc. - -from oslo.config import cfg - -from neutron.db import api as db -from neutron.plugins.embrane.common import config # noqa -from neutron.tests.unit import test_extension_extraroute as extraroute_test -from neutron.tests.unit import test_l3_plugin as router_test - -PLUGIN_NAME = ('neutron.plugins.embrane.plugins.embrane_fake_plugin.' - 'EmbraneFakePlugin') - - -class TestEmbraneL3NatDBTestCase(router_test.L3NatDBIntTestCase): - _plugin_name = PLUGIN_NAME - - def setUp(self): - cfg.CONF.set_override('admin_password', "admin123", 'heleos') - self.addCleanup(db.clear_db) - super(TestEmbraneL3NatDBTestCase, self).setUp() - - -class ExtraRouteDBTestCase(extraroute_test.ExtraRouteDBIntTestCase): - _plugin_name = PLUGIN_NAME diff --git a/neutron/tests/unit/embrane/test_embrane_neutron_plugin.py b/neutron/tests/unit/embrane/test_embrane_neutron_plugin.py deleted file mode 100644 index 74b64e415..000000000 --- a/neutron/tests/unit/embrane/test_embrane_neutron_plugin.py +++ /dev/null @@ -1,82 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Embrane, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Ivar Lazzaro, Embrane, Inc. -import sys - -import mock -from oslo.config import cfg - -from neutron.db import api as db -from neutron.plugins.embrane.common import config # noqa -from neutron.tests.unit import test_db_plugin as test_plugin - -PLUGIN_NAME = ('neutron.plugins.embrane.plugins.embrane_fake_plugin.' - 'EmbraneFakePlugin') - - -class EmbranePluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase): - _plugin_name = PLUGIN_NAME - - def setUp(self): - cfg.CONF.set_override('admin_password', "admin123", 'heleos') - p = mock.patch.dict(sys.modules, {'heleosapi': mock.Mock()}) - p.start() - self.addCleanup(db.clear_db) - # dict patches must be explicitly stopped - self.addCleanup(p.stop) - super(EmbranePluginV2TestCase, self).setUp(self._plugin_name) - - -class TestEmbraneBasicGet(test_plugin.TestBasicGet, EmbranePluginV2TestCase): - pass - - -class TestEmbraneV2HTTPResponse(test_plugin.TestV2HTTPResponse, - EmbranePluginV2TestCase): - pass - - -class TestEmbranePortsV2(test_plugin.TestPortsV2, EmbranePluginV2TestCase): - - def test_create_ports_bulk_emulated_plugin_failure(self): - self.skip("Temporary skipping due to incompatibility with the" - " plugin dynamic class type") - - def test_recycle_expired_previously_run_within_context(self): - self.skip("Temporary skipping due to incompatibility with the" - " plugin dynamic class type") - - def test_recycle_held_ip_address(self): - self.skip("Temporary skipping due to incompatibility with the" - " plugin dynamic class type") - - -class TestEmbraneNetworksV2(test_plugin.TestNetworksV2, - EmbranePluginV2TestCase): - - def test_create_networks_bulk_emulated_plugin_failure(self): - self.skip("Temporary skipping due to incompatibility with the" - " plugin dynamic class type") - - -class TestEmbraneSubnetsV2(test_plugin.TestSubnetsV2, - EmbranePluginV2TestCase): - - def test_create_subnets_bulk_emulated_plugin_failure(self): - self.skip("Temporary skipping due to incompatibility with the" - " plugin dynamic class type") diff --git a/neutron/tests/unit/hyperv/__init__.py b/neutron/tests/unit/hyperv/__init__.py deleted file mode 100644 index 7ef4e09fa..000000000 --- a/neutron/tests/unit/hyperv/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Cloudbase Solutions SRL -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. diff --git a/neutron/tests/unit/hyperv/test_hyperv_neutron_agent.py b/neutron/tests/unit/hyperv/test_hyperv_neutron_agent.py deleted file mode 100644 index 5d2a24c0d..000000000 --- a/neutron/tests/unit/hyperv/test_hyperv_neutron_agent.py +++ /dev/null @@ -1,221 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Cloudbase Solutions SRL -# Copyright 2013 Pedro Navarro Perez -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -Unit tests for Windows Hyper-V virtual switch neutron driver -""" - -import mock -from oslo.config import cfg - -from neutron.plugins.hyperv.agent import hyperv_neutron_agent -from neutron.plugins.hyperv.agent import utilsfactory -from neutron.tests import base - -cfg.CONF.import_opt('enable_metrics_collection', - 'neutron.plugins.hyperv.agent.hyperv_neutron_agent', - 'AGENT') - - -class TestHyperVNeutronAgent(base.BaseTestCase): - - _FAKE_PORT_ID = 'fake_port_id' - - def setUp(self): - super(TestHyperVNeutronAgent, self).setUp() - # Avoid rpc initialization for unit tests - cfg.CONF.set_override('rpc_backend', - 'neutron.openstack.common.rpc.impl_fake') - - utilsfactory._get_windows_version = mock.MagicMock( - return_value='6.2.0') - - class MockFixedIntervalLoopingCall(object): - def __init__(self, f): - self.f = f - - def start(self, interval=0): - self.f() - - mock.patch('neutron.openstack.common.loopingcall.' - 'FixedIntervalLoopingCall', - new=MockFixedIntervalLoopingCall).start() - cfg.CONF.set_default('firewall_driver', - 'neutron.agent.firewall.NoopFirewallDriver', - group='SECURITYGROUP') - self.agent = hyperv_neutron_agent.HyperVNeutronAgent() - self.agent.plugin_rpc = mock.Mock() - self.agent.sec_groups_agent = mock.MagicMock() - self.agent.context = mock.Mock() - self.agent.agent_id = mock.Mock() - - fake_agent_state = { - 'binary': 'neutron-hyperv-agent', - 'host': 'fake_host_name', - 'topic': 'N/A', - 'configurations': {'vswitch_mappings': ['*:MyVirtualSwitch']}, - 'agent_type': 'HyperV agent', - 'start_flag': True} - self.agent_state = fake_agent_state - - def test_port_bound_enable_metrics(self): - cfg.CONF.set_override('enable_metrics_collection', True, 'AGENT') - self._test_port_bound(True) - - def test_port_bound_no_metrics(self): - cfg.CONF.set_override('enable_metrics_collection', False, 'AGENT') - self._test_port_bound(False) - - def _test_port_bound(self, enable_metrics): - port = mock.MagicMock() - mock_enable_metrics = mock.MagicMock() - net_uuid = 'my-net-uuid' - - with mock.patch.multiple( - self.agent._utils, - connect_vnic_to_vswitch=mock.MagicMock(), - set_vswitch_port_vlan_id=mock.MagicMock(), - enable_port_metrics_collection=mock_enable_metrics): - - self.agent._port_bound(port, net_uuid, 'vlan', None, None) - - self.assertEqual(enable_metrics, mock_enable_metrics.called) - - def test_port_unbound(self): - map = { - 'network_type': 'vlan', - 'vswitch_name': 'fake-vswitch', - 'ports': [], - 'vlan_id': 1} - net_uuid = 'my-net-uuid' - network_vswitch_map = (net_uuid, map) - with mock.patch.object(self.agent, - '_get_network_vswitch_map_by_port_id', - return_value=network_vswitch_map): - with mock.patch.object( - self.agent._utils, - 'disconnect_switch_port'): - self.agent._port_unbound(net_uuid) - - def test_port_enable_control_metrics_ok(self): - cfg.CONF.set_override('enable_metrics_collection', True, 'AGENT') - self.agent._port_metric_retries[self._FAKE_PORT_ID] = ( - cfg.CONF.AGENT.metrics_max_retries) - - with mock.patch.multiple(self.agent._utils, - can_enable_control_metrics=mock.MagicMock(), - enable_control_metrics=mock.MagicMock()): - - self.agent._utils.can_enable_control_metrics.return_value = True - self.agent._port_enable_control_metrics() - self.agent._utils.enable_control_metrics.assert_called_with( - self._FAKE_PORT_ID) - - self.assertNotIn(self._FAKE_PORT_ID, self.agent._port_metric_retries) - - def test_port_enable_control_metrics_maxed(self): - cfg.CONF.set_override('enable_metrics_collection', True, 'AGENT') - cfg.CONF.set_override('metrics_max_retries', 3, 'AGENT') - self.agent._port_metric_retries[self._FAKE_PORT_ID] = ( - cfg.CONF.AGENT.metrics_max_retries) - - with mock.patch.multiple(self.agent._utils, - can_enable_control_metrics=mock.MagicMock(), - enable_control_metrics=mock.MagicMock()): - - self.agent._utils.can_enable_control_metrics.return_value = False - for i in range(cfg.CONF.AGENT.metrics_max_retries + 1): - self.assertIn(self._FAKE_PORT_ID, - self.agent._port_metric_retries) - self.agent._port_enable_control_metrics() - - self.assertNotIn(self._FAKE_PORT_ID, self.agent._port_metric_retries) - - def test_treat_devices_added_returns_true_for_missing_device(self): - attrs = {'get_device_details.side_effect': Exception()} - self.agent.plugin_rpc.configure_mock(**attrs) - self.assertTrue(self.agent._treat_devices_added([{}])) - - def mock_treat_devices_added(self, details, func_name): - """Mock treat devices added. - - :param details: the details to return for the device - :param func_name: the function that should be called - :returns: whether the named function was called - """ - attrs = {'get_device_details.return_value': details} - self.agent.plugin_rpc.configure_mock(**attrs) - with mock.patch.object(self.agent, func_name) as func: - self.assertFalse(self.agent._treat_devices_added([{}])) - return func.called - - def test_treat_devices_added_updates_known_port(self): - details = mock.MagicMock() - details.__contains__.side_effect = lambda x: True - with mock.patch.object(self.agent.plugin_rpc, - "update_device_up") as func: - self.assertTrue(self.mock_treat_devices_added(details, - '_treat_vif_port')) - self.assertTrue(func.called) - - def test_treat_devices_added_missing_port_id(self): - details = mock.MagicMock() - details.__contains__.side_effect = lambda x: False - with mock.patch.object(self.agent.plugin_rpc, - "update_device_up") as func: - self.assertFalse(self.mock_treat_devices_added(details, - '_treat_vif_port')) - self.assertFalse(func.called) - - def test_treat_devices_removed_returns_true_for_missing_device(self): - attrs = {'update_device_down.side_effect': Exception()} - self.agent.plugin_rpc.configure_mock(**attrs) - self.assertTrue(self.agent._treat_devices_removed([{}])) - - def mock_treat_devices_removed(self, port_exists): - details = dict(exists=port_exists) - attrs = {'update_device_down.return_value': details} - self.agent.plugin_rpc.configure_mock(**attrs) - with mock.patch.object(self.agent, '_port_unbound') as func: - self.assertFalse(self.agent._treat_devices_removed([{}])) - self.assertEqual(func.called, not port_exists) - - def test_treat_devices_removed_unbinds_port(self): - self.mock_treat_devices_removed(False) - - def test_treat_devices_removed_ignores_missing_port(self): - self.mock_treat_devices_removed(False) - - def test_report_state(self): - with mock.patch.object(self.agent.state_rpc, - "report_state") as report_st: - self.agent._report_state() - report_st.assert_called_with(self.agent.context, - self.agent.agent_state) - self.assertNotIn("start_flag", self.agent.agent_state) - - def test_main(self): - with mock.patch.object(hyperv_neutron_agent, - 'HyperVNeutronAgent') as plugin: - with mock.patch.object(hyperv_neutron_agent, - 'common_config') as common_config: - hyperv_neutron_agent.main() - - self.assertTrue(common_config.init.called) - self.assertTrue(common_config.setup_logging.called) - plugin.assert_has_calls([mock.call().daemon_loop()]) diff --git a/neutron/tests/unit/hyperv/test_hyperv_neutron_plugin.py b/neutron/tests/unit/hyperv/test_hyperv_neutron_plugin.py deleted file mode 100644 index 8e34777c2..000000000 --- a/neutron/tests/unit/hyperv/test_hyperv_neutron_plugin.py +++ /dev/null @@ -1,69 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Cloudbase Solutions SRL -# Copyright 2013 Pedro Navarro Perez -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import contextlib - -from oslo.config import cfg - -from neutron import context -from neutron.extensions import portbindings -from neutron import manager -from neutron.tests.unit import test_db_plugin as test_plugin - - -class HyperVNeutronPluginTestCase(test_plugin.NeutronDbPluginV2TestCase): - - _plugin_name = ('neutron.plugins.hyperv.' - 'hyperv_neutron_plugin.HyperVNeutronPlugin') - - def setUp(self): - super(HyperVNeutronPluginTestCase, self).setUp(self._plugin_name) - - -class TestHyperVVirtualSwitchBasicGet( - test_plugin.TestBasicGet, HyperVNeutronPluginTestCase): - pass - - -class TestHyperVVirtualSwitchV2HTTPResponse( - test_plugin.TestV2HTTPResponse, HyperVNeutronPluginTestCase): - pass - - -class TestHyperVVirtualSwitchPortsV2( - test_plugin.TestPortsV2, HyperVNeutronPluginTestCase): - def test_port_vif_details(self): - with self.port(name='name') as port: - self.assertEqual(port['port']['binding:vif_type'], - portbindings.VIF_TYPE_HYPERV) - - def test_ports_vif_details(self): - cfg.CONF.set_default('allow_overlapping_ips', True) - plugin = manager.NeutronManager.get_plugin() - with contextlib.nested(self.port(), self.port()) as (port1, port2): - ctx = context.get_admin_context() - ports = plugin.get_ports(ctx) - self.assertEqual(len(ports), 2) - for port in ports: - self.assertEqual(port['binding:vif_type'], - portbindings.VIF_TYPE_HYPERV) - - -class TestHyperVVirtualSwitchNetworksV2( - test_plugin.TestNetworksV2, HyperVNeutronPluginTestCase): - pass diff --git a/neutron/tests/unit/hyperv/test_hyperv_rpcapi.py b/neutron/tests/unit/hyperv/test_hyperv_rpcapi.py deleted file mode 100644 index 965842738..000000000 --- a/neutron/tests/unit/hyperv/test_hyperv_rpcapi.py +++ /dev/null @@ -1,125 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Cloudbase Solutions SRL -# Copyright 2013 Pedro Navarro Perez -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -Unit Tests for hyperv neutron rpc -""" - -import mock - -from neutron.agent import rpc as agent_rpc -from neutron.common import rpc_compat -from neutron.common import topics -from neutron.openstack.common import context -from neutron.plugins.hyperv import agent_notifier_api as ana -from neutron.plugins.hyperv.common import constants -from neutron.tests import base - - -class rpcHyperVApiTestCase(base.BaseTestCase): - - def _test_hyperv_neutron_api( - self, rpcapi, topic, method, rpc_method, **kwargs): - ctxt = context.RequestContext('fake_user', 'fake_project') - expected_retval = 'foo' if method == 'call' else None - expected_msg = rpcapi.make_msg(method, **kwargs) - if rpc_method == 'cast' and method == 'run_instance': - kwargs['call'] = False - - proxy = rpc_compat.RpcProxy - with mock.patch.object(proxy, rpc_method) as rpc_method_mock: - rpc_method_mock.return_value = expected_retval - retval = getattr(rpcapi, method)(ctxt, **kwargs) - - self.assertEqual(retval, expected_retval) - expected = [ - mock.call(ctxt, expected_msg, topic=topic) - ] - rpc_method_mock.assert_has_calls(expected) - - def test_delete_network(self): - rpcapi = ana.AgentNotifierApi(topics.AGENT) - self._test_hyperv_neutron_api( - rpcapi, - topics.get_topic_name( - topics.AGENT, - topics.NETWORK, - topics.DELETE), - 'network_delete', rpc_method='fanout_cast', - network_id='fake_request_spec') - - def test_port_update(self): - rpcapi = ana.AgentNotifierApi(topics.AGENT) - self._test_hyperv_neutron_api( - rpcapi, - topics.get_topic_name( - topics.AGENT, - topics.PORT, - topics.UPDATE), - 'port_update', rpc_method='fanout_cast', - port='fake_port', - network_type='fake_network_type', - segmentation_id='fake_segmentation_id', - physical_network='fake_physical_network') - - def test_port_delete(self): - rpcapi = ana.AgentNotifierApi(topics.AGENT) - self._test_hyperv_neutron_api( - rpcapi, - topics.get_topic_name( - topics.AGENT, - topics.PORT, - topics.DELETE), - 'port_delete', rpc_method='fanout_cast', - port_id='port_id') - - def test_tunnel_update(self): - rpcapi = ana.AgentNotifierApi(topics.AGENT) - self._test_hyperv_neutron_api( - rpcapi, - topics.get_topic_name( - topics.AGENT, - constants.TUNNEL, - topics.UPDATE), - 'tunnel_update', rpc_method='fanout_cast', - tunnel_ip='fake_ip', tunnel_id='fake_id') - - def test_device_details(self): - rpcapi = agent_rpc.PluginApi(topics.PLUGIN) - self._test_hyperv_neutron_api( - rpcapi, topics.PLUGIN, - 'get_device_details', rpc_method='call', - device='fake_device', - agent_id='fake_agent_id') - - def test_update_device_down(self): - rpcapi = agent_rpc.PluginApi(topics.PLUGIN) - self._test_hyperv_neutron_api( - rpcapi, topics.PLUGIN, - 'update_device_down', rpc_method='call', - device='fake_device', - agent_id='fake_agent_id', - host='fake_host') - - def test_tunnel_sync(self): - rpcapi = agent_rpc.PluginApi(topics.PLUGIN) - self._test_hyperv_neutron_api( - rpcapi, topics.PLUGIN, - 'tunnel_sync', rpc_method='call', - tunnel_ip='fake_tunnel_ip', - tunnel_type=None) diff --git a/neutron/tests/unit/hyperv/test_hyperv_security_groups_driver.py b/neutron/tests/unit/hyperv/test_hyperv_security_groups_driver.py deleted file mode 100644 index bcbe6ba0e..000000000 --- a/neutron/tests/unit/hyperv/test_hyperv_security_groups_driver.py +++ /dev/null @@ -1,189 +0,0 @@ -# Copyright 2014 Cloudbase Solutions SRL -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# @author: Claudiu Belu, Cloudbase Solutions Srl - -""" -Unit tests for the Hyper-V Security Groups Driver. -""" - -import mock -from oslo.config import cfg - -from neutron.plugins.hyperv.agent import security_groups_driver as sg_driver -from neutron.plugins.hyperv.agent import utilsfactory -from neutron.tests import base - -CONF = cfg.CONF - - -class TestHyperVSecurityGroupsDriver(base.BaseTestCase): - - _FAKE_DEVICE = 'fake_device' - _FAKE_ID = 'fake_id' - _FAKE_DIRECTION = 'ingress' - _FAKE_ETHERTYPE = 'IPv4' - _FAKE_ETHERTYPE_IPV6 = 'IPv6' - _FAKE_DEST_IP_PREFIX = 'fake_dest_ip_prefix' - _FAKE_SOURCE_IP_PREFIX = 'fake_source_ip_prefix' - _FAKE_PARAM_NAME = 'fake_param_name' - _FAKE_PARAM_VALUE = 'fake_param_value' - - _FAKE_PORT_MIN = 9001 - _FAKE_PORT_MAX = 9011 - - def setUp(self): - super(TestHyperVSecurityGroupsDriver, self).setUp() - self._mock_windows_version = mock.patch.object(utilsfactory, - 'get_hypervutils') - self._mock_windows_version.start() - self._driver = sg_driver.HyperVSecurityGroupsDriver() - self._driver._utils = mock.MagicMock() - - @mock.patch('neutron.plugins.hyperv.agent.security_groups_driver' - '.HyperVSecurityGroupsDriver._create_port_rules') - def test_prepare_port_filter(self, mock_create_rules): - mock_port = self._get_port() - mock_utils_method = self._driver._utils.create_default_reject_all_rules - self._driver.prepare_port_filter(mock_port) - - self.assertEqual(mock_port, - self._driver._security_ports[self._FAKE_DEVICE]) - mock_utils_method.assert_called_once_with(self._FAKE_ID) - self._driver._create_port_rules.assert_called_once_with( - self._FAKE_ID, mock_port['security_group_rules']) - - def test_update_port_filter(self): - mock_port = self._get_port() - new_mock_port = self._get_port() - new_mock_port['id'] += '2' - new_mock_port['security_group_rules'][0]['ethertype'] += "2" - - self._driver._security_ports[mock_port['device']] = mock_port - self._driver._create_port_rules = mock.MagicMock() - self._driver._remove_port_rules = mock.MagicMock() - self._driver.update_port_filter(new_mock_port) - - self._driver._remove_port_rules.assert_called_once_with( - mock_port['id'], mock_port['security_group_rules']) - self._driver._create_port_rules.assert_called_once_with( - new_mock_port['id'], new_mock_port['security_group_rules']) - self.assertEqual(new_mock_port, - self._driver._security_ports[new_mock_port['device']]) - - @mock.patch('neutron.plugins.hyperv.agent.security_groups_driver' - '.HyperVSecurityGroupsDriver.prepare_port_filter') - def test_update_port_filter_new_port(self, mock_method): - mock_port = self._get_port() - self._driver.prepare_port_filter = mock.MagicMock() - self._driver.update_port_filter(mock_port) - - self._driver.prepare_port_filter.assert_called_once_with(mock_port) - - def test_remove_port_filter(self): - mock_port = self._get_port() - self._driver._security_ports[mock_port['device']] = mock_port - self._driver.remove_port_filter(mock_port) - self.assertFalse(mock_port['device'] in self._driver._security_ports) - - def test_create_port_rules_exception(self): - fake_rule = self._create_security_rule() - self._driver._utils.create_security_rule.side_effect = Exception( - 'Generated Exception for testing.') - self._driver._create_port_rules(self._FAKE_ID, [fake_rule]) - - def test_create_param_map(self): - fake_rule = self._create_security_rule() - self._driver._get_rule_remote_address = mock.MagicMock( - return_value=self._FAKE_SOURCE_IP_PREFIX) - actual = self._driver._create_param_map(fake_rule) - expected = { - 'direction': self._driver._ACL_PROP_MAP[ - 'direction'][self._FAKE_DIRECTION], - 'acl_type': self._driver._ACL_PROP_MAP[ - 'ethertype'][self._FAKE_ETHERTYPE], - 'local_port': '%s-%s' % (self._FAKE_PORT_MIN, self._FAKE_PORT_MAX), - 'protocol': self._driver._ACL_PROP_MAP['default'], - 'remote_address': self._FAKE_SOURCE_IP_PREFIX - } - - self.assertEqual(expected, actual) - - @mock.patch('neutron.plugins.hyperv.agent.security_groups_driver' - '.HyperVSecurityGroupsDriver._create_param_map') - def test_create_port_rules(self, mock_method): - fake_rule = self._create_security_rule() - mock_method.return_value = { - self._FAKE_PARAM_NAME: self._FAKE_PARAM_VALUE} - self._driver._create_port_rules(self._FAKE_ID, [fake_rule]) - - self._driver._utils.create_security_rule.assert_called_once_with( - self._FAKE_ID, fake_param_name=self._FAKE_PARAM_VALUE) - - def test_convert_any_address_to_same_ingress(self): - rule = self._create_security_rule() - actual = self._driver._get_rule_remote_address(rule) - self.assertEqual(self._FAKE_SOURCE_IP_PREFIX, actual) - - def test_convert_any_address_to_same_egress(self): - rule = self._create_security_rule() - rule['direction'] += '2' - actual = self._driver._get_rule_remote_address(rule) - self.assertEqual(self._FAKE_DEST_IP_PREFIX, actual) - - def test_convert_any_address_to_ipv4(self): - rule = self._create_security_rule() - del rule['source_ip_prefix'] - actual = self._driver._get_rule_remote_address(rule) - self.assertEqual(self._driver._ACL_PROP_MAP['address_default']['IPv4'], - actual) - - def test_convert_any_address_to_ipv6(self): - rule = self._create_security_rule() - del rule['source_ip_prefix'] - rule['ethertype'] = self._FAKE_ETHERTYPE_IPV6 - actual = self._driver._get_rule_remote_address(rule) - self.assertEqual(self._driver._ACL_PROP_MAP['address_default']['IPv6'], - actual) - - def test_get_rule_protocol_icmp(self): - self._test_get_rule_protocol( - 'icmp', self._driver._ACL_PROP_MAP['protocol']['icmp']) - - def test_get_rule_protocol_no_icmp(self): - self._test_get_rule_protocol('tcp', 'tcp') - - def _test_get_rule_protocol(self, protocol, expected): - rule = self._create_security_rule() - rule['protocol'] = protocol - actual = self._driver._get_rule_protocol(rule) - - self.assertEqual(expected, actual) - - def _get_port(self): - return { - 'device': self._FAKE_DEVICE, - 'id': self._FAKE_ID, - 'security_group_rules': [self._create_security_rule()] - } - - def _create_security_rule(self): - return { - 'direction': self._FAKE_DIRECTION, - 'ethertype': self._FAKE_ETHERTYPE, - 'dest_ip_prefix': self._FAKE_DEST_IP_PREFIX, - 'source_ip_prefix': self._FAKE_SOURCE_IP_PREFIX, - 'port_range_min': self._FAKE_PORT_MIN, - 'port_range_max': self._FAKE_PORT_MAX - } diff --git a/neutron/tests/unit/hyperv/test_hyperv_utilsfactory.py b/neutron/tests/unit/hyperv/test_hyperv_utilsfactory.py deleted file mode 100644 index fef96d734..000000000 --- a/neutron/tests/unit/hyperv/test_hyperv_utilsfactory.py +++ /dev/null @@ -1,54 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Cloudbase Solutions SRL -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# @author: Claudiu Belu, Cloudbase Solutions Srl - -""" -Unit tests for the Hyper-V utils factory. -""" - -import mock - -from oslo.config import cfg - -from neutron.plugins.hyperv.agent import utils -from neutron.plugins.hyperv.agent import utilsfactory -from neutron.plugins.hyperv.agent import utilsv2 -from neutron.tests import base - -CONF = cfg.CONF - - -class TestHyperVUtilsFactory(base.BaseTestCase): - - def test_get_hypervutils_v2_r2(self): - self._test_returned_class(utilsv2.HyperVUtilsV2R2, True, '6.3.0') - - def test_get_hypervutils_v2(self): - self._test_returned_class(utilsv2.HyperVUtilsV2, False, '6.2.0') - - def test_get_hypervutils_v1_old_version(self): - self._test_returned_class(utils.HyperVUtils, False, '6.1.0') - - def test_get_hypervutils_v1_forced(self): - self._test_returned_class(utils.HyperVUtils, True, '6.2.0') - - def _test_returned_class(self, expected_class, force_v1, os_version): - CONF.hyperv.force_hyperv_utils_v1 = force_v1 - utilsfactory._get_windows_version = mock.MagicMock( - return_value=os_version) - actual_class = type(utilsfactory.get_hypervutils()) - self.assertEqual(actual_class, expected_class) diff --git a/neutron/tests/unit/hyperv/test_hyperv_utilsv2.py b/neutron/tests/unit/hyperv/test_hyperv_utilsv2.py deleted file mode 100644 index c020f16e0..000000000 --- a/neutron/tests/unit/hyperv/test_hyperv_utilsv2.py +++ /dev/null @@ -1,519 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2013 Cloudbase Solutions SRL -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# @author: Alessandro Pilotti, Cloudbase Solutions Srl - -""" -Unit tests for the Hyper-V utils V2. -""" - -import mock - -from neutron.plugins.hyperv.agent import utils -from neutron.plugins.hyperv.agent import utilsv2 -from neutron.tests import base - - -class TestHyperVUtilsV2(base.BaseTestCase): - - _FAKE_VSWITCH_NAME = "fake_vswitch_name" - _FAKE_PORT_NAME = "fake_port_name" - _FAKE_JOB_PATH = 'fake_job_path' - _FAKE_RET_VAL = 0 - _FAKE_VM_PATH = "fake_vm_path" - _FAKE_RES_DATA = "fake_res_data" - _FAKE_RES_PATH = "fake_res_path" - _FAKE_VSWITCH = "fake_vswitch" - _FAKE_VLAN_ID = "fake_vlan_id" - _FAKE_CLASS_NAME = "fake_class_name" - _FAKE_ELEMENT_NAME = "fake_element_name" - _FAKE_HYPERV_VM_STATE = 'fake_hyperv_state' - - _FAKE_ACL_ACT = 'fake_acl_action' - _FAKE_ACL_DIR = 'fake_acl_dir' - _FAKE_ACL_TYPE = 'fake_acl_type' - _FAKE_LOCAL_PORT = 'fake_local_port' - _FAKE_PROTOCOL = 'fake_port_protocol' - _FAKE_REMOTE_ADDR = '0.0.0.0/0' - _FAKE_WEIGHT = 'fake_weight' - - def setUp(self): - super(TestHyperVUtilsV2, self).setUp() - self._utils = utilsv2.HyperVUtilsV2() - self._utils._wmi_conn = mock.MagicMock() - - def test_connect_vnic_to_vswitch_found(self): - self._test_connect_vnic_to_vswitch(True) - - def test_connect_vnic_to_vswitch_not_found(self): - self._test_connect_vnic_to_vswitch(False) - - def _test_connect_vnic_to_vswitch(self, found): - self._utils._get_vnic_settings = mock.MagicMock() - - if not found: - mock_vm = mock.MagicMock() - self._utils._get_vm_from_res_setting_data = mock.MagicMock( - return_value=mock_vm) - self._utils._add_virt_resource = mock.MagicMock() - else: - self._utils._modify_virt_resource = mock.MagicMock() - - self._utils._get_vswitch = mock.MagicMock() - self._utils._get_switch_port_allocation = mock.MagicMock() - - mock_port = mock.MagicMock() - self._utils._get_switch_port_allocation.return_value = (mock_port, - found) - - self._utils.connect_vnic_to_vswitch(self._FAKE_VSWITCH_NAME, - self._FAKE_PORT_NAME) - - if not found: - self._utils._add_virt_resource.assert_called_with(mock_vm, - mock_port) - else: - self._utils._modify_virt_resource.assert_called_with(mock_port) - - def test_add_virt_resource(self): - self._test_virt_method('AddResourceSettings', 3, '_add_virt_resource', - True, self._FAKE_VM_PATH, [self._FAKE_RES_DATA]) - - def test_add_virt_feature(self): - self._test_virt_method('AddFeatureSettings', 3, '_add_virt_feature', - True, self._FAKE_VM_PATH, [self._FAKE_RES_DATA]) - - def test_modify_virt_resource(self): - self._test_virt_method('ModifyResourceSettings', 3, - '_modify_virt_resource', False, - ResourceSettings=[self._FAKE_RES_DATA]) - - def test_remove_virt_resource(self): - self._test_virt_method('RemoveResourceSettings', 2, - '_remove_virt_resource', False, - ResourceSettings=[self._FAKE_RES_PATH]) - - def test_remove_virt_feature(self): - self._test_virt_method('RemoveFeatureSettings', 2, - '_remove_virt_feature', False, - FeatureSettings=[self._FAKE_RES_PATH]) - - def _test_virt_method(self, vsms_method_name, return_count, - utils_method_name, with_mock_vm, *args, **kwargs): - mock_svc = self._utils._conn.Msvm_VirtualSystemManagementService()[0] - vsms_method = getattr(mock_svc, vsms_method_name) - mock_rsd = self._mock_vsms_method(vsms_method, return_count) - if with_mock_vm: - mock_vm = mock.MagicMock() - mock_vm.path_.return_value = self._FAKE_VM_PATH - getattr(self._utils, utils_method_name)(mock_vm, mock_rsd) - else: - getattr(self._utils, utils_method_name)(mock_rsd) - - if args: - vsms_method.assert_called_once_with(*args) - else: - vsms_method.assert_called_once_with(**kwargs) - - def _mock_vsms_method(self, vsms_method, return_count): - args = None - if return_count == 3: - args = (self._FAKE_JOB_PATH, mock.MagicMock(), self._FAKE_RET_VAL) - else: - args = (self._FAKE_JOB_PATH, self._FAKE_RET_VAL) - - vsms_method.return_value = args - mock_res_setting_data = mock.MagicMock() - mock_res_setting_data.GetText_.return_value = self._FAKE_RES_DATA - mock_res_setting_data.path_.return_value = self._FAKE_RES_PATH - - self._utils._check_job_status = mock.MagicMock() - - return mock_res_setting_data - - def test_disconnect_switch_port_delete_port(self): - self._test_disconnect_switch_port(True) - - def test_disconnect_switch_port_modify_port(self): - self._test_disconnect_switch_port(False) - - def _test_disconnect_switch_port(self, delete_port): - self._utils._get_switch_port_allocation = mock.MagicMock() - - mock_sw_port = mock.MagicMock() - self._utils._get_switch_port_allocation.return_value = (mock_sw_port, - True) - - if delete_port: - self._utils._remove_virt_resource = mock.MagicMock() - else: - self._utils._modify_virt_resource = mock.MagicMock() - - self._utils.disconnect_switch_port(self._FAKE_VSWITCH_NAME, - self._FAKE_PORT_NAME, - delete_port) - - if delete_port: - self._utils._remove_virt_resource.assert_called_with(mock_sw_port) - else: - self._utils._modify_virt_resource.assert_called_with(mock_sw_port) - - def test_get_vswitch(self): - self._utils._conn.Msvm_VirtualEthernetSwitch.return_value = [ - self._FAKE_VSWITCH] - vswitch = self._utils._get_vswitch(self._FAKE_VSWITCH_NAME) - - self.assertEqual(self._FAKE_VSWITCH, vswitch) - - def test_get_vswitch_not_found(self): - self._utils._conn.Msvm_VirtualEthernetSwitch.return_value = [] - self.assertRaises(utils.HyperVException, self._utils._get_vswitch, - self._FAKE_VSWITCH_NAME) - - def test_get_vswitch_external_port(self): - mock_vswitch = mock.MagicMock() - mock_sw_port = mock.MagicMock() - mock_vswitch.associators.return_value = [mock_sw_port] - mock_le = mock_sw_port.associators.return_value - mock_le.__len__.return_value = 1 - mock_le1 = mock_le[0].associators.return_value - mock_le1.__len__.return_value = 1 - - vswitch_port = self._utils._get_vswitch_external_port(mock_vswitch) - - self.assertEqual(mock_sw_port, vswitch_port) - - def test_set_vswitch_port_vlan_id(self): - mock_port_alloc = mock.MagicMock() - self._utils._get_switch_port_allocation = mock.MagicMock(return_value=( - mock_port_alloc, True)) - self._utils._get_vlan_setting_data_from_port_alloc = mock.MagicMock() - - mock_svc = self._utils._conn.Msvm_VirtualSystemManagementService()[0] - mock_svc.RemoveFeatureSettings.return_value = (self._FAKE_JOB_PATH, - self._FAKE_RET_VAL) - mock_vlan_settings = mock.MagicMock() - self._utils._get_vlan_setting_data = mock.MagicMock(return_value=( - mock_vlan_settings, True)) - - mock_svc.AddFeatureSettings.return_value = (self._FAKE_JOB_PATH, - None, - self._FAKE_RET_VAL) - - self._utils.set_vswitch_port_vlan_id(self._FAKE_VLAN_ID, - self._FAKE_PORT_NAME) - - self.assertTrue(mock_svc.RemoveFeatureSettings.called) - self.assertTrue(mock_svc.AddFeatureSettings.called) - - def test_get_setting_data(self): - self._utils._get_first_item = mock.MagicMock(return_value=None) - - mock_data = mock.MagicMock() - self._utils._get_default_setting_data = mock.MagicMock( - return_value=mock_data) - - ret_val = self._utils._get_setting_data(self._FAKE_CLASS_NAME, - self._FAKE_ELEMENT_NAME, - True) - - self.assertEqual(ret_val, (mock_data, False)) - - def test_enable_port_metrics_collection(self): - mock_port = mock.MagicMock() - self._utils._get_switch_port_allocation = mock.MagicMock(return_value=( - mock_port, True)) - - mock_acl = mock.MagicMock() - - with mock.patch.multiple( - self._utils, - _get_default_setting_data=mock.MagicMock(return_value=mock_acl), - _add_virt_feature=mock.MagicMock()): - - self._utils.enable_port_metrics_collection(self._FAKE_PORT_NAME) - - self.assertEqual(4, len(self._utils._add_virt_feature.mock_calls)) - self._utils._add_virt_feature.assert_called_with( - mock_port, mock_acl) - - @mock.patch('neutron.plugins.hyperv.agent.utilsv2.HyperVUtilsV2' - '._get_switch_port_allocation') - def test_enable_control_metrics_ok(self, mock_get_port_allocation): - mock_metrics_svc = self._utils._conn.Msvm_MetricService()[0] - mock_metrics_def_source = self._utils._conn.CIM_BaseMetricDefinition - mock_metric_def = mock.MagicMock() - mock_port = mock.MagicMock() - mock_get_port_allocation.return_value = (mock_port, True) - - mock_metrics_def_source.return_value = [mock_metric_def] - m_call = mock.call(Subject=mock_port.path_.return_value, - Definition=mock_metric_def.path_.return_value, - MetricCollectionEnabled=self._utils._METRIC_ENABLED) - - self._utils.enable_control_metrics(self._FAKE_PORT_NAME) - - mock_metrics_svc.ControlMetrics.assert_has_calls([m_call, m_call]) - - @mock.patch('neutron.plugins.hyperv.agent.utilsv2.HyperVUtilsV2' - '._get_switch_port_allocation') - def test_enable_control_metrics_no_port(self, mock_get_port_allocation): - mock_metrics_svc = self._utils._conn.Msvm_MetricService()[0] - mock_get_port_allocation.return_value = (None, False) - - self._utils.enable_control_metrics(self._FAKE_PORT_NAME) - self.assertEqual(0, mock_metrics_svc.ControlMetrics.call_count) - - @mock.patch('neutron.plugins.hyperv.agent.utilsv2.HyperVUtilsV2' - '._get_switch_port_allocation') - def test_enable_control_metrics_no_def(self, mock_get_port_allocation): - mock_metrics_svc = self._utils._conn.Msvm_MetricService()[0] - mock_metrics_def_source = self._utils._conn.CIM_BaseMetricDefinition - mock_port = mock.MagicMock() - - mock_get_port_allocation.return_value = (mock_port, True) - mock_metrics_def_source.return_value = None - - self._utils.enable_control_metrics(self._FAKE_PORT_NAME) - self.assertEqual(0, mock_metrics_svc.ControlMetrics.call_count) - - @mock.patch('neutron.plugins.hyperv.agent.utilsv2.HyperVUtilsV2' - '._is_port_vm_started') - @mock.patch('neutron.plugins.hyperv.agent.utilsv2.HyperVUtilsV2' - '._get_switch_port_allocation') - def test_can_enable_control_metrics_true(self, mock_get, mock_is_started): - mock_acl = mock.MagicMock() - mock_acl.Action = self._utils._ACL_ACTION_METER - self._test_can_enable_control_metrics(mock_get, mock_is_started, - [mock_acl, mock_acl], True) - - @mock.patch('neutron.plugins.hyperv.agent.utilsv2.HyperVUtilsV2' - '._is_port_vm_started') - @mock.patch('neutron.plugins.hyperv.agent.utilsv2.HyperVUtilsV2' - '._get_switch_port_allocation') - def test_can_enable_control_metrics_false(self, mock_get, mock_is_started): - self._test_can_enable_control_metrics(mock_get, mock_is_started, [], - False) - - def _test_can_enable_control_metrics(self, mock_get_port, mock_vm_started, - acls, expected_result): - mock_port = mock.MagicMock() - mock_acl = mock.MagicMock() - mock_acl.Action = self._utils._ACL_ACTION_METER - - mock_port.associators.return_value = acls - mock_get_port.return_value = (mock_port, True) - mock_vm_started.return_value = True - - result = self._utils.can_enable_control_metrics(self._FAKE_PORT_NAME) - self.assertEqual(expected_result, result) - - def test_is_port_vm_started_true(self): - self._test_is_port_vm_started(self._utils._HYPERV_VM_STATE_ENABLED, - True) - - def test_is_port_vm_started_false(self): - self._test_is_port_vm_started(self._FAKE_HYPERV_VM_STATE, False) - - def _test_is_port_vm_started(self, vm_state, expected_result): - mock_svc = self._utils._conn.Msvm_VirtualSystemManagementService()[0] - mock_port = mock.MagicMock() - mock_vmsettings = mock.MagicMock() - mock_summary = mock.MagicMock() - mock_summary.EnabledState = vm_state - mock_vmsettings.path_.return_value = self._FAKE_RES_PATH - - mock_port.associators.return_value = [mock_vmsettings] - mock_svc.GetSummaryInformation.return_value = (self._FAKE_RET_VAL, - [mock_summary]) - - result = self._utils._is_port_vm_started(mock_port) - self.assertEqual(expected_result, result) - mock_svc.GetSummaryInformation.assert_called_once_with( - [self._utils._VM_SUMMARY_ENABLED_STATE], - [self._FAKE_RES_PATH]) - - @mock.patch('neutron.plugins.hyperv.agent.utilsv2.HyperVUtilsV2' - '._remove_virt_feature') - @mock.patch('neutron.plugins.hyperv.agent.utilsv2.HyperVUtilsV2' - '._bind_security_rule') - def test_create_default_reject_all_rules(self, mock_bind, mock_remove): - (m_port, m_acl) = self._setup_security_rule_test() - m_acl.Action = self._utils._ACL_ACTION_DENY - self._utils.create_default_reject_all_rules(self._FAKE_PORT_NAME) - - calls = [] - ipv4_pair = (self._utils._ACL_TYPE_IPV4, self._utils._IPV4_ANY) - ipv6_pair = (self._utils._ACL_TYPE_IPV6, self._utils._IPV6_ANY) - for direction in [self._utils._ACL_DIR_IN, self._utils._ACL_DIR_OUT]: - for acl_type, address in [ipv4_pair, ipv6_pair]: - for protocol in [self._utils._TCP_PROTOCOL, - self._utils._UDP_PROTOCOL, - self._utils._ICMP_PROTOCOL]: - calls.append(mock.call(m_port, direction, acl_type, - self._utils._ACL_ACTION_DENY, - self._utils._ACL_DEFAULT, - protocol, address, mock.ANY)) - - self._utils._remove_virt_feature.assert_called_once_with(m_acl) - self._utils._bind_security_rule.assert_has_calls(calls) - - @mock.patch('neutron.plugins.hyperv.agent.utilsv2.HyperVUtilsV2' - '._remove_virt_feature') - @mock.patch('neutron.plugins.hyperv.agent.utilsv2.HyperVUtilsV2' - '._bind_security_rule') - def test_create_default_reject_all_rules_already_added(self, mock_bind, - mock_remove): - (m_port, m_acl) = self._setup_security_rule_test() - m_acl.Action = self._utils._ACL_ACTION_DENY - m_port.associators.return_value = [ - m_acl] * self._utils._REJECT_ACLS_COUNT - self._utils.create_default_reject_all_rules(self._FAKE_PORT_NAME) - - self.assertFalse(self._utils._remove_virt_feature.called) - self.assertFalse(self._utils._bind_security_rule.called) - - @mock.patch('neutron.plugins.hyperv.agent.utilsv2.HyperVUtilsV2' - '._remove_virt_feature') - @mock.patch('neutron.plugins.hyperv.agent.utilsv2.HyperVUtilsV2' - '._add_virt_feature') - @mock.patch('neutron.plugins.hyperv.agent.utilsv2.HyperVUtilsV2' - '._create_security_acl') - def test_bind_security_rule(self, mock_create_acl, mock_add, mock_remove): - (m_port, m_acl) = self._setup_security_rule_test() - mock_create_acl.return_value = m_acl - - self._utils._bind_security_rule( - m_port, self._FAKE_ACL_DIR, self._FAKE_ACL_TYPE, - self._FAKE_ACL_ACT, self._FAKE_LOCAL_PORT, self._FAKE_PROTOCOL, - self._FAKE_REMOTE_ADDR, self._FAKE_WEIGHT) - - self._utils._add_virt_feature.assert_called_once_with(m_port, m_acl) - - @mock.patch('neutron.plugins.hyperv.agent.utilsv2.HyperVUtilsV2' - '._remove_virt_feature') - def test_remove_security_rule(self, mock_remove_feature): - mock_acl = self._setup_security_rule_test()[1] - self._utils.remove_security_rule( - self._FAKE_PORT_NAME, self._FAKE_ACL_DIR, self._FAKE_ACL_TYPE, - self._FAKE_LOCAL_PORT, self._FAKE_PROTOCOL, self._FAKE_REMOTE_ADDR) - self._utils._remove_virt_feature.assert_called_once_with(mock_acl) - - @mock.patch('neutron.plugins.hyperv.agent.utilsv2.HyperVUtilsV2' - '._remove_multiple_virt_features') - def test_remove_all_security_rules(self, mock_remove_feature): - mock_acl = self._setup_security_rule_test()[1] - self._utils.remove_all_security_rules(self._FAKE_PORT_NAME) - self._utils._remove_multiple_virt_features.assert_called_once_with( - [mock_acl]) - - def _setup_security_rule_test(self): - mock_port = mock.MagicMock() - mock_acl = mock.MagicMock() - mock_port.associators.return_value = [mock_acl] - - self._utils._get_switch_port_allocation = mock.MagicMock(return_value=( - mock_port, True)) - self._utils._filter_security_acls = mock.MagicMock( - return_value=[mock_acl]) - - return (mock_port, mock_acl) - - def test_filter_acls(self): - mock_acl = mock.MagicMock() - mock_acl.Action = self._FAKE_ACL_ACT - mock_acl.Applicability = self._utils._ACL_APPLICABILITY_LOCAL - mock_acl.Direction = self._FAKE_ACL_DIR - mock_acl.AclType = self._FAKE_ACL_TYPE - mock_acl.RemoteAddress = self._FAKE_REMOTE_ADDR - - acls = [mock_acl, mock_acl] - good_acls = self._utils._filter_acls( - acls, self._FAKE_ACL_ACT, self._FAKE_ACL_DIR, - self._FAKE_ACL_TYPE, self._FAKE_REMOTE_ADDR) - bad_acls = self._utils._filter_acls( - acls, self._FAKE_ACL_ACT, self._FAKE_ACL_DIR, self._FAKE_ACL_TYPE) - - self.assertEqual(acls, good_acls) - self.assertEqual([], bad_acls) - - -class TestHyperVUtilsV2R2(base.BaseTestCase): - _FAKE_ACL_ACT = 'fake_acl_action' - _FAKE_ACL_DIR = 'fake_direction' - _FAKE_ACL_TYPE = 'fake_acl_type' - _FAKE_LOCAL_PORT = 'fake_local_port' - _FAKE_PROTOCOL = 'fake_port_protocol' - _FAKE_REMOTE_ADDR = '10.0.0.0/0' - - def setUp(self): - super(TestHyperVUtilsV2R2, self).setUp() - self._utils = utilsv2.HyperVUtilsV2R2() - - def test_filter_security_acls(self): - self._test_filter_security_acls( - self._FAKE_LOCAL_PORT, self._FAKE_PROTOCOL, self._FAKE_REMOTE_ADDR) - - def test_filter_security_acls_default(self): - default = self._utils._ACL_DEFAULT - self._test_filter_security_acls( - default, default, self._FAKE_REMOTE_ADDR) - - def _test_filter_security_acls(self, local_port, protocol, remote_addr): - acls = [] - default = self._utils._ACL_DEFAULT - for port, proto in [(default, default), (local_port, protocol)]: - mock_acl = mock.MagicMock() - mock_acl.Action = self._utils._ACL_ACTION_ALLOW - mock_acl.Direction = self._FAKE_ACL_DIR - mock_acl.LocalPort = port - mock_acl.Protocol = proto - mock_acl.RemoteIPAddress = remote_addr - acls.append(mock_acl) - - right_acls = [a for a in acls if a.LocalPort == local_port] - - good_acls = self._utils._filter_security_acls( - acls, mock_acl.Action, self._FAKE_ACL_DIR, self._FAKE_ACL_TYPE, - local_port, protocol, remote_addr) - bad_acls = self._utils._filter_security_acls( - acls, self._FAKE_ACL_ACT, self._FAKE_ACL_DIR, self._FAKE_ACL_TYPE, - local_port, protocol, remote_addr) - - self.assertEqual(right_acls, good_acls) - self.assertEqual([], bad_acls) - - def test_get_new_weight(self): - mockacl1 = mock.MagicMock() - mockacl1.Weight = self._utils._MAX_WEIGHT - 1 - mockacl2 = mock.MagicMock() - mockacl2.Weight = self._utils._MAX_WEIGHT - 3 - self.assertEqual(self._utils._MAX_WEIGHT - 2, - self._utils._get_new_weight([mockacl1, mockacl2])) - - def test_get_new_weight_no_acls(self): - self.assertEqual(self._utils._MAX_WEIGHT - 1, - self._utils._get_new_weight([])) - - def test_get_new_weight_default_acls(self): - mockacl1 = mock.MagicMock() - mockacl1.Weight = self._utils._MAX_WEIGHT - 1 - mockacl2 = mock.MagicMock() - mockacl2.Weight = self._utils._MAX_WEIGHT - 2 - mockacl2.Action = self._utils._ACL_ACTION_DENY - - self.assertEqual(self._utils._MAX_WEIGHT - 2, - self._utils._get_new_weight([mockacl1, mockacl2])) diff --git a/neutron/tests/unit/ibm/__init__.py b/neutron/tests/unit/ibm/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/neutron/tests/unit/ibm/test_sdnve_agent.py b/neutron/tests/unit/ibm/test_sdnve_agent.py deleted file mode 100644 index 3b33d901e..000000000 --- a/neutron/tests/unit/ibm/test_sdnve_agent.py +++ /dev/null @@ -1,118 +0,0 @@ -# Copyright 2014 IBM Corp. -# -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Mohammad Banikazemi, IBM Corp - - -import contextlib - -import mock -from oslo.config import cfg - -from neutron.agent.linux import ip_lib -from neutron.plugins.ibm.agent import sdnve_neutron_agent -from neutron.tests import base - - -NOTIFIER = ('neutron.plugins.ibm.' - 'sdnve_neutron_plugin.AgentNotifierApi') - - -class CreateAgentConfigMap(base.BaseTestCase): - - def test_create_agent_config_map_succeeds(self): - self.assertTrue(sdnve_neutron_agent.create_agent_config_map(cfg.CONF)) - - def test_create_agent_config_using_controller_ips(self): - cfg.CONF.set_override('controller_ips', - ['10.10.10.1', '10.10.10.2'], group='SDNVE') - cfgmap = sdnve_neutron_agent.create_agent_config_map(cfg.CONF) - self.assertEqual(cfgmap['controller_ip'], '10.10.10.1') - - def test_create_agent_config_using_interface_mappings(self): - cfg.CONF.set_override('interface_mappings', - ['interface1 : eth1', 'interface2 : eth2'], - group='SDNVE') - cfgmap = sdnve_neutron_agent.create_agent_config_map(cfg.CONF) - self.assertEqual(cfgmap['interface_mappings'], - {'interface1': 'eth1', 'interface2': 'eth2'}) - - -class TestSdnveNeutronAgent(base.BaseTestCase): - - def setUp(self): - super(TestSdnveNeutronAgent, self).setUp() - notifier_p = mock.patch(NOTIFIER) - notifier_cls = notifier_p.start() - self.notifier = mock.Mock() - notifier_cls.return_value = self.notifier - # Avoid rpc initialization for unit tests - cfg.CONF.set_override('rpc_backend', - 'neutron.openstack.common.rpc.impl_fake') - cfg.CONF.set_override('integration_bridge', - 'br_int', group='SDNVE') - kwargs = sdnve_neutron_agent.create_agent_config_map(cfg.CONF) - - class MockFixedIntervalLoopingCall(object): - def __init__(self, f): - self.f = f - - def start(self, interval=0): - self.f() - - with contextlib.nested( - mock.patch('neutron.plugins.ibm.agent.sdnve_neutron_agent.' - 'SdnveNeutronAgent.setup_integration_br', - return_value=mock.Mock()), - mock.patch('neutron.openstack.common.loopingcall.' - 'FixedIntervalLoopingCall', - new=MockFixedIntervalLoopingCall)): - self.agent = sdnve_neutron_agent.SdnveNeutronAgent(**kwargs) - - def test_setup_physical_interfaces(self): - with mock.patch.object(self.agent.int_br, - 'add_port') as add_port_func: - with mock.patch.object(ip_lib, - 'device_exists', - return_valxue=True): - self.agent.setup_physical_interfaces({"interface1": "eth1"}) - add_port_func.assert_called_once_with('eth1') - - def test_setup_physical_interfaces_none(self): - with mock.patch.object(self.agent.int_br, - 'add_port') as add_port_func: - with mock.patch.object(ip_lib, - 'device_exists', - return_valxue=True): - self.agent.setup_physical_interfaces({}) - self.assertFalse(add_port_func.called) - - def test_get_info_set_controller(self): - with mock.patch.object(self.agent.int_br, - 'run_vsctl') as run_vsctl_func: - kwargs = {} - kwargs['info'] = {'new_controller': '10.10.10.1'} - self.agent.info_update('dummy', **kwargs) - run_vsctl_func.assert_called_once_with(['set-controller', - 'br_int', - 'tcp:10.10.10.1']) - - def test_get_info(self): - with mock.patch.object(self.agent.int_br, - 'run_vsctl') as run_vsctl_func: - kwargs = {} - self.agent.info_update('dummy', **kwargs) - self.assertFalse(run_vsctl_func.called) diff --git a/neutron/tests/unit/ibm/test_sdnve_api.py b/neutron/tests/unit/ibm/test_sdnve_api.py deleted file mode 100644 index f1f8d60b8..000000000 --- a/neutron/tests/unit/ibm/test_sdnve_api.py +++ /dev/null @@ -1,145 +0,0 @@ -# Copyright 2014 IBM Corp. -# -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Mohammad Banikazemi, IBM Corp - - -import mock - -from neutron.openstack.common import uuidutils -from neutron.plugins.ibm.common import constants -from neutron.plugins.ibm import sdnve_api -from neutron.tests import base - -RESOURCE_PATH = { - 'network': "ln/networks/", -} -RESOURCE = 'network' -HTTP_OK = 200 -TENANT_ID = uuidutils.generate_uuid() - - -class TestSdnveApi(base.BaseTestCase): - - def setUp(self): - super(TestSdnveApi, self).setUp() - - class MockKeystoneClient(object): - def __init__(self, **kwargs): - pass - - def get_tenant_name(self, id): - return 'test tenant name' - - with mock.patch('neutron.plugins.ibm.sdnve_api.' - 'KeystoneClient', - new=MockKeystoneClient): - self.api = sdnve_api.Client() - - def mock_do_request(self, method, url, body=None, headers=None, - params=None, connection_type=None): - return (HTTP_OK, url) - - def mock_do_request_tenant(self, method, url, body=None, headers=None, - params=None, connection_type=None): - return (HTTP_OK, {'id': TENANT_ID, - 'network_type': constants.TENANT_TYPE_OF}) - - def mock_do_request_no_tenant(self, method, url, body=None, headers=None, - params=None, connection_type=None): - return (None, None) - - def mock_process_request(self, body): - return body - - def test_sdnve_api_list(self): - with mock.patch('neutron.plugins.ibm.sdnve_api.' - 'Client.do_request', - new=self.mock_do_request): - result = self.api.sdnve_list(RESOURCE) - self.assertEqual(result, (HTTP_OK, RESOURCE_PATH[RESOURCE])) - - def test_sdnve_api_show(self): - with mock.patch('neutron.plugins.ibm.sdnve_api.' - 'Client.do_request', - new=self.mock_do_request): - result = self.api.sdnve_show(RESOURCE, TENANT_ID) - self.assertEqual(result, - (HTTP_OK, RESOURCE_PATH[RESOURCE] + TENANT_ID)) - - def test_sdnve_api_create(self): - with mock.patch('neutron.plugins.ibm.sdnve_api.' - 'Client.do_request', - new=self.mock_do_request): - with mock.patch('neutron.plugins.ibm.sdnve_api.' - 'Client.process_request', - new=self.mock_process_request): - result = self.api.sdnve_create(RESOURCE, '') - self.assertEqual(result, (HTTP_OK, RESOURCE_PATH[RESOURCE])) - - def test_sdnve_api_update(self): - with mock.patch('neutron.plugins.ibm.sdnve_api.' - 'Client.do_request', - new=self.mock_do_request): - with mock.patch('neutron.plugins.ibm.sdnve_api.' - 'Client.process_request', - new=self.mock_process_request): - result = self.api.sdnve_update(RESOURCE, TENANT_ID, '') - self.assertEqual(result, - (HTTP_OK, - RESOURCE_PATH[RESOURCE] + TENANT_ID)) - - def test_sdnve_api_delete(self): - with mock.patch('neutron.plugins.ibm.sdnve_api.' - 'Client.do_request', - new=self.mock_do_request): - result = self.api.sdnve_delete(RESOURCE, TENANT_ID) - self.assertEqual(result, - (HTTP_OK, RESOURCE_PATH[RESOURCE] + TENANT_ID)) - - def test_sdnve_get_tenant_by_id(self): - with mock.patch('neutron.plugins.ibm.sdnve_api.' - 'Client.do_request', - new=self.mock_do_request_tenant): - id = TENANT_ID - result = self.api.sdnve_get_tenant_byid(id) - self.assertEqual(result, - (TENANT_ID, constants.TENANT_TYPE_OF)) - - def test_sdnve_check_and_create_tenant(self): - with mock.patch('neutron.plugins.ibm.sdnve_api.' - 'Client.do_request', - new=self.mock_do_request_tenant): - id = TENANT_ID - result = self.api.sdnve_check_and_create_tenant(id) - self.assertEqual(result, TENANT_ID) - - def test_sdnve_check_and_create_tenant_fail(self): - with mock.patch('neutron.plugins.ibm.sdnve_api.' - 'Client.do_request', - new=self.mock_do_request_no_tenant): - id = TENANT_ID - result = self.api.sdnve_check_and_create_tenant( - id, constants.TENANT_TYPE_OF) - self.assertIsNone(result) - - def test_process_request(self): - my_request = {'key_1': 'value_1', 'router:external': 'True', - 'key_2': 'value_2'} - expected = {'key_1': 'value_1', 'router_external': 'True', - 'key_2': 'value_2'} - result = self.api.process_request(my_request) - self.assertEqual(expected, result) diff --git a/neutron/tests/unit/ibm/test_sdnve_plugin.py b/neutron/tests/unit/ibm/test_sdnve_plugin.py deleted file mode 100644 index 4e4c967cc..000000000 --- a/neutron/tests/unit/ibm/test_sdnve_plugin.py +++ /dev/null @@ -1,126 +0,0 @@ -# Copyright 2014 IBM Corp. -# -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Mohammad Banikazemi, IBM Corp - - -import contextlib -import mock - -from neutron.extensions import portbindings -from neutron.tests.unit import _test_extension_portbindings as test_bindings -from neutron.tests.unit import test_db_plugin as test_plugin -from neutron.tests.unit import test_l3_plugin as test_l3_plugin - -from neutron.plugins.ibm.common import constants - - -_plugin_name = ('neutron.plugins.ibm.' - 'sdnve_neutron_plugin.SdnvePluginV2') -HTTP_OK = 200 - - -class MockClient(object): - def sdnve_list(self, resource, **params): - return (HTTP_OK, 'body') - - def sdnve_show(self, resource, specific, **params): - return (HTTP_OK, 'body') - - def sdnve_create(self, resource, body): - return (HTTP_OK, 'body') - - def sdnve_update(self, resource, specific, body=None): - return (HTTP_OK, 'body') - - def sdnve_delete(self, resource, specific): - return (HTTP_OK, 'body') - - def sdnve_get_tenant_byid(self, os_tenant_id): - return (os_tenant_id, constants.TENANT_TYPE_OF) - - def sdnve_check_and_create_tenant( - self, os_tenant_id, network_type=None): - return os_tenant_id - - def sdnve_get_controller(self): - return - - -class MockKeystoneClient(object): - def __init__(self, **kwargs): - pass - - def get_tenant_type(self, id): - return constants.TENANT_TYPE_OF - - def get_tenant_name(self, id): - return "tenant name" - - -class IBMPluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase): - def setUp(self): - with contextlib.nested( - mock.patch('neutron.plugins.ibm.sdnve_api.' - 'KeystoneClient', - new=MockKeystoneClient), - mock.patch('neutron.plugins.ibm.sdnve_api.' - 'Client', - new=MockClient)): - super(IBMPluginV2TestCase, self).setUp(plugin=_plugin_name) - - -class TestIBMBasicGet(test_plugin.TestBasicGet, - IBMPluginV2TestCase): - pass - - -class TestIBMV2HTTPResponse(test_plugin.TestV2HTTPResponse, - IBMPluginV2TestCase): - pass - - -class TestIBMNetworksV2(test_plugin.TestNetworksV2, - IBMPluginV2TestCase): - pass - - -class TestIBMPortsV2(test_plugin.TestPortsV2, - IBMPluginV2TestCase): - pass - - -class TestIBMSubnetsV2(test_plugin.TestSubnetsV2, - IBMPluginV2TestCase): - pass - - -class TestIBMPortBinding(IBMPluginV2TestCase, - test_bindings.PortBindingsTestCase): - VIF_TYPE = portbindings.VIF_TYPE_OVS - - -class IBMPluginRouterTestCase(test_l3_plugin.L3NatDBIntTestCase): - - def setUp(self): - with contextlib.nested( - mock.patch('neutron.plugins.ibm.sdnve_api.' - 'KeystoneClient', - new=MockKeystoneClient), - mock.patch('neutron.plugins.ibm.sdnve_api.' - 'Client', - new=MockClient)): - super(IBMPluginRouterTestCase, self).setUp(plugin=_plugin_name) diff --git a/neutron/tests/unit/linuxbridge/__init__.py b/neutron/tests/unit/linuxbridge/__init__.py deleted file mode 100644 index 7e503debd..000000000 --- a/neutron/tests/unit/linuxbridge/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2012 OpenStack Foundation. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. diff --git a/neutron/tests/unit/linuxbridge/test_agent_scheduler.py b/neutron/tests/unit/linuxbridge/test_agent_scheduler.py deleted file mode 100644 index 397baaf5c..000000000 --- a/neutron/tests/unit/linuxbridge/test_agent_scheduler.py +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright (c) 2013 OpenStack Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from neutron.tests.unit.linuxbridge import test_linuxbridge_plugin -from neutron.tests.unit.openvswitch import test_agent_scheduler - - -class LbAgentSchedulerTestCase( - test_agent_scheduler.OvsAgentSchedulerTestCase): - plugin_str = test_linuxbridge_plugin.PLUGIN_NAME - l3_plugin = None - - -class LbL3AgentNotifierTestCase( - test_agent_scheduler.OvsL3AgentNotifierTestCase): - plugin_str = test_linuxbridge_plugin.PLUGIN_NAME - l3_plugin = None - - -class LbDhcpAgentNotifierTestCase( - test_agent_scheduler.OvsDhcpAgentNotifierTestCase): - plugin_str = test_linuxbridge_plugin.PLUGIN_NAME diff --git a/neutron/tests/unit/linuxbridge/test_defaults.py b/neutron/tests/unit/linuxbridge/test_defaults.py deleted file mode 100644 index 1c395e81d..000000000 --- a/neutron/tests/unit/linuxbridge/test_defaults.py +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright (c) 2012 OpenStack Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from oslo.config import cfg - -from neutron.plugins.linuxbridge.common import config # noqa -from neutron.tests import base - - -class ConfigurationTest(base.BaseTestCase): - - def test_defaults(self): - self.assertEqual(2, - cfg.CONF.AGENT.polling_interval) - self.assertEqual(False, - cfg.CONF.AGENT.rpc_support_old_agents) - self.assertEqual('sudo', - cfg.CONF.AGENT.root_helper) - self.assertEqual('local', - cfg.CONF.VLANS.tenant_network_type) - self.assertEqual(0, - len(cfg.CONF.VLANS.network_vlan_ranges)) - self.assertEqual(0, - len(cfg.CONF.LINUX_BRIDGE. - physical_interface_mappings)) - self.assertEqual(False, cfg.CONF.VXLAN.enable_vxlan) - self.assertEqual(config.DEFAULT_VXLAN_GROUP, - cfg.CONF.VXLAN.vxlan_group) - self.assertEqual(0, len(cfg.CONF.VXLAN.local_ip)) - self.assertEqual(False, cfg.CONF.VXLAN.l2_population) diff --git a/neutron/tests/unit/linuxbridge/test_lb_db.py b/neutron/tests/unit/linuxbridge/test_lb_db.py deleted file mode 100644 index 41f56b52e..000000000 --- a/neutron/tests/unit/linuxbridge/test_lb_db.py +++ /dev/null @@ -1,172 +0,0 @@ -# Copyright (c) 2012 OpenStack Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from oslo.config import cfg -from six import moves -import testtools -from testtools import matchers - -from neutron.common import exceptions as n_exc -from neutron.db import api as db -from neutron.plugins.linuxbridge.db import l2network_db_v2 as lb_db -from neutron.tests import base -from neutron.tests.unit import test_db_plugin as test_plugin - -PHYS_NET = 'physnet1' -PHYS_NET_2 = 'physnet2' -VLAN_MIN = 10 -VLAN_MAX = 19 -VLAN_RANGES = {PHYS_NET: [(VLAN_MIN, VLAN_MAX)]} -UPDATED_VLAN_RANGES = {PHYS_NET: [(VLAN_MIN + 5, VLAN_MAX + 5)], - PHYS_NET_2: [(VLAN_MIN + 20, VLAN_MAX + 20)]} - -PLUGIN_NAME = ('neutron.plugins.linuxbridge.' - 'lb_neutron_plugin.LinuxBridgePluginV2') - - -class NetworkStatesTest(base.BaseTestCase): - def setUp(self): - super(NetworkStatesTest, self).setUp() - db.configure_db() - lb_db.sync_network_states(VLAN_RANGES) - self.session = db.get_session() - self.addCleanup(db.clear_db) - - def test_sync_network_states(self): - self.assertIsNone(lb_db.get_network_state(PHYS_NET, - VLAN_MIN - 1)) - self.assertFalse(lb_db.get_network_state(PHYS_NET, - VLAN_MIN).allocated) - self.assertFalse(lb_db.get_network_state(PHYS_NET, - VLAN_MIN + 1).allocated) - self.assertFalse(lb_db.get_network_state(PHYS_NET, - VLAN_MAX - 1).allocated) - self.assertFalse(lb_db.get_network_state(PHYS_NET, - VLAN_MAX).allocated) - self.assertIsNone(lb_db.get_network_state(PHYS_NET, - VLAN_MAX + 1)) - - lb_db.sync_network_states(UPDATED_VLAN_RANGES) - - self.assertIsNone(lb_db.get_network_state(PHYS_NET, - VLAN_MIN + 5 - 1)) - self.assertFalse(lb_db.get_network_state(PHYS_NET, - VLAN_MIN + 5).allocated) - self.assertFalse(lb_db.get_network_state(PHYS_NET, - VLAN_MIN + 5 + 1).allocated) - self.assertFalse(lb_db.get_network_state(PHYS_NET, - VLAN_MAX + 5 - 1).allocated) - self.assertFalse(lb_db.get_network_state(PHYS_NET, - VLAN_MAX + 5).allocated) - self.assertIsNone(lb_db.get_network_state(PHYS_NET, - VLAN_MAX + 5 + 1)) - - self.assertIsNone(lb_db.get_network_state(PHYS_NET_2, - VLAN_MIN + 20 - 1)) - self.assertFalse(lb_db.get_network_state(PHYS_NET_2, - VLAN_MIN + 20).allocated) - self.assertFalse(lb_db.get_network_state(PHYS_NET_2, - VLAN_MIN + 20 + 1).allocated) - self.assertFalse(lb_db.get_network_state(PHYS_NET_2, - VLAN_MAX + 20 - 1).allocated) - self.assertFalse(lb_db.get_network_state(PHYS_NET_2, - VLAN_MAX + 20).allocated) - self.assertIsNone(lb_db.get_network_state(PHYS_NET_2, - VLAN_MAX + 20 + 1)) - - lb_db.sync_network_states(VLAN_RANGES) - - self.assertIsNone(lb_db.get_network_state(PHYS_NET, - VLAN_MIN - 1)) - self.assertFalse(lb_db.get_network_state(PHYS_NET, - VLAN_MIN).allocated) - self.assertFalse(lb_db.get_network_state(PHYS_NET, - VLAN_MIN + 1).allocated) - self.assertFalse(lb_db.get_network_state(PHYS_NET, - VLAN_MAX - 1).allocated) - self.assertFalse(lb_db.get_network_state(PHYS_NET, - VLAN_MAX).allocated) - self.assertIsNone(lb_db.get_network_state(PHYS_NET, - VLAN_MAX + 1)) - - self.assertIsNone(lb_db.get_network_state(PHYS_NET_2, - VLAN_MIN + 20)) - self.assertIsNone(lb_db.get_network_state(PHYS_NET_2, - VLAN_MAX + 20)) - - def test_network_pool(self): - vlan_ids = set() - for x in moves.xrange(VLAN_MIN, VLAN_MAX + 1): - physical_network, vlan_id = lb_db.reserve_network(self.session) - self.assertEqual(physical_network, PHYS_NET) - self.assertThat(vlan_id, matchers.GreaterThan(VLAN_MIN - 1)) - self.assertThat(vlan_id, matchers.LessThan(VLAN_MAX + 1)) - vlan_ids.add(vlan_id) - - with testtools.ExpectedException(n_exc.NoNetworkAvailable): - physical_network, vlan_id = lb_db.reserve_network(self.session) - - for vlan_id in vlan_ids: - lb_db.release_network(self.session, PHYS_NET, vlan_id, VLAN_RANGES) - - def test_specific_network_inside_pool(self): - vlan_id = VLAN_MIN + 5 - self.assertFalse(lb_db.get_network_state(PHYS_NET, - vlan_id).allocated) - lb_db.reserve_specific_network(self.session, PHYS_NET, vlan_id) - self.assertTrue(lb_db.get_network_state(PHYS_NET, - vlan_id).allocated) - - with testtools.ExpectedException(n_exc.VlanIdInUse): - lb_db.reserve_specific_network(self.session, PHYS_NET, vlan_id) - - lb_db.release_network(self.session, PHYS_NET, vlan_id, VLAN_RANGES) - self.assertFalse(lb_db.get_network_state(PHYS_NET, - vlan_id).allocated) - - def test_specific_network_outside_pool(self): - vlan_id = VLAN_MAX + 5 - self.assertIsNone(lb_db.get_network_state(PHYS_NET, vlan_id)) - lb_db.reserve_specific_network(self.session, PHYS_NET, vlan_id) - self.assertTrue(lb_db.get_network_state(PHYS_NET, - vlan_id).allocated) - - with testtools.ExpectedException(n_exc.VlanIdInUse): - lb_db.reserve_specific_network(self.session, PHYS_NET, vlan_id) - - lb_db.release_network(self.session, PHYS_NET, vlan_id, VLAN_RANGES) - self.assertIsNone(lb_db.get_network_state(PHYS_NET, vlan_id)) - - -class NetworkBindingsTest(test_plugin.NeutronDbPluginV2TestCase): - def setUp(self): - cfg.CONF.set_override('network_vlan_ranges', ['physnet1:1000:2999'], - group='VLANS') - super(NetworkBindingsTest, self).setUp(plugin=PLUGIN_NAME) - db.configure_db() - self.session = db.get_session() - - def test_add_network_binding(self): - params = {'provider:network_type': 'vlan', - 'provider:physical_network': PHYS_NET, - 'provider:segmentation_id': 1234} - params['arg_list'] = tuple(params.keys()) - with self.network(**params) as network: - TEST_NETWORK_ID = network['network']['id'] - binding = lb_db.get_network_binding(self.session, TEST_NETWORK_ID) - self.assertIsNotNone(binding) - self.assertEqual(binding.network_id, TEST_NETWORK_ID) - self.assertEqual(binding.physical_network, PHYS_NET) - self.assertEqual(binding.vlan_id, 1234) diff --git a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py b/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py deleted file mode 100644 index d72b5615f..000000000 --- a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py +++ /dev/null @@ -1,1054 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright (c) 2012 OpenStack Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import contextlib -import os - -import mock -from oslo.config import cfg -import testtools - -from neutron.agent.linux import ip_lib -from neutron.agent.linux import utils -from neutron.common import constants -from neutron.common import exceptions -from neutron.plugins.common import constants as p_const -from neutron.plugins.linuxbridge.agent import linuxbridge_neutron_agent -from neutron.plugins.linuxbridge.common import constants as lconst -from neutron.tests import base - -LOCAL_IP = '192.168.0.33' -DEVICE_1 = 'tapabcdef01-12' - - -class FakeIpLinkCommand(object): - def set_up(self): - pass - - -class FakeIpDevice(object): - def __init__(self): - self.link = FakeIpLinkCommand() - - -class TestLinuxBridge(base.BaseTestCase): - - def setUp(self): - super(TestLinuxBridge, self).setUp() - interface_mappings = {'physnet1': 'eth1'} - root_helper = cfg.CONF.AGENT.root_helper - - self.linux_bridge = linuxbridge_neutron_agent.LinuxBridgeManager( - interface_mappings, root_helper) - - def test_ensure_physical_in_bridge_invalid(self): - result = self.linux_bridge.ensure_physical_in_bridge('network_id', - p_const.TYPE_VLAN, - 'physnetx', - 7) - self.assertFalse(result) - - def test_ensure_physical_in_bridge_flat(self): - with mock.patch.object(self.linux_bridge, - 'ensure_flat_bridge') as flat_bridge_func: - self.linux_bridge.ensure_physical_in_bridge( - 'network_id', p_const.TYPE_FLAT, 'physnet1', None) - self.assertTrue(flat_bridge_func.called) - - def test_ensure_physical_in_bridge_vlan(self): - with mock.patch.object(self.linux_bridge, - 'ensure_vlan_bridge') as vlan_bridge_func: - self.linux_bridge.ensure_physical_in_bridge( - 'network_id', p_const.TYPE_VLAN, 'physnet1', 7) - self.assertTrue(vlan_bridge_func.called) - - def test_ensure_physical_in_bridge_vxlan(self): - self.linux_bridge.vxlan_mode = lconst.VXLAN_UCAST - with mock.patch.object(self.linux_bridge, - 'ensure_vxlan_bridge') as vxlan_bridge_func: - self.linux_bridge.ensure_physical_in_bridge( - 'network_id', 'vxlan', 'physnet1', 7) - self.assertTrue(vxlan_bridge_func.called) - - -class TestLinuxBridgeAgent(base.BaseTestCase): - - LINK_SAMPLE = [ - '1: lo: mtu 16436 qdisc noqueue \\' - 'state UNKNOWN \\' - 'link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00', - '2: eth77: mtu 1500 \\' - 'qdisc mq state UP qlen 1000\ link/ether \\' - 'cc:dd:ee:ff:ab:cd brd ff:ff:ff:ff:ff:ff'] - - def setUp(self): - super(TestLinuxBridgeAgent, self).setUp() - # disable setting up periodic state reporting - cfg.CONF.set_override('report_interval', 0, 'AGENT') - cfg.CONF.set_override('rpc_backend', - 'neutron.openstack.common.rpc.impl_fake') - cfg.CONF.set_default('firewall_driver', - 'neutron.agent.firewall.NoopFirewallDriver', - group='SECURITYGROUP') - self.execute_p = mock.patch.object(ip_lib.IPWrapper, '_execute') - self.execute = self.execute_p.start() - self.execute.return_value = '\n'.join(self.LINK_SAMPLE) - self.get_mac_p = mock.patch('neutron.agent.linux.utils.' - 'get_interface_mac') - self.get_mac = self.get_mac_p.start() - self.get_mac.return_value = '00:00:00:00:00:01' - self.agent = linuxbridge_neutron_agent.LinuxBridgeNeutronAgentRPC({}, - 0, - None) - - def test_treat_devices_removed_with_existed_device(self): - agent = linuxbridge_neutron_agent.LinuxBridgeNeutronAgentRPC({}, - 0, - None) - devices = [DEVICE_1] - with contextlib.nested( - mock.patch.object(agent.plugin_rpc, "update_device_down"), - mock.patch.object(agent, "remove_devices_filter") - ) as (fn_udd, fn_rdf): - fn_udd.return_value = {'device': DEVICE_1, - 'exists': True} - with mock.patch.object(linuxbridge_neutron_agent.LOG, - 'info') as log: - resync = agent.treat_devices_removed(devices) - self.assertEqual(2, log.call_count) - self.assertFalse(resync) - self.assertTrue(fn_udd.called) - self.assertTrue(fn_rdf.called) - - def test_treat_devices_removed_with_not_existed_device(self): - agent = linuxbridge_neutron_agent.LinuxBridgeNeutronAgentRPC({}, - 0, - None) - devices = [DEVICE_1] - with contextlib.nested( - mock.patch.object(agent.plugin_rpc, "update_device_down"), - mock.patch.object(agent, "remove_devices_filter") - ) as (fn_udd, fn_rdf): - fn_udd.return_value = {'device': DEVICE_1, - 'exists': False} - with mock.patch.object(linuxbridge_neutron_agent.LOG, - 'debug') as log: - resync = agent.treat_devices_removed(devices) - self.assertEqual(1, log.call_count) - self.assertFalse(resync) - self.assertTrue(fn_udd.called) - self.assertTrue(fn_rdf.called) - - def test_treat_devices_removed_failed(self): - agent = linuxbridge_neutron_agent.LinuxBridgeNeutronAgentRPC({}, - 0, - None) - devices = [DEVICE_1] - with contextlib.nested( - mock.patch.object(agent.plugin_rpc, "update_device_down"), - mock.patch.object(agent, "remove_devices_filter") - ) as (fn_udd, fn_rdf): - fn_udd.side_effect = Exception() - with mock.patch.object(linuxbridge_neutron_agent.LOG, - 'debug') as log: - resync = agent.treat_devices_removed(devices) - self.assertEqual(2, log.call_count) - self.assertTrue(resync) - self.assertTrue(fn_udd.called) - self.assertTrue(fn_rdf.called) - - def test_loop_restores_updated_devices_on_exception(self): - agent = self.agent - agent.updated_devices = set(['tap1', 'tap2']) - - with contextlib.nested( - mock.patch.object(agent, 'scan_devices'), - mock.patch.object(linuxbridge_neutron_agent.LOG, 'info'), - mock.patch.object(agent, 'process_network_devices') - ) as (scan_devices, log, process_network_devices): - # Simulate effect of 2 port_update()s when loop is running. - # And break out of loop at start of 2nd iteration. - log.side_effect = [agent.updated_devices.add('tap3'), - agent.updated_devices.add('tap4'), - ValueError] - scan_devices.side_effect = RuntimeError - - with testtools.ExpectedException(ValueError): - agent.daemon_loop() - - # Check that the originals {tap1,tap2} have been restored - # and the new updates {tap3, tap4} have not been overwritten. - self.assertEqual(set(['tap1', 'tap2', 'tap3', 'tap4']), - agent.updated_devices) - self.assertEqual(3, log.call_count) - - def mock_scan_devices(self, expected, mock_current, - registered_devices, updated_devices): - self.agent.br_mgr = mock.Mock() - self.agent.br_mgr.get_tap_devices.return_value = mock_current - - results = self.agent.scan_devices(registered_devices, updated_devices) - self.assertEqual(expected, results) - - def test_scan_devices_returns_empty_sets(self): - registered = set() - updated = set() - mock_current = set() - expected = {'current': set(), - 'updated': set(), - 'added': set(), - 'removed': set()} - self.mock_scan_devices(expected, mock_current, registered, updated) - - def test_scan_devices_no_changes(self): - registered = set(['tap1', 'tap2']) - updated = set() - mock_current = set(['tap1', 'tap2']) - expected = {'current': set(['tap1', 'tap2']), - 'updated': set(), - 'added': set(), - 'removed': set()} - self.mock_scan_devices(expected, mock_current, registered, updated) - - def test_scan_devices_new_and_removed(self): - registered = set(['tap1', 'tap2']) - updated = set() - mock_current = set(['tap2', 'tap3']) - expected = {'current': set(['tap2', 'tap3']), - 'updated': set(), - 'added': set(['tap3']), - 'removed': set(['tap1'])} - self.mock_scan_devices(expected, mock_current, registered, updated) - - def test_scan_devices_new_updates(self): - registered = set(['tap1']) - updated = set(['tap2']) - mock_current = set(['tap1', 'tap2']) - expected = {'current': set(['tap1', 'tap2']), - 'updated': set(['tap2']), - 'added': set(['tap2']), - 'removed': set()} - self.mock_scan_devices(expected, mock_current, registered, updated) - - def test_scan_devices_updated_missing(self): - registered = set(['tap1']) - updated = set(['tap2']) - mock_current = set(['tap1']) - expected = {'current': set(['tap1']), - 'updated': set(), - 'added': set(), - 'removed': set()} - self.mock_scan_devices(expected, mock_current, registered, updated) - - def test_process_network_devices(self): - agent = self.agent - device_info = {'current': set(), - 'added': set(['tap3', 'tap4']), - 'updated': set(['tap2', 'tap3']), - 'removed': set(['tap1'])} - agent.prepare_devices_filter = mock.Mock() - agent.refresh_firewall = mock.Mock() - agent.treat_devices_added_updated = mock.Mock(return_value=False) - agent.treat_devices_removed = mock.Mock(return_value=False) - - agent.process_network_devices(device_info) - - agent.prepare_devices_filter.assert_called_with(set(['tap3', 'tap4'])) - self.assertTrue(agent.refresh_firewall.called) - agent.treat_devices_added_updated.assert_called_with(set(['tap2', - 'tap3', - 'tap4'])) - agent.treat_devices_removed.assert_called_with(set(['tap1'])) - - def test_treat_devices_added_updated_admin_state_up_true(self): - agent = self.agent - mock_details = {'port_id': 'port123', - 'network_id': 'net123', - 'admin_state_up': True, - 'network_type': 'vlan', - 'segmentation_id': 100, - 'physical_network': 'physnet1'} - agent.plugin_rpc = mock.Mock() - agent.plugin_rpc.get_device_details.return_value = mock_details - agent.br_mgr = mock.Mock() - agent.br_mgr.add_interface.return_value = True - - resync_needed = agent.treat_devices_added_updated(set(['tap1'])) - - self.assertFalse(resync_needed) - agent.br_mgr.add_interface.assert_called_with('net123', 'vlan', - 'physnet1', 100, - 'port123') - self.assertTrue(agent.plugin_rpc.update_device_up.called) - - def test_treat_devices_added_updated_admin_state_up_false(self): - mock_details = {'port_id': 'port123', - 'network_id': 'net123', - 'admin_state_up': False, - 'network_type': 'vlan', - 'segmentation_id': 100, - 'physical_network': 'physnet1'} - self.agent.plugin_rpc = mock.Mock() - self.agent.plugin_rpc.get_device_details.return_value = mock_details - self.agent.remove_port_binding = mock.Mock() - - resync_needed = self.agent.treat_devices_added_updated(set(['tap1'])) - - self.assertFalse(resync_needed) - self.agent.remove_port_binding.assert_called_with('net123', 'port123') - self.assertFalse(self.agent.plugin_rpc.update_device_up.called) - - -class TestLinuxBridgeManager(base.BaseTestCase): - def setUp(self): - super(TestLinuxBridgeManager, self).setUp() - self.interface_mappings = {'physnet1': 'eth1'} - self.root_helper = cfg.CONF.AGENT.root_helper - - self.lbm = linuxbridge_neutron_agent.LinuxBridgeManager( - self.interface_mappings, self.root_helper) - - def test_interface_exists_on_bridge(self): - with mock.patch.object(os, 'listdir') as listdir_fn: - listdir_fn.return_value = ["abc"] - self.assertTrue( - self.lbm.interface_exists_on_bridge("br-int", "abc") - ) - self.assertFalse( - self.lbm.interface_exists_on_bridge("br-int", "abd") - ) - - def test_get_bridge_name(self): - nw_id = "123456789101112" - self.assertEqual(self.lbm.get_bridge_name(nw_id), - "brq" + nw_id[0:11]) - nw_id = "" - self.assertEqual(self.lbm.get_bridge_name(nw_id), - "brq") - - def test_get_subinterface_name(self): - self.assertEqual(self.lbm.get_subinterface_name("eth0", "0"), - "eth0.0") - self.assertEqual(self.lbm.get_subinterface_name("eth0", ""), - "eth0.") - - def test_get_tap_device_name(self): - if_id = "123456789101112" - self.assertEqual(self.lbm.get_tap_device_name(if_id), - "tap" + if_id[0:11]) - if_id = "" - self.assertEqual(self.lbm.get_tap_device_name(if_id), - "tap") - - def test_get_vxlan_device_name(self): - vn_id = constants.MAX_VXLAN_VNI - self.assertEqual(self.lbm.get_vxlan_device_name(vn_id), - "vxlan-" + str(vn_id)) - self.assertIsNone(self.lbm.get_vxlan_device_name(vn_id + 1)) - - def test_get_all_neutron_bridges(self): - br_list = ["br-int", "brq1", "brq2", "br-ex"] - with mock.patch.object(os, 'listdir') as listdir_fn: - listdir_fn.return_value = br_list - self.assertEqual(self.lbm.get_all_neutron_bridges(), - br_list[1:3]) - self.assertTrue(listdir_fn.called) - - def test_get_interfaces_on_bridge(self): - with contextlib.nested( - mock.patch.object(utils, 'execute'), - mock.patch.object(os, 'listdir'), - mock.patch.object(ip_lib, 'device_exists', return_value=True) - ) as (exec_fn, listdir_fn, dev_exists_fn): - listdir_fn.return_value = ["qbr1"] - self.assertEqual(self.lbm.get_interfaces_on_bridge("br0"), - ["qbr1"]) - - def test_get_interfaces_on_bridge_not_existing(self): - with mock.patch.object(ip_lib, 'device_exists', return_value=False): - self.assertEqual([], self.lbm.get_interfaces_on_bridge("br0")) - - def test_get_tap_devices_count(self): - with mock.patch.object(os, 'listdir') as listdir_fn: - listdir_fn.return_value = ['tap2101', 'eth0.100', 'vxlan-1000'] - self.assertEqual(self.lbm.get_tap_devices_count('br0'), 1) - listdir_fn.side_effect = OSError() - self.assertEqual(self.lbm.get_tap_devices_count('br0'), 0) - - def test_get_interface_by_ip(self): - with contextlib.nested( - mock.patch.object(ip_lib.IPWrapper, 'get_devices'), - mock.patch.object(ip_lib.IpAddrCommand, 'list') - ) as (get_dev_fn, ip_list_fn): - device = mock.Mock() - device.name = 'dev_name' - get_dev_fn.return_value = [device] - ip_list_fn.returnvalue = mock.Mock() - self.assertEqual(self.lbm.get_interface_by_ip(LOCAL_IP), - 'dev_name') - - def test_get_bridge_for_tap_device(self): - with contextlib.nested( - mock.patch.object(self.lbm, "get_all_neutron_bridges"), - mock.patch.object(self.lbm, "get_interfaces_on_bridge") - ) as (get_all_qbr_fn, get_if_fn): - get_all_qbr_fn.return_value = ["br-int", "br-ex"] - get_if_fn.return_value = ["tap1", "tap2", "tap3"] - self.assertEqual(self.lbm.get_bridge_for_tap_device("tap1"), - "br-int") - self.assertIsNone(self.lbm.get_bridge_for_tap_device("tap4")) - - def test_is_device_on_bridge(self): - self.assertTrue(not self.lbm.is_device_on_bridge("")) - with mock.patch.object(os.path, 'exists') as exists_fn: - exists_fn.return_value = True - self.assertTrue(self.lbm.is_device_on_bridge("tap1")) - exists_fn.assert_called_with( - "/sys/devices/virtual/net/tap1/brport" - ) - - def test_get_interface_details(self): - with contextlib.nested( - mock.patch.object(ip_lib.IpAddrCommand, 'list'), - mock.patch.object(ip_lib.IpRouteCommand, 'get_gateway') - ) as (list_fn, getgw_fn): - gwdict = dict(gateway='1.1.1.1') - getgw_fn.return_value = gwdict - ipdict = dict(cidr='1.1.1.1/24', - broadcast='1.1.1.255', - scope='global', - ip_version=4, - dynamic=False) - list_fn.return_value = ipdict - ret = self.lbm.get_interface_details("eth0") - - self.assertTrue(list_fn.called) - self.assertTrue(getgw_fn.called) - self.assertEqual(ret, (ipdict, gwdict)) - - def test_ensure_flat_bridge(self): - with contextlib.nested( - mock.patch.object(ip_lib.IpAddrCommand, 'list'), - mock.patch.object(ip_lib.IpRouteCommand, 'get_gateway') - ) as (list_fn, getgw_fn): - gwdict = dict(gateway='1.1.1.1') - getgw_fn.return_value = gwdict - ipdict = dict(cidr='1.1.1.1/24', - broadcast='1.1.1.255', - scope='global', - ip_version=4, - dynamic=False) - list_fn.return_value = ipdict - with mock.patch.object(self.lbm, 'ensure_bridge') as ens: - self.assertEqual( - self.lbm.ensure_flat_bridge("123", "eth0"), - "eth0" - ) - self.assertTrue(list_fn.called) - self.assertTrue(getgw_fn.called) - ens.assert_called_once_with("brq123", "eth0", - ipdict, gwdict) - - def test_ensure_vlan_bridge(self): - with contextlib.nested( - mock.patch.object(self.lbm, 'ensure_vlan'), - mock.patch.object(self.lbm, 'ensure_bridge'), - mock.patch.object(self.lbm, 'get_interface_details'), - ) as (ens_vl_fn, ens, get_int_det_fn): - ens_vl_fn.return_value = "eth0.1" - get_int_det_fn.return_value = (None, None) - self.assertEqual(self.lbm.ensure_vlan_bridge("123", "eth0", "1"), - "eth0.1") - ens.assert_called_with("brq123", "eth0.1", None, None) - - get_int_det_fn.return_value = ("ips", "gateway") - self.assertEqual(self.lbm.ensure_vlan_bridge("123", "eth0", "1"), - "eth0.1") - ens.assert_called_with("brq123", "eth0.1", "ips", "gateway") - - def test_ensure_local_bridge(self): - with mock.patch.object(self.lbm, 'ensure_bridge') as ens_fn: - self.lbm.ensure_local_bridge("54321") - ens_fn.assert_called_once_with("brq54321") - - def test_ensure_vlan(self): - with mock.patch.object(ip_lib, 'device_exists') as de_fn: - de_fn.return_value = True - self.assertEqual(self.lbm.ensure_vlan("eth0", "1"), "eth0.1") - de_fn.return_value = False - with mock.patch.object(utils, 'execute') as exec_fn: - exec_fn.return_value = False - self.assertEqual(self.lbm.ensure_vlan("eth0", "1"), "eth0.1") - # FIXME(kevinbenton): validate the params to the exec_fn calls - self.assertEqual(exec_fn.call_count, 2) - exec_fn.return_value = True - self.assertIsNone(self.lbm.ensure_vlan("eth0", "1")) - self.assertEqual(exec_fn.call_count, 3) - - def test_ensure_vxlan(self): - seg_id = "12345678" - self.lbm.local_int = 'eth0' - self.lbm.vxlan_mode = lconst.VXLAN_MCAST - with mock.patch.object(ip_lib, 'device_exists') as de_fn: - de_fn.return_value = True - self.assertEqual(self.lbm.ensure_vxlan(seg_id), "vxlan-" + seg_id) - de_fn.return_value = False - with mock.patch.object(self.lbm.ip, - 'add_vxlan') as add_vxlan_fn: - add_vxlan_fn.return_value = FakeIpDevice() - self.assertEqual(self.lbm.ensure_vxlan(seg_id), - "vxlan-" + seg_id) - add_vxlan_fn.assert_called_with("vxlan-" + seg_id, seg_id, - group="224.0.0.1", - dev=self.lbm.local_int) - cfg.CONF.set_override('l2_population', 'True', 'VXLAN') - self.assertEqual(self.lbm.ensure_vxlan(seg_id), - "vxlan-" + seg_id) - add_vxlan_fn.assert_called_with("vxlan-" + seg_id, seg_id, - group="224.0.0.1", - dev=self.lbm.local_int, - proxy=True) - - def test_update_interface_ip_details(self): - gwdict = dict(gateway='1.1.1.1', - metric=50) - ipdict = dict(cidr='1.1.1.1/24', - broadcast='1.1.1.255', - scope='global', - ip_version=4, - dynamic=False) - with contextlib.nested( - mock.patch.object(ip_lib.IpAddrCommand, 'add'), - mock.patch.object(ip_lib.IpAddrCommand, 'delete') - ) as (add_fn, del_fn): - self.lbm.update_interface_ip_details("br0", "eth0", - [ipdict], None) - self.assertTrue(add_fn.called) - self.assertTrue(del_fn.called) - - with contextlib.nested( - mock.patch.object(ip_lib.IpRouteCommand, 'add_gateway'), - mock.patch.object(ip_lib.IpRouteCommand, 'delete_gateway') - ) as (addgw_fn, delgw_fn): - self.lbm.update_interface_ip_details("br0", "eth0", - None, gwdict) - self.assertTrue(addgw_fn.called) - self.assertTrue(delgw_fn.called) - - def test_bridge_exists_and_ensure_up(self): - ip_lib_mock = mock.Mock() - with mock.patch.object(ip_lib, 'IPDevice', return_value=ip_lib_mock): - # device exists - self.assertTrue(self.lbm._bridge_exists_and_ensure_up("br0")) - self.assertTrue(ip_lib_mock.link.set_up.called) - # device doesn't exists - ip_lib_mock.link.set_up.side_effect = RuntimeError - self.assertFalse(self.lbm._bridge_exists_and_ensure_up("br0")) - - def test_ensure_bridge(self): - with contextlib.nested( - mock.patch.object(self.lbm, '_bridge_exists_and_ensure_up'), - mock.patch.object(utils, 'execute'), - mock.patch.object(self.lbm, 'update_interface_ip_details'), - mock.patch.object(self.lbm, 'interface_exists_on_bridge'), - mock.patch.object(self.lbm, 'is_device_on_bridge'), - mock.patch.object(self.lbm, 'get_bridge_for_tap_device'), - ) as (de_fn, exec_fn, upd_fn, ie_fn, if_br_fn, get_if_br_fn): - de_fn.return_value = False - exec_fn.return_value = False - self.assertEqual(self.lbm.ensure_bridge("br0", None), "br0") - ie_fn.return_Value = False - self.lbm.ensure_bridge("br0", "eth0") - upd_fn.assert_called_with("br0", "eth0", None, None) - ie_fn.assert_called_with("br0", "eth0") - - self.lbm.ensure_bridge("br0", "eth0", "ips", "gateway") - upd_fn.assert_called_with("br0", "eth0", "ips", "gateway") - ie_fn.assert_called_with("br0", "eth0") - - exec_fn.side_effect = Exception() - de_fn.return_value = True - self.lbm.ensure_bridge("br0", "eth0") - ie_fn.assert_called_with("br0", "eth0") - - exec_fn.reset_mock() - exec_fn.side_effect = None - de_fn.return_value = True - ie_fn.return_value = False - get_if_br_fn.return_value = "br1" - self.lbm.ensure_bridge("br0", "eth0") - expected = [ - mock.call(['brctl', 'delif', 'br1', 'eth0'], - root_helper=self.root_helper), - mock.call(['brctl', 'addif', 'br0', 'eth0'], - root_helper=self.root_helper), - ] - exec_fn.assert_has_calls(expected) - - def test_ensure_physical_in_bridge(self): - self.assertFalse( - self.lbm.ensure_physical_in_bridge("123", p_const.TYPE_VLAN, - "phys", "1") - ) - with mock.patch.object(self.lbm, "ensure_flat_bridge") as flbr_fn: - self.assertTrue( - self.lbm.ensure_physical_in_bridge("123", p_const.TYPE_FLAT, - "physnet1", None) - ) - self.assertTrue(flbr_fn.called) - with mock.patch.object(self.lbm, "ensure_vlan_bridge") as vlbr_fn: - self.assertTrue( - self.lbm.ensure_physical_in_bridge("123", p_const.TYPE_VLAN, - "physnet1", "1") - ) - self.assertTrue(vlbr_fn.called) - - with mock.patch.object(self.lbm, "ensure_vxlan_bridge") as vlbr_fn: - self.lbm.vxlan_mode = lconst.VXLAN_MCAST - self.assertTrue( - self.lbm.ensure_physical_in_bridge("123", p_const.TYPE_VXLAN, - "physnet1", "1") - ) - self.assertTrue(vlbr_fn.called) - - def test_add_tap_interface(self): - with mock.patch.object(ip_lib, "device_exists") as de_fn: - de_fn.return_value = False - self.assertFalse( - self.lbm.add_tap_interface("123", p_const.TYPE_VLAN, - "physnet1", "1", "tap1") - ) - - de_fn.return_value = True - with contextlib.nested( - mock.patch.object(self.lbm, "ensure_local_bridge"), - mock.patch.object(utils, "execute"), - mock.patch.object(self.lbm, "get_bridge_for_tap_device") - ) as (en_fn, exec_fn, get_br): - exec_fn.return_value = False - get_br.return_value = True - self.assertTrue(self.lbm.add_tap_interface("123", - p_const.TYPE_LOCAL, - "physnet1", None, - "tap1")) - en_fn.assert_called_with("123") - - get_br.return_value = False - exec_fn.return_value = True - self.assertFalse(self.lbm.add_tap_interface("123", - p_const.TYPE_LOCAL, - "physnet1", None, - "tap1")) - - with mock.patch.object(self.lbm, - "ensure_physical_in_bridge") as ens_fn: - ens_fn.return_value = False - self.assertFalse(self.lbm.add_tap_interface("123", - p_const.TYPE_VLAN, - "physnet1", "1", - "tap1")) - - def test_add_interface(self): - with mock.patch.object(self.lbm, "add_tap_interface") as add_tap: - self.lbm.add_interface("123", p_const.TYPE_VLAN, "physnet-1", - "1", "234") - add_tap.assert_called_with("123", p_const.TYPE_VLAN, "physnet-1", - "1", "tap234") - - def test_delete_vlan_bridge(self): - with contextlib.nested( - mock.patch.object(ip_lib, "device_exists"), - mock.patch.object(self.lbm, "get_interfaces_on_bridge"), - mock.patch.object(self.lbm, "remove_interface"), - mock.patch.object(self.lbm, "get_interface_details"), - mock.patch.object(self.lbm, "update_interface_ip_details"), - mock.patch.object(self.lbm, "delete_vxlan"), - mock.patch.object(utils, "execute") - ) as (de_fn, getif_fn, remif_fn, if_det_fn, - updif_fn, del_vxlan, exec_fn): - de_fn.return_value = False - self.lbm.delete_vlan_bridge("br0") - self.assertFalse(getif_fn.called) - - de_fn.return_value = True - getif_fn.return_value = ["eth0", "eth1", "vxlan-1002"] - if_det_fn.return_value = ("ips", "gateway") - exec_fn.return_value = False - self.lbm.delete_vlan_bridge("br0") - updif_fn.assert_called_with("eth1", "br0", "ips", "gateway") - del_vxlan.assert_called_with("vxlan-1002") - - def test_delete_vlan_bridge_with_ip(self): - with contextlib.nested( - mock.patch.object(ip_lib, "device_exists"), - mock.patch.object(self.lbm, "get_interfaces_on_bridge"), - mock.patch.object(self.lbm, "remove_interface"), - mock.patch.object(self.lbm, "get_interface_details"), - mock.patch.object(self.lbm, "update_interface_ip_details"), - mock.patch.object(self.lbm, "delete_vlan"), - mock.patch.object(utils, "execute") - ) as (de_fn, getif_fn, remif_fn, if_det_fn, - updif_fn, del_vlan, exec_fn): - de_fn.return_value = True - getif_fn.return_value = ["eth0", "eth1.1"] - if_det_fn.return_value = ("ips", "gateway") - exec_fn.return_value = False - self.lbm.delete_vlan_bridge("br0") - updif_fn.assert_called_with("eth1.1", "br0", "ips", "gateway") - self.assertFalse(del_vlan.called) - - def test_delete_vlan_bridge_no_ip(self): - with contextlib.nested( - mock.patch.object(ip_lib, "device_exists"), - mock.patch.object(self.lbm, "get_interfaces_on_bridge"), - mock.patch.object(self.lbm, "remove_interface"), - mock.patch.object(self.lbm, "get_interface_details"), - mock.patch.object(self.lbm, "update_interface_ip_details"), - mock.patch.object(self.lbm, "delete_vlan"), - mock.patch.object(utils, "execute") - ) as (de_fn, getif_fn, remif_fn, if_det_fn, - updif_fn, del_vlan, exec_fn): - de_fn.return_value = True - getif_fn.return_value = ["eth0", "eth1.1"] - exec_fn.return_value = False - if_det_fn.return_value = ([], None) - self.lbm.delete_vlan_bridge("br0") - del_vlan.assert_called_with("eth1.1") - self.assertFalse(updif_fn.called) - - def test_delete_vxlan_bridge_no_int_mappings(self): - interface_mappings = {} - lbm = linuxbridge_neutron_agent.LinuxBridgeManager( - interface_mappings, self.root_helper) - - with contextlib.nested( - mock.patch.object(ip_lib, "device_exists"), - mock.patch.object(lbm, "get_interfaces_on_bridge"), - mock.patch.object(lbm, "remove_interface"), - mock.patch.object(lbm, "delete_vxlan"), - mock.patch.object(utils, "execute") - ) as (de_fn, getif_fn, remif_fn, del_vxlan, exec_fn): - de_fn.return_value = False - lbm.delete_vlan_bridge("br0") - self.assertFalse(getif_fn.called) - - de_fn.return_value = True - getif_fn.return_value = ["vxlan-1002"] - exec_fn.return_value = False - lbm.delete_vlan_bridge("br0") - del_vxlan.assert_called_with("vxlan-1002") - - def test_remove_empty_bridges(self): - self.lbm.network_map = {'net1': mock.Mock(), 'net2': mock.Mock()} - - def tap_count_side_effect(*args): - return 0 if args[0] == 'brqnet1' else 1 - - with contextlib.nested( - mock.patch.object(self.lbm, "delete_vlan_bridge"), - mock.patch.object(self.lbm, "get_tap_devices_count", - side_effect=tap_count_side_effect), - ) as (del_br_fn, count_tap_fn): - self.lbm.remove_empty_bridges() - del_br_fn.assert_called_once_with('brqnet1') - - def test_remove_interface(self): - with contextlib.nested( - mock.patch.object(ip_lib, "device_exists"), - mock.patch.object(self.lbm, "is_device_on_bridge"), - mock.patch.object(utils, "execute") - ) as (de_fn, isdev_fn, exec_fn): - de_fn.return_value = False - self.assertFalse(self.lbm.remove_interface("br0", "eth0")) - self.assertFalse(isdev_fn.called) - - de_fn.return_value = True - isdev_fn.return_value = False - self.assertTrue(self.lbm.remove_interface("br0", "eth0")) - - isdev_fn.return_value = True - exec_fn.return_value = True - self.assertFalse(self.lbm.remove_interface("br0", "eth0")) - - exec_fn.return_value = False - self.assertTrue(self.lbm.remove_interface("br0", "eth0")) - - def test_delete_vlan(self): - with contextlib.nested( - mock.patch.object(ip_lib, "device_exists"), - mock.patch.object(utils, "execute") - ) as (de_fn, exec_fn): - de_fn.return_value = False - self.lbm.delete_vlan("eth1.1") - self.assertFalse(exec_fn.called) - - de_fn.return_value = True - exec_fn.return_value = False - self.lbm.delete_vlan("eth1.1") - self.assertTrue(exec_fn.called) - - def _check_vxlan_support(self, expected, vxlan_module_supported, - vxlan_ucast_supported, vxlan_mcast_supported): - with contextlib.nested( - mock.patch.object(self.lbm, 'vxlan_module_supported', - return_value=vxlan_module_supported), - mock.patch.object(self.lbm, 'vxlan_ucast_supported', - return_value=vxlan_ucast_supported), - mock.patch.object(self.lbm, 'vxlan_mcast_supported', - return_value=vxlan_mcast_supported)): - if expected == lconst.VXLAN_NONE: - self.assertRaises(exceptions.VxlanNetworkUnsupported, - self.lbm.check_vxlan_support) - self.assertEqual(expected, self.lbm.vxlan_mode) - else: - self.lbm.check_vxlan_support() - self.assertEqual(expected, self.lbm.vxlan_mode) - - def test_check_vxlan_support(self): - self._check_vxlan_support(expected=lconst.VXLAN_UCAST, - vxlan_module_supported=True, - vxlan_ucast_supported=True, - vxlan_mcast_supported=True) - self._check_vxlan_support(expected=lconst.VXLAN_MCAST, - vxlan_module_supported=True, - vxlan_ucast_supported=False, - vxlan_mcast_supported=True) - - self._check_vxlan_support(expected=lconst.VXLAN_NONE, - vxlan_module_supported=False, - vxlan_ucast_supported=False, - vxlan_mcast_supported=False) - self._check_vxlan_support(expected=lconst.VXLAN_NONE, - vxlan_module_supported=True, - vxlan_ucast_supported=False, - vxlan_mcast_supported=False) - - def _check_vxlan_module_supported(self, expected, execute_side_effect): - with mock.patch.object( - utils, 'execute', - side_effect=execute_side_effect): - self.assertEqual(expected, self.lbm.vxlan_module_supported()) - - def test_vxlan_module_supported(self): - self._check_vxlan_module_supported( - expected=True, - execute_side_effect=None) - self._check_vxlan_module_supported( - expected=False, - execute_side_effect=RuntimeError()) - - def _check_vxlan_ucast_supported( - self, expected, l2_population, iproute_arg_supported, fdb_append): - cfg.CONF.set_override('l2_population', l2_population, 'VXLAN') - with contextlib.nested( - mock.patch.object( - ip_lib, 'device_exists', return_value=False), - mock.patch.object(self.lbm, 'delete_vxlan', return_value=None), - mock.patch.object(self.lbm, 'ensure_vxlan', return_value=None), - mock.patch.object( - utils, 'execute', - side_effect=None if fdb_append else RuntimeError()), - mock.patch.object( - ip_lib, 'iproute_arg_supported', - return_value=iproute_arg_supported)): - self.assertEqual(expected, self.lbm.vxlan_ucast_supported()) - - def test_vxlan_ucast_supported(self): - self._check_vxlan_ucast_supported( - expected=False, - l2_population=False, iproute_arg_supported=True, fdb_append=True) - self._check_vxlan_ucast_supported( - expected=False, - l2_population=True, iproute_arg_supported=False, fdb_append=True) - self._check_vxlan_ucast_supported( - expected=False, - l2_population=True, iproute_arg_supported=True, fdb_append=False) - self._check_vxlan_ucast_supported( - expected=True, - l2_population=True, iproute_arg_supported=True, fdb_append=True) - - def _check_vxlan_mcast_supported( - self, expected, vxlan_group, iproute_arg_supported): - cfg.CONF.set_override('vxlan_group', vxlan_group, 'VXLAN') - with mock.patch.object( - ip_lib, 'iproute_arg_supported', - return_value=iproute_arg_supported): - self.assertEqual(expected, self.lbm.vxlan_mcast_supported()) - - def test_vxlan_mcast_supported(self): - self._check_vxlan_mcast_supported( - expected=False, - vxlan_group='', - iproute_arg_supported=True) - self._check_vxlan_mcast_supported( - expected=False, - vxlan_group='224.0.0.1', - iproute_arg_supported=False) - self._check_vxlan_mcast_supported( - expected=True, - vxlan_group='224.0.0.1', - iproute_arg_supported=True) - - -class TestLinuxBridgeRpcCallbacks(base.BaseTestCase): - def setUp(self): - cfg.CONF.set_override('local_ip', LOCAL_IP, 'VXLAN') - super(TestLinuxBridgeRpcCallbacks, self).setUp() - - self.u_execute_p = mock.patch('neutron.agent.linux.utils.execute') - self.u_execute = self.u_execute_p.start() - - class FakeLBAgent(object): - def __init__(self): - self.agent_id = 1 - self.br_mgr = (linuxbridge_neutron_agent. - LinuxBridgeManager({'physnet1': 'eth1'}, - cfg.CONF.AGENT.root_helper)) - - self.br_mgr.vxlan_mode = lconst.VXLAN_UCAST - segment = mock.Mock() - segment.network_type = 'vxlan' - segment.segmentation_id = 1 - self.br_mgr.network_map['net_id'] = segment - - self.lb_rpc = linuxbridge_neutron_agent.LinuxBridgeRpcCallbacks( - object(), - FakeLBAgent() - ) - - self.root_helper = cfg.CONF.AGENT.root_helper - - def test_network_delete(self): - with contextlib.nested( - mock.patch.object(self.lb_rpc.agent.br_mgr, "get_bridge_name"), - mock.patch.object(self.lb_rpc.agent.br_mgr, "delete_vlan_bridge") - ) as (get_br_fn, del_fn): - get_br_fn.return_value = "br0" - self.lb_rpc.network_delete("anycontext", network_id="123") - get_br_fn.assert_called_with("123") - del_fn.assert_called_with("br0") - - def test_fdb_add(self): - fdb_entries = {'net_id': - {'ports': - {'agent_ip': [constants.FLOODING_ENTRY, - ['port_mac', 'port_ip']]}, - 'network_type': 'vxlan', - 'segment_id': 1}} - - with mock.patch.object(utils, 'execute', - return_value='') as execute_fn: - self.lb_rpc.fdb_add(None, fdb_entries) - - expected = [ - mock.call(['bridge', 'fdb', 'show', 'dev', 'vxlan-1'], - root_helper=self.root_helper), - mock.call(['bridge', 'fdb', 'add', - constants.FLOODING_ENTRY[0], - 'dev', 'vxlan-1', 'dst', 'agent_ip'], - root_helper=self.root_helper, - check_exit_code=False), - mock.call(['ip', 'neigh', 'replace', 'port_ip', 'lladdr', - 'port_mac', 'dev', 'vxlan-1', 'nud', 'permanent'], - root_helper=self.root_helper, - check_exit_code=False), - mock.call(['bridge', 'fdb', 'add', 'port_mac', 'dev', - 'vxlan-1', 'dst', 'agent_ip'], - root_helper=self.root_helper, - check_exit_code=False), - ] - execute_fn.assert_has_calls(expected) - - def test_fdb_ignore(self): - fdb_entries = {'net_id': - {'ports': - {LOCAL_IP: [constants.FLOODING_ENTRY, - ['port_mac', 'port_ip']]}, - 'network_type': 'vxlan', - 'segment_id': 1}} - - with mock.patch.object(utils, 'execute', - return_value='') as execute_fn: - self.lb_rpc.fdb_add(None, fdb_entries) - self.lb_rpc.fdb_remove(None, fdb_entries) - - self.assertFalse(execute_fn.called) - - fdb_entries = {'other_net_id': - {'ports': - {'192.168.0.67': [constants.FLOODING_ENTRY, - ['port_mac', 'port_ip']]}, - 'network_type': 'vxlan', - 'segment_id': 1}} - - with mock.patch.object(utils, 'execute', - return_value='') as execute_fn: - self.lb_rpc.fdb_add(None, fdb_entries) - self.lb_rpc.fdb_remove(None, fdb_entries) - - self.assertFalse(execute_fn.called) - - def test_fdb_remove(self): - fdb_entries = {'net_id': - {'ports': - {'agent_ip': [constants.FLOODING_ENTRY, - ['port_mac', 'port_ip']]}, - 'network_type': 'vxlan', - 'segment_id': 1}} - - with mock.patch.object(utils, 'execute', - return_value='') as execute_fn: - self.lb_rpc.fdb_remove(None, fdb_entries) - - expected = [ - mock.call(['bridge', 'fdb', 'del', - constants.FLOODING_ENTRY[0], - 'dev', 'vxlan-1', 'dst', 'agent_ip'], - root_helper=self.root_helper, - check_exit_code=False), - mock.call(['ip', 'neigh', 'del', 'port_ip', 'lladdr', - 'port_mac', 'dev', 'vxlan-1'], - root_helper=self.root_helper, - check_exit_code=False), - mock.call(['bridge', 'fdb', 'del', 'port_mac', - 'dev', 'vxlan-1', 'dst', 'agent_ip'], - root_helper=self.root_helper, - check_exit_code=False), - ] - execute_fn.assert_has_calls(expected) - - def test_fdb_update_chg_ip(self): - fdb_entries = {'chg_ip': - {'net_id': - {'agent_ip': - {'before': [['port_mac', 'port_ip_1']], - 'after': [['port_mac', 'port_ip_2']]}}}} - - with mock.patch.object(utils, 'execute', - return_value='') as execute_fn: - self.lb_rpc.fdb_update(None, fdb_entries) - - expected = [ - mock.call(['ip', 'neigh', 'replace', 'port_ip_2', 'lladdr', - 'port_mac', 'dev', 'vxlan-1', 'nud', 'permanent'], - root_helper=self.root_helper, - check_exit_code=False), - mock.call(['ip', 'neigh', 'del', 'port_ip_1', 'lladdr', - 'port_mac', 'dev', 'vxlan-1'], - root_helper=self.root_helper, - check_exit_code=False) - ] - execute_fn.assert_has_calls(expected) diff --git a/neutron/tests/unit/linuxbridge/test_lb_security_group.py b/neutron/tests/unit/linuxbridge/test_lb_security_group.py deleted file mode 100644 index 62662036a..000000000 --- a/neutron/tests/unit/linuxbridge/test_lb_security_group.py +++ /dev/null @@ -1,99 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2012, Nachi Ueno, NTT MCL, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock - -from neutron.api.v2 import attributes -from neutron.extensions import securitygroup as ext_sg -from neutron.plugins.linuxbridge.db import l2network_db_v2 as lb_db -from neutron.tests.unit import test_extension_security_group as test_sg -from neutron.tests.unit import test_security_groups_rpc as test_sg_rpc - - -PLUGIN_NAME = ('neutron.plugins.linuxbridge.' - 'lb_neutron_plugin.LinuxBridgePluginV2') -NOTIFIER = ('neutron.plugins.linuxbridge.' - 'lb_neutron_plugin.AgentNotifierApi') - - -class LinuxBridgeSecurityGroupsTestCase(test_sg.SecurityGroupDBTestCase): - _plugin_name = PLUGIN_NAME - - def setUp(self, plugin=None): - test_sg_rpc.set_firewall_driver(test_sg_rpc.FIREWALL_IPTABLES_DRIVER) - notifier_p = mock.patch(NOTIFIER) - notifier_cls = notifier_p.start() - self.notifier = mock.Mock() - notifier_cls.return_value = self.notifier - self._attribute_map_bk_ = {} - for item in attributes.RESOURCE_ATTRIBUTE_MAP: - self._attribute_map_bk_[item] = (attributes. - RESOURCE_ATTRIBUTE_MAP[item]. - copy()) - super(LinuxBridgeSecurityGroupsTestCase, self).setUp(PLUGIN_NAME) - - def tearDown(self): - attributes.RESOURCE_ATTRIBUTE_MAP = self._attribute_map_bk_ - super(LinuxBridgeSecurityGroupsTestCase, self).tearDown() - - -class TestLinuxBridgeSecurityGroups(LinuxBridgeSecurityGroupsTestCase, - test_sg.TestSecurityGroups, - test_sg_rpc.SGNotificationTestMixin): - pass - - -class TestLinuxBridgeSecurityGroupsXML(TestLinuxBridgeSecurityGroups): - fmt = 'xml' - - -class TestLinuxBridgeSecurityGroupsDB(LinuxBridgeSecurityGroupsTestCase): - def test_security_group_get_port_from_device(self): - with self.network() as n: - with self.subnet(n): - with self.security_group() as sg: - security_group_id = sg['security_group']['id'] - res = self._create_port(self.fmt, n['network']['id']) - port = self.deserialize(self.fmt, res) - fixed_ips = port['port']['fixed_ips'] - data = {'port': {'fixed_ips': fixed_ips, - 'name': port['port']['name'], - ext_sg.SECURITYGROUPS: - [security_group_id]}} - - req = self.new_update_request('ports', data, - port['port']['id']) - res = self.deserialize(self.fmt, - req.get_response(self.api)) - port_id = res['port']['id'] - device_id = port_id[:8] - port_dict = lb_db.get_port_from_device(device_id) - self.assertEqual(port_id, port_dict['id']) - self.assertEqual([security_group_id], - port_dict[ext_sg.SECURITYGROUPS]) - self.assertEqual([], port_dict['security_group_rules']) - self.assertEqual([fixed_ips[0]['ip_address']], - port_dict['fixed_ips']) - self._delete('ports', port['port']['id']) - - def test_security_group_get_port_from_device_with_no_port(self): - port_dict = lb_db.get_port_from_device('bad_device_id') - self.assertIsNone(port_dict) - - -class TestLinuxBridgeSecurityGroupsDBXML(TestLinuxBridgeSecurityGroupsDB): - fmt = 'xml' diff --git a/neutron/tests/unit/linuxbridge/test_linuxbridge_plugin.py b/neutron/tests/unit/linuxbridge/test_linuxbridge_plugin.py deleted file mode 100644 index 3ff0f7592..000000000 --- a/neutron/tests/unit/linuxbridge/test_linuxbridge_plugin.py +++ /dev/null @@ -1,132 +0,0 @@ -# Copyright (c) 2012 OpenStack Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import contextlib - -import mock -from oslo.config import cfg - -from neutron.common import constants as q_const -from neutron.extensions import portbindings -from neutron import manager -from neutron.plugins.linuxbridge import lb_neutron_plugin -from neutron.tests.unit import _test_extension_portbindings as test_bindings -from neutron.tests.unit import test_db_plugin as test_plugin -from neutron.tests.unit import test_security_groups_rpc as test_sg_rpc - -PLUGIN_NAME = ('neutron.plugins.linuxbridge.' - 'lb_neutron_plugin.LinuxBridgePluginV2') - - -class LinuxBridgePluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase): - _plugin_name = PLUGIN_NAME - - def setUp(self): - super(LinuxBridgePluginV2TestCase, self).setUp(PLUGIN_NAME) - self.port_create_status = 'DOWN' - - -class TestLinuxBridgeBasicGet(test_plugin.TestBasicGet, - LinuxBridgePluginV2TestCase): - pass - - -class TestLinuxBridgeV2HTTPResponse(test_plugin.TestV2HTTPResponse, - LinuxBridgePluginV2TestCase): - pass - - -class TestLinuxBridgeNetworksV2(test_plugin.TestNetworksV2, - LinuxBridgePluginV2TestCase): - pass - - -class TestLinuxBridgePortsV2(test_plugin.TestPortsV2, - LinuxBridgePluginV2TestCase): - - def test_update_port_status_build(self): - with self.port() as port: - self.assertEqual(port['port']['status'], 'DOWN') - self.assertEqual(self.port_create_status, 'DOWN') - - -class TestLinuxBridgePortBinding(LinuxBridgePluginV2TestCase, - test_bindings.PortBindingsTestCase): - VIF_TYPE = portbindings.VIF_TYPE_BRIDGE - HAS_PORT_FILTER = True - ENABLE_SG = True - FIREWALL_DRIVER = test_sg_rpc.FIREWALL_IPTABLES_DRIVER - - def setUp(self): - test_sg_rpc.set_firewall_driver(self.FIREWALL_DRIVER) - cfg.CONF.set_override( - 'enable_security_group', self.ENABLE_SG, - group='SECURITYGROUP') - super(TestLinuxBridgePortBinding, self).setUp() - - -class TestLinuxBridgePortBindingNoSG(TestLinuxBridgePortBinding): - HAS_PORT_FILTER = False - ENABLE_SG = False - FIREWALL_DRIVER = test_sg_rpc.FIREWALL_NOOP_DRIVER - - -class TestLinuxBridgePortBindingHost( - LinuxBridgePluginV2TestCase, - test_bindings.PortBindingsHostTestCaseMixin): - pass - - -class TestLinuxBridgePluginRpcCallbacks(test_plugin.NeutronDbPluginV2TestCase): - def setUp(self): - super(TestLinuxBridgePluginRpcCallbacks, self).setUp(PLUGIN_NAME) - self.callbacks = lb_neutron_plugin.LinuxBridgeRpcCallbacks() - - def test_update_device_down(self): - with contextlib.nested( - mock.patch.object(self.callbacks, "get_port_from_device", - return_value=None), - mock.patch.object(manager.NeutronManager, "get_plugin") - ) as (gpfd, gp): - self.assertEqual( - self.callbacks.update_device_down("fake_context", - agent_id="123", - device="device", - host="host"), - {'device': 'device', 'exists': False} - ) - gpfd.return_value = {'id': 'fakeid', - 'status': q_const.PORT_STATUS_ACTIVE} - self.assertEqual( - self.callbacks.update_device_down("fake_context", - agent_id="123", - device="device", - host="host"), - {'device': 'device', 'exists': True} - ) - - def test_update_device_up(self): - with contextlib.nested( - mock.patch.object(self.callbacks, "get_port_from_device", - return_value=None), - mock.patch.object(manager.NeutronManager, "get_plugin") - ) as (gpfd, gp): - gpfd.return_value = {'id': 'fakeid', - 'status': q_const.PORT_STATUS_ACTIVE} - self.callbacks.update_device_up("fake_context", - agent_id="123", - device="device", - host="host") - gpfd.assert_called_once_with('device') diff --git a/neutron/tests/unit/linuxbridge/test_rpcapi.py b/neutron/tests/unit/linuxbridge/test_rpcapi.py deleted file mode 100644 index 616a06acd..000000000 --- a/neutron/tests/unit/linuxbridge/test_rpcapi.py +++ /dev/null @@ -1,132 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2012, Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -Unit Tests for linuxbridge rpc -""" - -import fixtures -from oslo.config import cfg - -from neutron.agent import rpc as agent_rpc -from neutron.common import topics -from neutron.openstack.common import context -from neutron.plugins.linuxbridge import lb_neutron_plugin as plb -from neutron.tests import base - - -class rpcApiTestCase(base.BaseTestCase): - def _test_lb_api(self, rpcapi, topic, method, rpc_method, - expected_msg=None, **kwargs): - ctxt = context.RequestContext('fake_user', 'fake_project') - expected_retval = 'foo' if method == 'call' else None - if not expected_msg: - expected_msg = rpcapi.make_msg(method, **kwargs) - if rpc_method == 'cast' and method == 'run_instance': - kwargs['call'] = False - - self.fake_args = None - self.fake_kwargs = None - - def _fake_rpc_method(*args, **kwargs): - self.fake_args = args - self.fake_kwargs = kwargs - if expected_retval: - return expected_retval - - self.useFixture(fixtures.MonkeyPatch( - 'neutron.common.rpc_compat.RpcProxy.' + rpc_method, - _fake_rpc_method)) - - retval = getattr(rpcapi, method)(ctxt, **kwargs) - - self.assertEqual(expected_retval, retval) - expected_args = [ctxt, expected_msg] - expected_kwargs = {'topic': topic} - - # skip the first argument which is 'self' - for arg, expected_arg in zip(self.fake_args[1:], expected_args): - self.assertEqual(expected_arg, arg) - self.assertEqual(expected_kwargs, self.fake_kwargs) - - def test_delete_network(self): - rpcapi = plb.AgentNotifierApi(topics.AGENT) - self._test_lb_api(rpcapi, - topics.get_topic_name(topics.AGENT, - topics.NETWORK, - topics.DELETE), - 'network_delete', rpc_method='fanout_cast', - network_id='fake_request_spec') - - def test_port_update(self): - cfg.CONF.set_override('rpc_support_old_agents', False, 'AGENT') - rpcapi = plb.AgentNotifierApi(topics.AGENT) - expected_msg = rpcapi.make_msg('port_update', - port='fake_port', - network_type='vlan', - physical_network='fake_net', - segmentation_id='fake_vlan_id') - self._test_lb_api(rpcapi, - topics.get_topic_name(topics.AGENT, - topics.PORT, - topics.UPDATE), - 'port_update', rpc_method='fanout_cast', - expected_msg=expected_msg, - port='fake_port', - physical_network='fake_net', - vlan_id='fake_vlan_id') - - def test_port_update_old_agent(self): - cfg.CONF.set_override('rpc_support_old_agents', True, 'AGENT') - rpcapi = plb.AgentNotifierApi(topics.AGENT) - expected_msg = rpcapi.make_msg('port_update', - port='fake_port', - network_type='vlan', - physical_network='fake_net', - segmentation_id='fake_vlan_id', - vlan_id='fake_vlan_id') - self._test_lb_api(rpcapi, - topics.get_topic_name(topics.AGENT, - topics.PORT, - topics.UPDATE), - 'port_update', rpc_method='fanout_cast', - expected_msg=expected_msg, - port='fake_port', - physical_network='fake_net', - vlan_id='fake_vlan_id') - - def test_device_details(self): - rpcapi = agent_rpc.PluginApi(topics.PLUGIN) - self._test_lb_api(rpcapi, topics.PLUGIN, - 'get_device_details', rpc_method='call', - device='fake_device', - agent_id='fake_agent_id') - - def test_update_device_down(self): - rpcapi = agent_rpc.PluginApi(topics.PLUGIN) - self._test_lb_api(rpcapi, topics.PLUGIN, - 'update_device_down', rpc_method='call', - device='fake_device', - agent_id='fake_agent_id', - host='fake_host') - - def test_update_device_up(self): - rpcapi = agent_rpc.PluginApi(topics.PLUGIN) - self._test_lb_api(rpcapi, topics.PLUGIN, - 'update_device_up', rpc_method='call', - device='fake_device', - agent_id='fake_agent_id', - host='fake_host') diff --git a/neutron/tests/unit/metaplugin/__init__.py b/neutron/tests/unit/metaplugin/__init__.py deleted file mode 100644 index d8bce7745..000000000 --- a/neutron/tests/unit/metaplugin/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2012, Nachi Ueno, NTT MCL, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. diff --git a/neutron/tests/unit/metaplugin/fake_plugin.py b/neutron/tests/unit/metaplugin/fake_plugin.py deleted file mode 100644 index 1430697f3..000000000 --- a/neutron/tests/unit/metaplugin/fake_plugin.py +++ /dev/null @@ -1,79 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright 2012, Nachi Ueno, NTT MCL, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.db import db_base_plugin_v2 -from neutron.db import external_net_db -from neutron.db import l3_gwmode_db - - -class Fake1(db_base_plugin_v2.NeutronDbPluginV2, - external_net_db.External_net_db_mixin, - l3_gwmode_db.L3_NAT_db_mixin): - supported_extension_aliases = ['external-net', 'router'] - - def fake_func(self): - return 'fake1' - - def create_network(self, context, network): - session = context.session - with session.begin(subtransactions=True): - net = super(Fake1, self).create_network(context, network) - self._process_l3_create(context, net, network['network']) - return net - - def update_network(self, context, id, network): - session = context.session - with session.begin(subtransactions=True): - net = super(Fake1, self).update_network(context, id, - network) - self._process_l3_update(context, net, network['network']) - return net - - def delete_network(self, context, id): - session = context.session - with session.begin(subtransactions=True): - self._process_l3_delete(context, id) - return super(Fake1, self).delete_network(context, id) - - def create_port(self, context, port): - port = super(Fake1, self).create_port(context, port) - return port - - def create_subnet(self, context, subnet): - subnet = super(Fake1, self).create_subnet(context, subnet) - return subnet - - def update_port(self, context, id, port): - port = super(Fake1, self).update_port(context, id, port) - return port - - def delete_port(self, context, id, l3_port_check=True): - if l3_port_check: - self.prevent_l3_port_deletion(context, id) - self.disassociate_floatingips(context, id) - return super(Fake1, self).delete_port(context, id) - - -class Fake2(Fake1): - def fake_func(self): - return 'fake2' - - def fake_func2(self): - return 'fake2' - - def start_rpc_listeners(self): - # return value is only used to confirm this method was called. - return 'OK' diff --git a/neutron/tests/unit/metaplugin/test_basic.py b/neutron/tests/unit/metaplugin/test_basic.py deleted file mode 100644 index 5f2046957..000000000 --- a/neutron/tests/unit/metaplugin/test_basic.py +++ /dev/null @@ -1,78 +0,0 @@ -# Copyright (c) 2012 OpenStack Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from neutron.tests.unit.metaplugin import test_metaplugin -from neutron.tests.unit import test_db_plugin as test_plugin -from neutron.tests.unit import test_l3_plugin - - -class MetaPluginV2DBTestCase(test_plugin.NeutronDbPluginV2TestCase): - - _plugin_name = ('neutron.plugins.metaplugin.' - 'meta_neutron_plugin.MetaPluginV2') - - def setUp(self, plugin=None, ext_mgr=None, - service_plugins=None): - # NOTE(salv-orlando): The plugin keyword argument is ignored, - # as this class will always invoke super with self._plugin_name. - # These keyword parameters ensure setUp methods always have the - # same signature. - test_metaplugin.setup_metaplugin_conf() - ext_mgr = ext_mgr or test_l3_plugin.L3TestExtensionManager() - self.addCleanup(test_metaplugin.unregister_meta_hooks) - super(MetaPluginV2DBTestCase, self).setUp( - plugin=self._plugin_name, ext_mgr=ext_mgr, - service_plugins=service_plugins) - - -class TestMetaBasicGet(test_plugin.TestBasicGet, - MetaPluginV2DBTestCase): - pass - - -class TestMetaV2HTTPResponse(test_plugin.TestV2HTTPResponse, - MetaPluginV2DBTestCase): - pass - - -class TestMetaPortsV2(test_plugin.TestPortsV2, - MetaPluginV2DBTestCase): - pass - - -class TestMetaNetworksV2(test_plugin.TestNetworksV2, - MetaPluginV2DBTestCase): - pass - - -class TestMetaSubnetsV2(test_plugin.TestSubnetsV2, - MetaPluginV2DBTestCase): - #TODO(nati) This test fails if we run all test, but It success just one - def test_update_subnet_route(self): - pass - - def test_update_subnet_dns_to_None(self): - pass - - def test_update_subnet_route_to_None(self): - pass - - def test_update_subnet_dns(self): - pass - - -class TestMetaL3NatDBTestCase(test_l3_plugin.L3NatDBIntTestCase, - MetaPluginV2DBTestCase): - pass diff --git a/neutron/tests/unit/metaplugin/test_metaplugin.py b/neutron/tests/unit/metaplugin/test_metaplugin.py deleted file mode 100644 index 7dc621978..000000000 --- a/neutron/tests/unit/metaplugin/test_metaplugin.py +++ /dev/null @@ -1,404 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2012, Nachi Ueno, NTT MCL, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -from oslo.config import cfg -import testtools - -from neutron.common import exceptions as exc -from neutron.common import topics -from neutron import context -from neutron.db import api as db -from neutron.db import db_base_plugin_v2 -from neutron.db import models_v2 -from neutron.extensions import flavor as ext_flavor -from neutron.openstack.common import uuidutils -from neutron.plugins.metaplugin import meta_neutron_plugin -from neutron.tests import base - -CONF_FILE = "" -META_PATH = "neutron.plugins.metaplugin" -FAKE_PATH = "neutron.tests.unit.metaplugin" -PROXY_PATH = "%s.proxy_neutron_plugin.ProxyPluginV2" % META_PATH -PLUGIN_LIST = """ -fake1:%s.fake_plugin.Fake1,fake2:%s.fake_plugin.Fake2,proxy:%s -""".strip() % (FAKE_PATH, FAKE_PATH, PROXY_PATH) -L3_PLUGIN_LIST = """ -fake1:%s.fake_plugin.Fake1,fake2:%s.fake_plugin.Fake2 -""".strip() % (FAKE_PATH, FAKE_PATH) - - -def setup_metaplugin_conf(has_l3=True): - cfg.CONF.set_override('auth_url', 'http://localhost:35357/v2.0', - 'PROXY') - cfg.CONF.set_override('auth_region', 'RegionOne', 'PROXY') - cfg.CONF.set_override('admin_user', 'neutron', 'PROXY') - cfg.CONF.set_override('admin_password', 'password', 'PROXY') - cfg.CONF.set_override('admin_tenant_name', 'service', 'PROXY') - cfg.CONF.set_override('plugin_list', PLUGIN_LIST, 'META') - if has_l3: - cfg.CONF.set_override('l3_plugin_list', L3_PLUGIN_LIST, 'META') - else: - cfg.CONF.set_override('l3_plugin_list', "", 'META') - cfg.CONF.set_override('default_flavor', 'fake2', 'META') - cfg.CONF.set_override('default_l3_flavor', 'fake1', 'META') - cfg.CONF.set_override('base_mac', "12:34:56:78:90:ab") - #TODO(nati) remove this after subnet quota change is merged - cfg.CONF.set_override('max_dns_nameservers', 10) - cfg.CONF.set_override('rpc_backend', - 'neutron.openstack.common.rpc.impl_fake') - - -# Hooks registered by metaplugin must not exist for other plugins UT. -# So hooks must be unregistered (overwrite to None in fact). -def unregister_meta_hooks(): - db_base_plugin_v2.NeutronDbPluginV2.register_model_query_hook( - models_v2.Network, 'metaplugin_net', None, None, None) - db_base_plugin_v2.NeutronDbPluginV2.register_model_query_hook( - models_v2.Port, 'metaplugin_port', None, None, None) - - -class MetaNeutronPluginV2Test(base.BaseTestCase): - """Class conisting of MetaNeutronPluginV2 unit tests.""" - - has_l3 = True - - def setUp(self): - super(MetaNeutronPluginV2Test, self).setUp() - db._ENGINE = None - db._MAKER = None - self.fake_tenant_id = uuidutils.generate_uuid() - self.context = context.get_admin_context() - - db.configure_db() - self.addCleanup(db.clear_db) - self.addCleanup(unregister_meta_hooks) - - setup_metaplugin_conf(self.has_l3) - - self.client_cls_p = mock.patch('neutronclient.v2_0.client.Client') - client_cls = self.client_cls_p.start() - self.client_inst = mock.Mock() - client_cls.return_value = self.client_inst - self.client_inst.create_network.return_value = \ - {'id': 'fake_id'} - self.client_inst.create_port.return_value = \ - {'id': 'fake_id'} - self.client_inst.create_subnet.return_value = \ - {'id': 'fake_id'} - self.client_inst.update_network.return_value = \ - {'id': 'fake_id'} - self.client_inst.update_port.return_value = \ - {'id': 'fake_id'} - self.client_inst.update_subnet.return_value = \ - {'id': 'fake_id'} - self.client_inst.delete_network.return_value = True - self.client_inst.delete_port.return_value = True - self.client_inst.delete_subnet.return_value = True - plugin = (meta_neutron_plugin.MetaPluginV2.__module__ + '.' - + meta_neutron_plugin.MetaPluginV2.__name__) - self.setup_coreplugin(plugin) - self.plugin = meta_neutron_plugin.MetaPluginV2(configfile=None) - - def _fake_network(self, flavor): - data = {'network': {'name': flavor, - 'admin_state_up': True, - 'shared': False, - 'router:external': [], - 'tenant_id': self.fake_tenant_id, - ext_flavor.FLAVOR_NETWORK: flavor}} - return data - - def _fake_port(self, net_id): - return {'port': {'name': net_id, - 'network_id': net_id, - 'admin_state_up': True, - 'device_id': 'bad_device_id', - 'device_owner': 'bad_device_owner', - 'admin_state_up': True, - 'host_routes': [], - 'fixed_ips': [], - 'mac_address': - self.plugin._generate_mac(self.context, net_id), - 'tenant_id': self.fake_tenant_id}} - - def _fake_subnet(self, net_id): - allocation_pools = [{'start': '10.0.0.2', - 'end': '10.0.0.254'}] - return {'subnet': {'name': net_id, - 'network_id': net_id, - 'gateway_ip': '10.0.0.1', - 'dns_nameservers': ['10.0.0.2'], - 'host_routes': [], - 'cidr': '10.0.0.0/24', - 'allocation_pools': allocation_pools, - 'enable_dhcp': True, - 'ip_version': 4}} - - def _fake_router(self, flavor): - data = {'router': {'name': flavor, 'admin_state_up': True, - 'tenant_id': self.fake_tenant_id, - ext_flavor.FLAVOR_ROUTER: flavor, - 'external_gateway_info': None}} - return data - - def test_create_delete_network(self): - network1 = self._fake_network('fake1') - ret1 = self.plugin.create_network(self.context, network1) - self.assertEqual('fake1', ret1[ext_flavor.FLAVOR_NETWORK]) - - network2 = self._fake_network('fake2') - ret2 = self.plugin.create_network(self.context, network2) - self.assertEqual('fake2', ret2[ext_flavor.FLAVOR_NETWORK]) - - network3 = self._fake_network('proxy') - ret3 = self.plugin.create_network(self.context, network3) - self.assertEqual('proxy', ret3[ext_flavor.FLAVOR_NETWORK]) - - db_ret1 = self.plugin.get_network(self.context, ret1['id']) - self.assertEqual('fake1', db_ret1['name']) - - db_ret2 = self.plugin.get_network(self.context, ret2['id']) - self.assertEqual('fake2', db_ret2['name']) - - db_ret3 = self.plugin.get_network(self.context, ret3['id']) - self.assertEqual('proxy', db_ret3['name']) - - db_ret4 = self.plugin.get_networks(self.context) - self.assertEqual(3, len(db_ret4)) - - db_ret5 = self.plugin.get_networks( - self.context, - {ext_flavor.FLAVOR_NETWORK: ['fake1']}) - self.assertEqual(1, len(db_ret5)) - self.assertEqual('fake1', db_ret5[0]['name']) - self.plugin.delete_network(self.context, ret1['id']) - self.plugin.delete_network(self.context, ret2['id']) - self.plugin.delete_network(self.context, ret3['id']) - - def test_create_delete_port(self): - network1 = self._fake_network('fake1') - network_ret1 = self.plugin.create_network(self.context, network1) - network2 = self._fake_network('fake2') - network_ret2 = self.plugin.create_network(self.context, network2) - network3 = self._fake_network('proxy') - network_ret3 = self.plugin.create_network(self.context, network3) - - port1 = self._fake_port(network_ret1['id']) - port2 = self._fake_port(network_ret2['id']) - port3 = self._fake_port(network_ret3['id']) - - port1_ret = self.plugin.create_port(self.context, port1) - port2_ret = self.plugin.create_port(self.context, port2) - port3_ret = self.plugin.create_port(self.context, port3) - ports_all = self.plugin.get_ports(self.context) - - self.assertEqual(network_ret1['id'], port1_ret['network_id']) - self.assertEqual(network_ret2['id'], port2_ret['network_id']) - self.assertEqual(network_ret3['id'], port3_ret['network_id']) - self.assertEqual(3, len(ports_all)) - - port1_dict = self.plugin._make_port_dict(port1_ret) - port2_dict = self.plugin._make_port_dict(port2_ret) - port3_dict = self.plugin._make_port_dict(port3_ret) - - self.assertEqual(port1_dict, port1_ret) - self.assertEqual(port2_dict, port2_ret) - self.assertEqual(port3_dict, port3_ret) - - port1['port']['admin_state_up'] = False - port2['port']['admin_state_up'] = False - port3['port']['admin_state_up'] = False - self.plugin.update_port(self.context, port1_ret['id'], port1) - self.plugin.update_port(self.context, port2_ret['id'], port2) - self.plugin.update_port(self.context, port3_ret['id'], port3) - port_in_db1 = self.plugin.get_port(self.context, port1_ret['id']) - port_in_db2 = self.plugin.get_port(self.context, port2_ret['id']) - port_in_db3 = self.plugin.get_port(self.context, port3_ret['id']) - self.assertEqual(False, port_in_db1['admin_state_up']) - self.assertEqual(False, port_in_db2['admin_state_up']) - self.assertEqual(False, port_in_db3['admin_state_up']) - - self.plugin.delete_port(self.context, port1_ret['id']) - self.plugin.delete_port(self.context, port2_ret['id']) - self.plugin.delete_port(self.context, port3_ret['id']) - - self.plugin.delete_network(self.context, network_ret1['id']) - self.plugin.delete_network(self.context, network_ret2['id']) - self.plugin.delete_network(self.context, network_ret3['id']) - - def test_create_delete_subnet(self): - # for this test we need to enable overlapping ips - cfg.CONF.set_default('allow_overlapping_ips', True) - network1 = self._fake_network('fake1') - network_ret1 = self.plugin.create_network(self.context, network1) - network2 = self._fake_network('fake2') - network_ret2 = self.plugin.create_network(self.context, network2) - network3 = self._fake_network('proxy') - network_ret3 = self.plugin.create_network(self.context, network3) - - subnet1 = self._fake_subnet(network_ret1['id']) - subnet2 = self._fake_subnet(network_ret2['id']) - subnet3 = self._fake_subnet(network_ret3['id']) - - subnet1_ret = self.plugin.create_subnet(self.context, subnet1) - subnet2_ret = self.plugin.create_subnet(self.context, subnet2) - subnet3_ret = self.plugin.create_subnet(self.context, subnet3) - self.assertEqual(network_ret1['id'], subnet1_ret['network_id']) - self.assertEqual(network_ret2['id'], subnet2_ret['network_id']) - self.assertEqual(network_ret3['id'], subnet3_ret['network_id']) - - subnet_in_db1 = self.plugin.get_subnet(self.context, subnet1_ret['id']) - subnet_in_db2 = self.plugin.get_subnet(self.context, subnet2_ret['id']) - subnet_in_db3 = self.plugin.get_subnet(self.context, subnet3_ret['id']) - - subnet1['subnet']['allocation_pools'].pop() - subnet2['subnet']['allocation_pools'].pop() - subnet3['subnet']['allocation_pools'].pop() - - self.plugin.update_subnet(self.context, - subnet1_ret['id'], subnet1) - self.plugin.update_subnet(self.context, - subnet2_ret['id'], subnet2) - self.plugin.update_subnet(self.context, - subnet3_ret['id'], subnet3) - subnet_in_db1 = self.plugin.get_subnet(self.context, subnet1_ret['id']) - subnet_in_db2 = self.plugin.get_subnet(self.context, subnet2_ret['id']) - subnet_in_db3 = self.plugin.get_subnet(self.context, subnet3_ret['id']) - - self.assertEqual(4, subnet_in_db1['ip_version']) - self.assertEqual(4, subnet_in_db2['ip_version']) - self.assertEqual(4, subnet_in_db3['ip_version']) - - self.plugin.delete_subnet(self.context, subnet1_ret['id']) - self.plugin.delete_subnet(self.context, subnet2_ret['id']) - self.plugin.delete_subnet(self.context, subnet3_ret['id']) - - self.plugin.delete_network(self.context, network_ret1['id']) - self.plugin.delete_network(self.context, network_ret2['id']) - self.plugin.delete_network(self.context, network_ret3['id']) - - def test_create_delete_router(self): - router1 = self._fake_router('fake1') - router_ret1 = self.plugin.create_router(self.context, router1) - router2 = self._fake_router('fake2') - router_ret2 = self.plugin.create_router(self.context, router2) - - self.assertEqual('fake1', router_ret1[ext_flavor.FLAVOR_ROUTER]) - self.assertEqual('fake2', router_ret2[ext_flavor.FLAVOR_ROUTER]) - - router_in_db1 = self.plugin.get_router(self.context, router_ret1['id']) - router_in_db2 = self.plugin.get_router(self.context, router_ret2['id']) - - self.assertEqual('fake1', router_in_db1[ext_flavor.FLAVOR_ROUTER]) - self.assertEqual('fake2', router_in_db2[ext_flavor.FLAVOR_ROUTER]) - - self.plugin.delete_router(self.context, router_ret1['id']) - self.plugin.delete_router(self.context, router_ret2['id']) - with testtools.ExpectedException(meta_neutron_plugin.FlavorNotFound): - self.plugin.get_router(self.context, router_ret1['id']) - - def test_extension_method(self): - self.assertEqual('fake1', self.plugin.fake_func()) - self.assertEqual('fake2', self.plugin.fake_func2()) - - def test_extension_not_implemented_method(self): - try: - self.plugin.not_implemented() - except AttributeError: - return - except Exception: - self.fail("AttributeError Error is not raised") - - self.fail("No Error is not raised") - - def test_create_network_flavor_fail(self): - with mock.patch('neutron.plugins.metaplugin.meta_db_v2.' - 'add_network_flavor_binding', - side_effect=Exception): - network = self._fake_network('fake1') - self.assertRaises(meta_neutron_plugin.FaildToAddFlavorBinding, - self.plugin.create_network, - self.context, - network) - count = self.plugin.get_networks_count(self.context) - self.assertEqual(count, 0) - - def test_create_router_flavor_fail(self): - with mock.patch('neutron.plugins.metaplugin.meta_db_v2.' - 'add_router_flavor_binding', - side_effect=Exception): - router = self._fake_router('fake1') - self.assertRaises(meta_neutron_plugin.FaildToAddFlavorBinding, - self.plugin.create_router, - self.context, - router) - count = self.plugin.get_routers_count(self.context) - self.assertEqual(count, 0) - - -class MetaNeutronPluginV2TestWithoutL3(MetaNeutronPluginV2Test): - """Tests without l3_plugin_list configration.""" - - has_l3 = False - - def test_supported_extension_aliases(self): - self.assertEqual(self.plugin.supported_extension_aliases, - ['flavor', 'external-net']) - - def test_create_delete_router(self): - self.skipTest("Test case without router") - - def test_create_router_flavor_fail(self): - self.skipTest("Test case without router") - - -class MetaNeutronPluginV2TestRpcFlavor(base.BaseTestCase): - """Tests for rpc_flavor.""" - - def setUp(self): - super(MetaNeutronPluginV2TestRpcFlavor, self).setUp() - db._ENGINE = None - db._MAKER = None - db.configure_db() - self.addCleanup(db.clear_db) - self.addCleanup(unregister_meta_hooks) - - def test_rpc_flavor(self): - setup_metaplugin_conf() - cfg.CONF.set_override('rpc_flavor', 'fake1', 'META') - self.plugin = meta_neutron_plugin.MetaPluginV2() - self.assertEqual(topics.PLUGIN, 'q-plugin') - ret = self.plugin.rpc_workers_supported() - self.assertFalse(ret) - - def test_invalid_rpc_flavor(self): - setup_metaplugin_conf() - cfg.CONF.set_override('rpc_flavor', 'fake-fake', 'META') - self.assertRaises(exc.Invalid, - meta_neutron_plugin.MetaPluginV2) - self.assertEqual(topics.PLUGIN, 'q-plugin') - - def test_rpc_flavor_multiple_rpc_workers(self): - setup_metaplugin_conf() - cfg.CONF.set_override('rpc_flavor', 'fake2', 'META') - self.plugin = meta_neutron_plugin.MetaPluginV2() - self.assertEqual(topics.PLUGIN, 'q-plugin') - ret = self.plugin.rpc_workers_supported() - self.assertTrue(ret) - ret = self.plugin.start_rpc_listeners() - self.assertEqual('OK', ret) diff --git a/neutron/tests/unit/midonet/__init__.py b/neutron/tests/unit/midonet/__init__.py deleted file mode 100644 index 439ff6594..000000000 --- a/neutron/tests/unit/midonet/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright (C) 2012 Midokura Japan K.K. -# Copyright (C) 2013 Midokura PTE LTD -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. diff --git a/neutron/tests/unit/midonet/etc/midonet.ini.test b/neutron/tests/unit/midonet/etc/midonet.ini.test deleted file mode 100644 index 8e4fc847f..000000000 --- a/neutron/tests/unit/midonet/etc/midonet.ini.test +++ /dev/null @@ -1,16 +0,0 @@ -[midonet] - -# MidoNet API server URI -midonet_uri = http://localhost:8080/midonet-api - -# MidoNet admin username -username = admin - -# MidoNet admin password -password = passw0rd - -# Virtual provider router ID -provider_router_id = 00112233-0011-0011-0011-001122334455 - -# Virtual metadata router ID -metadata_router_id = ffeeddcc-ffee-ffee-ffee-ffeeddccbbaa diff --git a/neutron/tests/unit/midonet/mock_lib.py b/neutron/tests/unit/midonet/mock_lib.py deleted file mode 100644 index 9fdae9cd6..000000000 --- a/neutron/tests/unit/midonet/mock_lib.py +++ /dev/null @@ -1,265 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright (C) 2013 Midokura PTE LTD -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Ryu Ishimoto, Midokura Japan KK - -import mock -import uuid - - -def get_bridge_mock(id=None, **kwargs): - if id is None: - id = str(uuid.uuid4()) - - bridge = mock.Mock() - bridge.get_id.return_value = id - bridge.get_tenant_id.return_value = kwargs.get("tenant_id", "test-tenant") - bridge.get_name.return_value = kwargs.get("name", "net") - bridge.get_ports.return_value = [] - bridge.get_peer_ports.return_value = [] - bridge.get_admin_state_up.return_value = kwargs.get("admin_state_up", True) - return bridge - - -def get_bridge_port_mock(id=None, bridge_id=None, **kwargs): - if id is None: - id = str(uuid.uuid4()) - if bridge_id is None: - bridge_id = str(uuid.uuid4()) - - port = mock.Mock() - port.get_id.return_value = id - port.get_bridge_id.return_value = bridge_id - port.get_admin_state_up.return_value = kwargs.get("admin_state_up", True) - port.get_type.return_value = "Bridge" - port.create.return_value = port - return port - - -def get_chain_mock(id=None, tenant_id='test-tenant', name='chain', - rules=None): - if id is None: - id = str(uuid.uuid4()) - - if rules is None: - rules = [] - - chain = mock.Mock() - chain.get_id.return_value = id - chain.get_tenant_id.return_value = tenant_id - chain.get_name.return_value = name - chain.get_rules.return_value = rules - return chain - - -def get_port_group_mock(id=None, tenant_id='test-tenant', name='pg'): - if id is None: - id = str(uuid.uuid4()) - - port_group = mock.Mock() - port_group.get_id.return_value = id - port_group.get_tenant_id.return_value = tenant_id - port_group.get_name.return_value = name - return port_group - - -def get_router_mock(id=None, **kwargs): - if id is None: - id = str(uuid.uuid4()) - - router = mock.Mock() - router.get_id.return_value = id - router.get_tenant_id.return_value = kwargs.get("tenant_id", "test-tenant") - router.get_name.return_value = kwargs.get("name", "router") - router.get_ports.return_value = [] - router.get_peer_ports.return_value = [] - router.get_routes.return_value = [] - router.get_admin_state_up.return_value = kwargs.get("admin_state_up", True) - return router - - -def get_rule_mock(id=None, chain_id=None, properties=None): - if id is None: - id = str(uuid.uuid4()) - - if chain_id is None: - chain_id = str(uuid.uuid4()) - - if properties is None: - properties = {} - - rule = mock.Mock() - rule.get_id.return_value = id - rule.get_chain_id.return_value = chain_id - rule.get_properties.return_value = properties - return rule - - -def get_subnet_mock(bridge_id=None, gateway_ip='10.0.0.1', - subnet_prefix='10.0.0.0', subnet_len=int(24)): - if bridge_id is None: - bridge_id = str(uuid.uuid4()) - - subnet = mock.Mock() - subnet.get_id.return_value = subnet_prefix + '/' + str(subnet_len) - subnet.get_bridge_id.return_value = bridge_id - subnet.get_default_gateway.return_value = gateway_ip - subnet.get_subnet_prefix.return_value = subnet_prefix - subnet.get_subnet_length.return_value = subnet_len - return subnet - - -class MidonetLibMockConfig(): - - def __init__(self, inst): - self.inst = inst - - def _create_bridge(self, **kwargs): - return get_bridge_mock(**kwargs) - - def _create_router(self, **kwargs): - return get_router_mock(**kwargs) - - def _create_subnet(self, bridge, gateway_ip, subnet_prefix, subnet_len): - return get_subnet_mock(bridge.get_id(), gateway_ip=gateway_ip, - subnet_prefix=subnet_prefix, - subnet_len=subnet_len) - - def _add_bridge_port(self, bridge, **kwargs): - return get_bridge_port_mock(bridge_id=bridge.get_id(), **kwargs) - - def _get_bridge(self, id): - return get_bridge_mock(id=id) - - def _get_port(self, id): - return get_bridge_port_mock(id=id) - - def _get_router(self, id): - return get_router_mock(id=id) - - def _update_bridge(self, id, **kwargs): - return get_bridge_mock(id=id, **kwargs) - - def setup(self): - # Bridge methods side effects - self.inst.create_bridge.side_effect = self._create_bridge - self.inst.get_bridge.side_effect = self._get_bridge - self.inst.update_bridge.side_effect = self._update_bridge - - # Subnet methods side effects - self.inst.create_subnet.side_effect = self._create_subnet - - # Port methods side effects - ex_bp = self.inst.add_bridge_port - ex_bp.side_effect = self._add_bridge_port - self.inst.get_port.side_effect = self._get_port - - # Router methods side effects - self.inst.create_router.side_effect = self._create_router - self.inst.get_router.side_effect = self._get_router - - -class MidoClientMockConfig(): - - def __init__(self, inst): - self.inst = inst - self.chains_in = None - self.port_groups_in = None - self.chains_out = None - self.rules_out = None - self.port_groups_out = None - - def _get_query_tenant_id(self, query): - if query is not None and query['tenant_id']: - tenant_id = query['tenant_id'] - else: - tenant_id = 'test-tenant' - return tenant_id - - def _get_bridge(self, id): - return get_bridge_mock(id=id) - - def _get_chain(self, id, query=None): - if not self.chains_in: - return [] - - tenant_id = self._get_query_tenant_id(query) - for chain in self.chains_in: - chain_id = chain['id'] - if chain_id is id: - rule_mocks = [] - if 'rules' in chain: - for rule in chain['rules']: - rule_mocks.append( - get_rule_mock(id=rule['id'], - chain_id=id, - properties=rule['properties'])) - - return get_chain_mock(id=chain_id, name=chain['name'], - tenant_id=tenant_id, rules=rule_mocks) - return None - - def _get_chains(self, query=None): - if not self.chains_in: - return [] - - tenant_id = self._get_query_tenant_id(query) - self.chains_out = [] - self.rules_out = [] - for chain in self.chains_in: - chain_id = chain['id'] - - rule_mocks = [] - if 'rules' in chain: - for rule in chain['rules']: - rule_mocks.append( - get_rule_mock(id=rule['id'], - chain_id=id, - properties=rule['properties'])) - self.rules_out += rule_mocks - - self.chains_out.append(get_chain_mock(id=chain_id, - name=chain['name'], - tenant_id=tenant_id, - rules=rule_mocks)) - return self.chains_out - - def _get_port_groups(self, query=None): - if not self.port_groups_in: - return [] - - tenant_id = self._get_query_tenant_id(query) - self.port_groups_out = [] - for port_group in self.port_groups_in: - self.port_groups_out.append(get_port_group_mock( - id=port_group['id'], name=port_group['name'], - tenant_id=tenant_id)) - return self.port_groups_out - - def _get_router(self, id): - return get_router_mock(id=id) - - def _add_bridge_port(self, bridge): - return get_bridge_port_mock(bridge_id=bridge.get_id()) - - def setup(self): - self.inst.get_bridge.side_effect = self._get_bridge - self.inst.get_chains.side_effect = self._get_chains - self.inst.get_chain.side_effect = self._get_chain - self.inst.get_port_groups.side_effect = self._get_port_groups - self.inst.get_router.side_effect = self._get_router - self.inst.add_bridge_port.side_effect = self._add_bridge_port diff --git a/neutron/tests/unit/midonet/test_midonet_driver.py b/neutron/tests/unit/midonet/test_midonet_driver.py deleted file mode 100644 index 67677c92a..000000000 --- a/neutron/tests/unit/midonet/test_midonet_driver.py +++ /dev/null @@ -1,55 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright (C) 2012 Midokura Japan K.K. -# Copyright (C) 2013 Midokura PTE LTD -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Rossella Sblendido, Midokura Japan KK - -import mock - -from neutron.agent.common import config -from neutron.agent.linux import dhcp -from neutron.common import config as base_config -import neutron.plugins.midonet.agent.midonet_driver as driver -from neutron.tests import base - - -class FakeNetwork: - id = 'aaaabbbb-cccc-dddd-eeee-ffff00001111' - namespace = 'qdhcp-ns' - - -class TestDhcpNoOpDriver(base.BaseTestCase): - def setUp(self): - super(TestDhcpNoOpDriver, self).setUp() - self.conf = config.setup_conf() - config.register_interface_driver_opts_helper(self.conf) - self.conf.register_opts(base_config.core_opts) - self.conf.register_opts(dhcp.OPTS) - self.conf.enable_isolated_metadata = True - self.conf.use_namespaces = True - instance = mock.patch("neutron.agent.linux.dhcp.DeviceManager") - self.mock_mgr = instance.start() - - def test_disable_no_retain_port(self): - dhcp_driver = driver.DhcpNoOpDriver(self.conf, FakeNetwork()) - dhcp_driver.disable(retain_port=False) - self.assertTrue(self.mock_mgr.return_value.destroy.called) - - def test_disable_retain_port(self): - dhcp_driver = driver.DhcpNoOpDriver(self.conf, FakeNetwork()) - dhcp_driver.disable(retain_port=True) - self.assertFalse(self.mock_mgr.return_value.destroy.called) diff --git a/neutron/tests/unit/midonet/test_midonet_lib.py b/neutron/tests/unit/midonet/test_midonet_lib.py deleted file mode 100644 index bed900fa3..000000000 --- a/neutron/tests/unit/midonet/test_midonet_lib.py +++ /dev/null @@ -1,189 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright (C) 2012 Midokura Japan K.K. -# Copyright (C) 2013 Midokura PTE LTD -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Ryu Ishimoto, Midokura Japan KK -# @author: Tomoe Sugihara, Midokura Japan KK -import sys - -import mock -import testtools -import webob.exc as w_exc - -from neutron.openstack.common import uuidutils -with mock.patch.dict(sys.modules, {'midonetclient': mock.Mock()}): - from neutron.plugins.midonet import midonet_lib -import neutron.tests.unit.midonet.mock_lib as mock_lib - - -def _create_test_chain(id, name, tenant_id): - return {'id': id, 'name': name, 'tenant_id': tenant_id} - - -def _create_test_port_group(id, name, tenant_id): - return {"id": id, "name": name, "tenant_id": tenant_id} - - -class MidoClientTestCase(testtools.TestCase): - - def setUp(self): - super(MidoClientTestCase, self).setUp() - self._tenant_id = 'test-tenant' - self.mock_api = mock.Mock() - self.mock_api_cfg = mock_lib.MidoClientMockConfig(self.mock_api) - self.mock_api_cfg.setup() - self.client = midonet_lib.MidoClient(self.mock_api) - - def test_delete_chains_by_names(self): - - tenant_id = uuidutils.generate_uuid() - chain1_id = uuidutils.generate_uuid() - chain1 = _create_test_chain(chain1_id, "chain1", tenant_id) - - chain2_id = uuidutils.generate_uuid() - chain2 = _create_test_chain(chain2_id, "chain2", tenant_id) - - calls = [mock.call.delete_chain(chain1_id), - mock.call.delete_chain(chain2_id)] - self.mock_api_cfg.chains_in = [chain2, chain1] - self.client.delete_chains_by_names(tenant_id, ["chain1", "chain2"]) - - self.mock_api.assert_has_calls(calls, any_order=True) - - def test_delete_port_group_by_name(self): - - tenant_id = uuidutils.generate_uuid() - pg1_id = uuidutils.generate_uuid() - pg1 = _create_test_port_group(pg1_id, "pg1", tenant_id) - pg2_id = uuidutils.generate_uuid() - pg2 = _create_test_port_group(pg2_id, "pg2", tenant_id) - - self.mock_api_cfg.port_groups_in = [pg1, pg2] - self.client.delete_port_group_by_name(tenant_id, "pg1") - self.mock_api.delete_port_group.assert_called_once_with(pg1_id) - - def test_create_dhcp(self): - - bridge = mock.Mock() - - gateway_ip = "192.168.1.1" - cidr = "192.168.1.0/24" - host_rts = [{'destination': '10.0.0.0/24', 'nexthop': '10.0.0.1'}, - {'destination': '10.0.1.0/24', 'nexthop': '10.0.1.1'}] - dns_servers = ["8.8.8.8", "8.8.4.4"] - - dhcp_call = mock.call.add_bridge_dhcp(bridge, gateway_ip, cidr, - host_rts=host_rts, - dns_nservers=dns_servers) - - self.client.create_dhcp(bridge, gateway_ip, cidr, host_rts=host_rts, - dns_servers=dns_servers) - self.mock_api.assert_has_calls([dhcp_call]) - - def test_delete_dhcp(self): - - bridge = mock.Mock() - subnet = mock.Mock() - subnet.get_subnet_prefix.return_value = "10.0.0.0" - subnets = mock.MagicMock(return_value=[subnet]) - bridge.get_dhcp_subnets.side_effect = subnets - self.client.delete_dhcp(bridge, "10.0.0.0/24") - bridge.assert_has_calls(mock.call.get_dhcp_subnets) - subnet.assert_has_calls([mock.call.get_subnet_prefix(), - mock.call.delete()]) - - def test_add_dhcp_host(self): - - bridge = mock.Mock() - dhcp_subnet_call = mock.call.get_dhcp_subnet("10.0.0.0_24") - ip_addr_call = dhcp_subnet_call.add_dhcp_host().ip_addr("10.0.0.10") - mac_addr_call = ip_addr_call.mac_addr("2A:DB:6B:8C:19:99") - calls = [dhcp_subnet_call, ip_addr_call, mac_addr_call, - mac_addr_call.create()] - - self.client.add_dhcp_host(bridge, "10.0.0.0/24", "10.0.0.10", - "2A:DB:6B:8C:19:99") - bridge.assert_has_calls(calls, any_order=True) - - def test_add_dhcp_route_option(self): - - bridge = mock.Mock() - subnet = bridge.get_dhcp_subnet.return_value - subnet.get_opt121_routes.return_value = None - dhcp_subnet_call = mock.call.get_dhcp_subnet("10.0.0.0_24") - dst_ip = "10.0.0.3/24" - gw_ip = "10.0.0.1" - prefix, length = dst_ip.split("/") - routes = [{'destinationPrefix': prefix, 'destinationLength': length, - 'gatewayAddr': gw_ip}] - opt121_routes_call = dhcp_subnet_call.opt121_routes(routes) - calls = [dhcp_subnet_call, opt121_routes_call, - opt121_routes_call.update()] - - self.client.add_dhcp_route_option(bridge, "10.0.0.0/24", - gw_ip, dst_ip) - bridge.assert_has_calls(calls, any_order=True) - - def test_get_router_error(self): - self.mock_api.get_router.side_effect = w_exc.HTTPInternalServerError() - self.assertRaises(midonet_lib.MidonetApiException, - self.client.get_router, uuidutils.generate_uuid()) - - def test_get_router_not_found(self): - self.mock_api.get_router.side_effect = w_exc.HTTPNotFound() - self.assertRaises(midonet_lib.MidonetResourceNotFound, - self.client.get_router, uuidutils.generate_uuid()) - - def test_get_bridge_error(self): - self.mock_api.get_bridge.side_effect = w_exc.HTTPInternalServerError() - self.assertRaises(midonet_lib.MidonetApiException, - self.client.get_bridge, uuidutils.generate_uuid()) - - def test_get_bridge_not_found(self): - self.mock_api.get_bridge.side_effect = w_exc.HTTPNotFound() - self.assertRaises(midonet_lib.MidonetResourceNotFound, - self.client.get_bridge, uuidutils.generate_uuid()) - - def test_get_bridge(self): - bridge_id = uuidutils.generate_uuid() - - bridge = self.client.get_bridge(bridge_id) - - self.assertIsNotNone(bridge) - self.assertEqual(bridge.get_id(), bridge_id) - self.assertTrue(bridge.get_admin_state_up()) - - def test_add_bridge_port(self): - bridge_id = uuidutils.generate_uuid() - - bridge = self.client.get_bridge(bridge_id) - - self.assertIsNotNone(bridge) - - port = self.client.add_bridge_port(bridge) - - self.assertEqual(bridge.get_id(), port.get_bridge_id()) - self.assertTrue(port.get_admin_state_up()) - - def test_get_router(self): - router_id = uuidutils.generate_uuid() - - router = self.client.get_router(router_id) - - self.assertIsNotNone(router) - self.assertEqual(router.get_id(), router_id) - self.assertTrue(router.get_admin_state_up()) diff --git a/neutron/tests/unit/midonet/test_midonet_plugin.py b/neutron/tests/unit/midonet/test_midonet_plugin.py deleted file mode 100644 index 46ed5bf0d..000000000 --- a/neutron/tests/unit/midonet/test_midonet_plugin.py +++ /dev/null @@ -1,218 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright (C) 2012 Midokura Japan K.K. -# Copyright (C) 2013 Midokura PTE LTD -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Rossella Sblendido, Midokura Europe SARL -# @author: Ryu Ishimoto, Midokura Japan KK -# @author: Tomoe Sugihara, Midokura Japan KK - -import mock -import os -import sys - -import neutron.common.test_lib as test_lib -from neutron.extensions import portbindings -from neutron.tests.unit import _test_extension_portbindings as test_bindings -import neutron.tests.unit.midonet.mock_lib as mock_lib -import neutron.tests.unit.test_db_plugin as test_plugin -import neutron.tests.unit.test_extension_security_group as sg -import neutron.tests.unit.test_l3_plugin as test_l3_plugin - -MIDOKURA_PKG_PATH = "neutron.plugins.midonet.plugin" -MIDONET_PLUGIN_NAME = ('%s.MidonetPluginV2' % MIDOKURA_PKG_PATH) - - -class MidonetPluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase): - - def setUp(self, - plugin=MIDONET_PLUGIN_NAME, - ext_mgr=None, - service_plugins=None): - self.mock_api = mock.patch( - 'neutron.plugins.midonet.midonet_lib.MidoClient') - etc_path = os.path.join(os.path.dirname(__file__), 'etc') - test_lib.test_config['config_files'] = [os.path.join( - etc_path, 'midonet.ini.test')] - - p = mock.patch.dict(sys.modules, {'midonetclient': mock.Mock()}) - p.start() - # dict patches must be explicitly stopped - self.addCleanup(p.stop) - self.instance = self.mock_api.start() - mock_cfg = mock_lib.MidonetLibMockConfig(self.instance.return_value) - mock_cfg.setup() - super(MidonetPluginV2TestCase, self).setUp(plugin=plugin, - ext_mgr=ext_mgr) - - def tearDown(self): - super(MidonetPluginV2TestCase, self).tearDown() - self.mock_api.stop() - - -class TestMidonetNetworksV2(test_plugin.TestNetworksV2, - MidonetPluginV2TestCase): - - pass - - -class TestMidonetL3NatTestCase(MidonetPluginV2TestCase, - test_l3_plugin.L3NatDBIntTestCase): - def setUp(self, - plugin=MIDONET_PLUGIN_NAME, - ext_mgr=None, - service_plugins=None): - super(TestMidonetL3NatTestCase, self).setUp(plugin=plugin, - ext_mgr=None, - service_plugins=None) - - def test_floatingip_with_invalid_create_port(self): - self._test_floatingip_with_invalid_create_port(MIDONET_PLUGIN_NAME) - - def test_floatingip_assoc_no_port(self): - with self.subnet(cidr='200.0.0.0/24') as public_sub: - self._set_net_external(public_sub['subnet']['network_id']) - res = super(TestMidonetL3NatTestCase, self)._create_floatingip( - self.fmt, public_sub['subnet']['network_id']) - # Cleanup - floatingip = self.deserialize(self.fmt, res) - self._delete('floatingips', floatingip['floatingip']['id']) - self.assertFalse(self.instance.return_value.add_static_nat.called) - - def test_floatingip_assoc_with_port(self): - with self.subnet(cidr='200.0.0.0/24') as public_sub: - self._set_net_external(public_sub['subnet']['network_id']) - with self.port() as private_port: - with self.router() as r: - # We need to hook up the private subnet to the external - # network in order to associate the fip. - sid = private_port['port']['fixed_ips'][0]['subnet_id'] - private_sub = {'subnet': {'id': sid}} - self._add_external_gateway_to_router( - r['router']['id'], - public_sub['subnet']['network_id']) - - # Check that get_link_port was called - if not, Source NAT - # will not be set up correctly on the MidoNet side - self.assertTrue( - self.instance.return_value.get_link_port.called) - - self._router_interface_action('add', r['router']['id'], - private_sub['subnet']['id'], - None) - - # Create the fip. - res = super(TestMidonetL3NatTestCase, - self)._create_floatingip( - self.fmt, - public_sub['subnet']['network_id'], - port_id=private_port['port']['id']) - - # Cleanup the resources used for the test - floatingip = self.deserialize(self.fmt, res) - self._delete('floatingips', floatingip['floatingip']['id']) - self._remove_external_gateway_from_router( - r['router']['id'], - public_sub['subnet']['network_id']) - self._router_interface_action('remove', - r['router']['id'], - private_sub['subnet']['id'], - None) - self.assertTrue(self.instance.return_value.add_static_nat.called) - - -class TestMidonetSecurityGroupsTestCase(sg.SecurityGroupDBTestCase): - - _plugin_name = ('%s.MidonetPluginV2' % MIDOKURA_PKG_PATH) - - def setUp(self): - self.mock_api = mock.patch( - 'neutron.plugins.midonet.midonet_lib.MidoClient') - etc_path = os.path.join(os.path.dirname(__file__), 'etc') - test_lib.test_config['config_files'] = [os.path.join( - etc_path, 'midonet.ini.test')] - - self.instance = self.mock_api.start() - mock_cfg = mock_lib.MidonetLibMockConfig(self.instance.return_value) - mock_cfg.setup() - p = mock.patch.dict(sys.modules, {'midonetclient': mock.Mock()}) - p.start() - # dict patches must be explicitly stopped - self.addCleanup(p.stop) - super(TestMidonetSecurityGroupsTestCase, self).setUp(self._plugin_name) - - -class TestMidonetSecurityGroup(sg.TestSecurityGroups, - TestMidonetSecurityGroupsTestCase): - - pass - - -class TestMidonetSubnetsV2(test_plugin.TestSubnetsV2, - MidonetPluginV2TestCase): - - # IPv6 is not supported by MidoNet yet. Ignore tests that attempt to - # create IPv6 subnet. - def test_create_subnet_inconsistent_ipv6_cidrv4(self): - pass - - def test_create_subnet_inconsistent_ipv6_dns_v4(self): - pass - - def test_create_subnet_with_v6_allocation_pool(self): - pass - - def test_update_subnet_inconsistent_ipv6_gatewayv4(self): - pass - - def test_update_subnet_inconsistent_ipv6_hostroute_dst_v4(self): - pass - - def test_update_subnet_inconsistent_ipv6_hostroute_np_v4(self): - pass - - def test_create_subnet_inconsistent_ipv6_gatewayv4(self): - pass - - def test_create_subnet_dhcp_disabled(self): - super(TestMidonetSubnetsV2, self)._test_create_subnet( - enable_dhcp=False) - self.assertFalse(self.instance.return_value.create_dhcp.called) - - -class TestMidonetPortsV2(test_plugin.TestPortsV2, - MidonetPluginV2TestCase): - - # IPv6 is not supported by MidoNet yet. Ignore tests that attempt to - # create IPv6 subnet. - - def test_requested_subnet_id_v4_and_v6(self): - pass - - def test_vif_port_binding(self): - with self.port(name='myname') as port: - self.assertEqual('midonet', port['port']['binding:vif_type']) - self.assertTrue(port['port']['admin_state_up']) - - -class TestMidonetPluginPortBinding(test_bindings.PortBindingsTestCase, - MidonetPluginV2TestCase): - - VIF_TYPE = portbindings.VIF_TYPE_MIDONET - HAS_PORT_FILTER = True - - def setUp(self): - super(TestMidonetPluginPortBinding, self).setUp() diff --git a/neutron/tests/unit/ml2/__init__.py b/neutron/tests/unit/ml2/__init__.py deleted file mode 100644 index 788cea1f7..000000000 --- a/neutron/tests/unit/ml2/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2013 OpenStack Foundation -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. diff --git a/neutron/tests/unit/ml2/_test_mech_agent.py b/neutron/tests/unit/ml2/_test_mech_agent.py deleted file mode 100644 index 4fbdc10e5..000000000 --- a/neutron/tests/unit/ml2/_test_mech_agent.py +++ /dev/null @@ -1,218 +0,0 @@ -# Copyright (c) 2013 OpenStack Foundation -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - - -from neutron.extensions import portbindings -from neutron.plugins.ml2 import driver_api as api -from neutron.tests import base - -NETWORK_ID = "fake_network" -PORT_ID = "fake_port" - - -class FakeNetworkContext(api.NetworkContext): - def __init__(self, segments): - self._network_segments = segments - - @property - def current(self): - return {'id': NETWORK_ID} - - @property - def original(self): - return None - - @property - def network_segments(self): - return self._network_segments - - -class FakePortContext(api.PortContext): - def __init__(self, agent_type, agents, segments, - vnic_type=portbindings.VNIC_NORMAL): - self._agent_type = agent_type - self._agents = agents - self._network_context = FakeNetworkContext(segments) - self._bound_vnic_type = vnic_type - self._bound_segment_id = None - self._bound_vif_type = None - self._bound_vif_details = None - - @property - def current(self): - return {'id': PORT_ID, - 'binding:vnic_type': self._bound_vnic_type} - - @property - def original(self): - return None - - @property - def network(self): - return self._network_context - - @property - def bound_segment(self): - if self._bound_segment_id: - for segment in self._network_context.network_segments: - if segment[api.ID] == self._bound_segment_id: - return segment - - @property - def original_bound_segment(self): - return None - - @property - def bound_driver(self): - return None - - @property - def original_bound_driver(self): - return None - - def host_agents(self, agent_type): - if agent_type == self._agent_type: - return self._agents - else: - return [] - - def set_binding(self, segment_id, vif_type, vif_details): - self._bound_segment_id = segment_id - self._bound_vif_type = vif_type - self._bound_vif_details = vif_details - - -class AgentMechanismBaseTestCase(base.BaseTestCase): - # These following must be overriden for the specific mechanism - # driver being tested: - VIF_TYPE = None - CAP_PORT_FILTER = None - AGENT_TYPE = None - AGENTS = None - AGENTS_DEAD = None - AGENTS_BAD = None - - def _check_unbound(self, context): - self.assertIsNone(context._bound_segment_id) - self.assertIsNone(context._bound_vif_type) - self.assertIsNone(context._bound_vif_details) - - def _check_bound(self, context, segment): - self.assertEqual(context._bound_segment_id, segment[api.ID]) - self.assertEqual(context._bound_vif_type, self.VIF_TYPE) - vif_details = context._bound_vif_details - self.assertIsNotNone(vif_details) - self.assertEqual(vif_details[portbindings.CAP_PORT_FILTER], - self.CAP_PORT_FILTER) - - -class AgentMechanismGenericTestCase(AgentMechanismBaseTestCase): - UNKNOWN_TYPE_SEGMENTS = [{api.ID: 'unknown_segment_id', - api.NETWORK_TYPE: 'no_such_type'}] - - def test_unknown_type(self): - context = FakePortContext(self.AGENT_TYPE, - self.AGENTS, - self.UNKNOWN_TYPE_SEGMENTS) - self.driver.bind_port(context) - self._check_unbound(context) - - -class AgentMechanismLocalTestCase(AgentMechanismBaseTestCase): - LOCAL_SEGMENTS = [{api.ID: 'unknown_segment_id', - api.NETWORK_TYPE: 'no_such_type'}, - {api.ID: 'local_segment_id', - api.NETWORK_TYPE: 'local'}] - - def test_type_local(self): - context = FakePortContext(self.AGENT_TYPE, - self.AGENTS, - self.LOCAL_SEGMENTS) - self.driver.bind_port(context) - self._check_bound(context, self.LOCAL_SEGMENTS[1]) - - def test_type_local_dead(self): - context = FakePortContext(self.AGENT_TYPE, - self.AGENTS_DEAD, - self.LOCAL_SEGMENTS) - self.driver.bind_port(context) - self._check_unbound(context) - - -class AgentMechanismFlatTestCase(AgentMechanismBaseTestCase): - FLAT_SEGMENTS = [{api.ID: 'unknown_segment_id', - api.NETWORK_TYPE: 'no_such_type'}, - {api.ID: 'flat_segment_id', - api.NETWORK_TYPE: 'flat', - api.PHYSICAL_NETWORK: 'fake_physical_network'}] - - def test_type_flat(self): - context = FakePortContext(self.AGENT_TYPE, - self.AGENTS, - self.FLAT_SEGMENTS) - self.driver.bind_port(context) - self._check_bound(context, self.FLAT_SEGMENTS[1]) - - def test_type_flat_bad(self): - context = FakePortContext(self.AGENT_TYPE, - self.AGENTS_BAD, - self.FLAT_SEGMENTS) - self.driver.bind_port(context) - self._check_unbound(context) - - -class AgentMechanismVlanTestCase(AgentMechanismBaseTestCase): - VLAN_SEGMENTS = [{api.ID: 'unknown_segment_id', - api.NETWORK_TYPE: 'no_such_type'}, - {api.ID: 'vlan_segment_id', - api.NETWORK_TYPE: 'vlan', - api.PHYSICAL_NETWORK: 'fake_physical_network', - api.SEGMENTATION_ID: 1234}] - - def test_type_vlan(self): - context = FakePortContext(self.AGENT_TYPE, - self.AGENTS, - self.VLAN_SEGMENTS) - self.driver.bind_port(context) - self._check_bound(context, self.VLAN_SEGMENTS[1]) - - def test_type_vlan_bad(self): - context = FakePortContext(self.AGENT_TYPE, - self.AGENTS_BAD, - self.VLAN_SEGMENTS) - self.driver.bind_port(context) - self._check_unbound(context) - - -class AgentMechanismGreTestCase(AgentMechanismBaseTestCase): - GRE_SEGMENTS = [{api.ID: 'unknown_segment_id', - api.NETWORK_TYPE: 'no_such_type'}, - {api.ID: 'gre_segment_id', - api.NETWORK_TYPE: 'gre', - api.SEGMENTATION_ID: 1234}] - - def test_type_gre(self): - context = FakePortContext(self.AGENT_TYPE, - self.AGENTS, - self.GRE_SEGMENTS) - self.driver.bind_port(context) - self._check_bound(context, self.GRE_SEGMENTS[1]) - - def test_type_gre_bad(self): - context = FakePortContext(self.AGENT_TYPE, - self.AGENTS_BAD, - self.GRE_SEGMENTS) - self.driver.bind_port(context) - self._check_unbound(context) diff --git a/neutron/tests/unit/ml2/drivers/__init__.py b/neutron/tests/unit/ml2/drivers/__init__.py deleted file mode 100644 index 788cea1f7..000000000 --- a/neutron/tests/unit/ml2/drivers/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2013 OpenStack Foundation -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. diff --git a/neutron/tests/unit/ml2/drivers/brocade/__init__.py b/neutron/tests/unit/ml2/drivers/brocade/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/neutron/tests/unit/ml2/drivers/brocade/test_brocade_mechanism_driver.py b/neutron/tests/unit/ml2/drivers/brocade/test_brocade_mechanism_driver.py deleted file mode 100644 index 2dac0fe2a..000000000 --- a/neutron/tests/unit/ml2/drivers/brocade/test_brocade_mechanism_driver.py +++ /dev/null @@ -1,69 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright (c) 2013 OpenStack Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import mock - -from neutron.openstack.common import importutils -from neutron.openstack.common import log as logging -from neutron.plugins.ml2 import config as ml2_config -from neutron.plugins.ml2.drivers.brocade import (mechanism_brocade - as brocademechanism) -from neutron.tests.unit import test_db_plugin - -LOG = logging.getLogger(__name__) -MECHANISM_NAME = ('neutron.plugins.ml2.' - 'drivers.brocade.mechanism_brocade.BrocadeMechanism') - - -class TestBrocadeMechDriverV2(test_db_plugin.NeutronDbPluginV2TestCase): - """Test Brocade VCS/VDX mechanism driver. - """ - - _mechanism_name = MECHANISM_NAME - - def setUp(self): - - _mechanism_name = MECHANISM_NAME - - ml2_opts = { - 'mechanism_drivers': ['brocade'], - 'tenant_network_types': ['vlan']} - - for opt, val in ml2_opts.items(): - ml2_config.cfg.CONF.set_override(opt, val, 'ml2') - - def mocked_brocade_init(self): - self._driver = mock.MagicMock() - - with mock.patch.object(brocademechanism.BrocadeMechanism, - 'brocade_init', new=mocked_brocade_init): - super(TestBrocadeMechDriverV2, self).setUp() - self.mechanism_driver = importutils.import_object(_mechanism_name) - - -class TestBrocadeMechDriverNetworksV2(test_db_plugin.TestNetworksV2, - TestBrocadeMechDriverV2): - pass - - -class TestBrocadeMechDriverPortsV2(test_db_plugin.TestPortsV2, - TestBrocadeMechDriverV2): - pass - - -class TestBrocadeMechDriverSubnetsV2(test_db_plugin.TestSubnetsV2, - TestBrocadeMechDriverV2): - pass diff --git a/neutron/tests/unit/ml2/drivers/cisco/__init__.py b/neutron/tests/unit/ml2/drivers/cisco/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/neutron/tests/unit/ml2/drivers/cisco/apic/__init__.py b/neutron/tests/unit/ml2/drivers/cisco/apic/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/neutron/tests/unit/ml2/drivers/cisco/apic/test_cisco_apic_client.py b/neutron/tests/unit/ml2/drivers/cisco/apic/test_cisco_apic_client.py deleted file mode 100644 index 23444033a..000000000 --- a/neutron/tests/unit/ml2/drivers/cisco/apic/test_cisco_apic_client.py +++ /dev/null @@ -1,272 +0,0 @@ -# Copyright (c) 2014 Cisco Systems -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Henry Gessau, Cisco Systems - -import mock -import requests -import requests.exceptions - -from neutron.plugins.ml2.drivers.cisco.apic import apic_client as apic -from neutron.plugins.ml2.drivers.cisco.apic import exceptions as cexc -from neutron.tests import base -from neutron.tests.unit.ml2.drivers.cisco.apic import ( - test_cisco_apic_common as mocked) - - -class TestCiscoApicClient(base.BaseTestCase, mocked.ControllerMixin): - - def setUp(self): - super(TestCiscoApicClient, self).setUp() - self.set_up_mocks() - self.apic = apic.RestClient(mocked.APIC_HOST) - self.addCleanup(mock.patch.stopall) - - def _mock_authenticate(self, timeout=300): - self.reset_reponses() - self.mock_apic_manager_login_responses(timeout=timeout) - self.apic.login(mocked.APIC_USR, mocked.APIC_PWD) - - def test_login_by_instantiation(self): - self.reset_reponses() - self.mock_apic_manager_login_responses() - apic2 = apic.RestClient(mocked.APIC_HOST, - usr=mocked.APIC_USR, pwd=mocked.APIC_PWD) - self.assertIsNotNone(apic2.authentication) - self.assertEqual(apic2.username, mocked.APIC_USR) - - def test_client_session_login_ok(self): - self._mock_authenticate() - self.assertEqual( - self.apic.authentication['userName'], mocked.APIC_USR) - self.assertTrue(self.apic.api_base.startswith('http://')) - self.assertEqual(self.apic.username, mocked.APIC_USR) - self.assertIsNotNone(self.apic.authentication) - self.apic = apic.RestClient(mocked.APIC_HOST, mocked.APIC_PORT, - ssl=True) - self.assertTrue(self.apic.api_base.startswith('https://')) - - def test_client_session_login_fail(self): - self.mock_error_post_response(requests.codes.unauthorized, - code='599', - text=u'Fake error') - self.assertRaises(cexc.ApicResponseNotOk, self.apic.login, - mocked.APIC_USR, mocked.APIC_PWD) - - def test_client_session_login_timeout(self): - self.response['post'].append(requests.exceptions.Timeout) - self.assertRaises(cexc.ApicHostNoResponse, self.apic.login, - mocked.APIC_USR, mocked.APIC_PWD) - - def test_client_session_logout_ok(self): - self.mock_response_for_post('aaaLogout') - self.apic.logout() - self.assertIsNone(self.apic.authentication) - # Multiple signouts should not cause an error - self.apic.logout() - self.assertIsNone(self.apic.authentication) - - def test_client_session_logout_fail(self): - self._mock_authenticate() - self.mock_error_post_response(requests.codes.timeout, - code='123', text='failed') - self.assertRaises(cexc.ApicResponseNotOk, self.apic.logout) - - def test_query_not_logged_in(self): - self.apic.authentication = None - self.assertRaises(cexc.ApicSessionNotLoggedIn, - self.apic.fvTenant.get, mocked.APIC_TENANT) - - def test_query_no_response(self): - self._mock_authenticate() - requests.Session.get = mock.Mock(return_value=None) - self.assertRaises(cexc.ApicHostNoResponse, - self.apic.fvTenant.get, mocked.APIC_TENANT) - - def test_query_error_response_no_data(self): - self._mock_authenticate() - self.mock_error_get_response(requests.codes.bad) # No error attrs. - self.assertRaises(cexc.ApicResponseNotOk, - self.apic.fvTenant.get, mocked.APIC_TENANT) - - def test_generic_get_data(self): - self._mock_authenticate() - self.mock_response_for_get('topSystem', name='ifc1') - top_system = self.apic.get_data('class/topSystem') - self.assertIsNotNone(top_system) - name = top_system[0]['topSystem']['attributes']['name'] - self.assertEqual(name, 'ifc1') - - def test_session_timeout_refresh_ok(self): - self._mock_authenticate(timeout=-1) - # Client will do refresh before getting tenant - self.mock_response_for_get('aaaLogin', token='ok', - refreshTimeoutSeconds=300) - self.mock_response_for_get('fvTenant', name=mocked.APIC_TENANT) - tenant = self.apic.fvTenant.get(mocked.APIC_TENANT) - self.assertEqual(tenant['name'], mocked.APIC_TENANT) - - def test_session_timeout_refresh_no_cookie(self): - self._mock_authenticate(timeout=-1) - # Client will do refresh before getting tenant - self.mock_response_for_get('aaaLogin', notoken='test') - self.assertRaises(cexc.ApicResponseNoCookie, - self.apic.fvTenant.get, mocked.APIC_TENANT) - - def test_session_timeout_refresh_error(self): - self._mock_authenticate(timeout=-1) - self.mock_error_get_response(requests.codes.timeout, - code='503', text=u'timed out') - self.assertRaises(cexc.ApicResponseNotOk, - self.apic.fvTenant.get, mocked.APIC_TENANT) - - def test_session_timeout_refresh_timeout_error(self): - self._mock_authenticate(timeout=-1) - # Client will try to get refresh, we fake a refresh error. - self.mock_error_get_response(requests.codes.bad_request, - code='403', - text=u'Token was invalid. Expired.') - # Client will then try to re-login. - self.mock_apic_manager_login_responses() - # Finally the client will try to get the tenant. - self.mock_response_for_get('fvTenant', name=mocked.APIC_TENANT) - tenant = self.apic.fvTenant.get(mocked.APIC_TENANT) - self.assertEqual(tenant['name'], mocked.APIC_TENANT) - - def test_lookup_mo_bad_token_retry(self): - self._mock_authenticate() - # For the first get request we mock a bad token. - self.mock_error_get_response(requests.codes.bad_request, - code='403', - text=u'Token was invalid. Expired.') - # Client will then try to re-login. - self.mock_apic_manager_login_responses() - # Then the client will retry to get the tenant. - self.mock_response_for_get('fvTenant', name=mocked.APIC_TENANT) - tenant = self.apic.fvTenant.get(mocked.APIC_TENANT) - self.assertEqual(tenant['name'], mocked.APIC_TENANT) - - def test_use_unsupported_managed_object(self): - self._mock_authenticate() - # unittest.assertRaises cannot catch exceptions raised in - # __getattr__, so we need to defer the evaluation using lambda. - self.assertRaises(cexc.ApicManagedObjectNotSupported, - lambda: self.apic.nonexistentObject) - - def test_lookup_nonexistant_mo(self): - self._mock_authenticate() - self.mock_response_for_get('fvTenant') - self.assertIsNone(self.apic.fvTenant.get(mocked.APIC_TENANT)) - - def test_lookup_existing_mo(self): - self._mock_authenticate() - self.mock_response_for_get('fvTenant', name='infra') - tenant = self.apic.fvTenant.get('infra') - self.assertEqual(tenant['name'], 'infra') - - def test_list_mos_ok(self): - self._mock_authenticate() - self.mock_response_for_get('fvTenant', name='t1') - self.mock_append_to_response('fvTenant', name='t2') - tlist = self.apic.fvTenant.list_all() - self.assertIsNotNone(tlist) - self.assertEqual(len(tlist), 2) - self.assertIn({'name': 't1'}, tlist) - self.assertIn({'name': 't2'}, tlist) - - def test_list_mo_names_ok(self): - self._mock_authenticate() - self.mock_response_for_get('fvTenant', name='t1') - self.mock_append_to_response('fvTenant', name='t2') - tnlist = self.apic.fvTenant.list_names() - self.assertIsNotNone(tnlist) - self.assertEqual(len(tnlist), 2) - self.assertIn('t1', tnlist) - self.assertIn('t2', tnlist) - - def test_list_mos_split_class_fail(self): - self._mock_authenticate() - self.mock_response_for_get('fvnsEncapBlk', name='Blk1') - encap_blks = self.apic.fvnsEncapBlk__vlan.list_all() - self.assertEqual(len(encap_blks), 1) - - def test_delete_mo_ok(self): - self._mock_authenticate() - self.mock_response_for_post('fvTenant') - self.assertTrue(self.apic.fvTenant.delete(mocked.APIC_TENANT)) - - def test_create_mo_ok(self): - self._mock_authenticate() - self.mock_response_for_post('fvTenant', name=mocked.APIC_TENANT) - self.mock_response_for_get('fvTenant', name=mocked.APIC_TENANT) - self.apic.fvTenant.create(mocked.APIC_TENANT) - tenant = self.apic.fvTenant.get(mocked.APIC_TENANT) - self.assertEqual(tenant['name'], mocked.APIC_TENANT) - - def test_create_mo_already_exists(self): - self._mock_authenticate() - self.mock_error_post_response(requests.codes.bad_request, - code='103', - text=u'Fake 103 error') - self.assertRaises(cexc.ApicResponseNotOk, - self.apic.vmmProvP.create, mocked.APIC_VMMP) - - def test_create_mo_with_prereq(self): - self._mock_authenticate() - self.mock_response_for_post('fvTenant', name=mocked.APIC_TENANT) - self.mock_response_for_post('fvBD', name=mocked.APIC_NETWORK) - self.mock_response_for_get('fvBD', name=mocked.APIC_NETWORK) - bd_args = mocked.APIC_TENANT, mocked.APIC_NETWORK - self.apic.fvBD.create(*bd_args) - network = self.apic.fvBD.get(*bd_args) - self.assertEqual(network['name'], mocked.APIC_NETWORK) - - def test_create_mo_prereq_exists(self): - self._mock_authenticate() - self.mock_response_for_post('vmmDomP', name=mocked.APIC_DOMAIN) - self.mock_response_for_get('vmmDomP', name=mocked.APIC_DOMAIN) - self.apic.vmmDomP.create(mocked.APIC_VMMP, mocked.APIC_DOMAIN) - dom = self.apic.vmmDomP.get(mocked.APIC_VMMP, mocked.APIC_DOMAIN) - self.assertEqual(dom['name'], mocked.APIC_DOMAIN) - - def test_create_mo_fails(self): - self._mock_authenticate() - self.mock_response_for_post('fvTenant', name=mocked.APIC_TENANT) - self.mock_error_post_response(requests.codes.bad_request, - code='not103', - text=u'Fake not103 error') - bd_args = mocked.APIC_TENANT, mocked.APIC_NETWORK - self.assertRaises(cexc.ApicResponseNotOk, - self.apic.fvBD.create, *bd_args) - - def test_update_mo(self): - self._mock_authenticate() - self.mock_response_for_post('fvTenant', name=mocked.APIC_TENANT) - self.mock_response_for_get('fvTenant', name=mocked.APIC_TENANT, - more='extra') - self.apic.fvTenant.update(mocked.APIC_TENANT, more='extra') - tenant = self.apic.fvTenant.get(mocked.APIC_TENANT) - self.assertEqual(tenant['name'], mocked.APIC_TENANT) - self.assertEqual(tenant['more'], 'extra') - - def test_attr_fail_empty_list(self): - self._mock_authenticate() - self.mock_response_for_get('fvTenant') # No attrs for tenant. - self.assertIsNone(self.apic.fvTenant.get(mocked.APIC_TENANT)) - - def test_attr_fail_other_obj(self): - self._mock_authenticate() - self.mock_response_for_get('other', name=mocked.APIC_TENANT) - self.assertIsNone(self.apic.fvTenant.get(mocked.APIC_TENANT)) diff --git a/neutron/tests/unit/ml2/drivers/cisco/apic/test_cisco_apic_common.py b/neutron/tests/unit/ml2/drivers/cisco/apic/test_cisco_apic_common.py deleted file mode 100644 index e150c1f09..000000000 --- a/neutron/tests/unit/ml2/drivers/cisco/apic/test_cisco_apic_common.py +++ /dev/null @@ -1,225 +0,0 @@ -# Copyright (c) 2014 Cisco Systems -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Henry Gessau, Cisco Systems - -import mock -import requests - -from oslo.config import cfg - -from neutron.common import config as neutron_config -from neutron.plugins.ml2 import config as ml2_config -from neutron.plugins.ml2.drivers.cisco.apic import apic_client as apic -from neutron.tests import base - - -OK = requests.codes.ok - -APIC_HOST = 'fake.controller.local' -APIC_PORT = 7580 -APIC_USR = 'notadmin' -APIC_PWD = 'topsecret' - -APIC_TENANT = 'citizen14' -APIC_NETWORK = 'network99' -APIC_NETNAME = 'net99name' -APIC_SUBNET = '10.3.2.1/24' -APIC_L3CTX = 'layer3context' -APIC_AP = 'appProfile001' -APIC_EPG = 'endPointGroup001' - -APIC_CONTRACT = 'signedContract' -APIC_SUBJECT = 'testSubject' -APIC_FILTER = 'carbonFilter' -APIC_ENTRY = 'forcedEntry' - -APIC_VMMP = 'OpenStack' -APIC_DOMAIN = 'cumuloNimbus' -APIC_PDOM = 'rainStorm' - -APIC_NODE_PROF = 'red' -APIC_LEAF = 'green' -APIC_LEAF_TYPE = 'range' -APIC_NODE_BLK = 'blue' -APIC_PORT_PROF = 'yellow' -APIC_PORT_SEL = 'front' -APIC_PORT_TYPE = 'range' -APIC_PORT_BLK1 = 'block01' -APIC_PORT_BLK2 = 'block02' -APIC_ACC_PORT_GRP = 'alpha' -APIC_FUNC_PROF = 'beta' -APIC_ATT_ENT_PROF = 'delta' -APIC_VLAN_NAME = 'gamma' -APIC_VLAN_MODE = 'dynamic' -APIC_VLANID_FROM = 2900 -APIC_VLANID_TO = 2999 -APIC_VLAN_FROM = 'vlan-%d' % APIC_VLANID_FROM -APIC_VLAN_TO = 'vlan-%d' % APIC_VLANID_TO - - -class ControllerMixin(object): - - """Mock the controller for APIC driver and service unit tests.""" - - def __init__(self): - self.response = None - - def set_up_mocks(self): - # The mocked responses from the server are lists used by - # mock.side_effect, which means each call to post or get will - # return the next item in the list. This allows the test cases - # to stage a sequence of responses to method(s) under test. - self.response = {'post': [], 'get': []} - self.reset_reponses() - - def reset_reponses(self, req=None): - # Clear all staged responses. - reqs = req and [req] or ['post', 'get'] # Both if none specified. - for req in reqs: - del self.response[req][:] - self.restart_responses(req) - - def restart_responses(self, req): - responses = mock.MagicMock(side_effect=self.response[req]) - if req == 'post': - requests.Session.post = responses - elif req == 'get': - requests.Session.get = responses - - def mock_response_for_post(self, mo, **attrs): - attrs['debug_mo'] = mo # useful for debugging - self._stage_mocked_response('post', OK, mo, **attrs) - - def mock_response_for_get(self, mo, **attrs): - self._stage_mocked_response('get', OK, mo, **attrs) - - def mock_append_to_response(self, mo, **attrs): - # Append a MO to the last get response. - mo_attrs = attrs and {mo: {'attributes': attrs}} or {} - self.response['get'][-1].json.return_value['imdata'].append(mo_attrs) - - def mock_error_post_response(self, status, **attrs): - self._stage_mocked_response('post', status, 'error', **attrs) - - def mock_error_get_response(self, status, **attrs): - self._stage_mocked_response('get', status, 'error', **attrs) - - def _stage_mocked_response(self, req, mock_status, mo, **attrs): - response = mock.MagicMock() - response.status_code = mock_status - mo_attrs = attrs and [{mo: {'attributes': attrs}}] or [] - response.json.return_value = {'imdata': mo_attrs} - self.response[req].append(response) - - def mock_responses_for_create(self, obj): - self._mock_container_responses_for_create( - apic.ManagedObjectClass(obj).container) - name = '-'.join([obj, 'name']) # useful for debugging - self._stage_mocked_response('post', OK, obj, name=name) - - def _mock_container_responses_for_create(self, obj): - # Recursively generate responses for creating obj's containers. - if obj: - mo = apic.ManagedObjectClass(obj) - if mo.can_create: - if mo.container: - self._mock_container_responses_for_create(mo.container) - name = '-'.join([obj, 'name']) # useful for debugging - self._stage_mocked_response('post', OK, obj, debug_name=name) - - def mock_apic_manager_login_responses(self, timeout=300): - # APIC Manager tests are based on authenticated session - self.mock_response_for_post('aaaLogin', userName=APIC_USR, - token='ok', refreshTimeoutSeconds=timeout) - - def assert_responses_drained(self, req=None): - """Fail if all the expected responses have not been consumed.""" - request = {'post': self.session.post, 'get': self.session.get} - reqs = req and [req] or ['post', 'get'] # Both if none specified. - for req in reqs: - try: - request[req]('some url') - except StopIteration: - pass - else: - # User-friendly error message - msg = req + ' response queue not drained' - self.fail(msg=msg) - - -class ConfigMixin(object): - - """Mock the config for APIC driver and service unit tests.""" - - def __init__(self): - self.mocked_parser = None - - def set_up_mocks(self): - # Mock the configuration file - args = ['--config-file', base.etcdir('neutron.conf.test')] - neutron_config.init(args=args) - - # Configure the ML2 mechanism drivers and network types - ml2_opts = { - 'mechanism_drivers': ['apic'], - 'tenant_network_types': ['vlan'], - } - for opt, val in ml2_opts.items(): - ml2_config.cfg.CONF.set_override(opt, val, 'ml2') - - # Configure the Cisco APIC mechanism driver - apic_test_config = { - 'apic_host': APIC_HOST, - 'apic_username': APIC_USR, - 'apic_password': APIC_PWD, - 'apic_port': APIC_PORT, - 'apic_vmm_domain': APIC_DOMAIN, - 'apic_vlan_ns_name': APIC_VLAN_NAME, - 'apic_vlan_range': '%d:%d' % (APIC_VLANID_FROM, APIC_VLANID_TO), - 'apic_node_profile': APIC_NODE_PROF, - 'apic_entity_profile': APIC_ATT_ENT_PROF, - 'apic_function_profile': APIC_FUNC_PROF, - } - for opt, val in apic_test_config.items(): - cfg.CONF.set_override(opt, val, 'ml2_cisco_apic') - - apic_switch_cfg = { - 'apic_switch:east01': {'ubuntu1,ubuntu2': ['3/11']}, - 'apic_switch:east02': {'rhel01,rhel02': ['4/21'], - 'rhel03': ['4/22']}, - } - self.mocked_parser = mock.patch.object(cfg, - 'MultiConfigParser').start() - self.mocked_parser.return_value.read.return_value = [apic_switch_cfg] - self.mocked_parser.return_value.parsed = [apic_switch_cfg] - - -class DbModelMixin(object): - - """Mock the DB models for the APIC driver and service unit tests.""" - - def __init__(self): - self.mocked_session = None - - def set_up_mocks(self): - self.mocked_session = mock.Mock() - get_session = mock.patch('neutron.db.api.get_session').start() - get_session.return_value = self.mocked_session - - def mock_db_query_filterby_first_return(self, value): - """Mock db.session.query().filterby().first() to return value.""" - query = self.mocked_session.query.return_value - query.filter_by.return_value.first.return_value = value diff --git a/neutron/tests/unit/ml2/drivers/cisco/apic/test_cisco_apic_manager.py b/neutron/tests/unit/ml2/drivers/cisco/apic/test_cisco_apic_manager.py deleted file mode 100644 index 24a2c217d..000000000 --- a/neutron/tests/unit/ml2/drivers/cisco/apic/test_cisco_apic_manager.py +++ /dev/null @@ -1,698 +0,0 @@ -# Copyright (c) 2014 Cisco Systems -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Henry Gessau, Cisco Systems - -import mock -from webob import exc as wexc - -from neutron.openstack.common import uuidutils - -from neutron.plugins.ml2.drivers.cisco.apic import apic_manager -from neutron.plugins.ml2.drivers.cisco.apic import exceptions as cexc -from neutron.tests import base -from neutron.tests.unit.ml2.drivers.cisco.apic import ( - test_cisco_apic_common as mocked) - - -class TestCiscoApicManager(base.BaseTestCase, - mocked.ControllerMixin, - mocked.ConfigMixin, - mocked.DbModelMixin): - - def setUp(self): - super(TestCiscoApicManager, self).setUp() - mocked.ControllerMixin.set_up_mocks(self) - mocked.ConfigMixin.set_up_mocks(self) - mocked.DbModelMixin.set_up_mocks(self) - - self.mock_apic_manager_login_responses() - self.mgr = apic_manager.APICManager() - self.session = self.mgr.apic.session - self.assert_responses_drained() - self.reset_reponses() - - def test_mgr_session_login(self): - login = self.mgr.apic.authentication - self.assertEqual(login['userName'], mocked.APIC_USR) - - def test_mgr_session_logout(self): - self.mock_response_for_post('aaaLogout') - self.mgr.apic.logout() - self.assert_responses_drained() - self.assertIsNone(self.mgr.apic.authentication) - - def test_to_range(self): - port_list = [4, 2, 3, 1, 7, 8, 10, 20, 6, 22, 21] - expected_ranges = [(1, 4), (6, 8), (10, 10), (20, 22)] - port_ranges = [r for r in apic_manager.group_by_ranges(port_list)] - self.assertEqual(port_ranges, expected_ranges) - - def test_get_profiles(self): - self.mock_db_query_filterby_first_return('faked') - self.assertEqual( - self.mgr.db.get_port_profile_for_node('node'), - 'faked' - ) - self.assertEqual( - self.mgr.db.get_profile_for_module('node', 'prof', 'module'), - 'faked' - ) - self.assertEqual( - self.mgr.db.get_profile_for_module_and_ports( - 'node', 'prof', 'module', 'from', 'to' - ), - 'faked' - ) - - def test_add_profile(self): - self.mgr.db.add_profile_for_module_and_ports( - 'node', 'prof', 'hpselc', 'module', 'from', 'to') - self.assertTrue(self.mocked_session.add.called) - self.assertTrue(self.mocked_session.flush.called) - - def test_ensure_port_profile_created(self): - port_name = mocked.APIC_PORT - self.mock_responses_for_create('infraAccPortP') - self.mock_response_for_get('infraAccPortP', name=port_name) - port = self.mgr.ensure_port_profile_created_on_apic(port_name) - self.assert_responses_drained() - self.assertEqual(port['name'], port_name) - - def test_ensure_port_profile_created_exc(self): - port_name = mocked.APIC_PORT - self.mock_error_post_response(wexc.HTTPBadRequest) - self.mock_response_for_post('infraAccPortP') - self.assertRaises(cexc.ApicResponseNotOk, - self.mgr.ensure_port_profile_created_on_apic, - port_name) - self.assert_responses_drained() - - def test_ensure_node_profile_created_for_switch_old(self): - old_switch = mocked.APIC_NODE_PROF - self.mock_response_for_get('infraNodeP', name=old_switch) - self.mgr.ensure_node_profile_created_for_switch(old_switch) - self.assert_responses_drained() - old_name = self.mgr.node_profiles[old_switch]['object']['name'] - self.assertEqual(old_name, old_switch) - - def test_ensure_node_profile_created_for_switch_new(self): - new_switch = mocked.APIC_NODE_PROF - self.mock_response_for_get('infraNodeP') - self.mock_responses_for_create('infraNodeP') - self.mock_responses_for_create('infraLeafS') - self.mock_responses_for_create('infraNodeBlk') - self.mock_response_for_get('infraNodeP', name=new_switch) - self.mgr.ensure_node_profile_created_for_switch(new_switch) - self.assert_responses_drained() - new_name = self.mgr.node_profiles[new_switch]['object']['name'] - self.assertEqual(new_name, new_switch) - - def test_ensure_node_profile_created_for_switch_new_exc(self): - new_switch = mocked.APIC_NODE_PROF - self.mock_response_for_get('infraNodeP') - self.mock_error_post_response(wexc.HTTPBadRequest) - self.mock_response_for_post('infraNodeP') - self.assertRaises(cexc.ApicResponseNotOk, - self.mgr.ensure_node_profile_created_for_switch, - new_switch) - self.assert_responses_drained() - - def test_ensure_vmm_domain_created_old(self): - dom = mocked.APIC_DOMAIN - self.mock_response_for_get('vmmDomP', name=dom) - self.mgr.ensure_vmm_domain_created_on_apic(dom) - self.assert_responses_drained() - old_dom = self.mgr.vmm_domain['name'] - self.assertEqual(old_dom, dom) - - def _mock_new_vmm_dom_responses(self, dom, seg_type=None): - vmm = mocked.APIC_VMMP - dn = self.mgr.apic.vmmDomP.mo.dn(vmm, dom) - self.mock_response_for_get('vmmDomP') - self.mock_responses_for_create('vmmDomP') - if seg_type: - self.mock_responses_for_create(seg_type) - self.mock_response_for_get('vmmDomP', name=dom, dn=dn) - - def test_ensure_vmm_domain_created_new_no_vlan_ns(self): - dom = mocked.APIC_DOMAIN - self._mock_new_vmm_dom_responses(dom) - self.mgr.ensure_vmm_domain_created_on_apic(dom) - self.assert_responses_drained() - new_dom = self.mgr.vmm_domain['name'] - self.assertEqual(new_dom, dom) - - def test_ensure_vmm_domain_created_new_no_vlan_ns_exc(self): - dom = mocked.APIC_DOMAIN - self.mock_response_for_get('vmmDomP') - self.mock_error_post_response(wexc.HTTPBadRequest) - self.mock_response_for_post('vmmDomP') - self.assertRaises(cexc.ApicResponseNotOk, - self.mgr.ensure_vmm_domain_created_on_apic, dom) - self.assert_responses_drained() - - def test_ensure_vmm_domain_created_new_with_vlan_ns(self): - dom = mocked.APIC_DOMAIN - self._mock_new_vmm_dom_responses(dom, seg_type='infraRsVlanNs__vmm') - ns = {'dn': 'test_vlan_ns'} - self.mgr.ensure_vmm_domain_created_on_apic(dom, vlan_ns=ns) - self.assert_responses_drained() - new_dom = self.mgr.vmm_domain['name'] - self.assertEqual(new_dom, dom) - - def test_ensure_vmm_domain_created_new_with_vxlan_ns(self): - dom = mocked.APIC_DOMAIN - # TODO(Henry): mock seg_type vxlan when vxlan is ready - self._mock_new_vmm_dom_responses(dom, seg_type=None) - ns = {'dn': 'test_vxlan_ns'} - self.mgr.ensure_vmm_domain_created_on_apic(dom, vxlan_ns=ns) - self.assert_responses_drained() - new_dom = self.mgr.vmm_domain['name'] - self.assertEqual(new_dom, dom) - - def test_ensure_infra_created_no_infra(self): - self.mgr.switch_dict = {} - self.mgr.ensure_infra_created_on_apic() - - def _ensure_infra_created_seq1_setup(self): - am = 'neutron.plugins.ml2.drivers.cisco.apic.apic_manager.APICManager' - np_create_for_switch = mock.patch( - am + '.ensure_node_profile_created_for_switch').start() - self.mock_db_query_filterby_first_return(None) - pp_create_for_switch = mock.patch( - am + '.ensure_port_profile_created_on_apic').start() - pp_create_for_switch.return_value = {'dn': 'port_profile_dn'} - return np_create_for_switch, pp_create_for_switch - - def test_ensure_infra_created_seq1(self): - np_create_for_switch, pp_create_for_switch = ( - self._ensure_infra_created_seq1_setup()) - - def _profile_for_module(aswitch, ppn, module): - profile = mock.Mock() - profile.ppn = ppn - profile.hpselc_id = '-'.join([aswitch, module, 'hpselc_id']) - return profile - - self.mgr.db.get_profile_for_module = mock.Mock( - side_effect=_profile_for_module) - self.mgr.db.get_profile_for_module_and_ports = mock.Mock( - return_value=None) - self.mgr.db.add_profile_for_module_and_ports = mock.Mock() - - num_switches = len(self.mgr.switch_dict) - for loop in range(num_switches): - self.mock_responses_for_create('infraRsAccPortP') - self.mock_responses_for_create('infraPortBlk') - - self.mgr.ensure_infra_created_on_apic() - self.assert_responses_drained() - self.assertEqual(np_create_for_switch.call_count, num_switches) - self.assertEqual(pp_create_for_switch.call_count, num_switches) - for switch in self.mgr.switch_dict: - np_create_for_switch.assert_any_call(switch) - - def test_ensure_infra_created_seq1_exc(self): - np_create_for_switch, __ = self._ensure_infra_created_seq1_setup() - self.mock_error_post_response(wexc.HTTPBadRequest) - self.mock_response_for_post('infraAccPortP') - - self.assertRaises(cexc.ApicResponseNotOk, - self.mgr.ensure_infra_created_on_apic) - self.assert_responses_drained() - self.assertTrue(np_create_for_switch.called) - self.assertEqual(np_create_for_switch.call_count, 1) - - def _ensure_infra_created_seq2_setup(self): - am = 'neutron.plugins.ml2.drivers.cisco.apic.apic_manager.APICManager' - np_create_for_switch = mock.patch( - am + '.ensure_node_profile_created_for_switch').start() - - def _profile_for_node(aswitch): - profile = mock.Mock() - profile.profile_id = '-'.join([aswitch, 'profile_id']) - return profile - - self.mgr.db.get_port_profile_for_node = mock.Mock( - side_effect=_profile_for_node) - self.mgr.db.get_profile_for_module = mock.Mock( - return_value=None) - self.mgr.function_profile = {'dn': 'dn'} - self.mgr.db.get_profile_for_module_and_ports = mock.Mock( - return_value=True) - - return np_create_for_switch - - def test_ensure_infra_created_seq2(self): - np_create_for_switch = self._ensure_infra_created_seq2_setup() - - num_switches = len(self.mgr.switch_dict) - for loop in range(num_switches): - self.mock_responses_for_create('infraHPortS') - self.mock_responses_for_create('infraRsAccBaseGrp') - - self.mgr.ensure_infra_created_on_apic() - self.assert_responses_drained() - self.assertEqual(np_create_for_switch.call_count, num_switches) - for switch in self.mgr.switch_dict: - np_create_for_switch.assert_any_call(switch) - - def test_ensure_infra_created_seq2_exc(self): - np_create_for_switch = self._ensure_infra_created_seq2_setup() - - self.mock_error_post_response(wexc.HTTPBadRequest) - self.mock_response_for_post('infraHPortS') - - self.assertRaises(cexc.ApicResponseNotOk, - self.mgr.ensure_infra_created_on_apic) - self.assert_responses_drained() - self.assertTrue(np_create_for_switch.called) - self.assertEqual(np_create_for_switch.call_count, 1) - - def test_ensure_context_unenforced_new_ctx(self): - self.mock_response_for_get('fvCtx') - self.mock_responses_for_create('fvCtx') - self.mgr.ensure_context_unenforced() - self.assert_responses_drained() - - def test_ensure_context_unenforced_pref1(self): - self.mock_response_for_get('fvCtx', pcEnfPref='1') - self.mock_response_for_post('fvCtx') - self.mgr.ensure_context_unenforced() - self.assert_responses_drained() - - def test_ensure_context_unenforced_pref2(self): - self.mock_response_for_get('fvCtx', pcEnfPref='2') - self.mgr.ensure_context_unenforced() - self.assert_responses_drained() - - def _mock_vmm_dom_prereq(self, dom): - self._mock_new_vmm_dom_responses(dom) - self.mgr.ensure_vmm_domain_created_on_apic(dom) - - def _mock_new_phys_dom_responses(self, dom, seg_type=None): - dn = self.mgr.apic.physDomP.mo.dn(dom) - self.mock_response_for_get('physDomP') - self.mock_responses_for_create('physDomP') - if seg_type: - self.mock_responses_for_create(seg_type) - self.mock_response_for_get('physDomP', name=dom, dn=dn) - - def _mock_phys_dom_prereq(self, dom): - self._mock_new_phys_dom_responses(dom) - self.mgr.ensure_phys_domain_created_on_apic(dom) - - def test_ensure_entity_profile_created_old(self): - ep = mocked.APIC_ATT_ENT_PROF - self.mock_response_for_get('infraAttEntityP', name=ep) - self.mgr.ensure_entity_profile_created_on_apic(ep) - self.assert_responses_drained() - - def _mock_new_entity_profile(self, exc=None): - self.mock_response_for_get('infraAttEntityP') - self.mock_responses_for_create('infraAttEntityP') - self.mock_responses_for_create('infraRsDomP') - if exc: - self.mock_error_get_response(exc, code='103', text=u'Fail') - else: - self.mock_response_for_get('infraAttEntityP') - - def test_ensure_entity_profile_created_new(self): - self._mock_phys_dom_prereq(mocked.APIC_PDOM) - ep = mocked.APIC_ATT_ENT_PROF - self._mock_new_entity_profile() - self.mgr.ensure_entity_profile_created_on_apic(ep) - self.assert_responses_drained() - - def test_ensure_entity_profile_created_new_exc(self): - self._mock_phys_dom_prereq(mocked.APIC_PDOM) - ep = mocked.APIC_ATT_ENT_PROF - self._mock_new_entity_profile(exc=wexc.HTTPBadRequest) - self.mock_response_for_post('infraAttEntityP') - self.assertRaises(cexc.ApicResponseNotOk, - self.mgr.ensure_entity_profile_created_on_apic, ep) - self.assert_responses_drained() - - def _mock_entity_profile_preqreq(self): - self._mock_phys_dom_prereq(mocked.APIC_PDOM) - ep = mocked.APIC_ATT_ENT_PROF - self._mock_new_entity_profile() - self.mgr.ensure_entity_profile_created_on_apic(ep) - - def test_ensure_function_profile_created_old(self): - self._mock_entity_profile_preqreq() - fp = mocked.APIC_FUNC_PROF - self.mock_response_for_get('infraAccPortGrp', name=fp) - self.mgr.ensure_function_profile_created_on_apic(fp) - self.assert_responses_drained() - old_fp = self.mgr.function_profile['name'] - self.assertEqual(old_fp, fp) - - def _mock_new_function_profile(self, fp): - dn = self.mgr.apic.infraAttEntityP.mo.dn(fp) - self.mock_responses_for_create('infraAccPortGrp') - self.mock_responses_for_create('infraRsAttEntP') - self.mock_response_for_get('infraAccPortGrp', name=fp, dn=dn) - - def test_ensure_function_profile_created_new(self): - fp = mocked.APIC_FUNC_PROF - dn = self.mgr.apic.infraAttEntityP.mo.dn(fp) - self.mgr.entity_profile = {'dn': dn} - self.mock_response_for_get('infraAccPortGrp') - self.mock_responses_for_create('infraAccPortGrp') - self.mock_responses_for_create('infraRsAttEntP') - self.mock_response_for_get('infraAccPortGrp', name=fp, dn=dn) - self.mgr.ensure_function_profile_created_on_apic(fp) - self.assert_responses_drained() - new_fp = self.mgr.function_profile['name'] - self.assertEqual(new_fp, fp) - - def test_ensure_function_profile_created_new_exc(self): - fp = mocked.APIC_FUNC_PROF - dn = self.mgr.apic.infraAttEntityP.mo.dn(fp) - self.mgr.entity_profile = {'dn': dn} - self.mock_response_for_get('infraAccPortGrp') - self.mock_error_post_response(wexc.HTTPBadRequest) - self.mock_response_for_post('infraAccPortGrp') - self.assertRaises(cexc.ApicResponseNotOk, - self.mgr.ensure_function_profile_created_on_apic, fp) - self.assert_responses_drained() - - def test_ensure_vlan_ns_created_old(self): - ns = mocked.APIC_VLAN_NAME - mode = mocked.APIC_VLAN_MODE - self.mock_response_for_get('fvnsVlanInstP', name=ns, mode=mode) - new_ns = self.mgr.ensure_vlan_ns_created_on_apic(ns, '100', '199') - self.assert_responses_drained() - self.assertIsNone(new_ns) - - def _mock_new_vlan_instance(self, ns, vlan_encap=None): - self.mock_responses_for_create('fvnsVlanInstP') - if vlan_encap: - self.mock_response_for_get('fvnsEncapBlk', **vlan_encap) - else: - self.mock_response_for_get('fvnsEncapBlk') - self.mock_responses_for_create('fvnsEncapBlk__vlan') - self.mock_response_for_get('fvnsVlanInstP', name=ns) - - def test_ensure_vlan_ns_created_new_no_encap(self): - ns = mocked.APIC_VLAN_NAME - self.mock_response_for_get('fvnsVlanInstP') - self._mock_new_vlan_instance(ns) - new_ns = self.mgr.ensure_vlan_ns_created_on_apic(ns, '200', '299') - self.assert_responses_drained() - self.assertEqual(new_ns['name'], ns) - - def test_ensure_vlan_ns_created_new_exc(self): - ns = mocked.APIC_VLAN_NAME - self.mock_response_for_get('fvnsVlanInstP') - self.mock_error_post_response(wexc.HTTPBadRequest) - self.mock_response_for_post('fvnsVlanInstP') - self.assertRaises(cexc.ApicResponseNotOk, - self.mgr.ensure_vlan_ns_created_on_apic, - ns, '200', '299') - self.assert_responses_drained() - - def test_ensure_vlan_ns_created_new_with_encap(self): - ns = mocked.APIC_VLAN_NAME - self.mock_response_for_get('fvnsVlanInstP') - ns_args = {'name': 'encap', 'from': '300', 'to': '399'} - self._mock_new_vlan_instance(ns, vlan_encap=ns_args) - new_ns = self.mgr.ensure_vlan_ns_created_on_apic(ns, '300', '399') - self.assert_responses_drained() - self.assertEqual(new_ns['name'], ns) - - def test_ensure_tenant_created_on_apic(self): - self.mock_response_for_get('fvTenant', name='any') - self.mgr.ensure_tenant_created_on_apic('two') - self.mock_response_for_get('fvTenant') - self.mock_responses_for_create('fvTenant') - self.mgr.ensure_tenant_created_on_apic('four') - self.assert_responses_drained() - - def test_ensure_bd_created_existing_bd(self): - self.mock_response_for_get('fvBD', name='BD') - self.mgr.ensure_bd_created_on_apic('t1', 'two') - self.assert_responses_drained() - - def test_ensure_bd_created_not_ctx(self): - self.mock_response_for_get('fvBD') - self.mock_responses_for_create('fvBD') - self.mock_response_for_get('fvCtx') - self.mock_responses_for_create('fvCtx') - self.mock_responses_for_create('fvRsCtx') - self.mgr.ensure_bd_created_on_apic('t2', 'three') - self.assert_responses_drained() - - def test_ensure_bd_created_exc(self): - self.mock_response_for_get('fvBD') - self.mock_error_post_response(wexc.HTTPBadRequest) - self.mock_response_for_post('fvBD') - self.assertRaises(cexc.ApicResponseNotOk, - self.mgr.ensure_bd_created_on_apic, 't2', 'three') - self.assert_responses_drained() - - def test_ensure_bd_created_ctx_pref1(self): - self.mock_response_for_get('fvBD') - self.mock_responses_for_create('fvBD') - self.mock_response_for_get('fvCtx', pcEnfPref='1') - self.mock_responses_for_create('fvRsCtx') - self.mgr.ensure_bd_created_on_apic('t3', 'four') - self.assert_responses_drained() - - def test_ensure_bd_created_ctx_pref2(self): - self.mock_response_for_get('fvBD') - self.mock_responses_for_create('fvBD') - self.mock_response_for_get('fvCtx', pcEnfPref='2') - self.mock_response_for_post('fvCtx') - self.mock_responses_for_create('fvRsCtx') - self.mgr.ensure_bd_created_on_apic('t3', 'four') - self.assert_responses_drained() - - def test_delete_bd(self): - self.mock_response_for_post('fvBD') - self.mgr.delete_bd_on_apic('t1', 'bd') - self.assert_responses_drained() - - def test_ensure_subnet_created(self): - self.mock_response_for_get('fvSubnet', name='sn1') - self.mgr.ensure_subnet_created_on_apic('t0', 'bd1', '2.2.2.2/8') - self.mock_response_for_get('fvSubnet') - self.mock_responses_for_create('fvSubnet') - self.mgr.ensure_subnet_created_on_apic('t2', 'bd3', '4.4.4.4/16') - self.assert_responses_drained() - - def test_ensure_filter_created(self): - self.mock_response_for_get('vzFilter', name='f1') - self.mgr.ensure_filter_created_on_apic('t1', 'two') - self.mock_response_for_get('vzFilter') - self.mock_responses_for_create('vzFilter') - self.mgr.ensure_filter_created_on_apic('t2', 'four') - self.assert_responses_drained() - - def test_ensure_epg_created_for_network_old(self): - self.mock_db_query_filterby_first_return('faked') - epg = self.mgr.ensure_epg_created_for_network('X', 'Y', 'Z') - self.assertEqual(epg, 'faked') - - def test_ensure_epg_created_for_network_new(self): - tenant = mocked.APIC_TENANT - network = mocked.APIC_NETWORK - netname = mocked.APIC_NETNAME - self._mock_phys_dom_prereq(mocked.APIC_PDOM) - self.mock_db_query_filterby_first_return(None) - self.mock_responses_for_create('fvAEPg') - self.mock_response_for_get('fvBD', name=network) - self.mock_responses_for_create('fvRsBd') - self.mock_responses_for_create('fvRsDomAtt') - new_epg = self.mgr.ensure_epg_created_for_network(tenant, - network, netname) - self.assert_responses_drained() - self.assertEqual(new_epg.network_id, network) - self.assertTrue(self.mocked_session.add.called) - self.assertTrue(self.mocked_session.flush.called) - - def test_ensure_epg_created_for_network_exc(self): - tenant = mocked.APIC_TENANT - network = mocked.APIC_NETWORK - netname = mocked.APIC_NETNAME - self.mock_db_query_filterby_first_return(None) - self.mock_error_post_response(wexc.HTTPBadRequest) - self.mock_response_for_post('fvAEPg') - self.assertRaises(cexc.ApicResponseNotOk, - self.mgr.ensure_epg_created_for_network, - tenant, network, netname) - self.assert_responses_drained() - - def test_delete_epg_for_network_no_epg(self): - self.mock_db_query_filterby_first_return(None) - self.mgr.delete_epg_for_network('tenant', 'network') - - def test_delete_epg_for_network(self): - epg = mock.Mock() - epg.epg_id = mocked.APIC_EPG - self.mock_db_query_filterby_first_return(epg) - self.mock_response_for_post('fvAEPg') - self.mgr.delete_epg_for_network('tenant', 'network') - self.assertTrue(self.mocked_session.delete.called) - self.assertTrue(self.mocked_session.flush.called) - - def test_ensure_path_created_for_port(self): - epg = mock.Mock() - epg.epg_id = 'epg01' - eepg = mock.Mock(return_value=epg) - apic_manager.APICManager.ensure_epg_created_for_network = eepg - self.mock_response_for_get('fvRsPathAtt', tDn='foo') - self.mgr.ensure_path_created_for_port('tenant', 'network', 'rhel01', - 'static', 'netname') - self.assert_responses_drained() - - def test_ensure_path_created_for_port_no_path_att(self): - epg = mock.Mock() - epg.epg_id = 'epg2' - eepg = mock.Mock(return_value=epg) - self.mgr.ensure_epg_created_for_network = eepg - self.mock_response_for_get('fvRsPathAtt') - self.mock_responses_for_create('fvRsPathAtt') - self.mgr.ensure_path_created_for_port('tenant', 'network', 'ubuntu2', - 'static', 'netname') - self.assert_responses_drained() - - def test_ensure_path_created_for_port_unknown_host(self): - epg = mock.Mock() - epg.epg_id = 'epg3' - eepg = mock.Mock(return_value=epg) - apic_manager.APICManager.ensure_epg_created_for_network = eepg - self.mock_response_for_get('fvRsPathAtt', tDn='foo') - self.assertRaises(cexc.ApicHostNotConfigured, - self.mgr.ensure_path_created_for_port, - 'tenant', 'network', 'cirros3', 'static', 'netname') - - def test_create_tenant_filter(self): - tenant = mocked.APIC_TENANT - self.mock_responses_for_create('vzFilter') - self.mock_responses_for_create('vzEntry') - filter_id = self.mgr.create_tenant_filter(tenant) - self.assert_responses_drained() - self.assertTrue(uuidutils.is_uuid_like(str(filter_id))) - - def test_create_tenant_filter_exc(self): - tenant = mocked.APIC_TENANT - self.mock_error_post_response(wexc.HTTPBadRequest) - self.mock_response_for_post('vzFilter') - self.assertRaises(cexc.ApicResponseNotOk, - self.mgr.create_tenant_filter, tenant) - self.assert_responses_drained() - - def test_set_contract_for_epg_consumer(self): - tenant = mocked.APIC_TENANT - epg = mocked.APIC_EPG - contract = mocked.APIC_CONTRACT - self.mock_responses_for_create('fvRsCons') - self.mgr.set_contract_for_epg(tenant, epg, contract) - self.assert_responses_drained() - - def test_set_contract_for_epg_provider(self): - tenant = mocked.APIC_TENANT - epg = mocked.APIC_EPG - contract = mocked.APIC_CONTRACT - epg_obj = mock.Mock() - epg_obj.epg_id = epg - epg_obj.provider = False - self.mock_db_query_filterby_first_return(epg_obj) - self.mock_responses_for_create('fvRsProv') - self.mock_response_for_post('vzBrCP') - self.mgr.set_contract_for_epg(tenant, epg, contract, provider=True) - self.assert_responses_drained() - self.assertTrue(self.mocked_session.merge.called) - self.assertTrue(self.mocked_session.flush.called) - self.assertTrue(epg_obj.provider) - - def test_set_contract_for_epg_provider_exc(self): - tenant = mocked.APIC_TENANT - epg = mocked.APIC_EPG - contract = mocked.APIC_CONTRACT - self.mock_error_post_response(wexc.HTTPBadRequest) - self.mock_response_for_post('vzBrCP') - self.mock_response_for_post('fvRsProv') - self.assertRaises(cexc.ApicResponseNotOk, - self.mgr.set_contract_for_epg, - tenant, epg, contract, provider=True) - self.assert_responses_drained() - - def test_delete_contract_for_epg_consumer(self): - tenant = mocked.APIC_TENANT - epg = mocked.APIC_EPG - contract = mocked.APIC_CONTRACT - self.mock_response_for_post('fvRsCons') - self.mgr.delete_contract_for_epg(tenant, epg, contract) - self.assert_responses_drained() - - def test_delete_contract_for_epg_provider(self): - tenant = mocked.APIC_TENANT - epg = mocked.APIC_EPG - contract = mocked.APIC_CONTRACT - epg_obj = mock.Mock() - epg_obj.epg_id = epg + '-other' - epg_obj.provider = False - self.mock_db_query_filterby_first_return(epg_obj) - self.mock_response_for_post('fvRsProv') - self.mock_response_for_post('fvRsCons') - self.mock_responses_for_create('fvRsProv') - self.mock_response_for_post('vzBrCP') - self.mgr.delete_contract_for_epg(tenant, epg, contract, provider=True) - self.assert_responses_drained() - self.assertTrue(self.mocked_session.merge.called) - self.assertTrue(self.mocked_session.flush.called) - self.assertTrue(epg_obj.provider) - - def test_create_tenant_contract_existing(self): - tenant = mocked.APIC_TENANT - contract = mocked.APIC_CONTRACT - self.mock_db_query_filterby_first_return(contract) - new_contract = self.mgr.create_tenant_contract(tenant) - self.assertEqual(new_contract, contract) - - def test_create_tenant_contract_new(self): - tenant = mocked.APIC_TENANT - contract = mocked.APIC_CONTRACT - dn = self.mgr.apic.vzBrCP.mo.dn(tenant, contract) - self.mock_db_query_filterby_first_return(None) - self.mock_responses_for_create('vzBrCP') - self.mock_response_for_get('vzBrCP', dn=dn) - self.mock_responses_for_create('vzSubj') - self.mock_responses_for_create('vzFilter') - self.mock_responses_for_create('vzEntry') - self.mock_responses_for_create('vzInTerm') - self.mock_responses_for_create('vzRsFiltAtt__In') - self.mock_responses_for_create('vzOutTerm') - self.mock_responses_for_create('vzRsFiltAtt__Out') - self.mock_responses_for_create('vzCPIf') - self.mock_responses_for_create('vzRsIf') - new_contract = self.mgr.create_tenant_contract(tenant) - self.assert_responses_drained() - self.assertTrue(self.mocked_session.add.called) - self.assertTrue(self.mocked_session.flush.called) - self.assertEqual(new_contract['tenant_id'], tenant) - - def test_create_tenant_contract_exc(self): - tenant = mocked.APIC_TENANT - self.mock_db_query_filterby_first_return(None) - self.mock_error_post_response(wexc.HTTPBadRequest) - self.mock_response_for_post('vzBrCP') - self.assertRaises(cexc.ApicResponseNotOk, - self.mgr.create_tenant_contract, tenant) - self.assert_responses_drained() diff --git a/neutron/tests/unit/ml2/drivers/cisco/apic/test_cisco_apic_mechanism_driver.py b/neutron/tests/unit/ml2/drivers/cisco/apic/test_cisco_apic_mechanism_driver.py deleted file mode 100644 index 6addd4382..000000000 --- a/neutron/tests/unit/ml2/drivers/cisco/apic/test_cisco_apic_mechanism_driver.py +++ /dev/null @@ -1,226 +0,0 @@ -# Copyright (c) 2014 Cisco Systems -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# @author: Henry Gessau, Cisco Systems - -import mock - -from oslo.config import cfg - -from neutron.plugins.ml2.drivers.cisco.apic import mechanism_apic as md -from neutron.plugins.ml2.drivers import type_vlan # noqa -from neutron.tests import base -from neutron.tests.unit.ml2.drivers.cisco.apic import ( - test_cisco_apic_common as mocked) - - -HOST_ID1 = 'ubuntu' -HOST_ID2 = 'rhel' -ENCAP = '101' - -SUBNET_GATEWAY = '10.3.2.1' -SUBNET_CIDR = '10.3.1.0/24' -SUBNET_NETMASK = '24' - -TEST_SEGMENT1 = 'test-segment1' -TEST_SEGMENT2 = 'test-segment2' - - -class TestCiscoApicMechDriver(base.BaseTestCase, - mocked.ControllerMixin, - mocked.ConfigMixin, - mocked.DbModelMixin): - - def setUp(self): - super(TestCiscoApicMechDriver, self).setUp() - mocked.ControllerMixin.set_up_mocks(self) - mocked.ConfigMixin.set_up_mocks(self) - mocked.DbModelMixin.set_up_mocks(self) - - self.mock_apic_manager_login_responses() - self.driver = md.APICMechanismDriver() - self.driver.vif_type = 'test-vif_type' - self.driver.cap_port_filter = 'test-cap_port_filter' - - def test_initialize(self): - cfg.CONF.set_override('network_vlan_ranges', ['physnet1:100:199'], - 'ml2_type_vlan') - ns = mocked.APIC_VLAN_NAME - mode = mocked.APIC_VLAN_MODE - self.mock_response_for_get('fvnsVlanInstP', name=ns, mode=mode) - self.mock_response_for_get('physDomP', name=mocked.APIC_DOMAIN) - self.mock_response_for_get('infraAttEntityP', - name=mocked.APIC_ATT_ENT_PROF) - self.mock_response_for_get('infraAccPortGrp', - name=mocked.APIC_ACC_PORT_GRP) - mock.patch('neutron.plugins.ml2.drivers.cisco.apic.apic_manager.' - 'APICManager.ensure_infra_created_on_apic').start() - self.driver.initialize() - self.session = self.driver.apic_manager.apic.session - self.assert_responses_drained() - - def test_update_port_postcommit(self): - net_ctx = self._get_network_context(mocked.APIC_TENANT, - mocked.APIC_NETWORK, - TEST_SEGMENT1) - port_ctx = self._get_port_context(mocked.APIC_TENANT, - mocked.APIC_NETWORK, - 'vm1', net_ctx, HOST_ID1) - mgr = self.driver.apic_manager = mock.Mock() - self.driver.update_port_postcommit(port_ctx) - mgr.ensure_tenant_created_on_apic.assert_called_once_with( - mocked.APIC_TENANT) - mgr.ensure_path_created_for_port.assert_called_once_with( - mocked.APIC_TENANT, mocked.APIC_NETWORK, HOST_ID1, - ENCAP, mocked.APIC_NETWORK + '-name') - - def test_create_network_postcommit(self): - ctx = self._get_network_context(mocked.APIC_TENANT, - mocked.APIC_NETWORK, - TEST_SEGMENT1) - mgr = self.driver.apic_manager = mock.Mock() - self.driver.create_network_postcommit(ctx) - mgr.ensure_bd_created_on_apic.assert_called_once_with( - mocked.APIC_TENANT, mocked.APIC_NETWORK) - mgr.ensure_epg_created_for_network.assert_called_once_with( - mocked.APIC_TENANT, mocked.APIC_NETWORK, - mocked.APIC_NETWORK + '-name') - - def test_delete_network_postcommit(self): - ctx = self._get_network_context(mocked.APIC_TENANT, - mocked.APIC_NETWORK, - TEST_SEGMENT1) - mgr = self.driver.apic_manager = mock.Mock() - self.driver.delete_network_postcommit(ctx) - mgr.delete_bd_on_apic.assert_called_once_with( - mocked.APIC_TENANT, mocked.APIC_NETWORK) - mgr.delete_epg_for_network.assert_called_once_with( - mocked.APIC_TENANT, mocked.APIC_NETWORK) - - def test_create_subnet_postcommit(self): - net_ctx = self._get_network_context(mocked.APIC_TENANT, - mocked.APIC_NETWORK, - TEST_SEGMENT1) - subnet_ctx = self._get_subnet_context(SUBNET_GATEWAY, - SUBNET_CIDR, - net_ctx) - mgr = self.driver.apic_manager = mock.Mock() - self.driver.create_subnet_postcommit(subnet_ctx) - mgr.ensure_subnet_created_on_apic.assert_called_once_with( - mocked.APIC_TENANT, mocked.APIC_NETWORK, - '%s/%s' % (SUBNET_GATEWAY, SUBNET_NETMASK)) - - def _get_network_context(self, tenant_id, net_id, seg_id=None, - seg_type='vlan'): - network = {'id': net_id, - 'name': net_id + '-name', - 'tenant_id': tenant_id, - 'provider:segmentation_id': seg_id} - if seg_id: - network_segments = [{'id': seg_id, - 'segmentation_id': ENCAP, - 'network_type': seg_type, - 'physical_network': 'physnet1'}] - else: - network_segments = [] - return FakeNetworkContext(network, network_segments) - - def _get_subnet_context(self, gateway_ip, cidr, network): - subnet = {'tenant_id': network.current['tenant_id'], - 'network_id': network.current['id'], - 'id': '[%s/%s]' % (gateway_ip, cidr), - 'gateway_ip': gateway_ip, - 'cidr': cidr} - return FakeSubnetContext(subnet, network) - - def _get_port_context(self, tenant_id, net_id, vm_id, network, host): - port = {'device_id': vm_id, - 'device_owner': 'compute', - 'binding:host_id': host, - 'tenant_id': tenant_id, - 'id': mocked.APIC_PORT, - 'name': mocked.APIC_PORT, - 'network_id': net_id} - return FakePortContext(port, network) - - -class FakeNetworkContext(object): - """To generate network context for testing purposes only.""" - - def __init__(self, network, segments): - self._network = network - self._segments = segments - - @property - def current(self): - return self._network - - @property - def network_segments(self): - return self._segments - - -class FakeSubnetContext(object): - """To generate subnet context for testing purposes only.""" - - def __init__(self, subnet, network): - self._subnet = subnet - self._network = network - - @property - def current(self): - return self._subnet - - @property - def network(self): - return self._network - - -class FakePortContext(object): - """To generate port context for testing purposes only.""" - - def __init__(self, port, network): - self._fake_plugin = mock.Mock() - self._fake_plugin.get_ports.return_value = [] - self._fake_plugin_context = None - self._port = port - self._network = network - if network.network_segments: - self._bound_segment = network.network_segments[0] - else: - self._bound_segment = None - - @property - def current(self): - return self._port - - @property - def _plugin(self): - return self._fake_plugin - - @property - def _plugin_context(self): - return self._fake_plugin_context - - @property - def network(self): - return self._network - - @property - def bound_segment(self): - return self._bound_segment - - def set_binding(self, segment_id, vif_type, cap_port_filter): - pass diff --git a/neutron/tests/unit/ml2/drivers/cisco/nexus/__init__.py b/neutron/tests/unit/ml2/drivers/cisco/nexus/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_config.py b/neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_config.py deleted file mode 100644 index 55f0db3da..000000000 --- a/neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_config.py +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (c) 2014 Cisco Systems, Inc. -# All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import mock -from oslo.config import cfg - -from neutron.plugins.ml2.drivers.cisco.nexus import config as cisco_config -from neutron.tests import base - - -class TestCiscoNexusPluginConfig(base.BaseTestCase): - - def setUp(self): - self.config_parse() - super(TestCiscoNexusPluginConfig, self).setUp() - - def test_config_parse_error(self): - """Check that config error is raised upon config parser failure.""" - with mock.patch.object(cfg, 'MultiConfigParser') as parser: - parser.return_value.read.return_value = [] - self.assertRaises(cfg.Error, cisco_config.ML2MechCiscoConfig) - - def test_create_device_dictionary(self): - """Test creation of the device dictionary based on nexus config.""" - test_config = { - 'ml2_mech_cisco_nexus:1.1.1.1': { - 'username': ['admin'], - 'password': ['mySecretPassword'], - 'ssh_port': [22], - 'compute1': ['1/1'], - 'compute2': ['1/2'], - }, - 'ml2_mech_cisco_nexus:2.2.2.2': { - 'username': ['admin'], - 'password': ['mySecretPassword'], - 'ssh_port': [22], - 'compute3': ['1/1'], - 'compute4': ['1/2'], - }, - } - expected_dev_dict = { - ('1.1.1.1', 'username'): 'admin', - ('1.1.1.1', 'password'): 'mySecretPassword', - ('1.1.1.1', 'ssh_port'): 22, - ('1.1.1.1', 'compute1'): '1/1', - ('1.1.1.1', 'compute2'): '1/2', - ('2.2.2.2', 'username'): 'admin', - ('2.2.2.2', 'password'): 'mySecretPassword', - ('2.2.2.2', 'ssh_port'): 22, - ('2.2.2.2', 'compute3'): '1/1', - ('2.2.2.2', 'compute4'): '1/2', - } - with mock.patch.object(cfg, 'MultiConfigParser') as parser: - parser.return_value.read.return_value = cfg.CONF.config_file - parser.return_value.parsed = [test_config] - cisco_config.ML2MechCiscoConfig() - self.assertEqual(expected_dev_dict, - cisco_config.ML2MechCiscoConfig.nexus_dict) diff --git a/neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_mech.py b/neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_mech.py deleted file mode 100644 index 55717ebe2..000000000 --- a/neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_mech.py +++ /dev/null @@ -1,715 +0,0 @@ -# Copyright (c) 2012 OpenStack Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import contextlib -import mock - -import webob.exc as wexc - -from neutron.api.v2 import base -from neutron.common import constants as n_const -from neutron import context -from neutron.extensions import portbindings -from neutron import manager -from neutron.openstack.common import log as logging -from neutron.plugins.common import constants as p_const -from neutron.plugins.ml2 import config as ml2_config -from neutron.plugins.ml2 import driver_api as api -from neutron.plugins.ml2 import driver_context -from neutron.plugins.ml2.drivers.cisco.nexus import config as cisco_config -from neutron.plugins.ml2.drivers.cisco.nexus import exceptions as c_exc -from neutron.plugins.ml2.drivers.cisco.nexus import mech_cisco_nexus -from neutron.plugins.ml2.drivers.cisco.nexus import nexus_db_v2 -from neutron.plugins.ml2.drivers.cisco.nexus import nexus_network_driver -from neutron.plugins.ml2.drivers import type_vlan as vlan_config -from neutron.tests.unit import test_db_plugin - - -LOG = logging.getLogger(__name__) -ML2_PLUGIN = 'neutron.plugins.ml2.plugin.Ml2Plugin' -PHYS_NET = 'physnet1' -COMP_HOST_NAME = 'testhost' -COMP_HOST_NAME_2 = 'testhost_2' -VLAN_START = 1000 -VLAN_END = 1100 -NEXUS_IP_ADDR = '1.1.1.1' -NETWORK_NAME = 'test_network' -NETWORK_NAME_2 = 'test_network_2' -NEXUS_INTERFACE = '1/1' -NEXUS_INTERFACE_2 = '1/2' -CIDR_1 = '10.0.0.0/24' -CIDR_2 = '10.0.1.0/24' -DEVICE_ID_1 = '11111111-1111-1111-1111-111111111111' -DEVICE_ID_2 = '22222222-2222-2222-2222-222222222222' -DEVICE_OWNER = 'compute:None' -BOUND_SEGMENT1 = {api.NETWORK_TYPE: p_const.TYPE_VLAN, - api.PHYSICAL_NETWORK: PHYS_NET, - api.SEGMENTATION_ID: VLAN_START} -BOUND_SEGMENT2 = {api.NETWORK_TYPE: p_const.TYPE_VLAN, - api.PHYSICAL_NETWORK: PHYS_NET, - api.SEGMENTATION_ID: VLAN_START + 1} - - -class CiscoML2MechanismTestCase(test_db_plugin.NeutronDbPluginV2TestCase): - - def setUp(self): - """Configure for end-to-end neutron testing using a mock ncclient. - - This setup includes: - - Configure the ML2 plugin to use VLANs in the range of 1000-1100. - - Configure the Cisco mechanism driver to use an imaginary switch - at NEXUS_IP_ADDR. - - Create a mock NETCONF client (ncclient) for the Cisco mechanism - driver - - """ - - # Configure the ML2 mechanism drivers and network types - ml2_opts = { - 'mechanism_drivers': ['cisco_nexus'], - 'tenant_network_types': ['vlan'], - } - for opt, val in ml2_opts.items(): - ml2_config.cfg.CONF.set_override(opt, val, 'ml2') - - # Configure the ML2 VLAN parameters - phys_vrange = ':'.join([PHYS_NET, str(VLAN_START), str(VLAN_END)]) - vlan_config.cfg.CONF.set_override('network_vlan_ranges', - [phys_vrange], - 'ml2_type_vlan') - - # Configure the Cisco Nexus mechanism driver - nexus_config = { - (NEXUS_IP_ADDR, 'username'): 'admin', - (NEXUS_IP_ADDR, 'password'): 'mySecretPassword', - (NEXUS_IP_ADDR, 'ssh_port'): 22, - (NEXUS_IP_ADDR, COMP_HOST_NAME): NEXUS_INTERFACE, - (NEXUS_IP_ADDR, COMP_HOST_NAME_2): NEXUS_INTERFACE_2} - nexus_patch = mock.patch.dict( - cisco_config.ML2MechCiscoConfig.nexus_dict, - nexus_config) - nexus_patch.start() - self.addCleanup(nexus_patch.stop) - - # The NETCONF client module is not included in the DevStack - # distribution, so mock this module for unit testing. - self.mock_ncclient = mock.Mock() - mock.patch.object(nexus_network_driver.CiscoNexusDriver, - '_import_ncclient', - return_value=self.mock_ncclient).start() - - # Mock port context values for bound_segments and 'status'. - self.mock_bound_segment = mock.patch.object( - driver_context.PortContext, - 'bound_segment', - new_callable=mock.PropertyMock).start() - self.mock_bound_segment.return_value = BOUND_SEGMENT1 - - self.mock_original_bound_segment = mock.patch.object( - driver_context.PortContext, - 'original_bound_segment', - new_callable=mock.PropertyMock).start() - self.mock_original_bound_segment.return_value = None - - mock_status = mock.patch.object( - mech_cisco_nexus.CiscoNexusMechanismDriver, - '_is_status_active').start() - mock_status.return_value = n_const.PORT_STATUS_ACTIVE - - super(CiscoML2MechanismTestCase, self).setUp(ML2_PLUGIN) - - self.port_create_status = 'DOWN' - - @contextlib.contextmanager - def _patch_ncclient(self, attr, value): - """Configure an attribute on the mock ncclient module. - - This method can be used to inject errors by setting a side effect - or a return value for an ncclient method. - - :param attr: ncclient attribute (typically method) to be configured. - :param value: Value to be configured on the attribute. - - """ - # Configure attribute. - config = {attr: value} - self.mock_ncclient.configure_mock(**config) - # Continue testing - yield - # Unconfigure attribute - config = {attr: None} - self.mock_ncclient.configure_mock(**config) - - @staticmethod - def _config_dependent_side_effect(match_config, exc): - """Generates a config-dependent side effect for ncclient edit_config. - - This method generates a mock side-effect function which can be - configured on the mock ncclient module for the edit_config method. - This side effect will cause a given exception to be raised whenever - the XML config string that is passed to edit_config contains all - words in a given match config string. - - :param match_config: String containing keywords to be matched - :param exc: Exception to be raised when match is found - :return: Side effect function for the mock ncclient module's - edit_config method. - - """ - keywords = match_config.split() - - def _side_effect_function(target, config): - if all(word in config for word in keywords): - raise exc - return _side_effect_function - - def _is_in_nexus_cfg(self, words): - """Check if any config sent to Nexus contains all words in a list.""" - for call in (self.mock_ncclient.connect.return_value. - edit_config.mock_calls): - configlet = call[2]['config'] - if all(word in configlet for word in words): - return True - return False - - def _is_in_last_nexus_cfg(self, words): - """Confirm last config sent to Nexus contains specified keywords.""" - last_cfg = (self.mock_ncclient.connect.return_value. - edit_config.mock_calls[-1][2]['config']) - return all(word in last_cfg for word in words) - - def _is_vlan_configured(self, vlan_creation_expected=True, - add_keyword_expected=False): - vlan_created = self._is_in_nexus_cfg(['vlan', 'vlan-name']) - add_appears = self._is_in_last_nexus_cfg(['add']) - return (self._is_in_last_nexus_cfg(['allowed', 'vlan']) and - vlan_created == vlan_creation_expected and - add_appears == add_keyword_expected) - - def _is_vlan_unconfigured(self, vlan_deletion_expected=True): - vlan_deleted = self._is_in_last_nexus_cfg( - ['no', 'vlan', 'vlan-id-create-delete']) - return (self._is_in_nexus_cfg(['allowed', 'vlan', 'remove']) and - vlan_deleted == vlan_deletion_expected) - - -class TestCiscoBasicGet(CiscoML2MechanismTestCase, - test_db_plugin.TestBasicGet): - - pass - - -class TestCiscoV2HTTPResponse(CiscoML2MechanismTestCase, - test_db_plugin.TestV2HTTPResponse): - - pass - - -class TestCiscoPortsV2(CiscoML2MechanismTestCase, - test_db_plugin.TestPortsV2): - - @contextlib.contextmanager - def _create_resources(self, name=NETWORK_NAME, cidr=CIDR_1, - device_id=DEVICE_ID_1, - host_id=COMP_HOST_NAME): - """Create network, subnet, and port resources for test cases. - - Create a network, subnet, port and then update the port, yield the - result, then delete the port, subnet and network. - - :param name: Name of network to be created. - :param cidr: cidr address of subnetwork to be created. - :param device_id: Device ID to use for port to be created/updated. - :param host_id: Host ID to use for port create/update. - - """ - with self.network(name=name) as network: - with self.subnet(network=network, cidr=cidr) as subnet: - with self.port(subnet=subnet, cidr=cidr) as port: - data = {'port': {portbindings.HOST_ID: host_id, - 'device_id': device_id, - 'device_owner': 'compute:none', - 'admin_state_up': True}} - req = self.new_update_request('ports', data, - port['port']['id']) - yield req.get_response(self.api) - - def _assertExpectedHTTP(self, status, exc): - """Confirm that an HTTP status corresponds to an expected exception. - - Confirm that an HTTP status which has been returned for an - neutron API request matches the HTTP status corresponding - to an expected exception. - - :param status: HTTP status - :param exc: Expected exception - - """ - if exc in base.FAULT_MAP: - expected_http = base.FAULT_MAP[exc].code - else: - expected_http = wexc.HTTPInternalServerError.code - self.assertEqual(status, expected_http) - - def test_create_ports_bulk_emulated_plugin_failure(self): - real_has_attr = hasattr - - #ensures the API chooses the emulation code path - def fakehasattr(item, attr): - if attr.endswith('__native_bulk_support'): - return False - return real_has_attr(item, attr) - - with mock.patch('__builtin__.hasattr', - new=fakehasattr): - plugin_obj = manager.NeutronManager.get_plugin() - orig = plugin_obj.create_port - with mock.patch.object(plugin_obj, - 'create_port') as patched_plugin: - - def side_effect(*args, **kwargs): - return self._do_side_effect(patched_plugin, orig, - *args, **kwargs) - - patched_plugin.side_effect = side_effect - with self.network() as net: - res = self._create_port_bulk(self.fmt, 2, - net['network']['id'], - 'test', - True) - # Expect an internal server error as we injected a fault - self._validate_behavior_on_bulk_failure( - res, - 'ports', - wexc.HTTPInternalServerError.code) - - def test_create_ports_bulk_native(self): - if self._skip_native_bulk: - self.skipTest("Plugin does not support native bulk port create") - - def test_create_ports_bulk_emulated(self): - if self._skip_native_bulk: - self.skipTest("Plugin does not support native bulk port create") - - def test_create_ports_bulk_native_plugin_failure(self): - if self._skip_native_bulk: - self.skipTest("Plugin does not support native bulk port create") - ctx = context.get_admin_context() - with self.network() as net: - plugin_obj = manager.NeutronManager.get_plugin() - orig = plugin_obj.create_port - with mock.patch.object(plugin_obj, - 'create_port') as patched_plugin: - - def side_effect(*args, **kwargs): - return self._do_side_effect(patched_plugin, orig, - *args, **kwargs) - - patched_plugin.side_effect = side_effect - res = self._create_port_bulk(self.fmt, 2, net['network']['id'], - 'test', True, context=ctx) - # We expect an internal server error as we injected a fault - self._validate_behavior_on_bulk_failure( - res, - 'ports', - wexc.HTTPInternalServerError.code) - - def test_nexus_enable_vlan_cmd(self): - """Verify the syntax of the command to enable a vlan on an intf. - - Confirm that for the first VLAN configured on a Nexus interface, - the command string sent to the switch does not contain the - keyword 'add'. - - Confirm that for the second VLAN configured on a Nexus interface, - the command string sent to the switch contains the keyword 'add'. - - """ - # First vlan should be configured without 'add' keyword - with self._create_resources(): - self.assertTrue(self._is_vlan_configured( - vlan_creation_expected=True, - add_keyword_expected=False)) - self.mock_ncclient.reset_mock() - self.mock_bound_segment.return_value = BOUND_SEGMENT2 - - # Second vlan should be configured with 'add' keyword - with self._create_resources(name=NETWORK_NAME_2, - device_id=DEVICE_ID_2, - cidr=CIDR_2): - self.assertTrue(self._is_vlan_configured( - vlan_creation_expected=True, - add_keyword_expected=True)) - - # Return to first segment for delete port calls. - self.mock_bound_segment.return_value = BOUND_SEGMENT1 - - def test_nexus_add_trunk(self): - """Verify syntax to enable a vlan on an interface. - - Test also verifies that the vlan interface is not created. - - Test of the following ml2_conf_cisco_ini config: - [ml2_mech_cisco_nexus:1.1.1.1] - hostA=1/1 - hostB=1/2 - where vlan_id = 100 - - Confirm that for the first host configured on a Nexus interface, - the command string sent to the switch does not contain the - keyword 'add'. - - Confirm that for the second host configured on a Nexus interface, - the command staring sent to the switch contains does not contain - the keyword 'name' [signifies vlan intf creation]. - - """ - with self._create_resources(name='net1', cidr=CIDR_1): - self.assertTrue(self._is_in_last_nexus_cfg(['allowed', 'vlan'])) - self.assertFalse(self._is_in_last_nexus_cfg(['add'])) - with self._create_resources(name='net2', - cidr=CIDR_2, host_id=COMP_HOST_NAME_2): - self.assertTrue( - self._is_in_last_nexus_cfg(['allowed', 'vlan'])) - self.assertFalse(self._is_in_last_nexus_cfg(['name'])) - - def test_nexus_connect_fail(self): - """Test failure to connect to a Nexus switch. - - While creating a network, subnet, and port, simulate a connection - failure to a nexus switch. Confirm that the expected HTTP code - is returned for the create port operation. - - """ - with self._patch_ncclient('connect.side_effect', - AttributeError): - with self._create_resources() as result: - self._assertExpectedHTTP(result.status_int, - c_exc.NexusConnectFailed) - - def test_nexus_vlan_config_two_hosts(self): - """Verify config/unconfig of vlan on two compute hosts.""" - - @contextlib.contextmanager - def _create_port_check_vlan(comp_host_name, device_id, - vlan_creation_expected=True): - with self.port(subnet=subnet, fmt=self.fmt) as port: - data = {'port': {portbindings.HOST_ID: comp_host_name, - 'device_id': device_id, - 'device_owner': DEVICE_OWNER, - 'admin_state_up': True}} - req = self.new_update_request('ports', data, - port['port']['id']) - req.get_response(self.api) - self.assertTrue(self._is_vlan_configured( - vlan_creation_expected=vlan_creation_expected, - add_keyword_expected=False)) - self.mock_ncclient.reset_mock() - yield - - # Create network and subnet - with self.network(name=NETWORK_NAME) as network: - with self.subnet(network=network, cidr=CIDR_1) as subnet: - - # Create an instance on first compute host - with _create_port_check_vlan(COMP_HOST_NAME, DEVICE_ID_1, - vlan_creation_expected=True): - # Create an instance on second compute host - with _create_port_check_vlan(COMP_HOST_NAME_2, DEVICE_ID_2, - vlan_creation_expected=False): - pass - - # Instance on second host is now terminated. - # Vlan should be untrunked from port, but vlan should - # still exist on the switch. - self.assertTrue(self._is_vlan_unconfigured( - vlan_deletion_expected=False)) - self.mock_ncclient.reset_mock() - - # Instance on first host is now terminated. - # Vlan should be untrunked from port and vlan should have - # been deleted from the switch. - self.assertTrue(self._is_vlan_unconfigured( - vlan_deletion_expected=True)) - - def test_nexus_vm_migration(self): - """Verify VM (live) migration. - - Simulate the following: - Nova informs neutron of live-migration with port-update(new host). - This should trigger two update_port_pre/postcommit() calls. - - The first one should only change the current host_id and remove the - binding resulting in the mechanism drivers receiving: - PortContext.original['binding:host_id']: previous value - PortContext.original_bound_segment: previous value - PortContext.current['binding:host_id']: current (new) value - PortContext.bound_segment: None - - The second one binds the new host resulting in the mechanism - drivers receiving: - PortContext.original['binding:host_id']: previous value - PortContext.original_bound_segment: None - PortContext.current['binding:host_id']: previous value - PortContext.bound_segment: new value - """ - - # Create network, subnet and port. - with self._create_resources() as result: - # Verify initial database entry. - # Use port_id to verify that 1st host name was used. - binding = nexus_db_v2.get_nexusvm_bindings(VLAN_START, - DEVICE_ID_1)[0] - intf_type, nexus_port = binding.port_id.split(':') - self.assertEqual(nexus_port, NEXUS_INTERFACE) - - port = self.deserialize(self.fmt, result) - port_id = port['port']['id'] - - # Trigger update event to unbind segment. - # Results in port being deleted from nexus DB and switch. - data = {'port': {portbindings.HOST_ID: COMP_HOST_NAME_2}} - self.mock_bound_segment.return_value = None - self.mock_original_bound_segment.return_value = BOUND_SEGMENT1 - self.new_update_request('ports', data, - port_id).get_response(self.api) - - # Verify that port entry has been deleted. - self.assertRaises(c_exc.NexusPortBindingNotFound, - nexus_db_v2.get_nexusvm_bindings, - VLAN_START, DEVICE_ID_1) - - # Trigger update event to bind segment with new host. - self.mock_bound_segment.return_value = BOUND_SEGMENT1 - self.mock_original_bound_segment.return_value = None - self.new_update_request('ports', data, - port_id).get_response(self.api) - - # Verify that port entry has been added using new host name. - # Use port_id to verify that 2nd host name was used. - binding = nexus_db_v2.get_nexusvm_bindings(VLAN_START, - DEVICE_ID_1)[0] - intf_type, nexus_port = binding.port_id.split(':') - self.assertEqual(nexus_port, NEXUS_INTERFACE_2) - - def test_nexus_config_fail(self): - """Test a Nexus switch configuration failure. - - While creating a network, subnet, and port, simulate a nexus - switch configuration error. Confirm that the expected HTTP code - is returned for the create port operation. - - """ - with self._patch_ncclient( - 'connect.return_value.edit_config.side_effect', - AttributeError): - with self._create_resources() as result: - self._assertExpectedHTTP(result.status_int, - c_exc.NexusConfigFailed) - - def test_nexus_extended_vlan_range_failure(self): - """Test that extended VLAN range config errors are ignored. - - Some versions of Nexus switch do not allow state changes for - the extended VLAN range (1006-4094), but these errors can be - ignored (default values are appropriate). Test that such errors - are ignored by the Nexus plugin. - - """ - def mock_edit_config_a(target, config): - if all(word in config for word in ['state', 'active']): - raise Exception("Can't modify state for extended") - - with self._patch_ncclient( - 'connect.return_value.edit_config.side_effect', - mock_edit_config_a): - with self._create_resources() as result: - self.assertEqual(result.status_int, wexc.HTTPOk.code) - - def mock_edit_config_b(target, config): - if all(word in config for word in ['no', 'shutdown']): - raise Exception("Command is only allowed on VLAN") - - with self._patch_ncclient( - 'connect.return_value.edit_config.side_effect', - mock_edit_config_b): - with self._create_resources() as result: - self.assertEqual(result.status_int, wexc.HTTPOk.code) - - def test_nexus_vlan_config_rollback(self): - """Test rollback following Nexus VLAN state config failure. - - Test that the Cisco Nexus plugin correctly deletes the VLAN - on the Nexus switch when the 'state active' command fails (for - a reason other than state configuration change is rejected - for the extended VLAN range). - - """ - vlan_state_configs = ['state active', 'no shutdown'] - for config in vlan_state_configs: - with self._patch_ncclient( - 'connect.return_value.edit_config.side_effect', - self._config_dependent_side_effect(config, ValueError)): - with self._create_resources() as result: - # Confirm that the last configuration sent to the Nexus - # switch was deletion of the VLAN. - self.assertTrue( - self._is_in_last_nexus_cfg(['', '']) - ) - self._assertExpectedHTTP(result.status_int, - c_exc.NexusConfigFailed) - - def test_nexus_host_not_configured(self): - """Test handling of a NexusComputeHostNotConfigured exception. - - Test the Cisco NexusComputeHostNotConfigured exception by using - a fictitious host name during port creation. - - """ - with self._create_resources(host_id='fake_host') as result: - self._assertExpectedHTTP(result.status_int, - c_exc.NexusComputeHostNotConfigured) - - def test_nexus_missing_fields(self): - """Test handling of a NexusMissingRequiredFields exception. - - Test the Cisco NexusMissingRequiredFields exception by using - empty host_id and device_id values during port creation. - - """ - with self._create_resources(device_id='', host_id='') as result: - self._assertExpectedHTTP(result.status_int, - c_exc.NexusMissingRequiredFields) - - -class TestCiscoNetworksV2(CiscoML2MechanismTestCase, - test_db_plugin.TestNetworksV2): - - def test_create_networks_bulk_emulated_plugin_failure(self): - real_has_attr = hasattr - - def fakehasattr(item, attr): - if attr.endswith('__native_bulk_support'): - return False - return real_has_attr(item, attr) - - plugin_obj = manager.NeutronManager.get_plugin() - orig = plugin_obj.create_network - #ensures the API choose the emulation code path - with mock.patch('__builtin__.hasattr', - new=fakehasattr): - with mock.patch.object(plugin_obj, - 'create_network') as patched_plugin: - def side_effect(*args, **kwargs): - return self._do_side_effect(patched_plugin, orig, - *args, **kwargs) - patched_plugin.side_effect = side_effect - res = self._create_network_bulk(self.fmt, 2, 'test', True) - LOG.debug("response is %s" % res) - # We expect an internal server error as we injected a fault - self._validate_behavior_on_bulk_failure( - res, - 'networks', - wexc.HTTPInternalServerError.code) - - def test_create_networks_bulk_native_plugin_failure(self): - if self._skip_native_bulk: - self.skipTest("Plugin does not support native bulk network create") - plugin_obj = manager.NeutronManager.get_plugin() - orig = plugin_obj.create_network - with mock.patch.object(plugin_obj, - 'create_network') as patched_plugin: - - def side_effect(*args, **kwargs): - return self._do_side_effect(patched_plugin, orig, - *args, **kwargs) - - patched_plugin.side_effect = side_effect - res = self._create_network_bulk(self.fmt, 2, 'test', True) - # We expect an internal server error as we injected a fault - self._validate_behavior_on_bulk_failure( - res, - 'networks', - wexc.HTTPInternalServerError.code) - - -class TestCiscoSubnetsV2(CiscoML2MechanismTestCase, - test_db_plugin.TestSubnetsV2): - - def test_create_subnets_bulk_emulated_plugin_failure(self): - real_has_attr = hasattr - - #ensures the API choose the emulation code path - def fakehasattr(item, attr): - if attr.endswith('__native_bulk_support'): - return False - return real_has_attr(item, attr) - - with mock.patch('__builtin__.hasattr', - new=fakehasattr): - plugin_obj = manager.NeutronManager.get_plugin() - orig = plugin_obj.create_subnet - with mock.patch.object(plugin_obj, - 'create_subnet') as patched_plugin: - - def side_effect(*args, **kwargs): - self._do_side_effect(patched_plugin, orig, - *args, **kwargs) - - patched_plugin.side_effect = side_effect - with self.network() as net: - res = self._create_subnet_bulk(self.fmt, 2, - net['network']['id'], - 'test') - # We expect an internal server error as we injected a fault - self._validate_behavior_on_bulk_failure( - res, - 'subnets', - wexc.HTTPInternalServerError.code) - - def test_create_subnets_bulk_native_plugin_failure(self): - if self._skip_native_bulk: - self.skipTest("Plugin does not support native bulk subnet create") - plugin_obj = manager.NeutronManager.get_plugin() - orig = plugin_obj.create_subnet - with mock.patch.object(plugin_obj, - 'create_subnet') as patched_plugin: - def side_effect(*args, **kwargs): - return self._do_side_effect(patched_plugin, orig, - *args, **kwargs) - - patched_plugin.side_effect = side_effect - with self.network() as net: - res = self._create_subnet_bulk(self.fmt, 2, - net['network']['id'], - 'test') - - # We expect an internal server error as we injected a fault - self._validate_behavior_on_bulk_failure( - res, - 'subnets', - wexc.HTTPInternalServerError.code) - - -class TestCiscoPortsV2XML(TestCiscoPortsV2): - fmt = 'xml' - - -class TestCiscoNetworksV2XML(TestCiscoNetworksV2): - fmt = 'xml' - - -class TestCiscoSubnetsV2XML(TestCiscoSubnetsV2): - fmt = 'xml' diff --git a/neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_nexus.py b/neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_nexus.py deleted file mode 100644 index 31573b82b..000000000 --- a/neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_nexus.py +++ /dev/null @@ -1,201 +0,0 @@ -# Copyright (c) 2013 OpenStack Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import collections -import mock -import testtools - -from neutron.common import constants as n_const -from neutron.db import api as db -from neutron.extensions import portbindings -from neutron.openstack.common import importutils -from neutron.plugins.ml2 import driver_api as api -from neutron.plugins.ml2.drivers.cisco.nexus import constants -from neutron.plugins.ml2.drivers.cisco.nexus import exceptions -from neutron.plugins.ml2.drivers.cisco.nexus import mech_cisco_nexus -from neutron.plugins.ml2.drivers.cisco.nexus import nexus_db_v2 -from neutron.plugins.ml2.drivers.cisco.nexus import nexus_network_driver -from neutron.tests import base - - -NEXUS_IP_ADDRESS = '1.1.1.1' -NEXUS_IP_ADDRESS_PC = '2.2.2.2' -HOST_NAME_1 = 'testhost1' -HOST_NAME_2 = 'testhost2' -HOST_NAME_PC = 'testpchost' -INSTANCE_1 = 'testvm1' -INSTANCE_2 = 'testvm2' -INSTANCE_PC = 'testpcvm' -NEXUS_PORT_1 = 'ethernet:1/10' -NEXUS_PORT_2 = 'ethernet:1/20' -NEXUS_PORTCHANNELS = 'portchannel:2' -VLAN_ID_1 = 267 -VLAN_ID_2 = 265 -VLAN_ID_PC = 268 -DEVICE_OWNER = 'compute:test' -NEXUS_SSH_PORT = '22' -PORT_STATE = n_const.PORT_STATUS_ACTIVE -NETWORK_TYPE = 'vlan' -NEXUS_DRIVER = ('neutron.plugins.ml2.drivers.cisco.nexus.' - 'nexus_network_driver.CiscoNexusDriver') - - -class FakeNetworkContext(object): - - """Network context for testing purposes only.""" - - def __init__(self, segment_id): - self._network_segments = {api.SEGMENTATION_ID: segment_id, - api.NETWORK_TYPE: NETWORK_TYPE} - - @property - def network_segments(self): - return self._network_segments - - -class FakePortContext(object): - - """Port context for testing purposes only.""" - - def __init__(self, device_id, host_name, network_context): - self._port = { - 'status': PORT_STATE, - 'device_id': device_id, - 'device_owner': DEVICE_OWNER, - portbindings.HOST_ID: host_name - } - self._network = network_context - self._segment = network_context.network_segments - - @property - def current(self): - return self._port - - @property - def network(self): - return self._network - - @property - def bound_segment(self): - return self._segment - - -class TestCiscoNexusDevice(base.BaseTestCase): - - """Unit tests for Cisco ML2 Nexus device driver.""" - - TestConfigObj = collections.namedtuple( - 'TestConfigObj', - 'nexus_ip_addr host_name nexus_port instance_id vlan_id') - - test_configs = { - 'test_config1': TestConfigObj( - NEXUS_IP_ADDRESS, - HOST_NAME_1, - NEXUS_PORT_1, - INSTANCE_1, - VLAN_ID_1), - 'test_config2': TestConfigObj( - NEXUS_IP_ADDRESS, - HOST_NAME_2, - NEXUS_PORT_2, - INSTANCE_2, - VLAN_ID_2), - 'test_config_portchannel': TestConfigObj( - NEXUS_IP_ADDRESS_PC, - HOST_NAME_PC, - NEXUS_PORTCHANNELS, - INSTANCE_PC, - VLAN_ID_PC), - } - - def setUp(self): - """Sets up mock ncclient, and switch and credentials dictionaries.""" - super(TestCiscoNexusDevice, self).setUp() - - # Use a mock netconf client - mock_ncclient = mock.Mock() - mock.patch.object(nexus_network_driver.CiscoNexusDriver, - '_import_ncclient', - return_value=mock_ncclient).start() - - def new_nexus_init(mech_instance): - mech_instance.driver = importutils.import_object(NEXUS_DRIVER) - - mech_instance._nexus_switches = {} - for name, config in TestCiscoNexusDevice.test_configs.items(): - ip_addr = config.nexus_ip_addr - host_name = config.host_name - nexus_port = config.nexus_port - mech_instance._nexus_switches[(ip_addr, - host_name)] = nexus_port - mech_instance._nexus_switches[(ip_addr, - 'ssh_port')] = NEXUS_SSH_PORT - mech_instance._nexus_switches[(ip_addr, - constants.USERNAME)] = 'admin' - mech_instance._nexus_switches[(ip_addr, - constants.PASSWORD)] = 'password' - mech_instance.driver.nexus_switches = ( - mech_instance._nexus_switches) - - db.configure_db() - - mock.patch.object(mech_cisco_nexus.CiscoNexusMechanismDriver, - '__init__', new=new_nexus_init).start() - self._cisco_mech_driver = (mech_cisco_nexus. - CiscoNexusMechanismDriver()) - - self.addCleanup(db.clear_db) - - def _create_delete_port(self, port_config): - """Tests creation and deletion of a virtual port.""" - nexus_ip_addr = port_config.nexus_ip_addr - host_name = port_config.host_name - nexus_port = port_config.nexus_port - instance_id = port_config.instance_id - vlan_id = port_config.vlan_id - - network_context = FakeNetworkContext(vlan_id) - port_context = FakePortContext(instance_id, host_name, - network_context) - - self._cisco_mech_driver.update_port_precommit(port_context) - self._cisco_mech_driver.update_port_postcommit(port_context) - bindings = nexus_db_v2.get_nexusport_binding(nexus_port, - vlan_id, - nexus_ip_addr, - instance_id) - self.assertEqual(len(bindings), 1) - - self._cisco_mech_driver.delete_port_precommit(port_context) - self._cisco_mech_driver.delete_port_postcommit(port_context) - with testtools.ExpectedException(exceptions.NexusPortBindingNotFound): - nexus_db_v2.get_nexusport_binding(nexus_port, - vlan_id, - nexus_ip_addr, - instance_id) - - def test_create_delete_ports(self): - """Tests creation and deletion of two new virtual Ports.""" - self._create_delete_port( - TestCiscoNexusDevice.test_configs['test_config1']) - - self._create_delete_port( - TestCiscoNexusDevice.test_configs['test_config2']) - - def test_create_delete_portchannel(self): - """Tests creation of a port over a portchannel.""" - self._create_delete_port( - TestCiscoNexusDevice.test_configs['test_config_portchannel']) diff --git a/neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_nexus_db.py b/neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_nexus_db.py deleted file mode 100644 index 08cc9a951..000000000 --- a/neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_nexus_db.py +++ /dev/null @@ -1,206 +0,0 @@ -# Copyright (c) 2013 OpenStack Foundation -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import collections -import testtools - -from neutron.db import api as db -from neutron.plugins.ml2.drivers.cisco.nexus import exceptions -from neutron.plugins.ml2.drivers.cisco.nexus import nexus_db_v2 -from neutron.tests import base - - -class CiscoNexusDbTest(base.BaseTestCase): - - """Unit tests for Cisco mechanism driver's Nexus port binding database.""" - - NpbObj = collections.namedtuple('NpbObj', 'port vlan switch instance') - - def setUp(self): - super(CiscoNexusDbTest, self).setUp() - db.configure_db() - self.addCleanup(db.clear_db) - - def _npb_test_obj(self, pnum, vnum, switch='10.9.8.7', instance=None): - """Creates a Nexus port binding test object from a pair of numbers.""" - if pnum is 'router': - port = pnum - else: - port = '1/%s' % pnum - if instance is None: - instance = 'instance_%s_%s' % (pnum, vnum) - return self.NpbObj(port, vnum, switch, instance) - - def _assert_bindings_match(self, npb, npb_obj): - """Asserts that a port binding matches a port binding test obj.""" - self.assertEqual(npb.port_id, npb_obj.port) - self.assertEqual(npb.vlan_id, npb_obj.vlan) - self.assertEqual(npb.switch_ip, npb_obj.switch) - self.assertEqual(npb.instance_id, npb_obj.instance) - - def _add_binding_to_db(self, npb): - """Adds a port binding to the Nexus database.""" - return nexus_db_v2.add_nexusport_binding( - npb.port, npb.vlan, npb.switch, npb.instance) - - def _add_bindings_to_db(self, npbs): - """Adds a list of port bindings to the Nexus database.""" - for npb in npbs: - nexus_db_v2.add_nexusport_binding( - npb.port, npb.vlan, npb.switch, npb.instance) - - def _remove_binding_from_db(self, npb): - """Removes a port binding from the Nexus database.""" - return nexus_db_v2.remove_nexusport_binding( - npb.port, npb.vlan, npb.switch, npb.instance) - - def _get_nexusport_binding(self, npb): - """Gets a port binding based on port, vlan, switch, and instance.""" - return nexus_db_v2.get_nexusport_binding( - npb.port, npb.vlan, npb.switch, npb.instance) - - def _get_nexusvlan_binding(self, npb): - """Gets port bindings based on vlan and switch.""" - return nexus_db_v2.get_nexusvlan_binding(npb.vlan, npb.switch) - - def _get_nexusvm_binding(self, npb): - """Gets port binding based on vlan and instance.""" - return nexus_db_v2.get_nexusvm_bindings(npb.vlan, npb.instance)[0] - - def _get_port_vlan_switch_binding(self, npb): - """Gets port bindings based on port, vlan, and switch.""" - return nexus_db_v2.get_port_vlan_switch_binding( - npb.port, npb.vlan, npb.switch) - - def _get_port_switch_bindings(self, npb): - """Get port bindings based on port and switch.""" - return nexus_db_v2.get_port_switch_bindings(npb.port, npb.switch) - - def test_nexusportbinding_add_remove(self): - """Tests add and removal of port bindings from the Nexus database.""" - npb11 = self._npb_test_obj(10, 100) - npb = self._add_binding_to_db(npb11) - self._assert_bindings_match(npb, npb11) - npb = self._remove_binding_from_db(npb11) - self.assertEqual(len(npb), 1) - self._assert_bindings_match(npb[0], npb11) - with testtools.ExpectedException(exceptions.NexusPortBindingNotFound): - self._remove_binding_from_db(npb11) - - def test_nexusportbinding_get(self): - """Tests get of specific port bindings from the database.""" - npb11 = self._npb_test_obj(10, 100) - npb21 = self._npb_test_obj(20, 100) - npb22 = self._npb_test_obj(20, 200) - self._add_bindings_to_db([npb11, npb21, npb22]) - - npb = self._get_nexusport_binding(npb11) - self.assertEqual(len(npb), 1) - self._assert_bindings_match(npb[0], npb11) - npb = self._get_nexusport_binding(npb21) - self.assertEqual(len(npb), 1) - self._assert_bindings_match(npb[0], npb21) - npb = self._get_nexusport_binding(npb22) - self.assertEqual(len(npb), 1) - self._assert_bindings_match(npb[0], npb22) - - with testtools.ExpectedException(exceptions.NexusPortBindingNotFound): - nexus_db_v2.get_nexusport_binding( - npb21.port, npb21.vlan, npb21.switch, "dummyInstance") - - def test_nexusvlanbinding_get(self): - """Test get of port bindings based on vlan and switch.""" - npb11 = self._npb_test_obj(10, 100) - npb21 = self._npb_test_obj(20, 100) - npb22 = self._npb_test_obj(20, 200) - self._add_bindings_to_db([npb11, npb21, npb22]) - - npb_all_v100 = self._get_nexusvlan_binding(npb11) - self.assertEqual(len(npb_all_v100), 2) - npb_v200 = self._get_nexusvlan_binding(npb22) - self.assertEqual(len(npb_v200), 1) - self._assert_bindings_match(npb_v200[0], npb22) - - with testtools.ExpectedException(exceptions.NexusPortBindingNotFound): - nexus_db_v2.get_nexusvlan_binding(npb21.vlan, "dummySwitch") - - def test_nexusvmbinding_get(self): - """Test get of port bindings based on vlan and instance.""" - npb11 = self._npb_test_obj(10, 100) - npb21 = self._npb_test_obj(20, 100) - npb22 = self._npb_test_obj(20, 200) - self._add_bindings_to_db([npb11, npb21, npb22]) - - npb = self._get_nexusvm_binding(npb21) - self._assert_bindings_match(npb, npb21) - npb = self._get_nexusvm_binding(npb22) - self._assert_bindings_match(npb, npb22) - - with testtools.ExpectedException(exceptions.NexusPortBindingNotFound): - nexus_db_v2.get_nexusvm_bindings(npb21.vlan, "dummyInstance")[0] - - def test_nexusportvlanswitchbinding_get(self): - """Tests get of port bindings based on port, vlan, and switch.""" - npb11 = self._npb_test_obj(10, 100) - npb21 = self._npb_test_obj(20, 100) - self._add_bindings_to_db([npb11, npb21]) - - npb = self._get_port_vlan_switch_binding(npb11) - self.assertEqual(len(npb), 1) - self._assert_bindings_match(npb[0], npb11) - - with testtools.ExpectedException(exceptions.NexusPortBindingNotFound): - nexus_db_v2.get_port_vlan_switch_binding( - npb21.port, npb21.vlan, "dummySwitch") - - def test_nexusportswitchbinding_get(self): - """Tests get of port bindings based on port and switch.""" - npb11 = self._npb_test_obj(10, 100) - npb21 = self._npb_test_obj(20, 100, switch='2.2.2.2') - npb22 = self._npb_test_obj(20, 200, switch='2.2.2.2') - self._add_bindings_to_db([npb11, npb21, npb22]) - - npb = self._get_port_switch_bindings(npb11) - self.assertEqual(len(npb), 1) - self._assert_bindings_match(npb[0], npb11) - npb_all_p20 = self._get_port_switch_bindings(npb21) - self.assertEqual(len(npb_all_p20), 2) - - npb = nexus_db_v2.get_port_switch_bindings(npb21.port, "dummySwitch") - self.assertIsNone(npb) - - def test_nexusbinding_update(self): - """Tests update of vlan IDs for port bindings.""" - npb11 = self._npb_test_obj(10, 100, switch='1.1.1.1', instance='test') - npb21 = self._npb_test_obj(20, 100, switch='1.1.1.1', instance='test') - self._add_bindings_to_db([npb11, npb21]) - - npb_all_v100 = nexus_db_v2.get_nexusvlan_binding(100, '1.1.1.1') - self.assertEqual(len(npb_all_v100), 2) - - npb22 = self._npb_test_obj(20, 200, switch='1.1.1.1', instance='test') - npb = nexus_db_v2.update_nexusport_binding(npb21.port, 200) - self._assert_bindings_match(npb, npb22) - - npb_all_v100 = nexus_db_v2.get_nexusvlan_binding(100, '1.1.1.1') - self.assertEqual(len(npb_all_v100), 1) - self._assert_bindings_match(npb_all_v100[0], npb11) - - npb = nexus_db_v2.update_nexusport_binding(npb21.port, 0) - self.assertIsNone(npb) - - npb33 = self._npb_test_obj(30, 300, switch='1.1.1.1', instance='test') - with testtools.ExpectedException(exceptions.NexusPortBindingNotFound): - nexus_db_v2.update_nexusport_binding(npb33.port, 200) diff --git a/neutron/tests/unit/ml2/drivers/mechanism_bulkless.py b/neutron/tests/unit/ml2/drivers/mechanism_bulkless.py deleted file mode 100644 index 0a0d3de93..000000000 --- a/neutron/tests/unit/ml2/drivers/mechanism_bulkless.py +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright (c) 2014 OpenStack Foundation -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.plugins.ml2 import driver_api as api - - -class BulklessMechanismDriver(api.MechanismDriver): - """Test mechanism driver for testing bulk emulation.""" - - def initialize(self): - self.native_bulk_support = False diff --git a/neutron/tests/unit/ml2/drivers/mechanism_logger.py b/neutron/tests/unit/ml2/drivers/mechanism_logger.py deleted file mode 100644 index 401badb16..000000000 --- a/neutron/tests/unit/ml2/drivers/mechanism_logger.py +++ /dev/null @@ -1,120 +0,0 @@ -# Copyright (c) 2013 OpenStack Foundation -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.openstack.common import log -from neutron.plugins.ml2 import driver_api as api - -LOG = log.getLogger(__name__) - - -class LoggerMechanismDriver(api.MechanismDriver): - """Mechanism driver that logs all calls and parameters made. - - Generally used for testing and debugging. - """ - - def initialize(self): - pass - - def _log_network_call(self, method_name, context): - LOG.info(_("%(method)s called with network settings %(current)s " - "(original settings %(original)s) and " - "network segments %(segments)s"), - {'method': method_name, - 'current': context.current, - 'original': context.original, - 'segments': context.network_segments}) - - def create_network_precommit(self, context): - self._log_network_call("create_network_precommit", context) - - def create_network_postcommit(self, context): - self._log_network_call("create_network_postcommit", context) - - def update_network_precommit(self, context): - self._log_network_call("update_network_precommit", context) - - def update_network_postcommit(self, context): - self._log_network_call("update_network_postcommit", context) - - def delete_network_precommit(self, context): - self._log_network_call("delete_network_precommit", context) - - def delete_network_postcommit(self, context): - self._log_network_call("delete_network_postcommit", context) - - def _log_subnet_call(self, method_name, context): - LOG.info(_("%(method)s called with subnet settings %(current)s " - "(original settings %(original)s)"), - {'method': method_name, - 'current': context.current, - 'original': context.original}) - - def create_subnet_precommit(self, context): - self._log_subnet_call("create_subnet_precommit", context) - - def create_subnet_postcommit(self, context): - self._log_subnet_call("create_subnet_postcommit", context) - - def update_subnet_precommit(self, context): - self._log_subnet_call("update_subnet_precommit", context) - - def update_subnet_postcommit(self, context): - self._log_subnet_call("update_subnet_postcommit", context) - - def delete_subnet_precommit(self, context): - self._log_subnet_call("delete_subnet_precommit", context) - - def delete_subnet_postcommit(self, context): - self._log_subnet_call("delete_subnet_postcommit", context) - - def _log_port_call(self, method_name, context): - network_context = context.network - LOG.info(_("%(method)s called with port settings %(current)s " - "(original settings %(original)s) " - "bound to segment %(segment)s " - "(original segment %(original_segment)s) " - "using driver %(driver)s " - "(original driver %(original_driver)s) " - "on network %(network)s"), - {'method': method_name, - 'current': context.current, - 'original': context.original, - 'segment': context.bound_segment, - 'original_segment': context.original_bound_segment, - 'driver': context.bound_driver, - 'original_driver': context.original_bound_driver, - 'network': network_context.current}) - - def create_port_precommit(self, context): - self._log_port_call("create_port_precommit", context) - - def create_port_postcommit(self, context): - self._log_port_call("create_port_postcommit", context) - - def update_port_precommit(self, context): - self._log_port_call("update_port_precommit", context) - - def update_port_postcommit(self, context): - self._log_port_call("update_port_postcommit", context) - - def delete_port_precommit(self, context): - self._log_port_call("delete_port_precommit", context) - - def delete_port_postcommit(self, context): - self._log_port_call("delete_port_postcommit", context) - - def bind_port(self, context): - self._log_port_call("bind_port", context) diff --git a/neutron/tests/unit/ml2/drivers/mechanism_test.py b/neutron/tests/unit/ml2/drivers/mechanism_test.py deleted file mode 100644 index 6a0ca1e86..000000000 --- a/neutron/tests/unit/ml2/drivers/mechanism_test.py +++ /dev/null @@ -1,171 +0,0 @@ -# Copyright (c) 2013 OpenStack Foundation -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.common import constants as const -from neutron.extensions import portbindings -from neutron.plugins.ml2 import driver_api as api - - -class TestMechanismDriver(api.MechanismDriver): - """Test mechanism driver for testing mechanism driver api.""" - - def initialize(self): - self.bound_ports = set() - - def _check_network_context(self, context, original_expected): - assert(isinstance(context, api.NetworkContext)) - assert(isinstance(context.current, dict)) - assert(context.current['id'] is not None) - if original_expected: - assert(isinstance(context.original, dict)) - assert(context.current['id'] == context.original['id']) - else: - assert(not context.original) - assert(context.network_segments) - - def create_network_precommit(self, context): - self._check_network_context(context, False) - - def create_network_postcommit(self, context): - self._check_network_context(context, False) - - def update_network_precommit(self, context): - self._check_network_context(context, True) - - def update_network_postcommit(self, context): - self._check_network_context(context, True) - - def delete_network_precommit(self, context): - self._check_network_context(context, False) - - def delete_network_postcommit(self, context): - self._check_network_context(context, False) - - def _check_subnet_context(self, context, original_expected): - assert(isinstance(context, api.SubnetContext)) - assert(isinstance(context.current, dict)) - assert(context.current['id'] is not None) - if original_expected: - assert(isinstance(context.original, dict)) - assert(context.current['id'] == context.original['id']) - else: - assert(not context.original) - - def create_subnet_precommit(self, context): - self._check_subnet_context(context, False) - - def create_subnet_postcommit(self, context): - self._check_subnet_context(context, False) - - def update_subnet_precommit(self, context): - self._check_subnet_context(context, True) - - def update_subnet_postcommit(self, context): - self._check_subnet_context(context, True) - - def delete_subnet_precommit(self, context): - self._check_subnet_context(context, False) - - def delete_subnet_postcommit(self, context): - self._check_subnet_context(context, False) - - def _check_port_context(self, context, original_expected): - assert(isinstance(context, api.PortContext)) - assert(isinstance(context.current, dict)) - assert(context.current['id'] is not None) - - vif_type = context.current.get(portbindings.VIF_TYPE) - assert(vif_type is not None) - - if vif_type in (portbindings.VIF_TYPE_UNBOUND, - portbindings.VIF_TYPE_BINDING_FAILED): - assert(context.bound_segment is None) - assert(context.bound_driver is None) - assert(context.current['id'] not in self.bound_ports) - else: - assert(isinstance(context.bound_segment, dict)) - assert(context.bound_driver == 'test') - assert(context.current['id'] in self.bound_ports) - - if original_expected: - assert(isinstance(context.original, dict)) - assert(context.current['id'] == context.original['id']) - vif_type = context.original.get(portbindings.VIF_TYPE) - assert(vif_type is not None) - if vif_type in (portbindings.VIF_TYPE_UNBOUND, - portbindings.VIF_TYPE_BINDING_FAILED): - assert(context.original_bound_segment is None) - assert(context.original_bound_driver is None) - else: - assert(isinstance(context.original_bound_segment, dict)) - assert(context.original_bound_driver == 'test') - else: - assert(context.original is None) - assert(context.original_bound_segment is None) - assert(context.original_bound_driver is None) - - network_context = context.network - assert(isinstance(network_context, api.NetworkContext)) - self._check_network_context(network_context, False) - - def create_port_precommit(self, context): - self._check_port_context(context, False) - - def create_port_postcommit(self, context): - self._check_port_context(context, False) - - def update_port_precommit(self, context): - if (context.original_bound_driver == 'test' and - context.bound_driver != 'test'): - self.bound_ports.remove(context.original['id']) - self._check_port_context(context, True) - - def update_port_postcommit(self, context): - self._check_port_context(context, True) - - def delete_port_precommit(self, context): - self._check_port_context(context, False) - - def delete_port_postcommit(self, context): - self._check_port_context(context, False) - - def bind_port(self, context): - # REVISIT(rkukura): The upcoming fix for bug 1276391 will - # ensure the MDs see the unbinding of the port as a port - # update prior to re-binding, at which point this should be - # removed. - self.bound_ports.discard(context.current['id']) - - # REVISIT(rkukura): Currently, bind_port() is called as part - # of either a create or update transaction. The fix for bug - # 1276391 will change it to be called outside any transaction, - # so the context.original* will no longer be available. - self._check_port_context(context, context.original is not None) - - host = context.current.get(portbindings.HOST_ID, None) - segment = context.network.network_segments[0][api.ID] - if host == "host-ovs-no_filter": - context.set_binding(segment, portbindings.VIF_TYPE_OVS, - {portbindings.CAP_PORT_FILTER: False}) - self.bound_ports.add(context.current['id']) - elif host == "host-bridge-filter": - context.set_binding(segment, portbindings.VIF_TYPE_BRIDGE, - {portbindings.CAP_PORT_FILTER: True}) - self.bound_ports.add(context.current['id']) - elif host == "host-ovs-filter-active": - context.set_binding(segment, portbindings.VIF_TYPE_OVS, - {portbindings.CAP_PORT_FILTER: True}, - status=const.PORT_STATUS_ACTIVE) - self.bound_ports.add(context.current['id']) diff --git a/neutron/tests/unit/ml2/drivers/test_arista_mechanism_driver.py b/neutron/tests/unit/ml2/drivers/test_arista_mechanism_driver.py deleted file mode 100644 index 039839532..000000000 --- a/neutron/tests/unit/ml2/drivers/test_arista_mechanism_driver.py +++ /dev/null @@ -1,726 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright (c) 2013 OpenStack Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import mock -from oslo.config import cfg - -from neutron.common import constants as n_const -import neutron.db.api as ndb -from neutron.plugins.ml2.drivers.mech_arista import db -from neutron.plugins.ml2.drivers.mech_arista import exceptions as arista_exc -from neutron.plugins.ml2.drivers.mech_arista import mechanism_arista as arista -from neutron.tests import base - - -def setup_arista_wrapper_config(value=''): - cfg.CONF.keystone_authtoken = fake_keystone_info_class() - cfg.CONF.set_override('eapi_host', value, "ml2_arista") - cfg.CONF.set_override('eapi_username', value, "ml2_arista") - - -def setup_valid_config(): - # Config is not valid if value is not set - setup_arista_wrapper_config('value') - - -class AristaProvisionedVlansStorageTestCase(base.BaseTestCase): - """Test storing and retriving functionality of Arista mechanism driver. - - Tests all methods of this class by invoking them separately as well - as a group. - """ - - def setUp(self): - super(AristaProvisionedVlansStorageTestCase, self).setUp() - ndb.configure_db() - self.addCleanup(ndb.clear_db) - - def test_tenant_is_remembered(self): - tenant_id = 'test' - - db.remember_tenant(tenant_id) - net_provisioned = db.is_tenant_provisioned(tenant_id) - self.assertTrue(net_provisioned, 'Tenant must be provisioned') - - def test_tenant_is_removed(self): - tenant_id = 'test' - - db.remember_tenant(tenant_id) - db.forget_tenant(tenant_id) - net_provisioned = db.is_tenant_provisioned(tenant_id) - self.assertFalse(net_provisioned, 'The Tenant should be deleted') - - def test_network_is_remembered(self): - tenant_id = 'test' - network_id = '123' - segmentation_id = 456 - - db.remember_network(tenant_id, network_id, segmentation_id) - net_provisioned = db.is_network_provisioned(tenant_id, - network_id) - self.assertTrue(net_provisioned, 'Network must be provisioned') - - def test_network_is_removed(self): - tenant_id = 'test' - network_id = '123' - - db.remember_network(tenant_id, network_id, '123') - db.forget_network(tenant_id, network_id) - net_provisioned = db.is_network_provisioned(tenant_id, network_id) - self.assertFalse(net_provisioned, 'The network should be deleted') - - def test_vm_is_remembered(self): - vm_id = 'VM-1' - tenant_id = 'test' - network_id = '123' - port_id = 456 - host_id = 'ubuntu1' - - db.remember_vm(vm_id, host_id, port_id, network_id, tenant_id) - vm_provisioned = db.is_vm_provisioned(vm_id, host_id, port_id, - network_id, tenant_id) - self.assertTrue(vm_provisioned, 'VM must be provisioned') - - def test_vm_is_removed(self): - vm_id = 'VM-1' - tenant_id = 'test' - network_id = '123' - port_id = 456 - host_id = 'ubuntu1' - - db.remember_vm(vm_id, host_id, port_id, network_id, tenant_id) - db.forget_vm(vm_id, host_id, port_id, network_id, tenant_id) - vm_provisioned = db.is_vm_provisioned(vm_id, host_id, port_id, - network_id, tenant_id) - self.assertFalse(vm_provisioned, 'The vm should be deleted') - - def test_remembers_multiple_networks(self): - tenant_id = 'test' - expected_num_nets = 100 - nets = ['id%s' % n for n in range(expected_num_nets)] - for net_id in nets: - db.remember_network(tenant_id, net_id, 123) - - num_nets_provisioned = db.num_nets_provisioned(tenant_id) - self.assertEqual(expected_num_nets, num_nets_provisioned, - 'There should be %d nets, not %d' % - (expected_num_nets, num_nets_provisioned)) - - def test_removes_all_networks(self): - tenant_id = 'test' - num_nets = 100 - old_nets = db.num_nets_provisioned(tenant_id) - nets = ['id_%s' % n for n in range(num_nets)] - for net_id in nets: - db.remember_network(tenant_id, net_id, 123) - for net_id in nets: - db.forget_network(tenant_id, net_id) - - num_nets_provisioned = db.num_nets_provisioned(tenant_id) - expected = old_nets - self.assertEqual(expected, num_nets_provisioned, - 'There should be %d nets, not %d' % - (expected, num_nets_provisioned)) - - def test_remembers_multiple_tenants(self): - expected_num_tenants = 100 - tenants = ['id%s' % n for n in range(expected_num_tenants)] - for tenant_id in tenants: - db.remember_tenant(tenant_id) - - num_tenants_provisioned = db.num_provisioned_tenants() - self.assertEqual(expected_num_tenants, num_tenants_provisioned, - 'There should be %d tenants, not %d' % - (expected_num_tenants, num_tenants_provisioned)) - - def test_removes_multiple_tenants(self): - num_tenants = 100 - tenants = ['id%s' % n for n in range(num_tenants)] - for tenant_id in tenants: - db.remember_tenant(tenant_id) - for tenant_id in tenants: - db.forget_tenant(tenant_id) - - num_tenants_provisioned = db.num_provisioned_tenants() - expected = 0 - self.assertEqual(expected, num_tenants_provisioned, - 'There should be %d tenants, not %d' % - (expected, num_tenants_provisioned)) - - def test_num_vm_is_valid(self): - tenant_id = 'test' - network_id = '123' - port_id = 456 - host_id = 'ubuntu1' - - vm_to_remember = ['vm1', 'vm2', 'vm3'] - vm_to_forget = ['vm2', 'vm1'] - - for vm in vm_to_remember: - db.remember_vm(vm, host_id, port_id, network_id, tenant_id) - for vm in vm_to_forget: - db.forget_vm(vm, host_id, port_id, network_id, tenant_id) - - num_vms = len(db.get_vms(tenant_id)) - expected = len(vm_to_remember) - len(vm_to_forget) - - self.assertEqual(expected, num_vms, - 'There should be %d records, ' - 'got %d records' % (expected, num_vms)) - # clean up afterwards - db.forget_vm('vm3', host_id, port_id, network_id, tenant_id) - - def test_get_network_list_returns_eos_compatible_data(self): - tenant = u'test-1' - segm_type = 'vlan' - network_id = u'123' - network2_id = u'1234' - vlan_id = 123 - vlan2_id = 1234 - expected_eos_net_list = {network_id: {u'networkId': network_id, - u'segmentationTypeId': vlan_id, - u'segmentationType': segm_type}, - network2_id: {u'networkId': network2_id, - u'segmentationTypeId': vlan2_id, - u'segmentationType': segm_type}} - - db.remember_network(tenant, network_id, vlan_id) - db.remember_network(tenant, network2_id, vlan2_id) - - net_list = db.get_networks(tenant) - self.assertNotEqual(net_list != expected_eos_net_list, ('%s != %s' % - (net_list, expected_eos_net_list))) - - -class PositiveRPCWrapperValidConfigTestCase(base.BaseTestCase): - """Test cases to test the RPC between Arista Driver and EOS. - - Tests all methods used to send commands between Arista Driver and EOS - """ - - def setUp(self): - super(PositiveRPCWrapperValidConfigTestCase, self).setUp() - setup_valid_config() - self.drv = arista.AristaRPCWrapper() - self.region = 'RegionOne' - self.drv._server = mock.MagicMock() - - def _get_exit_mode_cmds(self, modes): - return ['exit'] * len(modes) - - def test_no_exception_on_correct_configuration(self): - self.assertIsNotNone(self.drv) - - def test_plug_host_into_network(self): - tenant_id = 'ten-1' - vm_id = 'vm-1' - port_id = 123 - network_id = 'net-id' - host = 'host' - port_name = '123-port' - - self.drv.plug_host_into_network(vm_id, host, port_id, - network_id, tenant_id, port_name) - cmds = ['enable', 'configure', 'cvx', 'service openstack', - 'region RegionOne', - 'tenant ten-1', 'vm id vm-1 hostid host', - 'port id 123 name "123-port" network-id net-id', - 'exit', 'exit', 'exit', 'exit', 'exit'] - - self.drv._server.runCmds.assert_called_once_with(version=1, cmds=cmds) - - def test_plug_dhcp_port_into_network(self): - tenant_id = 'ten-1' - vm_id = 'vm-1' - port_id = 123 - network_id = 'net-id' - host = 'host' - port_name = '123-port' - - self.drv.plug_dhcp_port_into_network(vm_id, host, port_id, - network_id, tenant_id, port_name) - cmds = ['enable', 'configure', 'cvx', 'service openstack', - 'region RegionOne', - 'tenant ten-1', 'network id net-id', - 'dhcp id vm-1 hostid host port-id 123 name "123-port"', - 'exit', 'exit', 'exit', 'exit'] - - self.drv._server.runCmds.assert_called_once_with(version=1, cmds=cmds) - - def test_unplug_host_from_network(self): - tenant_id = 'ten-1' - vm_id = 'vm-1' - port_id = 123 - network_id = 'net-id' - host = 'host' - self.drv.unplug_host_from_network(vm_id, host, port_id, - network_id, tenant_id) - cmds = ['enable', 'configure', 'cvx', 'service openstack', - 'region RegionOne', - 'tenant ten-1', 'vm id vm-1 hostid host', - 'no port id 123', - 'exit', 'exit', 'exit', 'exit', 'exit'] - self.drv._server.runCmds.assert_called_once_with(version=1, cmds=cmds) - - def test_unplug_dhcp_port_from_network(self): - tenant_id = 'ten-1' - vm_id = 'vm-1' - port_id = 123 - network_id = 'net-id' - host = 'host' - - self.drv.unplug_dhcp_port_from_network(vm_id, host, port_id, - network_id, tenant_id) - cmds = ['enable', 'configure', 'cvx', 'service openstack', - 'region RegionOne', - 'tenant ten-1', 'network id net-id', - 'no dhcp id vm-1 port-id 123', - 'exit', 'exit', 'exit', 'exit'] - - self.drv._server.runCmds.assert_called_once_with(version=1, cmds=cmds) - - def test_create_network(self): - tenant_id = 'ten-1' - network = { - 'network_id': 'net-id', - 'network_name': 'net-name', - 'segmentation_id': 123} - self.drv.create_network(tenant_id, network) - cmds = ['enable', 'configure', 'cvx', 'service openstack', - 'region RegionOne', - 'tenant ten-1', 'network id net-id name "net-name"', - 'segment 1 type vlan id 123', - 'exit', 'exit', 'exit', 'exit', 'exit', 'exit'] - self.drv._server.runCmds.assert_called_once_with(version=1, cmds=cmds) - - def test_create_network_bulk(self): - tenant_id = 'ten-2' - num_networks = 10 - networks = [{ - 'network_id': 'net-id-%d' % net_id, - 'network_name': 'net-name-%d' % net_id, - 'segmentation_id': net_id} for net_id in range(1, num_networks) - ] - - self.drv.create_network_bulk(tenant_id, networks) - cmds = ['enable', - 'configure', - 'cvx', - 'service openstack', - 'region RegionOne', - 'tenant ten-2'] - for net_id in range(1, num_networks): - cmds.append('network id net-id-%d name "net-name-%d"' % - (net_id, net_id)) - cmds.append('segment 1 type vlan id %d' % net_id) - - cmds.extend(self._get_exit_mode_cmds(['tenant', 'region', 'openstack', - 'cvx', 'configure', 'enable'])) - self.drv._server.runCmds.assert_called_once_with(version=1, cmds=cmds) - - def test_delete_network(self): - tenant_id = 'ten-1' - network_id = 'net-id' - self.drv.delete_network(tenant_id, network_id) - cmds = ['enable', 'configure', 'cvx', 'service openstack', - 'region RegionOne', - 'tenant ten-1', 'no network id net-id', - 'exit', 'exit', 'exit', 'exit', 'exit'] - self.drv._server.runCmds.assert_called_once_with(version=1, cmds=cmds) - - def test_delete_network_bulk(self): - tenant_id = 'ten-2' - num_networks = 10 - networks = [{ - 'network_id': 'net-id-%d' % net_id, - 'network_name': 'net-name-%d' % net_id, - 'segmentation_id': net_id} for net_id in range(1, num_networks) - ] - - networks = ['net-id-%d' % net_id for net_id in range(1, num_networks)] - self.drv.delete_network_bulk(tenant_id, networks) - cmds = ['enable', - 'configure', - 'cvx', - 'service openstack', - 'region RegionOne', - 'tenant ten-2'] - for net_id in range(1, num_networks): - cmds.append('no network id net-id-%d' % net_id) - - cmds.extend(self._get_exit_mode_cmds(['tenant', 'region', 'openstack', - 'cvx', 'configure'])) - self.drv._server.runCmds.assert_called_once_with(version=1, cmds=cmds) - - def test_delete_vm(self): - tenant_id = 'ten-1' - vm_id = 'vm-id' - self.drv.delete_vm(tenant_id, vm_id) - cmds = ['enable', 'configure', 'cvx', 'service openstack', - 'region RegionOne', - 'tenant ten-1', 'no vm id vm-id', - 'exit', 'exit', 'exit', 'exit', 'exit'] - self.drv._server.runCmds.assert_called_once_with(version=1, cmds=cmds) - - def test_delete_vm_bulk(self): - tenant_id = 'ten-2' - num_vms = 10 - vm_ids = ['vm-id-%d' % vm_id for vm_id in range(1, num_vms)] - self.drv.delete_vm_bulk(tenant_id, vm_ids) - - cmds = ['enable', - 'configure', - 'cvx', - 'service openstack', - 'region RegionOne', - 'tenant ten-2'] - - for vm_id in range(1, num_vms): - cmds.append('no vm id vm-id-%d' % vm_id) - - cmds.extend(self._get_exit_mode_cmds(['tenant', 'region', 'openstack', - 'cvx', 'configure'])) - self.drv._server.runCmds.assert_called_once_with(version=1, cmds=cmds) - - def test_create_vm_port_bulk(self): - tenant_id = 'ten-3' - num_vms = 10 - num_ports_per_vm = 2 - - vms = dict( - ('vm-id-%d' % vm_id, { - 'vmId': 'vm-id-%d' % vm_id, - 'host': 'host_%d' % vm_id, - } - ) for vm_id in range(1, num_vms) - ) - - devices = [n_const.DEVICE_OWNER_DHCP, 'compute'] - vm_port_list = [] - - net_count = 1 - for vm_id in range(1, num_vms): - for port_id in range(1, num_ports_per_vm): - port = { - 'id': 'port-id-%d-%d' % (vm_id, port_id), - 'device_id': 'vm-id-%d' % vm_id, - 'device_owner': devices[(vm_id + port_id) % 2], - 'network_id': 'network-id-%d' % net_count, - 'name': 'port-%d-%d' % (vm_id, port_id) - } - vm_port_list.append(port) - net_count += 1 - - self.drv.create_vm_port_bulk(tenant_id, vm_port_list, vms) - cmds = ['enable', - 'configure', - 'cvx', - 'service openstack', - 'region RegionOne', - 'tenant ten-3'] - - net_count = 1 - for vm_count in range(1, num_vms): - host = 'host_%s' % vm_count - for port_count in range(1, num_ports_per_vm): - vm_id = 'vm-id-%d' % vm_count - device_owner = devices[(vm_count + port_count) % 2] - port_name = '"port-%d-%d"' % (vm_count, port_count) - network_id = 'network-id-%d' % net_count - port_id = 'port-id-%d-%d' % (vm_count, port_count) - if device_owner == 'network:dhcp': - cmds.append('network id %s' % network_id) - cmds.append('dhcp id %s hostid %s port-id %s name %s' % ( - vm_id, host, port_id, port_name)) - elif device_owner == 'compute': - cmds.append('vm id %s hostid %s' % (vm_id, host)) - cmds.append('port id %s name %s network-id %s' % ( - port_id, port_name, network_id)) - net_count += 1 - - cmds.extend(self._get_exit_mode_cmds(['tenant', 'region', - 'openstack', 'cvx'])) - self.drv._server.runCmds.assert_called_once_with(version=1, cmds=cmds) - - def test_delete_tenant(self): - tenant_id = 'ten-1' - self.drv.delete_tenant(tenant_id) - cmds = ['enable', 'configure', 'cvx', 'service openstack', - 'region RegionOne', 'no tenant ten-1', - 'exit', 'exit', 'exit', 'exit'] - self.drv._server.runCmds.assert_called_once_with(version=1, cmds=cmds) - - def test_delete_tenant_bulk(self): - num_tenants = 10 - tenant_list = ['ten-%d' % t_id for t_id in range(1, num_tenants)] - self.drv.delete_tenant_bulk(tenant_list) - cmds = ['enable', - 'configure', - 'cvx', - 'service openstack', - 'region RegionOne'] - for ten_id in range(1, num_tenants): - cmds.append('no tenant ten-%d' % ten_id) - - cmds.extend(self._get_exit_mode_cmds(['region', 'openstack', - 'cvx', 'configure'])) - self.drv._server.runCmds.assert_called_once_with(version=1, cmds=cmds) - - def test_get_network_info_returns_none_when_no_such_net(self): - expected = [] - self.drv.get_tenants = mock.MagicMock() - self.drv.get_tenants.return_value = [] - - net_info = self.drv.get_tenants() - - self.drv.get_tenants.assert_called_once_with() - self.assertEqual(net_info, expected, ('Network info must be "None"' - 'for unknown network')) - - def test_get_network_info_returns_info_for_available_net(self): - valid_network_id = '12345' - valid_net_info = {'network_id': valid_network_id, - 'some_info': 'net info'} - known_nets = valid_net_info - - self.drv.get_tenants = mock.MagicMock() - self.drv.get_tenants.return_value = known_nets - - net_info = self.drv.get_tenants() - self.assertEqual(net_info, valid_net_info, - ('Must return network info for a valid net')) - - def test_check_cli_commands(self): - self.drv.check_cli_commands() - cmds = ['show openstack config region RegionOne timestamp'] - self.drv._server.runCmds.assert_called_once_with(version=1, cmds=cmds) - - -class AristaRPCWrapperInvalidConfigTestCase(base.BaseTestCase): - """Negative test cases to test the Arista Driver configuration.""" - - def setUp(self): - super(AristaRPCWrapperInvalidConfigTestCase, self).setUp() - self.setup_invalid_config() # Invalid config, required options not set - - def setup_invalid_config(self): - setup_arista_wrapper_config('') - - def test_raises_exception_on_wrong_configuration(self): - self.assertRaises(arista_exc.AristaConfigError, - arista.AristaRPCWrapper) - - -class NegativeRPCWrapperTestCase(base.BaseTestCase): - """Negative test cases to test the RPC between Arista Driver and EOS.""" - - def setUp(self): - super(NegativeRPCWrapperTestCase, self).setUp() - setup_valid_config() - - def test_exception_is_raised_on_json_server_error(self): - drv = arista.AristaRPCWrapper() - - drv._server = mock.MagicMock() - drv._server.runCmds.side_effect = Exception('server error') - self.assertRaises(arista_exc.AristaRpcError, drv.get_tenants) - - -class RealNetStorageAristaDriverTestCase(base.BaseTestCase): - """Main test cases for Arista Mechanism driver. - - Tests all mechanism driver APIs supported by Arista Driver. It invokes - all the APIs as they would be invoked in real world scenarios and - verifies the functionality. - """ - def setUp(self): - super(RealNetStorageAristaDriverTestCase, self).setUp() - self.fake_rpc = mock.MagicMock() - ndb.configure_db() - self.drv = arista.AristaDriver(self.fake_rpc) - - def tearDown(self): - super(RealNetStorageAristaDriverTestCase, self).tearDown() - self.drv.stop_synchronization_thread() - - def test_create_and_delete_network(self): - tenant_id = 'ten-1' - network_id = 'net1-id' - segmentation_id = 1001 - - network_context = self._get_network_context(tenant_id, - network_id, - segmentation_id) - self.drv.create_network_precommit(network_context) - net_provisioned = db.is_network_provisioned(tenant_id, network_id) - self.assertTrue(net_provisioned, 'The network should be created') - - expected_num_nets = 1 - num_nets_provisioned = db.num_nets_provisioned(tenant_id) - self.assertEqual(expected_num_nets, num_nets_provisioned, - 'There should be %d nets, not %d' % - (expected_num_nets, num_nets_provisioned)) - - #Now test the delete network - self.drv.delete_network_precommit(network_context) - net_provisioned = db.is_network_provisioned(tenant_id, network_id) - self.assertFalse(net_provisioned, 'The network should be created') - - expected_num_nets = 0 - num_nets_provisioned = db.num_nets_provisioned(tenant_id) - self.assertEqual(expected_num_nets, num_nets_provisioned, - 'There should be %d nets, not %d' % - (expected_num_nets, num_nets_provisioned)) - - def test_create_and_delete_multiple_networks(self): - tenant_id = 'ten-1' - expected_num_nets = 100 - segmentation_id = 1001 - nets = ['id%s' % n for n in range(expected_num_nets)] - for net_id in nets: - network_context = self._get_network_context(tenant_id, - net_id, - segmentation_id) - self.drv.create_network_precommit(network_context) - - num_nets_provisioned = db.num_nets_provisioned(tenant_id) - self.assertEqual(expected_num_nets, num_nets_provisioned, - 'There should be %d nets, not %d' % - (expected_num_nets, num_nets_provisioned)) - - #now test the delete networks - for net_id in nets: - network_context = self._get_network_context(tenant_id, - net_id, - segmentation_id) - self.drv.delete_network_precommit(network_context) - - num_nets_provisioned = db.num_nets_provisioned(tenant_id) - expected_num_nets = 0 - self.assertEqual(expected_num_nets, num_nets_provisioned, - 'There should be %d nets, not %d' % - (expected_num_nets, num_nets_provisioned)) - - def test_create_and_delete_ports(self): - tenant_id = 'ten-1' - network_id = 'net1-id' - segmentation_id = 1001 - vms = ['vm1', 'vm2', 'vm3'] - - network_context = self._get_network_context(tenant_id, - network_id, - segmentation_id) - self.drv.create_network_precommit(network_context) - - for vm_id in vms: - port_context = self._get_port_context(tenant_id, - network_id, - vm_id, - network_context) - self.drv.create_port_precommit(port_context) - - vm_list = db.get_vms(tenant_id) - provisioned_vms = len(vm_list) - expected_vms = len(vms) - self.assertEqual(expected_vms, provisioned_vms, - 'There should be %d ' - 'hosts, not %d' % (expected_vms, provisioned_vms)) - - # Now test the delete ports - for vm_id in vms: - port_context = self._get_port_context(tenant_id, - network_id, - vm_id, - network_context) - self.drv.delete_port_precommit(port_context) - - vm_list = db.get_vms(tenant_id) - provisioned_vms = len(vm_list) - expected_vms = 0 - self.assertEqual(expected_vms, provisioned_vms, - 'There should be %d ' - 'VMs, not %d' % (expected_vms, provisioned_vms)) - - def _get_network_context(self, tenant_id, net_id, seg_id): - network = {'id': net_id, - 'tenant_id': tenant_id} - network_segments = [{'segmentation_id': seg_id}] - return FakeNetworkContext(network, network_segments, network) - - def _get_port_context(self, tenant_id, net_id, vm_id, network): - port = {'device_id': vm_id, - 'device_owner': 'compute', - 'binding:host_id': 'ubuntu1', - 'tenant_id': tenant_id, - 'id': 101, - 'network_id': net_id - } - return FakePortContext(port, port, network) - - -class fake_keystone_info_class(object): - """To generate fake Keystone Authentification token information - - Arista Driver expects Keystone auth info. This fake information - is for testing only - """ - auth_protocol = 'abc' - auth_host = 'host' - auth_port = 5000 - admin_user = 'neutron' - admin_password = 'fun' - - -class FakeNetworkContext(object): - """To generate network context for testing purposes only.""" - - def __init__(self, network, segments=None, original_network=None): - self._network = network - self._original_network = original_network - self._segments = segments - - @property - def current(self): - return self._network - - @property - def original(self): - return self._original_network - - @property - def network_segments(self): - return self._segments - - -class FakePortContext(object): - """To generate port context for testing purposes only.""" - - def __init__(self, port, original_port, network): - self._port = port - self._original_port = original_port - self._network_context = network - - @property - def current(self): - return self._port - - @property - def original(self): - return self._original_port - - @property - def network(self): - return self._network_context diff --git a/neutron/tests/unit/ml2/drivers/test_bigswitch_mech.py b/neutron/tests/unit/ml2/drivers/test_bigswitch_mech.py deleted file mode 100644 index ea884ae51..000000000 --- a/neutron/tests/unit/ml2/drivers/test_bigswitch_mech.py +++ /dev/null @@ -1,144 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2014 Big Switch Networks, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import contextlib -import mock -import webob.exc - -from neutron import context as neutron_context -from neutron.extensions import portbindings -from neutron import manager -from neutron.plugins.bigswitch import servermanager -from neutron.plugins.ml2 import config as ml2_config -from neutron.plugins.ml2.drivers import type_vlan as vlan_config -import neutron.tests.unit.bigswitch.test_restproxy_plugin as trp -from neutron.tests.unit.ml2 import test_ml2_plugin -from neutron.tests.unit import test_db_plugin - -PHYS_NET = 'physnet1' -VLAN_START = 1000 -VLAN_END = 1100 -SERVER_POOL = 'neutron.plugins.bigswitch.servermanager.ServerPool' -DRIVER_MOD = 'neutron.plugins.ml2.drivers.mech_bigswitch.driver' -DRIVER = DRIVER_MOD + '.BigSwitchMechanismDriver' - - -class TestBigSwitchMechDriverBase(trp.BigSwitchProxyPluginV2TestCase): - - def setUp(self): - # Configure the ML2 mechanism drivers and network types - ml2_opts = { - 'mechanism_drivers': ['bigswitch'], - 'tenant_network_types': ['vlan'], - } - for opt, val in ml2_opts.items(): - ml2_config.cfg.CONF.set_override(opt, val, 'ml2') - - # Configure the ML2 VLAN parameters - phys_vrange = ':'.join([PHYS_NET, str(VLAN_START), str(VLAN_END)]) - vlan_config.cfg.CONF.set_override('network_vlan_ranges', - [phys_vrange], - 'ml2_type_vlan') - super(TestBigSwitchMechDriverBase, - self).setUp(test_ml2_plugin.PLUGIN_NAME) - - -class TestBigSwitchMechDriverNetworksV2(test_db_plugin.TestNetworksV2, - TestBigSwitchMechDriverBase): - pass - - -class TestBigSwitchMechDriverPortsV2(test_db_plugin.TestPortsV2, - TestBigSwitchMechDriverBase): - - VIF_TYPE = portbindings.VIF_TYPE_OVS - - def setUp(self): - super(TestBigSwitchMechDriverPortsV2, self).setUp() - self.port_create_status = 'DOWN' - - def test_update_port_status_build(self): - with self.port() as port: - self.assertEqual(port['port']['status'], 'DOWN') - self.assertEqual(self.port_create_status, 'DOWN') - - def _make_port(self, fmt, net_id, expected_res_status=None, arg_list=None, - **kwargs): - arg_list = arg_list or () - arg_list += ('binding:host_id', ) - res = self._create_port(fmt, net_id, expected_res_status, - arg_list, **kwargs) - # Things can go wrong - raise HTTP exc with res code only - # so it can be caught by unit tests - if res.status_int >= 400: - raise webob.exc.HTTPClientError(code=res.status_int) - return self.deserialize(fmt, res) - - def test_create404_triggers_background_sync(self): - # allow the async background thread to run for this test - self.spawn_p.stop() - with contextlib.nested( - mock.patch(SERVER_POOL + '.rest_create_port', - side_effect=servermanager.RemoteRestError( - reason=servermanager.NXNETWORK, status=404)), - mock.patch(DRIVER + '._send_all_data'), - self.port(**{'device_id': 'devid', 'binding:host_id': 'host'}) - ) as (mock_http, mock_send_all, p): - # wait for thread to finish - mm = manager.NeutronManager.get_plugin().mechanism_manager - bigdriver = mm.mech_drivers['bigswitch'].obj - bigdriver.evpool.waitall() - mock_send_all.assert_has_calls([ - mock.call( - send_routers=False, send_ports=True, - send_floating_ips=False, - triggered_by_tenant=p['port']['tenant_id'] - ) - ]) - self.spawn_p.start() - - def test_udpate404_triggers_background_sync(self): - with contextlib.nested( - mock.patch(SERVER_POOL + '.rest_update_port', - side_effect=servermanager.RemoteRestError( - reason=servermanager.NXNETWORK, s