示例#1
0
    def test_build_request_spec_without_image(self):
        image = None
        instance = {'uuid': 'fake-uuid'}
        instance_type = {'flavorid': 'fake-id'}

        self.mox.StubOutWithMock(flavors, 'extract_flavor')
        self.mox.StubOutWithMock(db, 'flavor_extra_specs_get')
        flavors.extract_flavor(mox.IgnoreArg()).AndReturn(instance_type)
        db.flavor_extra_specs_get(self.context, mox.IgnoreArg()).AndReturn([])
        self.mox.ReplayAll()

        request_spec = scheduler_utils.build_request_spec(self.context, image,
                                                          [instance])
        self.assertEqual({}, request_spec['image'])
示例#2
0
    def test_build_request_spec_without_image(self):
        image = None
        instance = {'uuid': 'fake-uuid'}
        instance_type = {'flavorid': 'fake-id'}

        self.mox.StubOutWithMock(flavors, 'extract_flavor')
        self.mox.StubOutWithMock(db, 'flavor_extra_specs_get')
        flavors.extract_flavor(mox.IgnoreArg()).AndReturn(instance_type)
        db.flavor_extra_specs_get(self.context, mox.IgnoreArg()).AndReturn([])
        self.mox.ReplayAll()

        request_spec = scheduler_utils.build_request_spec(
            self.context, image, [instance])
        self.assertEqual({}, request_spec['image'])
示例#3
0
文件: utils.py 项目: yaochi/nova
def build_request_spec(ctxt, image, instances, instance_type=None):
    """Build a request_spec for the scheduler.

    The request_spec assumes that all instances to be scheduled are the same
    type.
    """
    instance = instances[0]
    if isinstance(instance, obj_base.NovaObject):
        instance = obj_base.obj_to_primitive(instance)

    if instance_type is None:
        instance_type = flavors.extract_flavor(instance)
    # NOTE(comstud): This is a bit ugly, but will get cleaned up when
    # we're passing an InstanceType internal object.
    extra_specs = db.flavor_extra_specs_get(ctxt, instance_type['flavorid'])
    instance_type['extra_specs'] = extra_specs
    request_spec = {
        'image': image or {},
        'instance_properties': instance,
        'instance_type': instance_type,
        'num_instances': len(instances),
        # NOTE(alaski): This should be removed as logic moves from the
        # scheduler to conductor.  Provides backwards compatibility now.
        'instance_uuids': [inst['uuid'] for inst in instances]
    }
    return jsonutils.to_primitive(request_spec)
 def test_instance_type_extra_specs_create(self):
     net_attrs = {"net_arch": "ethernet", "net_mbps": "10000"}
     self.specs.update(net_attrs)
     db.flavor_extra_specs_update_or_create(self.context, self.flavorid,
                                            net_attrs)
     actual_specs = db.flavor_extra_specs_get(self.context, self.flavorid)
     self.assertEqual(self.specs, actual_specs)
示例#5
0
文件: utils.py 项目: YankunLi/nova
def build_request_spec(ctxt, image, instances, instance_type=None):
    """Build a request_spec for the scheduler.

    The request_spec assumes that all instances to be scheduled are the same
    type.
    """
    instance = instances[0]
    if isinstance(instance, obj_base.NovaObject):
        instance = obj_base.obj_to_primitive(instance)

    if instance_type is None:
        instance_type = flavors.extract_flavor(instance)
    # NOTE(comstud): This is a bit ugly, but will get cleaned up when
    # we're passing an InstanceType internal object.
    extra_specs = db.flavor_extra_specs_get(ctxt, instance_type['flavorid'])
    instance_type['extra_specs'] = extra_specs
    request_spec = {
            'image': image or {},
            'instance_properties': instance,
            'instance_type': instance_type,
            'num_instances': len(instances),
            # NOTE(alaski): This should be removed as logic moves from the
            # scheduler to conductor.  Provides backwards compatibility now.
            'instance_uuids': [inst['uuid'] for inst in instances]}
    return jsonutils.to_primitive(request_spec)
