@@ -1636,191 +1636,7 @@ def setUp(self):
1636
1636
lambda * args , ** kwargs : mock .MagicMock ()))
1637
1637
1638
1638
1639
- class CinderFixture (fixtures .Fixture ):
1640
- """A fixture to volume operations"""
1641
-
1642
- # the default project_id in OSAPIFixtures
1643
- tenant_id = '6f70656e737461636b20342065766572'
1644
-
1645
- SWAP_OLD_VOL = 'a07f71dc-8151-4e7d-a0cc-cd24a3f11113'
1646
- SWAP_NEW_VOL = '227cc671-f30b-4488-96fd-7d0bf13648d8'
1647
- SWAP_ERR_OLD_VOL = '828419fa-3efb-4533-b458-4267ca5fe9b1'
1648
- SWAP_ERR_NEW_VOL = '9c6d9c2d-7a8f-4c80-938d-3bf062b8d489'
1649
-
1650
- # This represents a bootable image-backed volume to test
1651
- # boot-from-volume scenarios.
1652
- IMAGE_BACKED_VOL = '6ca404f3-d844-4169-bb96-bc792f37de98'
1653
-
1654
- def __init__ (self , test ):
1655
- super (CinderFixture , self ).__init__ ()
1656
- self .test = test
1657
- self .swap_volume_instance_uuid = None
1658
- self .swap_volume_instance_error_uuid = None
1659
- self .reserved_volumes = list ()
1660
- # This is a map of instance UUIDs mapped to a list of volume IDs.
1661
- # This map gets updated on attach/detach operations.
1662
- self .attachments = collections .defaultdict (list )
1663
-
1664
- def volume_ids_for_instance (self , instance_uuid ):
1665
- return self .attachments .get (instance_uuid )
1666
-
1667
- def setUp (self ):
1668
- super (CinderFixture , self ).setUp ()
1669
-
1670
- def fake_get (self_api , context , volume_id , microversion = None ):
1671
- # Check for the special swap volumes.
1672
- if volume_id in (CinderFixture .SWAP_OLD_VOL ,
1673
- CinderFixture .SWAP_ERR_OLD_VOL ):
1674
- volume = {
1675
- 'status' : 'available' ,
1676
- 'display_name' : 'TEST1' ,
1677
- 'attach_status' : 'detached' ,
1678
- 'id' : volume_id ,
1679
- 'multiattach' : False ,
1680
- 'size' : 1
1681
- }
1682
- if ((self .swap_volume_instance_uuid and
1683
- volume_id == CinderFixture .SWAP_OLD_VOL ) or
1684
- (self .swap_volume_instance_error_uuid and
1685
- volume_id == CinderFixture .SWAP_ERR_OLD_VOL )):
1686
- instance_uuid = (self .swap_volume_instance_uuid
1687
- if volume_id == CinderFixture .SWAP_OLD_VOL
1688
- else self .swap_volume_instance_error_uuid )
1689
-
1690
- volume .update ({
1691
- 'status' : 'in-use' ,
1692
- 'attachments' : {
1693
- instance_uuid : {
1694
- 'mountpoint' : '/dev/vdb' ,
1695
- 'attachment_id' : volume_id
1696
- }
1697
- },
1698
- 'attach_status' : 'attached'
1699
- })
1700
- return volume
1701
-
1702
- # Check to see if the volume is attached.
1703
- for instance_uuid , volumes in self .attachments .items ():
1704
- if volume_id in volumes :
1705
- # The volume is attached.
1706
- volume = {
1707
- 'status' : 'in-use' ,
1708
- 'display_name' : volume_id ,
1709
- 'attach_status' : 'attached' ,
1710
- 'id' : volume_id ,
1711
- 'multiattach' : False ,
1712
- 'size' : 1 ,
1713
- 'attachments' : {
1714
- instance_uuid : {
1715
- 'attachment_id' : volume_id ,
1716
- 'mountpoint' : '/dev/vdb'
1717
- }
1718
- }
1719
- }
1720
- break
1721
- else :
1722
- # This is a test that does not care about the actual details.
1723
- reserved_volume = (volume_id in self .reserved_volumes )
1724
- volume = {
1725
- 'status' : 'attaching' if reserved_volume else 'available' ,
1726
- 'display_name' : 'TEST2' ,
1727
- 'attach_status' : 'detached' ,
1728
- 'id' : volume_id ,
1729
- 'multiattach' : False ,
1730
- 'size' : 1
1731
- }
1732
-
1733
- # Check for our special image-backed volume.
1734
- if volume_id == self .IMAGE_BACKED_VOL :
1735
- # Make it a bootable volume.
1736
- volume ['bootable' ] = True
1737
- # Add the image_id metadata.
1738
- volume ['volume_image_metadata' ] = {
1739
- # There would normally be more image metadata in here...
1740
- 'image_id' : '155d900f-4e14-4e4c-a73d-069cbf4541e6'
1741
- }
1742
-
1743
- return volume
1744
-
1745
- def fake_initialize_connection (self , context , volume_id , connector ):
1746
- if volume_id == CinderFixture .SWAP_ERR_NEW_VOL :
1747
- # Return a tuple in order to raise an exception.
1748
- return ()
1749
- return {}
1750
-
1751
- def fake_migrate_volume_completion (self , context , old_volume_id ,
1752
- new_volume_id , error ):
1753
- return {'save_volume_id' : new_volume_id }
1754
-
1755
- def fake_reserve_volume (self_api , context , volume_id ):
1756
- self .reserved_volumes .append (volume_id )
1757
-
1758
- def fake_unreserve_volume (self_api , context , volume_id ):
1759
- # NOTE(mnaser): It's possible that we unreserve a volume that was
1760
- # never reserved (ex: instance.volume_attach.error
1761
- # notification tests)
1762
- if volume_id in self .reserved_volumes :
1763
- self .reserved_volumes .remove (volume_id )
1764
-
1765
- def fake_attach (_self , context , volume_id , instance_uuid ,
1766
- mountpoint , mode = 'rw' ):
1767
- # Check to see if the volume is already attached to any server.
1768
- for instance , volumes in self .attachments .items ():
1769
- if volume_id in volumes :
1770
- raise exception .InvalidInput (
1771
- reason = 'Volume %s is already attached to '
1772
- 'instance %s' % (volume_id , instance ))
1773
- # It's not attached so let's "attach" it.
1774
- self .attachments [instance_uuid ].append (volume_id )
1775
-
1776
- self .test .stub_out ('nova.volume.cinder.API.attach' ,
1777
- fake_attach )
1778
-
1779
- def fake_detach (_self , context , volume_id , instance_uuid = None ,
1780
- attachment_id = None ):
1781
- # NOTE(mnaser): It's possible that we unreserve a volume that was
1782
- # never reserved (ex: instance.volume_attach.error
1783
- # notification tests)
1784
- if volume_id in self .reserved_volumes :
1785
- self .reserved_volumes .remove (volume_id )
1786
-
1787
- if instance_uuid is not None :
1788
- # If the volume isn't attached to this instance it will
1789
- # result in a ValueError which indicates a broken test or
1790
- # code, so we just let that raise up.
1791
- self .attachments [instance_uuid ].remove (volume_id )
1792
- else :
1793
- for instance , volumes in self .attachments .items ():
1794
- if volume_id in volumes :
1795
- volumes .remove (volume_id )
1796
- break
1797
-
1798
- self .test .stub_out ('nova.volume.cinder.API.detach' , fake_detach )
1799
-
1800
- self .test .stub_out ('nova.volume.cinder.API.begin_detaching' ,
1801
- lambda * args , ** kwargs : None )
1802
- self .test .stub_out ('nova.volume.cinder.API.get' ,
1803
- fake_get )
1804
- self .test .stub_out ('nova.volume.cinder.API.initialize_connection' ,
1805
- fake_initialize_connection )
1806
- self .test .stub_out (
1807
- 'nova.volume.cinder.API.migrate_volume_completion' ,
1808
- fake_migrate_volume_completion )
1809
- self .test .stub_out ('nova.volume.cinder.API.reserve_volume' ,
1810
- fake_reserve_volume )
1811
- self .test .stub_out ('nova.volume.cinder.API.roll_detaching' ,
1812
- lambda * args , ** kwargs : None )
1813
- self .test .stub_out ('nova.volume.cinder.API.terminate_connection' ,
1814
- lambda * args , ** kwargs : None )
1815
- self .test .stub_out ('nova.volume.cinder.API.unreserve_volume' ,
1816
- fake_unreserve_volume )
1817
- self .test .stub_out ('nova.volume.cinder.API.check_attached' ,
1818
- lambda * args , ** kwargs : None )
1819
-
1820
-
1821
- # TODO(mriedem): We can probably pull some of the common parts from the
1822
- # CinderFixture into a common mixin class for things like the variables
1823
- # and fake_get.
1639
+ # TODO(mriedem): Just rename this to be CinderFixture.
1824
1640
class CinderFixtureNewAttachFlow (fixtures .Fixture ):
1825
1641
"""A fixture to volume operations with the new Cinder attach/detach API"""
1826
1642
@@ -1874,8 +1690,8 @@ def fake_get(self_api, context, volume_id, microversion=None):
1874
1690
# Check for the special swap volumes.
1875
1691
attachments = self .volume_to_attachment [volume_id ]
1876
1692
1877
- if volume_id in (CinderFixture .SWAP_OLD_VOL ,
1878
- CinderFixture .SWAP_ERR_OLD_VOL ):
1693
+ if volume_id in (self .SWAP_OLD_VOL ,
1694
+ self .SWAP_ERR_OLD_VOL ):
1879
1695
volume = {
1880
1696
'status' : 'available' ,
1881
1697
'display_name' : 'TEST1' ,
@@ -1885,11 +1701,11 @@ def fake_get(self_api, context, volume_id, microversion=None):
1885
1701
'size' : 1
1886
1702
}
1887
1703
if ((self .swap_volume_instance_uuid and
1888
- volume_id == CinderFixture .SWAP_OLD_VOL ) or
1704
+ volume_id == self .SWAP_OLD_VOL ) or
1889
1705
(self .swap_volume_instance_error_uuid and
1890
- volume_id == CinderFixture .SWAP_ERR_OLD_VOL )):
1706
+ volume_id == self .SWAP_ERR_OLD_VOL )):
1891
1707
instance_uuid = (self .swap_volume_instance_uuid
1892
- if volume_id == CinderFixture .SWAP_OLD_VOL
1708
+ if volume_id == self .SWAP_OLD_VOL
1893
1709
else self .swap_volume_instance_error_uuid )
1894
1710
1895
1711
if attachments :
@@ -1956,7 +1772,7 @@ def fake_get(self_api, context, volume_id, microversion=None):
1956
1772
1957
1773
return volume
1958
1774
1959
- def fake_migrate_volume_completion (self , context , old_volume_id ,
1775
+ def fake_migrate_volume_completion (_self , context , old_volume_id ,
1960
1776
new_volume_id , error ):
1961
1777
return {'save_volume_id' : new_volume_id }
1962
1778
@@ -2021,7 +1837,7 @@ def fake_attachment_update(_self, context, attachment_id, connector,
2021
1837
'connection_info' : {'data' :
2022
1838
{'foo' : 'bar' ,
2023
1839
'target_lun' : '1' }}}
2024
- if attachment_id == CinderFixtureNewAttachFlow .SWAP_ERR_ATTACH_ID :
1840
+ if attachment_id == self .SWAP_ERR_ATTACH_ID :
2025
1841
# This intentionally triggers a TypeError for the
2026
1842
# instance.volume_swap.error versioned notification tests.
2027
1843
attachment_ref = {'connection_info' : ()}
0 commit comments