示例#1
0
    def test_recover_networks(self, mock_client):
        # Setup return values for get functions
        net = model.Network.from_neutron(fake_networks.fake_net2)
        mock_client.return_value.get_vpns.return_value = [net.vpn.data]
        mock_client.return_value.get_scopes.return_value = \
            [s.data for s in net.scopes.values()]
        mock_client.return_value.get_client_entries.return_value = \
            [ce.data for ce in net.client_entries.values()]
        mock_client.return_value.get_dns_views.return_value = [net.view.data]
        mock_client.return_value.get_ccm_zones.return_value = \
            [fz.data for fz in net.forward_zones.values()]
        mock_client.return_value.get_ccm_reverse_zones.return_value = \
            [rz.data for rz in net.reverse_zones.values()]
        mock_client.return_value.get_ccm_hosts.return_value = \
            [h.data for h in net.hosts.values()]

        # Extract key identifiers
        netid = fake_networks.fake_net2.id
        vpnid = net.vpn.data['id']
        viewid = net.view.data['viewId']
        zoneid = 'openstacklocal.'

        # Invoke recover_networks function
        networks = model.recover_networks()
        self.assertIn(netid, networks)
        rec = networks[netid]

        # Validate get functions are called as expected
        mock_client.return_value.get_vpns.assert_called_once_with()
        mock_client.return_value.get_scopes.assert_called_once_with(vpnid)
        mock_client.return_value.get_client_entries.assert_called_once_with()
        mock_client.return_value.get_dns_views.assert_called_once_with()
        mock_client.return_value.\
            get_ccm_zones.assert_called_once_with(viewid=viewid)
        mock_client.return_value.get_ccm_reverse_zones.assert_called_once_with(
            viewid=viewid)
        mock_client.return_value.get_ccm_hosts(viewid=viewid, zoneid=zoneid)

        # Validate that recover_networks returned correct data
        self.assertEqual(net.vpn.data, rec.vpn.data)
        self.assertEqual(net.view.data, rec.view.data)
        for scopeid in net.scopes:
            self.assertIn(scopeid, rec.scopes)
            self.assertEqual(net.scopes[scopeid].data,
                             rec.scopes[scopeid].data)
        for clientid in net.client_entries:
            self.assertIn(clientid, rec.client_entries)
            self.assertEqual(net.client_entries[clientid].data,
                             rec.client_entries[clientid].data)
        for fzid in net.forward_zones:
            self.assertIn(fzid, rec.forward_zones)
            self.assertEqual(net.forward_zones[fzid].data,
                             rec.forward_zones[fzid].data)
        for rzid in net.reverse_zones:
            self.assertIn(rzid, rec.reverse_zones)
            self.assertEqual(net.reverse_zones[rzid].data,
                             rec.reverse_zones[rzid].data)
        for hostid in net.hosts:
            self.assertIn(hostid, rec.hosts)
            self.assertEqual(net.hosts[hostid].data, rec.hosts[hostid].data)
示例#2
0
    def recover_networks(cls):
        """Track Network Objects.

        Creates global dict to track network objects across driver
        invocations and populates using the model module.
        """

        if "_networks" in globals():
            return

        global _networks
        _networks = model.recover_networks()
示例#3
0
    def recover_networks(cls):
        """Track Network Objects.

        Creates global dict to track network objects across driver
        invocations and populates using the model module.
        """

        if "_networks" in globals():
            return

        global _networks
        _networks = model.recover_networks()
示例#4
0
    def _synchronize_cpnr(cls):
        global last_activity
        while True:
            eventlet.sleep(cfg.CONF.cisco_pnr.sync_interval)
            if ((time.time() - last_activity) <
               cfg.CONF.cisco_pnr.sync_interval):
                    continue
            pnr_networks = model.recover_networks()
            # Delete stale VPNs in CPNR
            deleted_keys = set(pnr_networks.keys()) - set(
                               _networks.keys())
            for key in deleted_keys:
                deleted = pnr_networks[key]
                try:
                    lock = _locks.setdefault(deleted.vpn.data['name'],
                                             eventlet.semaphore.Semaphore())
                    with lock:
                        deleted.delete()
                except Exception:
                    LOG.exception(_LE('Failed to delete network %s in CPNR '
                                    'during sync:'), key)

            # Create VPNs in CPNR if not already present
            created_keys = set(_networks.keys()) - set(
                               pnr_networks.keys())
            for key in created_keys:
                created = _networks[key]
                try:
                    lock = _locks.setdefault(created.vpn.data['name'],
                                             eventlet.semaphore.Semaphore())
                    with lock:
                        created.create()
                except Exception:
                    LOG.exception(_LE('Failed to create network %s in CPNR '
                                    'during sync'), key)

            # Update VPNs in CPNR if normal update has been unsuccessful
            updated_keys = set(_networks.keys()) & set(
                               pnr_networks.keys())
            for key in updated_keys:
                updated = _networks[key]
                try:
                    lock = _locks.setdefault(updated.vpn.data['name'],
                                             eventlet.semaphore.Semaphore())
                    with lock:
                        pnr_networks[key].update(updated)
                except Exception:
                    LOG.exception(_LE('Failed to update network %s in CPNR '
                                    'during sync'), key)
