def test_build_and_upload_with_delete(self): """ Test that I can pass delete_after_upload to bundle.zip_and_upload_bundle and have it delete the bundle directory after a successful upload. """ (bundle_name, code_revision) = self._prep_build_test_bundle() bundle_dir = path.join(self.dir, 'app', bundle_name) self.assertTrue(path.isdir(bundle_dir)) bundle_file_name = bundle.zip_and_upload_bundle( 'app', bundle_name, bundle_storage_engine=bundle_storage_local) # still there self.assertTrue(path.isdir(bundle_dir)) # delete uploaded bundle bundle_storage_local.delete(bundle_file_name) # still there self.assertTrue(path.isdir(bundle_dir)) # ok now upload with delete bundle_file_name = bundle.zip_and_upload_bundle( 'app', bundle_name, bundle_storage_engine=bundle_storage_local, delete_after_upload=True) # Now it's gone! self.assertFalse(path.isdir(bundle_dir)) # delete uploaded bundle bundle_storage_local.delete(bundle_file_name)
def upload_project_bundle(zoomdb, opts): zoomdb.log("Uploading application bundle %s." % opts["BUNDLE_NAME"]) bundle.zip_and_upload_bundle( opts["APP_ID"], opts["BUNDLE_NAME"], bundle_storage_engine=opts["BUNDLE_STORAGE"], delete_after_upload=True) zoomdb.log("Bundle %s uploaded OK." % opts["BUNDLE_NAME"])
def test_upload_bundle(self): """Archive and upload a bundle.""" self.capture_logging("boto") self.patch(taskconfig, "NR_CUSTOMER_DIR", self.customer_directory) # add some random files and directories for i in range(5): self.makeDir(dirname=self.dir) for i in range(20): dirname = os.path.join(self.dir, random.choice(os.listdir(self.dir))) self.makeFile( content="".join(random.sample(string.printable, 99)), dirname=dirname) key_name = bundle.zip_and_upload_bundle( os.path.basename(self.app_dir), os.path.basename(self.dir), bundle_storage_engine=bundle_storage) s3 = S3Connection() bucket = s3.get_bucket( taskconfig.NR_BUNDLE_BUCKET) fh = open(self.makeFile(), "w") key = bucket.get_key(key_name) self.assertTrue(key is not None) key.get_file(fh) key.delete() fh.flush() tar = tarfile.TarFile.gzopen(fh.name) names = tar.getnames() entries = [] for root, dirs, files in os.walk(self.app_dir): for f in files: entries.append(os.path.join(root, f)[len(self.app_dir) + 1:]) for d in dirs: entries.append(os.path.join(root, d)[len(self.app_dir) + 1:]) names.sort() entries.sort() self.assertEqual(names, entries)
def test_build_and_upload(self): """ Test that I can do a build and then upload the result. This test that ownership settings are workable to get the bundle saved into storage even when built within a userenv. """ (bundle_name, code_revision) = self._prep_build_test_bundle() bundle_storage_file = path.join(taskconfig.NR_CUSTOMER_DIR, "bundle_storage_local", bundle_name + ".tgz") self.assertFalse(path.isfile(bundle_storage_file)) bundle_file_name = bundle.zip_and_upload_bundle( 'app', bundle_name, bundle_storage_engine=bundle_storage_local) self.assertTrue(path.isfile(bundle_storage_file)) bundle_storage_local.delete(bundle_file_name) self.assertFalse(path.isfile(bundle_storage_file))
def test_delete_bundles(self): """ Test the job to delete a specific bundle. """ zoomdb = StubZoomDB() (bundle_name, code_revision) = self._prep_build_test_bundle() db_bundle = zoomdb.add_bundle(bundle_name, code_revision) bundle_storage_file = path.join(taskconfig.NR_CUSTOMER_DIR, "bundle_storage_local", bundle_name + ".tgz") bundle_file_name = bundle.zip_and_upload_bundle( 'app', bundle_name, bundle_storage_engine=bundle_storage_local) self.assertTrue(path.isfile(bundle_storage_file)) bundle.delete_bundles(zoomdb, "app", [db_bundle.id], bundle_storage_engine=bundle_storage_local) self.assertFalse(path.isfile(bundle_storage_file))
def create_test_bundle_in_local_storage(): """ Creates a bundle for testing, and uploads it to the local storage. Returns the bundle's tarball's name. This function is used from test_nginx and perhaps other tests that require a bundle -- modify with care. """ print "Making a bundle fixture for testing." bundle_name = "bundle_test_deploy_app_2011-fixture" here = os.path.abspath(os.path.split(__file__)[0]) fixture_dir = os.path.join(here, '../fixtures') app_name = "test_deploy_app" # force rename the bundle app_dir = os.path.join(taskconfig.NR_CUSTOMER_DIR, app_name) if os.path.isdir(app_dir): utils.chown_to_me(app_dir) shutil.rmtree(app_dir) shutil.copytree(os.path.join(fixture_dir, "app"), app_dir) # create a git repo in app_dir and do a commit so that we can get the # most recent commit during bundle_app. utils.local(";".join([ ("cd %s/src" % app_dir), "git init .", "git add __init__.py", "git commit -m 'initial test_deploy commit'"])) zcfg_path = os.path.join(app_dir, "zoombuild.cfg") zcfg_content = file(zcfg_path).read() # django_tarball = os.path.join(fixture_dir, 'Django-1.2.5.tar.gz') # we don't use pip_reqs any more # zcfg_content = zcfg_content.replace( # "pip_reqs: Django==1.2.5", "pip_reqs: %s" % django_tarball) faster_zcfg = file(zcfg_path, "w") faster_zcfg.write(zcfg_content) faster_zcfg.close() bundle_name, code_revision = bundle.bundle_app( app_name, force_bundle_name=bundle_name) bundle_dir = os.path.join(taskconfig.NR_CUSTOMER_DIR, app_name, bundle_name) tarball_name = bundle.zip_and_upload_bundle(app_name, bundle_name, bundle_storage_local) print "Created bundle fixture in %s" % tarball_name # after upload, delete the dir where bundle was created shutil.rmtree(bundle_dir) return tarball_name