Skip to content

Commit e875038

Browse files
committed
Added tests
1 parent 64b9e41 commit e875038

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

src/BlockStorage/v2/Models/Volume.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,38 @@ public function parseMetadata(ResponseInterface $response): array
160160
return isset($json['metadata']) ? $json['metadata'] : [];
161161
}
162162

163+
/**
164+
* Update the bootable status for a volume, mark it as a bootable volume.
165+
*
166+
* @param bool $bootable
167+
*/
163168
public function setBootable(bool $bootable)
164169
{
165170
$bootable = boolval($bootable);
166171
$this->execute($this->api->postVolumeBootable(), ['id' => $this->id, 'bootable' => $bootable]);
167172
}
168173

174+
/**
175+
* Sets the image metadata for a volume.
176+
*
177+
* @param array $metadata
178+
*/
169179
public function setImageMetadata(array $metadata)
170180
{
171181
$this->execute($this->api->postImageMetadata(), ['id' => $this->id, 'metadata' => $metadata]);
172182
}
173183

184+
/**
185+
* Administrator only. Resets the status, attach status, and migration status for a volume. Specify the os-reset_status action in the request body.
186+
*
187+
* @param array $options
188+
*
189+
* $options['status'] = (string) The volume status.
190+
* $options['migrationStatus'] = (string) The volume migration status.
191+
* $options['attachStatus'] = (string) The volume attach status. [OPTIONAL]
192+
*
193+
* @see https://developer.openstack.org/api-ref/block-storage/v2/index.html#volume-actions-volumes-action
194+
*/
174195
public function resetStatus(array $options)
175196
{
176197
$options += ['id' => $this->id];

src/BlockStorage/v2/Params.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public function volumeMigrationStatus(): array
106106
'location' => self::JSON,
107107
'required' => false,
108108
'description' => 'The volume migration status.',
109+
'sentAs' => 'migration_status',
109110
];
110111
}
111112

@@ -116,6 +117,7 @@ public function volumeAttachStatus(): array
116117
'location' => self::JSON,
117118
'required' => false,
118119
'description' => 'The volume attach status.',
120+
'sentAs' => 'attach_status',
119121
];
120122
}
121123

tests/unit/BlockStorage/v2/Models/VolumeTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,44 @@ public function test_it_resets_metadata()
8888

8989
$this->volume->resetMetadata(['key1' => 'val1']);
9090
}
91+
92+
public function test_it_sets_volume_bootable()
93+
{
94+
$this->setupMock('POST', 'volumes/1/action', ['os-set_bootable' => ['bootable' => 'True']], [], new Response(200));
95+
96+
$this->volume->setBootable(true);
97+
}
98+
99+
public function test_it_sets_image_meta_data()
100+
{
101+
$expectedJson = [
102+
'os-set_image_metadata' => [
103+
'metadata' => [
104+
'attr_foo' => 'foofoo',
105+
'attr_bar' => 'barbar',
106+
],
107+
],
108+
];
109+
110+
$this->setupMock('POST', 'volumes/1/action', $expectedJson, [], new Response(200));
111+
$this->volume->setImageMetadata([
112+
'attr_foo' => 'foofoo',
113+
'attr_bar' => 'barbar',
114+
]);
115+
}
116+
117+
public function test_it_resets_status()
118+
{
119+
$expectedJson = ['os-reset_status' => ['status' => 'available', 'attach_status' => 'detached', 'migration_status' => 'migrating']];
120+
121+
$this->setupMock('POST', 'volumes/1/action', $expectedJson, [], new Response(202));
122+
123+
$this->volume->resetStatus(
124+
[
125+
'status' => 'available',
126+
'attachStatus' => 'detached',
127+
'migrationStatus' => 'migrating',
128+
]
129+
);
130+
}
91131
}

tests/unit/Networking/v2/Extensions/Layer3/Models/FloatingIpTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,11 @@ public function test_it_retrieves()
7979
$this->floatingIp->id
8080
);
8181
}
82+
83+
public function test_it_associates_port()
84+
{
85+
$this->setupMock('PUT', 'v2.0/floatingips/id', ['floatingip' => ['port_id' => 'some-port-id']], [], 'FloatingIp');
86+
87+
$this->floatingIp->associatePort('some-port-id');
88+
}
8289
}

0 commit comments

Comments
 (0)