예제 #1
0
    def setUp(self):
        super(_IntegratedTestBase, self).setUp()

        f = self._get_flags()
        self.flags(**f)
        self.flags(verbose=True)

        nova.tests.image.fake.stub_out_image_service(self.stubs)
        self.flags(compute_scheduler_driver='nova.scheduler.'
                    'chance.ChanceScheduler')

        all_types = {'m1.tiny': 1, 'm1.small': 2, 'm1.medium': 2,
                                    'm1.large': 4, 'm1.xlarge': 4}
        admin_context = context.get_admin_context()
        for name, value in all_types.iteritems():
            inst_type = db.instance_type_get_by_name(admin_context, name)
            ext_spec = {'ecus_per_vcpu:': value}
            db.instance_type_extra_specs_update_or_create(admin_context,
                                                    inst_type["flavorid"],
                                                    ext_spec)

        # set up services
        self.compute = self.start_service('compute')
        self.volume = self.start_service('volume')
        self.network = self.start_service('network')
        self.scheduler = self.start_service('scheduler')

        self._start_api_service()

        self.api = client.TestOpenStackClient('fake', 'fake', self.auth_url)
예제 #2
0
 def create(self, req, flavor_id, body):
     self._check_body(body)
     context = req.environ['nova.context']
     specs = body.get('extra_specs')
     try:
         db.instance_type_extra_specs_update_or_create(
             context, flavor_id, specs)
     except exception.QuotaError as error:
         self._handle_quota_error(error)
     return body
예제 #3
0
 def create(self, req, flavor_id, body):
     self._check_body(body)
     context = req.environ['nova.context']
     specs = body.get('extra_specs')
     try:
         db.instance_type_extra_specs_update_or_create(context,
                                                           flavor_id,
                                                           specs)
     except exception.QuotaError as error:
         self._handle_quota_error(error)
     return body
예제 #4
0
 def create(self, req, flavor_id, body):
     context = req.environ['nova.context']
     authorize(context, action='create')
     self._check_body(body)
     specs = body.get('extra_specs')
     try:
         db.instance_type_extra_specs_update_or_create(
             context, flavor_id, specs)
     except exception.MetadataLimitExceeded as error:
         raise exc.HTTPBadRequest(explanation=error.format_message())
     return body
예제 #5
0
 def test_instance_type_extra_specs_update(self):
     expected_specs = dict(cpu_arch="x86_64",
                           cpu_model="Sandy Bridge",
                           xpu_arch="fermi",
                           xpus="2",
                           xpu_model="Tesla 2050")
     db.instance_type_extra_specs_update_or_create(
         self.context, self.flavorid, dict(cpu_model="Sandy Bridge"))
     actual_specs = db.instance_type_extra_specs_get(
         self.context, self.flavorid)
     self.assertEquals(expected_specs, actual_specs)
예제 #6
0
 def create(self, req, flavor_id, body):
     context = req.environ['nova.context']
     authorize(context, action='create')
     self._check_body(body)
     specs = body.get('extra_specs')
     try:
         db.instance_type_extra_specs_update_or_create(context,
                                                           flavor_id,
                                                           specs)
     except exception.MetadataLimitExceeded as error:
         raise exc.HTTPBadRequest(explanation=error.format_message())
     return body
예제 #7
0
 def create(self, req, flavor_id, body):
     context = req.environ["nova.context"]
     self.authorize(context, action="create")
     self._check_body(body)
     specs = body.get("extra_specs", {})
     if not specs or type(specs) is not dict:
         raise webob.exc.HTTPBadRequest(_("No or bad extra_specs provided"))
     try:
         db.instance_type_extra_specs_update_or_create(context, flavor_id, specs)
     except db_exc.DBDuplicateEntry as error:
         raise webob.exc.HTTPBadRequest(explanation=error.format_message())
     return body
예제 #8
0
 def create(self, req, flavor_id, body):
     context = req.environ['nova.context']
     self.authorize(context, action='create')
     self._check_body(body)
     specs = body.get('extra_specs', {})
     if not specs or type(specs) is not dict:
         raise webob.exc.HTTPBadRequest(_('No or bad extra_specs provided'))
     try:
         db.instance_type_extra_specs_update_or_create(
             context, flavor_id, specs)
     except db_exc.DBDuplicateEntry as error:
         raise webob.exc.HTTPBadRequest(explanation=error.format_message())
     return body
 def test_instance_type_extra_specs_update(self):
     expected_specs = dict(cpu_arch="x86_64",
                              cpu_model="Sandy Bridge",
                              xpu_arch="fermi",
                              xpus="2",
                              xpu_model="Tesla 2050")
     db.instance_type_extra_specs_update_or_create(
                           self.context,
                           self.flavorid,
                           dict(cpu_model="Sandy Bridge"))
     actual_specs = db.instance_type_extra_specs_get(
                           self.context,
                           self.flavorid)
     self.assertEquals(expected_specs, actual_specs)
