예제 #1
0
 def test_read_instance_metadata_success(self):
     self.mox.StubOutWithMock(ovz_utils.context, 'get_admin_context')
     ovz_utils.context.get_admin_context().AndReturn(fakes.ADMINCONTEXT)
     self.mox.StubOutWithMock(ovz_utils.conductor, 'instance_get')
     ovz_utils.conductor.instance_get(
         fakes.ADMINCONTEXT, fakes.INSTANCE['id']).AndReturn(fakes.INSTANCE)
     self.mox.ReplayAll()
     meta = ovz_utils.read_instance_metadata(fakes.INSTANCE['id'])
     self.assertTrue(isinstance(meta, dict))
     self.assertEqual(meta[fakes.METAKEY], fakes.METAVALUE)
예제 #2
0
 def test_read_instance_metadata_dberror(self):
     self.mox.StubOutWithMock(ovz_utils.context, 'get_admin_context')
     ovz_utils.context.get_admin_context().AndReturn(fakes.ADMINCONTEXT)
     self.mox.StubOutWithMock(ovz_utils.conductor, 'instance_get')
     ovz_utils.conductor.instance_get(
         fakes.ADMINCONTEXT, fakes.INSTANCE['id']).AndRaise(
             exception.InstanceNotFound(fakes.ERRORMSG))
     self.mox.ReplayAll()
     meta = ovz_utils.read_instance_metadata(fakes.INSTANCE['id'])
     self.assertTrue(isinstance(meta, dict))
     self.assertTrue(len(meta) == 0)
예제 #3
0
 def _get_instance_tc_id(self):
     """
     Look up instance metadata in the db and see if there is already
     a tc_id for the instance
     """
     instance_metadata = ovz_utils.read_instance_metadata(
         self.instance['id'])
     LOG.debug(_('Instances metadata: %s') % instance_metadata)
     if instance_metadata:
         tc_id = instance_metadata.get('tc_id')
         LOG.debug(
             _('TC id for instance %(instance_id)s is %(tc_id)s') %
             {'instance_id': self.instance['id'], 'tc_id': tc_id})
         return tc_id