Пример #1
0
def data(TEST):
    FlavorTemplateStruct = namedtuple('FlavorStruct', 'id name\
        capacities')
    CapacityStruct = namedtuple('CapacityStruct', 'name value unit')
    TEST.tuskar_flavor_templates = TestDataContainer()
    flavor_template_1 = FlavorTemplate(FlavorTemplateStruct(
            id="1",
            name='nano',
            capacities=[
              Capacity(CapacityStruct(
                name='cpu',
                unit='',
                value='1')),
              Capacity(CapacityStruct(
                name='memory',
                unit='MB',
                value='64')),
              Capacity(CapacityStruct(
                name='storage',
                unit='MB',
                value='128')),
              Capacity(CapacityStruct(
                name='ephemeral_disk',
                unit='GB',
                value='0')),
              Capacity(CapacityStruct(
                name='swap_disk',
                unit='GB',
                value='0'))]))
    flavor_template_2 = FlavorTemplate(FlavorTemplateStruct(
            id="2",
            name='large',
            capacities=[]))
    TEST.tuskar_flavor_templates.add(flavor_template_1, flavor_template_2)

    # Flavors
    TEST.tuskarclient_flavors = TestDataContainer()
    TEST.tuskar_flavors = TestDataContainer()
    flavor_1 = flavors.Flavor(flavors.FlavorManager(None),
                              {'id': '1',
                               'name': 'nano',
                               'max_vms': 100,
                               'capacities':
                                   [{"name": "cpu",
                                     "value": 64,
                                     "unit": "CPU"},
                                    {"name": "memory",
                                     "value": 1024,
                                     "unit": "MB"},
                                    {"name": "storage",
                                     "value": 1,
                                     "unit": "GB"},
                                    {"name": "ephemeral_disk",
                                     "value": 0,
                                     "unit": "GB"},
                                    {"name": "swap_disk",
                                     "value": 2,
                                     "unit": "GB"}]})
    flavor_2 = flavors.Flavor(flavors.FlavorManager(None),
                              {'id': '2',
                               'name': 'large',
                               'max_vms': 10,
                               'capacities': []})
    TEST.tuskarclient_flavors.add(flavor_1, flavor_2)
    TEST.tuskar_flavors.add(Flavor(flavor_1), Flavor(flavor_2))

    # Resource Classes
    TEST.tuskarclient_resource_classes = TestDataContainer()
    TEST.tuskar_resource_classes = TestDataContainer()
    resource_class_1 = resource_classes.ResourceClass(
        resource_classes.ResourceClassManager(None),
        {'id': '1',
         'service_type': 'compute',
         'racks': [{'id': 1}, {'id': 2}],
         'name': 'rclass1'})
    resource_class_2 = resource_classes.ResourceClass(
        resource_classes.ResourceClassManager(None),
        {'id': '2',
         'service_type': 'compute',
         'racks': [],
         'name': 'rclass2'})
    TEST.tuskarclient_resource_classes.add(resource_class_1, resource_class_2)
    TEST.tuskar_resource_classes.add(ResourceClass(resource_class_1),
                                     ResourceClass(resource_class_2))

    #Racks
    TEST.tuskarclient_racks = TestDataContainer()
    TEST.tuskar_racks = TestDataContainer()
    rack_1 = racks.Rack(racks.RackManager(None),
                        {'id': '1',
                         'name': 'rack1',
                         'location': 'location',
                         'subnet': '192.168.1.0/24',
                         'state': 'active',
                         'nodes':
                             [{'id': '1'},
                              {'id': '2'},
                              {'id': '3'},
                              {'id': '4'}],
                         'capacities':
                             [{"name": "total_cpu",
                               "value": "64",
                               "unit": "CPU"},
                              {"name": "total_memory",
                               "value": "1024",
                               "unit": "MB"}],
                         'resource_class': {'id': '1'}})
    rack_2 = racks.Rack(racks.RackManager(None),
                        {'id': '2',
                         'name': 'rack2',
                         'location': 'location',
                         'subnet': '192.168.1.0/25',
                         'state': 'provisioning',
                         'nodes': [],
                         'capacities':
                             [{"name": "total_cpu",
                               "value": "1",
                               "unit": "CPU"},
                              {"name": "total_memory",
                               "value": "4",
                               "unit": "MB"}],
                         'resource_class': {'id': '1'}})
    rack_3 = racks.Rack(racks.RackManager(None),
                        {'id': '3',
                         'name': 'rack3',
                         'location': 'location',
                         'subnet': '192.168.1.0/26',
                         'state': 'inactive',
                         'nodes': [],
                         'capacities':
                             [{"name": "total_cpu",
                               "value": "1",
                               "unit": "CPU"},
                              {"name": "total_memory",
                               "value": "2",
                               "unit": "MB"}],
                         'resource_class': None})
    TEST.tuskarclient_racks.add(rack_1, rack_2, rack_3)
    TEST.tuskar_racks.add(Rack(rack_1), Rack(rack_2), Rack(rack_3))

    # Nodes
    TEST.nodes = TestDataContainer()
    TEST.unracked_nodes = TestDataContainer()

    NodeStruct = namedtuple('RackStruct', 'id name prov_mac_address')
    node_1 = Node(NodeStruct(
            id="1",
            name="node1",
            prov_mac_address="00-B0-D0-86-AB-F7"))
    node_2 = Node(NodeStruct(
            id="2",
            name="node2",
            prov_mac_address="00-B0-D0-86-AB-F8"))
    node_3 = Node(NodeStruct(
            id="3",
            name="node3",
            prov_mac_address="00-B0-D0-86-AB-F9"))
    node_4 = Node(NodeStruct(
            id="4",
            name="node4",
            prov_mac_address="00-B0-D0-86-AB-F0"))
    node_5 = Node(NodeStruct(
            id="5",
            name="node5",
            prov_mac_address="00-B0-D0-86-AB-F1"))

    TEST.nodes.add(node_1, node_2, node_3, node_4)
    TEST.unracked_nodes.add(node_5)
Пример #2
0
 def test_flavor_template_get(self):
     test_template = self.tuskar_flavor_templates.first()
     template = FlavorTemplate.get(self.request,
                                              test_template.id)
     self.assertIsInstance(template, FlavorTemplate)
     self.assertEquals(template.name, test_template.name)
Пример #3
0
 def test_flavor_template_get(self):
     test_template = self.tuskar_flavor_templates.first()
     template = FlavorTemplate.get(self.request, test_template.id)
     self.assertIsInstance(template, FlavorTemplate)
     self.assertEquals(template.name, test_template.name)
Пример #4
0
 def test_flavor_template_list(self):
     templates = FlavorTemplate.list(self.request)
     self.assertEquals(7, len(templates))
     for t in templates:
         self.assertIsInstance(t, FlavorTemplate)
Пример #5
0
 def test_flavor_template_list(self):
     templates = FlavorTemplate.list(self.request)
     self.assertEquals(7, len(templates))
     for t in templates:
         self.assertIsInstance(t, FlavorTemplate)