Example #1
0
    def test_create_volume_from_image_exception(self):
        """Verify that create volume from image, the volume status is
        'downloading'."""
        dst_fd, dst_path = tempfile.mkstemp()
        os.close(dst_fd)

        self.stubs.Set(self.volume.driver, 'local_path', lambda x: dst_path)

        image_id = 'aaaaaaaa-0000-0000-0000-000000000000'
        # creating volume testdata
        volume_id = 1
        db.volume_create(self.context, {'id': volume_id,
                             'updated_at': datetime.datetime(1, 1, 1, 1, 1, 1),
                             'display_description': 'Test Desc',
                             'size': 20,
                             'status': 'creating',
                             'host': 'dummy'})

        self.assertRaises(exception.ImageNotFound,
                          self.volume.create_volume,
                          self.context,
                          volume_id,
                          None,
                          image_id)
        volume = db.volume_get(self.context, volume_id)
        self.assertEqual(volume['status'], "error")
        # cleanup
        db.volume_destroy(self.context, volume_id)
        os.unlink(dst_path)
Example #2
0
    def test_create_volume_from_image_exception(self):
        """Verify that create volume from image, the volume status is
        'downloading'."""
        dst_fd, dst_path = tempfile.mkstemp()
        os.close(dst_fd)

        self.stubs.Set(self.volume.driver, "local_path", lambda x: dst_path)

        image_id = "aaaaaaaa-0000-0000-0000-000000000000"
        # creating volume testdata
        volume_id = 1
        db.volume_create(
            self.context,
            {
                "id": volume_id,
                "updated_at": datetime.datetime(1, 1, 1, 1, 1, 1),
                "display_description": "Test Desc",
                "size": 20,
                "status": "creating",
                "host": "dummy",
            },
        )

        self.assertRaises(exception.ImageNotFound, self.volume.create_volume, self.context, volume_id, None, image_id)
        volume = db.volume_get(self.context, volume_id)
        self.assertEqual(volume["status"], "error")
        # cleanup
        db.volume_destroy(self.context, volume_id)
        os.unlink(dst_path)
Example #3
0
    def test_copy_volume_to_image_status_available(self):
        dst_fd, dst_path = tempfile.mkstemp()
        os.close(dst_fd)

        def fake_local_path(volume):
            return dst_path

        self.stubs.Set(self.volume.driver, 'local_path', fake_local_path)

        image_id = '70a599e0-31e7-49b7-b260-868f441e862b'
        # creating volume testdata
        volume_id = 1
        db.volume_create(self.context, {'id': volume_id,
                             'updated_at': datetime.datetime(1, 1, 1, 1, 1, 1),
                             'display_description': 'Test Desc',
                             'size': 20,
                             'status': 'uploading',
                             'instance_uuid': None,
                             'host': 'dummy'})

        try:
            # start test
            self.volume.copy_volume_to_image(self.context,
                                                volume_id,
                                                image_id)

            volume = db.volume_get(self.context, volume_id)
            self.assertEqual(volume['status'], 'available')
        finally:
            # cleanup
            db.volume_destroy(self.context, volume_id)
            os.unlink(dst_path)
Example #4
0
    def test_copy_volume_to_image_status_available(self):
        dst_fd, dst_path = tempfile.mkstemp()
        os.close(dst_fd)

        def fake_local_path(volume):
            return dst_path

        self.stubs.Set(self.volume.driver, "local_path", fake_local_path)

        image_id = "70a599e0-31e7-49b7-b260-868f441e862b"
        # creating volume testdata
        volume_id = 1
        db.volume_create(
            self.context,
            {
                "id": volume_id,
                "updated_at": datetime.datetime(1, 1, 1, 1, 1, 1),
                "display_description": "Test Desc",
                "size": 20,
                "status": "uploading",
                "instance_uuid": None,
                "host": "dummy",
            },
        )

        try:
            # start test
            self.volume.copy_volume_to_image(self.context, volume_id, image_id)

            volume = db.volume_get(self.context, volume_id)
            self.assertEqual(volume["status"], "available")
        finally:
            # cleanup
            db.volume_destroy(self.context, volume_id)
            os.unlink(dst_path)
Example #5
0
    def test_copy_volume_to_image_exception(self):
        dst_fd, dst_path = tempfile.mkstemp()
        os.close(dst_fd)

        def fake_local_path(volume):
            return dst_path

        self.stubs.Set(self.volume.driver, 'local_path', fake_local_path)

        image_id = 'aaaaaaaa-0000-0000-0000-000000000000'
        # creating volume testdata
        volume_id = 1
        db.volume_create(self.context, {'id': volume_id,
                             'updated_at': datetime.datetime(1, 1, 1, 1, 1, 1),
                             'display_description': 'Test Desc',
                             'size': 20,
                             'status': 'in-use',
                             'host': 'dummy'})

        try:
            # start test
            self.assertRaises(exception.ImageNotFound,
                              self.volume.copy_volume_to_image,
                              self.context,
                              volume_id,
                              image_id)

            volume = db.volume_get(self.context, volume_id)
            self.assertEqual(volume['status'], 'available')
        finally:
            # cleanup
            db.volume_destroy(self.context, volume_id)
            os.unlink(dst_path)
