Ejemplo n.º 1
0
    def test_bless_instance_migrate(self):
        self.vmsconn.set_return_val(
            "bless", ("newname", "migration_url", ["file1", "file2", "file3"]))
        self.vmsconn.set_return_val("post_bless",
                                    ["file1_ref", "file2_ref", "file3_ref"])
        self.vmsconn.set_return_val("bless_cleanup", None)

        blessed_uuid = utils.create_instance(self.context)
        pre_bless_instance = db.instance_get_by_uuid(self.context,
                                                     blessed_uuid)
        migration_url = self.gridcentric.bless_instance(
            self.context,
            instance_uuid=blessed_uuid,
            migration_url="mcdist://migrate_addr")
        post_bless_instance = db.instance_get_by_uuid(self.context,
                                                      blessed_uuid)

        self.assertEquals(pre_bless_instance['vm_state'],
                          post_bless_instance['vm_state'])
        self.assertEquals("migration_url", migration_url)
        metadata = db.instance_metadata_get(self.context, blessed_uuid)
        self.assertEquals("file1_ref,file2_ref,file3_ref", metadata['images'])
        self.assertEquals(pre_bless_instance['launched_at'],
                          post_bless_instance['launched_at'])
        self.assertFalse(pre_bless_instance.get('disable_terminate', None),
                         post_bless_instance.get('disable_terminate', None))
Ejemplo n.º 2
0
    def test_bless_instance(self):
        instance_uuid = utils.create_instance(self.context)

        num_instance_before = len(db.instance_get_all(self.context))

        blessed_instance = self.gridcentric_api.bless_instance(
            self.context, instance_uuid)

        self.assertEquals(vm_states.BUILDING, blessed_instance['vm_state'])
        # Ensure that we have a 2nd instance in the database that is a "clone"
        # of our original instance.
        instances = db.instance_get_all(self.context)
        self.assertTrue(
            len(instances) == (num_instance_before + 1),
            "There should be one new instance after blessing.")

        # The virtual machine should be marked that it is now blessed.
        metadata = db.instance_metadata_get(self.context,
                                            blessed_instance['uuid'])
        self.assertTrue(
            metadata.has_key('blessed_from'),
            "The instance should have a bless metadata after being blessed.")
        self.assertTrue(metadata['blessed_from'] == '%s' % instance_uuid,
            "The instance should have the blessed_from metadata set to true after being blessed. " \
          + "(value=%s)" % (metadata['blessed_from']))
Ejemplo n.º 3
0
 def test_launch_without_user_data(self):
     instance_uuid = utils.create_instance(self.context)
     blessed_instance = self.gridcentric_api.bless_instance(self.context, instance_uuid)
     blessed_instance_uuid = blessed_instance['uuid']
     launched_instance = self.gridcentric_api.launch_instance(self.context, blessed_instance_uuid, params={})
     user_data = launched_instance['user_data']
     self.assertEqual(user_data, '')
Ejemplo n.º 4
0
    def test_launch_instance_twice(self):

        instance_uuid = utils.create_instance(self.context)
        blessed_instance = self.gridcentric_api.bless_instance(
            self.context, instance_uuid)
        blessed_instance_uuid = blessed_instance['uuid']

        launched_instance = self.gridcentric_api.launch_instance(
            self.context, blessed_instance_uuid)
        launched_instance_uuid = launched_instance['uuid']
        metadata = db.instance_metadata_get(self.context,
                                            launched_instance['uuid'])
        self.assertTrue(
            metadata.has_key('launched_from'),
            "The instance should have a 'launched from' metadata after being launched."
        )
        self.assertTrue(metadata['launched_from'] == '%s' % (blessed_instance_uuid),
            "The instance should have the 'launched from' metadata set to blessed instanced id after being launched. " \
          + "(value=%s)" % (metadata['launched_from']))

        launched_instance = self.gridcentric_api.launch_instance(
            self.context, blessed_instance_uuid)
        launched_instance_uuid = launched_instance['uuid']
        metadata = db.instance_metadata_get(self.context,
                                            launched_instance['uuid'])
        self.assertTrue(
            metadata.has_key('launched_from'),
            "The instance should have a 'launched from' metadata after being launched."
        )
        self.assertTrue(metadata['launched_from'] == '%s' % (blessed_instance_uuid),
            "The instance should have the 'launched from' metadata set to blessed instanced id after being launched. " \
          + "(value=%s)" % (metadata['launched_from']))
