def test_check_for_updates_with_includes(self): info = appinfo.AppInfoExternal( application='app', module='default', version='version', runtime='python27', includes=['/appdir/include.yaml'], threadsafe=False) appinfo_includes.ParseAndReturnIncludePaths(mox.IgnoreArg()).AndReturn( (info, ['/appdir/include.yaml'])) os.path.getmtime('/appdir/app.yaml').InAnyOrder().AndReturn(10) os.path.getmtime('/appdir/include.yaml').InAnyOrder().AndReturn(10) os.path.getmtime('/appdir/app.yaml').AndReturn(10) os.path.getmtime('/appdir/include.yaml').AndReturn(11) appinfo_includes.ParseAndReturnIncludePaths(mox.IgnoreArg()).AndReturn( (info, ['/appdir/include.yaml'])) os.path.getmtime('/appdir/app.yaml').InAnyOrder().AndReturn(10) os.path.getmtime('/appdir/include.yaml').InAnyOrder().AndReturn(11) self.mox.ReplayAll() config = application_configuration.ModuleConfiguration('/appdir/app.yaml') self.assertEqual({'/appdir/app.yaml': 10, '/appdir/include.yaml': 10}, config._mtimes) config._mtimes = collections.OrderedDict([('/appdir/app.yaml', 10), ('/appdir/include.yaml', 10)]) self.assertSequenceEqual(set(), config.check_for_updates()) self.mox.VerifyAll() self.assertEqual({'/appdir/app.yaml': 10, '/appdir/include.yaml': 11}, config._mtimes)
def test_check_for_updates_mutable_changes(self): info1 = appinfo.AppInfoExternal( application='app', module='default', version='version', runtime='python27', threadsafe=False, libraries=[appinfo.Library(name='django', version='latest')], skip_files='.*', handlers=[], inbound_services=['warmup'], env_variables=appinfo.EnvironmentVariables(), error_handlers=[appinfo.ErrorHandlers(file='error.html')], ) info2 = appinfo.AppInfoExternal( application='app', module='default', version='version', runtime='python27', threadsafe=False, libraries=[appinfo.Library(name='jinja2', version='latest')], skip_files=r'.*\.py', handlers=[appinfo.URLMap()], inbound_services=[], ) appinfo_includes.ParseAndReturnIncludePaths(mox.IgnoreArg()).AndReturn( (info1, [])) os.path.getmtime('/appdir/app.yaml').AndReturn(10) os.path.getmtime('/appdir/app.yaml').AndReturn(11) appinfo_includes.ParseAndReturnIncludePaths(mox.IgnoreArg()).AndReturn( (info2, [])) os.path.getmtime('/appdir/app.yaml').AndReturn(11) self.mox.ReplayAll() config = application_configuration.ModuleConfiguration( '/appdir/app.yaml') self.assertSequenceEqual( set([ application_configuration.NORMALIZED_LIBRARIES_CHANGED, application_configuration.SKIP_FILES_CHANGED, application_configuration.HANDLERS_CHANGED, application_configuration.INBOUND_SERVICES_CHANGED, application_configuration.ENV_VARIABLES_CHANGED, application_configuration.ERROR_HANDLERS_CHANGED ]), config.check_for_updates()) self.mox.VerifyAll() self.assertEqual(info2.GetNormalizedLibraries(), config.normalized_libraries) self.assertEqual(info2.skip_files, config.skip_files) self.assertEqual(info2.error_handlers, config.error_handlers) self.assertEqual(info2.handlers, config.handlers) self.assertEqual(info2.inbound_services, config.inbound_services) self.assertEqual(info2.env_variables, config.env_variables)
def _parse_configuration(self, configuration_path): """Parse a configuration file (like app.yaml or appengine-web.xml). Args: configuration_path: A string containing the full path of the yaml file containing the configuration for this module. Returns: A tuple where the first element is the parsed appinfo.AppInfoExternal object and the second element is a list of the paths of the files that were used to produce it, namely the input configuration_path and any other file that was included from that one. """ if self._is_java: config, files = self._parse_java_configuration(configuration_path) else: with open(configuration_path) as f: config, files = appinfo_includes.ParseAndReturnIncludePaths(f) if self._forced_app_id: config.application = self._forced_app_id if config.runtime == 'vm' and not config.version: config.version = generate_version_id() logging.info('No version specified. Generated version id: %s', config.version) return config, [configuration_path] + files
def test_vm_health_check_taken_into_account(self): manual_scaling = appinfo.ManualScaling() vm_settings = appinfo.VmSettings() vm_settings['vm_runtime'] = 'myawesomeruntime' vm_settings['forwarded_ports'] = '49111:49111,5002:49112,8000' vm_health_check = appinfo.VmHealthCheck(enable_health_check=False) info = appinfo.AppInfoExternal( application='app', module='module1', version='1', runtime='vm', vm_settings=vm_settings, threadsafe=False, manual_scaling=manual_scaling, vm_health_check=vm_health_check ) appinfo_includes.ParseAndReturnIncludePaths(mox.IgnoreArg()).AndReturn( (info, [])) os.path.getmtime('/appdir/app.yaml').AndReturn(10) self.mox.ReplayAll() config = application_configuration.ModuleConfiguration('/appdir/app.yaml') self.mox.VerifyAll() # tests if it is not overriden from the defaults of health_check self.assertIs(config.health_check.enable_health_check, False)
def test_check_for_updates_immutable_changes(self): automatic_scaling1 = appinfo.AutomaticScaling( min_pending_latency='0.1s', max_pending_latency='1.0s', min_idle_instances=1, max_idle_instances=2) info1 = appinfo.AppInfoExternal( application='app', module='default', version='version', runtime='python27', threadsafe=False, automatic_scaling=automatic_scaling1) info2 = appinfo.AppInfoExternal( application='app2', module='default2', version='version2', runtime='python', threadsafe=True, automatic_scaling=appinfo.AutomaticScaling( min_pending_latency='1.0s', max_pending_latency='2.0s', min_idle_instances=1, max_idle_instances=2)) appinfo_includes.ParseAndReturnIncludePaths(mox.IgnoreArg()).AndReturn( (info1, [])) os.path.getmtime('/appdir/app.yaml').AndReturn(10) os.path.getmtime('/appdir/app.yaml').AndReturn(11) appinfo_includes.ParseAndReturnIncludePaths(mox.IgnoreArg()).AndReturn( (info2, [])) os.path.getmtime('/appdir/app.yaml').AndReturn(11) self.mox.ReplayAll() config = application_configuration.ModuleConfiguration('/appdir/app.yaml') self.assertSequenceEqual(set(), config.check_for_updates()) self.mox.VerifyAll() self.assertEqual('dev~app', config.application) self.assertEqual('default', config.module_name) self.assertEqual('version', config.major_version) self.assertRegexpMatches(config.version_id, r'^version\.\d+$') self.assertEqual('python27', config.runtime) self.assertFalse(config.threadsafe) self.assertEqual(automatic_scaling1, config.automatic_scaling)
def test_check_for_updates_no_changes(self): info = appinfo.AppInfoExternal( application='app', module='default', version='version', runtime='python27', threadsafe=False) appinfo_includes.ParseAndReturnIncludePaths(mox.IgnoreArg()).AndReturn( (info, [])) os.path.getmtime('/appdir/app.yaml').AndReturn(10) os.path.getmtime('/appdir/app.yaml').AndReturn(11) appinfo_includes.ParseAndReturnIncludePaths(mox.IgnoreArg()).AndReturn( (info, [])) os.path.getmtime('/appdir/app.yaml').AndReturn(11) self.mox.ReplayAll() config = application_configuration.ModuleConfiguration('/appdir/app.yaml') self.assertSequenceEqual(set(), config.check_for_updates()) self.mox.VerifyAll() self.assertEqual({'/appdir/app.yaml': 11}, config._mtimes)
def test_good_app_yaml_configuration(self): automatic_scaling = appinfo.AutomaticScaling( min_pending_latency='1.0s', max_pending_latency='2.0s', min_idle_instances=1, max_idle_instances=2) error_handlers = [appinfo.ErrorHandlers(file='error.html')] handlers = [appinfo.URLMap()] env_variables = appinfo.EnvironmentVariables() info = appinfo.AppInfoExternal( application='app', module='module1', version='1', runtime='python27', threadsafe=False, automatic_scaling=automatic_scaling, skip_files=r'\*.gif', error_handlers=error_handlers, handlers=handlers, inbound_services=['warmup'], env_variables=env_variables, ) appinfo_includes.ParseAndReturnIncludePaths(mox.IgnoreArg()).AndReturn( (info, [])) os.path.getmtime('/appdir/app.yaml').AndReturn(10) self.mox.ReplayAll() config = application_configuration.ModuleConfiguration( '/appdir/app.yaml') self.mox.VerifyAll() self.assertEqual(os.path.realpath('/appdir'), config.application_root) self.assertEqual(os.path.realpath('/appdir/app.yaml'), config.config_path) self.assertEqual('dev~app', config.application) self.assertEqual('app', config.application_external_name) self.assertEqual('dev', config.partition) self.assertEqual('module1', config.module_name) self.assertEqual('1', config.major_version) self.assertRegexpMatches(config.version_id, r'module1:1\.\d+') self.assertEqual('python27', config.runtime) self.assertFalse(config.threadsafe) self.assertEqual(automatic_scaling, config.automatic_scaling) self.assertEqual(info.GetNormalizedLibraries(), config.normalized_libraries) self.assertEqual(r'\*.gif', config.skip_files) self.assertEqual(error_handlers, config.error_handlers) self.assertEqual(handlers, config.handlers) self.assertEqual(['warmup'], config.inbound_services) self.assertEqual(env_variables, config.env_variables) self.assertEqual({'/appdir/app.yaml': 10}, config._mtimes)
def test_override_app_id(self): info = appinfo.AppInfoExternal(application='ignored-app', module='default', version='version', runtime='python27', threadsafe=False) appinfo_includes.ParseAndReturnIncludePaths(mox.IgnoreArg()).AndReturn( (info, [])) os.path.getmtime('/appdir/app.yaml').AndReturn(10) os.path.getmtime('/appdir/app.yaml').AndReturn(20) os.path.getmtime('/appdir/app.yaml').AndReturn(20) appinfo_includes.ParseAndReturnIncludePaths(mox.IgnoreArg()).AndReturn( (info, [])) self.mox.ReplayAll() config = application_configuration.ModuleConfiguration( '/appdir/app.yaml', 'overriding-app') self.assertEqual('overriding-app', config.application_external_name) self.assertEqual('dev~overriding-app', config.application) config.check_for_updates() self.assertEqual('overriding-app', config.application_external_name) self.assertEqual('dev~overriding-app', config.application) self.mox.VerifyAll()
def test_vm_app_yaml_configuration_network(self): manual_scaling = appinfo.ManualScaling() vm_settings = appinfo.VmSettings() vm_settings['vm_runtime'] = 'myawesomeruntime' network = appinfo.Network() network.forwarded_ports = ['49111:49111', '5002:49112', 8000] health_check = appinfo.HealthCheck() health_check.enable_health_check = False info = appinfo.AppInfoExternal( application='app', module='module1', version='1', runtime='vm', vm_settings=vm_settings, threadsafe=False, manual_scaling=manual_scaling, health_check=health_check, network=network ) appinfo_includes.ParseAndReturnIncludePaths(mox.IgnoreArg()).AndReturn( (info, [])) os.path.getmtime('/appdir/app.yaml').AndReturn(10) self.mox.ReplayAll() config = application_configuration.ModuleConfiguration('/appdir/app.yaml') self.mox.VerifyAll() self.assertEqual(os.path.realpath('/appdir'), config.application_root) self.assertEqual(os.path.realpath('/appdir/app.yaml'), config.config_path) self.assertEqual('dev~app', config.application) self.assertEqual('app', config.application_external_name) self.assertEqual('dev', config.partition) self.assertEqual('module1', config.module_name) self.assertEqual('1', config.major_version) self.assertRegexpMatches(config.version_id, r'module1:1\.\d+') self.assertEqual('vm', config.runtime) self.assertEqual(vm_settings['vm_runtime'], config.effective_runtime) self.assertItemsEqual( {49111: 49111, 5002: 49112, 8000: 8000}, config.forwarded_ports) self.assertFalse(config.threadsafe) self.assertEqual(manual_scaling, config.manual_scaling) self.assertEqual({'/appdir/app.yaml': 10}, config._mtimes) self.assertEqual(info.health_check, config.health_check)
def _parse_configuration(self, configuration_path): """Parse a configuration file (like app.yaml or appengine-web.xml). Args: configuration_path: A string containing the full path of the yaml file containing the configuration for this module. Returns: A tuple where the first element is the parsed appinfo.AppInfoExternal object and the second element is a list of the paths of the files that were used to produce it, namely the input configuration_path and any other file that was included from that one. """ if self._is_java: config, files = self._parse_java_configuration(configuration_path) else: with open(configuration_path) as f: config, files = appinfo_includes.ParseAndReturnIncludePaths(f) return config, [configuration_path] + files
def test_vm_no_version(self): manual_scaling = appinfo.ManualScaling() info = appinfo.AppInfoExternal( application='app', module='module1', runtime='vm', threadsafe=False, manual_scaling=manual_scaling, ) appinfo_includes.ParseAndReturnIncludePaths(mox.IgnoreArg()).AndReturn( (info, [])) os.path.getmtime('/appdir/app.yaml').AndReturn(10) self.mox.StubOutWithMock(application_configuration, 'generate_version_id') application_configuration.generate_version_id().AndReturn( 'generated-version') self.mox.ReplayAll() config = application_configuration.ModuleConfiguration('/appdir/app.yaml') self.mox.VerifyAll() self.assertEqual(config.major_version, 'generated-version')
def test_vm_app_yaml_configuration(self): manual_scaling = appinfo.ManualScaling() vm_settings = appinfo.VmSettings() vm_settings['vm_runtime'] = 'myawesomeruntime' info = appinfo.AppInfoExternal( application='app', module='module1', version='1', runtime='vm', vm_settings=vm_settings, threadsafe=False, manual_scaling=manual_scaling, ) appinfo_includes.ParseAndReturnIncludePaths(mox.IgnoreArg()).AndReturn( (info, [])) os.path.getmtime('/appdir/app.yaml').AndReturn(10) self.mox.ReplayAll() config = application_configuration.ModuleConfiguration( '/appdir/app.yaml') self.mox.VerifyAll() self.assertEqual(os.path.realpath('/appdir'), config.application_root) self.assertEqual(os.path.realpath('/appdir/app.yaml'), config.config_path) self.assertEqual('dev~app', config.application) self.assertEqual('app', config.application_external_name) self.assertEqual('dev', config.partition) self.assertEqual('module1', config.module_name) self.assertEqual('1', config.major_version) self.assertRegexpMatches(config.version_id, r'module1:1\.\d+') self.assertEqual('vm', config.runtime) self.assertEqual(vm_settings['vm_runtime'], config.effective_runtime) self.assertFalse(config.threadsafe) self.assertEqual(manual_scaling, config.manual_scaling) self.assertEqual({'/appdir/app.yaml': 10}, config._mtimes)
def _parse_configuration(configuration_path): # TODO: It probably makes sense to catch the exception raised # by Parse() and re-raise it using a module-specific exception. with open(configuration_path) as f: return appinfo_includes.ParseAndReturnIncludePaths(f)