Beispiel #1
0
    def test_get_inactive_flavors(self):
        flav1 = flavors.create('flavor1', 256, 1, 120)
        flav2 = flavors.create('flavor2', 512, 4, 250)
        flavors.destroy('flavor1')

        returned_flavors_ids = flavors.get_all_flavors().keys()
        self.assertNotIn(flav1['id'], returned_flavors_ids)
        self.assertIn(flav2['id'], returned_flavors_ids)

        returned_flavors_ids = flavors.get_all_flavors(inactive=True).keys()
        self.assertIn(flav1['id'], returned_flavors_ids)
        self.assertIn(flav2['id'], returned_flavors_ids)
Beispiel #2
0
    def test_get_inactive_flavors_with_same_name(self):
        flavors.create('flavor1', 256, 1, 120, 100, "test_id1")
        flavors.destroy('flavor1')
        flavors.create('flavor1', 512, 4, 250, 100, "test_id2")

        returned_flavors_ids = flavors.get_all_flavors().keys()
        self.assertNotIn('test_id1', returned_flavors_ids)
        self.assertIn('test_id2', returned_flavors_ids)

        returned_flavors_ids = flavors.get_all_flavors(inactive=True).keys()
        self.assertIn('test_id1', returned_flavors_ids)
        self.assertIn('test_id2', returned_flavors_ids)
Beispiel #3
0
    def test_get_inactive_flavors_with_same_name(self):
        flav1 = flavors.create('flavor', 256, 1, 120)
        flavors.destroy('flavor')
        flav2 = flavors.create('flavor', 512, 4, 250)

        returned_flavors_ids = flavors.get_all_flavors().keys()
        self.assertNotIn(flav1['id'], returned_flavors_ids)
        self.assertIn(flav2['id'], returned_flavors_ids)

        returned_flavors_ids = flavors.get_all_flavors(inactive=True).keys()
        self.assertIn(flav1['id'], returned_flavors_ids)
        self.assertIn(flav2['id'], returned_flavors_ids)
Beispiel #4
0
    def test_get_inactive_flavors(self):
        flav1 = flavors.create('flavor1', 256, 1, 120)
        flav2 = flavors.create('flavor2', 512, 4, 250)
        flavors.destroy('flavor1')

        returned_flavors_ids = flavors.get_all_flavors().keys()
        self.assertNotIn(flav1.id, returned_flavors_ids)
        self.assertIn(flav2.id, returned_flavors_ids)

        returned_flavors_ids = flavors.get_all_flavors(inactive=True).keys()
        self.assertIn(flav1.id, returned_flavors_ids)
        self.assertIn(flav2.id, returned_flavors_ids)
Beispiel #5
0
    def test_get_inactive_flavors_with_same_name(self):
        flav1 = flavors.create('flavor', 256, 1, 120)
        flavors.destroy('flavor')
        flav2 = flavors.create('flavor', 512, 4, 250)

        returned_flavors_ids = flavors.get_all_flavors().keys()
        self.assertNotIn(flav1.id, returned_flavors_ids)
        self.assertIn(flav2.id, returned_flavors_ids)

        returned_flavors_ids = flavors.get_all_flavors(inactive=True).keys()
        self.assertIn(flav1.id, returned_flavors_ids)
        self.assertIn(flav2.id, returned_flavors_ids)
Beispiel #6
0
    def test_get_inactive_flavors(self):
        flav1 = flavors.create("flavor1", 256, 1, 120)
        flav2 = flavors.create("flavor2", 512, 4, 250)
        flavors.destroy("flavor1")

        returned_flavors_ids = flavors.get_all_flavors().keys()
        self.assertNotIn(flav1["id"], returned_flavors_ids)
        self.assertIn(flav2["id"], returned_flavors_ids)

        returned_flavors_ids = flavors.get_all_flavors(inactive=True).keys()
        self.assertIn(flav1["id"], returned_flavors_ids)
        self.assertIn(flav2["id"], returned_flavors_ids)
Beispiel #7
0
    def test_get_inactive_flavors_with_same_flavorid(self):
        flav1 = flavors.create('flavor', 256, 1, 120, 100, "flavid")
        flavors.destroy('flavor')
        flav2 = flavors.create('flavor', 512, 4, 250, 100, "flavid")

        returned_flavors_ids = flavors.get_all_flavors().keys()
        self.assertNotIn(flav1.id, returned_flavors_ids)
        self.assertIn(flav2.id, returned_flavors_ids)

        returned_flavors_ids = flavors.get_all_flavors(inactive=True).keys()
        self.assertIn(flav1.id, returned_flavors_ids)
        self.assertIn(flav2.id, returned_flavors_ids)
Beispiel #8
0
    def test_get_inactive_flavors_with_same_flavorid(self):
        flav1 = flavors.create('flavor', 256, 1, 120, 100, "flavid")
        flavors.destroy('flavor')
        flav2 = flavors.create('flavor', 512, 4, 250, 100, "flavid")

        returned_flavors_ids = flavors.get_all_flavors().keys()
        self.assertNotIn(flav1['id'], returned_flavors_ids)
        self.assertIn(flav2['id'], returned_flavors_ids)

        returned_flavors_ids = flavors.get_all_flavors(inactive=True).keys()
        self.assertIn(flav1['id'], returned_flavors_ids)
        self.assertIn(flav2['id'], returned_flavors_ids)
