Browse Source

Use ShareInstance model to access share properties

The shares view uses the 'Share' model to access certain properties such
as the share type or the share type id. These properties are, however,
only proxied to the 'ShareInstance' model. This patch proposes to access
these properties through the 'ShareInstance' model directly in order to
avoid warning messages for proxied properties which pollute the m-api logs.

Closes-Bug: #1692058
Change-Id: I28fa366e106df51c7406673874bd993a44c500bf
(cherry picked from commit 2e6969c3fe)
Arne Wiebalck 2 years ago
parent
commit
6428a3cd1f

+ 10
- 7
manila/api/views/shares.py View File

@@ -65,12 +65,13 @@ class ViewBuilder(common.ViewBuilder):
65 65
 
66 66
         export_locations = share.get('export_locations', [])
67 67
 
68
-        if share['share_type_id'] and share.get('share_type'):
69
-            share_type = share['share_type']['name']
68
+        share_instance = share.get('instance') or {}
69
+
70
+        if share_instance.get('share_type'):
71
+            share_type = share_instance.get('share_type').get('name')
70 72
         else:
71
-            share_type = share['share_type_id']
73
+            share_type = share_instance.get('share_type_id')
72 74
 
73
-        share_instance = share.get('instance') or {}
74 75
         share_dict = {
75 76
             'id': share.get('id'),
76 77
             'size': share.get('size'),
@@ -109,11 +110,13 @@ class ViewBuilder(common.ViewBuilder):
109 110
 
110 111
     @common.ViewBuilder.versioned_method("2.6")
111 112
     def modify_share_type_field(self, context, share_dict, share):
112
-        share_type = share.get('share_type_id')
113
+        share_instance = share.get('instance') or {}
114
+
115
+        share_type = share_instance.get('share_type_id')
113 116
 
114 117
         share_type_name = None
115
-        if share.get('share_type'):
116
-            share_type_name = share.get('share_type').get('name')
118
+        if share_instance.get('share_type'):
119
+            share_type_name = share_instance.get('share_type').get('name')
117 120
 
118 121
         share_dict.update({
119 122
             'share_type_name': share_type_name,

+ 1
- 0
manila/tests/api/contrib/stubs.py View File

@@ -54,6 +54,7 @@ def stub_share(id, **kwargs):
54 54
         'share_network_id': None,
55 55
         'share_server_id': 'fake_share_server_id',
56 56
         'access_rules_status': 'active',
57
+        'share_type_id': '1',
57 58
     }
58 59
     if 'instance' in kwargs:
59 60
         share_instance.update(kwargs.pop('instance'))

+ 4
- 3
manila/tests/api/v1/test_shares.py View File

@@ -615,9 +615,9 @@ class ShareAPITest(test.TestCase):
615 615
                 'display_name': 'n2',
616 616
                 'status': constants.STATUS_AVAILABLE,
617 617
                 'snapshot_id': 'fake_snapshot_id',
618
-                'share_type_id': 'fake_share_type_id',
619 618
                 'instance': {'host': 'fake_host',
620
-                             'share_network_id': 'fake_share_network_id'},
619
+                             'share_network_id': 'fake_share_network_id',
620
+                             'share_type_id': 'fake_share_type_id'},
621 621
             },
622 622
             {'id': 'id3', 'display_name': 'n3'},
623 623
         ]
@@ -655,7 +655,8 @@ class ShareAPITest(test.TestCase):
655 655
         self.assertEqual(
656 656
             shares[1]['status'], result['shares'][0]['status'])
657 657
         self.assertEqual(
658
-            shares[1]['share_type_id'], result['shares'][0]['share_type'])
658
+            shares[1]['instance']['share_type_id'],
659
+            result['shares'][0]['share_type'])
659 660
         self.assertEqual(
660 661
             shares[1]['snapshot_id'], result['shares'][0]['snapshot_id'])
661 662
         if use_admin_context:

+ 9
- 3
manila/tests/api/v2/test_shares.py View File

@@ -1529,10 +1529,10 @@ class ShareAPITest(test.TestCase):
1529 1529
                 'display_name': 'n2',
1530 1530
                 'status': constants.STATUS_AVAILABLE,
1531 1531
                 'snapshot_id': 'fake_snapshot_id',
1532
-                'share_type_id': 'fake_share_type_id',
1533 1532
                 'instance': {
1534 1533
                     'host': 'fake_host',
1535 1534
                     'share_network_id': 'fake_share_network_id',
1535
+                    'share_type_id': 'fake_share_type_id',
1536 1536
                 },
1537 1537
             },
1538 1538
             {'id': 'id3', 'display_name': 'n3'},
@@ -1571,7 +1571,8 @@ class ShareAPITest(test.TestCase):
1571 1571
         self.assertEqual(
1572 1572
             shares[1]['status'], result['shares'][0]['status'])
1573 1573
         self.assertEqual(
1574
-            shares[1]['share_type_id'], result['shares'][0]['share_type'])
1574
+            shares[1]['instance']['share_type_id'],
1575
+            result['shares'][0]['share_type'])
1575 1576
         self.assertEqual(
1576 1577
             shares[1]['snapshot_id'], result['shares'][0]['snapshot_id'])
1577 1578
         if use_admin_context:
@@ -2538,7 +2539,12 @@ class ShareManageTest(test.TestCase):
2538 2539
         }
2539 2540
         self._setup_manage_mocks()
2540 2541
         return_share = mock.Mock(
2541
-            return_value=stubs.stub_share('fake', instance={}))
2542
+            return_value=stubs.stub_share(
2543
+                'fake',
2544
+                instance={
2545
+                    'share_type_id': '1',
2546
+                })
2547
+            )
2542 2548
         self.mock_object(
2543 2549
             share_api.API, 'manage', return_share)
2544 2550
         share = {

+ 6
- 1
manila/tests/api/views/test_shares.py View File

@@ -39,7 +39,12 @@ class ViewBuilderTestCase(test.TestCase):
39 39
             'export_location': 'fake_export_location',
40 40
             'export_locations': ['fake_export_location'],
41 41
             'access_rules_status': 'fake_rule_status',
42
-            'instance': {},
42
+            'instance': {
43
+                'share_type': {
44
+                    'name': 'fake_share_type_name',
45
+                },
46
+                'share_type_id': 'fake_share_type_id',
47
+            },
43 48
             'replication_type': 'fake_replication_type',
44 49
             'has_replicas': False,
45 50
             'user_id': 'fake_userid',

+ 4
- 2
manila/tests/fake_share.py View File

@@ -31,7 +31,6 @@ def fake_share(**kwargs):
31 31
         'share_proto': 'fake_proto',
32 32
         'share_network_id': 'fake share network id',
33 33
         'share_server_id': 'fake share server id',
34
-        'share_type_id': 'fake share type id',
35 34
         'export_location': 'fake_location:/fake_share',
36 35
         'project_id': 'fake_project_uuid',
37 36
         'availability_zone': 'fake_az',
@@ -39,7 +38,10 @@ def fake_share(**kwargs):
39 38
         'replication_type': None,
40 39
         'is_busy': False,
41 40
         'share_group_id': None,
42
-        'instance': {'host': 'fakehost'},
41
+        'instance': {
42
+            'host': 'fakehost',
43
+            'share_type_id': '1',
44
+        },
43 45
         'mount_snapshot_support': False,
44 46
     }
45 47
     share.update(kwargs)

Loading…
Cancel
Save