
    HgS                     P   d dl Z d dlmZ d dlmZmZ d dlmZmZm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZmZ  G d	 d
e          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d d          ZdS )    N)_MatchInvalid)DevicesDevice)DriveGroupSpecDeviceSelectionDriveGroupValidationError)drive_selection)PlacementSpec)InventoryFactory)_mk_inventory
_mk_devicec                       e Zd ZdZd Zd ZdS )TestMatcherz Test Matcher base class
    c                     t          dddi          }t          j        dd                              |          }||j                            d          u sJ dS )z_
        virtual is False
        key is found
        retrun value of key is expected
        /dev/vdbfoobarpathsys_apiN)r   r	   Matcher_get_disk_keyr   get)selfdisk_maprets      ?/usr/lib/python3/dist-packages/ceph/tests/test_disk_selector.pytest_get_disk_key_3zTestMatcher.test_get_disk_key_3   sb     zE5>BBB%eU33AA(KKh&**511111111    c                    t          d          }t          j        t                    5  t	          j        dd                              |           t          j        d           ddd           dS # 1 swxY w Y   dS )zZ
        virtual is False
        key is not found
        expect raise Exception
        r   r   r   r   z!No disk_key found for foo or NoneN)r   pytestraises	Exceptionr	   r   r   fail)r   r   s     r   test_get_disk_key_4zTestMatcher.test_get_disk_key_4   s     z***]9%% 	= 	=#E511??IIIK;<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=s   =A44A8;A8N)__name__
