engineyard-metadata 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.1.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{engineyard-metadata}
8
- s.version = "0.0.7"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Seamus Abshere"]
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
34
34
  "spec/metadata_spec.rb",
35
35
  "spec/spec_helper.rb",
36
36
  "spec/support/dna.json",
37
+ "spec/support/dot.git.config",
37
38
  "spec/support/engine_yard_cloud_api_response.json"
38
39
  ]
39
40
  s.homepage = %q{http://github.com/seamusabshere/engineyard-metadata}
@@ -1,4 +1,5 @@
1
- require 'rest' # from nap gem
1
+ gem 'nap' # gives you rest...
2
+ require 'rest'
2
3
  require 'active_support'
3
4
  require 'active_support/version'
4
5
  %w{
@@ -124,7 +125,7 @@ module EY
124
125
  if EY::Metadata.environment_name
125
126
  environment_hsh['name'] == EY::Metadata.environment_name
126
127
  else
127
- environment_hsh['apps'].any? { |app_hsh| app_hsh['repository_uri'] == repository_uri }
128
+ environment_hsh['apps'].any? { |app_hsh| app_hsh['repository_uri'] == EY::Metadata.repository_uri }
128
129
  end
129
130
  end
130
131
  raise RuntimeError, "[engineyard-metadata gem] Found too many environments: #{matching_environment_hshs.map { |hsh| hsh['name'] }.join(', ')}" if matching_environment_hshs.length > 1
@@ -21,6 +21,11 @@ module EY
21
21
  end
22
22
  end
23
23
 
24
+ def clear
25
+ @chef_dna = nil
26
+ @amazon_ec2_api = nil
27
+ end
28
+
24
29
  # An adapter that reads from the EngineYard AppCloud /etc/chef/dna.json file.
25
30
  def chef_dna
26
31
  @chef_dna ||= ChefDna.new
@@ -41,11 +41,13 @@ module EY
41
41
  autoload :AmazonEc2Api, 'engineyard-metadata/amazon_ec2_api'
42
42
  autoload :EngineYardCloudApi, 'engineyard-metadata/engine_yard_cloud_api'
43
43
 
44
- # this is a pretty sloppy way of detecting whether we're on ec2
45
- if File.exist? '/etc/chef/dna.json'
46
- extend Insider
47
- else
48
- extend Outsider
44
+ def self.reload
45
+ if File.directory? '/var/log/engineyard'
46
+ extend Insider
47
+ else
48
+ extend Outsider
49
+ end
49
50
  end
51
+ reload
50
52
  end
51
53
  end
@@ -34,14 +34,14 @@ module EY
34
34
  @repository_uri = nil
35
35
  @environment_name = nil
36
36
  @ey_cloud_token = nil
37
- @data = nil
37
+ @engine_yard_cloud_api = nil
38
38
  end
39
39
 
40
40
  def environment_name=(str)
41
41
  # clear this out in case it was inferred
42
42
  @repository_uri = nil
43
43
  # clear this out in case we're looking up a new environment
44
- @data = nil
44
+ @engine_yard_cloud_api = nil
45
45
  @environment_name = str
46
46
  end
47
47
 
@@ -62,7 +62,7 @@ module EY
62
62
  # clear this out in case it was inferred
63
63
  @repository_uri = nil
64
64
  # clear this out in case we're looking up a new environment
65
- @data = nil
65
+ @engine_yard_cloud_api = nil
66
66
  @ey_cloud_token = str
67
67
  end
68
68
 
@@ -88,10 +88,12 @@ module EY
88
88
  elsif ENV['EY_REPOSITORY_URI']
89
89
  ENV['EY_REPOSITORY_URI']
90
90
  elsif File.exist? git_config_path
91
- `git config --get remote.origin.url`.strip
92
- else
93
- raise RuntimeError, "[engineyard-metadata gem] You need to be inside a app's git repo or set ENV['EY_REPOSITORY_URI']"
91
+ git_config = File.read git_config_path
92
+ git_config =~ /^\[remote.*?\burl = (.*?)\n/m
93
+ $1
94
94
  end
95
+ raise RuntimeError, "[engineyard-metadata gem] Please set EY::Metadata.environment_name= or set ENV['EY_ENVIRONMENT_NAME']" unless @repository_uri.to_s.strip.length > 0
96
+ @repository_uri
95
97
  end
96
98
 
97
99
  # An adapter that reads from the public EngineYard Cloud API (https://cloud.engineyard.com)
@@ -1,213 +1,203 @@
1
1
  require 'spec_helper'
2
2
 
3
- shared_examples_for "all execution environments" do
4
- it 'gets the database username' do
3
+ shared_examples_for "it does in all execution environments" do
4
+ it 'get the database username' do
5
5
  EY::Metadata.database_username.should == 'FAKE_SSH_USERNAME'
6
6
  end
7
7
 
8
- it 'gets the database name' do
8
+ it 'get the database name' do
9
9
  EY::Metadata.database_name.should == 'FAKE_APP_NAME'
10
10
  end
11
11
 
12
- it 'gets the database host' do
12
+ it 'get the database host' do
13
13
  EY::Metadata.database_host.should == 'FAKE_DB_MASTER_PUBLIC_HOSTNAME'
14
14
  end
15
15
 
16
- it 'gets the ssh username' do
16
+ it 'get the ssh username' do
17
17
  EY::Metadata.ssh_username.should == 'FAKE_SSH_USERNAME'
18
18
  end
19
19
 
20
- it 'gets the app server hostnames' do
20
+ it 'get the app server hostnames' do
21
21
  EY::Metadata.app_servers.should == [ 'app_1.compute-1.amazonaws.com' , 'app_master.compute-1.amazonaws.com' ]
22
22
  end
23
23
 
24
- it 'gets the db server hostnames' do
24
+ it 'get the db server hostnames' do
25
25
  EY::Metadata.db_servers.should == [ 'FAKE_DB_MASTER_PUBLIC_HOSTNAME', 'db_slave_1.compute-1.amazonaws.com' ]
26
26
  end
27
27
 
28
- it 'gets the utilities hostnames' do
28
+ it 'get the utilities hostnames' do
29
29
  EY::Metadata.utilities.should == [ 'FAKE_UTIL_1_PUBLIC_HOSTNAME' ]
30
30
  end
31
31
 
32
- it 'gets the app master hostname' do
32
+ it 'get the app master hostname' do
33
33
  EY::Metadata.app_master.should == 'app_master.compute-1.amazonaws.com'
34
34
  end
35
35
 
36
- it 'gets the db master hostname' do
36
+ it 'get the db master hostname' do
37
37
  EY::Metadata.db_master.should == 'FAKE_DB_MASTER_PUBLIC_HOSTNAME'
38
38
  end
39
39
 
40
- it 'gets the db slave hostnames' do
40
+ it 'get the db slave hostnames' do
41
41
  EY::Metadata.db_slaves.should == [ 'db_slave_1.compute-1.amazonaws.com' ]
42
42
  end
43
43
 
44
- it 'gets the app slave hostnames' do
44
+ it 'get the app slave hostnames' do
45
45
  EY::Metadata.app_slaves.should == [ 'app_1.compute-1.amazonaws.com' ]
46
46
  end
47
47
 
48
- it 'gets the solo hostname' do
48
+ it 'get the solo hostname' do
49
49
  EY::Metadata.solo.should == nil
50
50
  end
51
51
 
52
- it 'gets the environment name' do
52
+ it 'get the environment name' do
53
53
  EY::Metadata.environment_name.should == 'FAKE_ENVIRONMENT_NAME'
54
54
  end
55
55
 
56
- it 'gets the stack name' do
56
+ it 'get the stack name' do
57
57
  EY::Metadata.stack_name.should == 'FAKE_STACK_NAME'
58
58
  end
59
59
 
60
- it 'gets the repository URI' do
60
+ it 'get the repository URI' do
61
61
  EY::Metadata.repository_uri.should == 'FAKE_REPOSITORY_URI'
62
62
  end
63
63
  end
64
64
 
65
- shared_examples_for "execution outside the cloud" do
66
- it 'cannot get the present instance ID' do
65
+ shared_examples_for "it's executing outside the cloud" do
66
+ it 'not get the present instance ID' do
67
67
  lambda {
68
68
  EY::Metadata.present_instance_id
69
69
  }.should raise_error(EY::Metadata::CannotGetFromHere)
70
70
  end
71
71
 
72
- it 'cannot get the present instance role (as a string)' do
72
+ it 'not get the present instance role (as a string)' do
73
73
  lambda {
74
74
  EY::Metadata.present_instance_role
75
75
  }.should raise_error(EY::Metadata::CannotGetFromHere)
76
76
  end
77
77
 
78
- it 'cannot get the present public hostname' do
78
+ it 'not get the present public hostname' do
79
79
  lambda {
80
80
  EY::Metadata.present_public_hostname
81
81
  }.should raise_error(EY::Metadata::CannotGetFromHere)
82
82
  end
83
83
 
84
- it 'cannot get the present security group' do
84
+ it 'not get the present security group' do
85
85
  lambda {
86
86
  EY::Metadata.present_security_group
87
87
  }.should raise_error(EY::Metadata::CannotGetFromHere)
88
88
  end
89
89
 
90
- it 'cannot get the database password' do
90
+ it 'not get the database password' do
91
91
  lambda {
92
92
  EY::Metadata.database_password
93
93
  }.should raise_error(EY::Metadata::CannotGetFromHere)
94
94
  end
95
95
 
96
- it 'cannot get the ssh password' do
96
+ it 'not get the ssh password' do
97
97
  lambda {
98
98
  EY::Metadata.ssh_password
99
99
  }.should raise_error(EY::Metadata::CannotGetFromHere)
100
100
  end
101
101
 
102
- it 'cannot get the mysql command' do
102
+ it 'not get the mysql command' do
103
103
  lambda {
104
104
  EY::Metadata.mysql_command
105
105
  }.should raise_error(EY::Metadata::CannotGetFromHere)
106
106
  end
107
107
 
108
- it 'cannot get the mysqldump command' do
108
+ it 'not get the mysqldump command' do
109
109
  lambda {
110
110
  EY::Metadata.mysqldump_command
111
111
  }.should raise_error(EY::Metadata::CannotGetFromHere)
112
112
  end
113
113
 
114
- it 'gets the raw EngineYard Cloud API data' do
114
+ it 'get the raw EngineYard Cloud API data' do
115
115
  EY::Metadata.engine_yard_cloud_api.data.should be_a(Hash)
116
116
  end
117
117
  end
118
118
 
119
+ shared_examples_for "it's executing inside the cloud" do
120
+ it 'get the present instance ID' do
121
+ EY::Metadata.present_instance_id.should == PRESENT_INSTANCE_ID
122
+ end
123
+
124
+ it 'get the present instance role (as a string)' do
125
+ EY::Metadata.present_instance_role.should == 'app_master'
126
+ end
127
+
128
+ it 'get the present public hostname' do
129
+ EY::Metadata.present_public_hostname.should == PRESENT_PUBLIC_HOSTNAME
130
+ end
131
+
132
+ it 'get the present security group' do
133
+ EY::Metadata.present_security_group.should == PRESENT_SECURITY_GROUP
134
+ end
135
+
136
+ it 'get the database password' do
137
+ EY::Metadata.database_password.should == 'USERS-0-PASSWORD'
138
+ end
139
+
140
+ it 'get the ssh password' do
141
+ EY::Metadata.ssh_password.should == 'SSH-PASSWORD'
142
+ end
143
+
144
+ it 'get the mysql command' do
145
+ EY::Metadata.mysql_command.should =~ %r{mysql -h FAKE_DB_MASTER_PUBLIC_HOSTNAME -u FAKE_SSH_USERNAME -pUSERS-0-PASSWORD FAKE_APP_NAME}
146
+ end
147
+
148
+ it 'get the mysqldump command' do
149
+ EY::Metadata.mysqldump_command.should =~ %r{mysqldump -h FAKE_DB_MASTER_PUBLIC_HOSTNAME -u FAKE_SSH_USERNAME -pUSERS-0-PASSWORD FAKE_APP_NAME}
150
+ end
151
+ end
152
+
119
153
  describe 'EY::Metadata' do
154
+ after do
155
+ stop_pretending
156
+ end
157
+
158
+ describe "being executed on an EngineYard AppCloud (i.e. Amazon EC2) instance" do
159
+ before do
160
+ pretend_we_are_on_an_engineyard_appcloud_ec2_instance
161
+ EY::Metadata.reload
162
+ end
163
+ it_should_behave_like "it does in all execution environments"
164
+ it_should_behave_like "it's executing inside the cloud"
165
+ end
166
+
120
167
  describe "being executed from a developer/administrator's local machine" do
121
168
  before do
122
169
  pretend_we_are_on_a_developer_machine
123
- load File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'engineyard-metadata', 'metadata.rb'))
170
+ EY::Metadata.reload
124
171
  EY::Metadata.clear
125
172
  ENV.delete 'EY_CLOUD_TOKEN'
126
173
  ENV.delete 'EY_ENVIRONMENT_NAME'
127
174
  end
128
-
129
- after do
130
- stop_pretending
131
- end
132
-
133
175
  describe "controlled with environment variables" do
134
176
  before do
135
177
  ENV['EY_CLOUD_TOKEN'] = FAKE_CLOUD_TOKEN + 'aaa'
136
178
  ENV['EY_ENVIRONMENT_NAME'] = FAKE_ENVIRONMENT_NAME
137
179
  EY::Metadata.ey_cloud_token.should == FAKE_CLOUD_TOKEN + 'aaa' # sanity check
138
180
  end
139
- it_should_behave_like "all execution environments"
140
- it_should_behave_like "execution outside the cloud"
181
+ it_should_behave_like "it does in all execution environments"
182
+ it_should_behave_like "it's executing outside the cloud"
141
183
  end
142
-
143
184
  describe "controlled with attr writers" do
144
185
  before do
145
186
  EY::Metadata.ey_cloud_token = FAKE_CLOUD_TOKEN + 'bbb'
146
187
  EY::Metadata.environment_name = FAKE_ENVIRONMENT_NAME
147
188
  EY::Metadata.ey_cloud_token.should == FAKE_CLOUD_TOKEN + 'bbb' # sanity check
148
189
  end
149
- it_should_behave_like "all execution environments"
150
- it_should_behave_like "execution outside the cloud"
190
+ it_should_behave_like "it does in all execution environments"
191
+ it_should_behave_like "it's executing outside the cloud"
151
192
  end
152
-
153
193
  describe "depending on .eyrc" do
154
194
  before do
155
- FakeFS.activate!
156
195
  File.open(EY::Metadata.eyrc_path, 'w') { |f| f.write({'api_token' => FAKE_CLOUD_TOKEN + 'ccc'}.to_yaml) }
157
196
  EY::Metadata.environment_name = FAKE_ENVIRONMENT_NAME
158
197
  EY::Metadata.ey_cloud_token.should == FAKE_CLOUD_TOKEN + 'ccc' # sanity check
159
198
  end
160
- it_should_behave_like "all execution environments"
161
- it_should_behave_like "execution outside the cloud"
162
- end
163
- end
164
-
165
- describe "being executed on an EngineYard AppCloud (i.e. Amazon EC2) instance" do
166
- before do
167
- pretend_we_are_on_an_engineyard_appcloud_ec2_instance
168
- load File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'engineyard-metadata', 'metadata.rb'))
169
- end
170
-
171
- after do
172
- stop_pretending
173
- end
174
-
175
- it_should_behave_like "all execution environments"
176
-
177
- it 'has a FakeFS dna.json' do
178
- File.exist?('/etc/chef/dna.json').should == true
179
- end
180
-
181
- it 'gets the present instance ID' do
182
- EY::Metadata.present_instance_id.should == PRESENT_INSTANCE_ID
183
- end
184
-
185
- it 'gets the present instance role (as a string)' do
186
- EY::Metadata.present_instance_role.should == 'app_master'
187
- end
188
-
189
- it 'gets the present public hostname' do
190
- EY::Metadata.present_public_hostname.should == PRESENT_PUBLIC_HOSTNAME
191
- end
192
-
193
- it 'gets the present security group' do
194
- EY::Metadata.present_security_group.should == PRESENT_SECURITY_GROUP
195
- end
196
-
197
- it 'gets the database password' do
198
- EY::Metadata.database_password.should == 'USERS-0-PASSWORD'
199
- end
200
-
201
- it 'gets the ssh password' do
202
- EY::Metadata.ssh_password.should == 'SSH-PASSWORD'
203
- end
204
-
205
- it 'gets the mysql command' do
206
- EY::Metadata.mysql_command.should =~ %r{mysql -h FAKE_DB_MASTER_PUBLIC_HOSTNAME -u FAKE_SSH_USERNAME -pUSERS-0-PASSWORD FAKE_APP_NAME}
207
- end
208
-
209
- it 'gets the mysqldump command' do
210
- EY::Metadata.mysqldump_command.should =~ %r{mysqldump -h FAKE_DB_MASTER_PUBLIC_HOSTNAME -u FAKE_SSH_USERNAME -pUSERS-0-PASSWORD FAKE_APP_NAME}
199
+ it_should_behave_like "it does in all execution environments"
200
+ it_should_behave_like "it's executing outside the cloud"
211
201
  end