Example #6
0
    def test_copy_volume_to_image_status_use(self):
        dst_fd, dst_path = tempfile.mkstemp()
        os.close(dst_fd)

        def fake_local_path(volume):
            return dst_path

        self.stubs.Set(self.volume.driver, 'local_path', fake_local_path)

        #image_id = '70a599e0-31e7-49b7-b260-868f441e862b'
        image_id = 'a440c04b-79fa-479c-bed1-0b816eaec379'
        # creating volume testdata
        volume_id = 1
        db.volume_create(self.context,
                         {'id': volume_id,
                         'updated_at': datetime.datetime(1, 1, 1, 1, 1, 1),
                         'display_description': 'Test Desc',
                         'size': 20,
                         'status': 'uploading',
                         'instance_uuid':
                            'b21f957d-a72f-4b93-b5a5-45b1161abb02',
                         'host': 'dummy'})

        try:
            # start test
            self.volume.copy_volume_to_image(self.context,
                                                volume_id,
                                                image_id)

            volume = db.volume_get(self.context, volume_id)
            self.assertEqual(volume['status'], 'in-use')
        finally:
            # cleanup
            db.volume_destroy(self.context, volume_id)
            os.unlink(dst_path)
Example #7
0
 def test_describe_volumes(self):
     """Makes sure describe_volumes works and filters results."""
     vol1 = db.volume_create(self.context, {})
     vol2 = db.volume_create(self.context, {})
     result = self.cloud.describe_volumes(self.context)
     self.assertEqual(len(result['volumeSet']), 2)
     volume_id = ec2utils.id_to_ec2_id(vol2['id'], 'vol-%08x')
     result = self.cloud.describe_volumes(self.context,
                                          volume_id=[volume_id])
     self.assertEqual(len(result['volumeSet']), 1)
     self.assertEqual(
         ec2utils.ec2_id_to_id(result['volumeSet'][0]['volumeId']),
         vol2['id'])
     db.volume_destroy(self.context, vol1['id'])
     db.volume_destroy(self.context, vol2['id'])
Example #8
0
 def test_describe_volumes(self):
     """Makes sure describe_volumes works and filters results."""
     vol1 = db.volume_create(self.context, {})
     vol2 = db.volume_create(self.context, {})
     result = self.cloud.describe_volumes(self.context)
     self.assertEqual(len(result['volumeSet']), 2)
     volume_id = cloud.id_to_ec2_id(vol2['id'], 'vol-%08x')
     result = self.cloud.describe_volumes(self.context,
                                          volume_id=[volume_id])
     self.assertEqual(len(result['volumeSet']), 1)
     self.assertEqual(
             cloud.ec2_id_to_id(result['volumeSet'][0]['volumeId']),
             vol2['id'])
     db.volume_destroy(self.context, vol1['id'])
     db.volume_destroy(self.context, vol2['id'])
Example #9
0
 def _create_volume(self, size=10):
     """Create a test volume"""
     vol = {}
     vol['user_id'] = self.user.id
     vol['project_id'] = self.project.id
     vol['size'] = size
     return db.volume_create(self.context, vol)['id']
Example #10
0
    def test_live_migration_src_check_volume_node_not_alive(self):
        """Raise exception when volume node is not alive."""

        instance_id = self._create_instance()
        i_ref = db.instance_get(self.context, instance_id)
        dic = {'instance_id': instance_id, 'size': 1}
        v_ref = db.volume_create(self.context, {
            'instance_id': instance_id,
            'size': 1
        })
        t1 = utils.utcnow() - datetime.timedelta(1)
        dic = {
            'created_at': t1,
            'updated_at': t1,
            'binary': 'nova-volume',
            'topic': 'volume',
            'report_count': 0
        }
        s_ref = db.service_create(self.context, dic)

        self.assertRaises(exception.VolumeServiceUnavailable,
                          self.scheduler.driver.schedule_live_migration,
                          self.context, instance_id, i_ref['host'])

        db.instance_destroy(self.context, instance_id)
        db.service_destroy(self.context, s_ref['id'])
        db.volume_destroy(self.context, v_ref['id'])
Example #11
0
    def _provision_volume(self, context, vol, vsa_id, availability_zone):

        if availability_zone is None:
            availability_zone = FLAGS.storage_availability_zone

        now = utils.utcnow()
        options = {
            'size': vol['size'],
            'user_id': context.user_id,
            'project_id': context.project_id,
            'snapshot_id': None,
            'availability_zone': availability_zone,
            'status': "creating",
            'attach_status': "detached",
            'display_name': vol['name'],
            'display_description': vol['description'],
            'volume_type_id': vol['volume_type_id'],
            'metadata': dict(to_vsa_id=vsa_id),
            'host': vol['host'],
            'scheduled_at': now
            }

        size = vol['size']
        host = vol['host']
        name = vol['name']
        LOG.debug(_("Provision volume %(name)s of size %(size)s GB on "\
                    "host %(host)s"), locals())

        volume_ref = db.volume_create(context, options)
        rpc.cast(context,
                 db.queue_get_for(context, "volume", vol['host']),
                 {"method": "create_volume",
                  "args": {"volume_id": volume_ref['id'],
                           "snapshot_id": None}})
Example #12
0
 def _create_volume(self, size=10):
     """Create a test volume"""
     vol = {}
     vol['user_id'] = self.user.id
     vol['project_id'] = self.project.id
     vol['size'] = size
     return db.volume_create(self.context, vol)['id']
Example #13
0
 def _create_volume(self, size=10):
     """Create a test volume"""
     vol = {}
     vol["user_id"] = self.user_id
     vol["project_id"] = self.project_id
     vol["size"] = size
     return db.volume_create(self.context, vol)["id"]