__module____qualname____doc__r   r&    r   r   r   r      s<         2 2 2	= 	= 	= 	= 	=r   r   c                       e Zd Zd Zd ZdS )TestSubstringMatcherc                     t          dt          d                    }t          j        dd          }|                    |          }|du sJ d S )Nr   samsungmodelr   r1   Tr   dictr	   SubstringMatchercomparer   	disk_dictmatcherr   s       r   test_comparez!TestSubstringMatcher.test_compare+   sS    
Dy4I4I4IJJJ	!27IFFooi((d{{{{{{r   c                     t          dt          d                    }t          j        dd          }|                    |          }|du sJ d S )Nr   nothing_matchingr0   r   r1   r/   Fr2   r6   s       r   test_compare_falsez'TestSubstringMatcher.test_compare_false1   sT    
D?Q4R4R4RSSS	!27IFFooi((e||||||r   Nr'   r(   r)   r9   r<   r+   r   r   r-   r-   *   2              r   r-   c                       e Zd Zd Zd ZdS )TestEqualityMatcherc                     t          dt          d                    }t          j        dd          }|                    |          }|du sJ d S )Nr   1rotatesr   rD   Tr   r3   r	   EqualityMatcherr5   r6   s       r   r9   z TestEqualityMatcher.test_compare9   sS    
D4E4E4EFFF	!1)SAAooi((d{{{{{{r   c                     t          dt          d                    }t          j        dd          }|                    |          }|du sJ d S )Nr   rB   rC   r   rD   0FrE   r6   s       r   r<   z&TestEqualityMatcher.test_compare_false?   sS    
D4E4E4EFFF	!1)SAAooi((e||||||r   Nr=   r+   r   r   r@   r@   8   r>   r   r@   c                       e Zd Zd Zd ZdS )TestAllMatcherc                     t          d          }t          j        dd          }|                    |          }|du sJ d S )Nr   r!   allTrueTr   r	   
AllMatcherr5   r6   s       r   r9   zTestAllMatcher.test_compareG   sF    
+++	!,UF;;ooi((d{{{{{{r   c                     t          d          }t          j        dd          }|                    |          }|du sJ d S )Nr   r!   rL   FalseTrN   r6   s       r   test_compare_value_not_truez*TestAllMatcher.test_compare_value_not_trueM   sF    
+++	!,UG<<ooi((d{{{{{{r   N)r'   r(   r)   r9   rR   r+   r   r   rJ   rJ   F   s2              r   rJ   c                   v   e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                            dg d          d             Zej                            dg d          d             Zej                            dg d          d             Zej                            dg d          d             Zd Zej                            dg d          d             Zej                            dg d          d             Zej                            dg d          d             Zd ZdS )TestSizeMatcherc                     t          j        dd          }t          |j        t                    sJ |j        d         dk    sJ |j        d         dk    sJ dS )! Testing exact notation with 20G size20Gr   20   GBNr	   SizeMatcher
isinstanceexacttupler   r8   s     r   test_parse_filter_exactz'TestSizeMatcher.test_parse_filter_exactU   sb    !-fe<<'-/////}Q4''''}Q4''''''r   c                     t          j        dd          }t          |j        t                    sJ |j        d         dk    sJ |j        d         dk    sJ dS )rV   rW   20GBr   rY   rZ   r[   Nr\   ra   s     r   test_parse_filter_exact_GB_Gz,TestSizeMatcher.test_parse_filter_exact_GB_G\   sb    !-ff=='-/////}Q4''''}Q4''''''r   c                     t          j        dd          }t          |j        t                    sJ |j        d         dk    sJ |j        d         dk    sJ |j        d         dk    sJ |j        d         dk    sJ dS )	z( Testing high-low notation with 20G:50G rW   z20G:50Gr   rY   50rZ   r[   N)r	   r]   r^   r_   r`   lowhighra   s     r   test_parse_filter_high_lowz*TestSizeMatcher.test_parse_filter_high_lowc   s     "-fi@@'-/////{1~%%%%|A$&&&&{1~%%%%|A$&&&&&&r   c                     t          j        dd          }t          |j        t                    sJ |j        d         dk    sJ |j        d         dk    sJ dS )z! Testing high notation with :50G rW   z:50Gr   rg   rZ   r[   N)r	   r]   r^   r_   r`   ri   ra   s     r   test_parse_filter_max_highz*TestSizeMatcher.test_parse_filter_max_highm   sb     "-ff=='-/////|A$&&&&|A$&&&&&&r   c                     t          j        dd          }t          |j        t                    sJ |j        d         dk    sJ |j        d         dk    sJ dS )z  Testing low notation with 20G: rW   z50G:r   rg   rZ   r[   N)r	   r]   r^   r_   r`   rh   ra   s     r   test_parse_filter_min_lowz)TestSizeMatcher.test_parse_filter_min_lowu   sb     "-ff=='-/////{1~%%%%{1~%%%%%%r   c                 f    t          j        dd                              d          }|dk    sJ dS )z8 I doubt anyone ever thought we'd need to understand KB rW   4K)4KBg     @@Nr	   r]   to_byter   r   s     r   test_to_byte_KBzTestSizeMatcher.test_to_byte_KB}   s5     )&$77??LLhr   c                 f    t          j        dd                              d          }|dk    sJ dS ) Pretty nonesense test..rW   10G10r[   g    _BNrs   ru   s     r   test_to_byte_GBzTestSizeMatcher.test_to_byte_GB   ;     )&%88@@NNir   c                 f    t          j        dd                              d          }|dk    sJ dS )rx   rW   10M)r{   MBg    cANrs   ru   s     r   test_to_byte_MBzTestSizeMatcher.test_to_byte_MB   r}   r   c                 f    t          j        dd                              d          }|dk    sJ dS )rx   rW   10T)r{   TBg  @0BNrs   ru   s     r   test_to_byte_TBzTestSizeMatcher.test_to_byte_TB   s;     )&%88@@NNj      r   c                     t          j        t                    5  t          j        dd                              d           ddd           n# 1 swxY w Y   dS )z Expect to raise rW   10P)r{   PBN)r"   r#   r   r	   r]   rt   r   s    r   test_to_byte_PBzTestSizeMatcher.test_to_byte_PB   s     ]=)) 	M 	M'66>>|LLL	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M,,s   )AAAc                     t          j        dd          }t          dt          d                    }|                    |          }|du sJ d S )NrW   rd   r   20.00 GBrW   r   Tr	   r]   r   r3   r5   r   r8   r7   r   s       r   test_compare_exactz"TestSizeMatcher.test_compare_exact   sS    !-ff==
Dj4I4I4IJJJ	ooi((d{{{{{{r   c                     t          j        dd          }t          dt          d                    }|                    |          }|du sJ d S )NrW   z20.12GBr   z20.12 GBr   r   Tr   r   s       r   test_compare_exact_decimalz*TestSizeMatcher.test_compare_exact_decimal   sS    !-fi@@
Dj4I4I4IJJJ	ooi((d{{{{{{r   ztest_input,expected)1.00 GBFr   T50.00 GBT	100.00 GBT	101.00 GBF
1101.00 GBFc                     t          j        dd          }t          dt          |                    }|                    |          }||u sJ d S )NrW   z
20GB:100GBr   r   r   r   r   
test_inputexpectedr8   r7   r   s         r   test_compare_high_lowz%TestSizeMatcher.test_compare_high_low   sU     "-flCC
Dj4I4I4IJJJ	ooi((hr   ))r   Tr   r   r   Fr   r   c                     t          j        dd          }t          dt          |                    }|                    |          }||u sJ d S )NrW   z:50GBr   r   r   r   r   s         r   test_compare_highz!TestSizeMatcher.test_compare_high   U     "-fg>>
Dj4I4I4IJJJ	ooi((hr   )r   r   Fr   r   )r   Tr   Tc                     t          j        dd          }t          dt          |                    }|                    |          }||u sJ d S )NrW   z50GB:r   r   r   r   r   s         r   test_compare_lowz TestSizeMatcher.test_compare_low   r   r   )r   r   )r   Fr   r   r   )z9.10 TBTc                     t          j        dd          }t          dt          |                    }|                    |          }||u sJ d S )NrW   z1TB:z/dev/sdzr   r   r   r   s         r   test_compare_at_least_1TBz)TestSizeMatcher.test_compare_at_least_1TB   sU     "-ff==
Dj4I4I4IJJJ	ooi((hr   c                 $   t          j        dd          }t          dt          d                    }t	          j        t                    5  |                    |           t	          j        d           d d d            d S # 1 swxY w Y   d S )NrW   Noner   r   r   r   zCouldn't parse size)	r	   r]   r   r3   r"   r#   r$   r5   r%   )r   r8   r7   s      r   test_compare_raisez"TestSizeMatcher.test_compare_raise   s    !-ff==
Dj4I4I4IJJJ	]9%% 	/ 	/OOI&&&K-...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   *BB	B	))ry   rz   )rd   rY   r[   )10grz   )20gbr   c                 b    t          j        dd                              |          |k    sJ d S NrW   ry   )r	   r]   _get_k_vr   r   r   s      r   test_get_k_vzTestSizeMatcher.test_get_k_v   s7     *6599BB:NNRZZZZZZZr   ))ry   r[   )r   r[   )rd   r[   )r   r[   )20TBr   )20tbr   )20Tr   )20tr   )20MBr   )20mbr   )20Mr   )20mr   c                 b    t          j        dd                              |          |k    sJ d S r   )r	   r]   _parse_suffixr   s      r   test_parse_suffixz!TestSizeMatcher.test_parse_suffix   s7     *6599GG
SSW_______r   ))Gr[   )r[   r[   )r   r   )Tr   )r   r   )Mr   c                 b    t          j        dd                              |          |k    sJ d S )Nry   rW   )r	   r]   _normalize_suffixr   s      r   test_normalize_suffixz%TestSizeMatcher.test_normalize_suffix	  s7     *5&99KKJWW[cccccccr   c                     t          j        t                    5  t          j        dd                              d           t          j        d           d d d            d S # 1 swxY w Y   d S )Nr   rW   PzUnit 'P' not supported)r"   r#   r   r	   r]   r   r%   r   s    r   test_normalize_suffix_raisesz,TestSizeMatcher.test_normalize_suffix_raises  s    ]=)) 	2 	2'v66HHMMMK0111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s   =A$$A(+A(N)r'   r(   r)   rb   re   rj   rl   rn   rv   r|   r   r   r   r   r   r"   markparametrizer   r   r   r   r   r   r   r   r   r+   r   r   rT   rT   T   s       ( ( (( ( (' ' '' ' '& & &            ! ! !- - -     [2 5 5 5     [2 5 5 5     [2 5 5 5     [2 5 5 5    / / / [2 5 5 5  [ [ [ [2 5 5 5  ` ` ` [2 5 5 5  d d d2 2 2 2 2r   rT   c                       e Zd Z ej        d          dd            Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zej        dd            ZdS )TestDriveGroupclass)scopeNc                     |dddddfd}|S )Nr    	bluestorec                     ddddiddd|dd	|d
d|ddddd||dd}ddddidddd|dddid|dd	}|dk    r|}n|}| rddddiddid}t          j        |          }	|	S )Nosdr   host_patternzdata*30G:50G42-RGBr/   )rW   r1   vendorlimitfastr1   r   :20GrW   r      5Gry   T)service_type
service_id	placementdata_deviceswal_devices
db_devicesdb_slots	wal_slotsblock_wal_sizeblock_db_sizeobjectstoreosds_per_device	encrypted	filestore1xrW   )	r   r   r   r   r   journal_devicesjournal_sizer   r   rL   )r   r   r   r   )r   	from_json)
empty
data_limit	wal_limitdb_limitr   disk_formatraw_sample_bluestoreraw_sample_filestore
raw_sampledgos
             r   make_sample_dataz1TestDriveGroup.test_fix.<locals>.make_sample_data  s    !&#,g6%%''	! ! $&   
 #%  "&!&*#2!1$ $ 6 !&#,g6*%""'	! ! F$ !%#2!!$ $ $ k))1

