Esempio n. 1
0
 def test_bool(self):
    bindings = YamlBindings()
    bindings.import_string(
       "root:\n - elem: true\n - elem: True\n - elem: false\n - elem: False\ncopy: ${root}")
    self.assertEqual([{'elem': True}, {'elem': True}, {'elem': False}, {'elem': False}],
                     bindings.get('root'))
    self.assertEqual(bindings.get('root'), bindings.get('copy'))
Esempio n. 2
0
 def test_list(self):
    bindings = YamlBindings()
    bindings.import_string(
       "root:\n - elem: 'first'\n - elem: 2\n - elem: true\ncopy: ${root}")
    self.assertEqual([{'elem': 'first'}, {'elem': 2}, {'elem': True}],
                     bindings.get('root'))
    self.assertEqual(bindings.get('root'), bindings.get('copy'))
Esempio n. 3
0
 def test_bool(self):
    bindings = YamlBindings()
    bindings.import_string(
       "root:\n - elem: true\n - elem: True\n - elem: false\n - elem: False\ncopy: ${root}")
    self.assertEqual([{'elem': True}, {'elem': True}, {'elem': False}, {'elem': False}],
                     bindings.get('root'))
    self.assertEqual(bindings.get('root'), bindings.get('copy'))
Esempio n. 4
0
 def test_load_transitive_indirect(self):
     bindings = YamlBindings()
     bindings.import_dict({'field': '${injected.value}', 'found': 'FOUND'})
     bindings.import_dict({'injected': {'value': '${found}'}})
     self.assertEqual('FOUND', bindings.get('field'))
     self.assertEqual('FOUND', bindings['field'])
     self.assertEqual('FOUND', bindings.get('field', None))
Esempio n. 5
0
 def test_load_transitive_indirect(self):
   bindings = YamlBindings()
   bindings.import_dict({'field': '${injected.value}', 'found': 'FOUND'})
   bindings.import_dict({'injected': {'value': '${found}'}})
   self.assertEqual('FOUND', bindings.get('field'))
   self.assertEqual('FOUND', bindings['field'])
   self.assertEqual('FOUND', bindings.get('field', None))
Esempio n. 6
0
 def test_list(self):
    bindings = YamlBindings()
    bindings.import_string(
       "root:\n - elem: 'first'\n - elem: 2\n - elem: true\ncopy: ${root}")
    self.assertEqual([{'elem': 'first'}, {'elem': 2}, {'elem': True}],
                     bindings.get('root'))
    self.assertEqual(bindings.get('root'), bindings.get('copy'))
Esempio n. 7
0
 def test_number(self):
     bindings = YamlBindings()
     bindings.import_string(
         "scalar: 123\nneg: -321\ndef: ${unkown:234}\nindirect: ${scalar}")
     self.assertEqual(123, bindings.get('scalar'))
     self.assertEqual(-321, bindings.get('neg'))
     self.assertEqual(234, bindings.get('def'))
     self.assertEqual(123, bindings.get('indirect'))
Esempio n. 8
0
 def test_boolean(self):
    bindings = YamlBindings()
    bindings.import_string(
       "t: true\nf: false\ndef: ${unkown:true}\nindirect: ${f}")
    self.assertEqual(True, bindings.get('t'))
    self.assertEqual(False, bindings.get('f'))
    self.assertEqual(True, bindings.get('def'))
    self.assertEqual(False, bindings.get('indirect'))
Esempio n. 9
0
 def test_boolean(self):
     bindings = YamlBindings()
     bindings.import_string(
         "t: true\nf: false\ndef: ${unkown:true}\nindirect: ${f}")
     self.assertEqual(True, bindings.get('t'))
     self.assertEqual(False, bindings.get('f'))
     self.assertEqual(True, bindings.get('def'))
     self.assertEqual(False, bindings.get('indirect'))
