def generate_aim_object(cls, aim_type, **kwargs):
        """Generate AIM object with random identity attributes.

        Identity attributes will be considered as strings, which could be
        schema-invalid. kwargs can be passed to fix that.
        """
        res_dict = {x: utils.generate_uuid()
                    for x in aim_type.identity_attributes.keys()}
        res_dict.update(kwargs)
        return aim_type(**res_dict)
 def test_status_add_tenant(self):
     for res_klass in self.mgr.aim_resources:
         if res_klass in [aim_status.AciStatus, aim_status.AciFault,
                          resource.Agent, infra.HostDomainMappingV2,
                          infra.HostDomainMapping, tree.ActionLog]:
             continue
         res = self.mgr.create(
             self.ctx, res_klass(
                 **{k: utils.generate_uuid()
                    for k in res_klass.identity_attributes.keys()}))
         status = self.mgr.get_status(self.ctx, res)
         if not status:
             continue
         status_add_tenant.migrate(self.ctx.db_session)
         status = self.mgr.get_status(self.ctx, res)
         self.assertEqual(res.root, status.resource_root)
Beispiel #3
0
 def test_status_add_dn(self):
     for res_klass in self.mgr.aim_resources:
         if res_klass in [aim_status.AciStatus, aim_status.AciFault,
                          resource.Agent, infra.HostDomainMappingV2,
                          infra.HostDomainMapping, tree.ActionLog]:
             continue
         res = self.mgr.create(
             self.ctx, res_klass(
                 **{k: utils.generate_uuid()
                    for k in res_klass.identity_attributes.keys()}))
         status = self.mgr.get_status(self.ctx, res)
         if not status:
             continue
         status_add_tenant.migrate(self.ctx.db_session)
         status = self.mgr.get_status(self.ctx, res)
         self.assertEqual(res.dn, status.resource_dn)
Beispiel #4
0
 def _test_aim_server_per_type(self):
     exclude = {
         api_res.Configuration,  # There are many already
         status_res.AciFault,  # Tested by status test
         status_res.AciStatus,  # Tested by status test
         tree_res.ActionLog,  # Never created by API
         api_res.Topology,  # Can create only 1
         api_res.Agent,  # Created only by AID
         # REVISIT: Instead of avaoiding classes
         # with enum data types, we should introspect the
         # object and create valid identifiers for the test
         infra_res.HostDomainMappingV2,  # Avoiding enums for now
     }
     # For debugging purposes, only test one type
     test_only = {}
     # For test performance purposes, only test N klasses
     klass_num = 10
     # Run for a limited set of types, or it will timeout
     for res_type in test_only or list(
         (self.mgr.aim_resources - exclude))[:klass_num]:
         for cardinality in [0, 1, 3]:
             fail_msg = ('Test Failed for type %s with '
                         'cardinality %s' % (res_type, cardinality))
             to_create = [
                 self.generate_aim_object(res_type)
                 for _ in range(cardinality)
             ]
             # Create objects
             data = [
                 self.root.aimc._generate_data_item(x) for x in to_create
             ]
             resp = self.POST('aim', data=json.dumps(data))
             self.assertEqual(200, resp.status_code, fail_msg)
             # Set objects' status
             status_supported = False
             if to_create and self.mgr.get_status(
                     self.ctx, to_create[0], create_if_absent=True):
                 status_supported = True
                 for aim_obj in to_create:
                     self.mgr.set_resource_sync_pending(self.ctx, aim_obj)
             # Test GET all
             resp = self.GET('aim')
             self.assertEqual(200, resp.status_code, fail_msg)
             self.assertEqual(len(to_create),
                              resp.json()['count'], fail_msg)
             # There are AIM IDs now
             for item in data:
                 item.update({'aim_id': mock.ANY})
             sorting_key = lambda x: x['attributes']
             data_resp = resp.json()['data']
             for to_compare in [data, data_resp]:
                 for x in to_compare:
                     for non_user in res_type.non_user_attributes():
                         x['attributes'].pop(non_user, None)
             self.assertEqual(sorted(data, key=sorting_key),
                              sorted(data_resp, key=sorting_key), fail_msg)
             # GET with status included
             resp = self.GET('aim?include-status=true')
             self.assertEqual(200, resp.status_code, fail_msg)
             self.assertEqual(
                 len(to_create) * (2 if status_supported else 1),
                 resp.json()['count'], fail_msg)
             # Create some with a PUT, with a common attribute
             comm_attr = {}
             for set_attr, schema_type in (
                     res_type.other_attributes.iteritems()):
                 if schema_type['type'] == 'string' and (
                         'enum' not in schema_type):
                     comm_attr[set_attr] = utils.generate_uuid()
                     break
             to_put = [
                 self.generate_aim_object(res_type, **comm_attr)
                 for _ in range(cardinality)
             ]
             put_data = [
                 self.root.aimc._generate_data_item(x) for x in to_put
             ]
             self.PUT('aim', data=json.dumps(put_data))
             resp = self.GET('aim')
             self.assertEqual(200, resp.status_code, fail_msg)
             # Objects added
             self.assertEqual(
                 len(to_create) + len(to_put),
                 resp.json()['count'], fail_msg)
             if comm_attr:
                 uri = ('aim?object-type=%s&%s=%s' %
                        (utils.camel_to_snake(res_type.__name__),
                         comm_attr.keys()[0], comm_attr.values()[0]))
                 resp = self.GET(uri)
                 self.assertEqual(200, resp.status_code, fail_msg)
                 self.assertEqual(len(to_put),
                                  resp.json()['count'], fail_msg)
             # Delete objects just created
             for item in to_put:
                 uri = ('aim?object-type=%s&%s' %
                        (utils.camel_to_snake(res_type.__name__), '&'.join([
                            '%s=%s' % (k, getattr(item, k))
                            for k in item.identity_attributes.keys()
                        ])))
                 self.DELETE(uri)
             resp = self.GET('aim')
             self.assertEqual(200, resp.status_code, fail_msg)
             self.assertEqual(len(to_create),
                              resp.json()['count'], fail_msg)
             # Delete all
             resp = self.DELETE('aim')
             self.assertEqual(200, resp.status_code, fail_msg)
             resp = self.GET('aim')
             self.assertEqual(200, resp.status_code, fail_msg)
             self.assertEqual(0, resp.json()['count'], fail_msg)
Beispiel #5
0
 def __init__(self, **kwargs):
     super(Agent, self).__init__({'admin_state_up': True,
                                  'id': utils.generate_uuid()}, **kwargs)
 def __init__(self, **kwargs):
     super(ActionLog, self).__init__({'uuid': utils.generate_uuid()},
                                     **kwargs)