1
 $)"'"0'!:t%	 
 !*:66CJr   r+   )r   r   r   s      r   test_fixzTestDriveGroup.test_fix  s5    #(()'(&'-/)4B	 B	 B	 B	H  r   c                 0     |            }|j         du sJ d S )NTr   r   r   s     r   test_encryption_propz#TestDriveGroup.test_encryption_prope  s'    8::!T))))))r   c                 4     |d          }|j         du sJ d S )NTr   Fr   r  s     r   test_encryption_prop_emptyz)TestDriveGroup.test_encryption_prop_emptyi  s.    8$'''!U******r   c                 4     |            }|j         dk    sJ d S Nr   r   r  s     r   test_db_slots_propz!TestDriveGroup.test_db_slots_propm  s'    8:: A%%%%%%r   c                 0     |d          }|j         J d S NTr  r  r  s     r   test_db_slots_prop_emptyz'TestDriveGroup.test_db_slots_prop_emptyq  s)    8$''' (((((r   c                 4     |            }|j         dk    sJ d S r  r   r  s     r   test_wal_slots_propz"TestDriveGroup.test_wal_slots_propu  s'    8::!Q&&&&&&r   c                 0     |d          }|j         J d S r  r  r  s     r   test_wal_slots_prop_emptyz(TestDriveGroup.test_wal_slots_prop_emptyy  s)    8$'''!)))))r   c                 4     |            }|j         dk    sJ d S )Nr   r   r  s     r   test_block_wal_size_propz'TestDriveGroup.test_block_wal_size_prop}  s'    8::&$......r   c                 0     |d          }|j         J d S r  r  r  s     r   test_block_wal_size_prop_emptyz-TestDriveGroup.test_block_wal_size_prop_empty  s)    8$'''&.....r   c                 4     |            }|j         dk    sJ d S )Nry   r   r  s     r   test_block_db_size_propz&TestDriveGroup.test_block_db_size_prop  s'    8::%......r   c                 0     |d          }|j         J d S r  r  r  s     r   test_block_db_size_prop_emptyz,TestDriveGroup.test_block_db_size_prop_empty  s)    8$'''%-----r   c                 V     |            }|j         t          dddd          k    sJ d S )Nr   r   r/   r   )r1   rW   r   r   )r   r   r  s     r   test_data_devices_propz%TestDriveGroup.test_data_devices_prop  sN    8::$	)
 )
 )
 
 
 
 
 
 
