def test_validate_parameters_env_provided(self): t = template_format.parse(test_template_no_default) env_params = {'net_name': 'betternetname'} engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t, env_params)) self.assertEqual('betternetname', res['Parameters']['net_name']['Default'])
def launch_engine(setup_logging=True): if setup_logging: logging.register_options(cfg.CONF) cfg.CONF(project='heat', prog='heat-engine', version=version.version_info.version_string()) if setup_logging: logging.setup(cfg.CONF, 'heat-engine') logging.set_defaults() messaging.setup() config.startup_sanity_check() mgr = None try: mgr = template._get_template_extension_manager() except template.TemplatePluginNotRegistered as ex: LOG.critical("%s", ex) if not mgr or not mgr.names(): sys.exit("ERROR: No template format plugins registered") from heat.engine import service as engine # noqa profiler.setup('heat-engine', cfg.CONF.host) gmr.TextGuruMeditation.setup_autorun(version) srv = engine.EngineService(cfg.CONF.host, rpc_api.ENGINE_TOPIC) workers = cfg.CONF.num_engine_workers if not workers: workers = max(4, processutils.get_worker_count()) launcher = service.launch(cfg.CONF, srv, workers=workers, restart_method='mutate') return launcher
def setUp(self): super(WaitCondMetadataUpdateTest, self).setUp() utils.setup_dummy_db() self.fc = fakes.FakeKeystoneClient() self.man = service.EngineService('a-host', 'a-topic') cfg.CONF.set_default('heat_waitcondition_server_url', 'http://_testnoexisthost_:8000/v1/waitcondition')
def setUp(self): super(StackEventTest, self).setUp() self.patchobject(context, 'StoredContext') self.ctx = utils.dummy_context(tenant_id='stack_event_test_tenant') self.eng = service.EngineService('a-host', 'a-topic') self.eng.thread_group_mgr = service.ThreadGroupManager()
def test_validate_hot_parameter_type(self): t = template_format.parse( """ heat_template_version: 2013-05-23 parameters: param1: type: string param2: type: number param3: type: json param4: type: comma_delimited_list param5: type: boolean """) engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t, {})) parameters = res['Parameters'] # make sure all the types are reported correctly self.assertEqual('String', parameters["param1"]["Type"]) self.assertEqual('Number', parameters["param2"]["Type"]) self.assertEqual('Json', parameters["param3"]["Type"]) self.assertEqual('CommaDelimitedList', parameters["param4"]["Type"]) self.assertEqual('Boolean', parameters["param5"]["Type"])
def test_validate_template_with_invalid_resource_properties(self): hot_tpl = template_format.parse(''' heat_template_version: 2013-05-23 resources: resource1: type: AWS::EC2::Instance Properties: property1: value1 metadata: foo: bar depends_on: dummy deletion_policy: dummy update_policy: foo: bar ''') self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, hot_tpl, {})) self.assertEqual( { 'Error': 'u\'"Properties" is not a valid keyword ' 'inside a resource definition\'' }, res) self.m.VerifyAll()
def test_invalid_resources(self): t = template_format.parse(test_template_invalid_resources) engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t, {})) self.assertEqual({'Error': 'Resources must contain Resource. ' 'Found a [string] instead'}, res)
def test_unimplemented_property(self): t = template_format.parse(test_template_unimplemented_property) engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t, {})) self.assertEqual( {'Error': 'Property SourceDestCheck not implemented yet'}, res)
def test_validate_parameters(self): t = template_format.parse(test_template_ref % 'WikiDatabase') self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t, {})) # Note: the assertion below does not expect a CFN dict of the parameter # but a dict of the parameters.Schema object. # For API CFN backward compatibility, formating to CFN is done in the # API layer in heat.engine.api.format_validate_parameter. expected = { 'KeyName': { 'Type': 'String', 'Description': 'Name of an existing EC2KeyPair to enable SSH ' 'access to the instances', 'NoEcho': 'false', 'Label': 'KeyName' } } self.assertEqual(expected, res['Parameters'])
def main(): logging.register_options(cfg.CONF) cfg.CONF(project='heat', prog='heat-engine', version=version.version_info.version_string()) logging.setup(cfg.CONF, 'heat-engine') logging.set_defaults() messaging.setup() config.startup_sanity_check() mgr = None try: mgr = template._get_template_extension_manager() except template.TemplatePluginNotRegistered as ex: LOG.critical(_LC("%s"), ex) if not mgr or not mgr.names(): sys.exit("ERROR: No template format plugins registered") from heat.engine import service as engine # noqa profiler.setup('heat-engine', cfg.CONF.host) gmr.TextGuruMeditation.setup_autorun(version) srv = engine.EngineService(cfg.CONF.host, rpc_api.ENGINE_TOPIC) workers = cfg.CONF.num_engine_workers if not workers: workers = max(4, processutils.get_worker_count()) launcher = service.launch(cfg.CONF, srv, workers=workers) if cfg.CONF.enable_cloud_watch_lite: # We create the periodic tasks here, which mean they are created # only in the parent process when num_engine_workers>1 is specified srv.create_periodic_tasks() launcher.wait()
def test_invalid_section_cfn(self): t = template_format.parse(""" { 'AWSTemplateFormatVersion': '2010-09-09', 'Resources': { 'server': { 'Type': 'OS::Nova::Server' } }, 'Output': {} } """) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') ex = self.assertRaises(rpc_common.ClientException, engine.validate_template, None, t) self.assertEqual(ex._exc_info[0], exception.InvalidTemplateSection) self.assertEqual('The template section is invalid: Output', str(ex._exc_info[1]))
def setUp(self): self.m = mox.Mox() self.ctx = create_context(self.m, self.username, self.tenant) setup_mocks(self.m, self.stack) self.m.ReplayAll() self.man = service.EngineService('a-host', 'a-topic')
def setUp(self): self.m = mox.Mox() self.username = '******' self.tenant = 'stack_service_create_test_tenant' self.ctx = create_context(self.m, self.username, self.tenant) self.man = service.EngineService('a-host', 'a-topic')
def setUp(self): super(SnapshotServiceTest, self).setUp() self.ctx = utils.dummy_context() self.engine = service.EngineService('a-host', 'a-topic') self.engine.create_periodic_tasks() utils.setup_dummy_db()
def setUp(self): self.m = mox.Mox() self.ctx = context.get_admin_context() self.ctx.tenant_id = 'test_tenant' self.fc = fakes.FakeKeystoneClient() self.man = service.EngineService('a-host', 'a-topic') cfg.CONF.set_default('heat_waitcondition_server_url', 'http://127.0.0.1:8000/v1/waitcondition')
def setUp(self): super(stackServiceCreateUpdateDeleteTest, self).setUp() self.username = '******' self.tenant = 'stack_service_create_test_tenant' setup_dummy_db() self.ctx = create_context(self.m, self.username, self.tenant) self.man = service.EngineService('a-host', 'a-topic')
def setUp(self): super(WaitCondMetadataUpdateTest, self).setUp() self.stub_keystoneclient() self.patch('heat.engine.service.warnings') self.man = service.EngineService('a-host', 'a-topic') cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition')
def create_stack(self, stack_name, scenario_tmpl): cnxt = utils.dummy_context() srv = service.EngineService("host", "engine") srv.thread_group_mgr = SynchronousThreadGroupManager() srv.worker_service = self.worker hot_tmpl = self.scenario_template_to_hot(scenario_tmpl) srv.create_stack(cnxt, stack_name, hot_tmpl, params={}, files={}, environment_files=None, args={})
def setUp(self): super(StackResourcesServiceTest, self).setUp() self.ctx = utils.dummy_context(tenant_id='stack_resource_test_tenant') self.eng = service.EngineService('a-host', 'a-topic') self.eng.thread_group_mgr = tools.DummyThreadGroupManager() self.eng.engine_id = 'engine-fake-uuid' cfg.CONF.set_default('heat_stack_user_role', 'stack_user_role')
def test_validate_with_environment(self): test_template = test_template_ref % 'WikiDatabase' test_template = test_template.replace('AWS::EC2::Instance', 'My::Instance') t = template_format.parse(test_template) engine = service.EngineService('a', 't') params = {'resource_registry': {'My::Instance': 'AWS::EC2::Instance'}} res = dict(engine.validate_template(None, t, params)) self.assertEqual('test.', res['Description'])
def test_validate_template_without_resources(self): hot_tpl = template_format.parse(''' heat_template_version: 2013-05-23 ''') engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, hot_tpl, {})) expected = {'Description': 'No description', 'Parameters': {}} self.assertEqual(expected, res)
def test_volume_snapshot_deletion_policy(self): t = template_format.parse(test_template_volume_snapshot) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual(res, {'Description': u'test.', 'Parameters': {}})
def test_invalid_deletion_policy(self): t = template_format.parse(test_template_invalid_deletion_policy) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual(res, {'Error': 'Invalid DeletionPolicy Destroy'})
def test_validate_properties(self): t = template_format.parse(test_template_invalid_property) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual(res, {'Error': 'Unknown Property UnknownProperty'})
def setUp(self): super(WaitCondMetadataUpdateTest, self).setUp() setup_dummy_db() self.ctx = context.get_admin_context() self.ctx.tenant_id = 'test_tenant' self.fc = fakes.FakeKeystoneClient() self.man = service.EngineService('a-host', 'a-topic') cfg.CONF.set_default('heat_waitcondition_server_url', 'http://127.0.0.1:8000/v1/waitcondition')
def setUp(self): super(stackServiceTestEmpty, self).setUp() # Change to a new, empty tenant context self.ctx = create_context(self.m, self.username, 'stack_list_all_empty_tenant') self.m.ReplayAll() self.man = service.EngineService('a-host', 'a-topic')
def test_validate_properties(self): t = template_format.parse(test_template_invalid_property) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t, {})) self.assertEqual({'Error': 'Unknown Property UnknownProperty'}, res)
def test_volume_snapshot_deletion_policy(self): t = template_format.parse(test_template_volume_snapshot) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t, {})) self.assertEqual({'Description': u'test.', 'Parameters': {}}, res)
def test_invalid_deletion_policy(self): t = template_format.parse(test_template_invalid_deletion_policy) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t, {})) self.assertEqual({'Error': 'Invalid DeletionPolicy Destroy'}, res)
def setUp(self): super(WaitCondMetadataUpdateTest, self).setUp() self.fc = fakes.FakeKeystoneClient() self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() self.man = service.EngineService('a-host', 'a-topic') cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition')