Ejemplo n.º 1
0
 def test_can_invoke_pip(self):
     pip = SubprocessPip()
     rc, err = pip.main(['--version'])
     # Simple assertion that we can execute pip and it gives us some output
     # and nothing on stderr.
     assert rc == 0
     assert err == b''
Ejemplo n.º 2
0
 def test_can_invoke_pip(self):
     pip = SubprocessPip()
     rc, err = pip.main(['--version'])
     # Simple assertion that we can execute pip and it gives us some output
     # and nothing on stderr.
     assert rc == 0
     assert err == b''
Ejemplo n.º 3
0
 def test_does_error_code_propagate(self):
     pip = SubprocessPip()
     rc, _, err = pip.main(['badcommand'])
     assert rc != 0
     # Don't want to depend on a particular error message from pip since it
     # may change if we pin a differnet version to Chalice at some point.
     # But there should be a non-empty error message of some kind.
     assert err != b''
Ejemplo n.º 4
0
 def test_does_error_code_propagate(self):
     pip = SubprocessPip()
     rc, err = pip.main(['badcommand'])
     assert rc != 0
     # Don't want to depend on a particular error message from pip since it
     # may change if we pin a differnet version to Chalice at some point.
     # But there should be a non-empty error message of some kind.
     assert err != b''
    def test_does_use_custom_pip_import_string(self):
        fake_osutils = FakePopenOSUtils([FakePopen(0, '', '')])
        expected_import_statement = 'foobarbaz'
        pip = SubprocessPip(osutils=fake_osutils,
                            import_string=expected_import_statement)
        pip.main(['--version'])

        pip_execution_string = fake_osutils.popens[0][0][0][2]
        import_statement = pip_execution_string.split(';')[1].strip()
        assert import_statement == expected_import_statement
Ejemplo n.º 6
0
    def test_does_use_custom_pip_import_string(self):
        fake_osutils = FakePopenOSUtils([FakePopen(0, '', '')])
        expected_import_statement = 'foobarbaz'
        pip = SubprocessPip(osutils=fake_osutils,
                            import_string=expected_import_statement)
        pip.main(['--version'])

        pip_execution_string = fake_osutils.popens[0][0][0][2]
        import_statement = pip_execution_string.split(';')[1].strip()
        assert import_statement == expected_import_statement
Ejemplo n.º 7
0
def create_build_stage(osutils, ui, swagger_gen):
    # type: (OSUtils, UI, SwaggerGenerator) -> BuildStage
    pip_runner = PipRunner(pip=SubprocessPip(osutils=osutils),
                           osutils=osutils)
    dependency_builder = PipDependencyBuilder(
        osutils=osutils,
        pip_runner=pip_runner
    )
    build_stage = BuildStage(
        steps=[
            InjectDefaults(),
            DeploymentPackager(
                packager=LambdaDeploymentPackager(
                    osutils=osutils,
                    dependency_builder=dependency_builder,
                    ui=ui,
                ),
            ),
            PolicyGenerator(
                policy_gen=AppPolicyGenerator(
                    osutils=osutils
                ),
                osutils=osutils,
            ),
            SwaggerBuilder(
                swagger_generator=swagger_gen,
            ),
            LambdaEventSourcePolicyInjector(),
            WebsocketPolicyInjector()
        ],
    )
    return build_stage
Ejemplo n.º 8
0
def create_default_deployer(session, config, ui):
    # type: (Session, Config, UI) -> Deployer
    client = TypedAWSClient(session)
    osutils = OSUtils()
    pip_runner = PipRunner(pip=SubprocessPip(osutils=osutils), osutils=osutils)
    dependency_builder = PipDependencyBuilder(osutils=osutils,
                                              pip_runner=pip_runner)
    return Deployer(
        application_builder=ApplicationGraphBuilder(),
        deps_builder=DependencyBuilder(),
        build_stage=BuildStage(steps=[
            InjectDefaults(),
            DeploymentPackager(packager=LambdaDeploymentPackager(
                osutils=osutils,
                dependency_builder=dependency_builder,
                ui=UI(),
            ), ),
            PolicyGenerator(policy_gen=AppPolicyGenerator(osutils=osutils), ),
            SwaggerBuilder(swagger_generator=TemplatedSwaggerGenerator(), )
        ], ),
        plan_stage=PlanStage(
            osutils=osutils,
            remote_state=RemoteState(
                client, config.deployed_resources(config.chalice_stage)),
        ),
        sweeper=UnreferencedResourcePlanner(),
        executor=Executor(client, ui),
        recorder=ResultsRecorder(osutils=osutils),
    )
Ejemplo n.º 9
0
def create_build_stage(osutils, ui, swagger_gen, config):
    # type: (OSUtils, UI, SwaggerGenerator, Config) -> BuildStage
    pip_runner = PipRunner(pip=SubprocessPip(osutils=osutils), osutils=osutils)
    dependency_builder = PipDependencyBuilder(osutils=osutils,
                                              pip_runner=pip_runner)
    deployment_packager = cast(BaseDeployStep, None)
    if config.automatic_layer:
        deployment_packager = ManagedLayerDeploymentPackager(
            lambda_packager=AppOnlyDeploymentPackager(
                osutils=osutils,
                dependency_builder=dependency_builder,
                ui=ui,
            ),
            layer_packager=LayerDeploymentPackager(
                osutils=osutils,
                dependency_builder=dependency_builder,
                ui=ui,
            ))
    else:
        deployment_packager = DeploymentPackager(
            packager=LambdaDeploymentPackager(
                osutils=osutils,
                dependency_builder=dependency_builder,
                ui=ui,
            ))
    build_stage = BuildStage(steps=[
        InjectDefaults(), deployment_packager,
        PolicyGenerator(
            policy_gen=AppPolicyGenerator(osutils=osutils),
            osutils=osutils,
        ),
        SwaggerBuilder(swagger_generator=swagger_gen, ),
        LambdaEventSourcePolicyInjector(),
        WebsocketPolicyInjector()
    ], )
    return build_stage
Ejemplo n.º 10
0
    def package(self):
        pip_runner = PipRunner(
            pip=SubprocessPip(osutils=self._osutils),
            osutils=self._osutils
        )

        dependency_builder = PipDependencyBuilder(
            osutils=self._osutils,
            pip_runner=pip_runner
        )

        packager = ChaliceLambdaDeploymentPackager(
            osutils=self._osutils,
            dependency_builder=dependency_builder,
            ui=self._ui,
        )

        self.package_path = packager.create_deployment_package(
            self.source_code_path,
            'python3.6'
        )
        package_content = self.load_package()
        self.cleanup()
        return package_content