r   c                 0     |d          }|j         J d S r  r   r  s     r   test_data_devices_prop_emptyz+TestDriveGroup.test_data_devices_prop_empty  )    8$'''"*****r   c                 R     |            }|j         t          dd          k    sJ d S )Nr   r   r   )r   r   r  s     r   test_db_devices_propz#TestDriveGroup.test_db_devices_prop  sH    8::"o'
 '
 '
 
 
 
 
 
 
r   c                 0     |d          }|j         J d S r  r  r  s     r   test_db_devices_prop_emptyz)TestDriveGroup.test_db_devices_prop_empty  r!  r   c                 R     |            }|j         t          dd          k    sJ d S )Nr   r   r   )r   r   r  s     r   test_wal_device_propz#TestDriveGroup.test_wal_device_prop  sH    8::#(
 (
 (
 
 
 
 
 
 
r   c                 0     |d          }|j         J d S r  )r   r  s     r   test_wal_device_prop_emptyz)TestDriveGroup.test_wal_device_prop_empty  s)    8$'''#+++++r   c                 8     |d          }|j         dk    sJ d S )Nr   )r   r   r  s     r   test_bluestore_format_propz)TestDriveGroup.test_bluestore_format_prop  s.    8444#{222222r   c                 8     |d          }|j         dk    sJ d S )NTr  r   r+  r  s     r   test_default_format_propz'TestDriveGroup.test_default_format_prop  s.    8$'''#{222222r   c                 8     |d          }|j         dk    sJ d S )N3r   r1  r  s     r   test_osds_per_devicez#TestDriveGroup.test_osds_per_device  s.    8C000'3......r   c                 4     |            }|j         dk    sJ d S )Nr   r1  r  s     r   test_osds_per_device_defaultz+TestDriveGroup.test_osds_per_device_default  s'    8::'2------r   c                 0     |d          }|j         J d S r  )r   r  s     r   test_journal_size_emptyz&TestDriveGroup.test_journal_size_empty  s)    8$'''$,,,,,r   Tc                     |dddddddfd}|S )N
   r      r   r   l       c                 ^   t                      }g }	|                    || ||          }