Example #14
0
    def _provision_volume(self, context, vol, vsa_id, availability_zone):

        if availability_zone is None:
            availability_zone = FLAGS.storage_availability_zone

        now = utils.utcnow()
        options = {
            'size': vol['size'],
            'user_id': context.user_id,
            'project_id': context.project_id,
            'snapshot_id': None,
            'availability_zone': availability_zone,
            'status': "creating",
            'attach_status': "detached",
            'display_name': vol['name'],
            'display_description': vol['description'],
            'volume_type_id': vol['volume_type_id'],
            'metadata': dict(to_vsa_id=vsa_id),
        }

        size = vol['size']
        host = vol['host']
        name = vol['name']
        LOG.debug(_("Provision volume %(name)s of size %(size)s GB on "\
                    "host %(host)s"), locals())

        volume_ref = db.volume_create(context.elevated(), options)
        driver.cast_to_volume_host(context,
                                   vol['host'],
                                   'create_volume',
                                   volume_id=volume_ref['id'],
                                   snapshot_id=None)
Example #15
0
File: vsa.py Project: Razique/nova
    def _provision_volume(self, context, vol, vsa_id, availability_zone):

        if availability_zone is None:
            availability_zone = FLAGS.storage_availability_zone

        now = utils.utcnow()
        options = {
            'size': vol['size'],
            'user_id': context.user_id,
            'project_id': context.project_id,
            'snapshot_id': None,
            'availability_zone': availability_zone,
            'status': "creating",
            'attach_status': "detached",
            'display_name': vol['name'],
            'display_description': vol['description'],
            'volume_type_id': vol['volume_type_id'],
            'metadata': dict(to_vsa_id=vsa_id),
            }

        size = vol['size']
        host = vol['host']
        name = vol['name']
        LOG.debug(_("Provision volume %(name)s of size %(size)s GB on "\
                    "host %(host)s"), locals())

        volume_ref = db.volume_create(context.elevated(), options)
        driver.cast_to_volume_host(context, vol['host'],
                'create_volume', volume_id=volume_ref['id'],
                snapshot_id=None)
Example #16
0
    def _provision_volume(self, context, vol, vsa_id, availability_zone):

        if availability_zone is None:
            availability_zone = FLAGS.storage_availability_zone

        now = utils.utcnow()
        options = {
            "size": vol["size"],
            "user_id": context.user_id,
            "project_id": context.project_id,
            "snapshot_id": None,
            "availability_zone": availability_zone,
            "status": "creating",
            "attach_status": "detached",
            "display_name": vol["name"],
            "display_description": vol["description"],
            "volume_type_id": vol["volume_type_id"],
            "metadata": dict(to_vsa_id=vsa_id),
        }

        size = vol["size"]
        host = vol["host"]
        name = vol["name"]
        LOG.debug(_("Provision volume %(name)s of size %(size)s GB on " "host %(host)s"), locals())

        volume_ref = db.volume_create(context.elevated(), options)
        driver.cast_to_volume_host(context, vol["host"], "create_volume", volume_id=volume_ref["id"], snapshot_id=None)
Example #17
0
 def test_update_of_volume_display_fields(self):
     vol = db.volume_create(self.context, {})
     self.cloud.update_volume(self.context,
                              ec2utils.id_to_ec2_id(vol['id'], 'vol-%08x'),
                              display_name='c00l v0lum3')
     vol = db.volume_get(self.context, vol['id'])
     self.assertEqual('c00l v0lum3', vol['display_name'])
     db.volume_destroy(self.context, vol['id'])
Example #18
0
 def test_update_of_volume_wont_update_private_fields(self):
     vol = db.volume_create(self.context, {})
     self.cloud.update_volume(self.context,
                              ec2utils.id_to_ec2_id(vol['id'], 'vol-%08x'),
                              mountpoint='/not/here')
     vol = db.volume_get(self.context, vol['id'])
     self.assertEqual(None, vol['mountpoint'])
     db.volume_destroy(self.context, vol['id'])
Example #19
0
 def _create_volume(self):
     """Create a test volume"""
     vol = {}
     vol['image_id'] = 'ami-test'
     vol['reservation_id'] = 'r-fakeres'
     vol['size'] = 1
     vol['availability_zone'] = 'test'
     return db.volume_create(self.context, vol)['id']
Example #20
0
 def test_update_of_volume_display_fields(self):
     vol = db.volume_create(self.context, {})
     self.cloud.update_volume(self.context,
                              cloud.id_to_ec2_id(vol['id'], 'vol-%08x'),
                              display_name='c00l v0lum3')
     vol = db.volume_get(self.context, vol['id'])
     self.assertEqual('c00l v0lum3', vol['display_name'])
     db.volume_destroy(self.context, vol['id'])
Example #21
0
 def _create_volume(self):
     """Create a test volume"""
     vol = {}
     vol["image_id"] = "ami-test"
     vol["reservation_id"] = "r-fakeres"
     vol["size"] = 1
     vol["availability_zone"] = "test"
     return db.volume_create(self.context, vol)["id"]
Example #22
0
 def test_update_of_volume_wont_update_private_fields(self):
     vol = db.volume_create(self.context, {})
     self.cloud.update_volume(self.context,
                              cloud.id_to_ec2_id(vol['id'], 'vol-%08x'),
                              mountpoint='/not/here')
     vol = db.volume_get(self.context, vol['id'])
     self.assertEqual(None, vol['mountpoint'])
     db.volume_destroy(self.context, vol['id'])
