diff --git a/spec/classes/neutron_plugins_ml2_spec.rb b/spec/classes/neutron_plugins_ml2_spec.rb index 236a2ccda..e79c035c5 100644 --- a/spec/classes/neutron_plugins_ml2_spec.rb +++ b/spec/classes/neutron_plugins_ml2_spec.rb @@ -145,8 +145,8 @@ describe 'neutron::plugins::ml2' do context 'configure ml2 with bad driver value' do before :each do - scope.expects(:warning).with('type_driver unknown.') - params.merge!(:type_drivers => ['foobar']) + allow(scope).to receive(:warning).with('type_driver unknown.') + params.merge!(:type_drivers => ['foobar']) end end diff --git a/spec/functions/convert_cert_to_string_spec.rb b/spec/functions/convert_cert_to_string_spec.rb index e0107571f..854782d04 100644 --- a/spec/functions/convert_cert_to_string_spec.rb +++ b/spec/functions/convert_cert_to_string_spec.rb @@ -15,24 +15,24 @@ describe 'convert_cert_to_string' do context 'when file does not exist' do it 'fails when cert file doesnt exist' do - File.stubs(:file?).with('/etc/ssl/certs/test.pem').returns(false) + allow(File).to receive(:file?).with('/etc/ssl/certs/test.pem').and_return(false) is_expected.to run.with_params('/etc/ssl/certs/test.pem').and_raise_error(Puppet::ParseError) end end context 'with certificate that doesnt need strip' do it 'should return proper value' do - File.stubs(:file?).with('/etc/ssl/certs/test.pem').returns(true) - File.stubs(:readlines).with('/etc/ssl/certs/test.pem').returns(['----- BEGIN CERTIFICATE -----', 'abc123data', '----- END CERTIFICATE -----']) + allow(File).to receive(:file?).with('/etc/ssl/certs/test.pem').and_return(true) + allow(File).to receive(:readlines).with('/etc/ssl/certs/test.pem').and_return(['----- BEGIN CERTIFICATE -----', 'abc123data', '----- END CERTIFICATE -----']) is_expected.to run.with_params('/etc/ssl/certs/test.pem').and_return('abc123data') end end context 'with certificate that requires strip' do it 'should return proper value' do - File.stubs(:file?).with('/etc/ssl/certs/test.pem').returns(true) + allow(File).to receive(:file?).with('/etc/ssl/certs/test.pem').and_return(true) # NOTE(tobias-urdin): There is spacing in the return data here on purpose to test the ruby string strip. - File.stubs(:readlines).with('/etc/ssl/certs/test.pem').returns(['----- BEGIN CERTIFICATE -----', ' abc321 ', '----- END CERTIFICATE -----']) + allow(File).to receive(:readlines).with('/etc/ssl/certs/test.pem').and_return(['----- BEGIN CERTIFICATE -----', ' abc321 ', '----- END CERTIFICATE -----']) is_expected.to run.with_params('/etc/ssl/certs/test.pem').and_return('abc321') end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 33f27e2d5..a99919e74 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,6 +13,8 @@ RSpec.configure do |c| c.module_path = File.join(fixture_path, 'modules') c.manifest_dir = File.join(fixture_path, 'manifests') + + c.mock_with :rspec end at_exit { RSpec::Puppet::Coverage.report! } diff --git a/spec/unit/provider/neutron_agent_ovs/ini_setting_spec.rb b/spec/unit/provider/neutron_agent_ovs/ini_setting_spec.rb index 6d3457015..e7f23ea3f 100644 --- a/spec/unit/provider/neutron_agent_ovs/ini_setting_spec.rb +++ b/spec/unit/provider/neutron_agent_ovs/ini_setting_spec.rb @@ -14,7 +14,6 @@ describe provider_class do [ 'RedHat', 'Debian', 'Ubuntu' ].each do |os| context "on #{os} with default setting" do it 'it should fall back to default and use plugins/ml2/openvswitch_agent.ini' do - Facter.fact(:operatingsystem).stubs(:value).returns("#{os}") expect(provider.section).to eq('DEFAULT') expect(provider.setting).to eq('foo') expect(provider.file_path).to eq('/etc/neutron/plugins/ml2/openvswitch_agent.ini') diff --git a/spec/unit/provider/neutron_l3_ovs_bridge/neutron_spec.rb b/spec/unit/provider/neutron_l3_ovs_bridge/neutron_spec.rb index dc7018d0d..9e2e6a18d 100644 --- a/spec/unit/provider/neutron_l3_ovs_bridge/neutron_spec.rb +++ b/spec/unit/provider/neutron_l3_ovs_bridge/neutron_spec.rb @@ -21,7 +21,7 @@ describe provider_class do describe 'when retrieving bridge ip addresses' do it 'should return an empty array for no matches' do - provider.expects(:ip).returns('') + expect(provider).to receive(:ip).and_return('') expect(provider.bridge_ip_addresses).to eql [] end @@ -33,7 +33,7 @@ describe provider_class do inet6 fe80::d095:15ff:fe80:b54f/64 scope link valid_lft forever preferred_lft forever EOT - provider.expects(:ip).returns(output) + expect(provider).to receive(:ip).and_return(output) expect(provider.bridge_ip_addresses).to eql ['172.24.4.225/28'] end @@ -42,8 +42,8 @@ EOT describe 'when checking if the l3 bridge exists' do it 'should return true if the gateway ip is present' do - provider.expects(:bridge_ip_addresses).returns(['a']) - provider.expects(:gateway_ip).returns('a') + expect(provider).to receive(:bridge_ip_addresses).and_return(['a']) + expect(provider).to receive(:gateway_ip).and_return('a') expect(provider.exists?).to eql true end diff --git a/spec/unit/provider/neutron_network/openstack_spec.rb b/spec/unit/provider/neutron_network/openstack_spec.rb index 03d9c107d..5880912da 100644 --- a/spec/unit/provider/neutron_network/openstack_spec.rb +++ b/spec/unit/provider/neutron_network/openstack_spec.rb @@ -40,10 +40,10 @@ describe provider_class do describe '#create' do context 'with defaults' do it 'creates network' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'create', '--format', 'shell', ['net1']) - .returns('admin_state_up="True" + .and_return('admin_state_up="True" availability_zone_hints="[]" id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" project_id="60f9544eb94c42a6b7e8e98c2be981b1" @@ -70,10 +70,10 @@ mtu="1500"') end it 'creates network' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'create', '--format', 'shell', ['net1', '--disable']) - .returns('admin_state_up="False" + .and_return('admin_state_up="False" availability_zone_hints="[]" id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" project_id="60f9544eb94c42a6b7e8e98c2be981b1" @@ -96,10 +96,10 @@ mtu="1500"') end it 'creates network' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'create', '--format', 'shell', ['net1', '--share']) - .returns('admin_state_up="True" + .and_return('admin_state_up="True" availability_zone_hints="[]" id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" project_id="60f9544eb94c42a6b7e8e98c2be981b1" @@ -122,10 +122,10 @@ mtu="1500"') end it 'creates network' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'create', '--format', 'shell', ['net1', '--project=openstack']) - .returns('admin_state_up="True" + .and_return('admin_state_up="True" availability_zone_hints="[]" id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" project_id="60f9544eb94c42a6b7e8e98c2be981b1" @@ -149,12 +149,12 @@ mtu="1500"') end it 'creates network' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'create', '--format', 'shell', ['net1', '--provider-network-type=vlan', '--provider-physical-network=datacentre', '--provider-segmentation-id=10']) - .returns('admin_state_up="True" + .and_return('admin_state_up="True" availability_zone_hints="[]" id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" project_id="60f9544eb94c42a6b7e8e98c2be981b1" @@ -182,10 +182,10 @@ mtu="1500"') end it 'creates network' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'create', '--format', 'shell', ['net1', '--external']) - .returns('admin_state_up="True" + .and_return('admin_state_up="True" availability_zone_hints="[]" id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" project_id="60f9544eb94c42a6b7e8e98c2be981b1" @@ -207,10 +207,10 @@ mtu="1500"') end it 'creates network' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'create', '--format', 'shell', ['net1', '--mtu=9000']) - .returns('admin_state_up="True" + .and_return('admin_state_up="True" availability_zone_hints="[]" id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" project_id="60f9544eb94c42a6b7e8e98c2be981b1" @@ -226,7 +226,7 @@ mtu="9000"') describe '#destroy' do it 'removes network' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'delete', 'net1') provider.destroy expect(provider.exists?).to be_falsey @@ -236,12 +236,12 @@ mtu="9000"') describe '#flush' do context '.admin_state_up' do it 'updates network' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'set', ['net1', '--disable']) provider.admin_state_up = 'False' provider.flush - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'set', ['net1', '--enable']) provider.admin_state_up = 'True' provider.flush @@ -250,12 +250,12 @@ mtu="9000"') context '.shared' do it 'updates network' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'set', ['net1', '--share']) provider.shared = 'True' provider.flush - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'set', ['net1', '--no-share']) provider.shared = 'False' provider.flush @@ -264,12 +264,12 @@ mtu="9000"') context '.router_external' do it 'updates network' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'set', ['net1', '--external']) provider.router_external = 'True' provider.flush - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'set', ['net1', '--internal']) provider.router_external = 'False' provider.flush @@ -278,7 +278,7 @@ mtu="9000"') context '.mtu' do it 'updates mtu' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'set', ['net1', '--mtu=1490']) provider.mtu = 1490 provider.flush @@ -288,26 +288,26 @@ mtu="9000"') describe '#instances' do it 'lists networks' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'list', '--quiet', '--format', 'csv', []) - .returns('"ID","Name","Subnets" + .and_return('"ID","Name","Subnets" "076520cc-b783-4cf5-a4a9-4cb5a5e93a9b","net1","[\'dd5e0ef1-2c88-4b0b-ba08-7df65be87963\']", "34e8f42b-89db-4a5b-92db-76ca7073414d","net2","[\'0da7a631-0f8f-4e51-8b1c-7a29d0d4f7b5\']", ') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'show', '--format', 'shell', '076520cc-b783-4cf5-a4a9-4cb5a5e93a9b') - .returns('admin_state_up="True" + .and_return('admin_state_up="True" availability_zone_hints="[]" id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" project_id="60f9544eb94c42a6b7e8e98c2be981b1" router_external="False" shared="False" mtu="1500"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'show', '--format', 'shell', '34e8f42b-89db-4a5b-92db-76ca7073414d') - .returns('admin_state_up="False" + .and_return('admin_state_up="False" availability_zone_hints="[]" id="34e8f42b-89db-4a5b-92db-76ca7073414d" project_id="60f9544eb94c42a6b7e8e98c2be981b1" diff --git a/spec/unit/provider/neutron_plugin_nuage/ini_setting_spec.rb b/spec/unit/provider/neutron_plugin_nuage/ini_setting_spec.rb index b99785658..a61ef1ecd 100644 --- a/spec/unit/provider/neutron_plugin_nuage/ini_setting_spec.rb +++ b/spec/unit/provider/neutron_plugin_nuage/ini_setting_spec.rb @@ -14,7 +14,6 @@ describe provider_class do [ 'RedHat', 'Debian' ].each do |os| context "on #{os} with default setting" do it 'it should fall back to default and use plugin.ini' do - Facter.fact(:operatingsystem).stubs(:value).returns("#{os}") expect(provider.section).to eq('DEFAULT') expect(provider.setting).to eq('foo') expect(provider.file_path).to eq('/etc/neutron/plugins/nuage/plugin.ini') diff --git a/spec/unit/provider/neutron_plugin_opencontrail/ini_setting_spec.rb b/spec/unit/provider/neutron_plugin_opencontrail/ini_setting_spec.rb index 97904334c..cdd9abee7 100644 --- a/spec/unit/provider/neutron_plugin_opencontrail/ini_setting_spec.rb +++ b/spec/unit/provider/neutron_plugin_opencontrail/ini_setting_spec.rb @@ -14,7 +14,6 @@ describe provider_class do [ 'RedHat', 'Debian' ].each do |os| context "on #{os} with default setting" do it 'it should fall back to default and use ContrailPlugin.ini' do - Facter.fact(:operatingsystem).stubs(:value).returns("#{os}") expect(provider.section).to eq('DEFAULT') expect(provider.setting).to eq('foo') expect(provider.file_path).to eq('/etc/neutron/plugins/opencontrail/ContrailPlugin.ini') diff --git a/spec/unit/provider/neutron_port/openstack_spec.rb b/spec/unit/provider/neutron_port/openstack_spec.rb index d3e52b0f1..c70324bac 100644 --- a/spec/unit/provider/neutron_port/openstack_spec.rb +++ b/spec/unit/provider/neutron_port/openstack_spec.rb @@ -41,10 +41,10 @@ describe provider_class do describe '#create' do context 'with defaults' do it 'creates port' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('port', 'create', '--format', 'shell', ['port1', '--network=net1']) - .returns('admin_state_up="True" + .and_return('admin_state_up="True" allowed_address_pairs="[]" binding_host_id="" binding_profile="{}" @@ -58,15 +58,15 @@ network_id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" project_id="60f9544eb94c42a6b7e8e98c2be981b1" security_groups="f1f0c3a3-9f2c-46b9-b2a5-b97d9a87bd7e" status="ACTIVE"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'show', '--format', 'shell', ['076520cc-b783-4cf5-a4a9-4cb5a5e93a9b']) - .returns('id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" + .and_return('id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" name="net1"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'show', '--format', 'shell', ['dd5e0ef1-2c88-4b0b-ba08-7df65be87963']) - .returns('id="dd5e0ef1-2c88-4b0b-ba08-7df65be87963" + .and_return('id="dd5e0ef1-2c88-4b0b-ba08-7df65be87963" name="subnet1"') provider.create expect(provider.exists?).to be_truthy @@ -89,10 +89,10 @@ name="subnet1"') end it 'creates port' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('port', 'create', '--format', 'shell', ['port1', '--network=net1', '--disable']) - .returns('admin_state_up="False" + .and_return('admin_state_up="False" allowed_address_pairs="[]" binding_host_id="" binding_profile="{}" @@ -106,15 +106,15 @@ network_id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" project_id="60f9544eb94c42a6b7e8e98c2be981b1" security_groups="f1f0c3a3-9f2c-46b9-b2a5-b97d9a87bd7e" status="ACTIVE"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'show', '--format', 'shell', ['076520cc-b783-4cf5-a4a9-4cb5a5e93a9b']) - .returns('id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" + .and_return('id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" name="net1"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'show', '--format', 'shell', ['dd5e0ef1-2c88-4b0b-ba08-7df65be87963']) - .returns('id="dd5e0ef1-2c88-4b0b-ba08-7df65be87963" + .and_return('id="dd5e0ef1-2c88-4b0b-ba08-7df65be87963" name="subnet1"') provider.create expect(provider.exists?).to be_truthy @@ -137,11 +137,11 @@ name="subnet1"') end it 'creates port' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('port', 'create', '--format', 'shell', ['port1', '--network=net1', '--fixed-ip subnet=subnet1']) - .returns('admin_state_up="True" + .and_return('admin_state_up="True" allowed_address_pairs="[]" binding_host_id="" binding_profile="{}" @@ -155,15 +155,15 @@ network_id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" project_id="60f9544eb94c42a6b7e8e98c2be981b1" security_groups="f1f0c3a3-9f2c-46b9-b2a5-b97d9a87bd7e" status="ACTIVE"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'show', '--format', 'shell', ['076520cc-b783-4cf5-a4a9-4cb5a5e93a9b']) - .returns('id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" + .and_return('id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" name="net1"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'show', '--format', 'shell', ['dd5e0ef1-2c88-4b0b-ba08-7df65be87963']) - .returns('id="dd5e0ef1-2c88-4b0b-ba08-7df65be87963" + .and_return('id="dd5e0ef1-2c88-4b0b-ba08-7df65be87963" name="subnet1"') provider.create expect(provider.exists?).to be_truthy @@ -187,11 +187,11 @@ name="subnet1"') end it 'creates port' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('port', 'create', '--format', 'shell', ['port1', '--network=net1', '--host=myhost', '--binding-profile key1=val1']) - .returns('admin_state_up="True" + .and_return('admin_state_up="True" allowed_address_pairs="[]" binding_host_id="myhost" binding_profile="{\'key1\': \'val1\'}" @@ -205,15 +205,15 @@ network_id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" project_id="60f9544eb94c42a6b7e8e98c2be981b1" security_groups="f1f0c3a3-9f2c-46b9-b2a5-b97d9a87bd7e" status="ACTIVE"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'show', '--format', 'shell', ['076520cc-b783-4cf5-a4a9-4cb5a5e93a9b']) - .returns('id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" + .and_return('id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" name="net1"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'show', '--format', 'shell', ['dd5e0ef1-2c88-4b0b-ba08-7df65be87963']) - .returns('id="dd5e0ef1-2c88-4b0b-ba08-7df65be87963" + .and_return('id="dd5e0ef1-2c88-4b0b-ba08-7df65be87963" name="subnet1"') provider.create expect(provider.exists?).to be_truthy @@ -228,7 +228,7 @@ name="subnet1"') describe '#destroy' do it 'removes port' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('port', 'delete', 'port1') provider.destroy expect(provider.exists?).to be_falsey @@ -238,12 +238,12 @@ name="subnet1"') describe '#flush' do context 'admin_state_up' do it 'updates port' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('port', 'set', ['port1', '--disable']) provider.admin_state_up = 'False' provider.flush - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('port', 'set', ['port1', '--enable']) provider.admin_state_up = 'True' provider.flush @@ -253,16 +253,16 @@ name="subnet1"') describe '#list' do it 'lists ports' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('port', 'list', '--quiet', '--format', 'csv', []) - .returns('"ID","Name","MAC Address","Fixed IP Addresses","Status" + .and_return('"ID","Name","MAC Address","Fixed IP Addresses","Status" "5222573b-314d-45f9-b6bd-299288ba667a","port1","fa:16:3e:45:3c:10","[{\'subnet_id\': \'dd5e0ef1-2c88-4b0b-ba08-7df65be87963\', \'ip_address\': \'10.0.0.2\'}]","ACTIVE" "c880affb-b15e-4632-b5e7-3adba6e3ab35","port2","fa:16:3e:45:3c:11","[{\'subnet_id\': \'0da7a631-0f8f-4e51-8b1c-7a29d0d4f7b5\', \'ip_address\': \'10.0.1.2\'}]","DOWN" ') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('port', 'show', '--format', 'shell', '5222573b-314d-45f9-b6bd-299288ba667a') - .returns('admin_state_up="True" + .and_return('admin_state_up="True" allowed_address_pairs="[]" binding_host_id="" binding_profile="{}" @@ -276,16 +276,16 @@ network_id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" project_id="60f9544eb94c42a6b7e8e98c2be981b1" security_groups="f1f0c3a3-9f2c-46b9-b2a5-b97d9a87bd7e" status="ACTIVE"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'show', '--format', 'shell', ['076520cc-b783-4cf5-a4a9-4cb5a5e93a9b']) - .returns('name="net1"') - provider_class.expects(:openstack) + .and_return('name="net1"') + expect(provider_class).to receive(:openstack) .with('subnet', 'show', '--format', 'shell', ['dd5e0ef1-2c88-4b0b-ba08-7df65be87963']) - .returns('name="subnet1"') + .and_return('name="subnet1"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('port', 'show', '--format', 'shell', 'c880affb-b15e-4632-b5e7-3adba6e3ab35') - .returns('admin_state_up="False" + .and_return('admin_state_up="False" allowed_address_pairs="[]" binding_host_id="" binding_profile="{}" @@ -299,12 +299,12 @@ network_id="34e8f42b-89db-4a5b-92db-76ca7073414d" project_id="60f9544eb94c42a6b7e8e98c2be981b1" security_groups="f1f0c3a3-9f2c-46b9-b2a5-b97d9a87bd7e" status="DOWN"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'show', '--format', 'shell', ['34e8f42b-89db-4a5b-92db-76ca7073414d']) - .returns('name="net2"') - provider_class.expects(:openstack) + .and_return('name="net2"') + expect(provider_class).to receive(:openstack) .with('subnet', 'show', '--format', 'shell', ['0da7a631-0f8f-4e51-8b1c-7a29d0d4f7b5']) - .returns('name="subnet2"') + .and_return('name="subnet2"') instances = provider_class.instances expect(instances.length).to eq(2) diff --git a/spec/unit/provider/neutron_router/openstack_spec.rb b/spec/unit/provider/neutron_router/openstack_spec.rb index 87f7659f9..f0c00e3cc 100644 --- a/spec/unit/provider/neutron_router/openstack_spec.rb +++ b/spec/unit/provider/neutron_router/openstack_spec.rb @@ -40,10 +40,10 @@ describe provider_class do describe '#create' do context 'with defaults' do it 'creates router' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'create', '--format', 'shell', ['router1']) - .returns('admin_state_up="True" + .and_return('admin_state_up="True" availability_zone_hints="[]" distributed="False" external_gateway_info="None" @@ -70,10 +70,10 @@ status="ACTIVE"') } end it 'creates router' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'create', '--format', 'shell', ['router1', '--disable']) - .returns('admin_state_up="False" + .and_return('admin_state_up="False" availability_zone_hints="[]" distributed="False" external_gateway_info="None" @@ -97,10 +97,10 @@ status="ACTIVE"') } end it 'creates router' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'create', '--format', 'shell', ['router1', '--centralized']) - .returns('admin_state_up="True" + .and_return('admin_state_up="True" availability_zone_hints="[]" distributed="False" external_gateway_info="None" @@ -124,10 +124,10 @@ status="ACTIVE"') } end it 'creates router' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'create', '--format', 'shell', ['router1', '--distributed']) - .returns('admin_state_up="True" + .and_return('admin_state_up="True" availability_zone_hints="[]" distributed="True" external_gateway_info="None" @@ -151,10 +151,10 @@ status="ACTIVE"') } end it 'creates router' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'create', '--format', 'shell', ['router1', '--ha']) - .returns('admin_state_up="True" + .and_return('admin_state_up="True" availability_zone_hints="[]" distributed="False" external_gateway_info="None" @@ -178,10 +178,10 @@ status="ACTIVE"') } end it 'creates router' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'create', '--format', 'shell', ['router1', '--no-ha']) - .returns('admin_state_up="True" + .and_return('admin_state_up="True" availability_zone_hints="[]" distributed="False" external_gateway_info="None" @@ -205,10 +205,10 @@ status="ACTIVE"') } end it 'creates router' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'create', '--format', 'shell', ['router1']) - .returns('admin_state_up="True" + .and_return('admin_state_up="True" availability_zone_hints="[]" distributed="False" external_gateway_info="None" @@ -217,12 +217,12 @@ id="d73f453a-77ca-4843-977a-3af0fda8dfcb" name="router1" project_id="60f9544eb94c42a6b7e8e98c2be981b1" status="ACTIVE"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'set', ['router1', '--external-gateway=net1']) - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'show', '--format', 'shell', ['router1']) - .returns('admin_state_up="True" + .and_return('admin_state_up="True" availability_zone_hints="[]" distributed="False" external_gateway_info="{\'network_id\': \'076520cc-b783-4cf5-a4a9-4cb5a5e93a9b\'}" @@ -239,7 +239,7 @@ status="ACTIVE"') describe '#destroy' do it 'removes router' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'delete', 'router1') provider.destroy expect(provider.exists?).to be_falsey @@ -249,11 +249,11 @@ status="ACTIVE"') describe '#flush' do context '.admin_state_up' do it 'updates router' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'set', ['router1', '--disable']) provider.admin_state_up = 'False' provider.flush - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'set', ['router1', '--enable']) provider.admin_state_up = 'True' provider.flush @@ -261,11 +261,11 @@ status="ACTIVE"') end context '.distributed' do it 'updates router' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'set', ['router1', '--distributed']) provider.distributed = 'True' provider.flush - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'set', ['router1', '--centralized']) provider.distributed = 'False' provider.flush @@ -273,11 +273,11 @@ status="ACTIVE"') end context '.ha' do it 'updates router' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'set', ['router1', '--ha']) provider.ha = 'True' provider.flush - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'set', ['router1', '--no-ha']) provider.ha = 'False' provider.flush @@ -285,11 +285,11 @@ status="ACTIVE"') end context '.gateway_network_name' do it 'updates router' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'set', ['router1', '--external-gateway=net1']) provider.gateway_network_name = 'net1' provider.flush - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'unset', ['router1', '--external-gateway']) provider.gateway_network_name = '' provider.flush @@ -299,15 +299,15 @@ status="ACTIVE"') describe '#instances' do it 'lists router' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'list', '--quiet', '--format', 'csv', []) - .returns('"ID","Name","Status","State","Project","Distributed","HA" + .and_return('"ID","Name","Status","State","Project","Distributed","HA" "d73f453a-77ca-4843-977a-3af0fda8dfcb","router1","ACTIVE","True","60f9544eb94c42a6b7e8e98c2be981b1",True,False "c3e93a5b-45ee-4029-b3a3-3331cb3e3f2a","router2","DOWN","False","60f9544eb94c42a6b7e8e98c2be981b1",False,True ') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'show', '--format', 'shell', 'd73f453a-77ca-4843-977a-3af0fda8dfcb') - .returns('admin_state_up="True" + .and_return('admin_state_up="True" availability_zone_hints="[]" distributed="False" external_gateway_info="None" @@ -316,9 +316,9 @@ id="d73f453a-77ca-4843-977a-3af0fda8dfcb" name="router1" project_id="60f9544eb94c42a6b7e8e98c2be981b1" status="ACTIVE"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'show', '--format', 'shell', 'c3e93a5b-45ee-4029-b3a3-3331cb3e3f2a') - .returns('admin_state_up="False" + .and_return('admin_state_up="False" availability_zone_hints="[]" distributed="True" external_gateway_info="None" diff --git a/spec/unit/provider/neutron_router_interface/openstack_spec.rb b/spec/unit/provider/neutron_router_interface/openstack_spec.rb index 0b8fd5fc9..ccf9f1d08 100644 --- a/spec/unit/provider/neutron_router_interface/openstack_spec.rb +++ b/spec/unit/provider/neutron_router_interface/openstack_spec.rb @@ -40,7 +40,7 @@ describe provider_class do describe '#create' do context 'with defaults' do it 'creates router interface' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'add subnet', ['router1', 'subnet1']) provider.create expect(provider.exists?).to be_truthy @@ -56,7 +56,7 @@ describe provider_class do } end it 'creates router interface' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'add port', ['router1', 'port1']) provider.create expect(provider.exists?).to be_truthy @@ -67,7 +67,7 @@ describe provider_class do describe '#destroy' do context 'with defaults' do it 'removes router interface' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'remove subnet', ['router1', 'subnet1']) provider.destroy expect(provider.exists?).to be_falsey @@ -82,7 +82,7 @@ describe provider_class do } end it 'removes router interface' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'remove port', ['router1', 'port1']) provider.destroy expect(provider.exists?).to be_falsey @@ -92,25 +92,25 @@ describe provider_class do describe '#instances' do it 'lists router interfaces' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'list', '--quiet', '--format', 'csv', []) - .returns('"ID","Name","Network","Subnet" + .and_return('"ID","Name","Network","Subnet" "dd5e0ef1-2c88-4b0b-ba08-7df65be87963","subnet1","076520cc-b783-4cf5-a4a9-4cb5a5e93a9b","10.0.0.0/24", "0da7a631-0f8f-4e51-8b1c-7a29d0d4f7b5","subnet2","34e8f42b-89db-4a5b-92db-76ca7073414d","10.0.1.0/24", ') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('router', 'list', '--quiet', '--format', 'csv', []) - .returns('"ID","Name","Status","State","Project","Distributed","HA" + .and_return('"ID","Name","Status","State","Project","Distributed","HA" "d73f453a-77ca-4843-977a-3af0fda8dfcb","router1","ACTIVE","True","60f9544eb94c42a6b7e8e98c2be981b1",True,False "c3e93a5b-45ee-4029-b3a3-3331cb3e3f2a","router2","ACTIVE","True","60f9544eb94c42a6b7e8e98c2be981b1",True,False ') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('port', 'list', '--quiet', '--format', 'csv', ['--router', 'd73f453a-77ca-4843-977a-3af0fda8dfcb']) - .returns('"ID","Name","MAC Address","Fixed IP Addresses","Status" + .and_return('"ID","Name","MAC Address","Fixed IP Addresses","Status" "5222573b-314d-45f9-b6bd-299288ba667a","port1","fa:16:3e:45:3c:10","[{\'subnet_id\': \'dd5e0ef1-2c88-4b0b-ba08-7df65be87963\', \'ip_address\': \'10.0.0.1\'}]","ACTIVE"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('port', 'list', '--quiet', '--format', 'csv', ['--router', 'c3e93a5b-45ee-4029-b3a3-3331cb3e3f2a']) - .returns('"ID","Name","MAC Address","Fixed IP Addresses","Status" + .and_return('"ID","Name","MAC Address","Fixed IP Addresses","Status" "c880affb-b15e-4632-b5e7-3adba6e3ab35","port2","fa:16:3e:45:3c:11","[{\'subnet_id\': \'0da7a631-0f8f-4e51-8b1c-7a29d0d4f7b5\', \'ip_address\': \'10.0.1.1\'}]","ACTIVE"') instances = provider_class.instances diff --git a/spec/unit/provider/neutron_security_group/openstack_spec.rb b/spec/unit/provider/neutron_security_group/openstack_spec.rb index 4417b983b..02541d55b 100644 --- a/spec/unit/provider/neutron_security_group/openstack_spec.rb +++ b/spec/unit/provider/neutron_security_group/openstack_spec.rb @@ -39,12 +39,12 @@ describe provider_class do describe '#create' do it 'creates security group' do - provider.class.stubs(:openstack) - .with('security group', 'list', ['--all']) - .returns('"ID", "Name", "Description", "Project"') - provider.class.stubs(:openstack) + allow(provider.class).to receive(:openstack) + .with('security group', 'list', ['--all']) + .and_return('"ID", "Name", "Description", "Project"') + allow(provider.class).to receive(:openstack) .with('security group', 'create', 'shell', ['example', 'description', 'test', 'project', '1a2b3c', 'project_domain', 'Default']) - .returns('created_at="2017-03-15T09:32:03Z" + .and_return('created_at="2017-03-15T09:32:03Z" description="test" headers="" id="593db854-a47d-411e-a894-66bf90959768" @@ -60,7 +60,7 @@ updated_at="2017-03-15T09:32:03Z"') describe '#destroy' do it 'removes security group' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('security group', 'delete', '593db854-a47d-411e-a894-66bf90959768') provider.instance_variable_set(:@property_hash, sec_group_attrs) provider.destroy diff --git a/spec/unit/provider/neutron_spec.rb b/spec/unit/provider/neutron_spec.rb index cb0fddfe4..3817bba58 100644 --- a/spec/unit/provider/neutron_spec.rb +++ b/spec/unit/provider/neutron_spec.rb @@ -36,7 +36,7 @@ describe Puppet::Provider::Neutron do it 'should fail if config is empty' do conf = {} - klass.expects(:neutron_conf).returns(conf) + expect(klass).to receive(:neutron_conf).and_return(conf) expect do klass.neutron_credentials end.to raise_error(Puppet::Error, credential_error) @@ -44,7 +44,7 @@ describe Puppet::Provider::Neutron do it 'should fail if config does not have keystone_authtoken section.' do conf = {'foo' => 'bar'} - klass.expects(:neutron_conf).returns(conf) + expect(klass).to receive(:neutron_conf).and_return(conf) expect do klass.neutron_credentials end.to raise_error(Puppet::Error, credential_error) @@ -52,7 +52,7 @@ describe Puppet::Provider::Neutron do it 'should fail if config does not contain all auth params' do conf = {'keystone_authtoken' => {'invalid_value' => 'foo'}} - klass.expects(:neutron_conf).returns(conf) + expect(klass).to receive(:neutron_conf).and_return(conf) expect do klass.neutron_credentials end.to raise_error(Puppet::Error, credential_error) diff --git a/spec/unit/provider/neutron_subnet/openstack_spec.rb b/spec/unit/provider/neutron_subnet/openstack_spec.rb index c33442837..b832276b1 100644 --- a/spec/unit/provider/neutron_subnet/openstack_spec.rb +++ b/spec/unit/provider/neutron_subnet/openstack_spec.rb @@ -42,11 +42,11 @@ describe provider_class do describe '#create' do context 'with defaults' do it 'creates subnet' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'create', '--format', 'shell', ['subnet1', '--dhcp', '--network=net1', '--subnet-range=10.0.0.0/24']) - .returns('allocation_pools="[{\'start\': \'10.0.0.2\', \'end\': \'10.0.0.254\'}]" + .and_return('allocation_pools="[{\'start\': \'10.0.0.2\', \'end\': \'10.0.0.254\'}]" cidr="10.0.0.0/24" description="" dns_nameservers="[]" @@ -59,10 +59,10 @@ ipv6_ra_mode="None" name="subnet1" network_id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" project_id="60f9544eb94c42a6b7e8e98c2be981b1"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'show', '--format', 'shell', ['076520cc-b783-4cf5-a4a9-4cb5a5e93a9b']) - .returns('id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" + .and_return('id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" name="net1"') provider.create expect(provider.exists?).to be_truthy @@ -88,7 +88,7 @@ name="net1"') } end it 'creates subnet' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'create', '--format', 'shell', ['subnet1', '--ip-version=4', '--gateway=10.0.0.1', '--no-dhcp', @@ -97,7 +97,7 @@ name="net1"') '--host-route=destination=10.0.1.0/24,nexthop=10.0.0.1', '--network=net1', '--subnet-range=10.0.0.0/24']) - .returns('allocation_pools="[{\'start\': \'10.0.0.2\', \'end\': \'10.0.0.10\'}]" + .and_return('allocation_pools="[{\'start\': \'10.0.0.2\', \'end\': \'10.0.0.10\'}]" cidr="10.0.0.0/24" description="" dns_nameservers="[\'8.8.8.8\']" @@ -110,10 +110,10 @@ ipv6_ra_mode="None" name="subnet1" network_id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" project_id="60f9544eb94c42a6b7e8e98c2be981b1"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'show', '--format', 'shell', ['076520cc-b783-4cf5-a4a9-4cb5a5e93a9b']) - .returns('id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" + .and_return('id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" name="net1"') provider.create expect(provider.exists?).to be_truthy @@ -139,7 +139,7 @@ name="net1"') end it 'creates ipv6 subnet' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'create', '--format', 'shell', ['subnet1', '--ip-version=6', '--gateway=2001:abcd::1', '--dhcp', @@ -148,7 +148,7 @@ name="net1"') '--host-route=destination=2001:abcd:0:1::/64,nexthop=2001:abcd::1', '--network=net1', '--subnet-range=2001:abcd::/64']) - .returns('allocation_pools="[{\'start\': \'2001:abcd::2\', \'end\': \'2001:abcd::ffff:ffff:ffff:fffe\'}]" + .and_return('allocation_pools="[{\'start\': \'2001:abcd::2\', \'end\': \'2001:abcd::ffff:ffff:ffff:fffe\'}]" cird="2001:abcd::/64" description="" dns_nameservers="[\'2001:4860:4860::8888\']" @@ -161,10 +161,10 @@ ipv6_ra_mode="None" name="subnet1" network_id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" project_id="60f9544eb94c42a6b7e8e98c2be981b1"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'show', '--format', 'shell', ['076520cc-b783-4cf5-a4a9-4cb5a5e93a9b']) - .returns('id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" + .and_return('id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" name="net1"') provider.create expect(provider.exists?).to be_truthy @@ -177,7 +177,7 @@ name="net1"') describe '#destroy' do it 'removes subnet' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'delete', 'subnet1') provider.destroy expect(provider.exists?).to be_falsey @@ -187,12 +187,12 @@ name="net1"') describe '#flush' do context 'gateway_ip' do it 'updates subnet' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'set', ['subnet1', '--gateway=10.0.0.1']) provider.gateway_ip = '10.0.0.1' provider.flush - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'set', ['subnet1', '--gateway=none']) provider.gateway_ip = '' provider.flush @@ -200,12 +200,12 @@ name="net1"') end context '.enable_dhcp' do it 'updates subnet' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'set', ['subnet1', '--no-dhcp']) provider.enable_dhcp = 'False' provider.flush - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'set', ['subnet1', '--dhcp']) provider.enable_dhcp = 'True' provider.flush @@ -213,9 +213,9 @@ name="net1"') end context '.allocation_pools' do it 'updates subnet' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'set', ['subnet1', '--no-allocation-pool']) - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'set', ['subnet1', '--allocation-pool=start=10.0.0.2,end=10.0.0.10']) provider.allocation_pools = 'start=10.0.0.2,end=10.0.0.10' provider.flush @@ -223,9 +223,9 @@ name="net1"') end context '.dns_nameservers' do it 'updates subnet' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'set', ['subnet1', '--no-dns-nameservers']) - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'set', ['subnet1', '--dns-nameserver=8.8.8.8']) provider.dns_nameservers = '8.8.8.8' provider.flush @@ -235,16 +235,16 @@ name="net1"') describe '#instances' do it 'lists subnets' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'list', '--quiet', '--format', 'csv', []) - .returns('"ID","Name","Network","Subnet" + .and_return('"ID","Name","Network","Subnet" "dd5e0ef1-2c88-4b0b-ba08-7df65be87963","subnet1","076520cc-b783-4cf5-a4a9-4cb5a5e93a9b","10.0.0.0/24", "0da7a631-0f8f-4e51-8b1c-7a29d0d4f7b5","subnet2","34e8f42b-89db-4a5b-92db-76ca7073414d","10.0.1.0/24", ') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'show', '--format', 'shell', 'dd5e0ef1-2c88-4b0b-ba08-7df65be87963') - .returns('allocation_pools="[{\'start\': \'10.0.0.2\', \'end\': \'10.0.0.254\'}]" + .and_return('allocation_pools="[{\'start\': \'10.0.0.2\', \'end\': \'10.0.0.254\'}]" cidr="10.0.0.0/24" description="" dns_nameservers="[]" @@ -258,13 +258,13 @@ ipv6_ra_mode="None" name="subnet1" network_id="076520cc-b783-4cf5-a4a9-4cb5a5e93a9b" project_id="60f9544eb94c42a6b7e8e98c2be981b1"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'show', '--format', 'shell', ['076520cc-b783-4cf5-a4a9-4cb5a5e93a9b']) - .returns('name="net1"') + .and_return('name="net1"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('subnet', 'show', '--format', 'shell', '0da7a631-0f8f-4e51-8b1c-7a29d0d4f7b5') - .returns('allocation_pools="[{\'start\': \'10.0.1.2\', \'end\': \'10.0.1.254\'}]" + .and_return('allocation_pools="[{\'start\': \'10.0.1.2\', \'end\': \'10.0.1.254\'}]" cidr="10.0.1.0/24" description="" dns_nameservers="[]" @@ -278,9 +278,9 @@ ipv6_ra_mode="None" name="subnet2" network_id="34e8f42b-89db-4a5b-92db-76ca7073414d" project_id="60f9544eb94c42a6b7e8e98c2be981b1"') - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('network', 'show', '--format', 'shell', ['34e8f42b-89db-4a5b-92db-76ca7073414d']) - .returns('name="net2"') + .and_return('name="net2"') instances = provider_class.instances expect(instances.length).to eq(2)