right_agent 2.0.7-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +82 -0
- data/Rakefile +113 -0
- data/lib/right_agent.rb +59 -0
- data/lib/right_agent/actor.rb +182 -0
- data/lib/right_agent/actor_registry.rb +76 -0
- data/lib/right_agent/actors/agent_manager.rb +232 -0
- data/lib/right_agent/agent.rb +1149 -0
- data/lib/right_agent/agent_config.rb +480 -0
- data/lib/right_agent/agent_identity.rb +210 -0
- data/lib/right_agent/agent_tag_manager.rb +237 -0
- data/lib/right_agent/audit_formatter.rb +107 -0
- data/lib/right_agent/clients.rb +31 -0
- data/lib/right_agent/clients/api_client.rb +383 -0
- data/lib/right_agent/clients/auth_client.rb +247 -0
- data/lib/right_agent/clients/balanced_http_client.rb +369 -0
- data/lib/right_agent/clients/base_retry_client.rb +495 -0
- data/lib/right_agent/clients/right_http_client.rb +279 -0
- data/lib/right_agent/clients/router_client.rb +493 -0
- data/lib/right_agent/command.rb +30 -0
- data/lib/right_agent/command/agent_manager_commands.rb +150 -0
- data/lib/right_agent/command/command_client.rb +136 -0
- data/lib/right_agent/command/command_constants.rb +33 -0
- data/lib/right_agent/command/command_io.rb +126 -0
- data/lib/right_agent/command/command_parser.rb +87 -0
- data/lib/right_agent/command/command_runner.rb +118 -0
- data/lib/right_agent/command/command_serializer.rb +63 -0
- data/lib/right_agent/connectivity_checker.rb +179 -0
- data/lib/right_agent/console.rb +65 -0
- data/lib/right_agent/core_payload_types.rb +44 -0
- data/lib/right_agent/core_payload_types/cookbook.rb +61 -0
- data/lib/right_agent/core_payload_types/cookbook_position.rb +46 -0
- data/lib/right_agent/core_payload_types/cookbook_repository.rb +116 -0
- data/lib/right_agent/core_payload_types/cookbook_sequence.rb +70 -0
- data/lib/right_agent/core_payload_types/dev_repositories.rb +100 -0
- data/lib/right_agent/core_payload_types/dev_repository.rb +76 -0
- data/lib/right_agent/core_payload_types/event_categories.rb +38 -0
- data/lib/right_agent/core_payload_types/executable_bundle.rb +130 -0
- data/lib/right_agent/core_payload_types/login_policy.rb +72 -0
- data/lib/right_agent/core_payload_types/login_user.rb +79 -0
- data/lib/right_agent/core_payload_types/planned_volume.rb +94 -0
- data/lib/right_agent/core_payload_types/recipe_instantiation.rb +73 -0
- data/lib/right_agent/core_payload_types/repositories_bundle.rb +50 -0
- data/lib/right_agent/core_payload_types/right_script_attachment.rb +95 -0
- data/lib/right_agent/core_payload_types/right_script_instantiation.rb +94 -0
- data/lib/right_agent/core_payload_types/runlist_policy.rb +44 -0
- data/lib/right_agent/core_payload_types/secure_document.rb +66 -0
- data/lib/right_agent/core_payload_types/secure_document_location.rb +63 -0
- data/lib/right_agent/core_payload_types/software_repository_instantiation.rb +61 -0
- data/lib/right_agent/daemonize.rb +35 -0
- data/lib/right_agent/dispatched_cache.rb +109 -0
- data/lib/right_agent/dispatcher.rb +272 -0
- data/lib/right_agent/enrollment_result.rb +221 -0
- data/lib/right_agent/exceptions.rb +87 -0
- data/lib/right_agent/history.rb +145 -0
- data/lib/right_agent/log.rb +460 -0
- data/lib/right_agent/minimal.rb +46 -0
- data/lib/right_agent/monkey_patches.rb +30 -0
- data/lib/right_agent/monkey_patches/ruby_patch.rb +55 -0
- data/lib/right_agent/monkey_patches/ruby_patch/array_patch.rb +29 -0
- data/lib/right_agent/monkey_patches/ruby_patch/darwin_patch.rb +24 -0
- data/lib/right_agent/monkey_patches/ruby_patch/linux_patch.rb +24 -0
- data/lib/right_agent/monkey_patches/ruby_patch/linux_patch/file_patch.rb +30 -0
- data/lib/right_agent/monkey_patches/ruby_patch/object_patch.rb +49 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch.rb +32 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/file_patch.rb +60 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/process_patch.rb +63 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/stdio_patch.rb +27 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/time_patch.rb +55 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/win32ole_patch.rb +34 -0
- data/lib/right_agent/multiplexer.rb +102 -0
- data/lib/right_agent/offline_handler.rb +270 -0
- data/lib/right_agent/operation_result.rb +300 -0
- data/lib/right_agent/packets.rb +673 -0
- data/lib/right_agent/payload_formatter.rb +104 -0
- data/lib/right_agent/pending_requests.rb +128 -0
- data/lib/right_agent/pid_file.rb +159 -0
- data/lib/right_agent/platform.rb +770 -0
- data/lib/right_agent/platform/unix/darwin/platform.rb +102 -0
- data/lib/right_agent/platform/unix/linux/platform.rb +305 -0
- data/lib/right_agent/platform/unix/platform.rb +226 -0
- data/lib/right_agent/platform/windows/mingw/platform.rb +447 -0
- data/lib/right_agent/platform/windows/mswin/platform.rb +236 -0
- data/lib/right_agent/platform/windows/platform.rb +1808 -0
- data/lib/right_agent/protocol_version_mixin.rb +69 -0
- data/lib/right_agent/retryable_request.rb +195 -0
- data/lib/right_agent/scripts/agent_controller.rb +543 -0
- data/lib/right_agent/scripts/agent_deployer.rb +400 -0
- data/lib/right_agent/scripts/common_parser.rb +160 -0
- data/lib/right_agent/scripts/log_level_manager.rb +192 -0
- data/lib/right_agent/scripts/stats_manager.rb +268 -0
- data/lib/right_agent/scripts/usage.rb +58 -0
- data/lib/right_agent/secure_identity.rb +92 -0
- data/lib/right_agent/security.rb +32 -0
- data/lib/right_agent/security/cached_certificate_store_proxy.rb +77 -0
- data/lib/right_agent/security/certificate.rb +102 -0
- data/lib/right_agent/security/certificate_cache.rb +89 -0
- data/lib/right_agent/security/distinguished_name.rb +56 -0
- data/lib/right_agent/security/encrypted_document.rb +83 -0
- data/lib/right_agent/security/rsa_key_pair.rb +76 -0
- data/lib/right_agent/security/signature.rb +86 -0
- data/lib/right_agent/security/static_certificate_store.rb +85 -0
- data/lib/right_agent/sender.rb +792 -0
- data/lib/right_agent/serialize.rb +29 -0
- data/lib/right_agent/serialize/message_pack.rb +107 -0
- data/lib/right_agent/serialize/secure_serializer.rb +151 -0
- data/lib/right_agent/serialize/secure_serializer_initializer.rb +47 -0
- data/lib/right_agent/serialize/serializable.rb +151 -0
- data/lib/right_agent/serialize/serializer.rb +159 -0
- data/lib/right_agent/subprocess.rb +38 -0
- data/lib/right_agent/tracer.rb +124 -0
- data/right_agent.gemspec +101 -0
- data/spec/actor_registry_spec.rb +80 -0
- data/spec/actor_spec.rb +162 -0
- data/spec/agent_config_spec.rb +235 -0
- data/spec/agent_identity_spec.rb +78 -0
- data/spec/agent_spec.rb +734 -0
- data/spec/agent_tag_manager_spec.rb +319 -0
- data/spec/clients/api_client_spec.rb +423 -0
- data/spec/clients/auth_client_spec.rb +272 -0
- data/spec/clients/balanced_http_client_spec.rb +576 -0
- data/spec/clients/base_retry_client_spec.rb +635 -0
- data/spec/clients/router_client_spec.rb +594 -0
- data/spec/clients/spec_helper.rb +111 -0
- data/spec/command/agent_manager_commands_spec.rb +51 -0
- data/spec/command/command_io_spec.rb +93 -0
- data/spec/command/command_parser_spec.rb +79 -0
- data/spec/command/command_runner_spec.rb +107 -0
- data/spec/command/command_serializer_spec.rb +51 -0
- data/spec/connectivity_checker_spec.rb +83 -0
- data/spec/core_payload_types/dev_repositories_spec.rb +64 -0
- data/spec/core_payload_types/dev_repository_spec.rb +33 -0
- data/spec/core_payload_types/executable_bundle_spec.rb +67 -0
- data/spec/core_payload_types/login_user_spec.rb +102 -0
- data/spec/core_payload_types/recipe_instantiation_spec.rb +81 -0
- data/spec/core_payload_types/right_script_attachment_spec.rb +65 -0
- data/spec/core_payload_types/right_script_instantiation_spec.rb +79 -0
- data/spec/core_payload_types/spec_helper.rb +23 -0
- data/spec/dispatched_cache_spec.rb +136 -0
- data/spec/dispatcher_spec.rb +324 -0
- data/spec/enrollment_result_spec.rb +53 -0
- data/spec/history_spec.rb +246 -0
- data/spec/log_spec.rb +192 -0
- data/spec/monkey_patches/eventmachine_spec.rb +62 -0
- data/spec/multiplexer_spec.rb +48 -0
- data/spec/offline_handler_spec.rb +340 -0
- data/spec/operation_result_spec.rb +208 -0
- data/spec/packets_spec.rb +461 -0
- data/spec/pending_requests_spec.rb +136 -0
- data/spec/platform/spec_helper.rb +216 -0
- data/spec/platform/unix/darwin/platform_spec.rb +181 -0
- data/spec/platform/unix/linux/platform_spec.rb +540 -0
- data/spec/platform/unix/spec_helper.rb +149 -0
- data/spec/platform/windows/mingw/platform_spec.rb +222 -0
- data/spec/platform/windows/mswin/platform_spec.rb +259 -0
- data/spec/platform/windows/spec_helper.rb +720 -0
- data/spec/retryable_request_spec.rb +306 -0
- data/spec/secure_identity_spec.rb +50 -0
- data/spec/security/cached_certificate_store_proxy_spec.rb +62 -0
- data/spec/security/certificate_cache_spec.rb +71 -0
- data/spec/security/certificate_spec.rb +49 -0
- data/spec/security/distinguished_name_spec.rb +46 -0
- data/spec/security/encrypted_document_spec.rb +55 -0
- data/spec/security/rsa_key_pair_spec.rb +55 -0
- data/spec/security/signature_spec.rb +66 -0
- data/spec/security/static_certificate_store_spec.rb +58 -0
- data/spec/sender_spec.rb +1045 -0
- data/spec/serialize/message_pack_spec.rb +131 -0
- data/spec/serialize/secure_serializer_spec.rb +132 -0
- data/spec/serialize/serializable_spec.rb +90 -0
- data/spec/serialize/serializer_spec.rb +197 -0
- data/spec/spec.opts +2 -0
- data/spec/spec.win32.opts +1 -0
- data/spec/spec_helper.rb +130 -0
- data/spec/tracer_spec.rb +114 -0
- metadata +447 -0
data/spec/actor_spec.rb
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2009-2011 RightScale Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
24
|
+
|
25
|
+
describe RightScale::Actor do
|
26
|
+
class ::WebDocumentImporter
|
27
|
+
include RightScale::Actor
|
28
|
+
expose_non_idempotent :import, :cancel
|
29
|
+
expose_idempotent :special
|
30
|
+
|
31
|
+
def import; 1 end
|
32
|
+
def cancel; 0 end
|
33
|
+
def continue; 1 end
|
34
|
+
def special; 2 end
|
35
|
+
def more_special; 3 end
|
36
|
+
end
|
37
|
+
|
38
|
+
module ::Actors
|
39
|
+
class ComedyActor
|
40
|
+
include RightScale::Actor
|
41
|
+
expose :fun_tricks
|
42
|
+
def fun_tricks
|
43
|
+
:rabbit_in_the_hat
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class ::Actors::InvalidActor
|
49
|
+
include RightScale::Actor
|
50
|
+
expose :non_existing
|
51
|
+
end
|
52
|
+
|
53
|
+
before :each do
|
54
|
+
@log = flexmock(RightScale::Log)
|
55
|
+
@log.should_receive(:warning).by_default.and_return { |m| raise RightScale::Log.format(*m) }
|
56
|
+
@log.should_receive(:error).by_default.and_return { |m| raise RightScale::Log.format(*m) }
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "expose" do
|
60
|
+
|
61
|
+
before :each do
|
62
|
+
@exposed = WebDocumentImporter.instance_variable_get(:@exposed).dup
|
63
|
+
end
|
64
|
+
|
65
|
+
after :each do
|
66
|
+
WebDocumentImporter.instance_variable_set(:@exposed, @exposed)
|
67
|
+
end
|
68
|
+
|
69
|
+
context "idempotent" do
|
70
|
+
|
71
|
+
it "exposes as idempotent" do
|
72
|
+
WebDocumentImporter.expose_idempotent(:more_special)
|
73
|
+
WebDocumentImporter.provides_for("webfiles").sort.should == [
|
74
|
+
"/webfiles/cancel", "/webfiles/import", "/webfiles/more_special", "/webfiles/special"]
|
75
|
+
WebDocumentImporter.idempotent?(:special).should be_true
|
76
|
+
WebDocumentImporter.idempotent?(:more_special).should be_true
|
77
|
+
end
|
78
|
+
|
79
|
+
it "treats already exposed non-idempotent method as non-idempotent" do
|
80
|
+
@log.should_receive(:warning).with(/Method cancel declared both idempotent and non-idempotent/).once
|
81
|
+
WebDocumentImporter.expose_idempotent(:cancel)
|
82
|
+
WebDocumentImporter.provides_for("webfiles").sort.should == [
|
83
|
+
"/webfiles/cancel", "/webfiles/import", "/webfiles/special"]
|
84
|
+
WebDocumentImporter.idempotent?(:cancel).should be_false
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
context "non_idempotent" do
|
90
|
+
|
91
|
+
it "exposes as non-idempotent" do
|
92
|
+
WebDocumentImporter.expose_non_idempotent(:continue)
|
93
|
+
WebDocumentImporter.provides_for("webfiles").sort.should == [
|
94
|
+
"/webfiles/cancel", "/webfiles/continue", "/webfiles/import", "/webfiles/special"]
|
95
|
+
WebDocumentImporter.idempotent?(:import).should be_false
|
96
|
+
WebDocumentImporter.idempotent?(:cancel).should be_false
|
97
|
+
WebDocumentImporter.idempotent?(:continue).should be_false
|
98
|
+
end
|
99
|
+
|
100
|
+
it "treats already exposed idempotent method as non-idempotent" do
|
101
|
+
@log.should_receive(:warning).with(/Method special declared both idempotent and non-idempotent/).once
|
102
|
+
WebDocumentImporter.expose_non_idempotent(:special)
|
103
|
+
WebDocumentImporter.provides_for("webfiles").sort.should == [
|
104
|
+
"/webfiles/cancel", "/webfiles/import", "/webfiles/special"]
|
105
|
+
WebDocumentImporter.idempotent?(:special).should be_false
|
106
|
+
end
|
107
|
+
|
108
|
+
it "defaults expose method to declare non_idempotent" do
|
109
|
+
WebDocumentImporter.expose(:continue)
|
110
|
+
WebDocumentImporter.provides_for("webfiles").sort.should == [
|
111
|
+
"/webfiles/cancel", "/webfiles/continue", "/webfiles/import", "/webfiles/special"]
|
112
|
+
WebDocumentImporter.idempotent?(:continue).should be_false
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "default_prefix" do
|
120
|
+
|
121
|
+
it "is calculated as default prefix as const path of class name" do
|
122
|
+
Actors::ComedyActor.default_prefix.should == "actors/comedy_actor"
|
123
|
+
WebDocumentImporter.default_prefix.should == "web_document_importer"
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "provides_for" do
|
129
|
+
|
130
|
+
before :each do
|
131
|
+
@provides = Actors::ComedyActor.provides_for("money")
|
132
|
+
end
|
133
|
+
|
134
|
+
it "returns an array" do
|
135
|
+
@provides.should be_kind_of(Array)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "maps exposed service methods to prefix" do
|
139
|
+
@provides.should == ["/money/fun_tricks"]
|
140
|
+
wdi_provides = WebDocumentImporter.provides_for("webfiles")
|
141
|
+
wdi_provides.should include("/webfiles/import")
|
142
|
+
wdi_provides.should include("/webfiles/cancel")
|
143
|
+
wdi_provides.should include("/webfiles/special")
|
144
|
+
end
|
145
|
+
|
146
|
+
it "excludes methods not existing in the actor class" do
|
147
|
+
@log.should_receive(:warning).with("Exposing non-existing method non_existing in actor money").once
|
148
|
+
Actors::InvalidActor.provides_for("money").should_not include("/money/non_existing")
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "idempotent?" do
|
154
|
+
|
155
|
+
it "returns whether idempotent" do
|
156
|
+
WebDocumentImporter.idempotent?(:import).should be_false
|
157
|
+
WebDocumentImporter.idempotent?(:special).should be_true
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
@@ -0,0 +1,235 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2011 RightScale Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
24
|
+
|
25
|
+
describe RightScale::AgentConfig do
|
26
|
+
|
27
|
+
before(:all) do
|
28
|
+
@agent_config = RightScale::AgentConfig
|
29
|
+
@pwd_dir = Dir.pwd
|
30
|
+
@tmp_dir = RightScale::Platform.filesystem.temp_dir
|
31
|
+
@test_dir = File.join(@tmp_dir, 'agent_config_test')
|
32
|
+
@agent_id1 = "rs-agent-1-1"
|
33
|
+
FileUtils.mkdir_p(@root_dir1 = File.join(@test_dir, 'root1'))
|
34
|
+
FileUtils.mkdir_p(@root_dir2 = File.join(@test_dir, 'root2'))
|
35
|
+
FileUtils.mkdir_p(@root_dir3 = File.join(@test_dir, 'root3'))
|
36
|
+
FileUtils.mkdir_p(@init_dir1 = File.join(@root_dir1, 'init'))
|
37
|
+
FileUtils.mkdir_p(@init_dir2 = File.join(@root_dir2, 'init'))
|
38
|
+
FileUtils.mkdir_p(@init_dir3 = File.join(@root_dir3, 'init'))
|
39
|
+
FileUtils.touch([@config1 = File.join(@init_dir1, 'config.yml'), @config2 = File.join(@init_dir2, 'config.yml')])
|
40
|
+
FileUtils.touch([@init2 = File.join(@init_dir2, 'init.rb'), @init3 = File.join(@init_dir3, 'init.rb')])
|
41
|
+
FileUtils.mkdir_p(@actors1 = File.join(@root_dir1, 'actors'))
|
42
|
+
FileUtils.mkdir_p(@actors3 = File.join(@root_dir3, 'actors'))
|
43
|
+
@actors = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'right_agent', 'actors'))
|
44
|
+
FileUtils.mkdir_p(@certs1 = File.join(@root_dir1, 'certs'))
|
45
|
+
FileUtils.mkdir_p(@certs2 = File.join(@root_dir2, 'certs'))
|
46
|
+
FileUtils.touch([@router_cert1 = File.join(@certs1, 'router.cert')])
|
47
|
+
FileUtils.touch([@router_cert2 = File.join(@certs2, 'router.cert')])
|
48
|
+
FileUtils.touch([@agent_cert2 = File.join(@certs2, 'agent.cert')])
|
49
|
+
FileUtils.touch([@router_key2 = File.join(@certs2, 'router.key')])
|
50
|
+
FileUtils.mkdir_p(@lib1 = File.join(@root_dir1, 'lib'))
|
51
|
+
FileUtils.mkdir_p(@scripts3 = File.join(@root_dir3, 'scripts'))
|
52
|
+
FileUtils.mkdir_p(@cfg_dir = File.join(@test_dir, 'cfg'))
|
53
|
+
FileUtils.mkdir_p(@cfg_agent1_dir = File.join(@cfg_dir, 'agent_1'))
|
54
|
+
FileUtils.mkdir_p(@pid_dir = File.join(@test_dir, 'pid'))
|
55
|
+
@agent_options1 = {
|
56
|
+
:identity => @agent_id1,
|
57
|
+
:root_dir => [@root_dir1, @root_dir2],
|
58
|
+
:log_dir => @tmp_dir,
|
59
|
+
:pid_dir => @pid_dir
|
60
|
+
}
|
61
|
+
File.open(@cfg_agent1 = File.join(@cfg_agent1_dir, 'config.yml'), "w") { |f| f.puts(YAML.dump(@agent_options1)) }
|
62
|
+
@agent_id2 = "rs-agent-2-2"
|
63
|
+
@agent_options2 = {
|
64
|
+
:identity => @agent_id2,
|
65
|
+
:root_dir => @root_dir2,
|
66
|
+
:pid_dir => @pid_dir
|
67
|
+
}
|
68
|
+
FileUtils.mkdir_p(@cfg_agent2_dir = File.join(@cfg_dir, 'agent_2'))
|
69
|
+
FileUtils.touch([@cfg_agent2 = File.join(@cfg_agent2_dir, 'config.yml')])
|
70
|
+
@pid = 12345
|
71
|
+
File.open(@cookie_file = File.join(@pid_dir, "#{@agent_id1}.pid"), "w") { |f| f.puts(@pid) }
|
72
|
+
@agent_cookie1 = {
|
73
|
+
:cookie => "1a2b3c",
|
74
|
+
:listen_port => 70000
|
75
|
+
}
|
76
|
+
File.open(@cookie_file = File.join(@pid_dir, "#{@agent_id1}.cookie"), "w") { |f| f.puts(YAML.dump(@agent_cookie1)) }
|
77
|
+
end
|
78
|
+
|
79
|
+
after(:all) do
|
80
|
+
FileUtils.remove_dir(@test_dir)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should return protocol version' do
|
84
|
+
@agent_config.protocol_version.should == RightScale::AgentConfig::PROTOCOL_VERSION
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should default root directory to current working directory' do
|
88
|
+
@agent_config.root_dir.should == @pwd_dir
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should set root directory to single directory' do
|
92
|
+
@agent_config.root_dir = @root_dir1
|
93
|
+
@agent_config.root_dir.should == @root_dir1
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should set root directory to list of directories' do
|
97
|
+
@agent_config.root_dir = [@root_dir1, @root_dir2]
|
98
|
+
@agent_config.root_dirs.should == [@root_dir1, @root_dir2]
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should be able to change root directory' do
|
102
|
+
@agent_config.root_dir = [@root_dir1, @root_dir2]
|
103
|
+
@agent_config.root_dir.should == [@root_dir1, @root_dir2]
|
104
|
+
@agent_config.root_dir = [@root_dir3, @root_dir2]
|
105
|
+
@agent_config.root_dir.should == [@root_dir3, @root_dir2]
|
106
|
+
@agent_config.root_dir = nil
|
107
|
+
@agent_config.root_dir.should == @pwd_dir
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should default configuration directory to platform specific directory' do
|
111
|
+
@agent_config.cfg_dir.should == RightScale::Platform.filesystem.right_agent_cfg_dir
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should set configuration directory' do
|
115
|
+
@agent_config.cfg_dir = @cfg_dir
|
116
|
+
@agent_config.cfg_dir.should == @cfg_dir
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should default process id directory to platform specific directory' do
|
120
|
+
@agent_config.pid_dir.should == RightScale::Platform.filesystem.pid_dir
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should set process id directory' do
|
124
|
+
@agent_config.pid_dir = @pid_dir
|
125
|
+
@agent_config.pid_dir.should == @pid_dir
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should return first init/init.rb file path found' do
|
129
|
+
@agent_config.root_dir = [@root_dir1, @root_dir2, @root_dir3]
|
130
|
+
@agent_config.init_file.should == @init2
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should return first init/config.yml file path found' do
|
134
|
+
@agent_config.root_dir = [@root_dir1, @root_dir2, @root_dir3]
|
135
|
+
@agent_config.init_cfg_file.should == @config1
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should return actors directory paths containing all in root directory paths with one from gem last' do
|
139
|
+
@agent_config.root_dir = [@root_dir1, @root_dir2, @root_dir3]
|
140
|
+
@agent_config.actors_dirs.should == [@actors1, @actors3, @actors]
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should return actors directory paths containing other actors directories' do
|
144
|
+
module RightScale
|
145
|
+
AgentConfig.module_eval { def self.other_actors_dirs; [RightScale::Platform.filesystem.temp_dir] end }
|
146
|
+
end
|
147
|
+
@agent_config.root_dir = [@root_dir1, @root_dir2]
|
148
|
+
@agent_config.actors_dirs.should == [@actors1, @tmp_dir, @actors]
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should return first certs file path found' do
|
152
|
+
@agent_config.root_dir = [@root_dir1, @root_dir2, @root_dir3]
|
153
|
+
@agent_config.certs_file('router.cert').should == @router_cert1
|
154
|
+
@agent_config.certs_file('router.key').should == @router_key2
|
155
|
+
@agent_config.certs_file('agent.key').should be_nil
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should return all certs file paths found without any duplicates and by root directory order' do
|
159
|
+
@agent_config.root_dir = [@root_dir1, @root_dir2, @root_dir3]
|
160
|
+
@agent_config.certs_files('*.cert').should == [@router_cert1, @agent_cert2]
|
161
|
+
@agent_config.certs_files('*.key').should == [@router_key2]
|
162
|
+
@agent_config.certs_files('*.abc').should == []
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'should return the first lib directory path' do
|
166
|
+
@agent_config.root_dir = [@root_dir1, @root_dir2, @root_dir3]
|
167
|
+
@agent_config.lib_dir.should == @lib1
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should return the first scripts directory path' do
|
171
|
+
@agent_config.root_dir = [@root_dir1, @root_dir2, @root_dir3]
|
172
|
+
@agent_config.scripts_dir.should == @scripts3
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'should return the configuration file path for an agent' do
|
176
|
+
@agent_config.cfg_dir = @cfg_dir
|
177
|
+
@agent_config.cfg_file('agent_1').should == @cfg_agent1
|
178
|
+
@agent_config.cfg_file('no_agent').should == File.join(@cfg_dir, 'no_agent', 'config.yml')
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'should check if agent configuration file exists if requested to' do
|
182
|
+
@agent_config.cfg_dir = @cfg_dir
|
183
|
+
@agent_config.cfg_file('agent_1', exists = true).should == @cfg_agent1
|
184
|
+
@agent_config.cfg_file('no_agent', exists = true).should be_nil
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should return configuration file paths for all agents' do
|
188
|
+
@agent_config.cfg_dir = @cfg_dir
|
189
|
+
@agent_config.cfg_files.should =~ [@cfg_agent1, @cfg_agent2]
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'should return a list of all configured agents' do
|
193
|
+
@agent_config.cfg_dir = @cfg_dir
|
194
|
+
@agent_config.cfg_agents.should =~ ['agent_1', 'agent_2']
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should return agent name for agent identity' do
|
198
|
+
@agent_config.cfg_dir = @cfg_dir
|
199
|
+
@agent_config.agent_name(@agent_id1).should == 'agent_1'
|
200
|
+
@agent_config.agent_name("rs-bogus-0-0").should be_nil
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'should load agent options from a configuration file and symbolize the keys' do
|
204
|
+
@agent_config.cfg_dir = @cfg_dir
|
205
|
+
@agent_config.load_cfg('agent_1').should == @agent_options1
|
206
|
+
@agent_config.load_cfg("no_agent").should be_nil
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'should store agent options in a configuration file in YAML format' do
|
210
|
+
@agent_config.cfg_dir = @cfg_dir
|
211
|
+
@agent_config.store_cfg("agent_2", @agent_options2) == @agent_config.cfg_file("agent_2")
|
212
|
+
@agent_config.load_cfg('agent_2').should == @agent_options2
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'should return the process id file object for an agent' do
|
216
|
+
@agent_config.cfg_dir = @cfg_dir
|
217
|
+
@agent_config.pid_file('agent_1').identity.should == @agent_id1
|
218
|
+
@agent_config.pid_file('no_agent').should be_nil
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'should return the agent options retrieved from the configuration file and associated pid file' do
|
222
|
+
@agent_config.cfg_dir = @cfg_dir
|
223
|
+
@agent_config.agent_options('agent_1').should == @agent_options1.merge(@agent_cookie1.merge(:pid => @pid, :log_path => @tmp_dir))
|
224
|
+
@agent_config.agent_options("no_agent").should == {}
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'should return the name of agents that are running' do
|
228
|
+
flexmock(Process).should_receive(:getpgid).with(@pid).and_return(123)
|
229
|
+
@agent_config.cfg_dir = @cfg_dir
|
230
|
+
@agent_config.cfg_agents.should =~ ['agent_1', 'agent_2']
|
231
|
+
@agent_config.running_agents.should =~ ['agent_1']
|
232
|
+
@agent_config.running_agents(/core/).should =~ []
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2009-2011 RightScale Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
24
|
+
|
25
|
+
describe RightScale::AgentIdentity do
|
26
|
+
|
27
|
+
it 'should create a token if none is provided' do
|
28
|
+
id = RightScale::AgentIdentity.new('prefix', 'agent_type', 1)
|
29
|
+
id.token.should_not be_nil
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should create unique tokens' do
|
33
|
+
id = RightScale::AgentIdentity.new('prefix', 'agent_type', 1)
|
34
|
+
id.token.should_not be_nil
|
35
|
+
id2 = RightScale::AgentIdentity.new('prefix', 'agent_type', 1)
|
36
|
+
id2.token.should_not be_nil
|
37
|
+
id.token.should_not == id2.token
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should use preset tokens' do
|
41
|
+
id = RightScale::AgentIdentity.new('prefix', 'agent_type', 1, 'token')
|
42
|
+
id.token.should == 'token'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should serialize' do
|
46
|
+
id = RightScale::AgentIdentity.new('prefix', 'agent_type', 1, 'token')
|
47
|
+
id2 = RightScale::AgentIdentity.parse(id.to_s)
|
48
|
+
id2.prefix.should == id.prefix
|
49
|
+
id2.agent_type.should == id.agent_type
|
50
|
+
id2.base_id.should == id.base_id
|
51
|
+
id2.token.should == id.token
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should validate' do
|
55
|
+
id = RightScale::AgentIdentity.new('prefix', 'agent_type', 1, 'token')
|
56
|
+
RightScale::AgentIdentity.valid?(id.to_s).should be_true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should treat serialized id with nanite, mapper, or router prefix as valid" do
|
60
|
+
RightScale::AgentIdentity.valid?("nanite-prefix-agent_type-token-1").should be_true
|
61
|
+
RightScale::AgentIdentity.valid?("mapper-prefix-agent_type-token-1").should be_true
|
62
|
+
RightScale::AgentIdentity.valid?("router-prefix-agent_type-token-1").should be_true
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should parse serialized id with nanite, mapper, or router prefix but discard this prefix" do
|
66
|
+
RightScale::AgentIdentity.parse("nanite-prefix-agent_type-token-1").to_s.should == "prefix-agent_type-token-1"
|
67
|
+
RightScale::AgentIdentity.parse("mapper-prefix-agent_type-token-1").to_s.should == "prefix-agent_type-token-1"
|
68
|
+
RightScale::AgentIdentity.parse("router-prefix-agent_type-token-1").to_s.should == "prefix-agent_type-token-1"
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should prefix with nanite to make backward compatible' do
|
72
|
+
id = RightScale::AgentIdentity.new('prefix', 'agent_type', 1, 'token')
|
73
|
+
RightScale::AgentIdentity.compatible_serialized(id.to_s, version_can_handle_non_nanite_ids).should == "prefix-agent_type-token-1"
|
74
|
+
RightScale::AgentIdentity.compatible_serialized(id.to_s, version_cannot_handle_non_nanite_ids).should == "nanite-prefix-agent_type-token-1"
|
75
|
+
RightScale::AgentIdentity.compatible_serialized(id.to_s).should == "prefix-agent_type-token-1"
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|