Skip to content

Commit c889751

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add "encryption-*" options in volume type commands"
2 parents ef1a86a + b2fd8ba commit c889751

10 files changed

Lines changed: 1235 additions & 19 deletions

File tree

doc/source/command-objects/volume-type.rst

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Create new volume type
1818
[--property <key=value> [...] ]
1919
[--project <project>]
2020
[--project-domain <project-domain>]
21+
[--encryption-provider <provider>]
22+
[--encryption-cipher <cipher>]
23+
[--encryption-key-size <key-size>]
24+
[--encryption-control-location <control-location>]
2125
<name>
2226
2327
.. option:: --description <description>
@@ -56,6 +60,34 @@ Create new volume type
5660

5761
*Volume version 2 only*
5862

63+
.. option:: --encryption-provider <provider>
64+
65+
Set the class that provides encryption support for this volume type
66+
(e.g "LuksEncryptor") (admin only)
67+
68+
This option is required when setting encryption type of a volume.
69+
Consider using other encryption options such as: :option:`--encryption-cipher`,
70+
:option:`--encryption-key-size` and :option:`--encryption-control-location`
71+
72+
.. option:: --encryption-cipher <cipher>
73+
74+
Set the encryption algorithm or mode for this volume type
75+
(e.g "aes-xts-plain64") (admin only)
76+
77+
.. option:: --encryption-key-size <key-size>
78+
79+
Set the size of the encryption key of this volume type
80+
(e.g "128" or "256") (admin only)
81+
82+
.. option:: --encryption-control-location <control-location>
83+
84+
Set the notional service where the encryption is performed
85+
("front-end" or "back-end") (admin only)
86+
87+
The default value for this option is "front-end" when setting encryption type of
88+
a volume. Consider using other encryption options such as: :option:`--encryption-cipher`,
89+
:option:`--encryption-key-size` and :option:`--encryption-provider`
90+
5991
.. _volume_type_create-name:
6092
.. describe:: <name>
6193

@@ -88,6 +120,7 @@ List volume types
88120
openstack volume type list
89121
[--long]
90122
[--default | --public | --private]
123+
[--encryption-type]
91124
92125
.. option:: --long
93126

@@ -111,6 +144,10 @@ List volume types
111144

112145
*Volume version 2 only*
113146

147+
.. option:: --encryption-type
148+
149+
Display encryption information for each volume type (admin only)
150+
114151
volume type set
115152
---------------
116153

@@ -125,6 +162,10 @@ Set volume type properties
125162
[--property <key=value> [...] ]
126163
[--project <project>]
127164
[--project-domain <project-domain>]
165+
[--encryption-provider <provider>]
166+
[--encryption-cipher <cipher>]
167+
[--encryption-key-size <key-size>]
168+
[--encryption-control-location <control-location>]
128169
<volume-type>
129170
130171
.. option:: --name <name>
@@ -154,6 +195,34 @@ Set volume type properties
154195

155196
Set a property on this volume type (repeat option to set multiple properties)
156197

198+
.. option:: --encryption-provider <provider>
199+
200+
Set the class that provides encryption support for this volume type
201+
(e.g "LuksEncryptor") (admin only)
202+
203+
This option is required when setting encryption type of a volume for the first time.
204+
Consider using other encryption options such as: :option:`--encryption-cipher`,
205+
:option:`--encryption-key-size` and :option:`--encryption-control-location`
206+
207+
.. option:: --encryption-cipher <cipher>
208+
209+
Set the encryption algorithm or mode for this volume type
210+
(e.g "aes-xts-plain64") (admin only)
211+
212+
.. option:: --encryption-key-size <key-size>
213+
214+
Set the size of the encryption key of this volume type
215+
(e.g "128" or "256") (admin only)
216+
217+
.. option:: --encryption-control-location <control-location>
218+
219+
Set the notional service where the encryption is performed
220+
("front-end" or "back-end") (admin only)
221+
222+
The default value for this option is "front-end" when setting encryption type of
223+
a volume for the first time. Consider using other encryption options such as:
224+
:option:`--encryption-cipher`, :option:`--encryption-key-size` and :option:`--encryption-provider`
225+
157226
.. _volume_type_set-volume-type:
158227
.. describe:: <volume-type>
159228

@@ -168,8 +237,13 @@ Display volume type details
168237
.. code:: bash
169238
170239
openstack volume type show
240+
[--encryption-type]
171241
<volume-type>
172242
243+
.. option:: --encryption-type
244+
245+
Display encryption information of this volume type (admin only)
246+
173247
.. _volume_type_show-volume-type:
174248
.. describe:: <volume-type>
175249