212
202
  end
213
203
  end
@@ -1,7 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'rspec'
3
- # require 'ruby-debug'
4
- # assumes active-support 3
5
3
  require 'active_support/json/encoding'
6
4
  require 'fakeweb'
7
5
  require 'fakefs/safe'
@@ -18,10 +16,15 @@ def pretend_we_are_on_a_developer_machine
18
16
  "https://cloud.engineyard.com/api/v2/environments",
19
17
  :status => ["200", "OK"],
20
18
  :body => File.read(File.join(File.dirname(__FILE__), 'support', 'engine_yard_cloud_api_response.json'))
21
- # FakeFS.activate!
19
+ dot_git_config = File.read File.join(File.dirname(__FILE__), 'support', 'dot.git.config')
20
+ FakeFS.activate!
21
+ git_config_path = File.join Dir.pwd, '.git', 'config'
22
+ FileUtils.mkdir_p File.dirname(git_config_path)
23
+ File.open(git_config_path, 'w') do |f|
24
+ f.write dot_git_config
25
+ end
22
26
  end
23
27
 
24
-
25
28
  def pretend_we_are_on_an_engineyard_appcloud_ec2_instance
26
29
  FakeWeb.allow_net_connect = false
27
30
  # fake call to amazon ec2 api to get present security group