Ejemplo n.º 5
0
 def test_launch_no_name(self):
     instance_uuid = utils.create_instance(self.context)
     blessed_instance = self.gridcentric_api.bless_instance(self.context, instance_uuid)
     blessed_instance_uuid = blessed_instance['uuid']
     launched_instance = self.gridcentric_api.launch_instance(self.context, blessed_instance_uuid, params={})
     name = launched_instance['display_name']
     self.assertEqual(name, 'None-0-clone')
     self.assertEqual(launched_instance['hostname'], 'none-0-clone')
Ejemplo n.º 6
0
    def test_migrate_bad_destination(self):
        instance_uuid = utils.create_instance(self.context, {"task_state":task_states.MIGRATING})

        try:
            self.gridcentric_api.migrate_instance(self.context, instance_uuid, "no_destination")
            self.fail("Should not be able to migrate a non-existent destination.")
        except exception.NovaException:
            pass
Ejemplo n.º 7
0
    def test_launch_not_blessed_image(self):

        instance_id = utils.create_instance(self.context)

        try:
            self.gridcentric.launch_instance(self.context, instance_id)
            self.fail("Should not be able to launch and instance that has not been blessed.")
        except exception.Error, e:
            pass # Success!
Ejemplo n.º 8
0
 def test_launch_with_user_data(self):
     instance_uuid = utils.create_instance(self.context)
     blessed_instance = self.gridcentric_api.bless_instance(self.context, instance_uuid)
     blessed_instance_uuid = blessed_instance['uuid']
     test_data = "here is some test user data"
     test_data_encoded = base64.b64encode(test_data)
     launched_instance = self.gridcentric_api.launch_instance(self.context, blessed_instance_uuid, params={'user_data': test_data_encoded})
     user_data = launched_instance['user_data']
     self.assertEqual(user_data, test_data_encoded)
Ejemplo n.º 9
0
 def test_launch_without_user_data(self):
     instance_uuid = utils.create_instance(self.context)
     blessed_instance = self.gridcentric_api.bless_instance(
         self.context, instance_uuid)
     blessed_instance_uuid = blessed_instance['uuid']
     launched_instance = self.gridcentric_api.launch_instance(
         self.context, blessed_instance_uuid, params={})
     user_data = launched_instance['user_data']
     self.assertEqual(user_data, '')
Ejemplo n.º 10
0
 def test_launch_no_name(self):
     instance_uuid = utils.create_instance(self.context)
     blessed_instance = self.gridcentric_api.bless_instance(
         self.context, instance_uuid)
     blessed_instance_uuid = blessed_instance['uuid']
     launched_instance = self.gridcentric_api.launch_instance(
         self.context, blessed_instance_uuid, params={})
     name = launched_instance['display_name']
     self.assertEqual(name, 'None-0-clone')
     self.assertEqual(launched_instance['hostname'], 'none-0-clone')
Ejemplo n.º 11
0
    def test_reset_host_non_migrating_instance(self):

        host = "test-host"
        instance_uuid = utils.create_instance(self.context, {'host': host})
        self.gridcentric.host = host
        self.gridcentric._refresh_host(self.context)

        instance = db.instance_get_by_uuid(self.context, instance_uuid)
        self.assertEquals(host, instance['host'])
        self.assertEquals(None, instance['task_state'])
Ejemplo n.º 12
0
    def test_migrate_migrating_instance(self):
        instance_uuid = utils.create_instance(self.context, {"task_state":task_states.MIGRATING})
        # Create a service so that one can be found by the api.
        utils.create_gridcentric_service(self.context)

        try:
            self.gridcentric_api.migrate_instance(self.context, instance_uuid, None)
            self.fail("Should not be able to migrate a migrating instance.")
        except exception.NovaException:
            pass
Ejemplo n.º 13
0
    def test_migrate_inactive_instance(self):
        instance_uuid = utils.create_instance(self.context, {"vm_state":vm_states.BUILDING})
        # Create a service so that one can be found by the api.
        utils.create_gridcentric_service(self.context)

        try:
            self.gridcentric_api.migrate_instance(self.context, instance_uuid, None)
            self.fail("Should not be able to migrate an inactive instance.")
        except exception.NovaException:
            pass
Ejemplo n.º 14
0
    def test_migrate_instance_no_destination(self):
        instance_uuid = utils.create_instance(self.context, {"vm_state":vm_states.ACTIVE})
        # Create a service so that one can be found by the api.
        utils.create_gridcentric_service(self.context)

        self.gridcentric_api.migrate_instance(self.context, instance_uuid, None)

        instance_ref = db.instance_get_by_uuid(self.context, instance_uuid)
        self.assertEquals(task_states.MIGRATING, instance_ref['task_state'])
        self.assertEquals(vm_states.ACTIVE, instance_ref['vm_state'])
