Ejemplo n.º 1
0
def test_snapshot_online_vm(vm):
    util.test_log_options['show_events'] = [
        'consul', 'snapshot', 'thaw', 'freeze', 'retry', 'fail'
    ]

    vm.ensure_online_local()
    vm.qemu.qmp.close()
    get_log()

    snapshot = json.dumps({'vm': 'simplevm', 'snapshot': 'backy-1234'})
    stdin = StringIO('[{"ModifyIndex": 123, "Value": "%s", '
                     '"Key": "snapshot/7468743"}]' %
                     snapshot.encode('base64').strip())
    Agent.handle_consul_event(stdin)
    assert Ellipsis("""\
count=1 event=start-consul-events
event=snapshot machine=simplevm snapshot=backy-1234
event=snapshot-create machine=simplevm name=backy-1234
event=freeze machine=simplevm volume=root
action=continue event=freeze-failed machine=simplevm reason=Unable to sync \
with guest agent after 10 tries.
event=snapshot-ignore machine=simplevm reason=not frozen
event=ensure-thawed machine=simplevm volume=root
event=guest-fsfreeze-thaw-failed exc_info=True machine=simplevm subsystem=qemu
event=ensure-thawed-failed machine=simplevm reason=Unable to sync with guest \
agent after 10 tries.
event=handle-key-failed exc_info=True key=snapshot/7468743
event=finish-consul-events""") == get_log()
Ejemplo n.º 2
0
def test_no_key_event():
    stdin = StringIO('[{"ModifyIndex": 123, "Value": ""}]')
    Agent.handle_consul_event(stdin)
    assert util.log_data == [
        'count=1 event=start-consul-events',
        'event=handle-key-failed exc_info=True key=None',
        'event=finish-handle-key key=None', 'event=finish-consul-events'
    ]
Ejemplo n.º 3
0
def test_empty_event():
    stdin = StringIO(
        '[{"ModifyIndex": 123, "Value": "", "Key": "node/test22"}]')
    Agent.handle_consul_event(stdin)
    assert util.log_data == [
        'count=1 event=start-consul-events',
        'event=handle-key key=node/test22',
        'event=ignore-key key=node/test22 reason=empty value',
        'event=finish-consul-events'
    ]
Ejemplo n.º 4
0
def test_snapshot_nonexisting_vm():
    util.test_log_options['show_events'] = ['consul', 'unknown', 'snapshot']

    get_log()

    snapshot = json.dumps({'vm': 'test77', 'snapshot': 'backy-1234'})
    snapshot = snapshot.encode('base64').replace('\n', '')

    stdin = StringIO('[{"ModifyIndex": 123, "Value": "%s", '
                     '"Key": "snapshot/7468743"}]' % snapshot)
    Agent.handle_consul_event(stdin)
    assert get_log() == """\
Ejemplo n.º 5
0
def test_qemu_config_change_physical():
    util.test_log_options['show_events'] = ['consul']

    test22 = json.dumps({
        u'classes': [
            u'role::appserver', u'role::backupclient', u'role::generic',
            u'role::postgresql90', u'role::pspdf', u'role::webproxy'
        ],
        u'name':
        u'test22',
        u'parameters': {
            u'ceph_id': u'admin',
            u'cores': 1,
            u'directory_password': u'1jmGYd3dddyjpFlLqg63RHie',
            u'directory_ring': 1,
            u'disk': 15,
            u'environment': u'staging',
            u'id': 4097,
            u'interfaces': {},
            u'kvm_host': u'host1',
            u'location': u'whq',
            u'machine': u'physical',
            u'memory': 512,
            u'name': u'test22',
            u'online': False,
            u'production': False,
            u'profile': u'generic',
            u'rbd_pool': u'rbd.ssd',
            u'resource_group': u'test',
            u'resource_group_parent': u'',
            u'reverses': {},
            u'service_description': u'asdf',
            u'servicing': True,
            u'swap_size': 1073741824,
            u'timezone': u'Europe/Berlin',
            u'tmp_size': 5368709120
        }
    }).encode('base64')
    test22 = test22.replace('\n', '')

    stdin = StringIO(
        '[{"ModifyIndex": 123, "Value": "%s", "Key": "node/test22"}]' % test22)
    Agent.handle_consul_event(stdin)
    assert util.log_data == [
        'count=1 event=start-consul-events',
        'event=ignore-consul-event machine=test22 reason=is a physical '
        'machine', 'event=finish-consul-events'
    ]
Ejemplo n.º 6
0
def test_snapshot_offline_vm(vm):
    util.test_log_options['show_events'] = ['consul', 'snapshot']

    vm.enc['parameters']['kvm_host'] = 'foobar'
    vm.stage_new_config()
    vm.activate_new_config()

    vm.ceph.ensure_root_volume()
    vm.ensure_offline()
    get_log()

    snapshot = json.dumps({'vm': 'simplevm', 'snapshot': 'backy-1234'})
    snapshot = snapshot.encode('base64').replace('\n', '')

    stdin = StringIO('[{"ModifyIndex": 123, "Value": "%s", '
                     '"Key": "snapshot/7468743"}]' % snapshot)
    Agent.handle_consul_event(stdin)
    assert get_log() == """\