Example #23
0
 def _create_volume(size='0'):
     """Create a volume object."""
     vol = {}
     vol['size'] = size
     vol['user_id'] = 'fake'
     vol['project_id'] = 'fake'
     vol['availability_zone'] = FLAGS.storage_availability_zone
     vol['status'] = "creating"
     vol['attach_status'] = "detached"
     return db.volume_create(context.get_admin_context(), vol)['id']
Example #24
0
    def _clone_volume_from_image(self, expected_status,
                                 clone_works=True):
        """Try to clone a volume from an image, and check the status
        afterwards"""
        def fake_clone_image(volume, image_location):
            pass

        def fake_clone_error(volume, image_location):
            raise exception.NovaException()

        self.stubs.Set(self.volume.driver, '_is_cloneable', lambda x: True)
        if clone_works:
            self.stubs.Set(self.volume.driver, 'clone_image', fake_clone_image)
        else:
            self.stubs.Set(self.volume.driver, 'clone_image', fake_clone_error)

        image_id = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
        volume_id = 1
        # creating volume testdata
        db.volume_create(self.context, {'id': volume_id,
                            'updated_at': timeutils.utcnow(),
                            'display_description': 'Test Desc',
                            'size': 20,
                            'status': 'creating',
                            'instance_uuid': None,
                            'host': 'dummy'})
        try:
            if clone_works:
                self.volume.create_volume(self.context,
                                          volume_id,
                                          image_id=image_id)
            else:
                self.assertRaises(exception.NovaException,
                                  self.volume.create_volume,
                                  self.context,
                                  volume_id,
                                  image_id=image_id)

            volume = db.volume_get(self.context, volume_id)
            self.assertEqual(volume['status'], expected_status)
        finally:
            # cleanup
            db.volume_destroy(self.context, volume_id)
Example #25
0
 def _create_volume(size='0'):
     """Create a volume object."""
     vol = {}
     vol['size'] = size
     vol['user_id'] = 'fake'
     vol['project_id'] = 'fake'
     vol['availability_zone'] = FLAGS.storage_availability_zone
     vol['status'] = "creating"
     vol['attach_status'] = "detached"
     return db.volume_create(context.get_admin_context(), vol)['id']
Example #26
0
    def _create_volume_from_image(self,
                                  expected_status,
                                  fakeout_copy_image_to_volume=False):
        """Call copy image to volume, Test the status of volume after calling
        copying image to volume."""
        def fake_local_path(volume):
            return dst_path

        def fake_copy_image_to_volume(context, volume, image_id):
            pass

        dst_fd, dst_path = tempfile.mkstemp()
        os.close(dst_fd)
        self.stubs.Set(self.volume.driver, 'local_path', fake_local_path)
        if fakeout_copy_image_to_volume:
            self.stubs.Set(self.volume, '_copy_image_to_volume',
                           fake_copy_image_to_volume)

        image_id = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
        volume_id = 1
        # creating volume testdata
        db.volume_create(
            self.context, {
                'id': volume_id,
                'updated_at': datetime.datetime(1, 1, 1, 1, 1, 1),
                'display_description': 'Test Desc',
                'size': 20,
                'status': 'creating',
                'instance_uuid': None,
                'host': 'dummy'
            })
        try:
            self.volume.create_volume(self.context,
                                      volume_id,
                                      image_id=image_id)

            volume = db.volume_get(self.context, volume_id)
            self.assertEqual(volume['status'], expected_status)
        finally:
            # cleanup
            db.volume_destroy(self.context, volume_id)
            os.unlink(dst_path)
Example #27
0
 def _create_volume(self, size=0):
     """Create a volume object."""
     vol = {}
     vol["size"] = size
     vol["user_id"] = "fake"
     vol["project_id"] = "fake"
     vol["host"] = "localhost"
     vol["availability_zone"] = FLAGS.storage_availability_zone
     vol["status"] = "creating"
     vol["attach_status"] = "detached"
     return db.volume_create(self.context, vol)
Example #28
0
 def _create_volume(size="0", snapshot_id=None):
     """Create a volume object."""
     vol = {}
     vol["size"] = size
     vol["snapshot_id"] = snapshot_id
     vol["user_id"] = "fake"
     vol["project_id"] = "fake"
     vol["availability_zone"] = FLAGS.storage_availability_zone
     vol["status"] = "creating"
     vol["attach_status"] = "detached"
     return db.volume_create(context.get_admin_context(), vol)
Example #29
0
 def _create_volume(self, size=0):
     """Create a volume object."""
     vol = {}
     vol['size'] = size
     vol['user_id'] = 'fake'
     vol['project_id'] = 'fake'
     vol['host'] = 'localhost'
     vol['availability_zone'] = FLAGS.storage_availability_zone
     vol['status'] = "creating"
     vol['attach_status'] = "detached"
     return db.volume_create(self.context, vol)
