def PushAndPublishTutorialDbs(): """Publish the tutorial databases.""" dbs = ("SFDb_3d", "SFDb_3d_TM", "SF_2d_Merc") # TODO: Be smarter about things that are already pushed and # published. Right now, publishing in this way with unpublish if there is # something already using the target. for db in dbs: result = utils.ExecuteCmd( "sudo /opt/google/bin/gequery Databases/%s --outfiles" % db) db_path = "" for line in result.split("\n"): if line.endswith("/gedb"): db_path = line break elif line.endswith("/mapdb"): db_path = line break if not db_path: raise Exception("Unable to find built database %s." % db) print "push and publish", db_path utils.ExecuteCmd("sudo /opt/google/bin/geserveradmin --adddb %s" % db_path) utils.ExecuteCmd("sudo /opt/google/bin/geserveradmin --pushdb %s" % db_path) # TODO: Use web api. utils.ExecuteCmd( "sudo /opt/google/bin/geserveradmin --publishdb %s --targetpath %s" % (db_path, db))
def GetTests(base_dir): """Get tests from cns and unpack them.""" utils.ChDir(base_dir) test_sets = [ "/cns/ih-d/home/bpeterson/gee_tests/gold_tests.tgz" ] for test_set in test_sets: utils.ExecuteCmd("fileutil cp %s test_set.tgz" % test_set) utils.ExecuteCmd("tar -xzf test_set.tgz") for path in os.listdir("test_set"): utils.ExecuteCmd("cp -r test_set/%s tests/" % path) utils.ExecuteCmd("rm test_set.tgz") utils.ExecuteCmd("rm -rf test_set") print "installed test set %s" % test_set
def Clean(force=False): """Clean gevol containing asset and publish roots.""" if not force: answer = raw_input("Are you sure you want to wipe out your assets? [y/n] ") if answer != "y": print "Skipping clean ..." return gevol_dir = GEVOL_DIR utils.ExecuteCmd("sudo rm -rf %s/*" % gevol_dir) utils.ExecuteCmd("sudo rm -rf /opt/google/gehttpd") utils.ExecuteCmd("sudo rm -rf /var/opt/google/pgsql") utils.ExecuteCmd("sudo rm -rf /var/opt/google/fusion-backups") utils.ExecuteCmd("sudo rm -rf ~/.fusion")
def CheckEnvironment(no_tests): """Make sure that we are not root and that we have prodaccess.""" print "Hostname: ", HOSTNAME if utils.DiskSpace("/tmp") < MIN_DISK_SPACE: print "Insufficient disk space." exit(0) if getpass.getuser() == "root": print "Please do not run as root." print "In order to run tests, you must use your own prodaccess." exit(0) if not no_tests: prodcertstatus = utils.ExecuteCmd("prodcertstatus") print prodcertstatus if "No valid" in prodcertstatus: utils.ExecuteCmd("prodaccess --nog")
def RunTestSets(base_dir): """Extract and run test sets.""" print "** For default test sets, please run:" print "fileutil cp /cns/ih-d/home/gee/test_sets/*.tgz test_sets/" utils.ChDir("%s/test_sets" % base_dir) for test_set_tarball in os.listdir("."): if test_set_tarball.endswith(".tgz"): # Extract tests utils.ExecuteCmd("tar -xzf %s" % test_set_tarball) utils.ChDir("test_set") # Run tests RunTests(test_set_tarball) utils.ChDir("..") # Clean up utils.ExecuteCmd("rm -rf test_set")
def SetUpPropertiesFile(installer_dir, template, replace): """Create a properties file from the template.""" utils.ChDir(installer_dir) content = utils.GetFileWithReplace(template, replace) fp = open("%s/installer.properties" % installer_dir, "w") fp.write(content) fp.close() utils.ExecuteCmd("chmod 755 installer.properties")
def InstallServer(installer_dir, template): """Install Earth Server using silent installer.""" replace = {} SetUpPropertiesFile(installer_dir, template, replace) # Was not able to get it to work using a relative path to the properties file. utils.ExecuteCmd("sudo ./InstallGEServer.sh %s/installer.properties" % installer_dir) print "Earth Server installed."
def Uninstall(): """Uninstall earlier versions of GEE.""" found = False for uninstall_script in os.listdir("/opt/google"): if uninstall_script.startswith("Uninstall_Google_Earth_Enterprise_Fusion"): utils.ExecuteCmd("sudo /opt/google/%s" % uninstall_script) found = True if not found: print "No uninstaller was found."
def UnpackTarball(path): """Unpack installer from tarball.""" if not os.path.exists(path): print "Unable to find %s." % path return False if not path.endswith("tar.gz"): print "Expecting %s to be installer tarball ending in .tar.gz" % path return False utils.ChDir(TMP_DIR) utils.ExecuteCmd("tar -xzf %s" % path) return True
def CheckRunningProcesses(): """Look for processes that will prevent installer from running.""" out = utils.ExecuteCmd("ps -ef") good = True check = ["gesystemmanager", "geresourceprovider", "gehttpd", "postgres"] for line in out.split("\n"): for target in check: if target in line and "grep" not in line: print "Need to kill:", line good = False if not good: exit(0)
def PushAndPublishDbs(dbs): """Push and publish list of databases. Args: dbs: list of databases. Raises: Exception: when unable to find database. """ # TODO: Be smarter about things that are already pushed and # published. Right now, publishing in this way with unpublish if there is # something already using the target. for db in dbs: db_path = GetGedbPath(db) if not db_path: raise Exception("Unable to find built database %s." % db) print "push and publish: ", db_path utils.ExecuteCmd("/opt/google/bin/geserveradmin --adddb %s" % db_path) utils.ExecuteCmd("/opt/google/bin/geserveradmin --pushdb %s" % db_path) # TODO: Use web api. utils.ExecuteCmd( "/opt/google/bin/geserveradmin --publishdb %s --targetpath %s" % (db_path, db))
def GetGedbPath(db_name): """Gets gedb/mapdb path for specified database. Args: db_name: a database name. Returns: a gedb/mapdb path. """ result = utils.ExecuteCmd( "/opt/google/bin/gequery Databases/%s --outfiles" % db_name) db_path = "" for line in result.split("\n"): if line.endswith("/gedb") or line.endswith("/mapdb"): db_path = line break return db_path
def RunTests(name): """Run all .py files in the current directory as tests.""" num_tests = 0 successes = 0 for test in os.listdir("."): if not test.startswith("__") and test.endswith(".py"): num_tests += 1 result = utils.ExecuteCmd("./%s" % test) lines = result.split("\n") num_lines = len(lines) for i in xrange(num_lines): if lines[num_lines - 1 - i].strip(): if "SUCCESS" in lines[num_lines - 1 - i]: successes += 1 print result break print "***** Testing: %s *****" % name print "%d of %d tests passed.\n" % (successes, num_tests)
def RunTests(base_dir): """Runs tests in the test directory.""" utils.ChDir(base_dir) num_tests = 0 successes = 0 for test in os.listdir("tests"): utils.ChDir("%s/tests" % base_dir) if not test.startswith("__") and test.endswith(".py"): num_tests += 1 result = utils.ExecuteCmd("./%s" % test) lines = result.split("\n") num_lines = len(lines) for i in xrange(num_lines): if lines[num_lines - 1 - i].strip(): if "SUCCESS" in lines[num_lines - 1 - i]: successes += 1 print result break print "*****" print "%d of %d tests passed." % (successes, num_tests)
def RunGeindexcheck(db_name): """Runs geindexcheck for specified database. Args: db_name: database name/path. """ if db_name and os.path.isabs(db_name): db_path = os.path.normpath(db_name) else: db_path = os.path.join("Databases", db_name) result = utils.ExecuteCmd( "/opt/google/bin/geindexcheck --mode all --database %s" % db_path, do_log=False, err2out=True) if "Fusion Fatal:" in result: print "geindexcheck FAILED for database: ", db_path print "Result: ", result else: print "SUCCESS"
def WaitForTutorialBuilds(): """Wait until Tutorial databases are built.""" dbs = ("SFDb_3d", "SFDb_3d_TM", "SF_2d_Merc") succeeded = {} for db in dbs: succeeded[db] = False done = False while not done: done = True for db in dbs: if not succeeded[db]: result = utils.ExecuteCmd( "sudo /opt/google/bin/gequery Databases/%s --status" % db) if "Succeeded" not in result: done = False print "Waiting for %s." % db else: print "*** %s built! ***" % db succeeded[db] = True if not done: time.sleep(BUILD_CHECK_WAIT_IN_SECS)
def StopFusion(): """Make sure Fusion isn't running.""" utils.ExecuteCmd("sudo /etc/init.d/gefusion stop")
def StopServer(): """Make sure that Earth Server isn't running.""" utils.ExecuteCmd("sudo /etc/init.d/geserver stop")
def StartFusion(): """Make sure Fusion is running.""" utils.ExecuteCmd("sudo /etc/init.d/gefusion start")
def StartServer(): """Make sure that Earth Server is running.""" utils.ExecuteCmd("sudo /etc/init.d/geserver start")
def BuildTutorial(base_dir): """Build tutorial databases.""" utils.ChDir(base_dir) utils.ExecuteCmd("env PATH=\"$PATH:/opt/google/bin\" ./run_tutorial.sh")