OpenStack Neutron Puppet Module
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

379 lines
14KB

  1. require 'spec_helper'
  2. describe 'neutron::agents::ml2::ovs' do
  3. let :pre_condition do
  4. "class { 'neutron': }"
  5. end
  6. let :default_params do
  7. { :package_ensure => 'present',
  8. :enabled => true,
  9. :bridge_uplinks => [],
  10. :bridge_mappings => [],
  11. :integration_bridge => 'br-int',
  12. :local_ip => false,
  13. :tunnel_types => [],
  14. :tunnel_bridge => 'br-tun',
  15. :drop_flows_on_start => false,
  16. :firewall_driver => 'iptables_hybrid',
  17. :manage_vswitch => true,
  18. :purge_config => false,
  19. :enable_dpdk => false,
  20. }
  21. end
  22. let :params do
  23. {}
  24. end
  25. shared_examples 'neutron plugin ovs agent with ml2 plugin' do
  26. let :p do
  27. default_params.merge(params)
  28. end
  29. it { should contain_class('neutron::params') }
  30. it 'passes purge to resource' do
  31. should contain_resources('neutron_agent_ovs').with({
  32. :purge => false
  33. })
  34. end
  35. it 'configures plugins/ml2/openvswitch_agent.ini' do
  36. should contain_neutron_agent_ovs('agent/polling_interval').with_value('<SERVICE DEFAULT>')
  37. should contain_neutron_agent_ovs('agent/l2_population').with_value('<SERVICE DEFAULT>')
  38. should contain_neutron_agent_ovs('agent/arp_responder').with_value('<SERVICE DEFAULT>')
  39. should contain_neutron_agent_ovs('agent/drop_flows_on_start').with_value(p[:drop_flows_on_start])
  40. should contain_neutron_agent_ovs('agent/extensions').with_value(['<SERVICE DEFAULT>'])
  41. should contain_neutron_agent_ovs('agent/minimize_polling').with_value(['<SERVICE DEFAULT>'])
  42. should contain_neutron_agent_ovs('agent/tunnel_csum').with_value(['<SERVICE DEFAULT>'])
  43. should contain_neutron_agent_ovs('ovs/datapath_type').with_value(['<SERVICE DEFAULT>'])
  44. should contain_neutron_agent_ovs('ovs/vhostuser_socket_dir').with_value(['<SERVICE DEFAULT>'])
  45. should contain_neutron_agent_ovs('ovs/ovsdb_interface').with_value(['<SERVICE DEFAULT>'])
  46. should contain_neutron_agent_ovs('ovs/ovsdb_timeout').with_value('<SERVICE DEFAULT>')
  47. should contain_neutron_agent_ovs('ovs/integration_bridge').with_value(p[:integration_bridge])
  48. should contain_neutron_agent_ovs('securitygroup/firewall_driver').\
  49. with_value(p[:firewall_driver])
  50. should contain_neutron_agent_ovs('securitygroup/enable_security_group').\
  51. with_value(['<SERVICE DEFAULT>'])
  52. should_not contain_neutron_agent_ovs('securitygroup/permitted_ethertypes')
  53. should contain_neutron_agent_ovs('ovs/tunnel_bridge').with_ensure('absent')
  54. should contain_neutron_agent_ovs('ovs/local_ip').with_ensure('absent')
  55. should contain_neutron_agent_ovs('ovs/int_peer_patch_port').with_ensure('absent')
  56. should contain_neutron_agent_ovs('ovs/tun_peer_patch_port').with_ensure('absent')
  57. should contain_neutron_agent_ovs('agent/tunnel_types').with_ensure('absent')
  58. end
  59. it 'installs neutron ovs agent package' do
  60. if platform_params.has_key?(:ovs_agent_package)
  61. should contain_package('neutron-ovs-agent').with(
  62. :name => platform_params[:ovs_agent_package],
  63. :ensure => p[:package_ensure],
  64. :tag => ['openstack', 'neutron-package'],
  65. )
  66. else
  67. end
  68. end
  69. it 'configures neutron ovs agent service' do
  70. should contain_service('neutron-ovs-agent-service').with(
  71. :name => platform_params[:ovs_agent_service],
  72. :enable => true,
  73. :ensure => 'running',
  74. :tag => ['neutron-service', 'neutron-db-sync-service'],
  75. )
  76. should contain_service('neutron-ovs-agent-service').that_subscribes_to('Anchor[neutron::service::begin]')
  77. should contain_service('neutron-ovs-agent-service').that_notifies('Anchor[neutron::service::end]')
  78. end
  79. context 'with manage_service as false' do
  80. before :each do
  81. params.merge!(:manage_service => false)
  82. end
  83. it 'should not start/stop service' do
  84. should contain_service('neutron-ovs-agent-service').without_ensure
  85. end
  86. end
  87. context 'when supplying permitted ethertypes' do
  88. before :each do
  89. params.merge!(:permitted_ethertypes => ['0x4008', '0x5'])
  90. end
  91. it 'should configured ethertypes' do
  92. should contain_neutron_agent_ovs('securitygroup/permitted_ethertypes').with_value('0x4008,0x5')
  93. end
  94. end
  95. context 'when supplying a firewall driver' do
  96. before :each do
  97. params.merge!(:firewall_driver => false)
  98. end
  99. it 'should configure firewall driver' do
  100. should contain_neutron_agent_ovs('securitygroup/firewall_driver').with_ensure('absent')
  101. end
  102. end
  103. context 'when disabling security groups' do
  104. before :each do
  105. params.merge!(:enable_security_group => false)
  106. end
  107. it 'should disable securitygroups' do
  108. should contain_neutron_agent_ovs('securitygroup/enable_security_group').with_value('false')
  109. end
  110. end
  111. context 'when enabling ARP responder' do
  112. before :each do
  113. params.merge!(:arp_responder => true)
  114. end
  115. it 'should enable ARP responder' do
  116. should contain_neutron_agent_ovs('agent/arp_responder').with_value(true)
  117. end
  118. end
  119. context 'when enabling DVR' do
  120. before :each do
  121. params.merge!(:enable_distributed_routing => true,
  122. :l2_population => true )
  123. end
  124. it 'should enable DVR' do
  125. should contain_neutron_agent_ovs('agent/enable_distributed_routing').with_value(true)
  126. end
  127. end
  128. context 'when supplying bridge mappings for provider networks' do
  129. before :each do
  130. params.merge!(:bridge_uplinks => ['br-ex:eth2'],:bridge_mappings => ['default:br-ex'])
  131. end
  132. it 'should require vswitch::ovs' do
  133. should contain_class('vswitch::ovs')
  134. end
  135. it 'configures bridge mappings' do
  136. should contain_neutron_agent_ovs('ovs/bridge_mappings')
  137. end
  138. it 'should configure bridge mappings' do
  139. should contain_neutron__plugins__ovs__bridge(params[:bridge_mappings].join(',')).with(
  140. :before => 'Service[neutron-ovs-agent-service]'
  141. )
  142. end
  143. it 'should configure bridge uplinks' do
  144. should contain_neutron__plugins__ovs__port(params[:bridge_uplinks].join(',')).with(
  145. :before => 'Service[neutron-ovs-agent-service]'
  146. )
  147. end
  148. end
  149. context 'when supplying bridge mappings for provider networks with manage vswitch set to false' do
  150. before :each do
  151. params.merge!(:bridge_uplinks => ['br-ex:eth2'],:bridge_mappings => ['default:br-ex'], :manage_vswitch => false)
  152. end
  153. it 'should not require vswitch::ovs' do
  154. should_not contain_class('vswitch::ovs')
  155. end
  156. it 'configures bridge mappings' do
  157. should contain_neutron_agent_ovs('ovs/bridge_mappings')
  158. end
  159. it 'should not configure bridge mappings' do
  160. should_not contain_neutron__plugins__ovs__bridge(params[:bridge_mappings].join(',')).with(
  161. :before => 'Service[neutron-ovs-agent-service]'
  162. )
  163. end
  164. it 'should not configure bridge uplinks' do
  165. should_not contain_neutron__plugins__ovs__port(params[:bridge_uplinks].join(',')).with(
  166. :before => 'Service[neutron-ovs-agent-service]'
  167. )
  168. end
  169. end
  170. context 'when setting ovsdb_timeout' do
  171. before :each do
  172. params.merge!( :ovsdb_timeout => 30 )
  173. end
  174. it 'configures ovsdb_timeout' do
  175. should contain_neutron_agent_ovs('ovs/ovsdb_timeout').with_value(params[:ovsdb_timeout])
  176. end
  177. end
  178. context 'when supplying extensions for ML2 plugin' do
  179. before :each do
  180. params.merge!(:extensions => ['qos'])
  181. end
  182. it 'configures extensions' do
  183. should contain_neutron_agent_ovs('agent/extensions').with_value(params[:extensions].join(','))
  184. end
  185. end
  186. context 'when supplying DPDK specific options' do
  187. before :each do
  188. params.merge!(:datapath_type => 'netdev', :vhostuser_socket_dir => '/var/run/openvswitch')
  189. end
  190. it 'configures ovs for DPDK' do
  191. should contain_neutron_agent_ovs('ovs/datapath_type').with_value(params[:datapath_type])
  192. should contain_neutron_agent_ovs('ovs/vhostuser_socket_dir').with_value(params[:vhostuser_socket_dir])
  193. end
  194. end
  195. context 'when enabling tunneling' do
  196. context 'without local ip address' do
  197. before :each do
  198. params.merge!(:tunnel_types => ['vxlan'])
  199. end
  200. it { should raise_error(Puppet::Error, /Local ip for ovs agent must be set when tunneling is enabled/) }
  201. end
  202. context 'with default params' do
  203. before :each do
  204. params.merge!(:tunnel_types => ['vxlan'], :local_ip => '127.0.0.1' )
  205. end
  206. it 'should configure ovs for tunneling' do
  207. should contain_neutron_agent_ovs('ovs/tunnel_bridge').with_value(default_params[:tunnel_bridge])
  208. should contain_neutron_agent_ovs('ovs/local_ip').with_value('127.0.0.1')
  209. should contain_neutron_agent_ovs('ovs/int_peer_patch_port').with_value('<SERVICE DEFAULT>')
  210. should contain_neutron_agent_ovs('ovs/tun_peer_patch_port').with_value('<SERVICE DEFAULT>')
  211. end
  212. end
  213. context 'with vxlan tunneling' do
  214. before :each do
  215. params.merge!(:local_ip => '127.0.0.1',
  216. :tunnel_types => ['vxlan'],
  217. :vxlan_udp_port => '4789')
  218. end
  219. it 'should perform vxlan network configuration' do
  220. should contain_neutron_agent_ovs('agent/tunnel_types').with_value(params[:tunnel_types])
  221. should contain_neutron_agent_ovs('agent/vxlan_udp_port').with_value(params[:vxlan_udp_port])
  222. end
  223. end
  224. context 'when l2 population is disabled and DVR and tunneling enabled' do
  225. before :each do
  226. params.merge!(:enable_distributed_routing => true,
  227. :l2_population => false,
  228. :tunnel_types => ['vxlan'],
  229. :local_ip => '127.0.0.1' )
  230. end
  231. it { should raise_error(Puppet::Error, /L2 population must be enabled when DVR and tunneling are enabled/) }
  232. end
  233. context 'when DVR is enabled and l2 population and tunneling are disabled' do
  234. before :each do
  235. params.merge!(:enable_distributed_routing => true,
  236. :l2_population => false,
  237. :tunnel_types => [] )
  238. end
  239. it 'should enable DVR without L2 population' do
  240. should contain_neutron_agent_ovs('agent/enable_distributed_routing').with_value(true)
  241. should contain_neutron_agent_ovs('agent/l2_population').with_value(false)
  242. end
  243. end
  244. end
  245. context 'when supplying ovsdb_interface' do
  246. context 'with incorrect value' do
  247. before :each do
  248. params.merge!(:ovsdb_interface => 'random')
  249. end
  250. it { should raise_error(Puppet::Error, /A value of \$ovsdb_interface is incorrect. The allowed values are vsctl and native/) }
  251. end
  252. context 'with supported value' do
  253. before :each do
  254. params.merge!(:ovsdb_interface => 'native')
  255. end
  256. it 'should configure ovsdb_interface for ovs' do
  257. should contain_neutron_agent_ovs('ovs/ovsdb_interface').with_value('native')
  258. end
  259. end
  260. end
  261. context 'when enabling dpdk with manage vswitch disabled' do
  262. before :each do
  263. params.merge!(:enable_dpdk => true, :manage_vswitch => false)
  264. end
  265. it { should raise_error(Puppet::Error, /Enabling DPDK without manage vswitch does not have any effect/) }
  266. end
  267. end
  268. shared_examples 'neutron::agents::ml2::ovs on Debian' do
  269. # placeholder for debian specific tests
  270. end
  271. shared_examples 'neutron::agents::ml2::ovs on RedHat' do
  272. it 'configures neutron ovs cleanup service' do
  273. should contain_service('ovs-cleanup-service').with(
  274. :name => platform_params[:ovs_cleanup_service],
  275. :enable => true
  276. ).that_requires('Anchor[neutron::install::end]')
  277. should contain_package('neutron-ovs-agent').that_requires('Anchor[neutron::install::begin]')
  278. should contain_package('neutron-ovs-agent').that_notifies('Anchor[neutron::install::end]')
  279. end
  280. it 'configures neutron destroy patch ports service' do
  281. should contain_service('neutron-destroy-patch-ports-service').with(
  282. :name => platform_params[:destroy_patch_ports_service],
  283. :enable => true,
  284. :ensure => 'running',
  285. :tag => ['neutron-service'],
  286. )
  287. end
  288. context 'when enabling dpdk with manage vswitch is default' do
  289. let :pre_condition do
  290. "class { 'vswitch::dpdk': host_core_list => '1,2', memory_channels => '1' }"
  291. end
  292. before :each do
  293. params.merge!(:enable_dpdk => true,
  294. :datapath_type => 'netdev',
  295. :vhostuser_socket_dir => '/var/run/openvswitch')
  296. end
  297. it 'should require vswitch::dpdk' do
  298. should contain_class('vswitch::dpdk')
  299. end
  300. end
  301. end
  302. on_supported_os({
  303. :supported_os => OSDefaults.get_supported_os
  304. }).each do |os,facts|
  305. context "on #{os}" do
  306. let (:facts) do
  307. facts.merge!(OSDefaults.get_facts())
  308. end
  309. let (:platform_params) do
  310. case facts[:osfamily]
  311. when 'Debian'
  312. { :ovs_agent_package => 'neutron-openvswitch-agent',
  313. :ovs_agent_service => 'neutron-openvswitch-agent' }
  314. when 'RedHat'
  315. { :ovs_cleanup_service => 'neutron-ovs-cleanup',
  316. :ovs_agent_service => 'neutron-openvswitch-agent',
  317. :destroy_patch_ports_service => 'neutron-destroy-patch-ports' }
  318. end
  319. end
  320. it_behaves_like 'neutron plugin ovs agent with ml2 plugin'
  321. it_behaves_like "neutron::agents::ml2::ovs on #{facts[:osfamily]}"
  322. end
  323. end
  324. end