def testNonString(self):
   decoder = option_decoders.StringDecoder(option=_OPTION)
   with self.assertRaises(errors.Config.InvalidValue) as cm:
     decoder.Decode(5, _COMPONENT, _FLAGS)
   self.assertEqual(str(cm.exception), (
       'Invalid test_component.test_option value: "5" (of type "int"). '
       'Value must be one of the following types: basestring.'))
示例#2
0
    def _GetOptionDecoderConstructions(cls):
        """Gets decoder classes and constructor args for each configurable option.

    Returns:
      dict. Maps option name string to a (ConfigOptionDecoder class, dict) pair.
      The pair specifies a decoder class and its __init__() keyword arguments
      to construct in order to decode the named option.
    """
        result = super(_ManagedRelationalDbSpec,
                       cls)._GetOptionDecoderConstructions()
        result.update({
            'cloud': (option_decoders.EnumDecoder, {
                'valid_values': providers.VALID_CLOUDS
            }),
            'engine': (option_decoders.EnumDecoder, {
                'valid_values': [
                    managed_relational_db.MYSQL,
                    managed_relational_db.POSTGRES,
                    managed_relational_db.AURORA_POSTGRES,
                ]
            }),
            'zones': (option_decoders.ListDecoder, {
                'item_decoder': option_decoders.StringDecoder(),
                'default': None
            }),
            'machine_type': (option_decoders.StringDecoder, {
                'default': None
            }),
            'engine_version': (option_decoders.StringDecoder, {
                'default': None
            }),
            'database_name': (option_decoders.StringDecoder, {
                'default': None
            }),
            'database_password': (option_decoders.StringDecoder, {
                'default': None
            }),
            'database_username': (option_decoders.StringDecoder, {
                'default': None
            }),
            'high_availability': (option_decoders.BooleanDecoder, {
                'default': False
            }),
            'backup_enabled': (option_decoders.BooleanDecoder, {
                'default': True
            }),
            'backup_start_time': (option_decoders.StringDecoder, {
                'default': '07:00'
            }),
            'vm_spec': (_PerCloudConfigDecoder, {}),
            'disk_spec': (_PerCloudConfigDecoder, {})
        })
        return result
    def _GetOptionDecoderConstructions(cls):
        """Gets decoder classes and constructor args for each configurable option.

    Returns:
      dict. Maps option name string to a (ConfigOptionDecoder class, dict) pair.
          The pair specifies a decoder class and its __init__() keyword
          arguments to construct in order to decode the named option.
    """
        result = super(GceVmSpec, cls)._GetOptionDecoderConstructions()
        result.update({
            'machine_type': (custom_virtual_machine_spec.MachineTypeDecoder, {
                'default': None
            }),
            'num_local_ssds': (option_decoders.IntDecoder, {
                'default': 0,
                'min': 0
            }),
            'preemptible': (option_decoders.BooleanDecoder, {
                'default': False
            }),
            'boot_disk_size': (option_decoders.IntDecoder, {
                'default': None
            }),
            'boot_disk_type': (option_decoders.StringDecoder, {
                'default': None
            }),
            'project': (option_decoders.StringDecoder, {
                'default': None
            }),
            'image_family': (option_decoders.StringDecoder, {
                'default': None
            }),
            'image_project': (option_decoders.StringDecoder, {
                'default': None
            }),
            'node_type': (option_decoders.StringDecoder, {
                'default': 'n1-node-96-624'
            }),
            'num_vms_per_host': (option_decoders.IntDecoder, {
                'default': None
            }),
            'min_cpu_platform': (option_decoders.StringDecoder, {
                'default': None
            }),
            'gce_tags': (option_decoders.ListDecoder, {
                'item_decoder': option_decoders.StringDecoder(),
                'default': None
            }),
        })
        return result
  def _GetOptionDecoderConstructions(cls):
    """Gets decoder classes and constructor args for each configurable option.

    Can be overridden by derived classes to add options or impose additional
    requirements on existing options.

    Returns:
      dict. Maps option name string to a (ConfigOptionDecoder class, dict) pair.
          The pair specifies a decoder class and its __init__() keyword
          arguments to construct in order to decode the named option.
    """
    result = super(BaseVmSpec, cls)._GetOptionDecoderConstructions()
    result.update({
        'disable_interrupt_moderation': (option_decoders.BooleanDecoder, {
            'default': False}),
        'disable_rss': (option_decoders.BooleanDecoder, {'default': False}),
        'image': (option_decoders.StringDecoder, {'none_ok': True,
                                                  'default': None}),
        'install_packages': (option_decoders.BooleanDecoder, {'default': True}),
        'machine_type': (option_decoders.StringDecoder, {'none_ok': True,
                                                         'default': None}),
        'gpu_type': (option_decoders.EnumDecoder, {
            'valid_values': VALID_GPU_TYPES,
            'default': None}),
        'gpu_count': (option_decoders.IntDecoder, {'min': 1, 'default': None}),
        'zone': (option_decoders.StringDecoder, {'none_ok': True,
                                                 'default': None}),
        'cidr': (option_decoders.StringDecoder, {'none_ok': True,
                                                 'default': None}),
        'use_dedicated_host': (option_decoders.BooleanDecoder,
                               {'default': False}),
        'num_vms_per_host': (option_decoders.IntDecoder,
                             {'default': None}),
        'background_network_mbits_per_sec': (option_decoders.IntDecoder, {
            'none_ok': True, 'default': None}),
        'background_network_ip_type': (option_decoders.EnumDecoder, {
            'default': vm_util.IpAddressSubset.EXTERNAL,
            'valid_values': [vm_util.IpAddressSubset.EXTERNAL,
                             vm_util.IpAddressSubset.INTERNAL]}),
        'background_cpu_threads': (option_decoders.IntDecoder, {
            'none_ok': True, 'default': None}),
        'vm_metadata': (option_decoders.ListDecoder, {
            'item_decoder': option_decoders.StringDecoder(),
            'default': []})})
    return result
 def testValidString(self):
     decoder = option_decoders.StringDecoder(option=_OPTION)
     self.assertEqual(decoder.Decode('red', _COMPONENT, _FLAGS), 'red')
 def testDefault(self):
     decoder = option_decoders.StringDecoder(default=None, option=_OPTION)
     self.assertFalse(decoder.required)
     self.assertIsNone(decoder.default)
 def __init__(self, **kwargs):
     super(_CommandDecoder,
           self).__init__(default=None,
                          none_ok=True,
                          item_decoder=option_decoders.StringDecoder(),
                          **kwargs)