Esempio n. 10
0
 def test_number(self):
    bindings = YamlBindings()
    bindings.import_string(
       "scalar: 123\nneg: -321\ndef: ${unkown:234}\nindirect: ${scalar}")
    self.assertEqual(123, bindings.get('scalar'))
    self.assertEqual(-321, bindings.get('neg'))
    self.assertEqual(234, bindings.get('def'))
    self.assertEqual(123, bindings.get('indirect'))
Esempio n. 11
0
 def test_cyclic_reference(self):
     bindings = YamlBindings()
     bindings.import_dict({
         'field': '${injected.value}',
         'injected': {
             'value': '${field}'
         }
     })
     with self.assertRaises(ValueError):
         bindings.get('field')
Esempio n. 12
0
 def test_load_default_bool(self):
     bindings = YamlBindings()
     bindings.import_dict({'field': '${undefined:True}'})
     self.assertEqual(True, bindings.get('field'))
     bindings.import_dict({'field': '${undefined:true}'})
     self.assertEqual(True, bindings.get('field'))
     bindings.import_dict({'field': '${undefined:false}'})
     self.assertEqual(False, bindings.get('field'))
     bindings.import_dict({'field': '${undefined:False}'})
     self.assertEqual(False, bindings.get('field'))
Esempio n. 13
0
 def test_load_default_bool(self):
   bindings = YamlBindings()
   bindings.import_dict({'field': '${undefined:True}'})
   self.assertEqual(True, bindings.get('field'))
   bindings.import_dict({'field': '${undefined:true}'})
   self.assertEqual(True, bindings.get('field'))
   bindings.import_dict({'field': '${undefined:false}'})
   self.assertEqual(False, bindings.get('field'))
   bindings.import_dict({'field': '${undefined:False}'})
   self.assertEqual(False, bindings.get('field'))
Esempio n. 14
0
  def test_load_key_not_found(self):
    bindings = YamlBindings()
    bindings.import_dict({'field': '${injected.value}', 'injected': {}})

    with self.assertRaises(KeyError):
      bindings['unknown']
    self.assertEqual(None, bindings.get('unknown', None))
Esempio n. 15
0
def maybe_copy_master_yml(options):
    """Copy the specified master spinnaker-local.yml, and credentials.

    This will look for paths to credentials within the spinnaker-local.yml, and
    copy those as well. The paths to the credentials (and the reference
    in the config file) will be changed to reflect the filesystem on the
    new instance, which may be different than on this instance.

    Args:
      options [Namespace]: The parser namespace options contain information
        about the instance we're going to copy to, as well as the source
        of the master spinnaker-local.yml file.
    """
    if not options.master_yml:
        maybe_inform('custom spinnaker-local.yml',
                     '.spinnaker/spinnaker-local.yml', '--copy_master_yml')
        return

    bindings = YamlBindings()
    bindings.import_path(options.master_yml)

    try:
        json_credential_path = bindings.get(
            'providers.google.primaryCredentials.jsonPath')
    except KeyError:
        json_credential_path = None

    gcp_home = os.path.join('/home', os.environ['LOGNAME'], '.spinnaker')

    # If there are credentials, write them to this path
    gcp_credential_path = os.path.join(gcp_home, 'google-credentials.json')

    with open(options.master_yml, 'r') as f:
        content = f.read()

    # Replace all the occurrences of the original credentials path with the
    # path that we are going to place the file in on the new instance.
    if json_credential_path:
        if not os.path.exists(json_credential_path):
            raise ValueError('{0} specifies google credentials in {1},'
                             ' which does not exist.'.format(
                                 options.master_yml, json_credential_path))

        content = content.replace(json_credential_path, gcp_credential_path)

    fd, temp_path = tempfile.mkstemp()
    os.fchmod(fd, os.stat(options.master_yml).st_mode)  # Copy original mode
    os.write(fd, content)
    os.close(fd)
    actual_path = temp_path

    # Copy the credentials here. The cfg file will be copied after.
    copy_custom_file(options, actual_path, '.spinnaker/spinnaker-local.yml')

    if json_credential_path:
        copy_custom_file(options, json_credential_path,
                         '.spinnaker/google-credentials.json')

    if temp_path:
        os.remove(temp_path)
