Ejemplo n.º 1
0
def serialize_json_empty_flavor_collection_test():
    data =  '{"flavors":[]}'
    
    flavor_collection = FlavorCollection([])
    
    flavor_collection_json = flavor_collection.serialize(util.JSON_MIMETYPE)
    assert util.json_are_equal(flavor_collection_json, data)
Ejemplo n.º 2
0
def serialize_xml_empty_flavor_collection_test():
    data =  '<?xml version="1.0" encoding="UTF-8"?>'
    data += '<flavors/>'
    
    flavor_collection = FlavorCollection([])
    
    flavor_collection_xml = flavor_collection.serialize(util.XML_MIMETYPE).decode('utf-8')
    assert flavor_collection_xml in data
Ejemplo n.º 3
0
 def get_flavors(self, public, promoted):
     flavors = self._get_public_flavors(public, promoted)
     flavor_collection = FlavorCollection(flavors)
     
     if not public and not promoted:
         private_flavors = self._get_private_flavors()
         self._remove_duplicated_flavors(flavors, private_flavors)
         flavor_collection.extend(private_flavors)
     
     return flavor_collection
Ejemplo n.º 4
0
def from_empty_openstack_flavor_list_test():
    mordor = util.create_example_infrastructure()
    
    flavor_collection = FlavorCollection([])
    
    converted_collection = FlavorCollection.from_openstack_flavor_list(
                                                    [], mordor)
    
    assert util.json_are_equal(
                flavor_collection.to_dict(), converted_collection.to_dict())
Ejemplo n.º 5
0
 def _get_private_region_flavors(self, region):
     token = session['token_keystone']
     infrastructure = self.database_manager.get_infrastructure(region)
     openstack_manager = OpenStackManager(region, token)
     openstack_flavors = openstack_manager.get_flavors()
     #TODO review how to manage the infrastructure to be aligned with the data base definition.
     return FlavorCollection.from_openstack_flavor_list(openstack_flavors, infrastructure)
Ejemplo n.º 6
0
def flavor_collection_extend_list_test():
    flavor1 = util.create_example_flavor()
    flavor2 = util.create_secondary_example_flavor()
    
    flavor_collection1 = FlavorCollection([])
    flavor_collection2 = FlavorCollection([flavor1])
    flavor_collection3 = FlavorCollection([flavor2])
    
    flavors = [flavor1]
    flavor_collection1.extend(flavor_collection2)
    
    assert flavor_collection1.flavors == flavors
    
    flavors = [flavor1, flavor2]
    flavor_collection1.extend(flavor_collection3)
    
    assert flavor_collection1.flavors == flavors
Ejemplo n.º 7
0
def from_openstack_flavor_list_test():
    data = util.load_json_from_file('flavor_collection_response.json')
    
    for flavor in data['flavors']:
        del(flavor['nodes'])
    
    openstackflavors = [OpenStackFlavor(None, data['flavors'][0]),
                        OpenStackFlavor(None, data['flavors'][1])]
    
    mordor = util.create_example_infrastructure()
    
    flavor_collection = util.create_example_flavor_collection(mordor)
    for flavor in flavor_collection.flavors:
        flavor.public = False
    
    converted_collection = FlavorCollection.from_openstack_flavor_list(
                                                    openstackflavors, mordor)
    
    assert util.json_are_equal(
                flavor_collection.to_dict(), converted_collection.to_dict())
Ejemplo n.º 8
0
 def _get_private_flavors(self):
     infrastructure = self.database_manager.get_infrastructure('Mordor')
     openstack_manager = OpenStackManager(infrastructure)
     openstack_flavors = openstack_manager.get_flavors()
     return FlavorCollection.from_openstack_flavor_list(openstack_flavors, infrastructure)
Ejemplo n.º 9
0
def emtpy_flavor_collection_to_dict_test():
    expected_dict =  {"flavors":[]}
    
    flavor_collection = FlavorCollection([])
    
    assert util.json_are_equal(expected_dict, flavor_collection.to_dict())