Пример #1
0
def stop_server():
    results = run("ps -ef")

    for line in results.splitlines():
        if (private.webRoot + "/" + private.appRoot + "/" + private.appContent + "/manage.py") in line.lower():
            print("kill server pid: " + str(line.split()[1]) + "...")
            run("kill -9 " + line.split()[1])
Пример #2
0
def stop_kserver(k_home):
    """ Stop a kafka broker server on api.env.hots_string node """

    #TODO does this work without screen
    api.run("screen -dm bash -c \"{}bin/zookeeper-server-start.sh {}config/zookeeper.properties; exec bash\"".format(k_home,k_home))
    api.run("screen -dm bash -c \"{}bin/kafka-server-stop.sh {}config/server.properties; exec bash\"".format(k_home,k_home))
    log.info("Stopped Kafka server on {}".format(api.env.host_string))
Пример #3
0
    def test_001_04_installed_version(self):
        print ("\nCheck if Python3 version 3.4.X is installed")

        if run("which python3"):
            python_version = run("python3 --version")
            print (python_version)
            self.assertTrue("Python 3.4" in python_version)
        else:
            self.assertTrue(False)
Пример #4
0
    def test_001_03_default_application(self):
        print ("\nCheck which Python is default")

        which = run("which python")
        self.assertTrue(which == '/usr/bin/python')

        print(which)
Пример #5
0
def install(appName):
    result = run( "echo \'" + sudo + "\' | sudo -kS apt-get -q -y --force-yes install " + appName + " 2>&1")
    for line in result.lower().splitlines():
        if (line.startswith("e:")):
            print(result)
            exit()
    print ("Installed: " + appName)
Пример #6
0
def install_reqs():
    # install pyhton3
    if (not run("which python3")):
        install("python3")

    # install pip3
    if (not run("which pip3")):
        install("python3-pip")

    # install django 1.8
    if (not run("pip3 list | grep -io django")):
        result = run( "echo \'" + sudo + "\' | sudo -kS pip3 install django==1.8.4")
        print("Installed: Django")

    # install wget
    if (not run("which wget")):
        install("wget")
Пример #7
0
def app_start():
    started = False
    results = run("ps -ef")

    for line in results.splitlines():
        if (private.webRoot + "/" + private.appRoot + "/" + private.appContent + "/manage.py") in line.lower():
            started = True

    try:
        response = requests.get("http://" + private.host + ":" + private.port)
        if response.status_code == 200:
            started = True
    except requests.exceptions.RequestException as e:
        started = False

    if not started:
        run("nohup python3 " + private.webRoot + "/" + private.appRoot + "/" + private.appContent + "/manage.py runserver 0.0.0.0:8000 > /dev/null 2>&1 &")
Пример #8
0
    def test_000_app_process(self):
        started = False
        results = run("ps -ef")

        for line in results.splitlines():
            if (private.webRoot + "/" + private.appRoot + "/" + private.appContent + "/manage.py") in line.lower():
                started = True

        self.assertTrue(started)
Пример #9
0
 def test_000_unit_tests(self):
     result = run(
         "python3 "
         + private.webRoot
         + "/"
         + private.appRoot
         + "/"
         + private.appContent
         + "/manage.py test lists &>/dev/null; echo $?"
     )
     self.assertTrue(result == "0")
Пример #10
0
def test():
    run("mkdir yarntesting")
    put(__file__, "yarntesting/testfile.py")
    with cd("yarntesting"):
        print(run("ls -1 *py"))
        run("echo $HOSTNAME >> {}".format(run("ls -1 *.py")))
    get("yarntesting/testfile.py", "{}.testfile".format(env.host_string))
Пример #11
0
def push_extract(source, destination):
    """Puts and extracts a *.tgz file in a remote directory after checking it exists or creating it """
    taronly=source.split("/")[-1]
    log.info("\nPushing kafka tgz to nodes and extracting")
    #Check for destination folder
    if api.run("[ -d \"{}\" ] && echo 1".format(destination)) != "1":
        api.run("mkdir {}".format(destination))

    #Check for tgz already existing there and then extract
    if api.run("[ -f \"{}\" ] && echo 1".format(destination+taronly)) == "1":
        api.run('tar --skip-old-files -xzf {} -C {} '.format(destination + taronly, destination))
        return
    else:
        api.put(source, destination+taronly)
        api.run('tar --skip-old-files -xzf {} -C {} '.format(destination + taronly, destination))
        return
Пример #12
0
 def tearDown(self):
     run("rm -rf testdir")
Пример #13
0
 def setUp(self):
     env.host_string = host
     env.user = username
     env.password = password
     run("mkdir -p testdir; cd testdir; echo \"example file\" > sample.txt")
Пример #14
0
def setEnvs(string, user):
    envvars = dict(pair.split(":") for pair in string.split(","))
    for var in envvars:
        api.run("echo \"export {0}={1}\" >> /home/{2}/.bash_profile".format(var, envvars[var], user))

    log.info("\n Set env variable: {0} = {1}".format(var, envvars[var]))
