def test_version_functions(self): self.assertTrue(version_obj("1.2.0") < version_obj("1.2.1")) self.assertFalse(version_obj("1.2.0") < version_obj("1.2.0")) self.assertFalse(version_obj("1.2.0") < version_obj("1.2.0C")) self.assertFalse(version_obj("1.2.0-rc1") < version_obj("1.2.0-rc0")) self.assertTrue(version_obj("1.2.0-rc0") < version_obj("1.2.0-rc1")) self.assertTrue(version_obj("1.2.0-rc0") < version_obj("1.2.0")) self.assertTrue(version_obj("1.2.0-rc0") < version_obj("1.2.1")) self.assertTrue(is_valid_version("1.0.1")) self.assertTrue(is_valid_version("0.1")) self.assertFalse(is_valid_version("1")) self.assertTrue(is_valid_version("0.1a")) self.assertTrue(is_valid_version("0.1c")) self.assertTrue(is_valid_version("1.8.9-rc0")) self.assertFalse(is_valid_version("a.1.2.3.4"))
def uninstall_mongodb(version): # validate version string if not is_valid_version(version): raise MongoctlException("Invalid version '%s'. Please provide a" " valid MongoDB version." % version) mongo_installation = get_mongo_installation(version) if mongo_installation is None: # no-op msg = ("Cannot find a MongoDB installation for version '%s'. Please" " use list-versions to see all possible versions " % version) log_info(msg) return log_info("Found MongoDB '%s' in '%s'" % (version, mongo_installation)) def rm_mongodb(): log_info("Deleting '%s'" % mongo_installation) shutil.rmtree(mongo_installation) log_info("MongoDB '%s' Uninstalled successfully!" % version) prompt_execute_task("Proceed uninstall?" , rm_mongodb)
def do_install_mongodb(os_name, bits, version): if version is None: version = fetch_latest_stable_version() log_info("Installing latest stable MongoDB version '%s'..." % version) # validate version string elif not is_valid_version(version): raise MongoctlException("Invalid version '%s'. Please provide a" " valid MongoDB version." % version) mongodb_installs_dir = config.get_mongodb_installs_dir() if not mongodb_installs_dir: raise MongoctlException("No mongoDBInstallationsDirectory configured" " in mongoctl.config") platform_spec = get_validate_platform_spec(os_name, bits) log_info("Running install for %s %sbit to " "mongoDBInstallationsDirectory (%s)..." % (os_name, bits, mongodb_installs_dir)) mongo_installation = get_mongo_installation(version) if mongo_installation is not None: # no-op log_info("You already have MongoDB %s installed ('%s'). " "Nothing to do." % (version, mongo_installation)) return mongo_installation archive_name = "mongodb-%s-%s.tgz" % (platform_spec, version) url = "http://fastdl.mongodb.org/%s/%s" % (os_name, archive_name) # Validate if the version exists response = urllib.urlopen(url) if response.getcode() != 200: msg = ("Unable to download from url '%s' (response code '%s'). " "It could be that version '%s' you specified does not exist." " Please double check the version you provide" % (url, response.getcode(), version)) raise MongoctlException(msg) mongo_dir_name = "mongodb-%s-%s" % (platform_spec, version) install_dir = os.path.join(mongodb_installs_dir, mongo_dir_name) ensure_dir(mongodb_installs_dir) # XXX LOOK OUT! Two processes installing same version simultaneously => BAD. # TODO: mutex to protect the following if not dir_exists(install_dir): try: ## download the url download(url) extract_archive(archive_name) log_info("Moving extracted folder to %s" % mongodb_installs_dir) shutil.move(mongo_dir_name, mongodb_installs_dir) os.remove(archive_name) log_info("Deleting archive %s" % archive_name) log_info("MongoDB %s installed successfully!" % version) return install_dir except Exception, e: log_exception(e) log_error("Failed to install MongoDB '%s'. Cause: %s" % (version, e))