@@ -40,6 +43,7 @@ def pretend_we_are_on_an_engineyard_appcloud_ec2_instance
40
43
  dna_json = File.read File.join(File.dirname(__FILE__), 'support', 'dna.json')
41
44
  # ... then turn on the fakefs
42
45
  FakeFS.activate!
46
+ FileUtils.mkdir_p '/var/log/engineyard'
43
47
  FileUtils.mkdir_p '/etc/chef'
44
48
  File.open '/etc/chef/dna.json', 'w' do |f|
45
49
  f.write dna_json
@@ -47,7 +51,10 @@ def pretend_we_are_on_an_engineyard_appcloud_ec2_instance
47
51
  end
48
52
 
49
53
  def stop_pretending
54
+ # http://lukeredpath.co.uk/blog/using-fakefs-with-cucumber-features.html
55
+ FakeFS::FileSystem.clear
50
56
  FakeFS.deactivate!
51
57
  FakeWeb.clean_registry
52
- FakeWeb.allow_net_connect = true
53
58
  end
59
+
60
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'engineyard-metadata'))
@@ -0,0 +1,18 @@
1
+ [core]
2
+ repositoryformatversion = 0
3
+ filemode = true
4
+ bare = false
5
+ logallrefupdates = true
6
+ ignorecase = true
7
+ [remote "origin"]
8
+ fetch = +refs/heads/*:refs/remotes/origin/*
9
+ url = FAKE_REPOSITORY_URI
10
+ [branch "master"]
11
+ remote = origin
12
+ merge = refs/heads/master
13
+ [branch "leap"]
14
+ remote = origin
15
+ merge = refs/heads/leap
16
+ [branch "cm1_r192"]
17
+ remote = origin
18
+ merge = refs/heads/cm1_r192
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: engineyard-metadata
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 7
10
- version: 0.0.7
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Seamus Abshere
@@ -118,6 +118,7 @@ files:
118
118
  - spec/metadata_spec.rb
119
119
  - spec/spec_helper.rb
120
120
  - spec/support/dna.json
121
+ - spec/support/dot.git.config
121
122
  - spec/support/engine_yard_cloud_api_response.json
122
123
  has_rdoc: true
123
124
  homepage: http://github.com/seamusabshere/engineyard-metadata