@@ -187,6 +261,7 @@ Unset volume type properties
187261
[--property <key> [...] ]
188262
[--project <project>]
189263
[--project-domain <project-domain>]
264+
[--encryption-type]
190265
<volume-type>
191266
192267
.. option:: --property <key>
@@ -204,6 +279,12 @@ Unset volume type properties
204279
Domain the project belongs to (name or ID).
205280
This can be used in case collisions between project names exist.
206281

282+
*Volume version 2 only*
283+
284+
.. option:: --encryption-type
285+
286+
Remove the encryption type for this volume type (admin only)
287+
207288
.. _volume_type_unset-volume-type:
208289
.. describe:: <volume-type>
209290

openstackclient/tests/functional/volume/v1/test_volume_type.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,74 @@ def test_multi_delete(self):
8787
time.sleep(5)
8888
raw_output = self.openstack(cmd)
8989
self.assertOutput('', raw_output)
90+
91+
# NOTE: Add some basic funtional tests with the old format to
92+
# make sure the command works properly, need to change
93+
# these to new test format when beef up all tests for
94+
# volume tye commands.
95+
def test_encryption_type(self):
96+
encryption_type = uuid.uuid4().hex
97+
# test create new encryption type
98+
opts = self.get_opts(['encryption'])
99+
raw_output = self.openstack(
100+
'volume type create '
101+
'--encryption-provider LuksEncryptor '
102+
'--encryption-cipher aes-xts-plain64 '
103+
'--encryption-key-size 128 '
104+
'--encryption-control-location front-end ' +
105+
encryption_type + opts)
106+
expected = ["provider='LuksEncryptor'",
107+
"cipher='aes-xts-plain64'",
108+
"key_size='128'",
109+
"control_location='front-end'"]
110+
for attr in expected:
111+
self.assertIn(attr, raw_output)
112+
# test show encryption type
113+
opts = self.get_opts(['encryption'])
114+
raw_output = self.openstack(
115+
'volume type show --encryption-type ' + encryption_type + opts)
116+
expected = ["provider='LuksEncryptor'",
117+
"cipher='aes-xts-plain64'",
118+
"key_size='128'",
119+
"control_location='front-end'"]
120+
for attr in expected:
121+
self.assertIn(attr, raw_output)
122+
# test list encryption type
123+
opts = self.get_opts(['Encryption'])
124+
raw_output = self.openstack(
125+
'volume type list --encryption-type ' + opts)
126+
expected = ["provider='LuksEncryptor'",
127+
"cipher='aes-xts-plain64'",
128+
"key_size='128'",
129+
"control_location='front-end'"]
130+
for attr in expected:
131+
self.assertIn(attr, raw_output)
132+
# test set new encryption type
133+
raw_output = self.openstack(
134+
'volume type set '
135+
'--encryption-provider LuksEncryptor '
136+
'--encryption-cipher aes-xts-plain64 '
137+
'--encryption-key-size 128 '
138+
'--encryption-control-location front-end ' +
139+
self.NAME)
140+
self.assertEqual('', raw_output)
141+
opts = self.get_opts(['encryption'])
142+
raw_output = self.openstack(
143+
'volume type show --encryption-type ' + self.NAME + opts)
144+
expected = ["provider='LuksEncryptor'",
145+
"cipher='aes-xts-plain64'",
146+
"key_size='128'",
147+
"control_location='front-end'"]
148+
for attr in expected:
149+
self.assertIn(attr, raw_output)
150+
# test unset encryption type
151+
raw_output = self.openstack(
152+
'volume type unset --encryption-type ' + self.NAME)
153+
self.assertEqual('', raw_output)
154+
opts = self.get_opts(['encryption'])
155+
raw_output = self.openstack(
156+
'volume type show --encryption-type ' + self.NAME + opts)
157+
self.assertEqual('\n', raw_output)
158+
# test delete encryption type
159+
raw_output = self.openstack('volume type delete ' + encryption_type)
160+
self.assertEqual('', raw_output)

