コード例 #1
0
 def testLoadManifest(self):
     self.Touch(self.temp_path,
                'runtimes.yaml',
                contents=ManifestTest.MANIFEST_FILE)
     self.StartObjectPatch(storage_api.StorageClient,
                           'ReadObject',
                           side_effect=lambda x: io.BytesIO(
                               ManifestTest.MANIFEST_FILE.encode('utf-8')))
     for builder_root in [_URLFromFile(self.temp_path), 'gs://mybucket']:
         m = runtime_builders.Manifest.LoadFromURI(builder_root +
                                                   '/runtimes.yaml')
         self.assertEqual(m._data, yaml.load(ManifestTest.MANIFEST_FILE))
         self.assertEqual(
             set(m.Runtimes()),
             {'erlang', 'erlang-1', 'erlang-1.2', 'erlang-0', 'erlang-0.1'})
         self.assertIsNone(m.GetBuilderReference('foo'))
         self.assertEqual(
             m.GetBuilderReference('erlang-1.2'),
             runtime_builders.BuilderReference(
                 'erlang-1.2', builder_root + '/erlang-1.2-12345.yaml'))
         self.assertEqual(
             m.GetBuilderReference('erlang'),
             runtime_builders.BuilderReference(
                 'erlang-1.2', builder_root + '/erlang-1.2-12345.yaml'))
         self.assertEqual(
             m.GetBuilderReference('erlang-0'),
             runtime_builders.BuilderReference('erlang-0.1', None,
                                               'erlang-0.1 is deprecated.'))
コード例 #2
0
 def testDeprecationMessage(self):
     br = runtime_builders.BuilderReference('foo', 'file:///junkpath')
     br.WarnIfDeprecated()
     self.AssertErrEquals('')
     br = runtime_builders.BuilderReference('foo', 'file:///junkpath',
                                            'deprecated')
     br.WarnIfDeprecated()
     self.AssertErrEquals('WARNING: deprecated\n')
コード例 #3
0
    def testReadError(self):
        with self.assertRaises(runtime_builders.FileReadError):
            br = runtime_builders.BuilderReference('foo', 'file:///junkpath')
            br.LoadCloudBuild({
                '_OUTPUT_IMAGE': 'gcr.io/my/image',
                '_GAE_APPLICATION_YAML_PATH': 'app.yaml'
            })

        with self.assertRaisesRegex(
                runtime_builders.CloudBuildLoadError,
                r'There is no build file associated with runtime \[foo\]'):
            br = runtime_builders.BuilderReference('foo', None)
            br.LoadCloudBuild({
                '_OUTPUT_IMAGE': 'gcr.io/my/image',
                '_GAE_APPLICATION_YAML_PATH': 'app.yaml'
            })
コード例 #4
0
 def testLegacyDefaultVersion(self):
     ref = self._GetReferenceFromYaml("""\
   env: flex
   runtime: fortran
   """)
     path = _URLFromFile(self.temp_path, 'fortran-3.yaml')
     self.assertEqual(ref,
                      runtime_builders.BuilderReference('fortran', path))
コード例 #5
0
 def testCustom(self):
     ref = self._GetReferenceFromYaml("""\
     env: flex
     runtime: custom
     """)
     path = _URLFromFile(self.temp_path,
                         runtime_builders.Resolver.CLOUDBUILD_FILE)
     self.assertEqual(ref,
                      runtime_builders.BuilderReference('custom', path))
コード例 #6
0
 def testLegacyPinnedVersion(self):
     ref = self._GetReferenceFromYaml("""\
   env: flex
   runtime: fortran
   runtime_config:
     runtime_version: 2
   """)
     path = _URLFromFile(self.temp_path, 'fortran-2.yaml')
     self.assertEqual(ref,
                      runtime_builders.BuilderReference('fortran', path))
コード例 #7
0
 def testPinned(self):
     ref = self._GetReferenceFromYaml("""\
   env: flex
   runtime: gs://my-bucket/my-builder.yaml
   """)
     self.assertEqual(
         ref,
         runtime_builders.BuilderReference(
             'gs://my-bucket/my-builder.yaml',
             'gs://my-bucket/my-builder.yaml'))
コード例 #8
0
 def testUnsupportedPath(self):
     for root in ('bad-url', 'badprotocol://bad-url', 'http://foo'):
         path = root + '/erlang-v2.yaml'
         with self.assertRaisesRegex(
                 runtime_builders.InvalidRuntimeBuilderURI,
                 re.escape('[{}] is not a valid runtime builder URI'.format(
                     path))):
             br = runtime_builders.BuilderReference('foo', path)
             br.LoadCloudBuild({
                 '_OUTPUT_IMAGE': 'gcr.io/my/image',
                 '_GAE_APPLICATION_YAML_PATH': 'app.yaml'
             })
