Beispiel #1
0
 def test_get_schema(self):
     sot = senlin_fields.Capacity(minimum=2, maximum=200)
     self.assertEqual(
         {
             'type': ['integer', 'string'],
             'minimum': 2,
             'maximum': 200,
             'pattern': '^[0-9]*$',
         }, sot.get_schema())
Beispiel #2
0
    def test_coerce(self):
        sot = senlin_fields.Capacity(minimum=2, maximum=200)
        obj = mock.Mock()
        res = sot.coerce(obj, 'attr', 12)
        self.assertEqual(12, res)
        res = sot.coerce(obj, 'attr', 2)
        self.assertEqual(2, res)
        res = sot.coerce(obj, 'attr', 200)
        self.assertEqual(200, res)

        sot = senlin_fields.Capacity()

        res = sot.coerce(obj, 'attr', 12)
        self.assertEqual(12, res)
        res = sot.coerce(obj, 'attr', 0)
        self.assertEqual(0, res)
        res = sot.coerce(obj, 'attr', CONF.max_nodes_per_cluster)
        self.assertEqual(CONF.max_nodes_per_cluster, res)
Beispiel #3
0
 def test_get_schema_default(self):
     cfg.CONF.set_override('max_nodes_per_cluster', 100, enforce_type=True)
     sot = senlin_fields.Capacity()
     self.assertEqual(
         {
             'type': ['integer', 'string'],
             'minimum': 0,
             'maximum': 100,
             'pattern': '^[0-9]*$',
         }, sot.get_schema())
Beispiel #4
0
    def test_coerce_failed(self):
        sot = senlin_fields.Capacity(minimum=2, maximum=200)
        obj = mock.Mock()

        ex = self.assertRaises(ValueError, sot.coerce, obj, 'attr', 1)
        self.assertEqual(
            "The value for the attr field must be greater than "
            "or equal to 2.", six.text_type(ex))

        ex = self.assertRaises(ValueError, sot.coerce, obj, 'attr', 201)
        self.assertEqual(
            "The value for the attr field must be less than "
            "or equal to 200.", six.text_type(ex))

        ex = self.assertRaises(ValueError, sot.coerce, obj, 'attr', 'badvalue')
        self.assertEqual("The value for attr must be an integer: 'badvalue'.",
                         six.text_type(ex))
Beispiel #5
0
    def test_init_with_values(self):
        CONF.set_override('max_nodes_per_cluster', 300, enforce_type=True)
        sot = senlin_fields.Capacity(2, 200)

        self.assertEqual(2, sot.minimum)
        self.assertEqual(200, sot.maximum)
Beispiel #6
0
    def test_init(self):
        CONF.set_override('max_nodes_per_cluster', 300)
        sot = senlin_fields.Capacity()

        self.assertEqual(0, sot.minimum)
        self.assertEqual(300, sot.maximum)