Example #30
0
    def _create_volume_from_image(self, expected_status, fakeout_copy_image_to_volume=False):
        """Call copy image to volume, Test the status of volume after calling
        copying image to volume."""

        def fake_local_path(volume):
            return dst_path

        def fake_copy_image_to_volume(context, volume, image_id):
            pass

        dst_fd, dst_path = tempfile.mkstemp()
        os.close(dst_fd)
        self.stubs.Set(self.volume.driver, "local_path", fake_local_path)
        if fakeout_copy_image_to_volume:
            self.stubs.Set(self.volume, "_copy_image_to_volume", fake_copy_image_to_volume)

        image_id = "c905cedb-7281-47e4-8a62-f26bc5fc4c77"
        volume_id = 1
        # creating volume testdata
        db.volume_create(
            self.context,
            {
                "id": volume_id,
                "updated_at": datetime.datetime(1, 1, 1, 1, 1, 1),
                "display_description": "Test Desc",
                "size": 20,
                "status": "creating",
                "instance_uuid": None,
                "host": "dummy",
            },
        )
        try:
            self.volume.create_volume(self.context, volume_id, image_id=image_id)

            volume = db.volume_get(self.context, volume_id)
            self.assertEqual(volume["status"], expected_status)
        finally:
            # cleanup
            db.volume_destroy(self.context, volume_id)
            os.unlink(dst_path)
Example #31
0
 def _create_volume(self, params={}):
     """Create a test volume"""
     vol = {}
     vol["snapshot_id"] = self.snapshot_id
     vol["user_id"] = self.user_id
     vol["project_id"] = self.project_id
     vol["host"] = FLAGS.host
     vol["availability_zone"] = FLAGS.storage_availability_zone
     vol["status"] = "creating"
     vol["attach_status"] = "detached"
     vol["size"] = self.volume_size
     vol.update(params)
     return db.volume_create(self.context, vol)["id"]
Example #32
0
 def _create_volume(self, params={}):
     """Create a test volume"""
     vol = {}
     vol['snapshot_id'] = self.snapshot_id
     vol['user_id'] = self.user_id
     vol['project_id'] = self.project_id
     vol['host'] = FLAGS.host
     vol['availability_zone'] = FLAGS.storage_availability_zone
     vol['status'] = "creating"
     vol['attach_status'] = "detached"
     vol['size'] = self.volume_size
     vol.update(params)
     return db.volume_create(self.context, vol)['id']
Example #33
0
    def _create_volume_from_image(self, expected_status,
                                  fakeout_copy_image_to_volume=False):
        """Call copy image to volume, Test the status of volume after calling
        copying image to volume."""
        def fake_local_path(volume):
            return dst_path

        def fake_copy_image_to_volume(context, volume, image_id):
            pass

        dst_fd, dst_path = tempfile.mkstemp()
        os.close(dst_fd)
        self.stubs.Set(self.volume.driver, 'local_path', fake_local_path)
        if fakeout_copy_image_to_volume:
            self.stubs.Set(self.volume, '_copy_image_to_volume',
                           fake_copy_image_to_volume)

        image_id = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
        volume_id = 1
        # creating volume testdata
        db.volume_create(self.context, {'id': volume_id,
                            'updated_at': datetime.datetime(1, 1, 1, 1, 1, 1),
                            'display_description': 'Test Desc',
                            'size': 20,
                            'status': 'creating',
                            'instance_uuid': None,
                            'host': 'dummy'})
        try:
            self.volume.create_volume(self.context,
                                      volume_id,
                                      image_id=image_id)

            volume = db.volume_get(self.context, volume_id)
            self.assertEqual(volume['status'], expected_status)
        finally:
            # cleanup
            db.volume_destroy(self.context, volume_id)
            os.unlink(dst_path)
Example #34
0
 def _create_volume(size=0, snapshot_id=None, image_id=None, metadata=None):
     """Create a volume object."""
     vol = {}
     vol['size'] = size
     vol['snapshot_id'] = snapshot_id
     vol['image_id'] = image_id
     vol['user_id'] = 'fake'
     vol['project_id'] = 'fake'
     vol['availability_zone'] = FLAGS.storage_availability_zone
     vol['status'] = "creating"
     vol['attach_status'] = "detached"
     if metadata is not None:
         vol['metadata'] = metadata
     return db.volume_create(context.get_admin_context(), vol)
Example #35
0
 def _create_volume(size=0, snapshot_id=None, image_id=None, metadata=None):
     """Create a volume object."""
     vol = {}
     vol["size"] = size
     vol["snapshot_id"] = snapshot_id
     vol["image_id"] = image_id
     vol["user_id"] = "fake"
     vol["project_id"] = "fake"
     vol["availability_zone"] = FLAGS.storage_availability_zone
     vol["status"] = "creating"
     vol["attach_status"] = "detached"
     if metadata is not None:
         vol["metadata"] = metadata
     return db.volume_create(context.get_admin_context(), vol)
Example #36
0
    def test_live_migration_raises_exception(self):
        """Confirms recover method is called when exceptions are raised."""
        # Skip if non-libvirt environment
        if not self.lazy_load_library_exists():
            return

        # Preparing data
        self.compute = utils.import_object(FLAGS.compute_manager)
        instance_dict = {
            'host': 'fake',
            'state': power_state.RUNNING,
            'state_description': 'running'
        }
        instance_ref = db.instance_create(self.context, self.test_instance)
        instance_ref = db.instance_update(self.context, instance_ref['id'],
                                          instance_dict)
        vol_dict = {'status': 'migrating', 'size': 1}
        volume_ref = db.volume_create(self.context, vol_dict)
        db.volume_attached(self.context, volume_ref['id'], instance_ref['id'],
                           '/dev/fake')

        # Preparing mocks
        vdmock = self.mox.CreateMock(libvirt.virDomain)
        self.mox.StubOutWithMock(vdmock, "migrateToURI")
        vdmock.migrateToURI(FLAGS.live_migration_uri % 'dest',
                            mox.IgnoreArg(),
                            None, FLAGS.live_migration_bandwidth).\
                            AndRaise(libvirt.libvirtError('ERR'))

        def fake_lookup(instance_name):
            if instance_name == instance_ref.name:
                return vdmock

        self.create_fake_libvirt_mock(lookupByName=fake_lookup)

        # Start test
        self.mox.ReplayAll()
        conn = libvirt_conn.LibvirtConnection(False)
        self.assertRaises(libvirt.libvirtError, conn._live_migration,
                          self.context, instance_ref, 'dest', '',
                          self.compute.recover_live_migration)

        instance_ref = db.instance_get(self.context, instance_ref['id'])
        self.assertTrue(instance_ref['state_description'] == 'running')
        self.assertTrue(instance_ref['state'] == power_state.RUNNING)
        volume_ref = db.volume_get(self.context, volume_ref['id'])
        self.assertTrue(volume_ref['status'] == 'in-use')

        db.volume_destroy(self.context, volume_ref['id'])
        db.instance_destroy(self.context, instance_ref['id'])
Example #37
0
    def test_post_live_migration_working_correctly(self):
        """Confirm post_live_migration() works as expected correctly."""
        dest = 'desthost'
        flo_addr = '1.2.1.2'

        # Preparing datas
        c = context.get_admin_context()
        instance_id = self._create_instance()
        i_ref = db.instance_get(c, instance_id)
        db.instance_update(c, i_ref['id'], {
            'state_description': 'migrating',
            'state': power_state.PAUSED
        })
        v_ref = db.volume_create(c, {'size': 1, 'instance_id': instance_id})
        fix_addr = db.fixed_ip_create(c, {
            'address': '1.1.1.1',
            'instance_id': instance_id
        })
        fix_ref = db.fixed_ip_get_by_address(c, fix_addr)
        flo_ref = db.floating_ip_create(c, {
            'address': flo_addr,
            'fixed_ip_id': fix_ref['id']
        })
        # reload is necessary before setting mocks
        i_ref = db.instance_get(c, instance_id)

        # Preparing mocks
        self.mox.StubOutWithMock(self.compute.volume_manager,
                                 'remove_compute_volume')
        for v in i_ref['volumes']:
            self.compute.volume_manager.remove_compute_volume(c, v['id'])
        self.mox.StubOutWithMock(self.compute.driver, 'unfilter_instance')
        self.compute.driver.unfilter_instance(i_ref, [])

        # executing
        self.mox.ReplayAll()
        ret = self.compute.post_live_migration(c, i_ref, dest)

        # make sure every data is rewritten to dest
        i_ref = db.instance_get(c, i_ref['id'])
        c1 = (i_ref['host'] == dest)
        flo_refs = db.floating_ip_get_all_by_host(c, dest)
        c2 = (len(flo_refs) != 0 and flo_refs[0]['address'] == flo_addr)

        # post operaton
        self.assertTrue(c1 and c2)
        db.instance_destroy(c, instance_id)
        db.volume_destroy(c, v_ref['id'])
        db.floating_ip_destroy(c, flo_addr)
Example #38
0
    def test_copy_volume_to_image_status_use(self):
        dst_fd, dst_path = tempfile.mkstemp()
        os.close(dst_fd)

        def fake_local_path(volume):
            return dst_path

        self.stubs.Set(self.volume.driver, "local_path", fake_local_path)

        # image_id = '70a599e0-31e7-49b7-b260-868f441e862b'
        image_id = "a440c04b-79fa-479c-bed1-0b816eaec379"
        # creating volume testdata
        volume_id = 1
        db.volume_create(
            self.context,
            {
                "id": volume_id,
                "updated_at": datetime.datetime(1, 1, 1, 1, 1, 1),
                "display_description": "Test Desc",
                "size": 20,
                "status": "uploading",
                "instance_uuid": "b21f957d-a72f-4b93-b5a5-45b1161abb02",
                "host": "dummy",
            },
        )

        try:
            # start test
            self.volume.copy_volume_to_image(self.context, volume_id, image_id)

            volume = db.volume_get(self.context, volume_id)
            self.assertEqual(volume["status"], "in-use")
        finally:
            # cleanup
            db.volume_destroy(self.context, volume_id)
            os.unlink(dst_path)
Example #39
0
    def test_copy_volume_to_image_exception(self):
        dst_fd, dst_path = tempfile.mkstemp()
        os.close(dst_fd)

        def fake_local_path(volume):
            return dst_path

        self.stubs.Set(self.volume.driver, "local_path", fake_local_path)

        image_id = "aaaaaaaa-0000-0000-0000-000000000000"
        # creating volume testdata
        volume_id = 1
        db.volume_create(
            self.context,
            {
                "id": volume_id,
                "updated_at": datetime.datetime(1, 1, 1, 1, 1, 1),
                "display_description": "Test Desc",
                "size": 20,
                "status": "in-use",
                "host": "dummy",
            },
        )

        try:
            # start test
            self.assertRaises(
                exception.ImageNotFound, self.volume.copy_volume_to_image, self.context, volume_id, image_id
            )

            volume = db.volume_get(self.context, volume_id)
            self.assertEqual(volume["status"], "available")
        finally:
            # cleanup
            db.volume_destroy(self.context, volume_id)
            os.unlink(dst_path)
