diff options
author | Ben Pfaff <blp@nicira.com> | 2012-06-27 09:56:20 -0700 |
---|---|---|
committer | Justin Pettit <jpettit@nicira.com> | 2012-08-13 15:31:37 -0700 |
commit | d4552c7d37d29219b52e076c395f99a7f896984c (patch) | |
tree | b97dfebb9392507518e204ec0a032d42afcda63e | |
parent | dfdc7813da6feaf33d4be359fb64c35b3a0474da (diff) |
tests: Fix MockXenAPI to make the ovs-xapi-sync test case pass again.
Commit a8d9dfc788 (xenserver: Improve efficiency of code by using
get_all_records_where()) updated the ovs-xapi-sync script and caused a unit
test failure. This fixes it.
Bug #12848.
Signed-off-by: Ben Pfaff <blp@nicira.com>
-rw-r--r-- | tests/MockXenAPI.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/MockXenAPI.py b/tests/MockXenAPI.py index 0c02dd54..cca1571f 100644 --- a/tests/MockXenAPI.py +++ b/tests/MockXenAPI.py @@ -1,4 +1,4 @@ -# Copyright (c) 2011 Nicira, Inc. +# Copyright (c) 2011, 2012 Nicira, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import re + def xapi_local(): return Session() @@ -48,6 +50,20 @@ class Table(object): def get_all(self): return [RecordRef(rec) for rec in self.records] + def get_all_records_where(self, condition): + k, v = re.match(r'field "([^"]*)"="([^"]*)"$', condition).groups() + d = {} + + # I'm sure that the keys used in the dictionary below are wrong + # but I can't find any documentation on get_all_records_where + # and this satisfies the current test case. + i = 0 + for rec in self.records: + if rec[k] == v: + d[i] = rec + i += 1 + return d + def get_by_uuid(self, uuid): recs = [rec for rec in self.records if rec["uuid"] == uuid] if len(recs) != 1: |