Ejemplo n.º 1
0
    def SetUp(self):
        self.descriptor = 'app.yaml'
        self.parsed = AppInfoFake('staged/app.yaml', 'my-service')
        self.source = 'my-source'
        self.upload_dir = 'staged'
        self.info = yaml_parsing.ServiceYamlInfo('app.yaml', self.parsed)

        self.parsed2 = AppInfoFake('staged/s2.yaml', 'other-service')
        self.info2 = yaml_parsing.ServiceYamlInfo('s2.yaml', self.parsed2)

        self.s1 = deployables.Service(self.descriptor, self.source, self.info,
                                      self.upload_dir)
        self.s2 = deployables.Service(self.descriptor, self.source, self.info2,
                                      self.upload_dir)
Ejemplo n.º 2
0
  def testCreateVersion(self):
    fake_build = app_build.BuildArtifact.MakeBuildIdArtifact('fake-build')
    fake_image = app_build.BuildArtifact.MakeImageArtifact('fake-image')
    fake_service = yaml_parsing.ServiceYamlInfo('app.yaml', self.appyaml)
    self.appyaml.Set('entrypoint', 'ls')

    image_version_expected = self.messages.Version(
        entrypoint=self.messages.Entrypoint(shell='ls'),
        runtime='python27',
        deployment=self.messages.Deployment(
            container=self.messages.ContainerInfo(image='fake-image')))

    image_version_result = self.client._CreateVersionResource(
        fake_service, None, None, fake_image)

    self.assertEqual(image_version_result, image_version_expected)

    # buildId deployments are only supported in the v1beta and v1alpha Admin API
    # versions currently, so use the v1beta client and messages.
    build_version_expected = self.beta_messages.Version(
        entrypoint=self.beta_messages.Entrypoint(shell='ls'),
        runtime='python27',
        deployment=self.beta_messages.Deployment(
            build=self.beta_messages.BuildInfo(cloudBuildId='fake-build')))

    build_version_result = self.beta_client._CreateVersionResource(
        fake_service, None, None, fake_build)

    self.assertEqual(build_version_result, build_version_expected)
Ejemplo n.º 3
0
  def testDeployServiceFromBuildId(self):
    """Test service deployment using an in-progress build ID."""
    fake_build = 'fake-build'
    fake_version = 'fake-version'

    fake_service = yaml_parsing.ServiceYamlInfo('app.yaml', self.appyaml)
    self.mocked_beta_client.apps_services_versions.Create.Expect(
        request=self.beta_messages.AppengineAppsServicesVersionsCreateRequest(
            parent='apps/fake-project/services/fake-service',
            version=self.beta_messages.Version(
                entrypoint=self.beta_messages.Entrypoint(shell=''),
                runtime='python27',
                deployment=self.beta_messages.Deployment(
                    build=self.beta_messages.BuildInfo(
                        cloudBuildId=fake_build)),
                id=fake_version,
            ),
        ),
        response=self.beta_messages.Operation(done=True))

    properties.VALUES.core.project.Set('fake-project')
    cloud_client_mock = mock.MagicMock()
    build_res = resources.REGISTRY.Parse(
        fake_build,
        params={'projectId': 'fake-project'},
        collection='cloudbuild.projects.builds')
    cloud_client_mock = mock.MagicMock()
    self.StartObjectPatch(
        cloudbuild_logs, 'CloudBuildClient', return_value=cloud_client_mock)
    fake_build = app_build.BuildArtifact.MakeBuildIdArtifact(fake_build)
    fake_build.build_op = 'fake_build_op'
    self.beta_client.DeployService('fake-service', fake_version, fake_service,
                                   None, fake_build)
    cloud_client_mock.Stream.assert_called_once_with(build_res, out=log.status)