Ejemplo n.º 15
0
    def test_migrate_instance_with_destination(self):
        instance_uuid = utils.create_instance(self.context, {"vm_state":vm_states.ACTIVE})
        gc_service = utils.create_gridcentric_service(self.context)
        dest = gc_service['host']

        self.gridcentric_api.migrate_instance(self.context, instance_uuid, dest)

        instance_ref = db.instance_get_by_uuid(self.context, instance_uuid)
        self.assertEquals(task_states.MIGRATING, instance_ref['task_state'])
        self.assertEquals(vm_states.ACTIVE, instance_ref['vm_state'])
Ejemplo n.º 16
0
    def test_bless_instance_twice(self):

        instance_id = utils.create_instance(self.context)

        num_instance_before = len(db.instance_get_all(self.context))
        self.gridcentric.bless_instance(self.context, instance_id)
        self.gridcentric.bless_instance(self.context, instance_id)

        instances = db.instance_get_all(self.context)
        self.assertTrue(len(instances) == num_instance_before + 2,
                        "There should be 2 more instances because we blessed twice.")
Ejemplo n.º 17
0
    def test_migrate_bad_destination(self):
        instance_uuid = utils.create_instance(
            self.context, {"task_state": task_states.MIGRATING})

        try:
            self.gridcentric_api.migrate_instance(self.context, instance_uuid,
                                                  "no_destination")
            self.fail(
                "Should not be able to migrate a non-existent destination.")
        except exception.NovaException:
            pass
Ejemplo n.º 18
0
    def test_launch_not_blessed_image(self):

        instance_uuid = utils.create_instance(self.context)

        try:
            self.gridcentric_api.launch_instance(self.context, instance_uuid)
            self.fail(
                "Should not be able to launch and instance that has not been blessed."
            )
        except exception.NovaException, e:
            pass  # Success!
Ejemplo n.º 19
0
    def test_reset_host_non_migrating_instance(self):

        host = "test-host"
        instance_uuid = utils.create_instance(self.context,
                                             {'host': host})
        self.gridcentric.host = host
        self.gridcentric._refresh_host(self.context)

        instance = db.instance_get_by_uuid(self.context, instance_uuid)
        self.assertEquals(host, instance['host'])
        self.assertEquals(None, instance['task_state'])
Ejemplo n.º 20
0
    def test_bless_quota(self):

        def assert_quotas(expected_increased):
            _pre_usages = dict(pre_usages)
            _pre_usages.pop('project_id', None)
            post_usages = sqlalchemy_db.quota_usage_get_all_by_project(self.context, self.context.project_id)
            # Need to assert something about the quota consumption
            for quota_key in ['instances', 'ram', 'cores']:
                pre_usage = _pre_usages.pop(quota_key)
                self.assertEquals(pre_usage.get('in_use',0) + expected_increased[quota_key],
                              post_usages[quota_key].get('in_use',0))
                self.assertEquals(pre_usage.get('reserved',0), post_usages[quota_key].get('reserved',0))

            for key, quota_usage in _pre_usages.iteritems():
                self.assertEquals(quota_usage.get('reserved', 0), post_usages[key].get('reserved', 0))
                self.assertEquals(quota_usage.get('in_use', 0), post_usages[key].get('in_use', 0))


        instance_uuid = utils.create_instance(self.context)
        instance = db.instance_get_by_uuid(self.context, instance_uuid)

        # Set the quota so that we can have two blessed instances (+ the instance we are blessing).
        db.quota_create(self.context, self.context.project_id,
                        'ram', 3 * instance['memory_mb'])

        pre_usages = sqlalchemy_db.quota_usage_get_all_by_project(self.context, self.context.project_id)

        # The amount of resources a blessed instance consumes.
        blessed_uuids = []
        for i in range(1, 3):
            blessed_uuids.append(
                        self.gridcentric_api.bless_instance(self.context, instance_uuid)['uuid'])
            expected = dict(zip(['instances', 'ram', 'cores'],
                                map(lambda x: i * x,
                                    [1, instance['memory_mb'], instance['vcpus']])))

            assert_quotas(expected)

        try:
            self.gridcentric_api.bless_instance(self.context, instance_uuid)
            self.fail("We should not have the quota to bless one more instance.")
        except exception.TooManyInstances:
            pass

        # Discard the blessed uuid and ensure that the quota increases.
        remaining = len(blessed_uuids)
        for blessed_uuid in blessed_uuids:
            self.gridcentric_api.discard_instance(self.context, blessed_uuid)
            remaining -= 1
            expected = dict(zip(['instances', 'ram', 'cores'],
                                map(lambda x: remaining * x,
                                    [1, instance['memory_mb'], instance['vcpus']])))
            assert_quotas(expected)