コード例 #9
0
 def testGCSFile(self):
     builder_path = 'gs://mybucket/erlang-v2.yaml'
     read_object_mock = self.StartObjectPatch(
         storage_api.StorageClient,
         'ReadObject',
         side_effect=lambda x: io.BytesIO(
             BuilderReferenceTest.BUILD_FILE.encode('utf-8')))
     br = runtime_builders.BuilderReference(builder_path, builder_path)
     self.assertEqual(br.runtime, builder_path)
     self.assertEqual(
         br.LoadCloudBuild({
             '_OUTPUT_IMAGE': 'gcr.io/my/image',
             '_GAE_APPLICATION_YAML_PATH': 'app.yaml'
         }),
         self.messages.Build(
             images=['$_OUTPUT_IMAGE'],
             steps=[
                 self.messages.BuildStep(
                     name='gcr.io/my-project/erlang-builder:v2',
                     env=[
                         'GAE_APPLICATION_YAML_PATH='
                         '${_GAE_APPLICATION_YAML_PATH}'
                     ]),
                 self.messages.BuildStep(
                     name='gcr.io/cloud-builders/docker',
                     args=['build', '-t', '$_OUTPUT_IMAGE', '.'],
                     env=[
                         'GAE_APPLICATION_YAML_PATH='
                         '${_GAE_APPLICATION_YAML_PATH}'
                     ])
             ],
             substitutions=self.messages.Build.
             SubstitutionsValue(additionalProperties=[
                 self.messages.Build.SubstitutionsValue.AdditionalProperty(
                     key='_GAE_APPLICATION_YAML_PATH', value='app.yaml'),
                 self.messages.Build.SubstitutionsValue.AdditionalProperty(
                     key='_OUTPUT_IMAGE', value='gcr.io/my/image')
             ]),
             options=self.messages.BuildOptions(
                 substitutionOption=self.substitution_types.ALLOW_LOOSE),
         ))
     config_object = storage_util.ObjectReference.FromUrl(builder_path)
     read_object_mock.assert_called_once_with(config_object)
コード例 #10
0
    def testManifest(self):
        ref = self._GetReferenceFromYaml("""\
      env: flex
      runtime: erlang
      """)
        path = _URLFromFile(self.temp_path, 'erlang-1.yaml')
        self.assertEqual(ref,
                         runtime_builders.BuilderReference('erlang-1', path))

        self.StartObjectPatch(
            runtime_builders,
            '_Read',
            side_effect=runtime_builders.FileReadError('No manifest'))
        with self.assertRaisesRegex(
                runtime_builders.BuilderResolveError,
                r'Unable to resolve a builder for runtime: \[erlang\]'):
            self._GetReferenceFromYaml("""\
        env: flex
        runtime: erlang
        """)
コード例 #11
0
 def testLocalFile(self):
     self.Touch(self.temp_path,
                'erlang-v2.yaml',
                contents=BuilderReferenceTest.BUILD_FILE)
     br = runtime_builders.BuilderReference(
         'foo', _URLFromFile(self.temp_path, 'erlang-v2.yaml'))
     self.assertEqual(br.runtime, 'foo')
     self.assertEqual(
         br.LoadCloudBuild({
             '_OUTPUT_IMAGE': 'gcr.io/my/image',
             '_GAE_APPLICATION_YAML_PATH': 'app.yaml'
         }),
         self.messages.Build(
             images=['$_OUTPUT_IMAGE'],
             steps=[
                 self.messages.BuildStep(
                     name='gcr.io/my-project/erlang-builder:v2',
                     env=[
                         'GAE_APPLICATION_YAML_PATH='
                         '${_GAE_APPLICATION_YAML_PATH}'
                     ]),
                 self.messages.BuildStep(
                     name='gcr.io/cloud-builders/docker',
                     args=['build', '-t', '$_OUTPUT_IMAGE', '.'],
                     env=[
                         'GAE_APPLICATION_YAML_PATH='
                         '${_GAE_APPLICATION_YAML_PATH}'
                     ])
             ],
             substitutions=self.messages.Build.
             SubstitutionsValue(additionalProperties=[
                 self.messages.Build.SubstitutionsValue.AdditionalProperty(
                     key='_GAE_APPLICATION_YAML_PATH', value='app.yaml'),
                 self.messages.Build.SubstitutionsValue.AdditionalProperty(
                     key='_OUTPUT_IMAGE', value='gcr.io/my/image')
             ]),
             options=self.messages.BuildOptions(
                 substitutionOption=self.substitution_types.ALLOW_LOOSE),
         ))