Пример #15
0
 def test_001_02_installed(self):
     print ("\nCheck that nano IS installed")
     self.assertTrue(run("which nano"))
Пример #16
0
 def test_000_python3(self):
     self.assertTrue(run("which python3"))
Пример #17
0
 def test_002_03_file_exists(self):
     print("\nCheck if file exists")
     self.assertTrue(run("test -f ~/testdir/sample.txt; echo $?") == "0")
Пример #18
0
 def test_simple_connection(self):
     print(env.__dict__)
     run("uptime")
Пример #19
0
 def test_002_05_file_content(self):
     print("\nCheck if file contants word \"example\"")
     self.assertTrue("example" in run("cat ~/testdir/sample.txt"))
Пример #20
0
    def test_000_app_directories(self):
        self.assertTrue(run("ls -l | grep " + private.webRoot))
        self.assertTrue(run("cd " + private.webRoot + "; ls -l | grep " + private.appRoot))
        self.assertTrue(run("cd " + private.webRoot + "/" + private.appRoot + "; ls -l | grep " + private.appContent))
        self.assertTrue(run("cd " + private.webRoot + "/" + private.appRoot + "; ls -l | grep " + private.appDatabase))
        self.assertTrue(run("cd " + private.webRoot + "/" + private.appRoot + "/" + private.appDatabase + "; ls -l | grep db.sqlite3"))

        # Check directory Contents
        contents = (run("cd " + private.webRoot + "/" + private.appRoot + "/" + private.appContent + "; ls -1")).lower().splitlines()
        self.assertTrue("lists" in contents)
        self.assertTrue("manage.py" in contents)
        self.assertTrue("requirements.txt" in contents)
        self.assertTrue("superlists" in contents)

        contents = (run("cd " + private.webRoot + "/" + private.appRoot + "/" + private.appContent + "/lists; ls -1")).lower().splitlines()
        self.assertTrue("admin.py" in contents)
        self.assertTrue("migrations" in contents)
        self.assertTrue("models.py" in contents)
        self.assertTrue("static" in contents)
        self.assertTrue("templates" in contents)
        self.assertTrue("tests.py" in contents)
        self.assertTrue("urls.py" in contents)
        self.assertTrue("views.py" in contents)

        contents = (run("cd " + private.webRoot + "/" + private.appRoot + "/" + private.appContent + "/lists/migrations; ls -1")).lower().splitlines()
        self.assertTrue("0001_initial.py" in contents)
        self.assertTrue("0002_item_text.py" in contents)
        self.assertTrue("0003_list.py" in contents)
        self.assertTrue("0004_item_list.py" in contents)
        
        contents = (run("cd " + private.webRoot + "/" + private.appRoot + "/" + private.appContent + "/lists/templates; ls -1")).lower().splitlines()
        self.assertTrue("base.html" in contents)
        self.assertTrue("home.html" in contents)
        self.assertTrue("list.html" in contents)

        contents = (run("cd " + private.webRoot + "/" + private.appRoot + "/" + private.appContent + "/lists/static; ls -1")).lower().splitlines()
        self.assertTrue("base.css" in contents)
        self.assertTrue("bootstrap" in contents)

        contents = (run("cd " + private.webRoot + "/" + private.appRoot + "/" + private.appContent + "/superlists; ls -1")).lower().splitlines()
        self.assertTrue("settings.py" in contents)
        self.assertTrue("urls.py" in contents)
        self.assertTrue("wsgi.py" in contents)
Пример #21
0
 def test_003_wget(self):
     self.assertTrue(run("which wget"))
Пример #22
0
 def test_002_django(self):
     results = run("pip3 list | grep -io django.*")
     self.assertTrue(results)
     self.assertTrue("1.8" in results)
Пример #23
0
 def test_001_pip3(self):
     self.assertTrue(run("which pip3"))
Пример #24
0
 def test_002_01_directory_exists(self):
     print("\nCheck if directory exists")
     self.assertTrue("testdir" in run("find ~/ -type d -name \"testdir\""))
Пример #25
0
 def test_002_02_directory_missing(self):
     print("\nCheck if directory missing")
     self.assertTrue(run("find ~/ -type d -name \"missingdir\"") == "")
Пример #26
0
 def test_001_01_not_installed(self):
     print("\nCheck that emacs is NOT installed")
     self.assertFalse(run("which emacs"))
Пример #27
0
 def test_002_04_file_missing(self):
     print("\nCheck if file missing")
     self.assertTrue(run("test -f ~/testdir/missing.txt; echo $?") == "1")
Пример #28
0
def cleanup_db():
    run("python3 " + private.webRoot + "/" + private.appRoot + "/" + private.appContent + "/manage.py migrate --noinput")
Пример #29
0
def test():
    with cd("/usr/bin/"):
        print(run("ls -l pyth*"))
Пример #30
0
 def setUp(self):
     env.host_string = "********"
     env.user = "******"
     env.password = "******"
     run("mkdir -p testdir; cd testdir; echo \"example file\" > sample.txt")