Exemple #1
0
 def convert_to_old_style_json(j):
     j_c = dict(j.copy())
     j_c.pop('service_name', None)
     if 'spec' in j_c:
         spec = j_c.pop('spec')
         j_c.update(spec)
     if 'placement' in j_c:
         if 'hosts' in j_c['placement']:
             j_c['placement']['hosts'] = [
                 {
                     'hostname': HostPlacementSpec.parse(h).hostname,
                     'network': HostPlacementSpec.parse(h).network,
                     'name': HostPlacementSpec.parse(h).name
                 }
                 for h in j_c['placement']['hosts']
             ]
     j_c.pop('objectstore', None)
     j_c.pop('filter_logic', None)
     return j_c
Exemple #2
0
def test_parse_host_placement_specs(test_input, expected, require_network):
    ret = HostPlacementSpec.parse(test_input, require_network=require_network)
    assert ret == expected
    assert str(ret) == test_input

    ps = PlacementSpec.from_string(test_input)
    assert ps.pretty_str() == test_input
    assert ps == PlacementSpec.from_string(ps.pretty_str())

    # Testing the old verbose way of generating json. Don't remove:
    assert ret == HostPlacementSpec.from_json({
        'hostname': ret.hostname,
        'network': ret.network,
        'name': ret.name
    })

    assert ret == HostPlacementSpec.from_json(ret.to_json())
Exemple #3
0
def test_parse_host_placement_specs_raises(test_input):
    with pytest.raises(ValueError):
        ret = HostPlacementSpec.parse(test_input)
Exemple #4
0
def test_parse_host_placement_specs_raises_wrong_format(test_input):
    with pytest.raises(ValueError):
        HostPlacementSpec.parse(test_input)
Exemple #5
0
def test_parse_host_placement_specs(test_input, expected, require_network):
    ret = HostPlacementSpec.parse(test_input, require_network=require_network)
    assert ret == expected
    assert str(ret) == test_input