summaryrefslogtreecommitdiff
path: root/nova/tests/unit/objects/test_instance_mapping.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>
* Raise InstanceMappingNotFound if StaleDataError is encounteredmelanie witt2020-06-241-0/+9
| | | | | | | | | | | | | | | | | | | | | We have a race where if a user issues a delete request while an instance is in the middle of booting, we could fail to update the 'queued_for_delete' field on the instance mapping with: sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table 'instance_mappings' expected to update 1 row(s); 0 were matched. This happens if we've retrieved the instance mapping record from the database and then it gets deleted by nova-conductor before we attempt to save() it. This handles the situation by adding try-except around the update call to catch StaleDataError and raise InstanceMappingNotFound instead, which the caller does know how to handle. Closes-Bug: #1882608 Change-Id: I2cdcad7226312ed81f4242c8d9ac919715524b48
* Add user_id field to InstanceMappingmelanie witt2019-03-081-4/+31
| | | | | | | | | | | This adds the new user_id column from the instance_mappings table as a field in the InstanceMapping object. There is already a project_id field containing the project_id for the instance. The user_id field will contain the corresponding user_id for the instance. Part of blueprint count-quota-usage-from-placement Change-Id: I0f523b2a2e09e1ece9e1911325e55cffd183a9d5
* Fix InstanceMapping to always default queued_for_delete=FalseDan Smith2019-02-061-0/+18
| | | | | | | | | | | This object has a default=False setting for queued_for_delete, but never actually sets that value. All newly created records should have a non-NULL value for this field, and we have a migration to fix them, so this change explicitly forces that =False, unless the object is being created with a value set. Closes-Bug: #1814913 Change-Id: I99c5cc24c7e9bf5e2e72ffc868990b87b0e8e3f8
* Add queued_for_delete field to InstanceMapping objectSurya Seetharaman2018-07-231-0/+13
| | | | | | | | | | | | | | This patch adds a new field queued_for_delete to InstanceMapping object which would be used to represent the value in the queued_for_delete column of the instance_mappings table for each record. This will be set to True if an instance is either deleted or soft_deleted. Will be adding a data migration tool for filling this field. Related to blueprint handling-down-cell Change-Id: Iebb6974efda6dd5b24bc9ad987b6400455c780b6
* cleanup mapping/reqspec after archive instanceSurya Seetharaman2017-11-211-0/+14
| | | | | | | | | | | | | | | | | | This patch aims at deleting the records of the archived instances from the instance_mappings and request_specs tables in the API database immediately following their archival from instances to shadow_instances table. So upon running the 'nova-manage db archive_deleted_rows' command the records of the archived instances will be automatically removed from the instance_mappings and request_specs tables as well. A warning has also been added to fix the issue of 'nova-manage verify_instance' returning a valid instance mapping even after the instance is deleted. The patch also adds InstanceMappingList.destory_bulk() and RequestSpec.destroy_bulk() methods for ease of bulk deletion of records. Change-Id: I483701a55576c245d091ff086b32081b392f746e Closes-Bug: #1724621 Closes-Bug: #1678056
* Fix invalid import orderbhagyashris2016-07-041-1/+0
| | | | | | | | | | Made corrections in import order as per OpenStack import standards [1]. [1] http://docs.openstack.org/developer/hacking/#import-order-template TrivialFix Change-Id: Idf90cec78f3853af246b8f98e0bb0308aa626c09
* Include CellMapping in InstanceMapping objectAndrew Laski2016-03-241-11/+64
| | | | | | | | | | | | | Right now InstanceMapping exposes the cell_mappings.id db field which is just an implementation detail of the db relationship and should not be exposed in the object. It is also useless as a way to look up the actual CellMapping through that object interface. And InstanceMapping is only looked up in order to find a CellMapping. So the CellMapping should be joined during the db query and loaded on the InstanceMapping object by default. Change-Id: Ia8691b76bba310327bfe0995964525409794d1af
* Make InstanceMappings.cell_id nullableAndrew Laski2016-03-021-0/+5
| | | | | | | | | | | | | In order to indicate that an instance boot request has been received, but the instance has not yet been scheduled to a cell, it should be mapped to a null cell_id. This will mean that an instance list/show will need to fetch the instance details from the BuildRequest object rather than looking for the instance in a cell database. A migration is added and the InstanceMapping object is modified to make this possible. Partially-implements: bp cells-scheduling-interaction Change-Id: Iee768512314f11a13e2a85a1e7d5442864ddbc4b
* Add InstanceMapping objectAndrew Laski2015-03-181-0/+122
This adds the InstanceMapping object for interacting with the instance_mapping table. Rather than creating a new db api the database operations are embedded within the object. This keeps the logic near where it's being used. This does make an assumption about using sqlalchemy for now. In order to allow for substituting the database driver we will probably want to setup a subclassing system for objects to swap that part out. This would allow for finer control than we currently have. Change-Id: Ide9cc7a255b886647fd424c2030beff0335e2cd3 bp: cells-v2-mapping