Beispiel #9
0
    def test_basic_create(self):
        # Ensure instance types can be created.
        original_list = flavors.get_all_flavors()

        # Create new type and make sure values stick
        flavor = flavors.create("flavor", 64, 1, 120)
        self.assertEqual(flavor["name"], "flavor")
        self.assertEqual(flavor["memory_mb"], 64)
        self.assertEqual(flavor["vcpus"], 1)
        self.assertEqual(flavor["root_gb"], 120)

        # Ensure new type shows up in list
        new_list = flavors.get_all_flavors()
        self.assertNotEqual(len(original_list), len(new_list), "flavor was not created")
Beispiel #10
0
    def test_create_then_delete(self):
        original_list = flavors.get_all_flavors()

        flavor = flavors.create("flavor", 64, 1, 120)

        # Ensure new type shows up in list
        new_list = flavors.get_all_flavors()
        self.assertNotEqual(len(original_list), len(new_list), "instance type was not created")

        flavors.destroy("flavor")
        self.assertRaises(exception.InstanceTypeNotFound, flavors.get_flavor, flavor["id"])

        # Deleted instance should not be in list anymore
        new_list = flavors.get_all_flavors()
        self.assertEqual(original_list, new_list)
Beispiel #11
0
    def test_basic_create(self):
        # Ensure instance types can be created.
        original_list = flavors.get_all_flavors()

        # Create new type and make sure values stick
        flavor = flavors.create('flavor', 64, 1, 120)
        self.assertEqual(flavor.name, 'flavor')
        self.assertEqual(flavor.memory_mb, 64)
        self.assertEqual(flavor.vcpus, 1)
        self.assertEqual(flavor.root_gb, 120)

        # Ensure new type shows up in list
        new_list = flavors.get_all_flavors()
        self.assertNotEqual(len(original_list), len(new_list),
                            'flavor was not created')
Beispiel #12
0
    def test_basic_create(self):
        # Ensure instance types can be created.
        original_list = flavors.get_all_flavors()

        # Create new type and make sure values stick
        flavor = flavors.create('flavor', 64, 1, 120)
        self.assertEqual(flavor['name'], 'flavor')
        self.assertEqual(flavor['memory_mb'], 64)
        self.assertEqual(flavor['vcpus'], 1)
        self.assertEqual(flavor['root_gb'], 120)

        # Ensure new type shows up in list
        new_list = flavors.get_all_flavors()
        self.assertNotEqual(len(original_list), len(new_list),
                            'flavor was not created')
    def _get_flavors(self, req):
        """Helper function that returns a list of flavor dicts."""
        filters = {}

        context = req.environ['nova.context']
        if context.is_admin:
            # Only admin has query access to all flavor types
            filters['is_public'] = self._parse_is_public(
                    req.params.get('is_public', None))
        else:
            filters['is_public'] = True
            filters['disabled'] = False

        if 'minRam' in req.params:
            try:
                filters['min_memory_mb'] = int(req.params['minRam'])
            except ValueError:
                msg = _('Invalid minRam filter [%s]') % req.params['minRam']
                raise webob.exc.HTTPBadRequest(explanation=msg)

        if 'minDisk' in req.params:
            try:
                filters['min_root_gb'] = int(req.params['minDisk'])
            except ValueError:
                msg = _('Invalid minDisk filter [%s]') % req.params['minDisk']
                raise webob.exc.HTTPBadRequest(explanation=msg)

        limited_flavors = flavors.get_all_flavors(context, filters=filters)
        flavors_list = limited_flavors.values()
        sorted_flavors = sorted(flavors_list,
                                key=lambda item: item['flavorid'])
        limited_flavors = common.limited_by_marker(sorted_flavors, req)
        return limited_flavors
Beispiel #14
0
    def test_create_then_delete(self):
        original_list = flavors.get_all_flavors()

        flavor = flavors.create('flavor', 64, 1, 120)

        # Ensure new type shows up in list
        new_list = flavors.get_all_flavors()
        self.assertNotEqual(len(original_list), len(new_list),
                            'instance type was not created')

        flavors.destroy('flavor')
        self.assertRaises(exception.FlavorNotFound, flavors.get_flavor,
                          flavor['id'])

        # Deleted instance should not be in list anymore
        new_list = flavors.get_all_flavors()
        self.assertEqual(original_list, new_list)
    def _get_flavor_refs(self, context):
        """Return a dictionary mapping flavorid to flavor_ref."""

        flavor_refs = flavors.get_all_flavors(context)
        rval = {}
        for name, obj in flavor_refs.iteritems():
            rval[obj['flavorid']] = obj
        return rval
