
    \e-                     $   d dl Z d dlmZ d dlZd dlmZ d dlmZ ej                  Z
 G d dej                        Zej                           G d de      Zej                           G d	 d
ej                        Z G d dej                        Zy)    N)base)
imageutils)mockc                      e Zd Zd ed      fgZd ed      fgZd edd      fd	 ed
d      fd edd      fd edd      fd edd      fd edd      fd edd      fd edd      fd edd      fd edd      fd edd      fgZd  ed d!"      fd# ed$d!"      fd% ed&d!"      fd' ed(d!"      fd) ed)d*"      fd+ ed,d*"      fd- ed-d."      fd edd"      fgZd/ ed01      fd2 ed31      fd4 ed51      fgZd6 ed07      fd8 ed97      fd: ed;7      fgZ	e
d<        Zd= Zd> Zd? Z ej                   d@      dA        Zy0)BImageUtilsHumanRawTestCasedisk_configzdisk.config)
image_namerawfile_format64Mi   )virtual_sizeexp_virtual_size64M_with_byte_hintz64M (67108844 bytes)i64M_byte6710884464_MiB_with_byte_hintz64 MiB (67108844 bytes)z4.4MigfF z4.4M_with_byte_hintz4.4M (4592640 bytes)i F z4.4_MiB_with_byte_hintz4.4 MiB (4592640 bytes)2Ki   2K_with_byte_hintz2K (2048 bytes)2_KiB_with_byte_hintz2 KiB (2048 bytes)z	1e+03_MiBz	1e+03 MiBi  >96Ki  )	disk_sizeexp_disk_size96_KiBz96 KiB96K_byte9830498304_Bz98304 Bz3.1Gl   gf z3.1_GiBz3.1 GiBunavailabler   
no_garbageN)garbage_before_snapshotgarbage_before_snapshot_listFgarbage_after_snapshot_listTno_snapshots)snapshot_countone_snapshots   three_snapshots   c                     t        j                  | j                  | j                  | j                  | j
                  | j                  | j                        | _        y N)	testscenariosmultiply_scenarios_image_name_file_format_virtual_size
_disk_size_garbage_before_snapshot_snapshot_count	scenariosclss    B/usr/lib/python3/dist-packages/oslo_utils/tests/test_imageutils.pygenerate_scenariosz-ImageUtilsHumanRawTestCase.generate_scenarios^   sF    %88OONN((!    c                 v    d| j                   z  d| j                  z  d| j                  z  d| j                  z  fS )Nz	image: %szfile_format: %szvirtual_size: %szdisk_size: %s)r	   r   r   r   )selfs    r6   _initialize_img_infoz/ImageUtilsHumanRawTestCase._initialize_img_infoh   s@    doo-!D$4$44"T%6%66$..02 	2r8   c                 f    |dz   }|dz   }t        | j                        D ]  }|d|dz   z  fz   } |S )N)zSnapshot list:)zHID        TAG                 VM SIZE                DATE       VM CLOCKzP%d        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000r&   )ranger$   )r:   img_infois      r6   _insert_snapshotsz,ImageUtilsHumanRawTestCase._insert_snapshotsn   sa    11 , ,
 t**+ 	>A $2 67U$< #> >H	>
 r8   c                    | j                  |j                  | j                         | j                  |j                  | j                         | j                  |j                  | j
                         | j                  |j                  | j                         | j                  0| j                  t        |j                        | j                         y y r*   )assertEqualimager	   r   r   r   r   r   r$   len	snapshots)r:   
image_infos     r6   _base_validationz+ImageUtilsHumanRawTestCase._base_validation|   s    ))4??;//1A1AB00$2G2GH--t/A/AB*S!5!568K8KL +r8   debtcollector.deprecatec                 l   | j                         }| j                  du r|dz   }| j                  | j                  |      }| j                  du r|dz   }dj	                  |      }t        j                  dt               t        j                  |      }|j                          | j                  |       y )NTzblah BLAH: bbFzjunk stuff: bbb
always)r;   r    r$   r@   joinwarningssimplefilterFutureWarningr   QemuImgInfoassert_calledrG   r:   mock_deprecater>   example_outputrF   s        r6   test_qemu_img_info_human_formatz:ImageUtilsHumanRawTestCase.test_qemu_img_info_human_format   s    ,,.''4/"44H*--h7H''50"66H8,h6++N;
$$&j)r8   )__name__
__module____qualname__dictr-   r.   r/   r0   r1   r2   classmethodr7   r;   r@   rG   r   patchrW    r8   r6   r   r      sm    
67K
 
'(L
 