Ejemplo n.º 7
0
def test_qemu_config_change(clean_config_test22):
    util.test_log_options['show_methods'] = ['info']
    cfg = {
        u'classes': [
            u'role::appserver', u'role::backupclient', u'role::generic',
            u'role::postgresql90', u'role::pspdf', u'role::webproxy'
        ],
        u'consul-generation':
        128,
        u'name':
        u'test22',
        u'parameters': {
            u'ceph_id': u'admin',
            u'cores': 1,
            u'directory_password': u'1jmGYd3dddyjpFlLqg63RHie',
            u'directory_ring': 1,
            u'disk': 15,
            u'environment': u'staging',
            u'id': 4097,
            u'interfaces': {},
            u'kvm_host': u'host1',
            u'location': u'whq',
            u'machine': u'virtual',
            u'memory': 512,
            u'name': u'test22',
            u'online': False,
            u'production': False,
            u'profile': u'generic',
            u'rbd_pool': u'rbd.ssd',
            u'resource_group': u'test',
            u'resource_group_parent': u'',
            u'reverses': {},
            u'service_description': u'asdf',
            u'servicing': True,
            u'swap_size': 1073741824,
            u'timezone': u'Europe/Berlin',
            u'tmp_size': 5368709120
        }
    }
    test22 = json.dumps(cfg).encode('base64')
    test22 = test22.replace('\n', '')

    stdin = StringIO(
        '[{"ModifyIndex": 128, "Value": "%s", "Key": "node/test22"}]' % test22)
    Agent.handle_consul_event(stdin)
    assert util.log_data == [
        'count=1 event=start-consul-events',
        'consul_event=node event=processing-consul-event machine=test22',
        'event=launch-ensure machine=test22', 'event=finish-consul-events'
    ]

    # Applying the same config again doesn't cause another ensure run.
    stdin.seek(0)
    util.log_data = []
    Agent.handle_consul_event(stdin)

    assert util.log_data == [
        'count=1 event=start-consul-events',
        'consul_event=node event=processing-consul-event machine=test22',
        'event=ignore-consul-event machine=test22 reason=config is unchanged',
        'event=finish-consul-events'
    ]

    # Changing the config does cause ensure to be called.
    util.log_data = []
    cfg['disk'] = 20
    test22 = json.dumps(cfg).encode('base64')
    test22 = test22.replace('\n', '')

    stdin = StringIO(
        '[{"ModifyIndex": 135, "Value": "%s", "Key": "node/test22"}]' % test22)
    Agent.handle_consul_event(stdin)
    assert util.log_data == [
        'count=1 event=start-consul-events',
        'consul_event=node event=processing-consul-event machine=test22',
        'event=launch-ensure machine=test22', 'event=finish-consul-events'
    ]
Ejemplo n.º 8
0
def test_no_events():
    stdin = StringIO("[]")
    Agent.handle_consul_event(stdin)
    assert util.log_data == []