chef-vpc-toolkit 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +14 -0
- data/COPYING +1 -1
- data/README.rdoc +29 -7
- data/VERSION +1 -1
- data/config/server_group.json +2 -2
- data/lib/chef-vpc-toolkit.rb +7 -2
- data/lib/chef-vpc-toolkit/chef-0.9.bash +1 -0
- data/lib/chef-vpc-toolkit/chef_bootstrap/fedora.bash +3 -3
- data/lib/chef-vpc-toolkit/chef_bootstrap/ubuntu.bash +1 -0
- data/lib/chef-vpc-toolkit/chef_installer.rb +8 -1
- data/lib/chef-vpc-toolkit/cloud-servers-vpc/client.rb +186 -0
- data/lib/chef-vpc-toolkit/cloud-servers-vpc/connection.rb +146 -0
- data/lib/chef-vpc-toolkit/cloud-servers-vpc/server.rb +113 -0
- data/lib/chef-vpc-toolkit/cloud-servers-vpc/server_group.rb +387 -0
- data/lib/chef-vpc-toolkit/cloud-servers-vpc/ssh_public_key.rb +25 -0
- data/lib/chef-vpc-toolkit/cloud-servers-vpc/vpn_network_interface.rb +29 -0
- data/lib/chef-vpc-toolkit/util.rb +20 -16
- data/lib/chef-vpc-toolkit/vpn_network_manager.rb +16 -16
- data/lib/chef-vpc-toolkit/xml_util.rb +15 -0
- data/rake/chef_vpc_toolkit.rake +194 -155
- data/test/client_test.rb +108 -0
- data/test/server_group_test.rb +259 -0
- data/test/server_test.rb +66 -0
- data/test/test_helper.rb +21 -0
- data/test/util_test.rb +7 -0
- data/test/vpn_network_manager_test.rb +7 -5
- metadata +17 -8
- data/lib/chef-vpc-toolkit/cloud_servers_vpc.rb +0 -393
- data/lib/chef-vpc-toolkit/http_util.rb +0 -118
- data/test/cloud_servers_vpc_test.rb +0 -129
data/test/client_test.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
module ChefVPCToolkit
|
4
|
+
module CloudServersVPC
|
5
|
+
|
6
|
+
class ClientTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
include ChefVPCToolkit::CloudServersVPC
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@tmp_dir=TmpDir.new_tmp_dir
|
12
|
+
Client.data_dir=@tmp_dir
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
FileUtils.rm_rf(@tmp_dir)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_new
|
20
|
+
client=Client.new(:name => "test", :description => "zz", :status => "Pending")
|
21
|
+
assert_equal "test", client.name
|
22
|
+
assert_equal "zz", client.description
|
23
|
+
assert_equal 0, client.vpn_network_interfaces.size
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_from_xml
|
27
|
+
client=Client.from_xml(CLIENT_XML)
|
28
|
+
assert_equal "local", client.name
|
29
|
+
assert_equal "Toolkit Client: local", client.description
|
30
|
+
assert_equal 5, client.id
|
31
|
+
assert_equal 11, client.server_group_id
|
32
|
+
vni=client.vpn_network_interfaces[0]
|
33
|
+
assert_not_nil vni.client_key
|
34
|
+
assert_not_nil vni.client_cert
|
35
|
+
assert_not_nil vni.ca_cert
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_client_to_and_from_xml
|
39
|
+
client=Client.from_xml(CLIENT_XML)
|
40
|
+
xml=client.to_xml
|
41
|
+
assert_not_nil xml
|
42
|
+
client=Client.from_xml(xml)
|
43
|
+
assert_equal "local", client.name
|
44
|
+
assert_equal "Toolkit Client: local", client.description
|
45
|
+
assert_equal 5, client.id
|
46
|
+
assert_equal 11, client.server_group_id
|
47
|
+
vni=client.vpn_network_interfaces[0]
|
48
|
+
assert_not_nil vni.client_key
|
49
|
+
assert_not_nil vni.client_cert
|
50
|
+
assert_not_nil vni.ca_cert
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_fetch
|
54
|
+
|
55
|
+
tmp_dir=TmpDir.new_tmp_dir
|
56
|
+
File.open("#{tmp_dir}/5.xml", 'w') do |f|
|
57
|
+
f.write(CLIENT_XML)
|
58
|
+
end
|
59
|
+
Client.data_dir=tmp_dir
|
60
|
+
|
61
|
+
Connection.stubs(:get).returns(CLIENT_XML)
|
62
|
+
|
63
|
+
# should raise exception if no ID is set and doing a remote lookup
|
64
|
+
assert_raises(RuntimeError) do
|
65
|
+
Client.fetch
|
66
|
+
end
|
67
|
+
|
68
|
+
client=Client.fetch(:id => "1234")
|
69
|
+
assert_not_nil client
|
70
|
+
assert_equal "Toolkit Client: local", client.description
|
71
|
+
|
72
|
+
client=Client.fetch(:id => "5", :source => "cache")
|
73
|
+
assert_not_nil client
|
74
|
+
assert_equal "Toolkit Client: local", client.description
|
75
|
+
|
76
|
+
#nonexistent group from cache
|
77
|
+
ENV['GROUP_ID']="1234"
|
78
|
+
assert_raises(RuntimeError) do
|
79
|
+
Client.fetch(:source => "cache")
|
80
|
+
end
|
81
|
+
|
82
|
+
#invalid fetch source
|
83
|
+
assert_raises(RuntimeError) do
|
84
|
+
Client.fetch(:id => "5", :source => "asdf")
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_delete
|
90
|
+
|
91
|
+
client=Client.from_xml(CLIENT_XML)
|
92
|
+
client.delete
|
93
|
+
assert_equal false, File.exists?(File.join(Client.data_dir, "#{client.id}.xml"))
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_create
|
98
|
+
|
99
|
+
Connection.stubs(:post).returns(CLIENT_XML)
|
100
|
+
client=Client.create(ServerGroup.from_xml(SERVER_GROUP_XML), "local")
|
101
|
+
assert_equal "local", client.name
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,259 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
module ChefVPCToolkit
|
7
|
+
module CloudServersVPC
|
8
|
+
|
9
|
+
class ServerGroupTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@tmp_dir=TmpDir.new_tmp_dir
|
13
|
+
ServerGroup.data_dir=@tmp_dir
|
14
|
+
end
|
15
|
+
|
16
|
+
def teardown
|
17
|
+
FileUtils.rm_rf(@tmp_dir)
|
18
|
+
end
|
19
|
+
|
20
|
+
TEST_JSON_CONFIG = %{{
|
21
|
+
"name": "test",
|
22
|
+
"domain_name": "vpc",
|
23
|
+
"description": "test description",
|
24
|
+
"servers": {
|
25
|
+
"login": {
|
26
|
+
"image_id": "51",
|
27
|
+
"flavor_id": "2",
|
28
|
+
"openvpn_server": "true"
|
29
|
+
},
|
30
|
+
"client1": {
|
31
|
+
"image_id": "69",
|
32
|
+
"flavor_id": "3"
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}}
|
36
|
+
|
37
|
+
def test_server_new
|
38
|
+
sg=ServerGroup.new(:name => "test", :domain_name => "vpc", :description => "zz")
|
39
|
+
assert_equal "test", sg.name
|
40
|
+
assert_equal "zz", sg.description
|
41
|
+
assert_equal "vpc", sg.domain_name
|
42
|
+
assert_equal "172.19.0.0", sg.vpn_network
|
43
|
+
assert_equal "255.255.128.0", sg.vpn_subnet
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_vpn_gateway_ip
|
47
|
+
sg=ServerGroup.from_xml(SERVER_GROUP_XML)
|
48
|
+
assert_equal "184.106.205.120", sg.vpn_gateway_ip
|
49
|
+
assert_equal 1759, sg.id
|
50
|
+
assert_equal "test description", sg.description
|
51
|
+
assert_equal "dan.prince", sg.owner_name
|
52
|
+
assert_equal "172.19.0.0", sg.vpn_network
|
53
|
+
assert_equal "255.255.128.0", sg.vpn_subnet
|
54
|
+
assert_equal 2, sg.servers.size
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_vpn_gateway_name
|
58
|
+
sg=ServerGroup.from_xml(SERVER_GROUP_XML)
|
59
|
+
assert_equal "login1", sg.vpn_gateway_name
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_server_group_from_json_config
|
63
|
+
sg=ServerGroup.from_json_config(TEST_JSON_CONFIG)
|
64
|
+
assert_equal "vpc", sg.domain_name
|
65
|
+
assert_equal "test", sg.name
|
66
|
+
assert_equal "test description", sg.description
|
67
|
+
assert_equal 2, sg.servers.size
|
68
|
+
assert_equal 1, sg.ssh_public_keys.size
|
69
|
+
|
70
|
+
# validate the login server
|
71
|
+
login_server=sg.server("login")
|
72
|
+
assert_equal 51, login_server.image_id
|
73
|
+
assert_equal 2, login_server.flavor_id
|
74
|
+
assert_equal true, login_server.openvpn_server?
|
75
|
+
|
76
|
+
# validate the client1 server
|
77
|
+
client1_server=sg.server("client1")
|
78
|
+
assert_equal 69, client1_server.image_id
|
79
|
+
assert_equal 3, client1_server.flavor_id
|
80
|
+
assert_equal false, client1_server.openvpn_server?
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_server_group_from_xml
|
85
|
+
sg=ServerGroup.from_xml(SERVER_GROUP_XML)
|
86
|
+
assert_equal "mydomain.net", sg.domain_name
|
87
|
+
assert_equal "test", sg.name
|
88
|
+
assert_equal "test description", sg.description
|
89
|
+
assert_equal 2, sg.servers.size
|
90
|
+
assert_equal 1759, sg.id
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_server_group_to_xml
|
94
|
+
sg=ServerGroup.from_xml(SERVER_GROUP_XML)
|
95
|
+
assert_equal "mydomain.net", sg.domain_name
|
96
|
+
assert_equal "test", sg.name
|
97
|
+
assert_equal "test description", sg.description
|
98
|
+
assert_equal 2, sg.servers.size
|
99
|
+
assert_equal 1759, sg.id
|
100
|
+
xml=sg.to_xml
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_print_server_group
|
104
|
+
|
105
|
+
sg=ServerGroup.from_xml(SERVER_GROUP_XML)
|
106
|
+
tmp = Tempfile.open('chef-cloud-toolkit')
|
107
|
+
begin
|
108
|
+
$stdout = tmp
|
109
|
+
sg.pretty_print
|
110
|
+
tmp.flush
|
111
|
+
output=IO.read(tmp.path)
|
112
|
+
$stdout = STDOUT
|
113
|
+
assert output =~ /login1/
|
114
|
+
assert output =~ /test1/
|
115
|
+
assert output =~ /184.106.205.120/
|
116
|
+
ensure
|
117
|
+
$stdout = STDOUT
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_server_names
|
123
|
+
|
124
|
+
sg=ServerGroup.from_xml(SERVER_GROUP_XML)
|
125
|
+
names=sg.server_names
|
126
|
+
|
127
|
+
assert_equal 2, names.size
|
128
|
+
assert names.include?("login1")
|
129
|
+
assert names.include?("test1")
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_fetch
|
134
|
+
|
135
|
+
tmp_dir=TmpDir.new_tmp_dir
|
136
|
+
File.open("#{tmp_dir}/5.xml", 'w') do |f|
|
137
|
+
f.write(SERVER_GROUP_XML)
|
138
|
+
end
|
139
|
+
ServerGroup.data_dir=tmp_dir
|
140
|
+
|
141
|
+
Connection.stubs(:get).returns(SERVER_GROUP_XML)
|
142
|
+
|
143
|
+
sg=ServerGroup.fetch
|
144
|
+
assert_not_nil sg
|
145
|
+
assert_equal "test", sg.name
|
146
|
+
|
147
|
+
sg=ServerGroup.fetch(:id => "1234")
|
148
|
+
assert_not_nil sg
|
149
|
+
assert_equal "test", sg.name
|
150
|
+
|
151
|
+
sg=ServerGroup.fetch(:id => "5", :source => "cache")
|
152
|
+
assert_not_nil sg
|
153
|
+
assert_equal "test", sg.name
|
154
|
+
|
155
|
+
#nonexistent group from cache
|
156
|
+
ENV['GROUP_ID']="1234"
|
157
|
+
assert_raises(RuntimeError) do
|
158
|
+
ServerGroup.fetch(:source => "cache")
|
159
|
+
end
|
160
|
+
|
161
|
+
#invalid fetch source
|
162
|
+
assert_raises(RuntimeError) do
|
163
|
+
ServerGroup.fetch(:id => "5", :source => "asdf")
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_list_from_cache
|
169
|
+
|
170
|
+
tmp_dir=TmpDir.new_tmp_dir
|
171
|
+
File.open("#{tmp_dir}/1759.xml", 'w') do |f|
|
172
|
+
f.write(SERVER_GROUP_XML)
|
173
|
+
end
|
174
|
+
ServerGroup.data_dir=tmp_dir
|
175
|
+
|
176
|
+
server_groups = ServerGroup.list
|
177
|
+
|
178
|
+
assert_equal 1, server_groups.size
|
179
|
+
assert_equal 1759, server_groups[0].id
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_list_from_remote
|
184
|
+
|
185
|
+
tmp_dir=TmpDir.new_tmp_dir
|
186
|
+
File.open("#{tmp_dir}/1759.xml", 'w') do |f|
|
187
|
+
f.write(SERVER_GROUP_XML)
|
188
|
+
end
|
189
|
+
ServerGroup.data_dir=tmp_dir
|
190
|
+
|
191
|
+
Connection.stubs(:get).returns(SERVER_GROUP_XML)
|
192
|
+
server_groups = ServerGroup.list(:source => "remote")
|
193
|
+
|
194
|
+
assert_equal 1, server_groups.size
|
195
|
+
assert_equal 1759, server_groups[0].id
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_create
|
200
|
+
|
201
|
+
sg=ServerGroup.from_json_config(TEST_JSON_CONFIG)
|
202
|
+
|
203
|
+
Connection.stubs(:post).returns(SERVER_GROUP_XML)
|
204
|
+
sg=ServerGroup.create(sg)
|
205
|
+
assert_not_nil sg
|
206
|
+
assert_equal "mydomain.net", sg.domain_name
|
207
|
+
assert_equal "test", sg.name
|
208
|
+
assert_equal "test description", sg.description
|
209
|
+
assert_equal 2, sg.servers.size
|
210
|
+
assert_equal 1759, sg.id
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_most_recent
|
215
|
+
|
216
|
+
File.open("#{ServerGroup.data_dir}/5.xml", 'w') do |f|
|
217
|
+
f.write(SERVER_GROUP_XML)
|
218
|
+
end
|
219
|
+
|
220
|
+
sg=ServerGroup.most_recent
|
221
|
+
|
222
|
+
assert_equal "mydomain.net", sg.domain_name
|
223
|
+
assert_equal 1759, sg.id
|
224
|
+
assert_equal 2, sg.servers.size
|
225
|
+
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_os_types
|
229
|
+
|
230
|
+
sg=ServerGroup.from_xml(SERVER_GROUP_XML)
|
231
|
+
os_types=sg.os_types
|
232
|
+
|
233
|
+
assert_equal 2, os_types.size
|
234
|
+
assert_equal "rhel", os_types["login1"]
|
235
|
+
assert_equal "ubuntu", os_types["test1"]
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_cache_to_disk
|
240
|
+
|
241
|
+
sg=ServerGroup.from_xml(SERVER_GROUP_XML)
|
242
|
+
assert sg.cache_to_disk
|
243
|
+
assert File.exists?(File.join(ServerGroup.data_dir, "#{sg.id}.xml"))
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_delete
|
248
|
+
|
249
|
+
sg=ServerGroup.from_xml(SERVER_GROUP_XML)
|
250
|
+
Connection.stubs(:delete).returns("")
|
251
|
+
sg.delete
|
252
|
+
assert_equal false, File.exists?(File.join(ServerGroup.data_dir, "#{sg.id}.xml"))
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
end
|
259
|
+
end
|
data/test/server_test.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
module ChefVPCToolkit
|
4
|
+
module CloudServersVPC
|
5
|
+
|
6
|
+
class ServerTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
include ChefVPCToolkit::CloudServersVPC
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@tmp_dir=TmpDir.new_tmp_dir
|
12
|
+
ServerGroup.data_dir=@tmp_dir
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
FileUtils.rm_rf(@tmp_dir)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_vpn_server_rebuild_fails
|
20
|
+
group=ServerGroup.from_xml(SERVER_GROUP_XML)
|
21
|
+
server=group.server("login1")
|
22
|
+
assert_raises(RuntimeError) do
|
23
|
+
server.rebuild
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_rebuild
|
28
|
+
group=ServerGroup.from_xml(SERVER_GROUP_XML)
|
29
|
+
server=group.server("test1")
|
30
|
+
Connection.stubs(:post).returns("")
|
31
|
+
server.rebuild
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_from_to_xml
|
35
|
+
server=Server.from_xml(SERVER_XML)
|
36
|
+
server=Server.from_xml(server.to_xml)
|
37
|
+
assert_equal "db1", server.name
|
38
|
+
assert_equal "blah", server.description
|
39
|
+
assert_equal 1234, server.id
|
40
|
+
assert_equal 888, server.cloud_server_id_number
|
41
|
+
assert_equal 999, server.server_group_id
|
42
|
+
assert_equal "10.119.225.116", server.internal_ip_addr
|
43
|
+
assert_equal "123.100.100.100", server.external_ip_addr
|
44
|
+
assert_equal "Online", server.status
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_create
|
48
|
+
|
49
|
+
Connection.stubs(:post).returns(SERVER_XML)
|
50
|
+
server=Server.create(Server.from_xml(SERVER_XML))
|
51
|
+
assert_equal "db1", server.name
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_delete
|
56
|
+
|
57
|
+
server=Server.from_xml(SERVER_XML)
|
58
|
+
Connection.stubs(:delete).returns("")
|
59
|
+
assert server.delete
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -172,3 +172,24 @@ QRiYX+gvycrIph1yyIGA1qeHYnjhQp4ZijhcwSFUAAyF
|
|
172
172
|
</vpn-network-interfaces>
|
173
173
|
</client>
|
174
174
|
}
|
175
|
+
|
176
|
+
SERVER_XML = %{
|
177
|
+
|
178
|
+
<linux-server>
|
179
|
+
<cloud-server-id-number type="integer">888</cloud-server-id-number>
|
180
|
+
<created-at type="datetime">2010-07-29T10:27:33-04:00</created-at>
|
181
|
+
<description>blah</description>
|
182
|
+
<error-message nil="true"></error-message>
|
183
|
+
<external-ip-addr>123.100.100.100</external-ip-addr>
|
184
|
+
<flavor-id type="integer">3</flavor-id>
|
185
|
+
<id type="integer">1234</id>
|
186
|
+
<image-id type="integer">14</image-id>
|
187
|
+
<internal-ip-addr>10.119.225.116</internal-ip-addr>
|
188
|
+
<name>db1</name>
|
189
|
+
<openvpn-server type="boolean">false</openvpn-server>
|
190
|
+
<retry-count type="integer">0</retry-count>
|
191
|
+
<server-group-id type="integer">999</server-group-id>
|
192
|
+
<status>Online</status>
|
193
|
+
<updated-at type="datetime">2010-07-29T11:19:04-04:00</updated-at>
|
194
|
+
</linux-server>
|
195
|
+
}
|