def test_fill_events_fault(self):
     events = [
         {'fvRsCtx': {
             'attributes': {'dn': 'uni/tn-ivar-wstest/BD-test/rsctx',
                            'tnFvCtxName': 'asasa'}}},
         {'faultInst': {'attributes': {
             'dn': 'uni/tn-ivar-wstest/BD-test/rsctx/fault-F0952',
             'code': 'F0952'}}}
     ]
     complete = [
         {'fvBD': {'attributes': {'arpFlood': 'yes',
                                  'dn': 'uni/tn-ivar-wstest/BD-test',
                                  'epMoveDetectMode': 'garp',
                                  'ipLearning': 'yes',
                                  'limitIpLearnToSubnets': 'no',
                                  'nameAlias': '',
                                  'unicastRoute': 'yes',
                                  'unkMacUcastAct': 'proxy'}}},
         {'fvRsCtx': {
             'attributes': {'dn': 'uni/tn-ivar-wstest/BD-test/rsctx',
                            'tnFvCtxName': 'asasa'}}},
         {'faultInst': {'attributes': {
          'dn': 'uni/tn-ivar-wstest/BD-test/rsctx/fault-F0952',
          'code': 'F0952'}}},
     ]
     self._add_data_to_tree(complete, self.backend_state)
     events = self.manager.ownership_mgr.filter_ownership(
         self.manager._fill_events(events))
     self.assertEqual(utils.deep_sort(complete),
                      utils.deep_sort(events))
    def test_fill_events(self):
        events = [
            {"fvRsCtx": {"attributes": {
                "dn": "uni/tn-test-tenant/BD-test/rsctx",
                "tnFvCtxName": "test", "status": "modified"}}},
        ]
        complete = {"fvRsCtx": {"attributes": {
            "dn": "uni/tn-test-tenant/BD-test/rsctx",
            "tnFvCtxName": "test"}}}
        parent_bd = {
            'fvBD': {
                'attributes': {
                    'arpFlood': 'no', 'dn': 'uni/tn-test-tenant/BD-test',
                    'epMoveDetectMode': '', 'ipLearning': 'yes',
                    'limitIpLearnToSubnets': 'no', 'nameAlias': '',
                    'unicastRoute': 'yes', 'unkMacUcastAct': 'proxy'}}}
        self._add_data_to_tree([parent_bd, complete], self.backend_state)
        events = self.manager.ownership_mgr.filter_ownership(
            self.manager._fill_events(events))
        self.assertEqual(utils.deep_sort([complete, parent_bd]),
                         utils.deep_sort(events))

        # Now start from BD
        events = [{"fvBD": {"attributes": {
            "arpFlood": "yes", "descr": "test",
            "dn": "uni/tn-test-tenant/BD-test", "status": "modified"}}}]
        parent_bd['fvBD']['attributes'].update(events[0]['fvBD']['attributes'])
        parent_bd['fvBD']['attributes'].pop('status')
        events = self.manager.ownership_mgr.filter_ownership(
            self.manager._fill_events(events))
        self.assertEqual(utils.deep_sort([parent_bd, complete]),
                         utils.deep_sort(events))
 def test_fill_events_noop(self):
     # On unchanged data, fill events is a noop
     events = self._init_event()
     events_copy = copy.deepcopy(events)
     events = self.manager._fill_events(events)
     self.assertEqual(utils.deep_sort(events),
                      utils.deep_sort(events_copy))