Esempio n. 16
0
    def test_load_key_not_found(self):
        bindings = YamlBindings()
        bindings.import_dict({'field': '${injected.value}', 'injected': {}})

        with self.assertRaises(KeyError):
            bindings['unknown']
        self.assertEqual(None, bindings.get('unknown', None))
Esempio n. 17
0
def maybe_copy_master_yml(options):
    """Copy the specified master spinnaker-local.yml, and credentials.

    This will look for paths to credentials within the spinnaker-local.yml, and
    copy those as well. The paths to the credentials (and the reference
    in the config file) will be changed to reflect the filesystem on the
    new instance, which may be different than on this instance.

    Args:
      options [Namespace]: The parser namespace options contain information
        about the instance we're going to copy to, as well as the source
        of the master spinnaker-local.yml file.
    """
    if not options.master_yml:
        maybe_inform("custom spinnaker-local.yml", ".spinnaker/spinnaker-local.yml", "--copy_master_yml")
        return

    bindings = YamlBindings()
    bindings.import_path(options.master_yml)

    try:
        json_credential_path = bindings.get("providers.google.primaryCredentials.jsonPath")
    except KeyError:
        json_credential_path = None

    gcp_home = os.path.join("/home", os.environ["LOGNAME"], ".spinnaker")

    # If there are credentials, write them to this path
    gcp_credential_path = os.path.join(gcp_home, "google-credentials.json")

    with open(options.master_yml, "r") as f:
        content = f.read()

    # Replace all the occurances of the original credentials path with the
    # path that we are going to place the file in on the new instance.
    if json_credential_path:
        if not os.path.exists(json_credential_path):
            raise ValueError(
                "{0} specifies google credentials in {1},"
                " which does not exist.".format(options.master_yml, json_credential_path)
            )

        content = content.replace(json_credential_path, gcp_credential_path)

    fd, temp_path = tempfile.mkstemp()
    os.fchmod(fd, os.stat(options.master_yml).st_mode)  # Copy original mode
    os.write(fd, content)
    os.close(fd)
    actual_path = temp_path

    # Copy the credentials here. The cfg file will be copied after.
    copy_custom_file(options, actual_path, ".spinnaker/spinnaker-local.yml")

    if json_credential_path:
        copy_custom_file(options, json_credential_path, ".spinnaker/google-credentials.json")

    if temp_path:
        os.remove(temp_path)
Esempio n. 18
0
def copy_master_yml(options):
    """Copy the specified master spinnaker-local.yml, and credentials.

    This will look for paths to credentials within the spinnaker-local.yml, and
    copy those as well. The paths to the credentials (and the reference
    in the config file) will be changed to reflect the filesystem on the
    new instance, which may be different than on this instance.

    Args:
      options [Namespace]: The parser namespace options contain information
        about the instance we're going to copy to, as well as the source
        of the master spinnaker-local.yml file.
    """
    print 'Creating .spinnaker directory...'
    check_run_quick('gcloud compute ssh --command "mkdir -p .spinnaker"'
                    ' --project={project} --zone={zone} {instance}'
                    .format(project=get_project(options),
                            zone=options.zone,
                            instance=options.instance),
                    echo=False)

    bindings = YamlBindings()
    bindings.import_path(options.master_yml)

    try:
      json_credential_path = bindings.get(
          'providers.google.primaryCredentials.jsonPath')
    except KeyError:
      json_credential_path = None

    gcp_home = os.path.join('/home', os.environ['LOGNAME'], '.spinnaker')

    # If there are credentials, write them to this path
    gcp_credential_path = os.path.join(gcp_home, 'google-credentials.json')

    with open(options.master_yml, 'r') as f:
        content = f.read()

    # Replace all the occurances of the original credentials path with the
    # path that we are going to place the file in on the new instance.
    if json_credential_path:
        content = content.replace(json_credential_path, gcp_credential_path)

    fd, temp_path = tempfile.mkstemp()
    os.write(fd, content)
    os.close(fd)
    actual_path = temp_path

    # Copy the credentials here. The cfg file will be copied after.
    copy_file(options, actual_path, '.spinnaker/spinnaker-local.yml')

    if json_credential_path:
        copy_file(options, json_credential_path,
                  '.spinnaker/google-credentials.json')

    if temp_path:
      os.remove(temp_path)
