Ejemplo n.º 1
0
 def test_delete_node_trait(self):
     db_utils.create_test_node_traits(node_id=self.node.id,
                                      traits=['trait1', 'trait2'])
     self.dbapi.delete_node_trait(self.node.id, 'trait1')
     result = self.dbapi.get_node_traits_by_node_id(self.node.id)
     self.assertEqual(1, len(result))
     self.assertEqual('trait2', result[0].trait)
Ejemplo n.º 2
0
    def test_with_traits(self):
        obj_utils.create_test_node(self.context,
                                   uuid=uuidutils.generate_uuid(),
                                   power_state='power on',
                                   resource_class='x-large',
                                   provision_state='available')
        node = obj_utils.create_test_node(self.context,
                                          uuid=uuidutils.generate_uuid(),
                                          power_state='power on',
                                          resource_class='x-large',
                                          provision_state='available')
        db_utils.create_test_node_traits(['tr1', 'tr2'], node_id=node.id)

        allocation = obj_utils.create_test_allocation(self.context,
                                                      resource_class='x-large',
                                                      traits=['tr2'])

        allocations.do_allocate(self.context, allocation)

        allocation = objects.Allocation.get_by_uuid(self.context,
                                                    allocation['uuid'])
        self.assertIsNone(allocation['last_error'])
        self.assertEqual('active', allocation['state'])

        node = objects.Node.get_by_uuid(self.context, node['uuid'])
        self.assertEqual(allocation['uuid'], node['instance_uuid'])
        self.assertEqual(allocation['id'], node['allocation_id'])
        self.assertEqual(allocation['traits'], ['tr2'])
Ejemplo n.º 3
0
 def test_get_node_traits_by_node_id(self):
     db_utils.create_test_node_traits(node_id=self.node.id,
                                      traits=['trait1', 'trait2'])
     result = self.dbapi.get_node_traits_by_node_id(self.node.id)
     self.assertEqual(self.node.id, result[0].node_id)
     self.assertItemsEqual(['trait1', 'trait2'],
                           [trait.trait for trait in result])
Ejemplo n.º 4
0
 def test_get_node_traits_by_node_id(self):
     db_utils.create_test_node_traits(node_id=self.node.id,
                                      traits=['trait1', 'trait2'])
     result = self.dbapi.get_node_traits_by_node_id(self.node.id)
     self.assertEqual(self.node.id, result[0].node_id)
     self.assertCountEqual(['trait1', 'trait2'],
                           [trait.trait for trait in result])
Ejemplo n.º 5
0
    def test_with_traits(self):
        obj_utils.create_test_node(self.context,
                                   uuid=uuidutils.generate_uuid(),
                                   power_state='power on',
                                   resource_class='x-large',
                                   provision_state='available')
        node = obj_utils.create_test_node(self.context,
                                          uuid=uuidutils.generate_uuid(),
                                          power_state='power on',
                                          resource_class='x-large',
                                          provision_state='available')
        db_utils.create_test_node_traits(['tr1', 'tr2'], node_id=node.id)

        allocation = obj_utils.create_test_allocation(self.context,
                                                      resource_class='x-large',
                                                      traits=['tr2'])

        allocations.do_allocate(self.context, allocation)

        allocation = objects.Allocation.get_by_uuid(self.context,
                                                    allocation['uuid'])
        self.assertIsNone(allocation['last_error'])
        self.assertEqual('active', allocation['state'])

        node = objects.Node.get_by_uuid(self.context, node['uuid'])
        self.assertEqual(allocation['uuid'], node['instance_uuid'])
        self.assertEqual(allocation['id'], node['allocation_id'])
        self.assertEqual(allocation['traits'], ['tr2'])
Ejemplo n.º 6
0
 def test_delete_node_trait(self):
     db_utils.create_test_node_traits(node_id=self.node.id,
                                      traits=['trait1', 'trait2'])
     self.dbapi.delete_node_trait(self.node.id, 'trait1')
     result = self.dbapi.get_node_traits_by_node_id(self.node.id)
     self.assertEqual(1, len(result))
     self.assertEqual('trait2', result[0].trait)
