コード例 #1
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']))
コード例 #2
0
ファイル: test_api.py プロジェクト: peterfeiner/cobalt
    def test_launch_instance_twice(self):

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

        launched_instance = self.cobalt_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.cobalt_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"]),
        )
コード例 #3
0
ファイル: test_manager.py プロジェクト: rmahmood/cobalt
    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))
コード例 #4
0
ファイル: test_manager.py プロジェクト: rmahmood/cobalt
    def test_bless_instance(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)

        pre_bless_time = datetime.utcnow()
        blessed_uuid = utils.create_pre_blessed_instance(self.context)
        migration_url = self.gridcentric.bless_instance(
            self.context, instance_uuid=blessed_uuid, migration_url=None)

        blessed_instance = db.instance_get_by_uuid(self.context, blessed_uuid)
        self.assertEquals("blessed", blessed_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'])

        # note(dscannell): Although we set the blessed metadata to True in the code, we need to compare
        # it against '1'. This is because the True gets converted to a '1' when added to the database.
        self.assertEquals('1', metadata['blessed'])
        self.assertTrue(pre_bless_time <= blessed_instance['launched_at'])

        self.assertTrue(blessed_instance['disable_terminate'])
コード例 #5
0
    def test_instance_update_with_instance_uuid(self):
        """ test instance_update() works when an instance UUID is passed """
        ctxt = context.get_admin_context()

        # Create an instance with some metadata
        values = {
            'metadata': {
                'host': 'foo'
            },
            'system_metadata': {
                'original_image_ref': 'blah'
            }
        }
        instance = db.instance_create(ctxt, values)

        # Update the metadata
        values = {
            'metadata': {
                'host': 'bar'
            },
            'system_metadata': {
                'original_image_ref': 'baz'
            }
        }
        db.instance_update(ctxt, instance.uuid, values)

        # Retrieve the user-provided metadata to ensure it was successfully
        # updated
        instance_meta = db.instance_metadata_get(ctxt, instance.id)
        self.assertEqual('bar', instance_meta['host'])

        # Retrieve the system metadata to ensure it was successfully updated
        system_meta = db.instance_system_metadata_get(ctxt, instance.uuid)
        self.assertEqual('baz', system_meta['original_image_ref'])
コード例 #6
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.cobalt_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']))

        system_metadata = db.instance_system_metadata_get(self.context, blessed_instance['uuid'])
        self.assertTrue(system_metadata.has_key('blessed_from'),
            "The instance should have a bless system_metadata after being blessed.")
        self.assertTrue(system_metadata['blessed_from'] == '%s' % instance_uuid,
            "The instance should have the blessed_from system_metadata set to true after being blessed. "\
            + "(value=%s)" % (system_metadata['blessed_from']))

        db_blessed_instance = db.instance_get_by_uuid(self.context,
                                                      blessed_instance['uuid'])
        self.assertTrue(db_blessed_instance['info_cache'])
        self.assertIsNotNone(db_blessed_instance['info_cache']['network_info'])
コード例 #7
0
ファイル: test_gridcentric.py プロジェクト: jingsu/openstack
    def test_launch_instance_twice(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']))

        self.gridcentric.launch_instance(self.context, blessed_instance_id)
        launched_instance_id = blessed_instance_id + 2
        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']))
コード例 #8
0
ファイル: test_api.py プロジェクト: alanmeadows/cobalt
    def test_launch_instance_twice(self):

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

        launched_instance = self.cobalt_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.cobalt_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']))
コード例 #9
0
ファイル: test_db_api.py プロジェクト: TMG-nl/nova
    def test_instance_update_with_instance_uuid(self):
        """ test instance_update() works when an instance UUID is passed """
        ctxt = context.get_admin_context()

        # Create an instance with some metadata
        metadata = {'host': 'foo'}
        values = {'metadata': metadata}
        instance = db.instance_create(ctxt, values)

        # Update the metadata
        metadata = {'host': 'bar'}
        values = {'metadata': metadata}
        db.instance_update(ctxt, instance.uuid, values)

        # Retrieve the metadata to ensure it was successfully updated
        instance_meta = db.instance_metadata_get(ctxt, instance.id)
        self.assertEqual('bar', instance_meta['host'])
コード例 #10
0
    def test_instance_update_with_instance_uuid(self):
        """ test instance_update() works when an instance UUID is passed """
        ctxt = context.get_admin_context()

        # Create an instance with some metadata
        metadata = {'host': 'foo'}
        values = {'metadata': metadata}
        instance = db.instance_create(ctxt, values)

        # Update the metadata
        metadata = {'host': 'bar'}
        values = {'metadata': metadata}
        db.instance_update(ctxt, instance.uuid, values)

        # Retrieve the metadata to ensure it was successfully updated
        instance_meta = db.instance_metadata_get(ctxt, instance.id)
        self.assertEqual('bar', instance_meta['host'])
コード例 #11
0
ファイル: test_db_api.py プロジェクト: hiteshwadekar/nova
    def test_instance_update_with_instance_id(self):
        """ test instance_update() works when an instance id is passed """
        ctxt = context.get_admin_context()

        # Create an instance with some metadata
        metadata = {"host": "foo"}
        values = {"metadata": metadata}
        instance = db.instance_create(ctxt, values)

        # Update the metadata
        metadata = {"host": "bar"}
        values = {"metadata": metadata}
        db.instance_update(ctxt, instance.id, values)

        # Retrieve the metadata to ensure it was successfully updated
        instance_meta = db.instance_metadata_get(ctxt, instance.id)
        self.assertEqual("bar", instance_meta["host"])
コード例 #12
0
ファイル: test_gridcentric.py プロジェクト: jingsu/openstack
    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']))
コード例 #13
0
ファイル: test_manager.py プロジェクト: rmahmood/cobalt
    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))
