Example #1
0
 def test_get_chassis_list(self):
     uuids = [self.chassis.uuid]
     for i in range(1, 6):
         ch = utils.create_test_chassis(uuid=uuidutils.generate_uuid())
         uuids.append(six.text_type(ch.uuid))
     res = self.dbapi.get_chassis_list()
     res_uuids = [r.uuid for r in res]
     six.assertCountEqual(self, uuids, res_uuids)
Example #2
0
 def test_get_chassis_list(self):
     uuids = [self.chassis.uuid]
     for i in range(1, 6):
         ch = utils.create_test_chassis(uuid=uuidutils.generate_uuid())
         uuids.append(six.text_type(ch.uuid))
     res = self.dbapi.get_chassis_list()
     res_uuids = [r.uuid for r in res]
     six.assertCountEqual(self, uuids, res_uuids)
Example #3
0
    def test_get_node_list_with_filters(self):
        ch1 = utils.create_test_chassis(uuid=uuidutils.generate_uuid())
        ch2 = utils.create_test_chassis(uuid=uuidutils.generate_uuid())

        node1 = utils.create_test_node(
            driver='driver-one',
            instance_uuid=uuidutils.generate_uuid(),
            reservation='fake-host',
            uuid=uuidutils.generate_uuid(),
            chassis_id=ch1['id'])
        node2 = utils.create_test_node(
            driver='driver-two',
            uuid=uuidutils.generate_uuid(),
            chassis_id=ch2['id'],
            maintenance=True)

        res = self.dbapi.get_node_list(filters={'chassis_uuid': ch1['uuid']})
        self.assertEqual([node1.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'chassis_uuid': ch2['uuid']})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'driver': 'driver-one'})
        self.assertEqual([node1.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'driver': 'bad-driver'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'associated': True})
        self.assertEqual([node1.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'associated': False})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'reserved': True})
        self.assertEqual([node1.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'reserved': False})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'maintenance': True})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'maintenance': False})
        self.assertEqual([node1.id], [r.id for r in res])
Example #4
0
 def test_max_count_zero(self):
     orig_node = utils.create_test_node(version=self.node_old_ver)
     orig_chassis = utils.create_test_chassis(version=self.chassis_old_ver)
     self.assertEqual((self.num_diff_objs, self.num_diff_objs),
                      self.dbapi.update_to_latest_versions(self.context, 0))
     node = self.dbapi.get_node_by_uuid(orig_node.uuid)
     self.assertEqual(self.node_ver, node.version)
     chassis = self.dbapi.get_chassis_by_uuid(orig_chassis.uuid)
     self.assertEqual(self.chassis_ver, chassis.version)
Example #5
0
 def test_max_count_zero(self):
     orig_node = utils.create_test_node(version=self.node_old_ver)
     orig_chassis = utils.create_test_chassis(version=self.chassis_old_ver)
     self.assertEqual((self.num_diff_objs, self.num_diff_objs),
                      self.dbapi.update_to_latest_versions(self.context, 0))
     node = self.dbapi.get_node_by_uuid(orig_node.uuid)
     self.assertEqual(self.node_ver, node.version)
     chassis = self.dbapi.get_chassis_by_uuid(orig_chassis.uuid)
     self.assertEqual(self.chassis_ver, chassis.version)
Example #6
0
 def test_save_after_refresh(self):
     # Ensure that it's possible to do object.save() after object.refresh()
     db_chassis = utils.create_test_chassis()
     c = objects.Chassis.get_by_uuid(self.context, db_chassis.uuid)
     c_copy = objects.Chassis.get_by_uuid(self.context, db_chassis.uuid)
     c.description = 'b240'
     c.save()
     c_copy.refresh()
     c_copy.description = 'aaff'
     # Ensure this passes and an exception is not generated
     c_copy.save()
Example #7
0
 def test_max_count_zero(self):
     orig_node = utils.create_test_node(version=None)
     orig_chassis = utils.create_test_chassis(version=None)
     self.assertIsNone(orig_node.version)
     self.assertIsNone(orig_chassis.version)
     self.assertEqual((2, 2),
                      self.dbapi.backfill_version_column(self.context, 0))
     node = self.dbapi.get_node_by_uuid(orig_node.uuid)
     self.assertEqual(self.node_ver, node.version)
     chassis = self.dbapi.get_chassis_by_uuid(orig_chassis.uuid)
     self.assertEqual(self.chassis_ver, chassis.version)
Example #8
0
 def test_save_after_refresh(self):
     # Ensure that it's possible to do object.save() after object.refresh()
     db_chassis = db_utils.create_test_chassis()
     c = objects.Chassis.get_by_uuid(self.context, db_chassis.uuid)
     c_copy = objects.Chassis.get_by_uuid(self.context, db_chassis.uuid)
     c.description = 'b240'
     c.save()
     c_copy.refresh()
     c_copy.description = 'aaff'
     # Ensure this passes and an exception is not generated
     c_copy.save()