Ejemplo n.º 7
0
    def test_add_node_trait_duplicate_at_limit(self):
        traits = ['trait%d' % n for n in range(50)]
        db_utils.create_test_node_traits(node_id=self.node.id, traits=traits)

        result = self.dbapi.add_node_trait(self.node.id, 'trait49', '1.0')
        self.assertEqual(self.node.id, result.node_id)
        self.assertEqual('trait49', result.trait)
Ejemplo n.º 8
0
    def test_add_node_trait_duplicate_at_limit(self):
        traits = ['trait%d' % n for n in range(50)]
        db_utils.create_test_node_traits(node_id=self.node.id, traits=traits)

        result = self.dbapi.add_node_trait(self.node.id, 'trait49', '1.0')
        self.assertEqual(self.node.id, result.node_id)
        self.assertEqual('trait49', result.trait)
Ejemplo n.º 9
0
    def test_add_node_trait_over_limit(self):
        traits = ['trait%d' % n for n in range(50)]
        db_utils.create_test_node_traits(node_id=self.node.id, traits=traits)

        self.assertRaises(exception.InvalidParameterValue,
                          self.dbapi.add_node_trait, self.node.id, 'trait50',
                          '1.0')
        # Ensure the trait was not added.
        result = self.dbapi.get_node_traits_by_node_id(self.node.id)
        self.assertNotIn('trait50', [trait.trait for trait in result])
Ejemplo n.º 10
0
    def test_add_node_trait_over_limit(self):
        traits = ['trait%d' % n for n in range(50)]
        db_utils.create_test_node_traits(node_id=self.node.id, traits=traits)

        self.assertRaises(exception.InvalidParameterValue,
                          self.dbapi.add_node_trait, self.node.id, 'trait50',
                          '1.0')
        # Ensure the trait was not added.
        result = self.dbapi.get_node_traits_by_node_id(self.node.id)
        self.assertNotIn('trait50', [trait.trait for trait in result])
Ejemplo n.º 11
0
 def test_get_node_by_uuid(self):
     node = utils.create_test_node()
     self.dbapi.set_node_tags(node.id, ['tag1', 'tag2'])
     utils.create_test_node_traits(node_id=node.id,
                                   traits=['trait1', 'trait2'])
     res = self.dbapi.get_node_by_uuid(node.uuid)
     self.assertEqual(node.id, res.id)
     self.assertEqual(node.uuid, res.uuid)
     self.assertItemsEqual(['tag1', 'tag2'], [tag.tag for tag in res.tags])
     self.assertItemsEqual(['trait1', 'trait2'],
                           [trait.trait for trait in res.traits])
Ejemplo n.º 12
0
 def test_get_node_by_uuid(self):
     node = utils.create_test_node()
     self.dbapi.set_node_tags(node.id, ['tag1', 'tag2'])
     utils.create_test_node_traits(node_id=node.id,
                                   traits=['trait1', 'trait2'])
     res = self.dbapi.get_node_by_uuid(node.uuid)
     self.assertEqual(node.id, res.id)
     self.assertEqual(node.uuid, res.uuid)
     self.assertItemsEqual(['tag1', 'tag2'], [tag.tag for tag in res.tags])
     self.assertItemsEqual(['trait1', 'trait2'],
                           [trait.trait for trait in res.traits])
Ejemplo n.º 13
0
    def test_get_node_by_instance(self):
        node = utils.create_test_node(
            instance_uuid='12345678-9999-0000-aaaa-123456789012')
        self.dbapi.set_node_tags(node.id, ['tag1', 'tag2'])
        utils.create_test_node_traits(node_id=node.id,
                                      traits=['trait1', 'trait2'])

        res = self.dbapi.get_node_by_instance(node.instance_uuid)
        self.assertEqual(node.uuid, res.uuid)
        self.assertItemsEqual(['tag1', 'tag2'], [tag.tag for tag in res.tags])
        self.assertItemsEqual(['trait1', 'trait2'],
                              [trait.trait for trait in res.traits])