コード例 #14
0
def update_vm_stat(params, remote_address):
    """
    NOTE(hzyangtk):
    params:
        state: 1 means live, others mean error,
    """
    ctxt = context.get_admin_context()
    try:
        fixed_ip = db.fixed_ip_get_by_address(ctxt, remote_address)
    except exception.FixedIpNotFoundForAddress:
        LOG.exception(_("fixed ip not found with address %s") % remote_address)
        raise
    instance_uuid = fixed_ip['instance_uuid']

    # NOTE(hzyangtk): determine if let all VMs store state in DB
    #                 when only HA vm record state, check db table
    #                 instance_metadata has key 'HA' or not.
    HA_key = 'HA'
    record_state = False
    if not FLAGS.record_all_vms_heartbeat:
        instance_metadata = db.instance_metadata_get(ctxt, instance_uuid)
        record_state = HA_key in instance_metadata
    else:
        record_state = True
    if record_state:
        cache_key = str(instance_uuid + '_heart')
        cache_value = timeutils.utcnow().strftime('%Y-%m-%d %H:%M:%S')
        memcache_client = get_memcache_client()
        if memcache_client is not None:
            result = memcache_client.set(cache_key, cache_value)
            if not result:
                LOG.exception(
                    _("Memcache insert error. Key: %(cache_key)s, "
                      "value: %(cache_value)s"), {
                          'cache_key': cache_key,
                          'cache_value': cache_value
                      })
                raise exception.NovaException()
            return json.dumps({cache_key: cache_value})
        else:
            LOG.exception(_("Memcache connection failed"))
            raise exception.NovaException()
    raise exception.NotFound()
コード例 #15
0
ファイル: test_db_api.py プロジェクト: edwardt/nova
    def test_instance_update_with_instance_uuid(self):
        """ test instance_update() works when an instance UUID is passed """
        ctxt = context.get_admin_context()

        # Create an instance with some metadata
        values = {"metadata": {"host": "foo"}, "system_metadata": {"original_image_ref": "blah"}}
        instance = db.instance_create(ctxt, values)

        # Update the metadata
        values = {"metadata": {"host": "bar"}, "system_metadata": {"original_image_ref": "baz"}}
        db.instance_update(ctxt, instance.uuid, values)

        # Retrieve the user-provided metadata to ensure it was successfully
        # updated
        instance_meta = db.instance_metadata_get(ctxt, instance.uuid)
        self.assertEqual("bar", instance_meta["host"])

        # Retrieve the system metadata to ensure it was successfully updated
        system_meta = db.instance_system_metadata_get(ctxt, instance.uuid)
        self.assertEqual("baz", system_meta["original_image_ref"])
コード例 #16
0
ファイル: base.py プロジェクト: xww/nova-old
def update_vm_stat(params, remote_address):
    """
    NOTE(hzyangtk):
    params:
        state: 1 means live, others mean error,
    """
    ctxt = context.get_admin_context()
    try:
        fixed_ip = db.fixed_ip_get_by_address(ctxt, remote_address)
    except exception.FixedIpNotFoundForAddress:
        LOG.exception(_("fixed ip not found with address %s") % remote_address)
        raise
    instance_uuid = fixed_ip['instance_uuid']

    # NOTE(hzyangtk): determine if let all VMs store state in DB
    #                 when only HA vm record state, check db table
    #                 instance_metadata has key 'HA' or not.
    HA_key = 'HA'
    record_state = False
    if not FLAGS.record_all_vms_heartbeat:
        instance_metadata = db.instance_metadata_get(ctxt, instance_uuid)
        record_state = HA_key in instance_metadata
    else:
        record_state = True
    if record_state:
        cache_key = str(instance_uuid + '_heart')
        cache_value = timeutils.utcnow().strftime('%Y-%m-%d %H:%M:%S')
        memcache_client = get_memcache_client()
        if memcache_client is not None:
            result = memcache_client.set(cache_key, cache_value)
            if not result:
                LOG.exception(_("Memcache insert error. Key: %(cache_key)s, "
                                "value: %(cache_value)s"),
                              {'cache_key': cache_key,
                               'cache_value': cache_value})
                raise exception.NovaException()
            return json.dumps({cache_key: cache_value})
        else:
            LOG.exception(_("Memcache connection failed"))
            raise exception.NovaException()
    raise exception.NotFound()
