#!/usr/bin/env python
# Copyright Hybrid Logic Ltd.  See LICENSE file for details.
"""
Run some powerstrip acceptance tests.
"""
# hack to get access to flocker module in submodule (rather than a version of
# flocker that happens to be installed locally)
import sys, os
BASE_PATH = os.path.dirname(os.path.realpath(__file__ + "/../"))
FLOCKER_PATH = BASE_PATH + "/flocker"
sys.path.insert(0, FLOCKER_PATH)

os.system("cp -va %s/%s %s/%s" % (BASE_PATH, "extra-vagrant-acceptance-targets/*",
    FLOCKER_PATH, "admin/vagrant-acceptance-targets/"))

# another hack - this time make the tests run faster by avoiding fetching lots
# of docker images.
from flocker.provision import _install
del _install.ACCEPTANCE_IMAGES[:]

def configure_cluster(control_node, agent_nodes):
    pass

def stop_cluster(control_node, agent_nodes):
    pass

# the ubuntu vagrant acceptance testing nodes come pre-prepared with the right
# control/agent bits running
_install.configure_cluster = configure_cluster
_install.stop_cluster = stop_cluster

from twisted.python.filepath import FilePath
import sys

path = BASEPATH = FilePath(sys.argv[0])
for parent in list(path.parents()) + [FilePath(FLOCKER_PATH)]:
    if parent.descendant(['flocker', '__init__.py']).exists():
        TOPLEVEL = parent
        sys.path.insert(0, parent.path)
        break
else:
    raise ImportError("Could not find top-level.")

# three hacks are lucky right
from fabric.api import env
print "!!!", env.key_filename
if not env.key_filename:
    env.key_filename = []
env.key_filename.append("/root/.ssh/id_rsa_flocker")

if __name__ == '__main__':
    from admin.acceptance import main
    main(sys.argv[1:] + ["flockerdockerplugin.test.test_acceptance"],
            top_level=TOPLEVEL, base_path=BASEPATH)
