def test_validate_version_good(self):
        spec_schema = {
            'type':
            schema.String('Type name', required=True),
            'version':
            schema.String('Version number', required=True),
            'key1':
            schema.String('first key', default='value1'),
            'key2':
            schema.Integer('second key',
                           required=True,
                           min_version='1.0',
                           max_version='1.2'),
        }

        data = {
            'key1': 'value1',
            'key2': 2,
            'type': 'test-type',
            'version': '1.0'
        }
        spec = schema.Spec(spec_schema, data)
        self.assertIsNone(spec.validate())

        data = {'key2': 2, 'type': 'test-type', 'version': '1.2'}
        spec = schema.Spec(spec_schema, data)
        self.assertIsNone(spec.validate())
Beispiel #2
0
    def __init__(self, name, spec, **kwargs):
        """Initialize a profile instance.

        :param name: A string that specifies the name for the profile.
        :param spec: A dictionary containing the detailed policy spec.
        :param kwargs: Keyword arguments for initializing the policy.
        :returns: An instance of a specific sub-class of Policy.
        """

        type_name, version = schema.get_spec_version(spec)

        self.name = name
        self.spec = spec

        self.id = kwargs.get('id', None)
        self.type = kwargs.get('type', '%s-%s' % (type_name, version))

        self.permission = kwargs.get('permission', '')
        self.metadata = kwargs.get('metadata', {})

        self.created_time = kwargs.get('created_time', None)
        self.updated_time = kwargs.get('updated_time', None)
        self.deleted_time = kwargs.get('deleted_time', None)

        self.spec_data = schema.Spec(self.spec_schema, self.spec)
        self.properties = schema.Spec(self.properties_schema,
                                      self.spec.get(self.PROPERTIES, {}))

        if not self.id:
            # new object needs a context dict
            self.context = self._init_context()
        else:
            self.context = kwargs.get('context')
Beispiel #3
0
    def __init__(self, name, spec, **kwargs):
        """Initialize a policy instance.

        :param name: The name for the policy.
        :param spec: A dictionary containing the detailed policy spec.
        :param kwargs: Keyword arguments for initializing the policy.
        :returns: An instance of a specific sub-class of Policy.
        """

        type_name, version = schema.get_spec_version(spec)
        type_str = "-".join([type_name, version])
        self.name = name
        self.spec = spec

        self.id = kwargs.get('id', None)
        self.type = kwargs.get('type', type_str)
        self.user = kwargs.get('user')
        self.project = kwargs.get('project')
        self.domain = kwargs.get('domain')
        self.data = kwargs.get('data', {})

        self.created_at = kwargs.get('created_at', None)
        self.updated_at = kwargs.get('updated_at', None)

        self.spec_data = schema.Spec(self.spec_schema, spec)
        self.properties = schema.Spec(self.properties_schema,
                                      self.spec.get(self.PROPERTIES, {}),
                                      version)

        self.singleton = True
        self._novaclient = None
        self._keystoneclient = None
        self._networkclient = None
        self._octaviaclient = None
        self._lbaasclient = None
Beispiel #4
0
    def __init__(self, name, spec, **kwargs):
        """Initialize a policy instance.

        :param name: The name for the policy.
        :param spec: A dictionary containing the detailed policy spec.
        :param kwargs: Keyword arguments for initializing the policy.
        :returns: An instance of a specific sub-class of Policy.
        """

        type_name, version = schema.get_spec_version(spec)

        self.name = name
        self.spec = spec

        self.id = kwargs.get('id', None)
        self.type = kwargs.get('type', "%s-%s" % (type_name, version))
        self.user = kwargs.get('user')
        self.project = kwargs.get('project')
        self.domain = kwargs.get('domain')
        self.level = kwargs.get('level', SHOULD)
        self.cooldown = kwargs.get('cooldown', 0)
        self.data = kwargs.get('data', {})

        self.created_time = kwargs.get('created_time', None)
        self.updated_time = kwargs.get('updated_time', None)
        self.deleted_time = kwargs.get('deleted_time', None)

        self.spec_data = schema.Spec(self.spec_schema, spec)
        self.properties = schema.Spec(self.properties_schema,
                                      self.spec.get(self.PROPERTIES, {}))
        self.singleton = True
    def test_validate(self):
        data = {'key1': 'value1', 'key2': 2}
        sot = schema.Spec(self.spec_schema, data)
        res = sot.validate()
        self.assertIsNone(res)

        data1 = {'key2': 2}
        sot = schema.Spec(self.spec_schema, data1)
        res = sot.validate()
        self.assertIsNone(res)
