summaryrefslogtreecommitdiff
path: root/nova/tests/functional/db/test_instance_group.py
Commit message (Collapse)AuthorAgeFilesLines
* Use unittest.mock instead of third party mockStephen Finucane2022-08-011-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Now that we no longer support py27, we can use the standard library unittest.mock module instead of the third party mock lib. Most of this is autogenerated, as described below, but there is one manual change necessary: nova/tests/functional/regressions/test_bug_1781286.py We need to avoid using 'fixtures.MockPatch' since fixtures is using 'mock' (the library) under the hood and a call to 'mock.patch.stop' found in that test will now "stop" mocks from the wrong library. We have discussed making this configurable but the option proposed isn't that pretty [1] so this is better. The remainder was auto-generated with the following (hacky) script, with one or two manual tweaks after the fact: import glob for path in glob.glob('nova/tests/**/*.py', recursive=True): with open(path) as fh: lines = fh.readlines() if 'import mock\n' not in lines: continue import_group_found = False create_first_party_group = False for num, line in enumerate(lines): line = line.strip() if line.startswith('import ') or line.startswith('from '): tokens = line.split() for lib in ( 'ddt', 'six', 'webob', 'fixtures', 'testtools' 'neutron', 'cinder', 'ironic', 'keystone', 'oslo', ): if lib in tokens[1]: create_first_party_group = True break if create_first_party_group: break import_group_found = True if not import_group_found: continue if line.startswith('import ') or line.startswith('from '): tokens = line.split() if tokens[1] > 'unittest': break elif tokens[1] == 'unittest' and ( len(tokens) == 2 or tokens[4] > 'mock' ): break elif not line: break if create_first_party_group: lines.insert(num, 'from unittest import mock\n\n') else: lines.insert(num, 'from unittest import mock\n') del lines[lines.index('import mock\n')] with open(path, 'w+') as fh: fh.writelines(lines) Note that we cannot remove mock from our requirements files yet due to importing pypowervm unit test code in nova unit tests. This library still uses the mock lib, and since we are importing test code and that lib (correctly) only declares mock in its test-requirements.txt, mock would not otherwise be installed and would cause errors while loading nova unit test code. [1] https://github.com/testing-cabal/fixtures/pull/49 Change-Id: Id5b04cf2f6ca24af8e366d23f15cf0e5cac8e1cc Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
* db: Move remaining 'nova.db.sqlalchemy' modulesStephen Finucane2021-08-091-1/+1
| | | | | | | | The two remaining modules, 'api_models' and 'api_migrations', are moved to the new 'nova.db.api' module. Change-Id: I138670fe36b07546db5518f78c657197780c5040 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
* Use uuidsentinel from oslo.utilsEric Fried2018-09-051-1/+1
| | | | | | | | | | | | oslo.utils release 3.37.0 [1] introduced uuidsentinel [2]. This change rips out nova's uuidsentinel and replaces it with the one from oslo.utils. [1] https://review.openstack.org/#/c/599754/ [2] https://review.openstack.org/#/c/594179/ Change-Id: I7f5f08691ca3f73073c66c29dddb996fb2c2b266 Depends-On: https://review.openstack.org/600041
* Add policy to InstanceGroup objectYikun Jiang2018-07-121-6/+12
| | | | | | | | | | | | | | | The change items in this patch as below: 1. Add policy and rules to InstanceGroup, deprecate the policies field. 2. Also, make _from_db_object and _create_in_db method to support new "policy" field. The internal usage of InstanceGroup.policies is converted to use the new model in the REST API and RequestSpec compat code. Related to blueprint complex-anti-affinity-policies Change-Id: Ib33719a4b9599d86848c618a6e142c71ece79ca5
* Refactor policies to policy in InstanceGroup DB modelYikun Jiang2018-07-091-2/+6
| | | | | | | | | | | | | | A group can only have 1 policy associated it, but now we have ONE to MANY model in group model, this patch change it to ONE to ONE Model. We also adapt create method to new model, and remove policy update support in group.save because now we don't support to update a policy of the group. Related to blueprint complex-anti-affinity-policies Change-Id: I95eb1c8470a567408696132ae656305be53dc5bb
* Remove compatibility code for instance groupsMatt Riedemann2018-06-271-129/+4
| | | | | | | | | | | | | | | | | | | | | | The /345_require_online_migration_completion cell database migration added in Ocata prevents anyone from upgrading the cell database schema until they have performed the online instance group data migrations via the "nova-manage db online_data_migrations" command. This means we can remove the compatibility code in the InstanceGroup object which performs a lookup routine in the API database and if not found it falls back to the cell database, which at this point should be empty, therefore making that dead code now. The test_get_by_name and test_get_by_hint tests are moved from _TestInstanceGroupListObject to _TestInstanceGroupObject since they don't have anything to do with InstanceGroupList. A follow up change will remove the now unused main DB API methods for instance groups. Change-Id: Ifbd53b13fa0fef62e0329283b73d587f367e46c2
* Add InstanceGroup._remove_members_in_dbmelanie witt2017-06-081-0/+19
| | | | | | | | | | | | | | This adds a method for removing server group members from the database. It's private because we don't expose a way to remove server group members in the API and it's only needed to handle races near the quota limit. To handle races, we will check quota limits, create group members in the database, then check quota again. If the quota limits have been exceeded after creation of the group members, they will be removed from the database and OverQuota will be raised. Part of blueprint cells-count-resources-to-check-quota-in-api Change-Id: I8cda7a1503750f6b23919a6fbf7bb40c84ac582b
* Add InstanceGroupList.get_counts()melanie witt2017-06-061-0/+20
| | | | | | | | | This adds a method for getting counts of server groups in the database for checking quota. Part of blueprint cells-count-resources-to-check-quota-in-api Change-Id: I9eadf93b432630607069cdf8ec1915920e32b905
* Add online migration to move instance groups to API databasemelanie witt2016-08-221-0/+55
| | | | | | | | | This moves instance groups from the main database to the API database in an online migration. Part of blueprint cells-instance-groups-api-db Change-Id: I946767509903c76e9089bda02e24d964e383b91c
* Make InstanceGroup object favor the API databasemelanie witt2016-08-191-0/+185
This makes the InstanceGroup object load first from the API database, falling back to the main database as necessary. Creates happen in the API database only now. Part of blueprint cells-instance-groups-api-db Change-Id: I2fe7524818e92a4d9a55f84633e70091a42531ea