예제 #10
0
 def test_instance_type_extra_specs_create(self):
     expected_specs = dict(cpu_arch="x86_64",
                           cpu_model="Nehalem",
                           xpu_arch="fermi",
                           xpus="2",
                           xpu_model="Tesla 2050",
                           net_arch="ethernet",
                           net_mbps="10000")
     db.instance_type_extra_specs_update_or_create(
         self.context, self.flavorid,
         dict(net_arch="ethernet", net_mbps=10000))
     actual_specs = db.instance_type_extra_specs_get(
         self.context, self.flavorid)
     self.assertEquals(expected_specs, actual_specs)
예제 #11
0
 def update(self, req, flavor_id, id, body):
     context = req.environ["nova.context"]
     self.authorize(context, action="update")
     self._check_body(body)
     if id not in body:
         expl = _("Request body and URI mismatch")
         raise webob.exc.HTTPBadRequest(explanation=expl)
     if len(body) > 1:
         expl = _("Request body contains too many items")
         raise webob.exc.HTTPBadRequest(explanation=expl)
     try:
         db.instance_type_extra_specs_update_or_create(context, flavor_id, body)
     except db_exc.DBDuplicateEntry as error:
         raise webob.exc.HTTPBadRequest(explanation=error.format_message())
     return body
예제 #12
0
파일: manage.py 프로젝트: comstud/nova
    def set_key(self, name, key, value=None):
        """Add key/value pair to specified instance type's extra_specs."""
        try:
            try:
                inst_type = flavors.get_instance_type_by_name(name)
            except exception.InstanceTypeNotFoundByName as e:
                print e
                return 2

            ctxt = context.get_admin_context()
            ext_spec = {key: value}
            db.instance_type_extra_specs_update_or_create(ctxt, inst_type["flavorid"], ext_spec)
            print _("Key %(key)s set to %(value)s on instance" " type %(name)s") % locals()
        except db_exc.DBError as e:
            _db_error(e)
예제 #13
0
 def update(self, req, flavor_id, id, body):
     context = req.environ['nova.context']
     authorize(context, action='update')
     self._check_body(body)
     if id not in body:
         expl = _('Request body and URI mismatch')
         raise exc.HTTPBadRequest(explanation=expl)
     if len(body) > 1:
         expl = _('Request body contains too many items')
         raise exc.HTTPBadRequest(explanation=expl)
     try:
         db.instance_type_extra_specs_update_or_create(
             context, flavor_id, body)
     except exception.MetadataLimitExceeded as error:
         raise exc.HTTPBadRequest(explanation=error.format_message())
     return body
예제 #14
0
    def update(self, req, flavor_id, id, body):
        self._check_body(body)
        context = req.environ['nova.context']
        if not id in body:
            expl = _('Request body and URI mismatch')
            raise exc.HTTPBadRequest(explanation=expl)
        if len(body) > 1:
            expl = _('Request body contains too many items')
            raise exc.HTTPBadRequest(explanation=expl)
        try:
            db.instance_type_extra_specs_update_or_create(
                context, flavor_id, body)
        except exception.QuotaError as error:
            self._handle_quota_error(error)

        return body
 def test_instance_type_extra_specs_create(self):
     expected_specs = dict(cpu_arch="x86_64",
                              cpu_model="Nehalem",
                              xpu_arch="fermi",
                              xpus="2",
                              xpu_model="Tesla 2050",
                              net_arch="ethernet",
                              net_mbps="10000")
     db.instance_type_extra_specs_update_or_create(
                           self.context,
                           self.flavorid,
                           dict(net_arch="ethernet",
                                net_mbps=10000))
     actual_specs = db.instance_type_extra_specs_get(
                           self.context,
                           self.flavorid)
     self.assertEquals(expected_specs, actual_specs)