Example #40
0
    def test_live_migration_raises_exception(self):
        """Confirms recover method is called when exceptions are raised."""
        # Skip if non-libvirt environment
        if not self.lazy_load_library_exists():
            return

        # Preparing data
        self.compute = utils.import_object(FLAGS.compute_manager)
        instance_dict = {'host': 'fake', 'state': power_state.RUNNING,
                         'state_description': 'running'}
        instance_ref = db.instance_create(self.context, self.test_instance)
        instance_ref = db.instance_update(self.context, instance_ref['id'],
                                          instance_dict)
        vol_dict = {'status': 'migrating', 'size': 1}
        volume_ref = db.volume_create(self.context, vol_dict)
        db.volume_attached(self.context, volume_ref['id'], instance_ref['id'],
                           '/dev/fake')

        # Preparing mocks
        vdmock = self.mox.CreateMock(libvirt.virDomain)
        self.mox.StubOutWithMock(vdmock, "migrateToURI")
        vdmock.migrateToURI(FLAGS.live_migration_uri % 'dest',
                            mox.IgnoreArg(),
                            None, FLAGS.live_migration_bandwidth).\
                            AndRaise(libvirt.libvirtError('ERR'))

        def fake_lookup(instance_name):
            if instance_name == instance_ref.name:
                return vdmock

        self.create_fake_libvirt_mock(lookupByName=fake_lookup)

        # Start test
        self.mox.ReplayAll()
        conn = libvirt_conn.LibvirtConnection(False)
        self.assertRaises(libvirt.libvirtError,
                      conn._live_migration,
                      self.context, instance_ref, 'dest', '',
                      self.compute.recover_live_migration)

        instance_ref = db.instance_get(self.context, instance_ref['id'])
        self.assertTrue(instance_ref['state_description'] == 'running')
        self.assertTrue(instance_ref['state'] == power_state.RUNNING)
        volume_ref = db.volume_get(self.context, volume_ref['id'])
        self.assertTrue(volume_ref['status'] == 'in-use')

        db.volume_destroy(self.context, volume_ref['id'])
        db.instance_destroy(self.context, instance_ref['id'])
Example #41
0
    def _attach_volume(self):
        """Attach volumes to an instance. """
        volume_id_list = []
        for index in xrange(3):
            vol = {}
            vol['size'] = 0
            vol_ref = db.volume_create(self.context, vol)
            self.volume.create_volume(self.context, vol_ref['id'])
            vol_ref = db.volume_get(self.context, vol_ref['id'])

            # each volume has a different mountpoint
            mountpoint = "/dev/sd" + chr((ord('b') + index))
            db.volume_attached(self.context, vol_ref['id'], self.instance_uuid,
                               mountpoint)
            volume_id_list.append(vol_ref['id'])

        return volume_id_list
Example #42
0
 def test_force_delete(self):
     # admin context
     ctx = context.RequestContext('admin', 'fake', is_admin=True)
     ctx.elevated()  # add roles
     # current status is creating
     volume = db.volume_create(ctx, {'status': 'creating'})
     req = webob.Request.blank('/v1/fake/volumes/%s/action' % volume['id'])
     req.method = 'POST'
     req.headers['content-type'] = 'application/json'
     req.body = jsonutils.dumps({'os-force_delete': {}})
     # attach admin context to request
     req.environ['nova.context'] = ctx
     resp = req.get_response(app())
     # request is accepted
     self.assertEquals(resp.status_int, 202)
     # volume is deleted
     self.assertRaises(exception.NotFound, db.volume_get, ctx, volume['id'])
Example #43
0
 def test_reset_status_as_non_admin(self):
     # current status is 'error'
     volume = db.volume_create(context.get_admin_context(),
                               {'status': 'error'})
     req = webob.Request.blank('/v1/fake/volumes/%s/action' % volume['id'])
     req.method = 'POST'
     req.headers['content-type'] = 'application/json'
     # request changing status to available
     req.body = jsonutils.dumps({'os-reset_status': {'status':
                                                     'available'}})
     # non-admin context
     req.environ['nova.context'] = context.RequestContext('fake', 'fake')
     resp = req.get_response(app())
     # request is not authorized
     self.assertEquals(resp.status_int, 403)
     volume = db.volume_get(context.get_admin_context(), volume['id'])
     # status is still 'error'
     self.assertEquals(volume['status'], 'error')
Example #44
0
 def test_invalid_status_for_volume(self):
     # admin context
     ctx = context.RequestContext('admin', 'fake', is_admin=True)
     ctx.elevated()  # add roles
     # current status is available
     volume = db.volume_create(ctx, {'status': 'available'})
     req = webob.Request.blank('/v1/fake/volumes/%s/action' % volume['id'])
     req.method = 'POST'
     req.headers['content-type'] = 'application/json'
     # 'invalid' is not a valid status
     req.body = jsonutils.dumps({'os-reset_status': {'status': 'invalid'}})
     # attach admin context to request
     req.environ['nova.context'] = ctx
     resp = req.get_response(app())
     # bad request
     self.assertEquals(resp.status_int, 400)
     volume = db.volume_get(ctx, volume['id'])
     # status is still 'available'
     self.assertEquals(volume['status'], 'available')