Example #9
0
 def test_old_version_max_count_1(self):
     orig_node = utils.create_test_node(version=self.node_old_ver)
     orig_chassis = utils.create_test_chassis(version=self.chassis_old_ver)
     num_modified = 1 if self.num_diff_objs else 0
     self.assertEqual((self.num_diff_objs, num_modified),
                      self.dbapi.update_to_latest_versions(self.context, 1))
     node = self.dbapi.get_node_by_uuid(orig_node.uuid)
     chassis = self.dbapi.get_chassis_by_uuid(orig_chassis.uuid)
     self.assertTrue(node.version == self.node_old_ver
                     or chassis.version == self.chassis_old_ver)
     self.assertTrue(node.version == self.node_ver
                     or chassis.version == self.chassis_ver)
Example #10
0
 def test_no_version_max_count_1(self):
     orig_node = utils.create_test_node(version=None)
     orig_chassis = utils.create_test_chassis(version=None)
     self.assertIsNone(orig_node.version)
     self.assertIsNone(orig_chassis.version)
     self.assertEqual((2, 1),
                      self.dbapi.backfill_version_column(self.context, 1))
     node = self.dbapi.get_node_by_uuid(orig_node.uuid)
     chassis = self.dbapi.get_chassis_by_uuid(orig_chassis.uuid)
     self.assertTrue(node.version is None or chassis.version is None)
     self.assertTrue(node.version == self.node_ver or
                     chassis.version == self.chassis_ver)
Example #11
0
 def test_old_version_max_count_1(self):
     orig_node = utils.create_test_node(version=self.node_old_ver)
     orig_chassis = utils.create_test_chassis(version=self.chassis_old_ver)
     num_modified = 1 if self.num_diff_objs else 0
     self.assertEqual((self.num_diff_objs, num_modified),
                      self.dbapi.update_to_latest_versions(self.context, 1))
     node = self.dbapi.get_node_by_uuid(orig_node.uuid)
     chassis = self.dbapi.get_chassis_by_uuid(orig_chassis.uuid)
     self.assertTrue(node.version == self.node_old_ver or
                     chassis.version == self.chassis_old_ver)
     self.assertTrue(node.version == self.node_ver or
                     chassis.version == self.chassis_ver)
Example #12
0
    def test_get_node_list_with_filters(self):
        ch1 = utils.create_test_chassis(uuid=uuidutils.generate_uuid())
        ch2 = utils.create_test_chassis(uuid=uuidutils.generate_uuid())

        node1 = utils.create_test_node(driver='driver-one',
                                       instance_uuid=uuidutils.generate_uuid(),
                                       reservation='fake-host',
                                       uuid=uuidutils.generate_uuid(),
                                       chassis_id=ch1['id'])
        node2 = utils.create_test_node(driver='driver-two',
                                       uuid=uuidutils.generate_uuid(),
                                       chassis_id=ch2['id'],
                                       maintenance=True,
                                       fault='boom',
                                       resource_class='foo')

        res = self.dbapi.get_node_list(filters={'chassis_uuid': ch1['uuid']})
        self.assertEqual([node1.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'chassis_uuid': ch2['uuid']})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'driver': 'driver-one'})
        self.assertEqual([node1.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'driver': 'bad-driver'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'associated': True})
        self.assertEqual([node1.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'associated': False})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'reserved': True})
        self.assertEqual([node1.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'reserved': False})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'maintenance': True})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'maintenance': False})
        self.assertEqual([node1.id], [r.id for r in res])

        res = self.dbapi.get_nodeinfo_list(filters={'fault': 'boom'})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_nodeinfo_list(filters={'fault': 'moob'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'resource_class': 'foo'})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'id': node1.id})
        self.assertEqual([node1.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'uuid': node1.uuid})
        self.assertEqual([node1.id], [r.id for r in res])

        # ensure unknown filters explode
        filters = {'bad_filter': 'foo'}
        self.assertRaisesRegex(ValueError,
                               'bad_filter',
                               self.dbapi.get_node_list,
                               filters=filters)

        # even with good filters present
        filters = {'bad_filter': 'foo', 'id': node1.id}
        self.assertRaisesRegex(ValueError,
                               'bad_filter',
                               self.dbapi.get_node_list,
                               filters=filters)
Example #13
0
 def setUp(self):
     super(DbChassisTestCase, self).setUp()
     self.chassis = utils.create_test_chassis()
