Esempio n. 1
0
def test_inventory():
    json_data = {
        'name':
        'host0',
        'addr':
        '1.2.3.4',
        'devices': [{
            'sys_api': {
                'rotational': '1',
                'size': 1024,
            },
            'path': '/dev/sda',
            'available': False,
            'rejected_reasons': [],
            'lvs': []
        }]
    }
    _test_resource(json_data, InventoryNode, {'abc': False})
    for devices in json_data['devices']:
        _test_resource(devices, inventory.Device)

    json_data = [{}, {'name': 'host0', 'addr': '1.2.3.4'}, {'devices': []}]
    for data in json_data:
        with pytest.raises(OrchestratorValidationError):
            InventoryNode.from_json(data)
Esempio n. 2
0
def test_inventory():
    json_data = {
        'name':
        'host0',
        'devices': [{
            'type': 'hdd',
            'id': '/dev/sda',
            'size': 1024,
            'rotates': True
        }]
    }
    _test_resource(json_data, InventoryNode, {'abc': False})
    for devices in json_data['devices']:
        _test_resource(devices, InventoryDevice, {'abc': False})

    json_data = [{}, {'name': 'host0'}, {'devices': []}]
    for data in json_data:
        with pytest.raises(OrchestratorValidationError):
            InventoryNode.from_json(data)
Esempio n. 3
0
 def _list_inventory(hosts=None, refresh=False):
     nodes = []
     for node in inventory:
         if hosts is None or node['name'] in hosts:
             nodes.append(InventoryNode.from_json(node))
     return nodes