Ejemplo n.º 4
0
    def test_get_resources_for_delete(self):
        objs = [
            {'fvBD': {'attributes': {
                'dn': 'uni/tn-t1/BD-test'}}},
            {'vzRsSubjFiltAtt': {'attributes': {
                'dn': 'uni/tn-t1/brc-c/subj-s/rssubjFiltAtt-f'}}},
            {'vzRsFiltAtt': {'attributes': {
                'dn': 'uni/tn-t1/brc-c/subj-s/intmnl/rsfiltAtt-g'}}},
            {'vzRsFiltAtt': {'attributes': {
                'dn': 'uni/tn-t1/brc-c/subj-s/outtmnl/rsfiltAtt-h'}}}]
        keys = [('fvTenant|t1', 'fvBD|test'),
                ('fvTenant|t1', 'vzBrCP|c', 'vzSubj|s',
                 'vzRsSubjFiltAtt|f'),
                ('fvTenant|t1', 'vzBrCP|c', 'vzSubj|s',
                 'vzInTerm|intmnl', 'vzRsFiltAtt|g'),
                ('fvTenant|t1', 'vzBrCP|c', 'vzSubj|s',
                 'vzOutTerm|outtmnl', 'vzRsFiltAtt|h')]
        result = self.universe.get_resources_for_delete(keys)
        self.assertEqual(utils.deep_sort(objs), utils.deep_sort(result))
        # Create a pending monitored object
        tn1 = resource.Tenant(name='tn1', monitored=True)
        monitored_bd = resource.BridgeDomain(
            tenant_name='tn1', name='monitoredBD', monitored=True)
        self.universe.manager.create(self.ctx, tn1)
        self.universe.manager.set_resource_sync_pending(self.ctx, tn1)
        self.universe.manager.create(self.ctx, monitored_bd)
        self.universe.manager.set_resource_sync_pending(self.ctx, monitored_bd)

        self.universe.multiverse = []
        result = self.universe.get_resources_for_delete(
            [('fvTenant|tn1', 'fvBD|monitoredBD')])
        self.assertEqual(1, len(result))
        result = result[0]
        self.assertEqual('tagInst', result.keys()[0])
        self.assertEqual('uni/tn-tn1/BD-monitoredBD/tag-openstack_aid',
                         list(result.values())[0]['attributes']['dn'])

        # Delete an RS-node of a monitored object
        self.universe.manager.create(self.ctx, resource.L3Outside(
            tenant_name='tn1', name='out', monitored=True))
        ext_net = self.universe.manager.create(
            self.ctx,
            resource.ExternalNetwork(tenant_name='tn1', l3out_name='out',
                                     name='inet',
                                     provided_contract_names=['p1'],
                                     monitored=True))
        self.universe.manager.set_resource_sync_synced(self.ctx, ext_net)
        result = self.universe.get_resources_for_delete(
            [('fvTenant|tn1', 'l3extOut|out', 'l3extInstP|inet',
              'fvRsProv|p1')])
        self.assertEqual(1, len(result))
        result = result[0]
        self.assertEqual('fvRsProv', result.keys()[0])
        self.assertEqual('uni/tn-tn1/out-out/instP-inet/rsprov-p1',
                         list(result.values())[0]['attributes']['dn'])
Ejemplo n.º 5
0
def resource_equal(self, other):

    if type(self) != type(other):
        return False
    for attr in self.identity_attributes:
        if getattr(self, attr) != getattr(other, attr):
            return False
    for attr in self.other_attributes:
        if (utils.deep_sort(getattr(self, attr, None)) != utils.deep_sort(
                getattr(other, attr, None))):
            return False
    return True
Ejemplo n.º 6
0
 def test_get_resources(self):
     objs = [
         self._get_example_aci_fault(),
         {'fvBD': {
             'attributes': {'arpFlood': 'no',
                            'dn': 'uni/tn-test-tenant/BD-test',
                            'epMoveDetectMode': '',
                            'ipLearning': 'yes',
                            'limitIpLearnToSubnets': 'no',
                            'nameAlias': '',
                            'unicastRoute': 'yes',
                            'unkMacUcastAct': 'proxy'}}},
         {'fvRsCtx': {'attributes': {
             'dn': 'uni/tn-test-tenant/BD-test/rsctx', 'tnFvCtxName': ''}}},
         {'vzSubj': {'attributes': {'dn': 'uni/tn-t1/brc-c/subj-s',
                                    'nameAlias': ''}}},
         {'vzInTerm': {'attributes': {
             'dn': 'uni/tn-t1/brc-c/subj-s/intmnl'}}},
         {'vzOutTerm': {'attributes': {
             'dn': 'uni/tn-t1/brc-c/subj-s/outtmnl'}}},
         {'vzRsSubjFiltAtt': {'attributes': {
             'dn': 'uni/tn-t1/brc-c/subj-s/rssubjFiltAtt-f',
             'tnVzFilterName': 'f'}}},
         {'vzRsFiltAtt': {'attributes': {
             'dn': 'uni/tn-t1/brc-c/subj-s/intmnl/rsfiltAtt-g',
             'tnVzFilterName': 'g'}}},
         {'vzRsFiltAtt': {'attributes': {
             'dn': 'uni/tn-t1/brc-c/subj-s/outtmnl/rsfiltAtt-h',
             'tnVzFilterName': 'h'}}}]
     self._add_data_to_tree(objs, self.backend_state)
     keys = [('fvTenant|t1', 'fvAp|a1', 'fvAEPg|test', 'faultInst|951'),
             ('fvTenant|test-tenant', 'fvBD|test'),
             ('fvTenant|t1', 'vzBrCP|c', 'vzSubj|s', 'vzRsSubjFiltAtt|f'),
             ('fvTenant|t1', 'vzBrCP|c', 'vzSubj|s'),
             ('fvTenant|t1', 'vzBrCP|c', 'vzSubj|s', 'vzOutTerm|outtmnl'),
             ('fvTenant|t1', 'vzBrCP|c', 'vzSubj|s', 'vzInTerm|intmnl',
              'vzRsFiltAtt|g'),
             ('fvTenant|t1', 'vzBrCP|c', 'vzSubj|s', 'vzOutTerm|outtmnl',
              'vzRsFiltAtt|h'),
             ('fvTenant|t1', 'vzBrCP|c', 'vzSubj|s')]
     result = self.universe.get_resources(keys)
     self.assertEqual(utils.deep_sort(objs),
                      utils.deep_sort(result))