|                    ||dd||           }|                    ||d|d|           }|	                    |
           |	                    |           |	                    |           t          |	          S )N)pieces	availablerW   human_readable_sizerH   ssd_type_model)r;  r=  
rotationalr1   rW   r<  )r;  r=  r?  rW   r1   r<  )devices)r   produceextendr   )r<  r   r   r   human_readable_size_datahuman_readable_size_walrW   human_readable_size_dbfactoryinventory_sample
data_disks	wal_disksdb_diskss                r   r   z2TestDriveGroup.inventory.<locals>.make_sample_data  s     '((G! ##$<	 ) > >J
  "$;&# ( % %I !$:&# ' % %H ##J///##I...##H---#34444r   r+   )r   r<  r   s      r   	inventoryzTestDriveGroup.inventory  s7    '0*,)*()6@5?",4>!	5 !	5 !	5 !	5F  r   )N)T)r'   r(   r)   r"   fixturer   r  r  r	  r  r  r  r  r  r  r  r  r   r#  r%  r'  r)  r,  r.  r2  r4  r6  rK  r+   r   r   r   r     s       V^'"""E  E  E  #"E N* * *+ + +& & &) ) )' ' '* * */ / // / // / /. . .
 
 
+ + +
 
 
+ + +
 
 
, , ,3 3 33 3 3/ / /. . .- - - ^$  $  $  ^$  $  $ r   r   c                   H   e Zd Z e ed          d ed                     e e            dz            g dg f e ed          d edd	
           ed                     e e            dz            g dddgf e ed          d ed           ed                     e ed           ed          z             dgdgf e ed          d ed           ed                     e ed          dz   ed          z             ddgdgf e ed          d ed           ed                     e ed          dz            ddgg fgZe	j
                            de          d             Zd ZdS )TestDriveSelection*r   foobarT)rL   r   r   r   r   )/dev/sda/dev/sdb/dev/sdc/dev/sdd/dev/sde   rL   r   )r   r   r   r   )rS  rT  rU  rV  rW  r?  FrT  rS  r9  rU  z(spec,inventory,expected_data,expected_dbc                     t          j        ||          }d |                                D             |k    sJ d |                                D             |k    sJ d S )Nc                     g | ]	}|j         
