295 (c5339030e64781bf8f0d80ab7c5044b5547df79b) 295 (b6aed193e5ecca32bb07e062f58f0daca06e7009)
1#!/usr/bin/env python3
2# group: rw
3#
4# Test case QMP's encrypted key management
5#
6# Copyright (C) 2019 Red Hat, Inc.
7#
8# This program is free software; you can redistribute it and/or modify

--- 43 unchanged lines hidden (view full) ---

52 def setUp(self):
53 # start the VM
54 self.vm = iotests.VM()
55 self.vm.launch()
56
57 # create the secrets and load 'em into the VM
58 self.secrets = [ Secret(i) for i in range(0, 6) ]
59 for secret in self.secrets:
1#!/usr/bin/env python3
2# group: rw
3#
4# Test case QMP's encrypted key management
5#
6# Copyright (C) 2019 Red Hat, Inc.
7#
8# This program is free software; you can redistribute it and/or modify

--- 43 unchanged lines hidden (view full) ---

52 def setUp(self):
53 # start the VM
54 self.vm = iotests.VM()
55 self.vm.launch()
56
57 # create the secrets and load 'em into the VM
58 self.secrets = [ Secret(i) for i in range(0, 6) ]
59 for secret in self.secrets:
60 result = self.vm.qmp("object-add", **secret.to_qmp_object())
61 self.assert_qmp(result, 'return', {})
60 self.vm.cmd("object-add", **secret.to_qmp_object())
62
63 if iotests.imgfmt == "qcow2":
64 self.pfx = "encrypt."
65 self.img_opts = [ '-o', "encrypt.format=luks" ]
66 else:
67 self.pfx = ""
68 self.img_opts = []
69

--- 27 unchanged lines hidden (view full) ---

97 if iotests.imgfmt == "qcow2":
98 encrypt_options = {
99 'encrypt': {
100 'format':'luks',
101 **encrypt_options
102 }
103 }
104
61
62 if iotests.imgfmt == "qcow2":
63 self.pfx = "encrypt."
64 self.img_opts = [ '-o', "encrypt.format=luks" ]
65 else:
66 self.pfx = ""
67 self.img_opts = []
68

--- 27 unchanged lines hidden (view full) ---

96 if iotests.imgfmt == "qcow2":
97 encrypt_options = {
98 'encrypt': {
99 'format':'luks',
100 **encrypt_options
101 }
102 }
103
105 result = self.vm.qmp('blockdev-add', {
104 self.vm.cmd('blockdev-add', {
106 'driver': iotests.imgfmt,
107 'node-name': id,
108 'read-only': read_only,
109
110 **encrypt_options,
111
112 'file': {
113 'driver': 'file',
114 'filename': test_img,
115 }
116 }
117 )
105 'driver': iotests.imgfmt,
106 'node-name': id,
107 'read-only': read_only,
108
109 **encrypt_options,
110
111 'file': {
112 'driver': 'file',
113 'filename': test_img,
114 }
115 }
116 )
118 self.assert_qmp(result, 'return', {})
119
120 # close the encrypted block device
121 def closeImageQmp(self, id):
117
118 # close the encrypted block device
119 def closeImageQmp(self, id):
122 result = self.vm.qmp('blockdev-del', {'node-name': id})
123 self.assert_qmp(result, 'return', {})
120 self.vm.cmd('blockdev-del', {'node-name': id})
124
125 ###########################################################################
126 # add a key to an encrypted block device
127 def addKeyQmp(self, id, new_secret, secret = None,
128 slot = None, force = False):
129
130 crypt_options = {
131 'state' : 'active',

--- 22 unchanged lines hidden (view full) ---

154 **crypt_options
155 },
156 }
157
158 if force == True:
159 args['force'] = True
160
161 #TODO: check what jobs return
121
122 ###########################################################################
123 # add a key to an encrypted block device
124 def addKeyQmp(self, id, new_secret, secret = None,
125 slot = None, force = False):
126
127 crypt_options = {
128 'state' : 'active',

--- 22 unchanged lines hidden (view full) ---

151 **crypt_options
152 },
153 }
154
155 if force == True:
156 args['force'] = True
157
158 #TODO: check what jobs return
162 result = self.vm.qmp('x-blockdev-amend', **args)
163 assert result['return'] == {}
159 self.vm.cmd('x-blockdev-amend', **args)
164 self.vm.run_job('job_add_key')
165
166 # erase a key from an encrypted block device
167 def eraseKeyQmp(self, id, old_secret = None, slot = None, force = False):
168
169 crypt_options = {
170 'state' : 'inactive',
171 }

--- 16 unchanged lines hidden (view full) ---

188 'driver' : iotests.imgfmt,
189 **crypt_options
190 },
191 }
192
193 if force == True:
194 args['force'] = True
195
160 self.vm.run_job('job_add_key')
161
162 # erase a key from an encrypted block device
163 def eraseKeyQmp(self, id, old_secret = None, slot = None, force = False):
164
165 crypt_options = {
166 'state' : 'inactive',
167 }

--- 16 unchanged lines hidden (view full) ---

184 'driver' : iotests.imgfmt,
185 **crypt_options
186 },
187 }
188
189 if force == True:
190 args['force'] = True
191
196 result = self.vm.qmp('x-blockdev-amend', **args)
197 assert result['return'] == {}
192 self.vm.cmd('x-blockdev-amend', **args)
198 self.vm.run_job('job_erase_key')
199
200 ###########################################################################
201 # create image, and change its key
202 def testChangeKey(self):
203
204 # create the image with secret0 and open it
205 self.createImg(test_img, self.secrets[0]);

--- 75 unchanged lines hidden ---
193 self.vm.run_job('job_erase_key')
194
195 ###########################################################################
196 # create image, and change its key
197 def testChangeKey(self):
198
199 # create the image with secret0 and open it
200 self.createImg(test_img, self.secrets[0]);

--- 75 unchanged lines hidden ---