@@ -57,9 +57,12 @@ class ImageCommitTestCase(iotests.QMPTestCase):
57
57
self .assert_no_active_block_jobs ()
58
58
self .vm .shutdown ()
59
59
60
- def run_commit_test (self , top , base , need_ready = False ):
60
+ def run_commit_test (self , top , base , need_ready = False , node_names = False ):
61
61
self .assert_no_active_block_jobs ()
62
- result = self .vm .qmp ('block-commit' , device = 'drive0' , top = top , base = base )
62
+ if node_names :
63
+ result = self .vm .qmp ('block-commit' , device = 'drive0' , top_node = top , base_node = base )
64
+ else :
65
+ result = self .vm .qmp ('block-commit' , device = 'drive0' , top = top , base = base )
63
66
self .assert_qmp (result , 'return' , {})
64
67
self .wait_for_complete (need_ready )
65
68
@@ -101,6 +104,11 @@ class TestSingleDrive(ImageCommitTestCase):
101
104
self .assertEqual (- 1 , qemu_io ('-f' , 'raw' , '-c' , 'read -P 0xab 0 524288' , backing_img ).find ("verification failed" ))
102
105
self .assertEqual (- 1 , qemu_io ('-f' , 'raw' , '-c' , 'read -P 0xef 524288 524288' , backing_img ).find ("verification failed" ))
103
106
107
+ def test_commit_node (self ):
108
+ self .run_commit_test ("mid" , "base" , node_names = True )
109
+ self .assertEqual (- 1 , qemu_io ('-f' , 'raw' , '-c' , 'read -P 0xab 0 524288' , backing_img ).find ("verification failed" ))
110
+ self .assertEqual (- 1 , qemu_io ('-f' , 'raw' , '-c' , 'read -P 0xef 524288 524288' , backing_img ).find ("verification failed" ))
111
+
104
112
def test_device_not_found (self ):
105
113
result = self .vm .qmp ('block-commit' , device = 'nonexistent' , top = '%s' % mid_img )
106
114
self .assert_qmp (result , 'error/class' , 'DeviceNotFound' )
@@ -123,6 +131,30 @@ class TestSingleDrive(ImageCommitTestCase):
123
131
self .assert_qmp (result , 'error/class' , 'GenericError' )
124
132
self .assert_qmp (result , 'error/desc' , 'Base \' badfile\' not found' )
125
133
134
+ def test_top_node_invalid (self ):
135
+ self .assert_no_active_block_jobs ()
136
+ result = self .vm .qmp ('block-commit' , device = 'drive0' , top_node = 'badfile' , base_node = 'base' )
137
+ self .assert_qmp (result , 'error/class' , 'GenericError' )
138
+ self .assert_qmp (result , 'error/desc' , "Cannot find device= nor node_name=badfile" )
139
+
140
+ def test_base_node_invalid (self ):
141
+ self .assert_no_active_block_jobs ()
142
+ result = self .vm .qmp ('block-commit' , device = 'drive0' , top_node = 'mid' , base_node = 'badfile' )
143
+ self .assert_qmp (result , 'error/class' , 'GenericError' )
144
+ self .assert_qmp (result , 'error/desc' , "Cannot find device= nor node_name=badfile" )
145
+
146
+ def test_top_path_and_node (self ):
147
+ self .assert_no_active_block_jobs ()
148
+ result = self .vm .qmp ('block-commit' , device = 'drive0' , top_node = 'mid' , base_node = 'base' , top = '%s' % mid_img )
149
+ self .assert_qmp (result , 'error/class' , 'GenericError' )
150
+ self .assert_qmp (result , 'error/desc' , "'top-node' and 'top' are mutually exclusive" )
151
+
152
+ def test_base_path_and_node (self ):
153
+ self .assert_no_active_block_jobs ()
154
+ result = self .vm .qmp ('block-commit' , device = 'drive0' , top_node = 'mid' , base_node = 'base' , base = '%s' % backing_img )
155
+ self .assert_qmp (result , 'error/class' , 'GenericError' )
156
+ self .assert_qmp (result , 'error/desc' , "'base-node' and 'base' are mutually exclusive" )
157
+
126
158
def test_top_is_active (self ):
127
159
self .run_commit_test (test_img , backing_img , need_ready = True )
128
160
self .assertEqual (- 1 , qemu_io ('-f' , 'raw' , '-c' , 'read -P 0xab 0 524288' , backing_img ).find ("verification failed" ))
@@ -139,6 +171,22 @@ class TestSingleDrive(ImageCommitTestCase):
139
171
self .assert_qmp (result , 'error/class' , 'GenericError' )
140
172
self .assert_qmp (result , 'error/desc' , 'Base \' %s\' not found' % mid_img )
141
173
174
+ def test_top_and_base_node_reversed (self ):
175
+ self .assert_no_active_block_jobs ()
176
+ result = self .vm .qmp ('block-commit' , device = 'drive0' , top_node = 'base' , base_node = 'top' )
177
+ self .assert_qmp (result , 'error/class' , 'GenericError' )
178
+ self .assert_qmp (result , 'error/desc' , "'top' is not in this backing file chain" )
179
+
180
+ def test_top_node_in_wrong_chain (self ):
181
+ self .assert_no_active_block_jobs ()
182
+
183
+ result = self .vm .qmp ('blockdev-add' , driver = 'null-co' , node_name = 'null' )
184
+ self .assert_qmp (result , 'return' , {})
185
+
186
+ result = self .vm .qmp ('block-commit' , device = 'drive0' , top_node = 'null' , base_node = 'base' )
187
+ self .assert_qmp (result , 'error/class' , 'GenericError' )
188
+ self .assert_qmp (result , 'error/desc' , "'null' is not in this backing file chain" )
189
+
142
190
# When the job is running on a BB that is automatically deleted on hot
143
191
# unplug, the job is cancelled when the device disappears
144
192
def test_hot_unplug (self ):
0 commit comments