Ejemplo n.º 14
0
    def test_get_node_by_instance(self):
        node = utils.create_test_node(
            instance_uuid='12345678-9999-0000-aaaa-123456789012')
        self.dbapi.set_node_tags(node.id, ['tag1', 'tag2'])
        utils.create_test_node_traits(node_id=node.id,
                                      traits=['trait1', 'trait2'])

        res = self.dbapi.get_node_by_instance(node.instance_uuid)
        self.assertEqual(node.uuid, res.uuid)
        self.assertItemsEqual(['tag1', 'tag2'], [tag.tag for tag in res.tags])
        self.assertItemsEqual(['trait1', 'trait2'],
                              [trait.trait for trait in res.traits])
Ejemplo n.º 15
0
    def test_reserve_node(self):
        node = utils.create_test_node()
        self.dbapi.set_node_tags(node.id, ['tag1', 'tag2'])
        utils.create_test_node_traits(node_id=node.id,
                                      traits=['trait1', 'trait2'])
        uuid = node.uuid

        r1 = 'fake-reservation'

        # reserve the node
        res = self.dbapi.reserve_node(r1, uuid)
        self.assertItemsEqual(['tag1', 'tag2'], [tag.tag for tag in res.tags])
        self.assertItemsEqual(['trait1', 'trait2'],
                              [trait.trait for trait in res.traits])

        # check reservation
        res = self.dbapi.get_node_by_uuid(uuid)
        self.assertEqual(r1, res.reservation)
Ejemplo n.º 16
0
    def test_reserve_node(self):
        node = utils.create_test_node()
        self.dbapi.set_node_tags(node.id, ['tag1', 'tag2'])
        utils.create_test_node_traits(node_id=node.id,
                                      traits=['trait1', 'trait2'])
        uuid = node.uuid

        r1 = 'fake-reservation'

        # reserve the node
        res = self.dbapi.reserve_node(r1, uuid)
        self.assertItemsEqual(['tag1', 'tag2'], [tag.tag for tag in res.tags])
        self.assertItemsEqual(['trait1', 'trait2'],
                              [trait.trait for trait in res.traits])

        # check reservation
        res = self.dbapi.get_node_by_uuid(uuid)
        self.assertEqual(r1, res.reservation)
Ejemplo n.º 17
0
    def test_traits_mismatch(self):
        node = obj_utils.create_test_node(self.context,
                                          resource_class='x-large',
                                          provision_state='active')
        db_utils.create_test_node_traits(['tr1', 'tr2'], node_id=node.id)
        allocation = obj_utils.create_test_allocation(self.context,
                                                      resource_class='x-large',
                                                      traits=['tr1', 'tr3'])

        self.assertRaises(exception.AllocationFailed,
                          allocations.backfill_allocation, self.context,
                          allocation, node.id)

        allocation = objects.Allocation.get_by_uuid(self.context,
                                                    allocation['uuid'])
        self.assertEqual('error', allocation['state'])
        self.assertIn('traits', allocation['last_error'])
        self.assertIsNone(allocation['node_id'])

        node = objects.Node.get_by_uuid(self.context, node['uuid'])
        self.assertIsNone(node['instance_uuid'])
        self.assertIsNone(node['allocation_id'])
Ejemplo n.º 18
0
 def test_node_trait_exists(self):
     db_utils.create_test_node_traits(node_id=self.node.id,
                                      traits=['trait1', 'trait2'])
     result = self.dbapi.node_trait_exists(self.node.id, 'trait1')
     self.assertTrue(result)
Ejemplo n.º 19
0
 def test_unset_node_traits(self):
     db_utils.create_test_node_traits(node_id=self.node.id,
                                      traits=['trait1', 'trait2'])
     self.dbapi.unset_node_traits(self.node.id)
     result = self.dbapi.get_node_traits_by_node_id(self.node.id)
     self.assertEqual([], result)
Ejemplo n.º 20
0
 def test_unset_node_traits(self):
     db_utils.create_test_node_traits(node_id=self.node.id,
                                      traits=['trait1', 'trait2'])
     self.dbapi.unset_node_traits(self.node.id)
     result = self.dbapi.get_node_traits_by_node_id(self.node.id)
     self.assertEqual([], result)
Ejemplo n.º 21
0
 def test_node_trait_exists(self):
     db_utils.create_test_node_traits(node_id=self.node.id,
                                      traits=['trait1', 'trait2'])
     result = self.dbapi.node_trait_exists(self.node.id, 'trait1')
     self.assertTrue(result)