Beispiel #6
0
    def test_spec_validate_good(self):
        spec_schema = {
            'key1': schema.String('first key', default='value1'),
            'key2': schema.Integer('second key', required=True),
        }

        data = {'key1': 'value1', 'key2': 2}
        spec = schema.Spec(spec_schema, data)
        self.assertEqual(None, spec.validate())

        data = {'key2': 2}
        spec = schema.Spec(spec_schema, data)
        self.assertEqual(None, spec.validate())
Beispiel #7
0
    def __init__(self, name, spec, **kwargs):
        """Initialize a profile instance.

        :param name: A string that specifies the name for the profile.
        :param spec: A dictionary containing the detailed profile spec.
        :param kwargs: Keyword arguments for initializing the profile.
        :returns: An instance of a specific sub-class of Profile.
        """

        type_name, version = schema.get_spec_version(spec)
        self.type_name = type_name
        self.version = version
        type_str = "-".join([type_name, version])

        self.name = name
        self.spec = spec

        self.id = kwargs.get('id', None)
        self.type = kwargs.get('type', type_str)

        self.user = kwargs.get('user')
        self.project = kwargs.get('project')
        self.domain = kwargs.get('domain')

        self.metadata = kwargs.get('metadata', {})

        self.created_at = kwargs.get('created_at', None)
        self.updated_at = kwargs.get('updated_at', None)

        self.spec_data = schema.Spec(self.spec_schema, self.spec)
        self.properties = schema.Spec(
            self.properties_schema,
            self.spec.get(self.PROPERTIES, {}),
            version)

        if not self.id:
            # new object needs a context dict
            self.context = self._init_context()
        else:
            self.context = kwargs.get('context')

        # initialize clients
        self._computeclient = None
        self._networkclient = None
        self._orchestrationclient = None
        self._workflowclient = None
        self._block_storageclient = None
        self._glanceclient = None
Beispiel #8
0
    def __init__(self, name, spec, **kwargs):
        """Initialize a trigger instance.

        :param name: The name for the trigger.
        :param spec: A dictionary containing the detailed trigger spec.
        :param kwargs: Keyword arguments for initializing the trigger.
        :returns: An instance of a specific sub-class of BaseTrigger.
        """
        type_name, version = schema.get_spec_version(spec)

        self.type_name = type_name
        self.name = name
        self.id = kwargs.get('id', None)
        self.physical_id = kwargs.get('physical_id', None)
        self.desc = kwargs.get('desc', '')
        self.state = kwargs.get('state', INSUFFICIENT_DATA)
        self.enabled = kwargs.get('enabled', True)
        self.severity = kwargs.get('severity', S_LOW)
        self.links = kwargs.get('links', {})

        self.user = kwargs.get('user')
        self.project = kwargs.get('project')
        self.domain = kwargs.get('domain')
        self.created_time = kwargs.get('created_time', None)
        self.updated_time = kwargs.get('updated_time', None)
        self.deleted_time = kwargs.get('deleted_time', None)

        self.spec = spec
        self.spec_data = schema.Spec(self.spec_schema, spec)
    def test___contains__(self):
        data = {'key2': 2}
        sot = schema.Spec(self.spec_schema, data, version='1.2')

        self.assertIn('key1', sot)
        self.assertIn('key2', sot)
        self.assertNotIn('key3', sot)
