def test_rendering_raw_two_variables(): fixture = """{{ b }} {{ a }}.""" subject = render(fixture, a="{% raw %}Worl{% endraw %}d", b="He{% raw %}llo{% endraw %}") assert_that(subject, equal_to("Hello World."))
def test_rendering_raw_one_indirection(): fixture = """{{ a }}.""" subject = render(fixture, a="{{ b }}", b="{% raw %}Hello World{% endraw %}") assert_that(subject, equal_to("Hello World."))
def execute(self, context): """Perform the plugin's task purpose.""" if context: from deployer.rendering import render msg = render(self.fail, **context.variables.last()) else: msg = self.fail LOGGER.error("| %s", msg) return Result(result='failure')
def execute(self, context): """Perform the plugin's task purpose.""" if context: msg = render(self.msg, **context.variables.last()) else: msg = self.msg for line in msg.splitlines(False): LOGGER.info("| %s", line) return Result(result='success')
def execute(self, context): """Perform the plugin's task purpose.""" result = Result(result='success') cmd = render(self.cmd, **context.variables.last()) argv = shlex.split(cmd, False, False) LOGGER.debug("Running: %r" % argv) try: result['stdout'] = Plugin.run(argv) except ProcessTerminated as e: LOGGER.error("Process failed and returned %d" % e.exitCode) result = Result(result='failure') return result
def execute(self, context): """Perform the plugin's task purpose.""" for env in os.environ.copy(): for pattern in self.env_unset: if fnmatch.fnmatchcase(env, pattern): LOGGER.debug("Removing '%s' from system environment.", env) try: os.unsetenv(env) except AttributeError: # noqa: no-cover pass # noqa: no-cover del os.environ[env] else: LOGGER.debug( "Keeping '%s' present in the system environment.", env) for key, value in self.env_set.items(): if context: value = render(value, **context.variables.last()) LOGGER.debug("Setting '%s' to '%s', in the system environment.", key, value) os.putenv(key, value) os.environ[key] = value return Result(result='success')
def execute(self, context): """Proxy of a plug-in's `execute` method.""" result = Result(result='failed') if context and len(self._match_tags) > 0 and len(context.tags) > 0: found = False for tag in context.tags: if tag in self._match_tags: found = True if not found: LOGGER.debug( "Skipping because this item does not have a user-selected tag." ) return Result(result='skipped') if self._when is not None: expr = BooleanExpression(self._when) if not expr.evaluate(context): return Result(result='skipped') if self._with_items is not None: if context and isinstance(self._with_items, six.string_types): with_items = my_safe_eval( render(self._with_items, **context.variables.last())) else: with_items = self._with_items for item in with_items: with with_scoped_variables(context, item): result = self._execute_one(context) if not result: break else: result = self._execute_one(context) return result
def execute(self, context): """Perform the plugin's task purpose.""" result = Result(result='success') for tag in self._tags: if isinstance(self._tags, (dict, OrderedDict)): # we have a dictionary of items. LOGGER.debug("Setting environment variables for tag.") for key, value in self._tags[tag].items(): if context: value = render(value, **context.variables.last()) else: # noqa: no-cover raise RuntimeError("Context is required.") LOGGER.debug( "Setting '%s' to '%s', in the system environment.", key, value) os.putenv(key, value) os.environ[key] = value with matrix_scoped_variables(context, tag): matrix_list = [] matrix_tags = [] if context and len(context.matrix_tags) > 0: matrix_list = context.variables.last( )['matrix_list'] if 'matrix_list' in context.variables.last( ) else [] matrix_tags = context.matrix_tags if len(matrix_tags) > 0 and not all([ fnmatch.fnmatch(x[1], x[0]) for x in zip(matrix_tags, matrix_list) ]): LOGGER.debug( "Skipping because this matrix item does not have a user-selected matrix tag." ) LOGGER.debug("matrix_list=%r matrix_tags=%r", matrix_list, matrix_tags) result = Result(result='skipped') else: LOGGER.debug('Beginning matrix entry: %s', tag) result = self._execute_tasks(context) LOGGER.debug('Completed matrix entry: %s', tag) if isinstance(self._tags, (dict, OrderedDict)): # we have a dictionary of items. LOGGER.debug("Unsetting environment variables for tag.") for key, _ in self._tags[tag].items(): try: os.unsetenv(key) except AttributeError: # noqa: no-cover pass # noqa: no-cover del os.environ[key] if not result: break if result['result'] in ['skipped', 'continue']: result = Result(result='success') return result
def test_rendering_raw_one_variable(): fixture = """Hello {{ test_env.a }}.""" subject = render(fixture, test_env={'a': '''{% raw %}World{% endraw %}'''}) assert_that(subject, equal_to("Hello World."))
def test_rendering_passthrough_raw_string_and_variable(): fixture = """{% raw %}Testing {% endraw %}{{ a }}""" subject = render(fixture, a='''{% raw %}{{ string }}.{% endraw %}''') assert_that(subject, equal_to("Testing {{ string }}."))
def test_rendering_passthrough_raw_string(): fixture = """{% raw %}Testing string.{% endraw %}""" subject = render(fixture) assert_that(subject, equal_to("Testing string."))
def test_rendering_two_indirections(): fixture = """{{ a }}.""" subject = render(fixture, a="{{ b }}", b="{{ c }}", c="Hello World") assert_that(subject, equal_to("Hello World."))
def test_rendering_two_variables(): fixture = """{{ b }} {{ a }}.""" subject = render(fixture, a="World", b="Hello") assert_that(subject, equal_to("Hello World."))
def test_rendering_one_variable(): fixture = """Hello {{ a }}.""" subject = render(fixture, a="World") assert_that(subject, equal_to("Hello World."))
def test_rendering_passthrough_string(): fixture = """Testing string.""" subject = render(fixture) assert_that(subject, equal_to(fixture))
def test_rendering_simple_context(): context = Context() fixture = """{{ platform }}""" subject = render(fixture, **context.variables.last()) assert_that(subject, equal_to(sys.platform.lower()))