tim 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +17 -0
- data/README.rdoc +231 -8
- data/app/controllers/tim/application_controller.rb +6 -3
- data/app/controllers/tim/base_images_controller.rb +10 -18
- data/app/controllers/tim/image_versions_controller.rb +10 -9
- data/app/controllers/tim/provider_images_controller.rb +13 -10
- data/app/controllers/tim/target_images_controller.rb +9 -7
- data/app/controllers/tim/templates_controller.rb +7 -7
- data/app/exceptions/tim/exceptions.rb +6 -0
- data/app/filters/tim/resource_link_filter.rb +56 -0
- data/app/models/tim/base_image.rb +7 -3
- data/app/models/tim/image_version.rb +4 -2
- data/app/models/tim/provider_image.rb +42 -6
- data/app/models/tim/target_image.rb +48 -9
- data/app/models/tim/template.rb +18 -3
- data/app/patches/rails/active_record/autosave_association.rb +29 -0
- data/app/validators/template_validator.rb +9 -5
- data/app/views/tim/base_images/_base_image.xml.haml +1 -0
- data/app/views/tim/target_images/_target_image.xml.haml +1 -0
- data/db/migrate/20121115151914_add_import_to_tim_base_images.rb +5 -0
- data/db/migrate/20121210131423_add_build_method_to_target_image.rb +5 -0
- data/db/migrate/20121216131814_rename_provider_account_id_attribute.rb +13 -0
- data/db/migrate/20121216134538_add_factory_base_image_id_to_image_versions.rb +5 -0
- data/lib/image_factory/model/base_image.rb +6 -0
- data/lib/tim/engine.rb +12 -0
- data/lib/tim/version.rb +1 -1
- data/spec/controllers/base_images_controller_spec.rb +24 -8
- data/spec/controllers/image_versions_controller_spec.rb +20 -7
- data/spec/controllers/provider_images_controller_spec.rb +19 -6
- data/spec/controllers/target_images_controller_spec.rb +22 -8
- data/spec/factories/tim/base_image.rb +5 -1
- data/spec/factories/tim/image_factory/target_image.rb +1 -0
- data/spec/factories/tim/image_version.rb +4 -0
- data/spec/factories/tim/provider_image.rb +4 -1
- data/spec/factories/tim/target_image.rb +6 -2
- data/spec/filters/resource_link_filter_spec.rb +158 -0
- data/spec/models/base_image_spec.rb +5 -5
- data/spec/models/dummy/pool_family_spec.rb +1 -1
- data/spec/models/dummy/provider_account_spec.rb +3 -1
- data/spec/models/dummy/provider_type_spec.rb +2 -1
- data/spec/models/dummy/user_spec.rb +1 -1
- data/spec/models/image_version_spec.rb +4 -3
- data/spec/models/provider_image_spec.rb +28 -5
- data/spec/models/target_image_spec.rb +74 -4
- data/spec/models/template_spec.rb +11 -2
- data/spec/validators/template_validator_spec.rb +10 -0
- data/spec/views/base_images_spec.rb +2 -1
- data/spec/views/provider_images_spec.rb +1 -0
- data/test/dummy/app/decorators/tim/controllers/base_images_controller_decorator.rb +13 -0
- data/test/dummy/config/database.yml +0 -3
- data/test/dummy/config/initializers/tim.rb +1 -1
- data/test/dummy/config/routes.rb +6 -1
- data/test/dummy/db/migrate/20121216133232_add_provider_account_id_to_provider_images.rb +5 -0
- data/test/dummy/db/schema.rb +28 -24
- data/tim.gemspec +32 -0
- metadata +46 -60
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +0 -982
- data/test/dummy/log/test.log +0 -8629
- data/test/dummy/tmp/cache/assets/C7A/BB0/sprockets%2F13445f7a19078dd2df39517062aa6711 +0 -0
- data/test/dummy/tmp/cache/assets/C8C/CC0/sprockets%2F95d79f3b3096348427f3e4e38b5202e3 +0 -0
- data/test/dummy/tmp/cache/assets/CB0/2B0/sprockets%2F79106b90879c02a115d7f6f1c8390ac4 +0 -0
- data/test/dummy/tmp/cache/assets/CE0/690/sprockets%2F04c628c2a636286bfa92a4966b82b92a +0 -0
- data/test/dummy/tmp/cache/assets/D03/040/sprockets%2Fd9e94204d4b307145f12efc109b16c1f +0 -0
- data/test/dummy/tmp/cache/assets/D06/DC0/sprockets%2Fcd282851b6e4c463409ba3ece67e0510 +0 -0
- data/test/dummy/tmp/cache/assets/D23/5F0/sprockets%2F2a521f3183c6bbcd71bd26a5490b201e +0 -0
- data/test/dummy/tmp/cache/assets/D64/3A0/sprockets%2F56ac1aed10c39b12a88cb1b30f668f58 +0 -0
- data/test/dummy/tmp/cache/assets/D69/BD0/sprockets%2F0aaf75cf34556b33a9fec534fe4d0415 +0 -0
- data/test/dummy/tmp/cache/assets/D87/D80/sprockets%2Fefa3c8b210e87358c7add88cd6f49597 +0 -0
- data/test/dummy/tmp/cache/assets/D89/200/sprockets%2Ff9b4e953c874ed6a87de6490d055d9db +0 -0
- data/test/dummy/tmp/cache/assets/DF4/430/sprockets%2F403bb1de60cae4325cebd7e6c389b8ad +0 -0
- data/test/dummy/tmp/cache/assets/E00/500/sprockets%2Faaddc5b6f2cb6b98930cc54cf4c64a95 +0 -0
- data/test/dummy/tmp/cache/assets/EB3/CE0/sprockets%2Fd75a89c9fffacd99bce7eed96844eafc +0 -0
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
FactoryGirl.define do
|
|
2
2
|
factory :provider_image, :class => Tim::ProviderImage do
|
|
3
|
-
association :target_image, :factory => :target_image
|
|
4
3
|
end
|
|
5
4
|
|
|
6
5
|
factory :provider_image_with_full_tree, :parent => :provider_image do
|
|
7
6
|
association :target_image, :factory => :target_image_with_full_tree
|
|
8
7
|
end
|
|
8
|
+
|
|
9
|
+
factory :provider_image_import, :parent => :provider_image do
|
|
10
|
+
association :target_image, :factory => :target_image_import
|
|
11
|
+
end
|
|
9
12
|
end
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
FactoryGirl.define do
|
|
2
2
|
factory :target_image, :class => Tim::TargetImage do
|
|
3
|
-
association :image_version, :factory => :image_version
|
|
4
3
|
target 'Mock'
|
|
4
|
+
build_method 'BARE_METAL'
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
factory :target_image_with_full_tree, :parent => :target_image do
|
|
8
8
|
association :image_version, :factory => :image_version_with_full_tree
|
|
9
9
|
end
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
factory :target_image_import, :parent => :target_image do
|
|
12
|
+
association :image_version, :factory => :image_version_import
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Tim
|
|
4
|
+
describe ResourceLinkFilter do
|
|
5
|
+
|
|
6
|
+
describe "#transform_resource_links" do
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@controller = stub({
|
|
10
|
+
:request => stub({
|
|
11
|
+
:format => :xml
|
|
12
|
+
})
|
|
13
|
+
})
|
|
14
|
+
@controller.stub(:params).and_return(params)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context "successful transformation" do
|
|
18
|
+
|
|
19
|
+
before do
|
|
20
|
+
ResourceLinkFilter.new(resource_links).before(@controller)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context "for a simple link" do
|
|
24
|
+
let(:params) do {
|
|
25
|
+
:catalog => {
|
|
26
|
+
:id => 123
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
end
|
|
30
|
+
let(:resource_links) { :catalog }
|
|
31
|
+
|
|
32
|
+
it "transforms the link" do
|
|
33
|
+
params[:catalog].should == nil
|
|
34
|
+
params[:catalog_id].should == 123
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context "for a nested link" do
|
|
39
|
+
let(:params) do
|
|
40
|
+
{
|
|
41
|
+
:catalog => {
|
|
42
|
+
:pool => {
|
|
43
|
+
:id => 123
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
let(:resource_links) { { :catalog => :pool } }
|
|
49
|
+
|
|
50
|
+
it "transforms the link" do
|
|
51
|
+
params[:catalog][:pool].should == nil
|
|
52
|
+
params[:catalog][:pool_id].should == 123
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
context "for multiple nested links" do
|
|
57
|
+
let(:params) do
|
|
58
|
+
{
|
|
59
|
+
:catalog => {
|
|
60
|
+
:pool => {
|
|
61
|
+
:id => 123
|
|
62
|
+
},
|
|
63
|
+
:something => {
|
|
64
|
+
:id => 456
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
end
|
|
69
|
+
let(:resource_links) { { :catalog => [:pool, :something] } }
|
|
70
|
+
|
|
71
|
+
it "transforms the links" do
|
|
72
|
+
params[:catalog][:pool].should == nil
|
|
73
|
+
params[:catalog][:pool_id].should == 123
|
|
74
|
+
params[:catalog][:something].should == nil
|
|
75
|
+
params[:catalog][:something_id].should == 456
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
context "for combined single- and double-nested links" do
|
|
80
|
+
let(:params) do
|
|
81
|
+
{
|
|
82
|
+
:catalog => {
|
|
83
|
+
:pool => {
|
|
84
|
+
:id => 123
|
|
85
|
+
},
|
|
86
|
+
:something => {
|
|
87
|
+
:double_nested_1 => {
|
|
88
|
+
:id => 456
|
|
89
|
+
},
|
|
90
|
+
:double_nested_2 => {
|
|
91
|
+
:id => 789
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
end
|
|
97
|
+
let(:resource_links) do
|
|
98
|
+
{
|
|
99
|
+
:catalog => [
|
|
100
|
+
:pool,
|
|
101
|
+
{ :something => [:double_nested_1, :double_nested_2] }
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it "transforms the links" do
|
|
107
|
+
params[:catalog][:pool].should == nil
|
|
108
|
+
params[:catalog][:pool_id].should == 123
|
|
109
|
+
params[:catalog][:something][:double_nested_1].should == nil
|
|
110
|
+
params[:catalog][:something][:double_nested_1_id].should == 456
|
|
111
|
+
params[:catalog][:something][:double_nested_2].should == nil
|
|
112
|
+
params[:catalog][:something][:double_nested_2_id].should == 789
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
context "when missing 'id' attribute in the link" do
|
|
119
|
+
let(:params) do
|
|
120
|
+
{
|
|
121
|
+
:catalog => {}
|
|
122
|
+
}
|
|
123
|
+
end
|
|
124
|
+
let(:resource_links) { :catalog }
|
|
125
|
+
|
|
126
|
+
it "does not transform anything" do
|
|
127
|
+
params[:catalog].should == {}
|
|
128
|
+
params[:catalog_id].should == nil
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
context "when missing the whole link" do
|
|
133
|
+
let(:params) { {} }
|
|
134
|
+
let(:resource_links) { :catalog }
|
|
135
|
+
|
|
136
|
+
it "does not transform anything" do
|
|
137
|
+
params[:catalog].should == nil
|
|
138
|
+
params[:catalog_id].should == nil
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
context "when not XML request" do
|
|
143
|
+
let(:params) { {} }
|
|
144
|
+
|
|
145
|
+
before do
|
|
146
|
+
@controller.stub_chain(:request, :format).and_return(:html)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it "does not touch params" do
|
|
150
|
+
@controller.should_not_receive(:params)
|
|
151
|
+
ResourceLinkFilter.new(:something).before(@controller)
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
end
|
|
158
|
+
end
|
|
@@ -4,16 +4,16 @@ module Tim
|
|
|
4
4
|
describe BaseImage do
|
|
5
5
|
describe "Model relationships" do
|
|
6
6
|
it 'should have many image versions' do
|
|
7
|
-
base_image =
|
|
7
|
+
base_image = FactoryGirl.build(:base_image_with_template)
|
|
8
8
|
2.times do
|
|
9
9
|
base_image.image_versions << ImageVersion.new
|
|
10
10
|
end
|
|
11
|
-
base_image.save
|
|
11
|
+
base_image.save
|
|
12
12
|
BaseImage.find(base_image).image_versions.size.should == 2
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it "should have one template" do
|
|
16
|
-
base_image =
|
|
16
|
+
base_image = FactoryGirl.build(:base_image)
|
|
17
17
|
base_image.template = FactoryGirl.build(:template)
|
|
18
18
|
base_image.save!
|
|
19
19
|
BaseImage.find(base_image).template.should == base_image.template
|
|
@@ -22,14 +22,14 @@ module Tim
|
|
|
22
22
|
|
|
23
23
|
describe "Dummy model relationships" do
|
|
24
24
|
it "should have one pool family" do
|
|
25
|
-
base_image =
|
|
25
|
+
base_image = FactoryGirl.build(:base_image_with_template)
|
|
26
26
|
base_image.pool_family = PoolFamily.new
|
|
27
27
|
base_image.save!
|
|
28
28
|
BaseImage.find(base_image).pool_family.should == base_image.pool_family
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
it "should have one user" do
|
|
32
|
-
base_image =
|
|
32
|
+
base_image = FactoryGirl.build(:base_image_with_template)
|
|
33
33
|
base_image.user = User.new
|
|
34
34
|
base_image.save!
|
|
35
35
|
BaseImage.find(base_image).user.should == base_image.user
|
|
@@ -5,7 +5,7 @@ describe PoolFamily do
|
|
|
5
5
|
it 'should have many base images' do
|
|
6
6
|
pool_family = PoolFamily.new
|
|
7
7
|
2.times do
|
|
8
|
-
pool_family.base_images <<
|
|
8
|
+
pool_family.base_images << FactoryGirl.build(:base_image_with_template)
|
|
9
9
|
end
|
|
10
10
|
pool_family.save!
|
|
11
11
|
PoolFamily.find(pool_family).base_images.size.should == 2
|
|
@@ -4,12 +4,14 @@ describe ProviderAccount do
|
|
|
4
4
|
describe "Dummy Model relationships" do
|
|
5
5
|
before(:each) do
|
|
6
6
|
Tim::ProviderImage.any_instance.stub(:create_factory_provider_image).and_return(true)
|
|
7
|
+
Tim::TargetImage.any_instance.stub(:create_factory_target_image).and_return(true)
|
|
8
|
+
Tim::ProviderImage.any_instance.stub(:imported?).and_return(false)
|
|
7
9
|
end
|
|
8
10
|
|
|
9
11
|
it 'should have many provider images' do
|
|
10
12
|
provider_account = ProviderAccount.new
|
|
11
13
|
2.times do
|
|
12
|
-
provider_account.provider_images <<
|
|
14
|
+
provider_account.provider_images << FactoryGirl.build(:provider_image_with_full_tree)
|
|
13
15
|
end
|
|
14
16
|
provider_account.save!
|
|
15
17
|
ProviderAccount.find(provider_account).provider_images.size.should == 2
|
|
@@ -4,12 +4,13 @@ describe ProviderType do
|
|
|
4
4
|
describe "Dummy Model relationships" do
|
|
5
5
|
before (:each) do
|
|
6
6
|
Tim::TargetImage.any_instance.stub(:create_factory_target_image).and_return(true)
|
|
7
|
+
Tim::TargetImage.any_instance.stub(:imported?).and_return(false)
|
|
7
8
|
end
|
|
8
9
|
|
|
9
10
|
it 'should have many target images' do
|
|
10
11
|
provider_type = ProviderType.new
|
|
11
12
|
2.times do
|
|
12
|
-
provider_type.target_images <<
|
|
13
|
+
provider_type.target_images << FactoryGirl.build(:target_image_with_full_tree)
|
|
13
14
|
end
|
|
14
15
|
provider_type.save!
|
|
15
16
|
ProviderType.find(provider_type).target_images.size.should == 2
|
|
@@ -5,19 +5,20 @@ module Tim
|
|
|
5
5
|
describe "Model relationships" do
|
|
6
6
|
before (:each) do
|
|
7
7
|
TargetImage.any_instance.stub(:create_factory_target_image).and_return(true)
|
|
8
|
+
Tim::TargetImage.any_instance.stub(:imported?).and_return(false)
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
it 'should have one base image' do
|
|
11
12
|
image_version = ImageVersion.new
|
|
12
|
-
image_version.base_image =
|
|
13
|
+
image_version.base_image = FactoryGirl.build(:base_image_with_template)
|
|
13
14
|
image_version.save!
|
|
14
15
|
ImageVersion.find(image_version).base_image.should == image_version.base_image
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
it 'should have many target images' do
|
|
18
|
-
image_version =
|
|
19
|
+
image_version = FactoryGirl.build(:image_version_with_full_tree)
|
|
19
20
|
2.times do
|
|
20
|
-
image_version.target_images <<
|
|
21
|
+
image_version.target_images << FactoryGirl.build(:target_image)
|
|
21
22
|
end
|
|
22
23
|
image_version.save!
|
|
23
24
|
ImageVersion.find(image_version).target_images.size.should == 2
|
|
@@ -4,12 +4,14 @@ module Tim
|
|
|
4
4
|
describe ProviderImage do
|
|
5
5
|
before (:each) do
|
|
6
6
|
TargetImage.any_instance.stub(:create_factory_target_image).and_return(true)
|
|
7
|
+
Tim::ProviderImage.any_instance.stub(:imported?).and_return(false)
|
|
8
|
+
Tim::TargetImage.any_instance.stub(:imported?).and_return(false)
|
|
7
9
|
end
|
|
8
10
|
|
|
9
11
|
describe "Model relationships" do
|
|
10
12
|
it 'should have one target image' do
|
|
11
|
-
provider_image =
|
|
12
|
-
provider_image.target_image =
|
|
13
|
+
provider_image = FactoryGirl.build(:provider_image)
|
|
14
|
+
provider_image.target_image = FactoryGirl.build(:target_image_with_full_tree)
|
|
13
15
|
provider_image.stub(:create_factory_provider_image).and_return(true)
|
|
14
16
|
provider_image.save!
|
|
15
17
|
ProviderImage.find(provider_image).target_image.should == provider_image.target_image
|
|
@@ -18,7 +20,7 @@ module Tim
|
|
|
18
20
|
|
|
19
21
|
describe "Dummy model relationships" do
|
|
20
22
|
it "should have one provider account" do
|
|
21
|
-
provider_image =
|
|
23
|
+
provider_image = FactoryGirl.build(:provider_image_with_full_tree)
|
|
22
24
|
provider_image.provider_account = ProviderAccount.new
|
|
23
25
|
provider_image.stub(:create_factory_provider_image).and_return(true)
|
|
24
26
|
provider_image.save!
|
|
@@ -39,7 +41,7 @@ module Tim
|
|
|
39
41
|
target = mock(:target)
|
|
40
42
|
target.stub(:target).and_return("mock")
|
|
41
43
|
|
|
42
|
-
pi = FactoryGirl.build(:
|
|
44
|
+
pi = FactoryGirl.build(:provider_image_with_full_tree)
|
|
43
45
|
pi.target_image.target = target
|
|
44
46
|
pi.should_receive(:populate_factory_fields)
|
|
45
47
|
pi.save
|
|
@@ -60,9 +62,30 @@ module Tim
|
|
|
60
62
|
pi.progress.should == "10"
|
|
61
63
|
pi.provider.should == "MockSphere"
|
|
62
64
|
pi.external_image_id.should == "mock-123456"
|
|
63
|
-
pi.
|
|
65
|
+
pi.factory_provider_account_id.should == "mock-account-123"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "should not make a request to factory if the base image is imported" do
|
|
69
|
+
Tim::ProviderImage.any_instance.stub(:imported?).and_return(true)
|
|
70
|
+
ti = FactoryGirl.build(:provider_image_import)
|
|
71
|
+
ti.should_not_receive(:create_factory_provider_image)
|
|
72
|
+
ti.save
|
|
64
73
|
end
|
|
65
74
|
|
|
75
|
+
it "should make a request to factory if the target image build type is SNAPSHOT" do
|
|
76
|
+
ti = FactoryGirl.build(:provider_image)
|
|
77
|
+
ti.should_not_receive(:create_factory_provider_image)
|
|
78
|
+
ti.save
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "should raise ImagefactoryConnectionRefused exception when it can"\
|
|
82
|
+
" not connect to Imagefactory" do
|
|
83
|
+
expect {
|
|
84
|
+
Tim::ImageFactory::ProviderImage.stub(:new).and_raise(Errno::ECONNREFUSED)
|
|
85
|
+
provider_image = FactoryGirl.build(:provider_image_with_full_tree)
|
|
86
|
+
provider_image.send(:create_factory_provider_image)
|
|
87
|
+
}.to raise_error(Tim::Error::ImagefactoryConnectionRefused)
|
|
88
|
+
end
|
|
66
89
|
end
|
|
67
90
|
end
|
|
68
91
|
end
|
|
@@ -3,19 +3,22 @@ require 'spec_helper'
|
|
|
3
3
|
module Tim
|
|
4
4
|
describe TargetImage do
|
|
5
5
|
|
|
6
|
+
before (:each) do
|
|
7
|
+
Tim::TargetImage.any_instance.stub(:imported?).and_return(false)
|
|
8
|
+
end
|
|
6
9
|
#TODO FIX: A bug in RSpec V2.1 means that any_instance propogates across context therefore we are stubbing each
|
|
7
10
|
#target_image. This bug is fixed in RSpec V2.6
|
|
8
11
|
describe "Model relationships" do
|
|
9
12
|
it 'should have one images version' do
|
|
10
|
-
target_image =
|
|
13
|
+
target_image = FactoryGirl.build(:target_image)
|
|
11
14
|
target_image.stub(:create_factory_target_image).and_return(true)
|
|
12
|
-
target_image.image_version =
|
|
15
|
+
target_image.image_version = FactoryGirl.build(:image_version_with_full_tree)
|
|
13
16
|
target_image.save!
|
|
14
17
|
TargetImage.find(target_image).image_version.should == target_image.image_version
|
|
15
18
|
end
|
|
16
19
|
|
|
17
20
|
it 'should have many provider images' do
|
|
18
|
-
target_image =
|
|
21
|
+
target_image = FactoryGirl.build(:target_image_with_full_tree)
|
|
19
22
|
target_image.stub(:create_factory_target_image).and_return(true)
|
|
20
23
|
ProviderImage.any_instance.stub(:create_factory_provider_image).and_return(true)
|
|
21
24
|
2.times do
|
|
@@ -28,7 +31,7 @@ module Tim
|
|
|
28
31
|
|
|
29
32
|
describe "Dummy model relationships" do
|
|
30
33
|
it "should have one provider type" do
|
|
31
|
-
target_image =
|
|
34
|
+
target_image = FactoryGirl.build(:target_image_with_full_tree)
|
|
32
35
|
target_image.stub(:create_factory_target_image).and_return(true)
|
|
33
36
|
target_image.provider_type = ProviderType.new
|
|
34
37
|
target_image.save!
|
|
@@ -67,8 +70,75 @@ module Tim
|
|
|
67
70
|
ti.status.should == "NEW"
|
|
68
71
|
ti.status_detail.should == "Building"
|
|
69
72
|
ti.progress.should == "0"
|
|
73
|
+
ti.image_version.factory_base_image_id.should == '2cc3b024-5fe7-4b0b-934b-c5d463b990b0'
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "should not make a request to factory if the base image is imported" do
|
|
77
|
+
Tim::TargetImage.any_instance.stub(:imported?).and_return(true)
|
|
78
|
+
ti = FactoryGirl.build(:target_image_import)
|
|
79
|
+
ti.should_not_receive(:create_factory_target_image)
|
|
80
|
+
ti.save
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should not make a request to factory if the target image is build method is SNAPSHOT" do
|
|
84
|
+
ti = FactoryGirl.build(:target_image_import, :build_method => "SNAPSHOT")
|
|
85
|
+
ti.should_not_receive(:create_factory_target_image)
|
|
86
|
+
ti.save
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "should send base image id to factory if it is set on image version" do
|
|
90
|
+
image_version = FactoryGirl.build(:image_version_with_full_tree,
|
|
91
|
+
:factory_base_image_id => "1234")
|
|
92
|
+
target_image = FactoryGirl.build(:target_image,
|
|
93
|
+
:image_version => image_version)
|
|
94
|
+
target_image.stub(:populate_factory_fields)
|
|
95
|
+
mock_target_image = double("factory_target_image")
|
|
96
|
+
Tim::ImageFactory::TargetImage.stub(:new).and_return(mock_target_image)
|
|
97
|
+
mock_target_image.should_receive(:parameters=)
|
|
98
|
+
mock_target_image.should_receive(:base_image_id=)
|
|
99
|
+
mock_target_image.should_receive(:save!)
|
|
100
|
+
target_image.save
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "should send template to factory if factory base image id is not set on image version" do
|
|
104
|
+
image_version = FactoryGirl.build(:image_version_with_full_tree)
|
|
105
|
+
target_image = FactoryGirl.build(:target_image,
|
|
106
|
+
:image_version => image_version)
|
|
107
|
+
target_image.stub(:populate_factory_fields)
|
|
108
|
+
mock_target_image = double("factory_target_image")
|
|
109
|
+
Tim::ImageFactory::TargetImage.stub(:new).and_return(mock_target_image)
|
|
110
|
+
mock_target_image.should_receive(:parameters=)
|
|
111
|
+
mock_target_image.should_receive(:template=)
|
|
112
|
+
mock_target_image.should_receive(:save!)
|
|
113
|
+
target_image.save
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it "should raise ImagefactoryConnectionRefused exception when it can"\
|
|
117
|
+
" not connect to Imagefactory" do
|
|
118
|
+
expect {
|
|
119
|
+
Tim::ImageFactory::TargetImage.stub(:new).and_raise(Errno::ECONNREFUSED)
|
|
120
|
+
target_image = TargetImage.new
|
|
121
|
+
target_image.send(:create_factory_target_image)
|
|
122
|
+
}.to raise_error(Tim::Error::ImagefactoryConnectionRefused)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "should set default factory data when importing" do
|
|
126
|
+
target_image = FactoryGirl.build(:target_image_with_full_tree)
|
|
127
|
+
target_image.stub(:imported?).and_return(true)
|
|
128
|
+
target_image.save!
|
|
129
|
+
target_image.progress.should == "COMPLETE"
|
|
130
|
+
target_image.status.should == "COMPLETE"
|
|
131
|
+
target_image.status_detail.should == "Imported Image"
|
|
70
132
|
end
|
|
71
133
|
|
|
134
|
+
it "should set default factory data when creating snapshot" do
|
|
135
|
+
target_image = FactoryGirl.build(:target_image_with_full_tree)
|
|
136
|
+
target_image.stub(:snapshot?).and_return(true)
|
|
137
|
+
target_image.save!
|
|
138
|
+
target_image.progress.should == "COMPLETE"
|
|
139
|
+
target_image.status.should == "COMPLETE"
|
|
140
|
+
target_image.status_detail.should == "Snapshot Image"
|
|
141
|
+
end
|
|
72
142
|
end
|
|
73
143
|
end
|
|
74
144
|
end
|