Esempio n. 19
0
def maybe_copy_master_yml(options):
    """Copy the specified master spinnaker-local.yml, and credentials.

    This will look for paths to credentials within the spinnaker-local.yml, and
    copy those as well. The paths to the credentials (and the reference
    in the config file) will be changed to reflect the filesystem on the
    new instance, which may be different than on this instance.

    Args:
      options [Namespace]: The parser namespace options contain information
        about the instance we're going to copy to, as well as the source
        of the master spinnaker-local.yml file.
    """
    if not options.master_yml:
        maybe_inform('custom spinnaker-local.yml',
                     '.spinnaker/spinnaker-local.yml', '--copy_master_yml')
        return

    bindings = YamlBindings()
    bindings.import_path(options.master_yml)

    try:
      json_credential_path = bindings.get(
          'providers.google.primaryCredentials.jsonPath')
    except KeyError:
      json_credential_path = None

    gcp_home = os.path.join('/home', os.environ['LOGNAME'], '.spinnaker')

    # If there are credentials, write them to this path
    gcp_credential_path = os.path.join(gcp_home, 'google-credentials.json')

    with open(options.master_yml, 'r') as f:
        content = f.read()

    # Replace all the occurances of the original credentials path with the
    # path that we are going to place the file in on the new instance.
    if json_credential_path:
        content = content.replace(json_credential_path, gcp_credential_path)

    fd, temp_path = tempfile.mkstemp()
    os.write(fd, content)
    os.close(fd)
    actual_path = temp_path

    # Copy the credentials here. The cfg file will be copied after.
    copy_custom_file(options, actual_path, '.spinnaker/spinnaker-local.yml')

    if json_credential_path:
        copy_custom_file(options, json_credential_path,
                         '.spinnaker/google-credentials.json')

    if temp_path:
      os.remove(temp_path)
Esempio n. 20
0
 def test_environ_bool(self):
     os.environ['TEST_BOOL'] = 'TRUE'
     bindings = YamlBindings()
     bindings.import_dict({'field': '${TEST_BOOL}'})
     self.assertEqual(True, bindings.get('field'))
Esempio n. 21
0
 def test_environ_int(self):
     os.environ['TEST_INT'] = '123'
     bindings = YamlBindings()
     bindings.import_dict({'field': '${TEST_INT}'})
     self.assertEqual(123, bindings.get('field'))
Esempio n. 22
0
 def test_environ(self):
   os.environ['TEST_VARIABLE'] = 'TEST_VALUE'
   bindings = YamlBindings()
   bindings.import_dict({'field': '${TEST_VARIABLE}'})
   self.assertEqual('TEST_VALUE', bindings.get('field'))
Esempio n. 23
0
 def test_environ(self):
     os.environ['TEST_VARIABLE'] = 'TEST_VALUE'
     bindings = YamlBindings()
     bindings.import_dict({'field': '${TEST_VARIABLE}'})
     self.assertEqual('TEST_VALUE', bindings.get('field'))
Esempio n. 24
0
 def test_load_default(self):
     bindings = YamlBindings()
     bindings.import_dict({'field': '${injected.value:HELLO}'})
     self.assertEqual('HELLO', bindings.get('field'))
