]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Merge "Don't use context.elevated to get volume"
authorJenkins <jenkins@review.openstack.org>
Fri, 14 Aug 2015 22:55:39 +0000 (22:55 +0000)
committerGerrit Code Review <review@openstack.org>
Fri, 14 Aug 2015 22:55:39 +0000 (22:55 +0000)
1  2 
cinder/tests/unit/api/v1/test_volumes.py
cinder/tests/unit/api/v2/stubs.py
cinder/tests/unit/api/v2/test_volumes.py
cinder/utils.py
cinder/volume/api.py

index 40b051aa7dcfd711294e507cf0cf06e58888b33c,74c097cb78129d3be5972805a1a6a504b039e245..934add1f7dc7a7ca30e538b702a4fd59fd2f9b47
@@@ -263,13 -266,17 +266,17 @@@ class VolumeApiTest(test.TestCase)
              'id': '1',
              'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1),
              'size': 1}}
 -        self.assertEqual(res_dict, expected)
 -        self.assertEqual(len(self.notifier.notifications), 2)
 +        self.assertEqual(expected, res_dict)
 +        self.assertEqual(2, len(self.notifier.notifications))
  
-     def test_volume_update_metadata(self):
-         self.stubs.Set(db, 'volume_get', stubs.stub_volume_get_db)
-         self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
+     @mock.patch.object(db, 'volume_admin_metadata_get',
+                        return_value={"qos_max_iops": 2000,
+                                      "readonly": "False",
+                                      "attached_mode": "rw"})
+     @mock.patch.object(db, 'volume_get', side_effect=stubs.stub_volume_get_db)
+     @mock.patch.object(volume_api.API, 'update',
+                        side_effect=stubs.stub_volume_update)
+     def test_volume_update_metadata(self, *args):
          updates = {
              "metadata": {"qos_max_iops": 2000}
          }
              'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1),
              'size': 1
          }}
 -        self.assertEqual(res_dict, expected)
 -        self.assertEqual(len(self.notifier.notifications), 2)
 +        self.assertEqual(expected, res_dict)
 +        self.assertEqual(2, len(self.notifier.notifications))
  
      def test_volume_update_with_admin_metadata(self):
+         def stubs_volume_admin_metadata_get(context, volume_id):
+             return {'key': 'value',
+                     'readonly': 'True'}
+         self.stubs.Set(db, 'volume_admin_metadata_get',
+                        stubs_volume_admin_metadata_get)
          self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
  
          volume = stubs.stub_volume("1")
                                   'created_at': datetime.datetime(1900, 1, 1,
                                                                   1, 1, 1),
                                   'size': 1}]}
 -        self.assertEqual(res_dict, expected)
 +        self.assertEqual(expected, res_dict)
  
-     def test_volume_show(self):
-         self.stubs.Set(db, 'volume_get', stubs.stub_volume_get_db)
+     @mock.patch.object(db, 'volume_admin_metadata_get',
+                        return_value={'attached_mode': 'rw',
+                                      'readonly': 'False'})
+     @mock.patch.object(db, 'volume_get', side_effect=stubs.stub_volume_get_db)
+     def test_volume_show(self, *args):
          req = fakes.HTTPRequest.blank('/v1/volumes/1')
          res_dict = self.controller.show(req, '1')
          expected = {'volume': {'status': 'fakestatus',
Simple merge
diff --cc cinder/utils.py
Simple merge
Simple merge