openstackclient/tests/functional/volume/v2/test_volume_type.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,90 @@ def test_multi_delete(self):
102102
time.sleep(5)
103103
raw_output = self.openstack(cmd)
104104
self.assertOutput('', raw_output)
105+
106+
# NOTE: Add some basic funtional tests with the old format to
107+
# make sure the command works properly, need to change
108+
# these to new test format when beef up all tests for
109+
# volume tye commands.
110+
def test_encryption_type(self):
111+
encryption_type = uuid.uuid4().hex
112+
# test create new encryption type
113+
opts = self.get_opts(['encryption'])
114+
raw_output = self.openstack(
115+
'volume type create '
116+
'--encryption-provider LuksEncryptor '
117+
'--encryption-cipher aes-xts-plain64 '
118+
'--encryption-key-size 128 '
119+
'--encryption-control-location front-end ' +
120+
encryption_type + opts)
121+
expected = ["provider='LuksEncryptor'",
122+
"cipher='aes-xts-plain64'",
123+
"key_size='128'",
124+
"control_location='front-end'"]
125+
for attr in expected:
126+
self.assertIn(attr, raw_output)
127+
# test show encryption type
128+
opts = self.get_opts(['encryption'])
129+
raw_output = self.openstack(
130+
'volume type show --encryption-type ' + encryption_type + opts)
131+
expected = ["provider='LuksEncryptor'",
132+
"cipher='aes-xts-plain64'",
133+
"key_size='128'",
134+
"control_location='front-end'"]
135+
for attr in expected:
136+
self.assertIn(attr, raw_output)
137+
# test list encryption type
138+
opts = self.get_opts(['Encryption'])
139+
raw_output = self.openstack(
140+
'volume type list --encryption-type ' + opts)
141+
expected = ["provider='LuksEncryptor'",
142+
"cipher='aes-xts-plain64'",
143+
"key_size='128'",
144+
"control_location='front-end'"]
145+
for attr in expected:
146+
self.assertIn(attr, raw_output)
147+
# test set existing encryption type
148+
raw_output = self.openstack(
149+
'volume type set '
150+
'--encryption-key-size 256 '
151+
'--encryption-control-location back-end ' +
152+
encryption_type)
153+
self.assertEqual('', raw_output)
154+
opts = self.get_opts(['encryption'])
155+
raw_output = self.openstack(
156+
'volume type show --encryption-type ' + encryption_type + opts)
157+
expected = ["provider='LuksEncryptor'",
158+
"cipher='aes-xts-plain64'",
159+
"key_size='256'",
160+
"control_location='back-end'"]
161+
for attr in expected:
162+
self.assertIn(attr, raw_output)
163+
# test set new encryption type
164+
raw_output = self.openstack(
165+
'volume type set '
166+
'--encryption-provider LuksEncryptor '
167+
'--encryption-cipher aes-xts-plain64 '
168+
'--encryption-key-size 128 '
169+
'--encryption-control-location front-end ' +
170+
self.NAME)
171+
self.assertEqual('', raw_output)
172+
opts = self.get_opts(['encryption'])
173+
raw_output = self.openstack(
174+
'volume type show --encryption-type ' + self.NAME + opts)
175+
expected = ["provider='LuksEncryptor'",
176+
"cipher='aes-xts-plain64'",
177+
"key_size='128'",
178+
"control_location='front-end'"]
179+
for attr in expected:
180+
self.assertIn(attr, raw_output)
181+
# test unset encryption type
182+
raw_output = self.openstack(
183+
'volume type unset --encryption-type ' + self.NAME)
184+
self.assertEqual('', raw_output)
185+
opts = self.get_opts(['encryption'])
186+
raw_output = self.openstack(
187+
'volume type show --encryption-type ' + self.NAME + opts)
188+
self.assertEqual('\n', raw_output)
189+
# test delete encryption type
190+
raw_output = self.openstack('volume type delete ' + encryption_type)
191+
self.assertEqual('', raw_output)

openstackclient/tests/unit/volume/v1/fakes.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ def __init__(self, **kwargs):
364364
self.qos_specs.resource_class = fakes.FakeResource(None, {})
365365
self.volume_types = mock.Mock()
366366
self.volume_types.resource_class = fakes.FakeResource(None, {})
367+
self.volume_encryption_types = mock.Mock()
368+
self.volume_encryption_types.resource_class = (
369+
fakes.FakeResource(None, {}))
367370
self.transfers = mock.Mock()
368371
self.transfers.resource_class = fakes.FakeResource(None, {})
369372
self.volume_snapshots = mock.Mock()
@@ -470,6 +473,34 @@ def get_types(types=None, count=2):
470473

471474
return mock.Mock(side_effect=types)
472475

476+
@staticmethod
477+
def create_one_encryption_type(attrs=None):
478+
"""Create a fake encryption type.
479+
480+
:param Dictionary attrs:
481+
A dictionary with all attributes
482+
:return:
483+
A FakeResource object with volume_type_id etc.
484+
"""
485+
attrs = attrs or {}
486+
487+
# Set default attributes.
488+
encryption_info = {
489+
"volume_type_id": 'type-id-' + uuid.uuid4().hex,
490+
'provider': 'LuksEncryptor',
491+
'cipher': None,
492+
'key_size': None,
493+
'control_location': 'front-end',
494+
}
495+
496+
# Overwrite default attributes.
497+
encryption_info.update(attrs)
498+
499+
encryption_type = fakes.FakeResource(
500+
info=copy.deepcopy(encryption_info),
501+
loaded=True)
502+
return encryption_type
503+
473504

474505
class FakeSnapshot(object):
475506
"""Fake one or more snapshot."""

0 commit comments

Comments
 (0)