def test_template_onchange_restart_nochange(self, mtemplating, mrestart, mfile_hash, misfile, mlog): mfile_hash.return_value = "myhash" misfile.return_value = True manager = mock.Mock( ** {'get_service.return_value': { 'required_data': [{ 'foo': 'bar' }] }}) callback = services.template( source='foo.yml', target='bar.yml', owner='user', group='group', perms=0o555, on_change_action=(partial(mrestart, "mysuperservice")), ) assert isinstance(callback, services.ManagerCallback) assert not mtemplating.render.called callback(manager, 'test', 'event') mtemplating.render.assert_called_once_with('foo.yml', 'bar.yml', { 'foo': 'bar', 'ctx': { 'foo': 'bar' } }, 'user', 'group', 0o555, template_loader=None) self.assertEqual(mrestart.call_args_list, [])
def test_template_loader(self, mtemplating): manager = mock.Mock( ** {'get_service.return_value': { 'required_data': [{ 'foo': 'bar' }] }}) callback = services.template(source='foo.yml', target='bar.yml', owner='user', group='group', perms=0o555, template_loader='myloader') assert isinstance(callback, services.ManagerCallback) assert not mtemplating.render.called callback(manager, 'test', 'event') mtemplating.render.assert_called_once_with('foo.yml', 'bar.yml', { 'foo': 'bar', 'ctx': { 'foo': 'bar' } }, 'user', 'group', 0o555, template_loader='myloader')
def test_template_defaults(self, mtemplating): manager = mock.Mock( ** {'get_service.return_value': { 'required_data': [{ 'foo': 'bar' }] }}) self.assertRaises(TypeError, services.template, source='foo.yml') callback = services.template(source='foo.yml', target='bar.yml') assert isinstance(callback, services.ManagerCallback) assert not mtemplating.render.called callback(manager, 'test', 'event') mtemplating.render.assert_called_once_with('foo.yml', 'bar.yml', {'foo': 'bar'}, 'root', 'root', 0o444)
def test_template_onchange_restart(self, mtemplating, mrestart, mfile_hash, misfile): def random_string(arg): return uuid.uuid4() mfile_hash.side_effect = random_string misfile.return_value = True manager = mock.Mock( ** {'get_service.return_value': { 'required_data': [{ 'foo': 'bar' }] }}) callback = services.template( source='foo.yml', target='bar.yml', owner='user', group='group', perms=0o555, on_change_action=(partial(mrestart, "mysuperservice")), ) assert isinstance(callback, services.ManagerCallback) assert not mtemplating.render.called callback(manager, 'test', 'event') mtemplating.render.assert_called_once_with('foo.yml', 'bar.yml', { 'foo': 'bar', 'ctx': { 'foo': 'bar' } }, 'user', 'group', 0o555, template_loader=None) mrestart.assert_called_with('mysuperservice')
ADMIN_UI_PACKAGES = ['build-essential', 'git', 'ruby1.9.3', 'bundler', 'libmysqlclient-dev', 'libsqlite3-dev', 'libpq-dev'] CF_DIR = '/var/lib/cloudfoundry' ADMIN_UI_DIR = os.path.join(CF_DIR, 'admin-ui') ADMIN_UI_CONFIG_PATH = os.path.join(ADMIN_UI_DIR, 'config', 'default.yml') upstart_template_context = {'working_directory': ADMIN_UI_DIR, 'config_path': ADMIN_UI_CONFIG_PATH, 'user': '******', 'group': 'vcap'} SERVICE = [ { 'service': 'admin-ui', 'ports': [charm_config['port']], 'required_data': [contexts.NatsRelation(), contexts.OrchestratorRelation(), contexts.CloudControllerDBRelation(), contexts.UAARelation(), contexts.UAADBRelation(), hookenv.config(), upstart_template_context], 'data_ready': [ services.template(source='admin-ui.conf', target='/etc/init/admin-ui.conf'), services.template(source='default.yml', target=ADMIN_UI_CONFIG_PATH), ] } ]