Beispiel #10
0
    def test_init_with_version(self):
        data = {'key1': 'value1', 'key2': 2}
        sot = schema.Spec(self.spec_schema, data, version='1.2')

        self.assertEqual(self.spec_schema, sot._schema)
        self.assertEqual(data, sot._data)
        self.assertEqual('1.2', sot._version)
Beispiel #11
0
    def test_init(self):
        data = {'key1': 'value1', 'key2': 2}
        sot = schema.Spec(self.spec_schema, data)

        self.assertEqual(self.spec_schema, sot._schema)
        self.assertEqual(data, sot._data)
        self.assertIsNone(sot._version)
Beispiel #12
0
    def test_resolve_value_required_key_missing(self):
        data = {'key1': 'value1'}
        sot = schema.Spec(self.spec_schema, data, version='1.0')

        ex = self.assertRaises(exc.ESchema, sot.resolve_value, 'key2')
        self.assertIn("Required spec item 'key2' not provided",
                      six.text_type(ex.message))
Beispiel #13
0
    def test__iter__(self):
        data = {'key2': 2}
        sot = schema.Spec(self.spec_schema, data, version='1.2')

        res = [k for k in iter(sot)]

        self.assertIn('key1', res)
        self.assertIn('key2', res)
Beispiel #14
0
    def test___getitem__(self):
        data = {'key2': 2}
        sot = schema.Spec(self.spec_schema, data, version='1.2')

        res = sot['key1']
        self.assertEqual('value1', res)
        res = sot['key2']
        self.assertEqual(2, res)
Beispiel #15
0
    def test_validate_fail_unrecognizable_key(self):
        spec_schema = {
            'key1': schema.String('first key', default='value1'),
        }
        data = {'key1': 'value1', 'key2': 2}
        sot = schema.Spec(spec_schema, data, version='1.0')
        ex = self.assertRaises(exc.ESchema, sot.validate)

        self.assertIn("Unrecognizable spec item 'key2'",
                      six.text_type(ex.message))
Beispiel #16
0
    def test_policy_validate_fail_unrecognizable_key(self):
        spec_schema = {
            'key1': schema.String('first key', default='value1'),
        }

        data = {'key1': 'value1', 'key2': 2}
        spec = schema.Spec(spec_schema, data)
        ex = self.assertRaises(exception.SpecValidationFailed, spec.validate)
        msg = _('Unrecognizable spec item "%s"') % 'key2'
        self.assertTrue(six.text_type(ex.message).find(msg) != -1)
Beispiel #17
0
    def test_validate_fail_value_type_incorrect(self):
        spec_schema = {
            'key1': schema.String('first key', default='value1'),
            'key2': schema.Integer('second key', required=True),
        }

        data = {'key1': 'value1', 'key2': 'abc'}
        spec = schema.Spec(spec_schema, data, version='1.0')
        ex = self.assertRaises(exc.ESchema, spec.validate)
        self.assertIn("The value 'abc' is not a valid Integer",
                      six.text_type(ex.message))
Beispiel #18
0
    def test_policy_validate_fail_required_key_missing(self):
        spec_schema = {
            'key1': schema.String('first key', default='value1'),
            'key2': schema.Integer('second key', required=True),
        }

        data = {'key1': 'value1'}
        spec = schema.Spec(spec_schema, data)
        ex = self.assertRaises(exception.SpecValidationFailed, spec.validate)
        msg = _('Required spec item "%s" not assigned') % 'key2'
        self.assertTrue(six.text_type(ex.message).find(msg) != -1)
Beispiel #19
0
    def test_resolve_value(self):
        data = {'key2': 2}
        sot = schema.Spec(self.spec_schema, data, version='1.2')

        res = sot.resolve_value('key2')
        self.assertEqual(2, res)

        res = sot.resolve_value('key1')
        self.assertEqual('value1', res)

        ex = self.assertRaises(exc.ESchema, sot.resolve_value, 'key3')
        self.assertEqual("Invalid spec item: key3", six.text_type(ex))