S r+   r!   .0ds     r   
<listcomp>z:TestDriveSelection.test_disk_selection.<locals>.<listcomp>$  s    3331333r   c                     g | ]	}|j         
S r+   r!   r]  s     r   r`  z:TestDriveSelection.test_disk_selection.<locals>.<listcomp>%  s    1111111r   )r	   DriveSelectionr   r   )r   specrK  expected_dataexpected_dbsels         r   test_disk_selectionz&TestDriveSelection.test_disk_selection!  sn    ,T9==33 0 0 2 2333}DDDD11 0 0111[@@@@@@r   c                 8   t          t          d          dt          d                    }t          t	          d          d	z            }d
}t          j        t          |          5  t          j	        ||           d d d            d S # 1 swxY w Y   d S )NrO  rP  rQ  wrongr   rR  TrZ  r9  zEFailed to validate OSD spec "foobar.data_devices": No filters applied)match)
r   r
   r   r   r   r"   r#   r   r	   rb  )r   rc  rK  ms       r   test_disk_selection_raisez,TestDriveSelection.test_disk_selection_raise'  s    'S999#,':::  
 "*"="="=a"?@@	S]4A>>> 	< 	<*4;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   ,BBBN)r'   r(   r)   r   r
   r   r   r   testdatar"   r   r   rg  rl  r+   r   r   rN  rN    s        N'-S999#,_6668 8 8 M**,,*++HHH"	
 N'-S999#,_Q???*?t444	   M**,,*++000:z2J		
 N'-S999#,_===*?e<<<	   M**666t9T9T9TTUUL:,		
 N'-S999#,_===*?e<<<	   M**555a7**PU:V:V:VVWW$zl		
 N'-S999#,_===*?e<<<	   M**555a788$b		
O1Hf [GRRA A SRA
	< 	< 	< 	< 	<r   rN  c                       e Zd Zd ZdS )TestDeviceSelectionLimitc                    t          ddd          }t          ddd          }t          ddd          }|||g}g }t          dd          }t          |	          }t          j        ||d
          }|                    ||d          rJ |                    |           |                    ||d          rJ |                    |           |                    ||d          sJ |j        ||gk    sJ d S )NrS  TF)ceph_devicer<  rT  rU  r9  rY  )r   rZ   )existing_daemons)r   r   r   r	   rb  _limit_reachedappend_data)	r   dev_adev_bdev_call_devicesprocessed_devicesfilterdgsdss	            r   test_limit_existing_devicesz4TestDeviceSelectionLimit.test_limit_existing_devices5  s5    ztuEEEzuEEEzuEEE%*E5$9*, T333&111+CqQQQ
 $$V->
KKKKK  ''' $$V->
KKKKK  '''   ):JGGGGG xE5>))))))r   N)r'   r(   r)   r~  r+   r   r   ro  ro  3  s#        "* "* "* "* "*r   ro  )r"   (ceph.deployment.drive_selection.matchersr   ceph.deployment.inventoryr   r   ceph.deployment.drive_groupr   r   r   ceph.deploymentr	   ceph.deployment.service_specr
   ceph.tests.factoriesr   ceph.tests.utilsr   r   objectr   r-   r@   rJ   rT   r   rN  ro  r+   r   r   <module>r     s-    B B B B B B 5 5 5 5 5 5 5 5" " " " " " " " " " , + + + + + 6 6 6 6 6 6 1 1 1 1 1 1 6 6 6 6 6 6 6 6= = = = =& = = =4    6       &       V   E2 E2 E2 E2 E2f E2 E2 E2PM  M  M  M  M V M  M  M `D< D< D< D< D< D< D< D<N$* $* $* $* $* $* $* $* $* $*r   