예제 #16
0
    def set_key(self, name, key, value=None):
        """Add key/value pair to specified instance type's extra_specs."""
        try:
            try:
                inst_type = instance_types.get_instance_type_by_name(name)
            except exception.InstanceTypeNotFoundByName, e:
                print e
                return(2)

            ctxt = context.get_admin_context()
            ext_spec = {key: value}
            db.instance_type_extra_specs_update_or_create(
                            ctxt,
                            inst_type["flavorid"],
                            ext_spec)
            print _("Key %(key)s set to %(value)s on instance"
                    " type %(name)s") % locals()
예제 #17
0
 def update(self, req, flavor_id, id, body):
     context = req.environ['nova.context']
     authorize(context, action='update')
     self._check_body(body)
     if id not in body:
         expl = _('Request body and URI mismatch')
         raise exc.HTTPBadRequest(explanation=expl)
     if len(body) > 1:
         expl = _('Request body contains too many items')
         raise exc.HTTPBadRequest(explanation=expl)
     try:
         db.instance_type_extra_specs_update_or_create(context,
                                                            flavor_id,
                                                            body)
     except exception.MetadataLimitExceeded as error:
         raise exc.HTTPBadRequest(explanation=error.format_message())
     return body
예제 #18
0
    def update(self, req, flavor_id, id, body):
        self._check_body(body)
        context = req.environ['nova.context']
        if not id in body:
            expl = _('Request body and URI mismatch')
            raise exc.HTTPBadRequest(explanation=expl)
        if len(body) > 1:
            expl = _('Request body contains too many items')
            raise exc.HTTPBadRequest(explanation=expl)
        try:
            db.instance_type_extra_specs_update_or_create(context,
                                                               flavor_id,
                                                               body)
        except exception.QuotaError as error:
            self._handle_quota_error(error)

        return body
예제 #19
0
    def setUp(self):
        super(CinderCloudTestCase, self).setUp()
        vol_tmpdir = tempfile.mkdtemp()
        self.flags(compute_driver='nova.virt.fake.FakeDriver',
                   volume_api_class='nova.tests.fake_volume.API',
                   volumes_dir=vol_tmpdir)

        def fake_show(meh, context, id):
            return {'id': id,
                    'name': 'fake_name',
                    'container_format': 'ami',
                    'status': 'active',
                    'properties': {
                        'kernel_id': 'cedef40a-ed67-4d10-800e-17455edce175',
                        'ramdisk_id': 'cedef40a-ed67-4d10-800e-17455edce175',
                        'type': 'machine',
                        'image_state': 'available'}}

        def fake_detail(_self, context, **kwargs):
            image = fake_show(None, context, None)
            image['name'] = kwargs.get('filters', {}).get('name')
            return [image]

        self.stubs.Set(fake._FakeImageService, 'show', fake_show)
        self.stubs.Set(fake._FakeImageService, 'detail', fake_detail)
        fake.stub_out_image_service(self.stubs)

        def dumb(*args, **kwargs):
            pass

        self.stubs.Set(compute_utils, 'notify_about_instance_usage', dumb)
        fake_network.set_stub_network_methods(self.stubs)

        # set up our cloud
        self.cloud = cloud.CloudController()
        self.flags(compute_scheduler_driver='nova.scheduler.'
                'chance.ChanceScheduler')

        # set up services
        self.compute = self.start_service('compute')
        self.scheduler = self.start_service('scheduler')
        self.network = self.start_service('network')
        self.volume = self.start_service('volume')

        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = context.RequestContext(self.user_id,
                                              self.project_id,
                                              is_admin=True)
        self.volume_api = volume.API()
        self.volume_api.reset_fake_api(self.context)

        all_types = {'m1.tiny': 1, 'm1.small': 2, 'm1.medium': 2,
                                    'm1.large': 4, 'm1.xlarge': 4}
        admin_context = context.get_admin_context()
        for name, value in all_types.iteritems():
            inst_type = db.instance_type_get_by_name(admin_context, name)
            ext_spec = {'ecus_per_vcpu:': value}
            db.instance_type_extra_specs_update_or_create(admin_context,
                                                    inst_type["flavorid"],
                                                    ext_spec)

        # NOTE(comstud): Make 'cast' behave like a 'call' which will
        # ensure that operations complete
        self.stubs.Set(rpc, 'cast', rpc.call)

        # make sure we can map ami-00000001/2 to a uuid in FakeImageService
        db.api.s3_image_create(self.context,
                               'cedef40a-ed67-4d10-800e-17455edce175')
        db.api.s3_image_create(self.context,
                               '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6')