%&.0 	1	t1G5= ? 	@	Tz+35 	6	 $4M8@#B 	C	6'.0 	1	2H6=!? 	@	!45N9@$B 	C	t%)+ 	,	d0A48: 	;	3G7;"= 	>	d,68 	9+M4 
u#(* 	+	4(&+- 	.	TG(-/ 	0	D9',. 	/	$.0 	1	D9'13 	4	}+,. 	/	d[)35 	6J( 
tD9:	'e)LM	&T(JK  
T23	$a01	D23O ! !2M TZZ)** +*r8   r   c                      e Zd Zd ed      fgZd edd      fgZd ed      fd	 ed
      fgZd ed      fd edd      fd edd      fgZd ed      fd edd      fgZe	d        Z
 ej                  d      d        Zy)ImageUtilsHumanQemuTestCaseqcow2r   65536   )cluster_sizeexp_cluster_sizeno_encryptionN)	encryptedrg   yesno_backing_file)backing_filebacking_file_pathz /var/lib/nova/a328c7998805951a_2)rj   exp_backing_file"backing_file_path_with_actual_pathzA/var/lib/nova/a328c7998805951a_2 (actual path: /b/3a988059e51a_2)z/b/3a988059e51a_2no_backing_file_format)backing_file_formatro   )ro   exp_backing_file_formatc                    t        j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  
      | _        y r*   )r+   r,   r-   r.   r/   r0   r1   r2   _qcow2_cluster_size_qcow2_encrypted_qcow2_backing_file_qcow2_backing_file_formatr3   r4   s    r6   r7   z.ImageUtilsHumanQemuTestCase.generate_scenarios   sj    %88OONN((##  ##**
,r8   rH   c                    | j                         }|d| j                  z  fz   }| j                  2|d| j                  z  fz   }| j                  |d| j                  z  fz   }| j                  |d| j                  z  fz   }| j
                  du r|dz   }| j                  | j                  |      }| j
                  du r|dz   }d	j                  |      }t        j                  d
t               t        j                  |      }|j                          | j                  |       | j!                  |j                  | j"                         | j                  X| j!                  |j                  | j$                         | j                  &| j!                  |j                  | j&                         | j                  '| j!                  |j                  | j                         y y )Nzcluster_size: %szbacking file: %szbacking file format: %szencrypted: %sTrJ   FrK   rL   rM   )r;   rd   rj   ro   rg   r    r$   r@   rN   rO   rP   rQ   r   rR   rS   rG   rB   re   rl   rp   rT   s        r6   rW   z;ImageUtilsHumanQemuTestCase.test_qemu_img_info_human_format   s   ,,.1D4E4EEGG(#5#'#4#4$5 #7 7H''3#'@'+'?'?(@ 'B B>>%?T^^#C"EEH''4/"44H*--h7H''50"66H8,h6++N;
$$&j)00$2G2GH(Z44!224''3  !?!?!%!=!=?>>%Z114>>B &r8   )rX   rY   rZ   r[   r.   rr   rs   rt   ru   r\   r7   r   r]   rW   r^   r8   r6   r`   r`      s    
$7+,L
 
$GeDE
 
$./	dU+, 
Dd34		=A
C	D 
.	 >2
4	5	 
"4D#AB	=D!F 	G" , , TZZ)*C +Cr8   r`   c                       e Zd Zd Zy)ImageUtilsBlankTestCasec                     dj                  g d      }t        j                         }| j                  t	        |      |       | j                  t        |j                        d       y )NrL   )zimage: Nonezfile_format: Nonezvirtual_size: Nonezdisk_size: Nonezcluster_size: Nonezbacking_file: Nonezbacking_file_format: Noner   )rN   r   rR   rB   strrD   rE   )r:   rV   rF   s      r6   test_qemu_img_info_blankz0ImageUtilsBlankTestCase.test_qemu_img_info_blank   sV     $A B
  ++-
Z.9Z112A6r8   N)rX   rY   rZ   r{   r^   r8   r6   rx   rx      s    7r8   rx   c                   l    e Zd Z ej                  d      d        Z ej                  d      d        Zy)ImageUtilsJSONTestCaserH   c                 $   d}t        j                  |d      }|j                          | j                  d|j                         | j                  d|j
                         | j                  d|j                         | j                  d|j                         | j                  d|j                         | j                  d	|j                  d
   d          | j                  d|j                         d}| j                  |t        |             y )Nan  {
                       "virtual-size": 41126400,
                       "filename": "fake_img",
                       "cluster-size": 65536,
                       "format": "qcow2",
                       "actual-size": 13168640,
                       "format-specific": {"data": {"foo": "bar"}},
                       "encrypted": true
                      }jsonformati sfake_imgrc   ra   i  bardatafoorh   z)format_specific: {'data': {'foo': 'bar'}})r   rR   assert_not_calledrB   r   rC   rd   r   r   format_specificrg   assertInrz   )r:   rU   
img_outputrF   expected_strs        r6   test_qemu_img_infoz)ImageUtilsJSONTestCase.test_qemu_img_info   s    
  ++JvF
((*:#:#:;Z%5%56
 7 78*"8"89:#7#78
 : :6 B5 IJ
 4 45BlC
O4r8   c                    d}t        j                  |d      }|j                          | j                  |j                         | j                  |j
                         | j                  |j                         | j                  |j                         | j                  |j                         | j                  |j                         | j                  |j                         y )Nz{}r   r   )r   rR   r   assertIsNoner   rC   rd   r   r   r   rg   )r:   rU   r   rF   s       r6   r{   z/ImageUtilsJSONTestCase.test_qemu_img_info_blank  s    
++JvF
((**112***+*112*001*../*445*../r8   N)rX   rY   rZ   r   r]   r   r{   r^   r8   r6   r}   r}      s@    TZZ)*5 +5. TZZ)*
0 +
0r8   r}   )rO   oslotestr   	test_baser+   
oslo_utilsr   unittestr   load_tests_apply_scenarios
load_testsBaseTestCaser   r7   r`   rx   r}   r^   r8   r6   <module>r      s      &  ! 55
u*!7!7 u*p  - - /MC"< MC`  . . 0	7i44 	7$0Y33 $0r8   