Ejemplo n.º 4
0
  def testDeployServiceWithEnvVars(self):
    """Test service deployment using an image name."""
    fake_image = 'fake-image'
    fake_version = 'fake-version'
    self.appyaml.Set('entrypoint', 'ls')
    variables = appinfo.EnvironmentVariables()
    variables.update({'FOO': 'on', 'BAR': 'true', 'BAZ': '123'})
    self.appyaml.Set('env_variables', variables)

    fake_service = yaml_parsing.ServiceYamlInfo('app.yaml', self.appyaml)
    env_var_message = self.messages.Version.EnvVariablesValue.AdditionalProperty
    self.mocked_client.apps_services_versions.Create.Expect(
        request=self.messages.AppengineAppsServicesVersionsCreateRequest(
            parent='apps/fake-project/services/fake-service',
            version=self.messages.Version(
                entrypoint=self.messages.Entrypoint(shell='ls'),
                runtime='python27',
                deployment=self.messages.Deployment(
                    container=self.messages.ContainerInfo(image=fake_image)),
                id=fake_version,
                envVariables=self.messages.Version.EnvVariablesValue(
                    additionalProperties=[
                        env_var_message(key='BAR', value='true'),
                        env_var_message(key='BAZ', value='123'),
                        env_var_message(key='FOO', value='on')]))),
        response=self.messages.Operation(done=True))

    fake_build = app_build.BuildArtifact.MakeImageArtifact('fake-image')
    self.client.DeployService('fake-service', fake_version, fake_service,
                              None, fake_build)
Ejemplo n.º 5
0
def _MakeConfig(runtime, environment='flex'):
    module = 'my-module'
    source_dir = 'my-module'
    app_yaml = appinfo.AppInfoExternal(runtime=runtime, env=environment)
    source_dir = os.path.join(source_dir, module)
    app_yaml_path = os.path.join(source_dir, 'app.yaml')
    yaml_info = yaml_parsing.ServiceYamlInfo(app_yaml_path, app_yaml)
    return yaml_info
Ejemplo n.º 6
0
  def testDeployService_WithExtraConfigs(self):
    fake_image = 'fake-image'
    fake_version = 'fake-version'
    self.appyaml.Set('entrypoint', 'ls')

    extra_config_settings = {
        'cloud_build_timeout': '50',
    }

    beta_settings = appinfo.BetaSettings()
    # This value is here to test that existing beta_settings value are not
    # over-written
    beta_settings['foo'] = 'bar'
    self.appyaml.beta_settings = beta_settings
    fake_service = yaml_parsing.ServiceYamlInfo('app.yaml', self.appyaml)

    prop = self.messages.Version.BetaSettingsValue.AdditionalProperty
    beta_settings = self.messages.Version.BetaSettingsValue(
        additionalProperties=[
            prop(key='cloud_build_timeout', value='50'),
            prop(key='foo', value='bar'),
        ])
    self.mocked_client.apps_services_versions.Create.Expect(
        request=self.messages.AppengineAppsServicesVersionsCreateRequest(
            parent='apps/fake-project/services/fake-service',
            version=self.messages.Version(
                entrypoint=self.messages.Entrypoint(shell='ls'),
                runtime='python27',
                deployment=self.messages.Deployment(
                    container=self.messages.ContainerInfo(image=fake_image)),
                id=fake_version,
                betaSettings=beta_settings),),
        response=self.messages.Operation(done=True))

    fake_build = app_build.BuildArtifact.MakeImageArtifact('fake-image')
    self.client.DeployService('fake-service', fake_version, fake_service, None,
                              fake_build,
                              extra_config_settings)
Ejemplo n.º 7
0
  def testDeployService(self):
    """Test service deployment using an image name."""
    fake_image = 'fake-image'
    fake_version = 'fake-version'
    self.appyaml.Set('entrypoint', 'ls')

    fake_service = yaml_parsing.ServiceYamlInfo('app.yaml', self.appyaml)
    self.mocked_client.apps_services_versions.Create.Expect(
        request=self.messages.AppengineAppsServicesVersionsCreateRequest(
            parent='apps/fake-project/services/fake-service',
            version=self.messages.Version(
                entrypoint=self.messages.Entrypoint(shell='ls'),
                runtime='python27',
                deployment=self.messages.Deployment(
                    container=self.messages.ContainerInfo(image=fake_image)),
                id=fake_version,
            ),
        ),
        response=self.messages.Operation(done=True))

    fake_build = app_build.BuildArtifact.MakeImageArtifact('fake-image')
    self.client.DeployService('fake-service', fake_version, fake_service,
                              None, fake_build)
