Пример #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, InventoryHost, {'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):
            InventoryHost.from_json(data)
Пример #2
0
def test_orch_device_ls():
    devices = Devices([Device("/dev/vdb", available=True)])
    ilist = OrchResult([InventoryHost("ceph-node-1", devices=devices), InventoryHost("ceph-node-2",
                       devices=devices), InventoryHost("ceph-node-10", devices=devices)])

    with mock.patch("orchestrator.OrchestratorCli.get_inventory", return_value=ilist):
        # Ensure natural sorting on hostnames (ceph-node-1, ceph-node-2, ceph-node-10)
        cmd = {
            'prefix': 'orch device ls'
        }
        m = OrchestratorCli('orchestrator', 0, 0)
        r = m._handle_command(None, cmd)
        out = 'HOST          PATH      TYPE     DEVICE ID   SIZE  AVAILABLE  REFRESHED  REJECT REASONS  \n'\
              'ceph-node-1   /dev/vdb  unknown  None          0   Yes        0s ago                     \n'\
              'ceph-node-2   /dev/vdb  unknown  None          0   Yes        0s ago                     \n'\
              'ceph-node-10  /dev/vdb  unknown  None          0   Yes        0s ago                     '
        assert r == HandleCommandResult(retval=0, stdout=out, stderr='')
Пример #3
0
 def test_device_ls(self, cephadm_module):
     with self._with_host(cephadm_module, 'test'):
         c = cephadm_module.get_inventory()
         assert wait(cephadm_module, c) == [InventoryHost('test')]
Пример #4
0
 def _list_inventory(hosts=None, refresh=False):
     inv_hosts = []
     for inv_host in inventory:
         if hosts is None or inv_host['name'] in hosts:
             inv_hosts.append(InventoryHost.from_json(inv_host))
     return inv_hosts
Пример #5
0
 def _list_inventory(hosts=None, refresh=False):  # pylint: disable=unused-argument
     inv_hosts = []
     for inv_host in inventory:
         if hosts is None or inv_host['name'] in hosts:
             inv_hosts.append(InventoryHost.from_json(inv_host))
     return inv_hosts