示例#5
0
    def _synchronize_cpnr(cls):
        global last_activity
        while True:
            eventlet.sleep(cfg.CONF.cisco_pnr.sync_interval)
            if ((time.time() - last_activity) <
                    cfg.CONF.cisco_pnr.sync_interval):
                continue
            pnr_networks = model.recover_networks()
            # Delete stale VPNs in CPNR
            deleted_keys = set(pnr_networks.keys()) - set(_networks.keys())
            for key in deleted_keys:
                deleted = pnr_networks[key]
                try:
                    lock = _locks.setdefault(deleted.vpn.data['name'],
                                             eventlet.semaphore.Semaphore())
                    with lock:
                        deleted.delete()
                except Exception:
                    LOG.exception(
                        _LE('Failed to delete network %s in CPNR '
                            'during sync:'), key)

            # Create VPNs in CPNR if not already present
            created_keys = set(_networks.keys()) - set(pnr_networks.keys())
            for key in created_keys:
                created = _networks[key]
                try:
                    lock = _locks.setdefault(created.vpn.data['name'],
                                             eventlet.semaphore.Semaphore())
                    with lock:
                        created.create()
                except Exception:
                    LOG.exception(
                        _LE('Failed to create network %s in CPNR '
                            'during sync'), key)

            # Update VPNs in CPNR if normal update has been unsuccessful
            updated_keys = set(_networks.keys()) & set(pnr_networks.keys())
            for key in updated_keys:
                updated = _networks[key]
                try:
                    lock = _locks.setdefault(updated.vpn.data['name'],
                                             eventlet.semaphore.Semaphore())
                    with lock:
                        pnr_networks[key].update(updated)
                except Exception:
                    LOG.exception(
                        _LE('Failed to update network %s in CPNR '
                            'during sync'), key)
    def test_recover_networks(self, mock_client):
        # Setup return values for get functions
        net = model.Network.from_neutron(fake_networks.fake_net2)
        mock_client.return_value.get_vpns.return_value = [net.vpn.data]
        mock_client.return_value.get_scopes.return_value = [s.data for s in net.scopes.values()]
        mock_client.return_value.get_client_entries.return_value = [ce.data for ce in net.client_entries.values()]
        mock_client.return_value.get_dns_views.return_value = [net.view.data]
        mock_client.return_value.get_ccm_zones.return_value = [fz.data for fz in net.forward_zones.values()]
        mock_client.return_value.get_ccm_reverse_zones.return_value = [rz.data for rz in net.reverse_zones.values()]
        mock_client.return_value.get_ccm_hosts.return_value = [h.data for h in net.hosts.values()]

        # Extract key identifiers
        netid = fake_networks.fake_net2.id
        vpnid = net.vpn.data["id"]
        viewid = net.view.data["viewId"]
        zoneid = "openstacklocal."

        # Invoke recover_networks function
        networks = model.recover_networks()
        self.assertIn(netid, networks)
        rec = networks[netid]

        # Validate get functions are called as expected
        mock_client.return_value.get_vpns.assert_called_once_with()
        mock_client.return_value.get_scopes.assert_called_once_with(vpnid)
        mock_client.return_value.get_client_entries.assert_called_once_with()
        mock_client.return_value.get_dns_views.assert_called_once_with()
        mock_client.return_value.get_ccm_zones.assert_called_once_with(viewid=viewid)
        mock_client.return_value.get_ccm_reverse_zones.assert_called_once_with(viewid=viewid)
        mock_client.return_value.get_ccm_hosts(viewid=viewid, zoneid=zoneid)

        # Validate that recover_networks returned correct data
        self.assertEqual(net.vpn.data, rec.vpn.data)
        self.assertEqual(net.view.data, rec.view.data)
        for scopeid in net.scopes:
            self.assertIn(scopeid, rec.scopes)
            self.assertEqual(net.scopes[scopeid].data, rec.scopes[scopeid].data)
        for clientid in net.client_entries:
            self.assertIn(clientid, rec.client_entries)
            self.assertEqual(net.client_entries[clientid].data, rec.client_entries[clientid].data)
        for fzid in net.forward_zones:
            self.assertIn(fzid, rec.forward_zones)
            self.assertEqual(net.forward_zones[fzid].data, rec.forward_zones[fzid].data)
        for rzid in net.reverse_zones:
            self.assertIn(rzid, rec.reverse_zones)
            self.assertEqual(net.reverse_zones[rzid].data, rec.reverse_zones[rzid].data)
        for hostid in net.hosts:
            self.assertIn(hostid, rec.hosts)
            self.assertEqual(net.hosts[hostid].data, rec.hosts[hostid].data)