Ejemplo n.º 21
0
    def test_reset_host_different_host_instance(self):

        host = "test-host"
        instance_uuid = utils.create_instance(self.context,
                                             {'task_state':task_states.MIGRATING,
                                              'host': host})
        self.gridcentric.host = 'different-host'
        self.gridcentric._refresh_host(self.context)

        instance = db.instance_get_by_uuid(self.context, instance_uuid)
        self.assertEquals(host, instance['host'])
        self.assertEquals(task_states.MIGRATING, instance['task_state'])
Ejemplo n.º 22
0
    def test_migrate_migrating_instance(self):
        instance_uuid = utils.create_instance(
            self.context, {"task_state": task_states.MIGRATING})
        # Create a service so that one can be found by the api.
        utils.create_gridcentric_service(self.context)

        try:
            self.gridcentric_api.migrate_instance(self.context, instance_uuid,
                                                  None)
            self.fail("Should not be able to migrate a migrating instance.")
        except exception.NovaException:
            pass
Ejemplo n.º 23
0
 def test_launch_with_security_groups(self):
     instance_uuid = utils.create_instance(self.context)
     blessed_instance = self.gridcentric_api.bless_instance(self.context,
                                                            instance_uuid)
     blessed_instance_uuid = blessed_instance['uuid']
     sg = utils.create_security_group(self.context,
                                 {'name': 'test-sg',
                                  'description': 'test security group'})
     inst = self.gridcentric_api.launch_instance(self.context,
         blessed_instance_uuid, params={'security_groups': ['test-sg']})
     self.assertEqual(inst['security_groups'][0].id, sg.id)
     self.assertEqual(1, len(inst['security_groups']))
Ejemplo n.º 24
0
    def test_bless_a_blessed_instance(self):

        instance_id = utils.create_instance(self.context)
        self.gridcentric.bless_instance(self.context, instance_id)

        blessed_id = instance_id + 1
        no_exception = False
        try:
            self.gridcentric.bless_instance(self.context, blessed_id)
            no_exception = True
        except Exception, e:
            pass # success
Ejemplo n.º 25
0
    def test_migrate_instance_no_destination(self):
        instance_uuid = utils.create_instance(self.context,
                                              {"vm_state": vm_states.ACTIVE})
        # Create a service so that one can be found by the api.
        utils.create_gridcentric_service(self.context)

        self.gridcentric_api.migrate_instance(self.context, instance_uuid,
                                              None)

        instance_ref = db.instance_get_by_uuid(self.context, instance_uuid)
        self.assertEquals(task_states.MIGRATING, instance_ref['task_state'])
        self.assertEquals(vm_states.ACTIVE, instance_ref['vm_state'])
Ejemplo n.º 26
0
    def test_migrate_inactive_instance(self):
        instance_uuid = utils.create_instance(self.context,
                                              {"vm_state": vm_states.BUILDING})
        # Create a service so that one can be found by the api.
        utils.create_gridcentric_service(self.context)

        try:
            self.gridcentric_api.migrate_instance(self.context, instance_uuid,
                                                  None)
            self.fail("Should not be able to migrate an inactive instance.")
        except exception.NovaException:
            pass
Ejemplo n.º 27
0
    def test_check_delete(self):

        instance_uuid = utils.create_instance(self.context)
        # This should not raise an error because the instance is not blessed.
        self.gridcentric_api.check_delete(self.context, instance_uuid)

        blessed_instance_uuid = utils.create_blessed_instance(self.context)
        try:
            self.gridcentric_api.check_delete(self.context, blessed_instance_uuid)
            self.fail("Check delete should fail for a blessed instance.")
        except exception.NovaException:
            pass
Ejemplo n.º 28
0
    def test_migrate_instance_with_destination(self):
        instance_uuid = utils.create_instance(self.context,
                                              {"vm_state": vm_states.ACTIVE})
        gc_service = utils.create_gridcentric_service(self.context)
        dest = gc_service['host']

        self.gridcentric_api.migrate_instance(self.context, instance_uuid,
                                              dest)

        instance_ref = db.instance_get_by_uuid(self.context, instance_uuid)
        self.assertEquals(task_states.MIGRATING, instance_ref['task_state'])
        self.assertEquals(vm_states.ACTIVE, instance_ref['vm_state'])
