Example #1
0
 def test_attach_in_used_volume_by_instance(self):
     """Test that attaching to an in-use volume fails."""
     # admin context
     ctx = context.RequestContext('admin', 'fake', True)
     # current status is available
     volume = db.volume_create(ctx, {'status': 'available', 'host': 'test',
                                     'provider_location': '', 'size': 1})
     connector = {'initiator': 'iqn.2012-07.org.fake:01'}
     # start service to handle rpc messages for attach requests
     svc = self.start_service('volume', host='test')
     self.volume_api.reserve_volume(ctx, volume)
     mountpoint = '/dev/vbd'
     self.volume_api.attach(ctx, volume, stubs.FAKE_UUID, None,
                            mountpoint, 'rw')
     conn_info = self.volume_api.initialize_connection(ctx,
                                                       volume, connector)
     self.assertEqual(conn_info['data']['access_mode'], 'rw')
     self.assertRaises(exception.InvalidVolume,
                       self.volume_api.attach,
                       ctx,
                       volume,
                       fakes.get_fake_uuid(),
                       None,
                       mountpoint,
                       'rw')
     self.assertRaises(exception.InvalidVolume,
                       self.volume_api.attach,
                       ctx,
                       volume,
                       fakes.get_fake_uuid(),
                       None,
                       mountpoint,
                       'ro')
     # cleanup
     svc.stop()
Example #2
0
 def test_attach_attaching_volume_with_different_mode(self):
     """Test that attaching volume reserved for another mode fails."""
     # admin context
     ctx = context.RequestContext('admin', 'fake', True)
     # current status is available
     volume = db.volume_create(ctx, {'status': 'available', 'host': 'test',
                                     'provider_location': '', 'size': 1})
     # start service to handle rpc messages for attach requests
     svc = self.start_service('volume', host='test')
     values = {'status': 'attaching',
               'instance_uuid': fakes.get_fake_uuid()}
     db.volume_update(ctx, volume['id'], values)
     db.volume_admin_metadata_update(ctx, volume['id'],
                                     {"attached_mode": 'rw'}, False)
     mountpoint = '/dev/vbd'
     self.assertRaises(exception.InvalidVolume,
                       self.volume_api.attach,
                       ctx,
                       volume,
                       values['instance_uuid'],
                       None,
                       mountpoint,
                       'ro')
     # cleanup
     svc.stop()
Example #3
0
 def test_attach_in_used_volume_by_instance(self):
     """Test that attaching to an in-use volume fails."""
     # admin context
     ctx = context.RequestContext("admin", "fake", True)
     # current status is available
     volume = db.volume_create(ctx, {"status": "available", "host": "test", "provider_location": "", "size": 1})
     connector = {"initiator": "iqn.2012-07.org.fake:01"}
     # start service to handle rpc messages for attach requests
     svc = self.start_service("volume", host="test")
     self.volume_api.reserve_volume(ctx, volume)
     mountpoint = "/dev/vbd"
     self.volume_api.attach(ctx, volume, stubs.FAKE_UUID, None, mountpoint, "rw")
     conn_info = self.volume_api.initialize_connection(ctx, volume, connector)
     self.assertEqual(conn_info["data"]["access_mode"], "rw")
     self.assertRaises(
         exception.InvalidVolume, self.volume_api.attach, ctx, volume, fakes.get_fake_uuid(), None, mountpoint, "rw"
     )
     self.assertRaises(
         exception.InvalidVolume, self.volume_api.attach, ctx, volume, fakes.get_fake_uuid(), None, mountpoint, "ro"
     )
     # cleanup
     svc.stop()
Example #4
0
 def test_attach_attaching_volume_with_different_instance(self):
     """Test that attaching volume reserved for another instance fails."""
     ctx = context.RequestContext("admin", "fake", True)
     # current status is available
     volume = db.volume_create(ctx, {"status": "available", "host": "test", "provider_location": "", "size": 1})
     # start service to handle rpc messages for attach requests
     svc = self.start_service("volume", host="test")
     values = {"status": "attaching", "instance_uuid": fakes.get_fake_uuid()}
     db.volume_update(ctx, volume["id"], values)
     mountpoint = "/dev/vbd"
     self.assertRaises(
         exception.InvalidVolume, self.volume_api.attach, ctx, volume, stubs.FAKE_UUID, None, mountpoint, "rw"
     )
     # cleanup
     svc.stop()
 def test_attach_in_use_volume(self):
     """Test that attaching to an in-use volume fails."""
     # admin context
     ctx = context.RequestContext('admin', 'fake', True)
     # current status is available
     volume = db.volume_create(ctx, {'status': 'available', 'host': 'test',
                                     'provider_location': ''})
     # start service to handle rpc messages for attach requests
     self.start_service('volume', host='test')
     self.volume_api.reserve_volume(ctx, volume)
     self.volume_api.initialize_connection(ctx, volume, {})
     mountpoint = '/dev/vbd'
     self.volume_api.attach(ctx, volume, stubs.FAKE_UUID, mountpoint)
     self.assertRaises(exception.InvalidVolume,
                       self.volume_api.attach,
                       ctx,
                       volume,
                       fakes.get_fake_uuid(),
                       mountpoint)
 def test_attach_attaching_volume_with_different_instance(self):
     """Test that attaching volume reserved for another instance fails."""
     # admin context
     ctx = context.RequestContext('admin', 'fake', True)
     # current status is available
     volume = db.volume_create(ctx, {'status': 'available', 'host': 'test',
                                     'provider_location': ''})
     # start service to handle rpc messages for attach requests
     self.start_service('volume', host='test')
     self.volume_api.initialize_connection(ctx, volume, {})
     values = {'status': 'attaching',
               'instance_uuid': fakes.get_fake_uuid()}
     db.volume_update(ctx, volume['id'], values)
     mountpoint = '/dev/vbd'
     self.assertRaises(exception.InvalidVolume,
                       self.volume_api.attach,
                       ctx,
                       volume,
                       stubs.FAKE_UUID,
                       mountpoint)
Example #7
0
 def test_attach_attaching_volume_with_different_instance(self):
     """Test that attaching volume reserved for another instance fails."""
     ctx = context.RequestContext('admin', 'fake', True)
     # current status is available
     volume = db.volume_create(ctx, {
         'status': 'available',
         'host': 'test',
         'provider_location': ''
     })
     # start service to handle rpc messages for attach requests
     svc = self.start_service('volume', host='test')
     values = {
         'status': 'attaching',
         'instance_uuid': fakes.get_fake_uuid()
     }
     db.volume_update(ctx, volume['id'], values)
     mountpoint = '/dev/vbd'
     self.assertRaises(exception.InvalidVolume, self.volume_api.attach, ctx,
                       volume, stubs.FAKE_UUID, None, mountpoint, 'rw')
     # cleanup
     svc.stop()
Example #8
0
 def test_attach_in_used_volume_by_instance(self):
     """Test that attaching to an in-use volume fails."""
     # admin context
     ctx = context.RequestContext('admin', 'fake', True)
     # current status is available
     volume = db.volume_create(ctx, {
         'status': 'available',
         'host': 'test',
         'provider_location': ''
     })
     connector = {'initiator': 'iqn.2012-07.org.fake:01'}
     # start service to handle rpc messages for attach requests
     svc = self.start_service('volume', host='test')
     self.volume_api.reserve_volume(ctx, volume)
     self.volume_api.initialize_connection(ctx, volume, connector)
     mountpoint = '/dev/vbd'
     self.volume_api.attach(ctx, volume, stubs.FAKE_UUID, None, mountpoint)
     self.assertRaises(exception.InvalidVolume, self.volume_api.attach, ctx,
                       volume, fakes.get_fake_uuid(), None, mountpoint)
     # cleanup
     svc.stop()