Ejemplo n.º 7
0
    def test_host_data_migration(self):
        self.mgr.create(self.ctx, infra.HostLink(
            host_name='h1', interface_name='eth0', path='h1/path/VPC'))
        self.mgr.create(self.ctx, infra.HostLink(
            host_name='h1', interface_name='eth1', path='h1/path/2'))
        self.mgr.create(self.ctx, infra.HostLink(
            host_name='h1', interface_name='eth2', path='h1/path/VPC'))
        self.mgr.create(self.ctx, infra.HostLink(
            host_name='h2', interface_name='eth2', path='h2/path'))

        epg1 = self.mgr.create(self.ctx, resource.EndpointGroup(
            tenant_name='t1', app_profile_name='ap', name='epg1',
            static_paths=[{'path': 'h1/path/2', 'encap': '100'},
                          {'path': 'h2/path', 'encap': '100'},
                          {'path': 'not_known', 'encap': '100'}]))
        epg2 = self.mgr.create(self.ctx, resource.EndpointGroup(
            tenant_name='t1', app_profile_name='ap', name='epg2',
            static_paths=[{'path': 'h1/path/2', 'encap': '100'},
                          {'path': 'h1/path/VPC', 'encap': '100'}]))
        dc = self.mgr.create(self.ctx, service_graph.DeviceCluster(
            tenant_name='t2', name='dc',
            devices=[{'path': 'h1/path/2', 'name': '1'},
                     {'path': 'h2/path', 'name': '2'}]))
        cdi1 = self.mgr.create(self.ctx, service_graph.ConcreteDeviceInterface(
            tenant_name='t2', device_cluster_name='dc', device_name='1',
            name='dc', path='h1/path/VPC'))
        cdi2 = self.mgr.create(self.ctx, service_graph.ConcreteDeviceInterface(
            tenant_name='t2', device_cluster_name='dc', device_name='2',
            name='dc', path='h2/path'))
        l3out_iface1 = self.mgr.create(
            self.ctx, resource.L3OutInterface(
                tenant_name='t2', l3out_name='dc', node_profile_name='1',
                interface_profile_name='dc1', interface_path='h1/path/VPC'))
        l3out_iface2 = self.mgr.create(
            self.ctx, resource.L3OutInterface(
                tenant_name='t2', l3out_name='dc', node_profile_name='1',
                interface_profile_name='dc2', interface_path='h2/path'))
        add_host_column.migrate(self.ctx.db_session)
        epg1 = self.mgr.get(self.ctx, epg1)
        self.assertEqual(
            utils.deep_sort(
                [{'path': 'h1/path/2', 'encap': '100', 'host': 'h1'},
                 {'path': 'h2/path', 'encap': '100', 'host': 'h2'},
                 {'path': 'not_known', 'encap': '100'}]),
            utils.deep_sort(epg1.static_paths))
        epg2 = self.mgr.get(self.ctx, epg2)
        self.assertEqual(
            utils.deep_sort(
                [{'path': 'h1/path/2', 'encap': '100', 'host': 'h1'},
                 {'path': 'h1/path/VPC', 'encap': '100', 'host': 'h1'}]),
            utils.deep_sort(epg2.static_paths))
        dc = self.mgr.get(self.ctx, dc)
        self.assertEqual(
            utils.deep_sort(
                [{'path': 'h1/path/2', 'name': '1', 'host': 'h1'},
                 {'path': 'h2/path', 'name': '2', 'host': 'h2'}]),
            utils.deep_sort(dc.devices))
        cdi1 = self.mgr.get(self.ctx, cdi1)
        self.assertEqual('h1', cdi1.host)
        cdi2 = self.mgr.get(self.ctx, cdi2)
        self.assertEqual('h2', cdi2.host)
        l3out_iface1 = self.mgr.get(self.ctx, l3out_iface1)
        self.assertEqual('h1', l3out_iface1.host)
        l3out_iface2 = self.mgr.get(self.ctx, l3out_iface2)
        self.assertEqual('h2', l3out_iface2.host)
    def test_load_domains(self):
        # create a VMM and PhysDom first
        pre_phys = resource.PhysicalDomain(name='pre-phys')
        pre_vmm = resource.VMMDomain(type='OpenStack', name='pre-vmm')
        ap = resource.ApplicationProfile(tenant_name='tn1', name='ap')
        pre_epg1 = resource.EndpointGroup(
            tenant_name='tn1', app_profile_name='ap', name='epg1')
        pre_epg2 = resource.EndpointGroup(
            tenant_name='tn1', app_profile_name='ap', name='epg2')
        self.mgr.create(self.ctx, resource.Tenant(name='tn1'))
        self.mgr.create(self.ctx, ap)
        self.mgr.create(self.ctx, pre_phys)
        self.mgr.create(self.ctx, pre_vmm)
        self.mgr.create(self.ctx, pre_epg2)
        self.mgr.create(self.ctx, pre_epg1)
        self.run_command('manager load-domains --no-mappings')
        # Verify pre-existing domains are still there
        self.assertIsNotNone(self.mgr.get(self.ctx, pre_phys))
        self.assertIsNotNone(self.mgr.get(self.ctx, pre_vmm))
        # Also the Domains defined in the config files exist
        self.assertIsNotNone(
            self.mgr.get(self.ctx, resource.PhysicalDomain(name='phys')))
        self.assertIsNotNone(
            self.mgr.get(self.ctx, resource.PhysicalDomain(name='phys2')))
        self.assertIsNotNone(
            self.mgr.get(self.ctx, resource.VMMDomain(type='OpenStack',
                                                      name='ostack')))
        self.assertIsNotNone(
            self.mgr.get(self.ctx, resource.VMMDomain(type='OpenStack',
                                                      name='ostack2')))
        self.assertIsNotNone(
            self.mgr.get(self.ctx, resource.VMMDomain(type='VMware',
                                                      name='vmware')))
        self.assertIsNotNone(
            self.mgr.get(self.ctx, resource.VMMDomain(type='VMware',
                                                      name='vmware2')))
        # EPGs are still empty
        pre_epg1 = self.mgr.get(self.ctx, pre_epg1)
        pre_epg2 = self.mgr.get(self.ctx, pre_epg2)

        self.assertEqual([], pre_epg1.vmm_domains)
        self.assertEqual([], pre_epg1.physical_domains)
        self.assertEqual([], pre_epg2.vmm_domains)
        self.assertEqual([], pre_epg2.physical_domains)

        # Delete one of them, and use the replace flag
        self.mgr.delete(self.ctx, resource.VMMDomain(type='OpenStack',
                                                     name='ostack2'))
        self.run_command('manager load-domains --replace --no-mappings')

        # Now only 2 Domains each exist
        self.assertEqual(4, len(self.mgr.find(self.ctx, resource.VMMDomain)))
        self.assertEqual(2, len(self.mgr.find(self.ctx,
                                              resource.PhysicalDomain)))

        # EPGs are still empty
        pre_epg1 = self.mgr.get(self.ctx, pre_epg1)
        pre_epg2 = self.mgr.get(self.ctx, pre_epg2)

        self.assertEqual([], pre_epg1.vmm_domains)
        self.assertEqual([], pre_epg1.physical_domains)
        self.assertEqual([], pre_epg2.vmm_domains)
        self.assertEqual([], pre_epg2.physical_domains)

        # now update the current environment
        cmd = 'manager load-domains --replace --enforce --no-mappings'
        self.run_command(cmd)
        pre_epg1 = self.mgr.get(self.ctx, pre_epg1)
        pre_epg2 = self.mgr.get(self.ctx, pre_epg2)

        def get_vmm(type, name):
            return {'type': type, 'name': name}

        def get_phys(name):
            return {'name': name}

        self.assertEqual(utils.deep_sort([get_vmm('OpenStack', 'ostack'),
                                          get_vmm('OpenStack', 'ostack2'),
                                          get_vmm('VMware', 'vmware'),
                                          get_vmm('VMware', 'vmware2')]),
                         utils.deep_sort(pre_epg1.vmm_domains))
        self.assertEqual(utils.deep_sort([get_phys('phys'),
                                          get_phys('phys2')]),
                         utils.deep_sort(pre_epg1.physical_domains))
        self.assertEqual(utils.deep_sort([get_vmm('OpenStack', 'ostack'),
                                          get_vmm('OpenStack', 'ostack2'),
                                          get_vmm('VMware', 'vmware'),
                                          get_vmm('VMware', 'vmware2')]),
                         utils.deep_sort(pre_epg2.vmm_domains))
        self.assertEqual(utils.deep_sort([get_phys('phys'),
                                          get_phys('phys2')]),
                         utils.deep_sort(pre_epg2.physical_domains))

        # re-run the command, but populate the  domain mappings
        self.run_command('manager load-domains --replace --enforce')

        pre_epg1 = self.mgr.get(self.ctx, pre_epg1)
        pre_epg2 = self.mgr.get(self.ctx, pre_epg2)

        def get_vmm(type, name):
            return {'type': type, 'name': name}

        def get_phys(name):
            return {'name': name}

        # The load-domains should creat host domain mappings with
        # wildcard entries for every entry in the configuration file
        existing_mappings = [{'domain_type': 'PhysDom',
                              'host_name': '*',
                              'domain_name': 'phys'},
                             {'domain_type': 'PhysDom',
                              'host_name': '*',
                              'domain_name': 'phys2'},
                             {'domain_type': 'OpenStack',
                              'host_name': '*',
                              'domain_name': 'ostack'},
                             {'domain_type': 'OpenStack',
                              'host_name': '*',
                              'domain_name': 'ostack'},
                             {'domain_type': 'VMware',
                              'host_name': '*',
                              'domain_name': 'vmware'},
                             {'domain_type': 'VMware',
                              'host_name': '*',
                              'domain_name': 'vmware2'}]
        for mapping in existing_mappings:
            mapping = infra.HostDomainMappingV2(
                host_name=mapping['host_name'],
                domain_name=mapping['domain_name'],
                domain_type=mapping['domain_type'])
            try:
                self.assertIsNotNone(self.mgr.get(self.ctx, mapping))
            except Exception:
                self.assertFalse(True)

        self.assertEqual(utils.deep_sort(
                         [get_vmm('OpenStack', 'ostack'),
                          get_vmm('OpenStack', 'ostack2'),
                          get_vmm('VMware', 'vmware'),
                          get_vmm('VMware', 'vmware2')]),
                         utils.deep_sort(pre_epg1.vmm_domains))
        self.assertEqual(utils.deep_sort([get_phys('phys'),
                                          get_phys('phys2')]),
                         utils.deep_sort(pre_epg1.physical_domains))
        self.assertEqual(utils.deep_sort([get_vmm('OpenStack', 'ostack'),
                                          get_vmm('OpenStack', 'ostack2'),
                                          get_vmm('VMware', 'vmware'),
                                          get_vmm('VMware', 'vmware2')]),
                         utils.deep_sort(pre_epg2.vmm_domains))
        self.assertEqual(utils.deep_sort([get_phys('phys'),
                                          get_phys('phys2')]),
                         utils.deep_sort(pre_epg2.physical_domains))

        # re-run the command, with host-specific domain mappings populated.
        # This should cause an exception
        self.mgr.create(self.ctx, infra.HostDomainMappingV2(
            host_name='host1',
            domain_name='ostack10',
            domain_type='OpenStack'))
        self.run_command('manager load-domains --enforce', raises=True)
 def sort_if_list(obj):
     return utils.deep_sort(obj)