Beispiel #16
0
    def test_create_then_delete(self):
        original_list = flavors.get_all_flavors()

        flavor = flavors.create('flavor', 64, 1, 120)

        # Ensure new type shows up in list
        new_list = flavors.get_all_flavors()
        self.assertNotEqual(len(original_list), len(new_list),
                            'instance type was not created')

        flavors.destroy('flavor')
        self.assertRaises(exception.FlavorNotFound,
                          flavors.get_flavor, flavor['id'])

        # Deleted instance should not be in list anymore
        new_list = flavors.get_all_flavors()
        self.assertEqual(original_list, new_list)
Beispiel #17
0
 def _generate_flavorid(self):
     """return a flavorid not in the DB."""
     nonexistent_flavor = 2700
     flavor_ids = [value["id"] for key, value in flavors.get_all_flavors().iteritems()]
     while nonexistent_flavor in flavor_ids:
         nonexistent_flavor += 1
     else:
         return nonexistent_flavor
Beispiel #18
0
 def _generate_name(self):
     """return a name not in the DB."""
     nonexistent_flavor = str(int(time.time()))
     all_flavors = flavors.get_all_flavors()
     while nonexistent_flavor in all_flavors:
         nonexistent_flavor += "z"
     else:
         return nonexistent_flavor
Beispiel #19
0
 def _generate_name(self):
     """return a name not in the DB."""
     nonexistent_flavor = str(int(time.time()))
     all_flavors = flavors.get_all_flavors()
     while nonexistent_flavor in all_flavors:
         nonexistent_flavor += "z"
     else:
         return nonexistent_flavor
    def _get_flavor_refs(self, context):
        """Return a dictionary mapping flavorid to flavor_ref."""

        flavor_refs = flavors.get_all_flavors(context)
        rval = {}
        for name, obj in flavor_refs.iteritems():
            rval[obj['flavorid']] = obj
        return rval
Beispiel #21
0
 def _generate_flavorid(self):
     """return a flavorid not in the DB."""
     nonexistent_flavor = 2700
     flavor_ids = [value["id"] for key, value in
                   flavors.get_all_flavors().iteritems()]
     while nonexistent_flavor in flavor_ids:
         nonexistent_flavor += 1
     else:
         return nonexistent_flavor
Beispiel #22
0
    def test_create_then_delete(self):
        original_list = flavors.get_all_flavors()

        flavor = flavors.create("flavor", 64, 1, 120)

        # Ensure new type shows up in list
        new_list = flavors.get_all_flavors()
        self.assertNotEqual(len(original_list), len(new_list), "instance type was not created")

        flavors.destroy("flavor")
        self.assertRaises(exception.FlavorNotFound, flavors.get_flavor, flavor.id)

        # Deleted instance should not be in list anymore
        new_list = flavors.get_all_flavors()
        self.assertEqual(len(original_list), len(new_list))
        for k in original_list.keys():
            f = original_list[k]
            self.assertIsInstance(f, objects.Flavor)
            self.assertEqual(f.flavorid, new_list[k].flavorid)
Beispiel #23
0
    def test_create_then_delete(self):
        original_list = flavors.get_all_flavors()

        flavor = flavors.create('flavor', 64, 1, 120)

        # Ensure new type shows up in list
        new_list = flavors.get_all_flavors()
        self.assertNotEqual(len(original_list), len(new_list),
                            'instance type was not created')

        flavors.destroy('flavor')
        self.assertRaises(exception.FlavorNotFound, flavors.get_flavor,
                          flavor.id)

        # Deleted instance should not be in list anymore
        new_list = flavors.get_all_flavors()
        self.assertEqual(len(original_list), len(new_list))
        for k in original_list.keys():
            f = original_list[k]
            self.assertIsInstance(f, objects.Flavor)
            self.assertEqual(f.flavorid, new_list[k].flavorid)
Beispiel #24
0
 def _existing_flavor(self):
     """return first flavor name."""
     return flavors.get_all_flavors().keys()[0]
Beispiel #25
0
 def _existing_flavor(self):
     """return first flavor name."""
     return flavors.get_all_flavors().keys()[0]
Beispiel #26
0
 def test_get_all_instance_types(self):
     # Ensures that all flavors can be retrieved.
     session = sql_session.get_session()
     total_instance_types = session.query(models.InstanceTypes).count()
     inst_types = flavors.get_all_flavors()
     self.assertEqual(total_instance_types, len(inst_types))
Beispiel #27
0
def retrieve_flavors():
    return flavors.get_all_flavors()
Beispiel #28
0
def retrieve_flavors():
    """
    Retrieve list of flavors.
    """
    return flavors.get_all_flavors()
Beispiel #29
0
 def test_get_all_instance_types(self):
     # Ensures that all flavors can be retrieved.
     session = sql_session.get_session()
     total_instance_types = session.query(models.InstanceTypes).count()
     inst_types = flavors.get_all_flavors()
     self.assertEqual(total_instance_types, len(inst_types))
Beispiel #30
0
def retrieve_flavors(context):
    return flavors.get_all_flavors(context)
Beispiel #31
0
def retrieve_flavors(context):
    """
    Retrieve list of flavors.
    """
    return flavors.get_all_flavors(context)
Beispiel #32
0
 def get_items(self, context, zone_id=None):
     flavors = instance_types.get_all_flavors(context, filters={})
     return flavors.values()