コード例 #17
0
ファイル: test_manager.py プロジェクト: rmahmood/cobalt
    def test_bless_instance_exception(self):
        self.vmsconn.set_return_val("bless", utils.TestInducedException())

        blessed_uuid = utils.create_pre_blessed_instance(self.context)

        migration_url = None
        try:
            migration_url = self.gridcentric.bless_instance(
                self.context, instance_uuid=blessed_uuid, migration_url=None)
            self.fail("The bless error should have been re-raised up.")
        except utils.TestInducedException:
            pass

        blessed_instance = db.instance_get_by_uuid(self.context, blessed_uuid)
        self.assertEquals(vm_states.ERROR, blessed_instance['vm_state'])
        self.assertEquals(None, migration_url)
        metadata = db.instance_metadata_get(self.context, blessed_uuid)
        self.assertEquals(None, metadata.get('images', None))
        self.assertEquals(None, metadata.get('blessed', None))
        self.assertEquals(None, blessed_instance['launched_at'])

        self.assertFalse(blessed_instance.get('disable_terminate', False))
コード例 #18
0
ファイル: test_db_api.py プロジェクト: matiu2/nova
    def test_instance_update_with_instance_uuid(self):
        """ test instance_update() works when an instance UUID is passed """
        ctxt = context.get_admin_context()

        # Create an instance with some metadata
        values = {'metadata': {'host': 'foo'},
                  'system_metadata': {'original_image_ref': 'blah'}}
        instance = db.instance_create(ctxt, values)

        # Update the metadata
        values = {'metadata': {'host': 'bar'},
                  'system_metadata': {'original_image_ref': 'baz'}}
        db.instance_update(ctxt, instance['uuid'], values)

        # Retrieve the user-provided metadata to ensure it was successfully
        # updated
        instance_meta = db.instance_metadata_get(ctxt, instance.uuid)
        self.assertEqual('bar', instance_meta['host'])

        # Retrieve the system metadata to ensure it was successfully updated
        system_meta = db.instance_system_metadata_get(ctxt, instance.uuid)
        self.assertEqual('baz', system_meta['original_image_ref'])
コード例 #19
0
ファイル: test_manager.py プロジェクト: rmahmood/cobalt
    def test_bless_instance_exception(self):
        self.vmsconn.set_return_val("bless", utils.TestInducedException())

        blessed_uuid = utils.create_pre_blessed_instance(self.context)

        migration_url = None
        try:
            migration_url = self.gridcentric.bless_instance(self.context,
                                                            instance_uuid=blessed_uuid,
                                                            migration_url=None)
            self.fail("The bless error should have been re-raised up.")
        except utils.TestInducedException:
            pass

        blessed_instance = db.instance_get_by_uuid(self.context, blessed_uuid)
        self.assertEquals(vm_states.ERROR, blessed_instance['vm_state'])
        self.assertEquals(None, migration_url)
        metadata = db.instance_metadata_get(self.context, blessed_uuid)
        self.assertEquals(None, metadata.get('images', None))
        self.assertEquals(None, metadata.get('blessed', None))
        self.assertEquals(None, blessed_instance['launched_at'])

        self.assertFalse(blessed_instance.get('disable_terminate', False))
コード例 #20
0
ファイル: test_manager.py プロジェクト: rmahmood/cobalt
    def test_bless_instance(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)

        pre_bless_time = datetime.utcnow()
        blessed_uuid = utils.create_pre_blessed_instance(self.context)
        migration_url = self.gridcentric.bless_instance(self.context, instance_uuid=blessed_uuid,
                                                        migration_url=None)

        blessed_instance = db.instance_get_by_uuid(self.context, blessed_uuid)
        self.assertEquals("blessed", blessed_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'])

        # note(dscannell): Although we set the blessed metadata to True in the code, we need to compare
        # it against '1'. This is because the True gets converted to a '1' when added to the database.
        self.assertEquals('1', metadata['blessed'])
        self.assertTrue(pre_bless_time <= blessed_instance['launched_at'])

        self.assertTrue(blessed_instance['disable_terminate'])
コード例 #21
0
ファイル: novadriver.py プロジェクト: dblundell/veta
 def _instance_metadata(self, context, instance_uuid):
     """ Looks up and returns the instance metadata """
     return db.instance_metadata_get(context, instance_uuid)