Exemplo n.º 1
0
async def test_snapshot_restore(deploy, event_loop):
    """
    Trigger snapshot and restore actions
    """
    from sh import juju, ls
    controller, model = deploy
    etcd = await model.deploy(str(ETCD_CHARM_PATH))
    await model.deploy('cs:~containers/easyrsa')
    await model.add_relation('easyrsa:client', 'etcd:certificates')

    await etcd.set_config({'channel': '3.2/stable'})
    await asyncify(_juju_wait)(controller, model.info.name)

    for unit in etcd.units:
        leader = await unit.is_leader_from_status()
        if leader:
            # Load dummy data
            await load_data(unit)
            for ver in ['v2', 'v3']:
                assert await is_data_present(unit, ver)
            filenames = {}
            for dataset in ['v2', 'v3']:
                # Take snapshot of data
                action = await unit.run_action('snapshot',
                                               **{'keys-version': dataset})
                action = await action.wait()
                assert action.status == 'completed'
                src = Path(action.results['snapshot']['path'])
                dst = Path(action.results['snapshot']['path']).name
                await unit.scp_from(str(src), str(dst))
                filenames[dataset] = str(dst)
                out = ls('-l', 'result*')
                print(out.stdout.decode().strip())

            await delete_data(unit)
            for ver in ['v2', 'v3']:
                assert await is_data_present(unit, ver) is False

            # Restore v2 data
            # Note: libjuju does not implement attach yet.
            juju('attach', '-m', "{}:{}".format(controller, model.info.name),
                 'etcd', "snapshot='./{}'".format(str(filenames['v2'])))
            action = await unit.run_action('restore')
            action = await action.wait()
            assert action.status == 'completed'
            for ver in ['v2', 'v3']:
                assert await is_data_present(unit, ver) is True

            # Restore v3 data
            juju('attach', '-m', "{}:{}".format(controller, model.info.name),
                 'etcd', "snapshot='./{}'".format(str(filenames['v3'])))

            action = await unit.run_action('restore')
            action = await action.wait()
            await action.status == 'completed'
            for ver in ['v2', 'v3']:
                assert await is_data_present(unit, ver) is True
Exemplo n.º 2
0
async def deploy(request, connection_name, controller_name, model_name, cloud):
    test_run_nonce = uuid.uuid4().hex[-4:]
    _model = "{}-{}".format(model_name, test_run_nonce)

    juju("add-model", "-c", controller_name, _model, cloud)
    juju("model-config", "-m", connection_name, "test-mode=true")

    _juju_model = Model()
    await _juju_model.connect("{}:{}".format(controller_name, _model))
    yield (controller_name, _juju_model)
    await _juju_model.disconnect()
    juju("destroy-model", "-y", "{}:{}".format(controller_name, _model))
Exemplo n.º 3
0
async def deploy():
    test_run_nonce = uuid.uuid4().hex[-4:]
    _model = 'test-{}-{}'.format(MODEL, test_run_nonce)

    juju('add-model', '-c', CONTROLLER, _model)
    juju('model-config', '-m', '{}:{}'.format(CONTROLLER, _model),
         'test-mode=true')

    _juju_model = Model()
    await _juju_model.connect("{}:{}".format(CONTROLLER, _model))
    yield (CONTROLLER, _juju_model)
    await _juju_model.disconnect()
    juju('destroy-model', '-y', '{}:{}'.format(CONTROLLER, _model))
Exemplo n.º 4
0
async def test_snapshot_restore(model, tools):
    """
    Trigger snapshot and restore actions
    """
    from sh import juju, ls

    etcd = model.applications["etcd"]
    for unit in etcd.units:
        leader = await unit.is_leader_from_status()
        if leader:
            # Load dummy data
            await load_data(unit)
            for ver in ["v3"]:
                assert await is_data_present(unit, ver)
            filenames = {}
            for dataset in ["v3"]:
                # Take snapshot of data
                action = await unit.run_action("snapshot",
                                               **{"keys-version": dataset})
                action = await action.wait()
                assert action.status == "completed"
                src = Path(action.results["snapshot"]["path"])
                dst = Path(action.results["snapshot"]["path"]).name
                await unit.scp_from(str(src), str(dst), tools.controller_name,
                                    tools.connection)
                filenames[dataset] = str(dst)
                out = ls("-l", "result*")
                print(out.stdout.decode().strip())

            await delete_data(unit)
            for ver in ["v3"]:
                assert await is_data_present(unit, ver) is False

            # Restore v2 data
            # Note: libjuju does not implement attach yet.
            juju(
                "attach",
                "-m",
                "{}:{}".format(tools.controller_name, model.info.name),
                "etcd",
                "snapshot='./{}'".format(str(filenames["v2"])),
            )
            action = await unit.run_action("restore")
            action = await action.wait()
            assert action.status == "completed"
            for ver in ["v3"]:
                assert await is_data_present(unit, ver) is True

            # Restore v3 data
            juju(
                "attach",
                "-m",
                "{}:{}".format(tools.controller_name, model.info.name),
                "etcd",
                "snapshot='./{}'".format(str(filenames["v3"])),
            )

            action = await unit.run_action("restore")
            action = await action.wait()
            await action.status == "completed"
            for ver in ["v3"]:
                assert await is_data_present(unit, ver) is True
Exemplo n.º 5
0
async def test_snapshot_restore(deploy, event_loop, connection_name, tools):
    """
    Trigger snapshot and restore actions
    """
    from sh import juju, ls

    controller, model = deploy
    etcd = await model.deploy(str(ETCD_CHARM_PATH))
    await model.deploy("cs:~containers/easyrsa")
    await model.add_relation("easyrsa:client", "etcd:certificates")

    await etcd.set_config({"channel": "3.2/stable"})
    await tools.juju_wait()

    for unit in etcd.units:
        leader = await unit.is_leader_from_status()
        if leader:
            # Load dummy data
            await load_data(unit)
            for ver in ["v3"]:
                assert await is_data_present(unit, ver)
            filenames = {}
            for dataset in ["v3"]:
                # Take snapshot of data
                action = await unit.run_action("snapshot",
                                               **{"keys-version": dataset})
                action = await action.wait()
                assert action.status == "completed"
                src = Path(action.results["snapshot"]["path"])
                dst = Path(action.results["snapshot"]["path"]).name
                await unit.scp_from(str(src), str(dst), controller,
                                    connection_name)
                filenames[dataset] = str(dst)
                out = ls("-l", "result*")
                print(out.stdout.decode().strip())

            await delete_data(unit)
            for ver in ["v3"]:
                assert await is_data_present(unit, ver) is False

            # Restore v2 data
            # Note: libjuju does not implement attach yet.
            juju(
                "attach",
                "-m",
                "{}:{}".format(controller, model.info.name),
                "etcd",
                "snapshot='./{}'".format(str(filenames["v2"])),
            )
            action = await unit.run_action("restore")
            action = await action.wait()
            assert action.status == "completed"
            for ver in ["v3"]:
                assert await is_data_present(unit, ver) is True

            # Restore v3 data
            juju(
                "attach",
                "-m",
                "{}:{}".format(controller, model.info.name),
                "etcd",
                "snapshot='./{}'".format(str(filenames["v3"])),
            )

            action = await unit.run_action("restore")
            action = await action.wait()
            await action.status == "completed"
            for ver in ["v3"]:
                assert await is_data_present(unit, ver) is True
 def juju_ssh(self, target, cmd):
     """ Run ssh command on target
     """
     ssh_opts = "-t -o ControlPath=~/.ssh/master-$$ -o ControlMaster=auto -o ControlPersist=60"
     sh.juju("-m", self._fmt_controller_model, "--pty=True", target,
             ssh_opts, "--", cmd)