Ejemplo n.º 1
0
    def test_input_types(self):
        swc_io.InputConfig(name='str', type='String').as_dict()
        swc_io.InputConfig(name='num', type='Number').as_dict()
        swc_io.InputConfig(name='list', type='CommaDelimitedList').as_dict()
        swc_io.InputConfig(name='json', type='Json').as_dict()
        swc_io.InputConfig(name='bool', type='Boolean').as_dict()

        self.assertRaises(ValueError, swc_io.InputConfig,
                          name='bogus', type='BogusType')
Ejemplo n.º 2
0
 def setUp(self):
     super(StructuredDeploymentWithStrictInputTest, self).setUp()
     self.source = {
         'config': {
             'foo': [{
                 "get_input": "bar"
             }, {
                 "get_input": "barz"
             }]
         }
     }
     self.inputs = [
         swc_io.InputConfig(name='bar', value='baz'),
         swc_io.InputConfig(name='barz', value='baz2')
     ]
Ejemplo n.º 3
0
 def test_input_config_value_json_default(self):
     name = 'baz'
     inp = swc_io.InputConfig(name=name,
                              type='Json',
                              default={'a': 1},
                              value=42)
     self.assertEqual({'a': 1}, inp.default())
Ejemplo n.º 4
0
    def test_input_config_value_ignore_string(self):
        name = 'baz'
        inp = swc_io.InputConfig(name=name, type='Number',
                                 default='')

        self.assertEqual({'type': 'Number', 'name': 'baz', 'default': ''},
                         inp.as_dict())
 def test_input_config_empty(self):
     name = 'foo'
     inp = swc_io.InputConfig(name=name)
     self.assertIsNone(inp.default())
     self.assertIs(False, inp.replace_on_change())
     self.assertEqual(name, inp.name())
     self.assertEqual({'name': name, 'type': 'String'}, inp.as_dict())
     self.assertEqual((name, None), inp.input_data())
Ejemplo n.º 6
0
 def test_input_config_value(self):
     name = 'baz'
     inp = swc_io.InputConfig(name=name, type='Number',
                              default=0, value=42)
     self.assertEqual(0, inp.default())
     self.assertIs(False, inp.replace_on_change())
     self.assertEqual(name, inp.name())
     self.assertEqual({'name': name, 'type': 'Number',
                       'default': 0, 'value': 42},
                      inp.as_dict())
     self.assertEqual((name, 42), inp.input_data())
Ejemplo n.º 7
0
 def test_input_config(self):
     name = 'bar'
     inp = swc_io.InputConfig(name=name, description='test', type='Number',
                              default=0, replace_on_change=True)
     self.assertEqual(0, inp.default())
     self.assertIs(True, inp.replace_on_change())
     self.assertEqual(name, inp.name())
     self.assertEqual({'name': name, 'type': 'Number',
                       'description': 'test', 'default': 0,
                       'replace_on_change': True},
                      inp.as_dict())
     self.assertEqual((name, None), inp.input_data())
Ejemplo n.º 8
0
 def _show_software_deployment(self, cnxt, deployment_id):
     sd = software_deployment_object.SoftwareDeployment.get_by_id(
         cnxt, deployment_id)
     if sd.status == rpc_api.SOFTWARE_DEPLOYMENT_IN_PROGRESS:
         c = sd.config.config
         input_values = dict(swc_io.InputConfig(**i).input_data()
                             for i in c[rpc_api.SOFTWARE_CONFIG_INPUTS])
         transport = input_values.get('deploy_signal_transport')
         if transport == 'TEMP_URL_SIGNAL':
             sd = self._refresh_swift_software_deployment(
                 cnxt, sd, input_values.get('deploy_signal_id'))
         elif transport == 'ZAQAR_SIGNAL':
             sd = self._refresh_zaqar_software_deployment(
                 cnxt, sd, input_values.get('deploy_queue_id'))
     return sd
Ejemplo n.º 9
0
    def _load_config(self):
        if self.properties.get(self.CONFIG):
            config = self.rpc_client().show_software_config(
                self.context, self.properties.get(self.CONFIG))
        else:
            config = {}

        config[rpc_api.SOFTWARE_CONFIG_INPUTS] = [
            swc_io.InputConfig(**i)
            for i in config.get(rpc_api.SOFTWARE_CONFIG_INPUTS, [])
        ]
        config[rpc_api.SOFTWARE_CONFIG_OUTPUTS] = [
            swc_io.OutputConfig(**o)
            for o in config.get(rpc_api.SOFTWARE_CONFIG_OUTPUTS, [])
        ]

        return config
