|
3 | 3 |
|
4 | 4 | RSpec.describe Cell do |
5 | 5 |
|
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 } } |
15 | 14 |
|
16 | 15 | describe ".digest_contents" do |
17 | 16 | subject { described_class.digest_contents "some contents" } |
|
85 | 84 | let(:mount_block_devices) do |
86 | 85 | described_class.mount_block_devices block_devices: block_devices |
87 | 86 | 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 | + ] |
94 | 93 | end |
95 | 94 |
|
96 | 95 | before do |
|
99 | 98 | .exactly(block_devices.count).times.and_return [:sdx1] |
100 | 99 | end |
101 | 100 |
|
102 | | - it { is_expected.to match block_devices_and_partitions } |
| 101 | + it { is_expected.to match block_devices_and_volumes } |
103 | 102 | end |
104 | 103 |
|
105 | 104 | describe ".mount_block_device" do |
106 | 105 | subject { mount_block_device } |
107 | 106 |
|
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 } |
111 | 110 |
|
112 | 111 | 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 |
116 | 115 | end |
117 | 116 |
|
118 | | - it { is_expected.to match [block_device_partition] } |
| 117 | + it { is_expected.to match [block_device_volume] } |
119 | 118 | end |
120 | 119 |
|
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}" } |
126 | 125 | 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 |
128 | 127 | end |
129 | 128 |
|
130 | 129 | before do |
|
145 | 144 | describe ".block_devices" do |
146 | 145 | subject { described_class.block_devices } |
147 | 146 |
|
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 | + ] |
155 | 154 | end |
156 | 155 |
|
157 | 156 | before do |
|
160 | 159 | ) |
161 | 160 | allow(described_class).to receive(:block_device?).and_return true |
162 | 161 | 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 |
165 | 164 | ) |
166 | 165 | end |
167 | 166 |
|
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 |
169 | 170 | end |
170 | 171 |
|
171 | 172 | describe ".block_device?" do |
|
208 | 209 | end |
209 | 210 | end |
210 | 211 |
|
211 | | - describe ".device_partitions" do |
| 212 | + describe ".device_volumes" do |
212 | 213 | before do |
213 | 214 | allow(Pathname).to receive(:new).with("/sys/block/sdb").and_return( |
214 | 215 | OpenStruct.new(children: [OpenStruct.new(basename: "sdb1", directory?: true)]) |
215 | 216 | ) |
216 | 217 | allow(File).to receive(:read).and_return "1024" |
217 | 218 | end |
218 | 219 |
|
219 | | - subject { described_class.device_partitions block_device: "sdb" } |
| 220 | + subject { described_class.device_volumes block_device: "sdb" } |
220 | 221 |
|
221 | | - it { is_expected.to eq(sdb1: { total_capacity: (1024 * 512) }) } |
| 222 | + it { is_expected.to eq([{ volume: :sdb1, total_capacity: (1024 * 512) }]) } |
222 | 223 | end |
223 | 224 |
|
224 | 225 | describe ".request" do |
|
0 commit comments