right_agent 0.17.2 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/right_agent.rb +0 -1
- data/lib/right_agent/agent_config.rb +1 -1
- data/lib/right_agent/minimal.rb +8 -7
- data/lib/right_agent/monkey_patches.rb +4 -2
- data/lib/right_agent/monkey_patches/ruby_patch.rb +9 -9
- data/lib/right_agent/monkey_patches/ruby_patch/linux_patch/file_patch.rb +2 -2
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/file_patch.rb +21 -51
- data/lib/right_agent/packets.rb +5 -1
- data/lib/right_agent/platform.rb +727 -299
- 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/right_agent.gemspec +13 -8
- 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
- metadata +45 -30
- data/lib/right_agent/platform/darwin.rb +0 -285
- data/lib/right_agent/platform/linux.rb +0 -537
- data/lib/right_agent/platform/windows.rb +0 -1384
- data/spec/platform/darwin_spec.rb +0 -13
- data/spec/platform/linux_spec.rb +0 -38
- data/spec/platform/linux_volume_manager_spec.rb +0 -201
- data/spec/platform/platform_spec.rb +0 -80
- data/spec/platform/windows_spec.rb +0 -13
- data/spec/platform/windows_volume_manager_spec.rb +0 -318
@@ -1,13 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
describe 'RightScale::Platform' do
|
4
|
-
subject { RightScale::Platform }
|
5
|
-
|
6
|
-
context 'under Darwin' do
|
7
|
-
context :installer do
|
8
|
-
context :install do
|
9
|
-
specify { lambda { subject.installer.install([]) }.should raise_exception }
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end if RightScale::Platform.darwin?
|
data/spec/platform/linux_spec.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
describe RightScale::Platform do
|
4
|
-
subject { RightScale::Platform }
|
5
|
-
|
6
|
-
context 'under Linux' do
|
7
|
-
context :installer do
|
8
|
-
context :install do
|
9
|
-
it 'should succeed if no packages are specified' do
|
10
|
-
packages = []
|
11
|
-
flexmock(subject.installer).should_receive(:run_installer_command).and_return('ok')
|
12
|
-
subject.installer.install(packages).should == true
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should succeed if all packages install successfully' do
|
16
|
-
packages = ['syslog-ng']
|
17
|
-
flexmock(subject.installer).should_receive(:run_installer_command).and_return('ok')
|
18
|
-
subject.installer.install(packages).should == true
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should fail if one more packages are not found' do
|
22
|
-
if subject.installer.yum?
|
23
|
-
failure_message = "No package l33th4x0r available."
|
24
|
-
elsif subject.installer.aptitude?
|
25
|
-
failure_message = "E: Couldn't find package l33th4x0r"
|
26
|
-
elsif subject.installer.zypper?
|
27
|
-
failure_message = "Package 'l33h4x0r' not found."
|
28
|
-
end
|
29
|
-
packages = ['syslog-ng', 'l33th4x0r']
|
30
|
-
|
31
|
-
flexmock(subject.installer).should_receive(:run_installer_command).and_return(failure_message)
|
32
|
-
|
33
|
-
lambda { subject.installer.install(packages) }.should raise_error
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end if RightScale::Platform.linux?
|
@@ -1,201 +0,0 @@
|
|
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
|
-
if RightScale::Platform.linux?
|
26
|
-
describe RightScale::Platform do
|
27
|
-
before(:all) do
|
28
|
-
@platform = RightScale::Platform
|
29
|
-
end
|
30
|
-
|
31
|
-
context :volume_manager do
|
32
|
-
context :parse_volumes do
|
33
|
-
it 'can parse volumes from blkid output' do
|
34
|
-
blkid_resp = <<EOF
|
35
|
-
/dev/xvdh1: SEC_TYPE="msdos" LABEL="METADATA" UUID="681B-8C5D" TYPE="vfat"
|
36
|
-
/dev/xvdb1: LABEL="SWAP-xvdb1" UUID="d51fcca0-6b10-4934-a572-f3898dfd8840" TYPE="swap"
|
37
|
-
/dev/xvda1: UUID="f4746f9c-0557-4406-9267-5e918e87ca2e" TYPE="ext3"
|
38
|
-
/dev/xvda2: UUID="14d88b9e-9fe6-4974-a8d6-180acdae4016" TYPE="ext3"
|
39
|
-
EOF
|
40
|
-
volume_hash_ary = [
|
41
|
-
{:device => "/dev/xvdh1", :sec_type => "msdos", :label => "METADATA", :uuid => "681B-8C5D", :type => "vfat", :filesystem => "vfat"},
|
42
|
-
{:device => "/dev/xvdb1", :label => "SWAP-xvdb1", :uuid => "d51fcca0-6b10-4934-a572-f3898dfd8840", :type => "swap", :filesystem => "swap"},
|
43
|
-
{:device => "/dev/xvda1", :uuid => "f4746f9c-0557-4406-9267-5e918e87ca2e", :type => "ext3", :filesystem => "ext3"},
|
44
|
-
{:device => "/dev/xvda2", :uuid => "14d88b9e-9fe6-4974-a8d6-180acdae4016", :type => "ext3", :filesystem => "ext3"}
|
45
|
-
]
|
46
|
-
|
47
|
-
@platform.volume_manager.parse_volumes(blkid_resp).should == volume_hash_ary
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'can parse volumes with hyphens or underscores (lvm use case)' do
|
51
|
-
blkid_resp = <<EOF
|
52
|
-
/dev/vg-rightscale-data_storage1/lvol0: UUID="ee34706d-866f-476e-9da4-6a18745456a4" TYPE="xfs"
|
53
|
-
EOF
|
54
|
-
|
55
|
-
volume_hash_ary = [
|
56
|
-
{:device => '/dev/vg-rightscale-data_storage1/lvol0', :uuid => 'ee34706d-866f-476e-9da4-6a18745456a4', :type => 'xfs', :filesystem => "xfs"}
|
57
|
-
]
|
58
|
-
|
59
|
-
@platform.volume_manager.parse_volumes(blkid_resp).should == volume_hash_ary
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'can parse volumes with periods' do
|
63
|
-
blkid_resp = <<EOF
|
64
|
-
/dev/please.dont.do.this: UUID="ee34706d-866f-476e-9da4-6a18745456a4" TYPE="xfs"
|
65
|
-
EOF
|
66
|
-
|
67
|
-
volume_hash_ary = [
|
68
|
-
{:device => '/dev/please.dont.do.this', :uuid => 'ee34706d-866f-476e-9da4-6a18745456a4', :type => 'xfs', :filesystem => "xfs"}
|
69
|
-
]
|
70
|
-
|
71
|
-
@platform.volume_manager.parse_volumes(blkid_resp).should == volume_hash_ary
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'raises a parser error when blkid output is malformed' do
|
75
|
-
blkid_resp = 'foobarbz'
|
76
|
-
|
77
|
-
lambda { @platform.volume_manager.parse_volumes(blkid_resp) }.should raise_error(RightScale::Platform::VolumeManager::ParserError)
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'returns an empty list of volumes when blkid output is empty' do
|
81
|
-
blkid_resp = ''
|
82
|
-
|
83
|
-
@platform.volume_manager.parse_volumes(blkid_resp).should == []
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'can filter results with only one condition' do
|
87
|
-
blkid_resp = <<EOF
|
88
|
-
/dev/xvdh1: SEC_TYPE="msdos" LABEL="METADATA" UUID="681B-8C5D" TYPE="vfat"
|
89
|
-
/dev/xvdb1: LABEL="SWAP-xvdb1" UUID="d51fcca0-6b10-4934-a572-f3898dfd8840" TYPE="swap"
|
90
|
-
/dev/xvda1: UUID="f4746f9c-0557-4406-9267-5e918e87ca2e" TYPE="ext3"
|
91
|
-
/dev/xvda2: UUID="14d88b9e-9fe6-4974-a8d6-180acdae4016" TYPE="ext3"
|
92
|
-
EOF
|
93
|
-
volume_hash_ary = [
|
94
|
-
{:device => "/dev/xvdh1", :sec_type => "msdos", :label => "METADATA", :uuid => "681B-8C5D", :type => "vfat", :filesystem => "vfat"}
|
95
|
-
]
|
96
|
-
|
97
|
-
condition = {:uuid => "681B-8C5D"}
|
98
|
-
|
99
|
-
@platform.volume_manager.parse_volumes(blkid_resp, condition).should == volume_hash_ary
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'can filter results with many conditions' do
|
103
|
-
blkid_resp = <<EOF
|
104
|
-
/dev/xvdh1: SEC_TYPE="msdos" LABEL="METADATA" UUID="681B-8C5D" TYPE="vfat"
|
105
|
-
/dev/xvdb1: LABEL="SWAP-xvdb1" UUID="d51fcca0-6b10-4934-a572-f3898dfd8840" TYPE="swap"
|
106
|
-
/dev/xvda1: UUID="f4746f9c-0557-4406-9267-5e918e87ca2e" TYPE="ext3"
|
107
|
-
/dev/xvda2: UUID="14d88b9e-9fe6-4974-a8d6-180acdae4016" TYPE="ext3"
|
108
|
-
EOF
|
109
|
-
volume_hash_ary = [
|
110
|
-
{:device => "/dev/xvda1", :uuid => "f4746f9c-0557-4406-9267-5e918e87ca2e", :type => "ext3", :filesystem => "ext3"},
|
111
|
-
{:device => "/dev/xvda2", :uuid => "14d88b9e-9fe6-4974-a8d6-180acdae4016", :type => "ext3", :filesystem => "ext3"}
|
112
|
-
]
|
113
|
-
|
114
|
-
condition = {:filesystem => "ext3"}
|
115
|
-
|
116
|
-
@platform.volume_manager.parse_volumes(blkid_resp, condition).should == volume_hash_ary
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context :mount_volume do
|
121
|
-
it 'mounts the specified volume if it is not already mounted' do
|
122
|
-
mount_resp = <<EOF
|
123
|
-
/dev/xvda2 on / type ext3 (rw,noatime,errors=remount-ro)
|
124
|
-
proc on /proc type proc (rw,noexec,nosuid,nodev)
|
125
|
-
EOF
|
126
|
-
|
127
|
-
flexmock(@platform.volume_manager).should_receive(:blocking_popen).with('mount').once.and_return([0, mount_resp])
|
128
|
-
flexmock(@platform.volume_manager).should_receive(:blocking_popen).with('mount -t vfat /dev/xvdh1 /var/spool/softlayer').once.and_return([0, '']);
|
129
|
-
|
130
|
-
@platform.volume_manager.mount_volume({:device => "/dev/xvdh1", :filesystem => "vfat"}, "/var/spool/softlayer")
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'does not attempt to re-mount the volume' do
|
134
|
-
mount_resp = <<EOF
|
135
|
-
/dev/xvda2 on / type ext3 (rw,noatime,errors=remount-ro)
|
136
|
-
proc on /proc type proc (rw,noexec,nosuid,nodev)
|
137
|
-
/dev/xvdh1 on /var/spool/softlayer type vfat (rw) [METADATA]
|
138
|
-
EOF
|
139
|
-
flexmock(@platform.volume_manager).should_receive(:blocking_popen).with('mount').once.and_return([0, mount_resp])
|
140
|
-
flexmock(@platform.volume_manager).should_receive(:blocking_popen).with('mount -t vfat /dev/xvdh1 /var/spool/softlayer').never.and_return([0, '']);
|
141
|
-
|
142
|
-
@platform.volume_manager.mount_volume({:device => "/dev/xvdh1", :filesystem => "vfat"}, "/var/spool/softlayer")
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'raises argument error when the volume parameter is not a hash' do
|
146
|
-
lambda { @platform.volume_manager.mount_volume("", "") }.should raise_error(ArgumentError)
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'raises argument error when the volume parameter is a hash but does not contain :device' do
|
150
|
-
lambda { @platform.volume_manager.mount_volume({}, "") }.should raise_error(ArgumentError)
|
151
|
-
end
|
152
|
-
|
153
|
-
it 'raises volume error when the device is already mounted to a different mountpoint' do
|
154
|
-
mount_resp = <<EOF
|
155
|
-
/dev/xvda2 on / type ext3 (rw,noatime,errors=remount-ro)
|
156
|
-
proc on /proc type proc (rw,noexec,nosuid,nodev)
|
157
|
-
none on /sys type sysfs (rw,noexec,nosuid,nodev)
|
158
|
-
none on /sys/kernel/debug type debugfs (rw)
|
159
|
-
none on /sys/kernel/security type securityfs (rw)
|
160
|
-
none on /dev type devtmpfs (rw,mode=0755)
|
161
|
-
none on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
|
162
|
-
none on /dev/shm type tmpfs (rw,nosuid,nodev)
|
163
|
-
none on /var/run type tmpfs (rw,nosuid,mode=0755)
|
164
|
-
none on /var/lock type tmpfs (rw,noexec,nosuid,nodev)
|
165
|
-
none on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
|
166
|
-
/dev/xvda1 on /boot type ext3 (rw,noatime)
|
167
|
-
/dev/xvdh1 on /mnt type vfat (rw) [METADATA]
|
168
|
-
EOF
|
169
|
-
|
170
|
-
mount_popen_mock = flexmock(:read => mount_resp)
|
171
|
-
flexmock(IO).should_receive(:popen).with('mount',Proc).and_yield(mount_popen_mock)
|
172
|
-
|
173
|
-
lambda { @platform.volume_manager.mount_volume({:device => "/dev/xvdh1"}, "/var/spool/softlayer")}.should raise_error(RightScale::Platform::VolumeManager::VolumeError)
|
174
|
-
end
|
175
|
-
|
176
|
-
it 'raises volume error when a different device is already mounted to the specified mountpoint' do
|
177
|
-
mount_resp = <<EOF
|
178
|
-
/dev/xvda2 on / type ext3 (rw,noatime,errors=remount-ro)
|
179
|
-
proc on /proc type proc (rw,noexec,nosuid,nodev)
|
180
|
-
none on /sys type sysfs (rw,noexec,nosuid,nodev)
|
181
|
-
none on /sys/kernel/debug type debugfs (rw)
|
182
|
-
none on /sys/kernel/security type securityfs (rw)
|
183
|
-
none on /dev type devtmpfs (rw,mode=0755)
|
184
|
-
none on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
|
185
|
-
none on /dev/shm type tmpfs (rw,nosuid,nodev)
|
186
|
-
none on /var/run type tmpfs (rw,nosuid,mode=0755)
|
187
|
-
none on /var/lock type tmpfs (rw,noexec,nosuid,nodev)
|
188
|
-
none on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
|
189
|
-
/dev/xvda1 on /boot type ext3 (rw,noatime)
|
190
|
-
/dev/xvdh2 on /var/spool/softlayer type vfat (rw) [METADATA]
|
191
|
-
EOF
|
192
|
-
|
193
|
-
mount_popen_mock = flexmock(:read => mount_resp)
|
194
|
-
flexmock(IO).should_receive(:popen).with('mount',Proc).and_yield(mount_popen_mock)
|
195
|
-
|
196
|
-
lambda { @platform.volume_manager.mount_volume({:device => "/dev/xvdh1"}, "/var/spool/softlayer")}.should raise_error(RightScale::Platform::VolumeManager::VolumeError)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
@@ -1,80 +0,0 @@
|
|
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::Platform do
|
26
|
-
subject { RightScale::Platform }
|
27
|
-
|
28
|
-
context :shell do
|
29
|
-
context :uptime do
|
30
|
-
it 'should be positive' do
|
31
|
-
subject.shell.uptime.should > 0
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should be strictly increasing' do
|
35
|
-
u0 = subject.shell.uptime
|
36
|
-
sleep(1)
|
37
|
-
u1 = subject.shell.uptime
|
38
|
-
|
39
|
-
(u1 - u0).should >= 0
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context :booted_at do
|
44
|
-
it 'should be some time in the past' do
|
45
|
-
Time.at(subject.shell.booted_at).to_i.should < Time.now.to_i
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should be constant' do
|
49
|
-
b0 = subject.shell.booted_at
|
50
|
-
sleep(1)
|
51
|
-
b1 = subject.shell.booted_at
|
52
|
-
|
53
|
-
b0.should == b1
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'cloud-family queries' do
|
59
|
-
# PLEASE NOTE: we are unable to use the magic RSpec "subject" because
|
60
|
-
# we are dispatching calls to a Singleton and we must partially mock its
|
61
|
-
# calls, and both __send__ and flexmock partial-mocking gets confused by
|
62
|
-
# the fact that #subject returns a Proc, not the actual subject. Do not
|
63
|
-
# attempt to use the pretty RSpec feature within this context. You have
|
64
|
-
# been warned!
|
65
|
-
before(:each) do
|
66
|
-
@subject = subject.instance
|
67
|
-
@subject.instance_variable_set(:@ec2, nil)
|
68
|
-
@subject.instance_variable_set(:@rackspace, nil)
|
69
|
-
@subject.instance_variable_set(:@eucalyptus, nil)
|
70
|
-
end
|
71
|
-
|
72
|
-
['ec2', 'rackspace', 'eucalyptus'].each do |cloud|
|
73
|
-
it "should detect #{cloud}" do
|
74
|
-
query = "#{cloud}?".to_sym
|
75
|
-
flexmock(@subject).should_receive(:read_cloud_file).once.and_return(cloud)
|
76
|
-
@subject.__send__(query).should be_true
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
describe RightScale::Platform do
|
4
|
-
subject { RightScale::Platform }
|
5
|
-
|
6
|
-
context 'under Windows' do
|
7
|
-
context :installer do
|
8
|
-
context :install do
|
9
|
-
specify { lambda { subject.installer.install([]) }.should raise_exception }
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end if RightScale::Platform.windows?
|
@@ -1,318 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2012 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
|
-
if RightScale::Platform.windows?
|
26
|
-
module OsInfoExtensions
|
27
|
-
def set_osinfo(osinfo)
|
28
|
-
@os_info = osinfo
|
29
|
-
end
|
30
|
-
|
31
|
-
def get_osinfo
|
32
|
-
@os_info
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe RightScale::Platform do
|
37
|
-
before(:all) do
|
38
|
-
@platform = RightScale::Platform
|
39
|
-
end
|
40
|
-
|
41
|
-
context :volume_manager do
|
42
|
-
context :is_attachable_volume_path do
|
43
|
-
it 'allows paths with hyphens and underscores' do
|
44
|
-
@platform.volume_manager.is_attachable_volume_path?('C:\\Some_crazy-path').should == true
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'allows paths with periods' do
|
48
|
-
@platform.volume_manager.is_attachable_volume_path?('C:\\Some.crazy.path').should == true
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'allows paths with tildes' do
|
52
|
-
@platform.volume_manager.is_attachable_volume_path?('C:\\~Some~crazy~path').should == true
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context :parse_volumes do
|
57
|
-
it 'can parse volumes from diskpart output' do
|
58
|
-
list_vol_resp = <<EOF
|
59
|
-
Volume ### Ltr Label Fs Type Size Status Info
|
60
|
-
---------- --- ----------- ----- ---------- ------- --------- --------
|
61
|
-
Volume 0 C 2008Boot NTFS Partition 80 GB Healthy System
|
62
|
-
* Volume 1 D NTFS Partition 4094 MB Healthy
|
63
|
-
Volume 2 NTFS Partition 4094 MB Healthy
|
64
|
-
EOF
|
65
|
-
|
66
|
-
volume_hash_ary = [
|
67
|
-
{:index => 0, :device => "C:", :label => "2008Boot", :filesystem => "NTFS", :type => "Partition", :total_size => 85899345920, :status => "Healthy", :info => "System"},
|
68
|
-
{:index => 1, :device => "D:", :label => nil, :filesystem => "NTFS", :type => "Partition", :total_size => 4292870144, :status => "Healthy", :info => nil},
|
69
|
-
{:index => 2, :device => nil, :label => nil, :filesystem => "NTFS", :type => "Partition", :total_size => 4292870144, :status => "Healthy", :info => nil}
|
70
|
-
]
|
71
|
-
|
72
|
-
@platform.volume_manager.send(:parse_volumes, list_vol_resp).should == volume_hash_ary
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'can parse volumes from diskpart output with mounted paths' do
|
76
|
-
list_vol_resp = <<EOF
|
77
|
-
Volume ### Ltr Label Fs Type Size Status Info
|
78
|
-
---------- --- ----------- ----- ---------- ------- --------- --------
|
79
|
-
Volume 0 C NTFS Partition 80 GB Healthy System
|
80
|
-
* Volume 1 FAT32 Partition 1023 MB Healthy
|
81
|
-
C:\\Program Files\\RightScale\\Mount\\Softlayer\\
|
82
|
-
EOF
|
83
|
-
|
84
|
-
volume_hash_ary = [
|
85
|
-
{:index => 0, :device => "C:", :label => nil, :filesystem => "NTFS", :type => "Partition", :total_size => 85899345920, :status => "Healthy", :info => "System"},
|
86
|
-
{:index => 1, :device => "C:\\Program Files\\RightScale\\Mount\\Softlayer\\", :label => nil, :filesystem => "FAT32", :type => "Partition", :total_size => 1072693248, :status => "Healthy", :info => nil}
|
87
|
-
]
|
88
|
-
|
89
|
-
@platform.volume_manager.send(:parse_volumes, list_vol_resp).should == volume_hash_ary
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'raises a parser error when diskpart output is malformed' do
|
93
|
-
list_vol_resp = "foobarbaz"
|
94
|
-
|
95
|
-
lambda { @platform.volume_manager.send(:parse_volumes, list_vol_resp) }.should raise_error(RightScale::Platform::VolumeManager::ParserError)
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'can filter results with only one condition' do
|
99
|
-
list_vol_resp = <<EOF
|
100
|
-
Volume ### Ltr Label Fs Type Size Status Info
|
101
|
-
---------- --- ----------- ----- ---------- ------- --------- --------
|
102
|
-
Volume 0 C 2008Boot NTFS Partition 80 GB Healthy System
|
103
|
-
* Volume 1 D NTFS Partition 4094 MB Healthy
|
104
|
-
Volume 2 NTFS Partition 4094 MB Healthy
|
105
|
-
EOF
|
106
|
-
|
107
|
-
volume_hash_ary = [
|
108
|
-
{:index => 1, :device => "D:", :label => nil, :filesystem => "NTFS", :type => "Partition", :total_size => 4292870144, :status => "Healthy", :info => nil}
|
109
|
-
]
|
110
|
-
|
111
|
-
condition = {:device => "D:"}
|
112
|
-
|
113
|
-
@platform.volume_manager.send(:parse_volumes, list_vol_resp, condition).should == volume_hash_ary
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'can filter results with many conditions' do
|
117
|
-
list_vol_resp = <<EOF
|
118
|
-
Volume ### Ltr Label Fs Type Size Status Info
|
119
|
-
---------- --- ----------- ----- ---------- ------- --------- --------
|
120
|
-
Volume 0 C 2008Boot NTFS Partition 80 GB Healthy System
|
121
|
-
* Volume 1 D NTFS Partition 4094 MB Healthy
|
122
|
-
Volume 2 NTFS Partition 4094 MB Healthy
|
123
|
-
EOF
|
124
|
-
|
125
|
-
volume_hash_ary = [
|
126
|
-
{:index => 1, :device => "D:", :label => nil, :filesystem => "NTFS", :type => "Partition", :total_size => 4292870144, :status => "Healthy", :info => nil}
|
127
|
-
]
|
128
|
-
|
129
|
-
condition = {:device => "D:", :filesystem => "NTFS", :type => "Partition"}
|
130
|
-
|
131
|
-
@platform.volume_manager.send(:parse_volumes, list_vol_resp, condition).should == volume_hash_ary
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
context :assign_device do
|
136
|
-
it 'assigns a device to a drive letter when a drive letter is specified' do
|
137
|
-
script = <<EOF
|
138
|
-
rescan
|
139
|
-
list volume
|
140
|
-
select volume "0"
|
141
|
-
attribute volume clear readonly noerr
|
142
|
-
|
143
|
-
assign letter=S
|
144
|
-
EOF
|
145
|
-
|
146
|
-
mount_resp = ''
|
147
|
-
flexmock(@platform.volume_manager).should_receive(:run_script).with(script).once.and_return([0, mount_resp])
|
148
|
-
|
149
|
-
@platform.volume_manager.assign_device('0', 'S:')
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'assigns a device to a path when a mount point is specified' do
|
153
|
-
osinfo = flexmock(:major => 6)
|
154
|
-
|
155
|
-
@platform.volume_manager.extend(OsInfoExtensions)
|
156
|
-
old_osinfo = @platform.volume_manager.get_osinfo
|
157
|
-
@platform.volume_manager.set_osinfo(osinfo)
|
158
|
-
|
159
|
-
script = <<EOF
|
160
|
-
rescan
|
161
|
-
list volume
|
162
|
-
select volume "0"
|
163
|
-
attribute volume clear readonly noerr
|
164
|
-
|
165
|
-
assign mount="C:\\Program Files\\RightScale\\Mount\\Softlayer"
|
166
|
-
EOF
|
167
|
-
|
168
|
-
flexmock(@platform.volume_manager).should_receive(:run_script).with(script).once.and_return([0, ''])
|
169
|
-
|
170
|
-
@platform.volume_manager.assign_device('0', "C:\\Program Files\\RightScale\\Mount\\Softlayer")
|
171
|
-
@platform.volume_manager.set_osinfo(old_osinfo)
|
172
|
-
end
|
173
|
-
|
174
|
-
it 'raises an exception when an invalid drive letter is specified' do
|
175
|
-
lambda{@platform.volume_manager.assign_device('0', 'C:')}.should raise_error(RightScale::Platform::VolumeManager::ArgumentError)
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'raises an exception when an invalid path is specified' do
|
179
|
-
lambda{@platform.volume_manager.assign_device('0', 'This is not a path')}.should raise_error(RightScale::Platform::VolumeManager::ArgumentError)
|
180
|
-
end
|
181
|
-
|
182
|
-
it 'raises an exception when a mount path is specified and OS is pre 2008' do
|
183
|
-
osinfo = flexmock(:major => 5)
|
184
|
-
|
185
|
-
@platform.volume_manager.extend(OsInfoExtensions)
|
186
|
-
old_osinfo = @platform.volume_manager.get_osinfo
|
187
|
-
@platform.volume_manager.set_osinfo(osinfo)
|
188
|
-
|
189
|
-
lambda{@platform.volume_manager.assign_device(0, "C:\\Somepath")}.should raise_error(RightScale::Platform::VolumeManager::ArgumentError)
|
190
|
-
@platform.volume_manager.set_osinfo(old_osinfo)
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'does not assign the device if the device is already assigned' do
|
194
|
-
script = <<EOF
|
195
|
-
rescan
|
196
|
-
list volume
|
197
|
-
select volume "0"
|
198
|
-
attribute volume clear readonly noerr
|
199
|
-
|
200
|
-
assign mount="C:\\Program Files\\RightScale\\Mount\\Softlayer"
|
201
|
-
EOF
|
202
|
-
|
203
|
-
flexmock(@platform.volume_manager).should_receive(:run_script).with(script).once.and_return([0, ''])
|
204
|
-
|
205
|
-
@platform.volume_manager.assign_device('0', "C:\\Program Files\\RightScale\\Mount\\Softlayer")
|
206
|
-
flexmock(@platform.volume_manager).should_receive(:volumes).once.and_return({:index => '0', :device => "C:\\Program Files\\RightScale\\Mount\\Softlayer"})
|
207
|
-
@platform.volume_manager.assign_device('0', "C:\\Program Files\\RightScale\\Mount\\Softlayer", :idempotent => true)
|
208
|
-
end
|
209
|
-
|
210
|
-
it 'does not clear readonly flag if :clear_readonly option is set to false' do
|
211
|
-
script = <<EOF
|
212
|
-
rescan
|
213
|
-
list volume
|
214
|
-
select volume "0"
|
215
|
-
|
216
|
-
|
217
|
-
assign mount="C:\\Program Files\\RightScale\\Mount\\Softlayer"
|
218
|
-
EOF
|
219
|
-
|
220
|
-
flexmock(@platform.volume_manager).should_receive(:run_script).with(script).once.and_return([0, ''])
|
221
|
-
@platform.volume_manager.assign_device('0', "C:\\Program Files\\RightScale\\Mount\\Softlayer", {:clear_readonly => false})
|
222
|
-
end
|
223
|
-
|
224
|
-
it 'removes all previous assignments if :remove_all option is set to true' do
|
225
|
-
script = <<EOF
|
226
|
-
rescan
|
227
|
-
list volume
|
228
|
-
select volume "0"
|
229
|
-
attribute volume clear readonly noerr
|
230
|
-
remove all noerr
|
231
|
-
assign mount="C:\\Program Files\\RightScale\\Mount\\Softlayer"
|
232
|
-
EOF
|
233
|
-
|
234
|
-
flexmock(@platform.volume_manager).should_receive(:run_script).with(script).once.and_return([0, ''])
|
235
|
-
@platform.volume_manager.assign_device('0', "C:\\Program Files\\RightScale\\Mount\\Softlayer", :remove_all => true)
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
context :format_disk do
|
240
|
-
it 'formats and assigns a drive to a drive letter when a drive letter is specified' do
|
241
|
-
osinfo = flexmock(:major => 6)
|
242
|
-
@platform.volume_manager.extend(OsInfoExtensions)
|
243
|
-
old_osinfo = @platform.volume_manager.get_osinfo
|
244
|
-
@platform.volume_manager.set_osinfo(osinfo)
|
245
|
-
|
246
|
-
script = <<EOF
|
247
|
-
rescan
|
248
|
-
list disk
|
249
|
-
select disk 0
|
250
|
-
attribute disk clear readonly noerr
|
251
|
-
online disk noerr
|
252
|
-
clean
|
253
|
-
create partition primary
|
254
|
-
assign letter=S
|
255
|
-
format FS=NTFS quick
|
256
|
-
EOF
|
257
|
-
|
258
|
-
flexmock(@platform.volume_manager).should_receive(:run_script).with(script).once.and_return([0,''])
|
259
|
-
@platform.volume_manager.format_disk(0, 'S:')
|
260
|
-
@platform.volume_manager.set_osinfo(old_osinfo)
|
261
|
-
end
|
262
|
-
|
263
|
-
it 'formats and assigns a drive to a path when a mount point is specified' do
|
264
|
-
osinfo = flexmock(:major => 6)
|
265
|
-
@platform.volume_manager.extend(OsInfoExtensions)
|
266
|
-
old_osinfo = @platform.volume_manager.get_osinfo
|
267
|
-
@platform.volume_manager.set_osinfo(osinfo)
|
268
|
-
|
269
|
-
script = <<EOF
|
270
|
-
rescan
|
271
|
-
list disk
|
272
|
-
select disk 0
|
273
|
-
attribute disk clear readonly noerr
|
274
|
-
online disk noerr
|
275
|
-
clean
|
276
|
-
create partition primary
|
277
|
-
assign mount="C:\\Somepath"
|
278
|
-
format FS=NTFS quick
|
279
|
-
EOF
|
280
|
-
|
281
|
-
flexmock(@platform.volume_manager).should_receive(:run_script).with(script).once.and_return([0,''])
|
282
|
-
@platform.volume_manager.format_disk(0, 'C:\\Somepath')
|
283
|
-
@platform.volume_manager.set_osinfo(old_osinfo)
|
284
|
-
end
|
285
|
-
|
286
|
-
it 'raises an exception when a mount path is specified and OS is pre 2008' do
|
287
|
-
osinfo = flexmock(:major => 5)
|
288
|
-
|
289
|
-
@platform.volume_manager.extend(OsInfoExtensions)
|
290
|
-
old_osinfo = @platform.volume_manager.get_osinfo
|
291
|
-
@platform.volume_manager.set_osinfo(osinfo)
|
292
|
-
|
293
|
-
lambda{@platform.volume_manager.format_disk(0, "C:\\Somepath")}.should raise_error(RightScale::Platform::VolumeManager::ArgumentError)
|
294
|
-
@platform.volume_manager.set_osinfo(old_osinfo)
|
295
|
-
end
|
296
|
-
|
297
|
-
end
|
298
|
-
|
299
|
-
context :online_disk do
|
300
|
-
it 'does not online the disk if the disk is already online' do
|
301
|
-
script = <<EOF
|
302
|
-
rescan
|
303
|
-
list disk
|
304
|
-
select disk 0
|
305
|
-
attribute disk clear readonly noerr
|
306
|
-
online disk noerr
|
307
|
-
EOF
|
308
|
-
|
309
|
-
flexmock(@platform.volume_manager).should_receive(:run_script).with(script).once.and_return([0, ''])
|
310
|
-
|
311
|
-
@platform.volume_manager.online_disk(0)
|
312
|
-
flexmock(@platform.volume_manager).should_receive(:disks).once.and_return({:index => 0, :status => "Online"})
|
313
|
-
@platform.volume_manager.online_disk(0, :idempotent => true)
|
314
|
-
end
|
315
|
-
end
|
316
|
-
end
|
317
|
-
end
|
318
|
-
end
|