Ejemplo n.º 10
0
    def create_software_config(self, cnxt, group, name, config,
                               inputs, outputs, options):

        swc_io.check_io_schema_list(inputs)
        in_conf = [swc_io.InputConfig(**i).as_dict() for i in inputs]
        swc_io.check_io_schema_list(outputs)
        out_conf = [swc_io.OutputConfig(**o).as_dict() for o in outputs]

        sc = software_config_object.SoftwareConfig.create(cnxt, {
            'group': group,
            'name': name,
            'config': {
                rpc_api.SOFTWARE_CONFIG_INPUTS: in_conf,
                rpc_api.SOFTWARE_CONFIG_OUTPUTS: out_conf,
                rpc_api.SOFTWARE_CONFIG_OPTIONS: options,
                rpc_api.SOFTWARE_CONFIG_CONFIG: config
            },
            'tenant': cnxt.tenant_id})
        return api.format_software_config(sc)
Ejemplo n.º 11
0
        def derive_inputs():
            for input_config in inputs:
                value = input_values.pop(input_config.name(),
                                         input_config.default())
                yield swc_io.InputConfig(value=value, **input_config.as_dict())

            # for any input values that do not have a declared input, add
            # a derived declared input so that they can be used as config
            # inputs
            for inpk, inpv in input_values.items():
                yield swc_io.InputConfig(name=inpk, value=inpv)

            yield swc_io.InputConfig(
                name=self.DEPLOY_SERVER_ID, value=self.properties[self.SERVER],
                description=_('ID of the server being deployed to'))
            yield swc_io.InputConfig(
                name=self.DEPLOY_ACTION, value=action,
                description=_('Name of the current action being deployed'))
            yield swc_io.InputConfig(
                name=self.DEPLOY_STACK_ID,
                value=self.stack.identifier().stack_path(),
                description=_('ID of the stack this deployment belongs to'))
            yield swc_io.InputConfig(
                name=self.DEPLOY_RESOURCE_NAME, value=self.name,
                description=_('Name of this deployment resource in the stack'))
            yield swc_io.InputConfig(
                name=self.DEPLOY_SIGNAL_TRANSPORT,
                value=self.properties[self.SIGNAL_TRANSPORT],
                description=_('How the server should signal to heat with '
                              'the deployment output values.'))

            if self._signal_transport_cfn():
                yield swc_io.InputConfig(
                    name=self.DEPLOY_SIGNAL_ID,
                    value=self._get_ec2_signed_url(),
                    description=_('ID of signal to use for signaling output '
                                  'values'))
                yield swc_io.InputConfig(
                    name=self.DEPLOY_SIGNAL_VERB, value='POST',
                    description=_('HTTP verb to use for signaling output '
                                  'values'))

            elif self._signal_transport_temp_url():
                yield swc_io.InputConfig(
                    name=self.DEPLOY_SIGNAL_ID,
                    value=self._get_swift_signal_url(),
                    description=_('ID of signal to use for signaling output '
                                  'values'))
                yield swc_io.InputConfig(
                    name=self.DEPLOY_SIGNAL_VERB, value='PUT',
                    description=_('HTTP verb to use for signaling output '
                                  'values'))

            elif (self._signal_transport_heat() or
                  self._signal_transport_zaqar()):
                creds = self._get_heat_signal_credentials()
                yield swc_io.InputConfig(
                    name=self.DEPLOY_AUTH_URL, value=creds['auth_url'],
                    description=_('URL for API authentication'))
                yield swc_io.InputConfig(
                    name=self.DEPLOY_USERNAME, value=creds['username'],
                    description=_('Username for API authentication'))
                yield swc_io.InputConfig(
                    name=self.DEPLOY_USER_ID, value=creds['user_id'],
                    description=_('User ID for API authentication'))
                yield swc_io.InputConfig(
                    name=self.DEPLOY_PASSWORD, value=creds['password'],
                    description=_('Password for API authentication'))
                yield swc_io.InputConfig(
                    name=self.DEPLOY_PROJECT_ID, value=creds['project_id'],
                    description=_('ID of project for API authentication'))
                if creds['region_name']:
                    yield swc_io.InputConfig(
                        name=self.DEPLOY_REGION_NAME,
                        value=creds['region_name'],
                        description=_('Region name for API authentication'))
            if self._signal_transport_zaqar():
                yield swc_io.InputConfig(
                    name=self.DEPLOY_QUEUE_ID,
                    value=self._get_zaqar_signal_queue_id(),
                    description=_('ID of queue to use for signaling output '
                                  'values'))
Ejemplo n.º 12
0
 def test_input_config_value_default_coerce(self):
     name = 'baz'
     inp = swc_io.InputConfig(name=name, type='Number', default='0')
     self.assertEqual(0, inp.default())
Ejemplo n.º 13
0
 def test_build_derived_config(self):
     source = {'config': {"foo": {"get_input": "bar"}}}
     inputs = [swc_io.InputConfig(name='bar', value='baz')]
     result = self.deployment._build_derived_config('CREATE', source,
                                                    inputs, {})
     self.assertEqual({"foo": "baz"}, result)