Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PULUMI_TEST_MODE environment variable doesn't work in Python #2818

Closed
clstokes opened this issue Jun 12, 2019 · 0 comments · Fixed by #2825
Closed

PULUMI_TEST_MODE environment variable doesn't work in Python #2818

clstokes opened this issue Jun 12, 2019 · 0 comments · Fixed by #2825
Assignees
Labels
kind/bug Some behavior is incorrect or out of spec
Milestone

Comments

@clstokes
Copy link
Contributor

The PULUMI_TEST_MODE environment variable doesn't work for Python applications. Instead users must set a flag programmatically in their Python application as shown below (for posterity's sake).

The PULUMI_TEST_MODE environment variable should work for all supported Pulumi languages. We should also document this officially.

For reference:

import pulumi
import unittest
import asyncio

# Import the Pulumi SDK and turn on test mode *before* allocating anything.

pulumi.runtime.settings._set_test_mode_enabled(True)    # This should be able to be set via PULUMI_TEST_MODE
pulumi.runtime.settings._set_project('webserver')
pulumi.runtime.settings._set_stack('test')

# Tests come next:


def async_test(coro):
    def wrapper(*args, **kwargs):
        loop = asyncio.new_event_loop()
        loop.run_until_complete(coro(*args, **kwargs))
        loop.close()
    return wrapper


class InstanceTests(unittest.TestCase):
    @async_test
    async def test_no_internet_access(self):
        # Now import the infrastructure module which will allocate our resource objects.
        from infra import group, server

        # Rendezvous with the resource's resulting ingress rules.
        ingress_fut = asyncio.Future()
        group.ingress.apply(lambda ig: ingress_fut.set_result(ig))
        ingress = await ingress_fut

        # Now loop through them and reject any that are open to the Internet (0.0.0.0/0).
        for rule in ingress:
            for cidr in rule['cidr_blocks']:
                self.assertNotEqual('0.0.0.0/0', cidr)

@lukehoban lukehoban added the kind/bug Some behavior is incorrect or out of spec label Jun 12, 2019
@ellismg ellismg added this to the 0.24 milestone Jun 12, 2019
ellismg added a commit that referenced this issue Jun 13, 2019
This mirrors the UX that we have in node where you can set
`PULUMI_TEST_MODE` to control if test mode is enabled from outside
your program.

Fixes #2818
ellismg added a commit that referenced this issue Jun 14, 2019
This mirrors the UX that we have in node where you can set
`PULUMI_TEST_MODE` to control if test mode is enabled from outside
your program.

Fixes #2818
ellismg added a commit that referenced this issue Jun 14, 2019
This mirrors the UX that we have in node where you can set
`PULUMI_TEST_MODE` to control if test mode is enabled from outside
your program.

Fixes #2818
ellismg added a commit that referenced this issue Jun 17, 2019
This mirrors the UX that we have in node where you can set
`PULUMI_TEST_MODE` to control if test mode is enabled from outside
your program.

Fixes #2818
ellismg added a commit that referenced this issue Jun 18, 2019
This mirrors the UX that we have in node where you can set
`PULUMI_TEST_MODE` to control if test mode is enabled from outside
your program.

Fixes #2818
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Some behavior is incorrect or out of spec
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants