Skip to content
This repository was archived by the owner on May 14, 2018. It is now read-only.

Commit f689c27

Browse files
committed
Rename partition to volumes
1 parent 00aa1fb commit f689c27

File tree

4 files changed

+99
-97
lines changed

4 files changed

+99
-97
lines changed

app/jobs/mount_block_devices_job.rb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,15 @@ def perform(block_devices:)
1010

1111
def mount_block_devices(block_devices:)
1212
block_devices = Cell.mount_block_devices block_devices: block_devices
13-
block_devices.map do |block_device, partitions|
13+
block_devices.map do |block_device|
1414
{
15-
device: block_device,
16-
status: :healthy,
17-
partitions: device_partitions(partitions: partitions)
15+
device: block_device[:device],
16+
status: :healthy,
17+
volumes: block_device[:volumes].map { |volume| { volume: volume, status: :healthy } }
1818
}
1919
end
2020
end
2121

22-
def device_partitions(partitions:)
23-
partitions[:partitions].map do |partition|
24-
{ partition: partition, status: :healthy }
25-
end
26-
end
27-
2822
def notify_brain(block_devices:)
2923
Brain.request path: "/cluster-api/v1/cells/#{Cell.uuid}/block-devices",
3024
method: :patch,

app/lib/cell.rb

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,43 @@ def self.fqdn
3030
end
3131

3232
def self.mount_block_devices(block_devices:)
33-
{}.tap do |successful_mounts|
33+
[].tap do |successful_mounts|
3434
block_devices.each do |block_device|
3535
next unless self.block_devices.keys.include? block_device.to_sym
36-
successful_mounts[block_device] = {
37-
partitions: mount_block_device(block_device: block_device)
36+
successful_mounts << {
37+
device: block_device,
38+
volumes: mount_block_device(block_device: block_device)
3839
}
3940
end
4041
end
4142
end
4243

4344
def self.mount_block_device(block_device:)
4445
[].tap do |successful_mounts|
45-
device_partitions(block_device: block_device).each_key do |block_device_partition|
46-
if mount_block_device_partition block_device_partition: block_device_partition
47-
successful_mounts << block_device_partition
46+
device_volumes(block_device: block_device).each_key do |block_device_volume|
47+
if mount_block_device_volume block_device_volume: block_device_volume
48+
successful_mounts << block_device_volume
4849
end
4950
end
5051
end
5152
end
5253

53-
def self.mount_block_device_partition(block_device_partition:)
54-
FileUtils.mkdir_p "/volumes/#{block_device_partition}"
55-
system "mount /dev/#{block_device_partition} /volumes/#{block_device_partition}"
54+
def self.mount_block_device_volume(block_device_volume:)
55+
FileUtils.mkdir_p "/volumes/#{block_device_volume}"
56+
system "mount /dev/#{block_device_volume} /volumes/#{block_device_volume}"
5657
end
5758

5859
def self.block_devices
5960
devices = Pathname.new("/sys/block").children.select do |device|
6061
device.directory? && block_device?(device: device)
6162
end
62-
Hash[devices.map do |device|
63-
[device.basename.to_s.to_sym,
64-
total_capacity: File.read(File.join(device.to_s, "size")).strip.to_i * 512,
65-
partitions: device_partitions(block_device: device.basename.to_s)]
66-
end]
63+
devices.map do |device|
64+
{
65+
device: device.basename.to_s.to_sym,
66+
total_capacity: File.read(File.join(device.to_s, "size")).strip.to_i * 512,
67+
volumes: device_volumes(block_device: device.basename.to_s)
68+
}
69+
end
6770
end
6871

6972
def self.block_device?(device:)
@@ -72,15 +75,16 @@ def self.block_device?(device:)
7275
File.read(File.join(device.to_s, "/device/type")).strip.to_i.zero?)
7376
end
7477

75-
def self.device_partitions(block_device:)
76-
partitions = Pathname.new(File.join("/sys/block", block_device.to_s)).children.select do |p|
78+
def self.device_volumes(block_device:)
79+
volumes = Pathname.new(File.join("/sys/block", block_device.to_s)).children.select do |p|
7780
p.directory? && p.basename.to_s =~ /^#{block_device}\d+/
7881
end
79-
partitions.map! do |partition|
80-
[partition.basename.to_s.to_sym,
81-
total_capacity: File.read(File.join(partition.to_s, "size")).strip.to_i * 512]
82+
volumes.map do |volume|
83+
{
84+
volume: volume.basename.to_s.to_sym,
85+
total_capacity: File.read(File.join(volume.to_s, "size")).strip.to_i * 512
86+
}
8287
end
83-
Hash[partitions]
8488
end
8589

8690
def self.request(cell_ip:, path:, method: :get, payload: nil, query: nil)

spec/jobs/mount_block_devices_job_spec.rb

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,46 @@
44

55
let(:cell_uuid) { SecureRandom.uuid }
66
let(:block_devices) { %w[sdb sdc sdd] }
7-
let(:block_device_partitions) do
8-
{
9-
sdb: {
10-
partitions: %i[sdb1 sdb2]
7+
let(:block_device_volumes) do
8+
[
9+
{
10+
device: :sdb,
11+
volumes: %i[sdb1 sdb2]
1112
},
12-
sdc: {
13-
partitions: %i[sdc1 sdc2]
13+
{
14+
device: :sdc,
15+
volumes: %i[sdc1 sdc2]
1416
},
15-
sdd: {
16-
partitions: %i[sdd1 sdd2]
17+
{
18+
device: :sdd,
19+
volumes: %i[sdd1 sdd2]
1720
}
18-
}
21+
]
1922
end
2023
let(:block_devices_payload) do
2124
[
2225
{
23-
device: :sdb,
24-
status: :healthy,
25-
partitions: [
26-
{ partition: :sdb1, status: :healthy },
27-
{ partition: :sdb2, status: :healthy }
26+
device: :sdb,
27+
status: :healthy,
28+
volumes: [
29+
{ volume: :sdb1, status: :healthy },
30+
{ volume: :sdb2, status: :healthy }
2831
]
2932
},
3033
{
31-
device: :sdc,
32-
status: :healthy,
33-
partitions: [
34-
{ partition: :sdc1, status: :healthy },
35-
{ partition: :sdc2, status: :healthy }
34+
device: :sdc,
35+
status: :healthy,
36+
volumes: [
37+
{ volume: :sdc1, status: :healthy },
38+
{ volume: :sdc2, status: :healthy }
3639
]
3740
},
3841
{
39-
device: :sdd,
40-
status: :healthy,
41-
partitions: [
42-
{ partition: :sdd1, status: :healthy },
43-
{ partition: :sdd2, status: :healthy }
42+
device: :sdd,
43+
status: :healthy,
44+
volumes: [
45+
{ volume: :sdd1, status: :healthy },
46+
{ volume: :sdd2, status: :healthy }
4447
]
4548
}
4649
]
@@ -60,7 +63,7 @@
6063
before do
6164
allow(Cell).to receive(:uuid).and_return cell_uuid
6265
allow(Cell).to receive(:mount_block_devices).with(block_devices: block_devices)
63-
.and_return block_device_partitions
66+
.and_return block_device_volumes
6467
allow(Brain).to receive(:request).with block_devices_params
6568
described_class.perform_now block_devices: block_devices
6669
end

spec/lib/cell_spec.rb

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33

44
RSpec.describe Cell do
55

6-
let(:cell_uuid) { SecureRandom.uuid }
7-
let(:cell_ip) { "127.0.0.1" }
8-
let(:cell_fqdn) { "cell.example.com" }
9-
let(:path) { "/some/path" }
10-
let(:payload) { { some: "payload" } }
11-
let(:loop_device) { OpenStruct.new basename: "loop0" }
12-
let(:block_device) { OpenStruct.new basename: "sdb" }
13-
let(:storage_mountpoints) { { "/dev/sdb1" => "/volumes/one", "/dev/sdc1" => "/volumes/two" } }
14-
let(:capacity) { { total_capacity: 107, available_capacity: 25 } }
6+
let(:cell_uuid) { SecureRandom.uuid }
7+
let(:cell_ip) { "127.0.0.1" }
8+
let(:cell_fqdn) { "cell.example.com" }
9+
let(:path) { "/some/path" }
10+
let(:payload) { { some: "payload" } }
11+
let(:loop_device) { OpenStruct.new basename: "loop0" }
12+
let(:block_device) { OpenStruct.new basename: "sdb" }
13+
let(:capacity) { { total_capacity: 107, available_capacity: 25 } }
1514

1615
describe ".digest_contents" do
1716
subject { described_class.digest_contents "some contents" }
@@ -85,12 +84,12 @@
8584
let(:mount_block_devices) do
8685
described_class.mount_block_devices block_devices: block_devices
8786
end
88-
let(:block_devices_and_partitions) do
89-
{
90-
sda: { partitions: [:sdx1] },
91-
sdb: { partitions: [:sdx1] },
92-
sdc: { partitions: [:sdx1] }
93-
}
87+
let(:block_devices_and_volumes) do
88+
[
89+
{ device: :sda, volumes: [:sdx1] },
90+
{ device: :sdb, volumes: [:sdx1] },
91+
{ device: :sdc, volumes: [:sdx1] }
92+
]
9493
end
9594

9695
before do
@@ -99,32 +98,32 @@
9998
.exactly(block_devices.count).times.and_return [:sdx1]
10099
end
101100

102-
it { is_expected.to match block_devices_and_partitions }
101+
it { is_expected.to match block_devices_and_volumes }
103102
end
104103

105104
describe ".mount_block_device" do
106105
subject { mount_block_device }
107106

108-
let(:block_device) { :sda }
109-
let(:block_device_partition) { :sda1 }
110-
let(:mount_block_device) { described_class.mount_block_device block_device: block_device }
107+
let(:block_device) { :sda }
108+
let(:block_device_volume) { :sda1 }
109+
let(:mount_block_device) { described_class.mount_block_device block_device: block_device }
111110

112111
before do
113-
allow(described_class).to receive(:device_partitions).and_return(sda1: {})
114-
allow(described_class).to receive(:mount_block_device_partition)
115-
.with(block_device_partition: block_device_partition).and_return true
112+
allow(described_class).to receive(:device_volumes).and_return(sda1: {})
113+
allow(described_class).to receive(:mount_block_device_volume)
114+
.with(block_device_volume: block_device_volume).and_return true
116115
end
117116

118-
it { is_expected.to match [block_device_partition] }
117+
it { is_expected.to match [block_device_volume] }
119118
end
120119

121-
describe ".mount_block_device_partition" do
122-
let(:block_device_partition) { :sdb }
123-
let(:block_device_partition_dev) { "/dev/#{block_device_partition}" }
124-
let(:volume) { "/volumes/#{block_device_partition}" }
125-
let(:mount_args) { "mount #{block_device_partition_dev} #{volume}" }
120+
describe ".mount_block_device_volume" do
121+
let(:block_device_volume) { :sdb }
122+
let(:block_device_volume_dev) { "/dev/#{block_device_volume}" }
123+
let(:volume) { "/volumes/#{block_device_volume}" }
124+
let(:mount_args) { "mount #{block_device_volume_dev} #{volume}" }
126125
let(:mount_block_device) do
127-
described_class.mount_block_device_partition block_device_partition: block_device_partition
126+
described_class.mount_block_device_volume block_device_volume: block_device_volume
128127
end
129128

130129
before do
@@ -145,13 +144,13 @@
145144
describe ".block_devices" do
146145
subject { described_class.block_devices }
147146

148-
let(:partitions) do
149-
{
150-
sdb1: { total_capacity: 2103296 },
151-
sdb2: { total_capacity: 16771072 },
152-
sdb3: { total_capacity: 209713152 },
153-
sdb4: { total_capacity: 771624960 }
154-
}
147+
let(:volumes) do
148+
[
149+
{ volume: :sdb1, total_capacity: 2103296 },
150+
{ volume: :sdb2, total_capacity: 16771072 },
151+
{ volume: :sdb3, total_capacity: 209713152 },
152+
{ volume: :sdb4, total_capacity: 771624960 }
153+
]
155154
end
156155

157156
before do
@@ -160,12 +159,14 @@
160159
)
161160
allow(described_class).to receive(:block_device?).and_return true
162161
allow(File).to receive(:read).and_return "1000215216"
163-
allow(described_class).to receive(:device_partitions).with(block_device: "sdb").and_return(
164-
partitions
162+
allow(described_class).to receive(:device_volumes).with(block_device: "sdb").and_return(
163+
volumes
165164
)
166165
end
167166

168-
it { is_expected.to eq sdb: { total_capacity: (1000215216 * 512), partitions: partitions } }
167+
it do
168+
is_expected.to eq [{ device: :sdb, total_capacity: (1000215216 * 512), volumes: volumes }]
169+
end
169170
end
170171

171172
describe ".block_device?" do
@@ -208,17 +209,17 @@
208209
end
209210
end
210211

211-
describe ".device_partitions" do
212+
describe ".device_volumes" do
212213
before do
213214
allow(Pathname).to receive(:new).with("/sys/block/sdb").and_return(
214215
OpenStruct.new(children: [OpenStruct.new(basename: "sdb1", directory?: true)])
215216
)
216217
allow(File).to receive(:read).and_return "1024"
217218
end
218219

219-
subject { described_class.device_partitions block_device: "sdb" }
220+
subject { described_class.device_volumes block_device: "sdb" }
220221

221-
it { is_expected.to eq(sdb1: { total_capacity: (1024 * 512) }) }
222+
it { is_expected.to eq([{ volume: :sdb1, total_capacity: (1024 * 512) }]) }
222223
end
223224

224225
describe ".request" do

0 commit comments

Comments
 (0)