Ejemplo n.º 29
0
    def test_bless_instance_twice(self):

        instance_uuid = utils.create_instance(self.context)

        num_instance_before = len(db.instance_get_all(self.context))
        self.gridcentric_api.bless_instance(self.context, instance_uuid)
        self.gridcentric_api.bless_instance(self.context, instance_uuid)

        instances = db.instance_get_all(self.context)
        self.assertTrue(
            len(instances) == num_instance_before + 2,
            "There should be 2 more instances because we blessed twice.")
    def test_bless_a_blessed_instance(self):

        instance_uuid = utils.create_instance(self.context)
        blessed_instance = self.gridcentric_api.bless_instance(self.context, instance_uuid)

        blessed_uuid = blessed_instance['uuid']
        no_exception = False
        try:
            self.gridcentric_api.bless_instance(self.context, blessed_uuid)
            no_exception = True
        except Exception, e:
            pass # success
Ejemplo n.º 31
0
    def test_reset_host_different_host_instance(self):

        host = "test-host"
        instance_uuid = utils.create_instance(self.context, {
            'task_state': task_states.MIGRATING,
            'host': host
        })
        self.gridcentric.host = 'different-host'
        self.gridcentric._refresh_host(self.context)

        instance = db.instance_get_by_uuid(self.context, instance_uuid)
        self.assertEquals(host, instance['host'])
        self.assertEquals(task_states.MIGRATING, instance['task_state'])
Ejemplo n.º 32
0
    def test_check_delete(self):

        instance_uuid = utils.create_instance(self.context)
        # This should not raise an error because the instance is not blessed.
        self.gridcentric_api.check_delete(self.context, instance_uuid)

        blessed_instance_uuid = utils.create_blessed_instance(self.context)
        try:
            self.gridcentric_api.check_delete(self.context,
                                              blessed_instance_uuid)
            self.fail("Check delete should fail for a blessed instance.")
        except exception.NovaException:
            pass
Ejemplo n.º 33
0
    def test_bless_a_non_active_instance(self):

        instance_id = utils.create_instance(self.context, {'vm_state':vm_states.BUILDING})

        no_exception = False
        try:
            self.gridcentric.bless_instance(self.context, instance_id)
            no_exception = True
        except:
            pass # success

        if no_exception:
            self.fail("Should not be able to bless an instance in a non-active state")
Ejemplo n.º 34
0
 def test_launch_with_user_data(self):
     instance_uuid = utils.create_instance(self.context)
     blessed_instance = self.gridcentric_api.bless_instance(
         self.context, instance_uuid)
     blessed_instance_uuid = blessed_instance['uuid']
     test_data = "here is some test user data"
     test_data_encoded = base64.b64encode(test_data)
     launched_instance = self.gridcentric_api.launch_instance(
         self.context,
         blessed_instance_uuid,
         params={'user_data': test_data_encoded})
     user_data = launched_instance['user_data']
     self.assertEqual(user_data, test_data_encoded)
Ejemplo n.º 35
0
    def test_discard_a_blessed_instance(self):

        instance_id = utils.create_instance(self.context)
        self.gridcentric.bless_instance(self.context, instance_id)
        blessed_id = instance_id + 1

        self.gridcentric.discard_instance(self.context, blessed_id)

        try:
            db.instance_get(self.context, blessed_id)
            self.fail("The blessed instance should no longer exists after being discarded.")
        except exception.InstanceNotFound:
            pass
Ejemplo n.º 36
0
 def test_launch_default_security_group(self):
     sg = utils.create_security_group(self.context, {
         'name': 'test-sg',
         'description': 'test security group'
     })
     instance_uuid = utils.create_instance(
         self.context, {'security_groups': [sg['name']]})
     blessed_instance = self.gridcentric_api.bless_instance(
         self.context, instance_uuid)
     blessed_instance_uuid = blessed_instance['uuid']
     inst = self.gridcentric_api.launch_instance(self.context,
                                                 blessed_instance_uuid,
                                                 params={})
     self.assertEqual(inst['security_groups'][0].id, sg.id)
Ejemplo n.º 37
0
    def test_launch_instance(self):

        instance_id = utils.create_instance(self.context)
        self.gridcentric.bless_instance(self.context, instance_id)
        blessed_instance_id = instance_id + 1
        self.gridcentric.launch_instance(self.context, blessed_instance_id)

        launched_instance_id = blessed_instance_id + 1
        metadata = db.instance_metadata_get(self.context, launched_instance_id)
        self.assertTrue(metadata.has_key('launched_from'),
                        "The instance should have a 'launched from' metadata after being launched.")
        self.assertTrue(metadata['launched_from'] == '%s' % (blessed_instance_id),
            "The instance should have the 'launched from' metadata set to blessed instanced id after being launched. " \
          + "(value=%s)" % (metadata['launched_from']))