示例#6
0
 def test_instance_type_extra_specs_delete(self):
     expected_specs = dict(cpu_arch="x86_64",
                           cpu_model="Nehalem",
                           xpu_arch="fermi",
                           xpus="2")
     db.flavor_extra_specs_delete(self.context, self.flavorid, "xpu_model")
     actual_specs = db.flavor_extra_specs_get(self.context, self.flavorid)
     self.assertEquals(expected_specs, actual_specs)
示例#7
0
    def test_extra_specs_update(self):
        expected_specs = {'k1': 'v1'}
        updated_specs = {'k1': 'v2'}

        self._test_extra_specs_empty()

        self.set_key(self.instance_type_name, "k1", "v1")
        actual_specs = db.flavor_extra_specs_get(context.get_admin_context(),
                                                 self.instance_type_flavorid)
        self.assertEquals(expected_specs, actual_specs)

        self.set_key(self.instance_type_name, "k1", "v2")
        actual_specs = db.flavor_extra_specs_get(context.get_admin_context(),
                                                 self.instance_type_flavorid)
        self.assertEquals(updated_specs, actual_specs)

        self.unset_key(self.instance_type_name, "k1")
 def test_flavor_extra_specs_delete(self):
     del self.specs["xpu_model"]
     db.flavor_extra_specs_delete(self.context,
                                  self.flavorid,
                                  "xpu_model")
     actual_specs = db.flavor_extra_specs_get(
                           self.context,
                           self.flavorid)
     self.assertEqual(self.specs, actual_specs)
 def test_flavor_extra_specs_delete(self):
     del self.specs["xpu_model"]
     db.flavor_extra_specs_delete(self.context,
                                  self.flavorid,
                                  "xpu_model")
     actual_specs = db.flavor_extra_specs_get(
                           self.context,
                           self.flavorid)
     self.assertEqual(self.specs, actual_specs)
 def test_instance_type_extra_specs_update(self):
     self.specs["cpu_model"] = "Sandy Bridge"
     db.flavor_extra_specs_update_or_create(
                           self.context,
                           self.flavorid,
                           dict(cpu_model="Sandy Bridge"))
     actual_specs = db.flavor_extra_specs_get(
                           self.context,
                           self.flavorid)
     self.assertEqual(self.specs, actual_specs)
示例#11
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.flavor_extra_specs_update_or_create(self.context, self.flavorid,
                                            dict(cpu_model="Sandy Bridge"))
     actual_specs = db.flavor_extra_specs_get(self.context, self.flavorid)
     self.assertEquals(expected_specs, actual_specs)
 def test_instance_type_extra_specs_update(self):
     self.specs["cpu_model"] = "Sandy Bridge"
     db.flavor_extra_specs_update_or_create(
                           self.context,
                           self.flavorid,
                           dict(cpu_model="Sandy Bridge"))
     actual_specs = db.flavor_extra_specs_get(
                           self.context,
                           self.flavorid)
     self.assertEqual(self.specs, actual_specs)
 def test_instance_type_specs_get(self):
     expected_specs = dict(cpu_arch="x86_64",
                              cpu_model="Nehalem",
                              xpu_arch="fermi",
                              xpus="2",
                              xpu_model="Tesla 2050")
     actual_specs = db.flavor_extra_specs_get(
                           self.context,
                           self.flavorid)
     self.assertEquals(expected_specs, actual_specs)
示例#14
0
    def test_extra_specs_update(self):
        expected_specs = {'k1': 'v1'}
        updated_specs = {'k1': 'v2'}

        self._test_extra_specs_empty()

        self.set_key(self.instance_type_name, "k1", "v1")
        actual_specs = db.flavor_extra_specs_get(
                              context.get_admin_context(),
                              self.instance_type_flavorid)
        self.assertEquals(expected_specs, actual_specs)

        self.set_key(self.instance_type_name, "k1", "v2")
        actual_specs = db.flavor_extra_specs_get(
                              context.get_admin_context(),
                              self.instance_type_flavorid)
        self.assertEquals(updated_specs, actual_specs)

        self.unset_key(self.instance_type_name, "k1")
