示例#1
0
def compare_obj(test, obj, db_obj, subs=None, allow_missing=None):
    """Compare a NovaObject and a dict-like database object.

    This automatically converts TZ-aware datetimes and iterates over
    the fields of the object.

    :param:test: The TestCase doing the comparison
    :param:obj: The NovaObject to examine
    :param:db_obj: The dict-like database object to use as reference
    :param:subs: A dict of objkey=dbkey field substitutions
    :param:allow_missing: A list of fields that may not be in db_obj
    """

    if subs is None:
        subs = {}
    if allow_missing is None:
        allow_missing = []

    for key in obj.fields:
        if key in allow_missing and not obj.obj_attr_is_set(key):
            continue
        obj_val = obj[key]
        db_key = subs.get(key, key)
        db_val = db_obj[db_key]
        if isinstance(obj_val, datetime.datetime):
            obj_val = obj_val.replace(tzinfo=None)
        test.assertEqual(db_val, obj_val)
示例#2
0
def compare_obj(test, obj, db_obj, subs=None, allow_missing=None):
    """Compare a NovaObject and a dict-like database object.

    This automatically converts TZ-aware datetimes and iterates over
    the fields of the object.

    :param:test: The TestCase doing the comparison
    :param:obj: The NovaObject to examine
    :param:db_obj: The dict-like database object to use as reference
    :param:subs: A dict of objkey=dbkey field substitutions
    :param:allow_missing: A list of fields that may not be in db_obj
    """

    if subs is None:
        subs = {}
    if allow_missing is None:
        allow_missing = []

    for key in obj.fields:
        if key in allow_missing and not obj.obj_attr_is_set(key):
            continue
        obj_val = obj[key]
        db_key = subs.get(key, key)
        db_val = db_obj[db_key]
        if isinstance(obj_val, datetime.datetime):
            obj_val = obj_val.replace(tzinfo=None)
        test.assertEqual(db_val, obj_val)
示例#3
0
 def _compare(test, db, obj):
     for field, value in db.items():
         # NOTE(danms): The datetimes on SQLA models are tz-unaware,
         # but the object has tz-aware datetimes. If we're comparing
         # a model to an object (as opposed to a fake dict), just
         # ignore the datetimes in the comparison.
         if (isinstance(db, api_models.API_BASE)
                 and isinstance(value, datetime.datetime)):
             continue
         test.assertEqual(db[field], obj[field])
 def _compare(test, db, obj, ignored_fields=None):
     if ignored_fields is None:
         ignored_fields = []
     for field, value in db.items():
         if field in ignored_fields:
             continue
         obj_field = field
         if obj_field == 'uuid':
             obj_field = 'instance_uuid'
         test.assertEqual(db[field], getattr(obj, obj_field),
                          'Field %s is not equal' % field)
示例#5
0
 def _compare(test, db, obj, ignored_fields=None):
     if ignored_fields is None:
         ignored_fields = []
     for field, value in db.items():
         if field in ignored_fields:
             continue
         obj_field = field
         if obj_field == 'uuid':
             obj_field = 'instance_uuid'
         test.assertEqual(db[field], obj[obj_field],
                 'Field {0!s} is not equal'.format(field))
示例#6
0
 def _compare(test, db, obj, ignored_fields=None):
     if ignored_fields is None:
         ignored_fields = []
     for field, value in db.items():
         if field in ignored_fields:
             continue
         obj_field = field
         if obj_field == 'uuid':
             obj_field = 'instance_uuid'
         test.assertEqual(db[field], getattr(obj, obj_field),
                 'Field %s is not equal' % field)
def assert_network_info_has_ip(test, actual_network_info,
                               expected_ip, expected_network):
    (network_info, vif_config_net_params) = actual_network_info
    expected_ip_block = expected_ip['ip_block']
    expected_dns = [expected_ip_block['dns1'], expected_ip_block['dns2']]
    test.assertEqual(vif_config_net_params['label'],
                     expected_network['label'])
    test.assertEqual(vif_config_net_params['gateway'],
                     expected_ip_block['gateway'])
    test.assertEqual(vif_config_net_params['broadcast'],
                     expected_ip_block['broadcast'])
    test.assertEqual(vif_config_net_params['dns'], expected_dns)
    test.assertEqual(vif_config_net_params['ips'],
                     [{'ip': expected_ip['address'],
                       'netmask': expected_ip_block['netmask'],
                       'enabled': '1'}])
示例#8
0
 def _compare(test, db, obj):
     for field, value in db.items():
         test.assertEqual(db[field], obj[field])
 def _compare(test, db, obj):
     for field, value in db.items():
         obj_field = field
         if obj_field == 'uuid':
             obj_field = 'instance_uuid'
         test.assertEqual(db[field], obj[obj_field])
示例#10
0
 def _compare(test, db, obj):
     for field, value in db.items():
         test.assertEqual(db[field], obj[field])
示例#11
0
 def _compare(test, db, obj):
     for field, value in db.items():
         obj_field = field
         if obj_field == "uuid":
             obj_field = "instance_uuid"
         test.assertEqual(db[field], obj[obj_field])