Ejemplo n.º 38
0
    def test_bless_a_blessed_instance(self):

        instance_uuid = utils.create_instance(self.context)
        blessed_instance = self.gridcentric_api.bless_instance(self.context, instance_uuid)

        blessed_uuid = blessed_instance['uuid']
        no_exception = False
        try:
            self.gridcentric_api.bless_instance(self.context, blessed_uuid)
            no_exception = True
        except Exception:
            pass # success

        if no_exception:
            self.fail("Should not be able to bless a blessed instance.")
Ejemplo n.º 39
0
    def test_launch_instance_migrate(self):

        self.vmsconn.set_return_val("launch", None)
        instance_uuid = utils.create_instance(self.context, {'vm_state': vm_states.ACTIVE})
        pre_launch_instance = db.instance_get_by_uuid(self.context, instance_uuid)

        self.gridcentric.launch_instance(self.context, instance_uuid=instance_uuid,
                                         migration_url="migration_url")

        post_launch_instance = db.instance_get_by_uuid(self.context, instance_uuid)

        self.assertEquals(vm_states.ACTIVE, post_launch_instance['vm_state'])
        self.assertEquals(None, post_launch_instance['task_state'])
        self.assertEquals(pre_launch_instance['launched_at'], post_launch_instance['launched_at'])
        self.assertEquals(self.gridcentric.host, post_launch_instance['host'])
Ejemplo n.º 40
0
    def test_reset_host_not_local_src(self):

        src_host = "src-test-host"
        dst_host = "dst-test-host"
        instance_uuid = utils.create_instance(self.context,
                                             {'task_state':task_states.MIGRATING,
                                              'host': src_host,
                                              'metadata': {'gc_src_host': src_host,
                                                           'gc_dst_host': dst_host}})
        self.gridcentric.host = src_host
        self.gridcentric._refresh_host(self.context)

        instance = db.instance_get_by_uuid(self.context, instance_uuid)
        self.assertEquals(dst_host, instance['host'])
        self.assertEquals(task_states.MIGRATING, instance['task_state'])
Ejemplo n.º 41
0
    def test_bless_a_non_active_instance(self):

        instance_uuid = utils.create_instance(self.context,
                                              {'vm_state': vm_states.BUILDING})

        no_exception = False
        try:
            self.gridcentric_api.bless_instance(self.context, instance_uuid)
            no_exception = True
        except:
            pass  # success

        if no_exception:
            self.fail(
                "Should not be able to bless an instance in a non-active state"
            )
Ejemplo n.º 42
0
    def test_bless_a_blessed_instance(self):

        instance_uuid = utils.create_instance(self.context)
        blessed_instance = self.gridcentric_api.bless_instance(
            self.context, instance_uuid)

        blessed_uuid = blessed_instance['uuid']
        no_exception = False
        try:
            self.gridcentric_api.bless_instance(self.context, blessed_uuid)
            no_exception = True
        except Exception:
            pass  # success

        if no_exception:
            self.fail("Should not be able to bless a blessed instance.")
Ejemplo n.º 43
0
    def test_discard_a_blessed_instance_with_remaining_launched_ones(self):

        instance_id = utils.create_instance(self.context)
        self.gridcentric.bless_instance(self.context, instance_id)
        blessed_id = instance_id + 1

        self.gridcentric.launch_instance(self.context, blessed_id)

        no_exception = False
        try:
            self.gridcentric.discard_instance(self.context, blessed_id)
            no_exception = True
        except:
            pass  # success

        if no_exception:
            self.fail("Should not be able to discard a blessed instance while launched ones still remain.")
Ejemplo n.º 44
0
    def test_bless_a_launched_instance(self):

        instance_id = utils.create_instance(self.context)
        self.gridcentric.bless_instance(self.context, instance_id)
        blessed_id = instance_id + 1

        self.gridcentric.launch_instance(self.context, blessed_id)
        launched_id = blessed_id + 1

        no_exception = False
        try:
            self.gridcentric.bless_instance(self.context, launched_id)
            no_exception = True
        except:
            pass # success

        if no_exception:
            self.fail("Should not be able to bless a launched instance.")
Ejemplo n.º 45
0
    def test_bless_instance(self):
        instance_id = utils.create_instance(self.context)

        num_instance_before = len(db.instance_get_all(self.context))
        self.gridcentric.bless_instance(self.context, instance_id)

        # Ensure that we have a 2nd instance in the database that is a "clone"
        # of our original instance.
        instances = db.instance_get_all(self.context)
        self.assertTrue(len(instances) == (num_instance_before + 1),
                        "There should be one new instances after blessing.")

        # The virtual machine should be marked that it is now blessed.
        metadata = db.instance_metadata_get(self.context, instance_id + 1)
        self.assertTrue(metadata.has_key('blessed'),
                        "The instance should have a bless metadata after being blessed.")
        self.assertTrue(metadata['blessed'] == '1',
            "The instance should have the bless metadata set to true after being blessed. " \
          + "(value=%s)" % (metadata['blessed']))
