Skip to content

Commit ab773a3

Browse files
committed
chore(cinder-understack): wire up volume and type for testing
This adds enough boilerplate so that we have a volume type with data set and can then utilize it for calling our volume creation function with appropriate data.
1 parent 951348d commit ab773a3

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

python/cinder-understack/cinder_understack/tests/test_dynamic_netapp_driver.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
"""Test NetApp dynamic driver implementation."""
22

3+
import uuid
34
from unittest import mock
45

6+
from cinder import context
7+
from cinder import db
58
from cinder.tests.unit import test
9+
from cinder.tests.unit import utils as test_utils
610
from cinder.tests.unit.volume.drivers.netapp import fakes as na_fakes
711
from cinder.volume.drivers.netapp.dataontap.nvme_library import NetAppNVMeStorageLibrary
812

@@ -16,6 +20,13 @@ def setUp(self):
1620
"""Set up test case."""
1721
super().setUp()
1822

23+
self.user_id = str(uuid.uuid4())
24+
self.project_id = str(uuid.uuid4())
25+
26+
self.ctxt = context.RequestContext(
27+
self.user_id, self.project_id, auth_token=True
28+
)
29+
1930
kwargs = {
2031
"configuration": self.get_config_base(),
2132
"host": "openstack@netapp_dynamic",
@@ -53,18 +64,26 @@ def test_library_inherits_from_netapp_library(self):
5364
def test_do_setup_calls_library(self, new_do_setup, old_do_setup, mock_rest):
5465
"""Test that do_setup delegates to library."""
5566
self._setup_rest_mock(mock_rest)
56-
context = mock.Mock()
57-
self.driver.do_setup(context)
67+
self.driver.do_setup(self.ctxt)
5868
# not yet wired in
5969
new_do_setup.assert_not_called()
6070
old_do_setup.assert_not_called()
6171

6272
@mock.patch.object(dynamic_netapp_driver.NetappDynamicLibrary, "create_volume")
6373
def test_create_volume_calls_library(self, mock_create_volume):
6474
"""Test that create_volume delegates to library."""
65-
volume = mock.Mock()
66-
self.driver.create_volume(volume)
67-
mock_create_volume.assert_called_once_with(volume)
75+
ctxt = context.get_admin_context()
76+
vol_type = test_utils.create_volume_type(
77+
ctxt,
78+
self,
79+
id=na_fakes.VOLUME.volume_type_id,
80+
name="my_vol_type",
81+
is_public=False,
82+
extra_specs={"netapp:svm_vserver": "data-svm"},
83+
)
84+
db.volume_type_access_add(ctxt, vol_type.id, self.project_id)
85+
self.driver.create_volume(na_fakes.VOLUME)
86+
mock_create_volume.assert_called_once_with(na_fakes.VOLUME)
6887

6988
@mock.patch.object(dynamic_netapp_driver.NetappDynamicLibrary, "get_volume_stats")
7089
def test_get_volume_stats_calls_library(self, mock_get_volume_stats):

0 commit comments

Comments
 (0)