Beispiel #20
0
    def test_spec_validate_fail_value_type_incorrect(self):
        spec_schema = {
            'key1': schema.String('first key', default='value1'),
            'key2': schema.Integer('second key', required=True),
        }

        data = {'key1': 'value1', 'key2': 'abc'}
        spec = schema.Spec(spec_schema, data)
        ex = self.assertRaises(exception.SpecValidationFailed, spec.validate)
        msg = _('The value "%s" cannot be converted into an '
                'integer.') % data['key2']
        self.assertTrue(six.text_type(ex.message).find(msg) != -1)
Beispiel #21
0
    def test_validate_version_fail_version_over_max(self):
        spec_schema = {
            'type': schema.String('Type name', required=True),
            'version': schema.String('Version number', required=True),
            'key1': schema.String('first key', default='value1',
                                  max_version='2.0'),
            'key2': schema.Integer('second key', required=True),
        }

        data = {
            'key1': 'value1',
            'key2': 2,
            'type': 'test-type',
            'version': '3.0'
        }
        spec = schema.Spec(spec_schema, data, version='3.0')
        ex = self.assertRaises(exc.ESchema, spec.validate)
        msg = 'key1 (max_version=2.0) is not supported by spec version 3.0.'
        self.assertIn(msg, str(ex.message))
Beispiel #22
0
    def test_validate_version_fail_unsupported_version(self):
        spec_schema = {
            'type': schema.String('Type name', required=True),
            'version': schema.String('Version number', required=True),
            'key1': schema.String('first key',
                                  default='value1',
                                  min_version='1.1'),
            'key2': schema.Integer('second key', required=True),
        }

        data = {
            'key1': 'value1',
            'key2': 2,
            'type': 'test-type',
            'version': '1.0'
        }
        spec = schema.Spec(spec_schema, data, version='1.0')
        ex = self.assertRaises(exc.ESchema, spec.validate)
        msg = 'key1 (min_version=1.1) is not supported by spec version 1.0.'
        self.assertIn(msg, six.text_type(ex.message))
Beispiel #23
0
 def __init__(self, name, spec, **kwargs):
     super(AggregateByResourcesAlarm, self).__init__(name, spec, **kwargs)
     rule_spec = spec.get('rule', {})
     self.rule = schema.Spec(self.rule_schema, rule_spec)
     self.namespace = 'gnocchi_aggregation_by_resources_threshold'
Beispiel #24
0
 def __init__(self, name, spec, **kwargs):
     super(ThresholdAlarm, self).__init__(name, spec, **kwargs)
     rule_spec = spec.get('rule', {})
     self.rule = schema.Spec(self.rule_schema, rule_spec)
     self.namespace = 'threshold'
Beispiel #25
0
 def __init__(self, name, spec, **kwargs):
     super(FakeTriggerImpl, self).__init__(name, spec, **kwargs)
     self.rule = schema.Spec(self.rule_schema, spec['rule'])
Beispiel #26
0
 def __init__(self, name, spec, **kwargs):
     super(TestTrigger, self).__init__(name, spec, **kwargs)
     rule_spec = spec.get('rule', {})
     self.rule = schema.Spec(self.rule_schema, rule_spec)
     self.namespace = 'test'
Beispiel #27
0
    def __init__(self, name, spec, **kwargs):
        super(Alarm, self).__init__(name, spec, **kwargs)

        self.alarm_properties = schema.Spec(self.alarm_schema, spec)
        self.namespace = 'default'
        self.rule = None
Beispiel #28
0
    def test___len__(self):
        data = {'key2': 2}
        sot = schema.Spec(self.spec_schema, data, version='1.2')

        res = len(sot)
        self.assertEqual(2, res)
Beispiel #29
0
    def __init__(self, name, spec, **kwargs):
        super(CombinationAlarm, self).__init__(name, spec, **kwargs)

        rule_spec = spec.get('rule', {})
        self.rule = schema.Spec(self.rule_schema, rule_spec)
        self.namespace = 'combination'