Ejemplo n.º 46
0
    def test_launch_instance_migrate_exception(self):

        self.vmsconn.set_return_val("launch", utils.TestInducedException())
        launched_uuid = utils.create_instance(self.context, {'vm_state': vm_states.ACTIVE})

        try:
            self.gridcentric.launch_instance(self.context, instance_uuid=launched_uuid,
                                             migration_url="migration_url")
            self.fail("The launch error should have been re-raised up.")
        except utils.TestInducedException:
            pass

        launched_instance = db.instance_get_by_uuid(self.context, launched_uuid)
        # (dscannell): This needs to be fixed up once we have the migration state transitions
        # performed correctly.
        self.assertEquals(vm_states.ACTIVE, launched_instance['vm_state'])
        self.assertEquals(task_states.SPAWNING, launched_instance['task_state'])
        self.assertEquals(None, launched_instance['launched_at'])
        self.assertEquals(None, launched_instance['host'])
Ejemplo n.º 47
0
    def test_bless_instance_migrate(self):
        self.vmsconn.set_return_val("bless",
                                    ("newname", "migration_url", ["file1", "file2", "file3"]))
        self.vmsconn.set_return_val("post_bless", ["file1_ref", "file2_ref", "file3_ref"])
        self.vmsconn.set_return_val("bless_cleanup", None)

        blessed_uuid = utils.create_instance(self.context)
        pre_bless_instance = db.instance_get_by_uuid(self.context, blessed_uuid)
        migration_url = self.gridcentric.bless_instance(self.context, instance_uuid=blessed_uuid,
                                                        migration_url="mcdist://migrate_addr")
        post_bless_instance = db.instance_get_by_uuid(self.context, blessed_uuid)

        self.assertEquals(pre_bless_instance['vm_state'], post_bless_instance['vm_state'])
        self.assertEquals("migration_url", migration_url)
        metadata = db.instance_metadata_get(self.context, blessed_uuid)
        self.assertEquals("file1_ref,file2_ref,file3_ref", metadata['images'])
        self.assertEquals(pre_bless_instance['launched_at'], post_bless_instance['launched_at'])
        self.assertFalse(pre_bless_instance.get('disable_terminate', None),
                         post_bless_instance.get('disable_terminate', None))
Ejemplo n.º 48
0
    def test_reset_host_not_local_src(self):

        src_host = "src-test-host"
        dst_host = "dst-test-host"
        instance_uuid = utils.create_instance(
            self.context, {
                'task_state': task_states.MIGRATING,
                'host': src_host,
                'metadata': {
                    'gc_src_host': src_host,
                    'gc_dst_host': dst_host
                }
            })
        self.gridcentric.host = src_host
        self.gridcentric._refresh_host(self.context)

        instance = db.instance_get_by_uuid(self.context, instance_uuid)
        self.assertEquals(dst_host, instance['host'])
        self.assertEquals(task_states.MIGRATING, instance['task_state'])
Ejemplo n.º 49
0
    def test_discard_a_blessed_instance_with_remaining_launched_ones(self):

        instance_uuid = utils.create_instance(self.context)
        bless_instance = self.gridcentric_api.bless_instance(
            self.context, instance_uuid)
        blessed_uuid = bless_instance['uuid']

        self.gridcentric_api.launch_instance(self.context, blessed_uuid)

        no_exception = False
        try:
            self.gridcentric_api.discard_instance(self.context, blessed_uuid)
            no_exception = True
        except:
            pass  # success

        if no_exception:
            self.fail(
                "Should not be able to discard a blessed instance while launched ones still remain."
            )
Ejemplo n.º 50
0
    def test_launch_instance_migrate(self):

        self.vmsconn.set_return_val("launch", None)
        instance_uuid = utils.create_instance(self.context,
                                              {'vm_state': vm_states.ACTIVE})
        pre_launch_instance = db.instance_get_by_uuid(self.context,
                                                      instance_uuid)

        self.gridcentric.launch_instance(self.context,
                                         instance_uuid=instance_uuid,
                                         migration_url="migration_url")

        post_launch_instance = db.instance_get_by_uuid(self.context,
                                                       instance_uuid)

        self.assertEquals(vm_states.ACTIVE, post_launch_instance['vm_state'])
        self.assertEquals(None, post_launch_instance['task_state'])
        self.assertEquals(pre_launch_instance['launched_at'],
                          post_launch_instance['launched_at'])
        self.assertEquals(self.gridcentric.host, post_launch_instance['host'])