Example #14
0
    def _create_test_data(self):
        allocated_node_id = 31
        fake_db_allocation = db_utils.create_test_allocation(
            node_id=allocated_node_id,
            resource_class="CUSTOM_TEST")
        fake_db_node = db_utils.create_test_node(
            chassis_id=None,
            driver='fake-driverz',
            owner='z')
        fake_db_node_alloced = db_utils.create_test_node(
            id=allocated_node_id,
            chassis_id=None,
            allocation_id=fake_db_allocation['id'],
            uuid='22e26c0b-03f2-4d2e-ae87-c02d7f33c000',
            driver='fake-driverz',
            owner='z')
        fake_vif_port_id = "ee21d58f-5de2-4956-85ff-33935ea1ca00"
        fake_db_port = db_utils.create_test_port(
            node_id=fake_db_node['id'],
            internal_info={'tenant_vif_port_id': fake_vif_port_id})
        fake_db_portgroup = db_utils.create_test_portgroup(
            uuid="6eb02b44-18a3-4659-8c0b-8d2802581ae4",
            node_id=fake_db_node['id'])
        fake_db_chassis = db_utils.create_test_chassis(
            drivers=['fake-hardware', 'fake-driverz', 'fake-driver'])
        fake_db_deploy_template = db_utils.create_test_deploy_template()
        fake_db_conductor = db_utils.create_test_conductor()
        fake_db_volume_target = db_utils.create_test_volume_target(
            node_id=fake_db_allocation['id'])
        fake_db_volume_connector = db_utils.create_test_volume_connector(
            node_id=fake_db_allocation['id'])
        # Trait name aligns with create_test_node_trait.
        fake_trait = 'trait'
        fake_setting = 'FAKE_SETTING'
        db_utils.create_test_bios_setting(
            node_id=fake_db_node['id'],
            name=fake_setting,
            value=fake_setting)
        db_utils.create_test_node_trait(
            node_id=fake_db_node['id'])

        # dedicated node for portgroup addition test to avoid
        # false positives with test runners.
        db_utils.create_test_node(
            uuid='18a552fb-dcd2-43bf-9302-e4c93287be11')
        self.format_data.update({
            'node_ident': fake_db_node['uuid'],
            'allocated_node_ident': fake_db_node_alloced['uuid'],
            'port_ident': fake_db_port['uuid'],
            'portgroup_ident': fake_db_portgroup['uuid'],
            'chassis_ident': fake_db_chassis['uuid'],
            'deploy_template_ident': fake_db_deploy_template['uuid'],
            'allocation_ident': fake_db_allocation['uuid'],
            'conductor_ident': fake_db_conductor['hostname'],
            'vif_ident': fake_vif_port_id,
            # Can't use the same fake-driver as other tests can
            # pollute a global method cache in the API that is in the
            # test runner, resulting in false positives.
            'driver_name': 'fake-driverz',
            'bios_setting': fake_setting,
            'trait': fake_trait,
            'volume_target_ident': fake_db_volume_target['uuid'],
            'volume_connector_ident': fake_db_volume_connector['uuid'],
        })
Example #15
0
 def setUp(self):
     super(DbChassisTestCase, self).setUp()
     self.chassis = utils.create_test_chassis()
Example #16
0
    def test_get_node_list_with_filters(self):
        ch1 = utils.create_test_chassis(uuid=uuidutils.generate_uuid())
        ch2 = utils.create_test_chassis(uuid=uuidutils.generate_uuid())

        node1 = utils.create_test_node(
            driver='driver-one',
            instance_uuid=uuidutils.generate_uuid(),
            reservation='fake-host',
            uuid=uuidutils.generate_uuid(),
            chassis_id=ch1['id'])
        node2 = utils.create_test_node(
            driver='driver-two',
            uuid=uuidutils.generate_uuid(),
            chassis_id=ch2['id'],
            maintenance=True,
            fault='boom',
            resource_class='foo',
            conductor_group='group1',
            power_state='power on')

        res = self.dbapi.get_node_list(filters={'chassis_uuid': ch1['uuid']})
        self.assertEqual([node1.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'chassis_uuid': ch2['uuid']})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'driver': 'driver-one'})
        self.assertEqual([node1.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'driver': 'bad-driver'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'associated': True})
        self.assertEqual([node1.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'associated': False})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'reserved': True})
        self.assertEqual([node1.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'reserved': False})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'maintenance': True})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'maintenance': False})
        self.assertEqual([node1.id], [r.id for r in res])

        res = self.dbapi.get_nodeinfo_list(filters={'fault': 'boom'})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_nodeinfo_list(filters={'fault': 'moob'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'resource_class': 'foo'})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'conductor_group': 'group1'})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'conductor_group': 'group2'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'id': node1.id})
        self.assertEqual([node1.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'uuid': node1.uuid})
        self.assertEqual([node1.id], [r.id for r in res])

        uuids = [uuidutils.generate_uuid(),
                 node1.uuid,
                 uuidutils.generate_uuid()]
        res = self.dbapi.get_node_list(filters={'uuid_in': uuids})
        self.assertEqual([node1.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'with_power_state': True})
        self.assertEqual([node2.id], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'with_power_state': False})
        self.assertEqual([node1.id], [r.id for r in res])

        # ensure unknown filters explode
        filters = {'bad_filter': 'foo'}
        self.assertRaisesRegex(ValueError,
                               'bad_filter',
                               self.dbapi.get_node_list,
                               filters=filters)

        # even with good filters present
        filters = {'bad_filter': 'foo', 'id': node1.id}
        self.assertRaisesRegex(ValueError,
                               'bad_filter',
                               self.dbapi.get_node_list,
                               filters=filters)