Ejemplo n.º 8
0
  def testDeployServiceFromBuildOptions(self):
    """Test service deployment using server-side builds."""
    fake_build = 'fake-build'
    fake_version = 'fake-version'
    manifest = {
        'filea': {'sourceUrl': 'https://storage.googleapis.com/a/b/c.py',
                  'sha1Sum': '123'},
    }
    app_yaml_path = 'yaml.yaml'
    cloud_build_timeout = '333'
    deployment_message = encoding.PyValueToMessage(
        self.beta_messages.Deployment, {'files': manifest,
                                        'cloudBuildOptions': {
                                            'appYamlPath': app_yaml_path,
                                            'cloudBuildTimeout':
                                            cloud_build_timeout,
                                        }})
    fake_service = yaml_parsing.ServiceYamlInfo('app.yaml', self.appyaml)
    op_metadata_warning1 = encoding.MessageToPyValue(
        self.beta_messages.OperationMetadataV1Beta(
            warning=['oh-no!'],
            createVersionMetadata=(
                self.beta_messages.CreateVersionMetadataV1Beta(
                    cloudBuildId='1-2-3-4',)),
        ))
    op_metadata_warning2 = encoding.MessageToPyValue(
        self.beta_messages.OperationMetadataV1Beta(
            warning=['oh-no!', 'it\'s getting worse!'],
            createVersionMetadata=(
                self.beta_messages.CreateVersionMetadataV1Beta(
                    cloudBuildId='1-2-3-4',)),
        ))
    op_metadata_warning1.update({
        '@type': 'type.googleapis.com/google.appengine.OperationMetadataV1Beta'
    })
    op_metadata_warning2.update({
        '@type': 'type.googleapis.com/google.appengine.OperationMetadataV1Beta'
    })
    self.mocked_beta_client.apps_services_versions.Create.Expect(
        request=self.beta_messages.AppengineAppsServicesVersionsCreateRequest(
            parent='apps/fake-project/services/fake-service',
            version=self.beta_messages.Version(
                entrypoint=self.beta_messages.Entrypoint(shell=''),
                runtime='python27',
                deployment=deployment_message,
                id=fake_version,
            ),
        ),
        response=self.beta_messages.Operation(
            name='apps/fake-project/operations/a-b-c-d',
            metadata=encoding.PyValueToMessage(
                self.beta_messages.Operation.MetadataValue,
                op_metadata_warning1,
            )))
    self.mocked_beta_client.apps_operations.Get.Expect(
        request=self.beta_messages.AppengineAppsOperationsGetRequest(
            name='apps/fake-project/operations/a-b-c-d'),
        response=self.beta_messages.Operation(
            metadata=encoding.PyValueToMessage(
                self.beta_messages.Operation.MetadataValue,
                op_metadata_warning2)))
    self.mocked_beta_client.apps_operations.Get.Expect(
        request=self.beta_messages.AppengineAppsOperationsGetRequest(
            name='apps/fake-project/operations/a-b-c-d'),
        response=self.beta_messages.Operation(done=True))

    fake_build = app_build.BuildArtifact.MakeBuildOptionsArtifact({
        'appYamlPath': app_yaml_path,
        'cloudBuildTimeout': cloud_build_timeout,
    })
    properties.VALUES.core.project.Set('fake-project')
    build_res = resources.REGISTRY.Parse(
        '1-2-3-4',
        params={'projectId': 'fake-project'},
        collection='cloudbuild.projects.builds')
    cloud_client_mock = mock.MagicMock()
    self.StartObjectPatch(
        cloudbuild_logs, 'CloudBuildClient', return_value=cloud_client_mock)
    warning_mock = self.StartPropertyPatch(log, 'warning')

    self.beta_client.DeployService('fake-service', fake_version, fake_service,
                                   manifest, fake_build)
    cloud_client_mock.Stream.assert_called_once_with(build_res, out=log.status)
    warning_mock.assert_has_calls(
        [mock.call('oh-no!\n'),
         mock.call('it\'s getting worse!\n')],
        any_order=True)