Ejemplo n.º 51
0
    def test_bless_instance(self):
        instance_uuid = utils.create_instance(self.context)

        num_instance_before = len(db.instance_get_all(self.context))

        blessed_instance = self.gridcentric_api.bless_instance(self.context, instance_uuid)

        self.assertEquals(vm_states.BUILDING, blessed_instance['vm_state'])
        # Ensure that we have a 2nd instance in the database that is a "clone"
        # of our original instance.
        instances = db.instance_get_all(self.context)
        self.assertTrue(len(instances) == (num_instance_before + 1),
                        "There should be one new instance after blessing.")

        # The virtual machine should be marked that it is now blessed.
        metadata = db.instance_metadata_get(self.context, blessed_instance['uuid'])
        self.assertTrue(metadata.has_key('blessed_from'),
                        "The instance should have a bless metadata after being blessed.")
        self.assertTrue(metadata['blessed_from'] == '%s' % instance_uuid,
            "The instance should have the blessed_from metadata set to true after being blessed. " \
          + "(value=%s)" % (metadata['blessed_from']))
Ejemplo n.º 52
0
    def test_launch_instance_migrate_exception(self):

        self.vmsconn.set_return_val("launch", utils.TestInducedException())
        launched_uuid = utils.create_instance(self.context,
                                              {'vm_state': vm_states.ACTIVE})

        try:
            self.gridcentric.launch_instance(self.context,
                                             instance_uuid=launched_uuid,
                                             migration_url="migration_url")
            self.fail("The launch error should have been re-raised up.")
        except utils.TestInducedException:
            pass

        launched_instance = db.instance_get_by_uuid(self.context,
                                                    launched_uuid)
        # (dscannell): This needs to be fixed up once we have the migration state transitions
        # performed correctly.
        self.assertEquals(vm_states.ACTIVE, launched_instance['vm_state'])
        self.assertEquals(task_states.SPAWNING,
                          launched_instance['task_state'])
        self.assertEquals(None, launched_instance['launched_at'])
        self.assertEquals(None, launched_instance['host'])
Ejemplo n.º 53
0
    def test_bless_quota(self):
        def assert_quotas(expected_increased):
            _pre_usages = dict(pre_usages)
            _pre_usages.pop('project_id', None)
            post_usages = sqlalchemy_db.quota_usage_get_all_by_project(
                self.context, self.context.project_id)
            # Need to assert something about the quota consumption
            for quota_key in ['instances', 'ram', 'cores']:
                pre_usage = _pre_usages.pop(quota_key)
                self.assertEquals(
                    pre_usage.get('in_use', 0) + expected_increased[quota_key],
                    post_usages[quota_key].get('in_use', 0))
                self.assertEquals(pre_usage.get('reserved', 0),
                                  post_usages[quota_key].get('reserved', 0))

            for key, quota_usage in _pre_usages.iteritems():
                self.assertEquals(quota_usage.get('reserved', 0),
                                  post_usages[key].get('reserved', 0))
                self.assertEquals(quota_usage.get('in_use', 0),
                                  post_usages[key].get('in_use', 0))

        instance_uuid = utils.create_instance(self.context)
        instance = db.instance_get_by_uuid(self.context, instance_uuid)

        # Set the quota so that we can have two blessed instances (+ the instance we are blessing).
        db.quota_create(self.context, self.context.project_id, 'ram',
                        3 * instance['memory_mb'])

        pre_usages = sqlalchemy_db.quota_usage_get_all_by_project(
            self.context, self.context.project_id)

        # The amount of resources a blessed instance consumes.
        blessed_uuids = []
        for i in range(1, 3):
            blessed_uuids.append(
                self.gridcentric_api.bless_instance(self.context,
                                                    instance_uuid)['uuid'])
            expected = dict(
                zip(['instances', 'ram', 'cores'],
                    map(lambda x: i * x,
                        [1, instance['memory_mb'], instance['vcpus']])))

            assert_quotas(expected)

        try:
            self.gridcentric_api.bless_instance(self.context, instance_uuid)
            self.fail(
                "We should not have the quota to bless one more instance.")
        except exception.TooManyInstances:
            pass

        # Discard the blessed uuid and ensure that the quota increases.
        remaining = len(blessed_uuids)
        for blessed_uuid in blessed_uuids:
            self.gridcentric_api.discard_instance(self.context, blessed_uuid)
            remaining -= 1
            expected = dict(
                zip(['instances', 'ram', 'cores'],
                    map(lambda x: remaining * x,
                        [1, instance['memory_mb'], instance['vcpus']])))
            assert_quotas(expected)