Example #45
0
    def test_live_migration_src_check_volume_node_not_alive(self):
        """Raise exception when volume node is not alive."""

        instance_id = self._create_instance()
        i_ref = db.instance_get(self.context, instance_id)
        dic = {'instance_id': instance_id, 'size': 1}
        v_ref = db.volume_create(self.context, {'instance_id': instance_id,
                                                'size': 1})
        t1 = datetime.datetime.utcnow() - datetime.timedelta(1)
        dic = {'created_at': t1, 'updated_at': t1, 'binary': 'nova-volume',
               'topic': 'volume', 'report_count': 0}
        s_ref = db.service_create(self.context, dic)

        try:
            self.scheduler.driver.schedule_live_migration(self.context,
                                                          instance_id,
                                                          i_ref['host'])
        except exception.Invalid, e:
            c = (e.message.find('volume node is not alive') >= 0)
Example #46
0
 def test_reset_status_as_admin(self):
     # admin context
     ctx = context.RequestContext('admin', 'fake', is_admin=True)
     ctx.elevated()  # add roles
     # current status is available
     volume = db.volume_create(ctx, {'status': 'available'})
     req = webob.Request.blank('/v1/fake/volumes/%s/action' % volume['id'])
     req.method = 'POST'
     req.headers['content-type'] = 'application/json'
     # request status of 'error'
     req.body = jsonutils.dumps({'os-reset_status': {'status': 'error'}})
     # attach admin context to request
     req.environ['nova.context'] = ctx
     resp = req.get_response(app())
     # request is accepted
     self.assertEquals(resp.status_int, 202)
     volume = db.volume_get(ctx, volume['id'])
     # status changed to 'error'
     self.assertEquals(volume['status'], 'error')
Example #47
0
    def test_scheduler_live_migration_with_volume(self):
        """scheduler_live_migration() works correctly as expected.

        Also, checks instance state is changed from 'running' -> 'migrating'.

        """

        instance_id = self._create_instance()
        i_ref = db.instance_get(self.context, instance_id)
        dic = {'instance_id': instance_id, 'size': 1}
        v_ref = db.volume_create(self.context, dic)

        # cannot check 2nd argument b/c the addresses of instance object
        # is different.
        driver_i = self.scheduler.driver
        nocare = mox.IgnoreArg()
        self.mox.StubOutWithMock(driver_i, '_live_migration_src_check')
        self.mox.StubOutWithMock(driver_i, '_live_migration_dest_check')
        self.mox.StubOutWithMock(driver_i, '_live_migration_common_check')
        driver_i._live_migration_src_check(nocare, nocare)
        driver_i._live_migration_dest_check(nocare, nocare, i_ref['host'])
        driver_i._live_migration_common_check(nocare, nocare, i_ref['host'])
        self.mox.StubOutWithMock(rpc, 'cast', use_mock_anything=True)
        kwargs = {'instance_id': instance_id, 'dest': i_ref['host']}
        rpc.cast(self.context,
                 db.queue_get_for(nocare, FLAGS.compute_topic, i_ref['host']),
                 {
                     "method": 'live_migration',
                     "args": kwargs
                 })

        self.mox.ReplayAll()
        self.scheduler.live_migration(self.context,
                                      FLAGS.compute_topic,
                                      instance_id=instance_id,
                                      dest=i_ref['host'])

        i_ref = db.instance_get(self.context, instance_id)
        self.assertTrue(i_ref['state_description'] == 'migrating')
        db.instance_destroy(self.context, instance_id)
        db.volume_destroy(self.context, v_ref['id'])
Example #48
0
    def _attach_volume(self):
        """Attach volumes to an instance. This function also sets
           a fake log message."""
        volume_id_list = []
        for index in xrange(3):
            vol = {}
            vol['size'] = 0
            volume_id = db.volume_create(self.context, vol)['id']
            self.volume.create_volume(self.context, volume_id)

            # each volume has a different mountpoint
            mountpoint = "/dev/sd" + chr((ord('b') + index))
            db.volume_attached(self.context, volume_id, self.instance_id,
                               mountpoint)

            (shelf_id,
             blade_id) = db.volume_get_shelf_and_blade(self.context, volume_id)
            self.output += "%s %s eth0 /dev/nova-volumes/vol-foo auto run\n" \
                      % (shelf_id, blade_id)

            volume_id_list.append(volume_id)

        return volume_id_list
Example #49
0
 def test_invalid_status_for_snapshot(self):
     # admin context
     ctx = context.RequestContext('admin', 'fake', is_admin=True)
     ctx.elevated()  # add roles
     # snapshot in 'available'
     volume = db.volume_create(ctx, {})
     snapshot = db.snapshot_create(ctx, {'status': 'available',
                                         'volume_id': volume['id']})
     req = webob.Request.blank('/v1/fake/snapshots/%s/action' %
                               snapshot['id'])
     req.method = 'POST'
     req.headers['content-type'] = 'application/json'
     # 'attaching' is not a valid status for snapshots
     req.body = jsonutils.dumps({'os-reset_status': {'status':
                                                     'attaching'}})
     # attach admin context to request
     req.environ['nova.context'] = ctx
     resp = req.get_response(app())
     # request is accepted
     print resp
     self.assertEquals(resp.status_int, 400)
     snapshot = db.snapshot_get(ctx, snapshot['id'])
     # status is still 'available'
     self.assertEquals(snapshot['status'], 'available')
Example #50
0
 def _create_volume(self):
     """Create a test volume"""
     vol = {}
     vol['size'] = 1
     vol['availability_zone'] = 'test'
     return db.volume_create(self.context, vol)['id']