def test_extract_app_to_dir(self): flexmock(os) os.should_receive('mkdir').and_return() flexmock(os.path) os.path.should_receive('abspath').with_args('relative/app.tar.gz')\ .and_return('/tmp/relative/app.tar.gz') flexmock(LocalState) LocalState.should_receive('shell')\ .with_args(re.compile('tar zxvf /tmp/relative/app.tar.gz'),False)\ .and_return() LocalState.extract_app_to_dir('relative/app.tar.gz',False)
def test_extract_app_to_dir(self): flexmock(os) os.should_receive('mkdir').and_return() flexmock(os.path) os.path.should_receive('abspath').with_args('relative/app.tar.gz') \ .and_return('/tmp/relative/app.tar.gz') flexmock(LocalState) LocalState.should_receive('shell') \ .with_args(re.compile('tar zxvf /tmp/relative/app.tar.gz'), False) \ .and_return() os.should_receive('listdir').and_return(['one_folder']) os.path.should_receive('isdir').with_args(re.compile('one_folder')).and_return(True) location = LocalState.extract_app_to_dir('relative/app.tar.gz', False) self.assertEquals(True, 'one_folder' in location)
def test_extract_app_to_dir(self): flexmock(os) os.should_receive('mkdir').and_return() flexmock(os.path) os.path.should_receive('abspath').with_args('relative/app.tar.gz') \ .and_return('/tmp/relative/app.tar.gz') flexmock(LocalState) LocalState.should_receive('shell') \ .with_args(re.compile('tar zxvf /tmp/relative/app.tar.gz'), False) \ .and_return() os.should_receive('listdir').and_return(['one_folder']) os.path.should_receive('isdir').with_args( re.compile('one_folder')).and_return(True) location = LocalState.extract_app_to_dir('relative/app.tar.gz', False) self.assertEquals(True, 'one_folder' in location)
def upload_app(cls, options): """Uploads the given App Engine application into AppScale. Args: options: A Namespace that has fields for each parameter that can be passed in via the command-line interface. """ if cls.TAR_GZ_REGEX.search(options.file): file_location = LocalState.extract_app_to_dir(options.file, options.verbose) created_dir = True else: file_location = options.file created_dir = False app_id = AppEngineHelper.get_app_id_from_app_config(file_location) app_language = AppEngineHelper.get_app_runtime_from_app_config( file_location) AppEngineHelper.validate_app_id(app_id) acc = AppControllerClient(LocalState.get_login_host(options.keyname), LocalState.get_secret_key(options.keyname)) userappserver_host = acc.get_uaserver_host(options.verbose) userappclient = UserAppClient(userappserver_host, LocalState.get_secret_key( options.keyname)) if options.test: username = LocalState.DEFAULT_USER elif options.email: username = options.email else: username = LocalState.get_username_from_stdin(is_admin=False) if not userappclient.does_user_exist(username): password = LocalState.get_password_from_stdin() RemoteHelper.create_user_accounts(username, password, userappserver_host, options.keyname) if userappclient.does_app_exist(app_id): raise AppScaleException("The given application is already running in " + \ "AppScale. Please choose a different application ID or use " + \ "appscale-remove-app to take down the existing application.") app_admin = userappclient.get_app_admin(app_id) if app_admin is not None and username != app_admin: raise AppScaleException("The given user doesn't own this application" + \ ", so they can't upload an app with that application ID. Please " + \ "change the application ID and try again.") AppScaleLogger.log("Uploading {0}".format(app_id)) userappclient.reserve_app_id(username, app_id, app_language) remote_file_path = RemoteHelper.copy_app_to_host(file_location, options.keyname, options.verbose) acc.done_uploading(app_id, remote_file_path) acc.update([app_id]) # now that we've told the AppController to start our app, find out what port # the app is running on and wait for it to start serving AppScaleLogger.log("Please wait for your app to start serving.") serving_host, serving_port = userappclient.get_serving_info(app_id, options.keyname) RemoteHelper.sleep_until_port_is_open(serving_host, serving_port, options.verbose) AppScaleLogger.success("Your app can be reached at the following URL: " + "http://{0}:{1}".format(serving_host, serving_port)) if created_dir: shutil.rmtree(file_location)
def upload_app(cls, options): """Uploads the given App Engine application into AppScale. Args: options: A Namespace that has fields for each parameter that can be passed in via the command-line interface. Returns: A tuple containing the host and port where the application is serving traffic from. """ if cls.TAR_GZ_REGEX.search(options.file): file_location = LocalState.extract_app_to_dir(options.file, options.verbose) created_dir = True elif os.path.isdir(options.file): file_location = options.file created_dir = False else: raise AppEngineConfigException('{0} is not a .tar.gz file or a ' \ 'directory. Please try uploading either a .tar.gz file or a ' \ 'directory.'.format(options.file)) try: app_id = AppEngineHelper.get_app_id_from_app_config(file_location) except AppEngineConfigException: # Java App Engine users may have specified their war directory. In that # case, just move up one level, back to the app's directory. file_location = file_location + os.sep + ".." app_id = AppEngineHelper.get_app_id_from_app_config(file_location) app_language = AppEngineHelper.get_app_runtime_from_app_config( file_location) AppEngineHelper.validate_app_id(app_id) if app_language == 'java': if AppEngineHelper.is_sdk_mismatch(file_location): AppScaleLogger.warn('AppScale did not find the correct SDK jar ' + 'versions in your app. The current supported ' + 'SDK version is ' + AppEngineHelper.SUPPORTED_SDK_VERSION + '.') acc = AppControllerClient(LocalState.get_login_host(options.keyname), LocalState.get_secret_key(options.keyname)) userappserver_host = acc.get_uaserver_host(options.verbose) userappclient = UserAppClient(userappserver_host, LocalState.get_secret_key( options.keyname)) if options.test: username = LocalState.DEFAULT_USER elif options.email: username = options.email else: username = LocalState.get_username_from_stdin(is_admin=False) if not userappclient.does_user_exist(username): password = LocalState.get_password_from_stdin() RemoteHelper.create_user_accounts(username, password, userappserver_host, options.keyname, clear_datastore=False) app_exists = userappclient.does_app_exist(app_id) app_admin = userappclient.get_app_admin(app_id) if app_admin is not None and username != app_admin: raise AppScaleException("The given user doesn't own this application" + \ ", so they can't upload an app with that application ID. Please " + \ "change the application ID and try again.") if app_exists: AppScaleLogger.log("Uploading new version of app {0}".format(app_id)) else: AppScaleLogger.log("Uploading initial version of app {0}".format(app_id)) userappclient.reserve_app_id(username, app_id, app_language) remote_file_path = RemoteHelper.copy_app_to_host(file_location, options.keyname, options.verbose) acc.done_uploading(app_id, remote_file_path) acc.update([app_id]) # now that we've told the AppController to start our app, find out what port # the app is running on and wait for it to start serving AppScaleLogger.log("Please wait for your app to start serving.") if app_exists: time.sleep(20) # give the AppController time to restart the app serving_host, serving_port = userappclient.get_serving_info(app_id, options.keyname) RemoteHelper.sleep_until_port_is_open(serving_host, serving_port, options.verbose) AppScaleLogger.success("Your app can be reached at the following URL: " + "http://{0}:{1}".format(serving_host, serving_port)) if created_dir: shutil.rmtree(file_location) return (serving_host, serving_port)
def upload_app(cls, options): """Uploads the given App Engine application into AppScale. Args: options: A Namespace that has fields for each parameter that can be passed in via the command-line interface. Returns: A tuple containing the host and port where the application is serving traffic from. """ if cls.TAR_GZ_REGEX.search(options.file): file_location = LocalState.extract_app_to_dir( options.file, options.verbose) created_dir = True else: file_location = options.file created_dir = False app_id = AppEngineHelper.get_app_id_from_app_config(file_location) app_language = AppEngineHelper.get_app_runtime_from_app_config( file_location) AppEngineHelper.validate_app_id(app_id) acc = AppControllerClient(LocalState.get_login_host(options.keyname), LocalState.get_secret_key(options.keyname)) userappserver_host = acc.get_uaserver_host(options.verbose) userappclient = UserAppClient( userappserver_host, LocalState.get_secret_key(options.keyname)) if options.test: username = LocalState.DEFAULT_USER elif options.email: username = options.email else: username = LocalState.get_username_from_stdin(is_admin=False) if not userappclient.does_user_exist(username): password = LocalState.get_password_from_stdin() RemoteHelper.create_user_accounts(username, password, userappserver_host, options.keyname) app_exists = userappclient.does_app_exist(app_id) app_admin = userappclient.get_app_admin(app_id) if app_admin is not None and username != app_admin: raise AppScaleException("The given user doesn't own this application" + \ ", so they can't upload an app with that application ID. Please " + \ "change the application ID and try again.") if app_exists: AppScaleLogger.log( "Uploading new version of app {0}".format(app_id)) else: AppScaleLogger.log( "Uploading initial version of app {0}".format(app_id)) userappclient.reserve_app_id(username, app_id, app_language) remote_file_path = RemoteHelper.copy_app_to_host( file_location, options.keyname, options.verbose) acc.done_uploading(app_id, remote_file_path) acc.update([app_id]) # now that we've told the AppController to start our app, find out what port # the app is running on and wait for it to start serving AppScaleLogger.log("Please wait for your app to start serving.") if app_exists: time.sleep(20) # give the AppController time to restart the app serving_host, serving_port = userappclient.get_serving_info( app_id, options.keyname) RemoteHelper.sleep_until_port_is_open(serving_host, serving_port, options.verbose) AppScaleLogger.success( "Your app can be reached at the following URL: " + "http://{0}:{1}".format(serving_host, serving_port)) if created_dir: shutil.rmtree(file_location) return (serving_host, serving_port)