示例#15
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.flavor_extra_specs_update_or_create(
         self.context, self.flavorid,
         dict(net_arch="ethernet", net_mbps=10000))
     actual_specs = db.flavor_extra_specs_get(self.context, self.flavorid)
     self.assertEquals(expected_specs, actual_specs)
示例#16
0
    def test_extra_specs_multiple(self):
        two_items_extra_specs = {'k1': 'v1', 'k3': 'v3'}

        self._test_extra_specs_empty()

        self.set_key(self.instance_type_name, "k1", "v1")
        self.set_key(self.instance_type_name, "k3", "v3")
        actual_specs = db.flavor_extra_specs_get(context.get_admin_context(),
                                                 self.instance_type_flavorid)
        self.assertEquals(two_items_extra_specs, actual_specs)

        self.unset_key(self.instance_type_name, "k1")
        self.unset_key(self.instance_type_name, "k3")
 def test_instance_type_extra_specs_create(self):
     net_attrs = {
         "net_arch": "ethernet",
         "net_mbps": "10000"
     }
     self.specs.update(net_attrs)
     db.flavor_extra_specs_update_or_create(
                           self.context,
                           self.flavorid,
                           net_attrs)
     actual_specs = db.flavor_extra_specs_get(
                           self.context,
                           self.flavorid)
     self.assertEqual(self.specs, actual_specs)
 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.flavor_extra_specs_update_or_create(
                           self.context,
                           self.flavorid,
                           dict(cpu_model="Sandy Bridge"))
     actual_specs = db.flavor_extra_specs_get(
                           self.context,
                           self.flavorid)
     self.assertEquals(expected_specs, actual_specs)
示例#19
0
    def test_extra_specs_multiple(self):
        two_items_extra_specs = {'k1': 'v1',
                                'k3': 'v3'}

        self._test_extra_specs_empty()

        self.set_key(self.instance_type_name, "k1", "v1")
        self.set_key(self.instance_type_name, "k3", "v3")
        actual_specs = db.flavor_extra_specs_get(
                              context.get_admin_context(),
                              self.instance_type_flavorid)
        self.assertEquals(two_items_extra_specs, actual_specs)

        self.unset_key(self.instance_type_name, "k1")
        self.unset_key(self.instance_type_name, "k3")
 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.flavor_extra_specs_update_or_create(
                           self.context,
                           self.flavorid,
                           dict(net_arch="ethernet",
                                net_mbps=10000))
     actual_specs = db.flavor_extra_specs_get(
                           self.context,
                           self.flavorid)
     self.assertEquals(expected_specs, actual_specs)
示例#21
0
 def _get_extra_specs(self, context, flavor_id):
     extra_specs = db.flavor_extra_specs_get(context, flavor_id)
     return dict(extra_specs=extra_specs)
 def test_instance_type_specs_get(self):
     actual_specs = db.flavor_extra_specs_get(
                           self.context,
                           self.flavorid)
     self.assertEqual(self.specs, actual_specs)
 def test_instance_type_specs_get(self):
     actual_specs = db.flavor_extra_specs_get(self.context, self.flavorid)
     self.assertEqual(self.specs, actual_specs)
示例#24
0
 def _test_extra_specs_empty(self):
     empty_specs = {}
     actual_specs = db.flavor_extra_specs_get(
                           context.get_admin_context(),
                           self.instance_type_id)
     self.assertEquals(empty_specs, actual_specs)
示例#25
0
 def _test_extra_specs_empty(self):
     empty_specs = {}
     actual_specs = db.flavor_extra_specs_get(context.get_admin_context(),
                                              self.instance_type_id)
     self.assertEquals(empty_specs, actual_specs)