Esempio n. 25
0
 def test_load_default_int(self):
     bindings = YamlBindings()
     bindings.import_dict({'field': '${undefined:123}'})
     self.assertEqual(123, bindings.get('field'))
Esempio n. 26
0
 def test_load_composite_value(self):
     bindings = YamlBindings()
     bindings.import_dict({'a': 'A', 'b': 'B'})
     bindings.import_string('test: ${a}/${b}')
     print str(bindings.map)
     self.assertEqual('A/B', bindings.get('test'))
Esempio n. 27
0
 def test_load_tail_not_found(self):
     bindings = YamlBindings()
     bindings.import_dict({'field': '${injected.value}', 'injected': {}})
     self.assertEqual('${injected.value}', bindings.get('field'))
Esempio n. 28
0
 def test_load_default_int(self):
   bindings = YamlBindings()
   bindings.import_dict({'field': '${undefined:123}'})
   self.assertEqual(123, bindings.get('field'))
Esempio n. 29
0
 def test_load_composite_value(self):
   bindings = YamlBindings()
   bindings.import_dict({'a': 'A', 'b':'B'})
   bindings.import_string('test: ${a}/${b}')
   print str(bindings.map)
   self.assertEqual('A/B', bindings.get('test'))
Esempio n. 30
0
 def test_environ_bool(self):
   os.environ['TEST_BOOL'] = 'TRUE'
   bindings = YamlBindings()
   bindings.import_dict({'field': '${TEST_BOOL}'})
   self.assertEqual(True, bindings.get('field'))
Esempio n. 31
0
 def test_load_transitive(self):
     bindings = YamlBindings()
     bindings.import_dict({'field': '${injected.value}'})
     bindings.import_dict({'injected': {'value': 'HELLO'}})
     self.assertEqual('HELLO', bindings.get('field'))
Esempio n. 32
0
 def test_load_tail_not_found(self):
   bindings = YamlBindings()
   bindings.import_dict({'field': '${injected.value}', 'injected': {}})
   self.assertEqual('${injected.value}', bindings.get('field'))
Esempio n. 33
0
 def test_environ_int(self):
   os.environ['TEST_INT'] = '123'
   bindings = YamlBindings()
   bindings.import_dict({'field': '${TEST_INT}'})
   self.assertEqual(123, bindings.get('field'))
Esempio n. 34
0
 def test_load_transitive(self):
   bindings = YamlBindings()
   bindings.import_dict({'field': '${injected.value}'})
   bindings.import_dict({'injected': {'value': 'HELLO'}})
   self.assertEqual('HELLO', bindings.get('field'))
Esempio n. 35
0
 def test_concat_default(self):
    bindings = YamlBindings()
    bindings.import_string(
       "mix: a.${s:TEST}")
    self.assertEqual('a.TEST', bindings.get('mix'))
Esempio n. 36
0
 def test_concat(self):
     bindings = YamlBindings()
     bindings.import_string("s: 'TEST'\nmix: a.${s}")
     self.assertEqual('a.TEST', bindings.get('mix'))
Esempio n. 37
0
 def test_concat_default(self):
     bindings = YamlBindings()
     bindings.import_string("mix: a.${s:TEST}")
     self.assertEqual('a.TEST', bindings.get('mix'))
Esempio n. 38
0
 def test_load_default(self):
   bindings = YamlBindings()
   bindings.import_dict({'field': '${injected.value:HELLO}'})
   self.assertEqual('HELLO', bindings.get('field'))
Esempio n. 39
0
 def test_cyclic_reference(self):
   bindings = YamlBindings()
   bindings.import_dict({'field': '${injected.value}',
                         'injected': {'value': '${field}'}})
   with self.assertRaises(ValueError):
     bindings.get('field')
Esempio n. 40
0
 def test_concat(self):
    bindings = YamlBindings()
    bindings.import_string(
       "s: 'TEST'\nmix: a.${s}")
    self.assertEqual('a.TEST', bindings.get('mix'))