Matt Chu | a05d215 | 2014-04-19 23:40:56 -0700 | [diff] [blame] | 1 | require 'chefspec' |
| 2 | require 'chefspec/berkshelf' |
Matt Chu | a05d215 | 2014-04-19 23:40:56 -0700 | [diff] [blame] | 3 | require 'spec_helper.rb' |
Matt Chu | a05d215 | 2014-04-19 23:40:56 -0700 | [diff] [blame] | 4 | |
Matt Chu | 99bc59a | 2014-08-21 14:44:15 -0700 | [diff] [blame] | 5 | shared_examples 'general tests' do |platform, platform_version| |
| 6 | context "on #{platform} #{platform_version}" do |
Matt Chu | a05d215 | 2014-04-19 23:40:56 -0700 | [diff] [blame] | 7 | |
Matt Chu | a05d215 | 2014-04-19 23:40:56 -0700 | [diff] [blame] | 8 | let(:chef_run) do |
Matt Chu | 9653bf8 | 2015-04-27 17:09:17 -0700 | [diff] [blame] | 9 | ChefSpec::SoloRunner.new( |
Matt Chu | f4ba1a4 | 2014-08-21 14:12:42 -0700 | [diff] [blame] | 10 | platform: platform, |
Matt Chu | 99bc59a | 2014-08-21 14:44:15 -0700 | [diff] [blame] | 11 | # TODO get this working; that is, figure out how to stub this properly |
| 12 | #version: platform_version, |
| 13 | #step_into: [ 'anaconda_package' ]) do |node| |
Matt Chu | 9653bf8 | 2015-04-27 17:09:17 -0700 | [diff] [blame] | 14 | version: platform_version |
| 15 | ) do |node| |
| 16 | # explicitly set the flavor for tests |
| 17 | # TODO test autodetection of x86 versus x86_64 |
| 18 | node.set['anaconda']['flavor'] = 'x86_64' |
Matt Chu | a05d215 | 2014-04-19 23:40:56 -0700 | [diff] [blame] | 19 | end |
| 20 | end |
Matt Chu | a05d215 | 2014-04-19 23:40:56 -0700 | [diff] [blame] | 21 | |
Matt Chu | 126302c | 2014-08-21 14:26:55 -0700 | [diff] [blame] | 22 | before do |
Matt Chu | 99bc59a | 2014-08-21 14:44:15 -0700 | [diff] [blame] | 23 | # TODO doesn't work |
| 24 | #stub_command('/opt/anaconda/2.0.1/bin/conda install astroid --yes').and_return(true) |
| 25 | #stub_command('/opt/anaconda/2.0.1/bin/conda remove astroid --yes').and_return(true) |
Matt Chu | 4c42be0 | 2014-08-20 16:56:42 -0700 | [diff] [blame] | 26 | |
| 27 | stub_command("rpm -qa | grep -q '^runit'").and_return(true) |
Matt Chu | 126302c | 2014-08-21 14:26:55 -0700 | [diff] [blame] | 28 | end |
| 29 | |
Matt Chu | bdc11ef | 2014-08-11 12:51:45 -0700 | [diff] [blame] | 30 | it 'runs without errors. see test-kitchen tests for more comprehensive tests that are not possible here' do |
Matt Chu | a05d215 | 2014-04-19 23:40:56 -0700 | [diff] [blame] | 31 | chef_run.converge(described_recipe) |
| 32 | |
Matt Chu | bdc11ef | 2014-08-11 12:51:45 -0700 | [diff] [blame] | 33 | expect(chef_run).to create_directory('/opt/anaconda') |
Matt Chu | 9a27cc7 | 2014-04-20 14:36:21 -0700 | [diff] [blame] | 34 | expect(chef_run).to run_bash('run anaconda installer') |
Matt Chu | a05d215 | 2014-04-19 23:40:56 -0700 | [diff] [blame] | 35 | end |
| 36 | |
Matt Chu | 1b82b9c | 2014-04-20 10:51:53 -0700 | [diff] [blame] | 37 | it 'generates the installer template correctly' do |
| 38 | chef_run.converge(described_recipe) |
| 39 | |
| 40 | # must be exactly 4 lines |
Matt Chu | 30eb44e | 2014-04-20 12:02:00 -0700 | [diff] [blame] | 41 | installer_config_path = "#{Chef::Config[:file_cache_path]}/installer_config" |
| 42 | expect(chef_run).to render_file(installer_config_path).with_content(/.*\n.*\n.*\n.*/) |
Matt Chu | 1b82b9c | 2014-04-20 10:51:53 -0700 | [diff] [blame] | 43 | end |
Matt Chu | a05d215 | 2014-04-19 23:40:56 -0700 | [diff] [blame] | 44 | |
Matt Chu | 4c42be0 | 2014-08-20 16:56:42 -0700 | [diff] [blame] | 45 | it 'has the anaconda_package resource' do |
Matt Chu | 412e856 | 2014-06-28 13:57:45 -0700 | [diff] [blame] | 46 | chef_run.converge('recipe[anaconda::package_tests]') |
| 47 | |
Matt Chu | 99bc59a | 2014-08-21 14:44:15 -0700 | [diff] [blame] | 48 | package_name = 'astroid' |
| 49 | |
Matt Chu | 4c42be0 | 2014-08-20 16:56:42 -0700 | [diff] [blame] | 50 | expect(chef_run).to install_anaconda_package(package_name) |
Matt Chu | 99bc59a | 2014-08-21 14:44:15 -0700 | [diff] [blame] | 51 | # TODO we want this test, but needs to be stubbed |
| 52 | #expect(chef_run).to run_execute("conda_package_install_#{package_name}").with( |
| 53 | #command: '/opt/anaconda/2.0.1/bin/conda install astroid --yes' |
| 54 | #) |
| 55 | |
Matt Chu | 4c42be0 | 2014-08-20 16:56:42 -0700 | [diff] [blame] | 56 | expect(chef_run).to remove_anaconda_package(package_name) |
Matt Chu | 99bc59a | 2014-08-21 14:44:15 -0700 | [diff] [blame] | 57 | # TODO we want this test, but needs to be stubbed |
| 58 | #expect(chef_run).to run_execute("conda_package_remove_#{package_name}").with( |
| 59 | #command: '/opt/anaconda/2.0.1/bin/conda remove astroid --yes' |
| 60 | #) |
Matt Chu | bdc11ef | 2014-08-11 12:51:45 -0700 | [diff] [blame] | 61 | |
| 62 | # for coverage |
| 63 | expect(chef_run).to write_log('do NOT include this in your runlist! for testing only.') |
Matt Chu | 412e856 | 2014-06-28 13:57:45 -0700 | [diff] [blame] | 64 | end |
| 65 | |
Matt Chu | 4c42be0 | 2014-08-20 16:56:42 -0700 | [diff] [blame] | 66 | it 'has the anaconda_nbservice resource' do |
| 67 | chef_run.converge('recipe[anaconda::notebook_server]') |
| 68 | |
| 69 | expect(chef_run).to create_anaconda_nbservice('notebook-server') |
| 70 | end |
| 71 | |
Matt Chu | 412e856 | 2014-06-28 13:57:45 -0700 | [diff] [blame] | 72 | it 'provides a convenience shell script' do |
Matt Chu | bdc11ef | 2014-08-11 12:51:45 -0700 | [diff] [blame] | 73 | chef_run.converge('recipe[anaconda::shell_conveniences]') |
Matt Chu | 412e856 | 2014-06-28 13:57:45 -0700 | [diff] [blame] | 74 | |
Matt Chu | bdc11ef | 2014-08-11 12:51:45 -0700 | [diff] [blame] | 75 | expect(chef_run).to create_template('/etc/profile.d/anaconda-env.sh') |
| 76 | end |
| 77 | |
| 78 | it 'caches the installer template' do |
| 79 | chef_run.converge(described_recipe) |
| 80 | |
| 81 | installer = "Anaconda-#{chef_run.node.anaconda.version}-Linux-#{chef_run.node.anaconda.flavor}.sh" |
| 82 | installer_path = "#{Chef::Config[:file_cache_path]}/#{installer}" |
| 83 | |
| 84 | expect(chef_run).to create_remote_file_if_missing(installer_path) |
Matt Chu | 412e856 | 2014-06-28 13:57:45 -0700 | [diff] [blame] | 85 | end |
| 86 | |
Matt Chu | b2e24b7 | 2014-09-07 14:35:37 -0700 | [diff] [blame] | 87 | it 'has a workaround for python: https://github.com/thmttch/chef-continuum-anaconda/issues/12' do |
Matt Chu | 9653bf8 | 2015-04-27 17:09:17 -0700 | [diff] [blame] | 88 | skip('How do you include a cookbook for testing purposes only? Needs python') |
Matt Chu | b2e24b7 | 2014-09-07 14:35:37 -0700 | [diff] [blame] | 89 | |
| 90 | chef_run.converge('python::default') |
| 91 | chef_run.converge(described_recipe) |
Matt Chu | 0530ec2 | 2014-10-12 11:07:14 -0700 | [diff] [blame] | 92 | chef_run.converge('anaconda::python_workaround') |
Matt Chu | b2e24b7 | 2014-09-07 14:35:37 -0700 | [diff] [blame] | 93 | |
| 94 | # TODO test that python_pip[setuptools] is removed/disabled |
| 95 | end |
| 96 | |
Matt Chu | a05d215 | 2014-04-19 23:40:56 -0700 | [diff] [blame] | 97 | end |
| 98 | end |
| 99 | |
Matt Chu | 3d31352 | 2014-04-20 20:53:28 -0700 | [diff] [blame] | 100 | describe 'anaconda::default' do |
Matt Chu | 9653bf8 | 2015-04-27 17:09:17 -0700 | [diff] [blame] | 101 | # https://github.com/customink/fauxhai/tree/master/lib/fauxhai/platforms |
Matt Chu | a05d215 | 2014-04-19 23:40:56 -0700 | [diff] [blame] | 102 | platforms = { |
Matt Chu | 9653bf8 | 2015-04-27 17:09:17 -0700 | [diff] [blame] | 103 | 'ubuntu' => [ '12.04', '14.04', '15.04' ], |
| 104 | # TODO 7.9 and 8.2 were recently released |
| 105 | 'debian' => [ '7.8', '8.1' ], |
| 106 | # TODO 6.7 is the latest |
| 107 | 'centos' => [ '5.11', '6.6', '7.1.1503' ], |
| 108 | 'redhat' => [ '5.9', '6.6', '7.1' ], |
Matt Chu | a05d215 | 2014-04-19 23:40:56 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | platforms.each do |platform, versions| |
Matt Chu | bdc11ef | 2014-08-11 12:51:45 -0700 | [diff] [blame] | 112 | versions.each do |platform_version| |
| 113 | Fauxhai.mock(platform: platform, version: platform_version) |
| 114 | include_examples 'general tests', platform, platform_version |
Matt Chu | a05d215 | 2014-04-19 23:40:56 -0700 | [diff] [blame] | 115 | end |
| 116 | end |
| 117 | end |