diff options
author | Dan Smith <danms@us.ibm.com> | 2013-05-30 09:30:12 -0700 |
---|---|---|
committer | Dan Smith <danms@us.ibm.com> | 2013-06-03 08:51:39 -0700 |
commit | 275e673e90c2a00d45451a232ffd66e7a9618174 (patch) | |
tree | a8aea460c097d75fd99da0596dd9445f187202e6 | |
parent | 0afcc051a99443004510458da32e507385d58873 (diff) | |
download | nova-275e673e90c2a00d45451a232ffd66e7a9618174.tar.gz nova-275e673e90c2a00d45451a232ffd66e7a9618174.tar.xz nova-275e673e90c2a00d45451a232ffd66e7a9618174.zip |
Add fake_instance.py
There are lots of places in the tests where we create a piece of
an instance-like dict and return that from a stubbed database
function. This "works" right now, but won't in the future of stricter
objects. This adds a fake_instance.py (to mirror the other ones
already there) which builds an instance database primitive that
includes sane values for every field it should have. This will make
testing much easier going forward with instance objects.
Related to blueprint unified-object-model
Change-Id: I13d97cc101c1964aa91ce48093507bbc88803cbb
-rw-r--r-- | nova/tests/fake_instance.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/nova/tests/fake_instance.py b/nova/tests/fake_instance.py new file mode 100644 index 000000000..b63d16555 --- /dev/null +++ b/nova/tests/fake_instance.py @@ -0,0 +1,40 @@ +# Copyright 2013 IBM Corp. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import datetime +import uuid + +from nova.objects import instance as instance_obj + + +def fake_db_instance(**updates): + db_instance = { + 'id': 1, + 'uuid': str(uuid.uuid4()), + 'user_id': 'fake-user', + 'project_id': 'fake-project', + 'host': 'fake-host', + 'created_at': datetime.datetime(1955, 11, 5), + } + for field, typefn in instance_obj.Instance.fields.items(): + if field in db_instance: + continue + try: + db_instance[field] = typefn(None) + except TypeError: + db_instance[field] = typefn() + + if updates: + db_instance.update(updates) + return db_instance |