Example #1
0
    def test_grid_sync_frequency_check(self):
        # prepare grid manager for sync
        stub = grid_sync_stub.GridSyncStub(self.ctx, self.connector_fixture)
        stub.prepare_grid_manager(wapi_version='1.8')
        grid_mgr = stub.get_grid_manager()
        grid_mgr._report_sync_time = mock.Mock()
        grid_mgr.mapping._sync_nios_for_network_view = mock.Mock()

        # test for no sync
        grid_mgr.grid_config.grid_sync_support = False
        grid_mgr.sync()
        assert not grid_mgr.member._discover_members.called
        assert not grid_mgr.grid_config._discover_config.called
        assert not grid_mgr.mapping._discover_network_views.called
        assert not grid_mgr.mapping._discover_networks.called
        last_sync_time = dbi.get_last_sync_time(self.ctx.session)
        self.assertIsNone(last_sync_time)

        # test for the first sync; expects sync
        grid_mgr.grid_config.grid_sync_support = True
        grid_mgr.sync()
        assert grid_mgr.member._discover_members.called_once
        assert grid_mgr.grid_config._discover_config.called_once
        assert grid_mgr.mapping._discover_network_views.called_once
        assert grid_mgr.mapping._discover_networks.called_once
        sync_time_from_second_sync = dbi.get_last_sync_time(self.ctx.session)
        self.assertEqual(sync_time_from_second_sync, grid_mgr.last_sync_time)

        # test for the second sync; expects no sync due to min wait time
        grid_mgr.grid_config.grid_sync_support = True
        grid_mgr.grid_config.grid_sync_minimum_wait_time = 10
        grid_mgr.sync()
        assert grid_mgr.member._discover_members.called_once
        assert grid_mgr.grid_config._discover_config.called_once
        assert grid_mgr.mapping._discover_network_views.called_once
        assert grid_mgr.mapping._discover_networks.called_once
        # should be the same as last_sync_time from the first sync
        # to prove that dicovery methods are not called in this test case.
        self.assertEqual(sync_time_from_second_sync, grid_mgr.last_sync_time)

        # test for the third sync; expects sync
        grid_mgr.grid_config.grid_sync_support = True
        grid_mgr.grid_config.grid_sync_minimum_wait_time = 0
        grid_mgr.sync()
        assert grid_mgr.member._discover_members.called_once
        assert grid_mgr.grid_config._discover_config.called_once
        assert grid_mgr.mapping._discover_network_views.called_once
        assert grid_mgr.mapping._discover_networks.called_once
        last_sync_time = dbi.get_last_sync_time(self.ctx.session)
        self.assertEqual(last_sync_time, grid_mgr.last_sync_time)
    def test_grid_sync_frequency_check(self):
        # prepare grid manager for sync
        stub = grid_sync_stub.GridSyncStub(self.ctx, self.connector_fixture)
        stub.prepare_grid_manager(wapi_version='1.8')
        grid_mgr = stub.get_grid_manager()
        grid_mgr._report_sync_time = mock.Mock()
        grid_mgr.mapping._sync_nios_for_network_view = mock.Mock()

        # test for no sync
        grid_mgr.grid_config.grid_sync_support = False
        grid_mgr.sync()
        assert not grid_mgr.member._discover_members.called
        assert not grid_mgr.grid_config._discover_config.called
        assert not grid_mgr.mapping._discover_network_views.called
        assert not grid_mgr.mapping._discover_networks.called
        last_sync_time = dbi.get_last_sync_time(self.ctx.session)
        self.assertIsNone(last_sync_time)

        # test for the first sync; expects sync
        grid_mgr.grid_config.grid_sync_support = True
        grid_mgr.sync()
        assert grid_mgr.member._discover_members.called_once
        assert grid_mgr.grid_config._discover_config.called_once
        assert grid_mgr.mapping._discover_network_views.called_once
        assert grid_mgr.mapping._discover_networks.called_once
        sync_time_from_second_sync = dbi.get_last_sync_time(self.ctx.session)
        self.assertEqual(sync_time_from_second_sync, grid_mgr.last_sync_time)

        # test for the second sync; expects no sync due to min wait time
        grid_mgr.grid_config.grid_sync_support = True
        grid_mgr.grid_config.grid_sync_minimum_wait_time = 10
        grid_mgr.sync()
        assert grid_mgr.member._discover_members.called_once
        assert grid_mgr.grid_config._discover_config.called_once
        assert grid_mgr.mapping._discover_network_views.called_once
        assert grid_mgr.mapping._discover_networks.called_once
        # should be the same as last_sync_time from the first sync
        # to prove that dicovery methods are not called in this test case.
        self.assertEqual(sync_time_from_second_sync, grid_mgr.last_sync_time)

        # test for the third sync; expects sync
        grid_mgr.grid_config.grid_sync_support = True
        grid_mgr.grid_config.grid_sync_minimum_wait_time = 0
        grid_mgr.sync()
        assert grid_mgr.member._discover_members.called_once
        assert grid_mgr.grid_config._discover_config.called_once
        assert grid_mgr.mapping._discover_network_views.called_once
        assert grid_mgr.mapping._discover_networks.called_once
        last_sync_time = dbi.get_last_sync_time(self.ctx.session)
        self.assertEqual(last_sync_time, grid_mgr.last_sync_time)
Example #3
0
    def test_grid_operations(self):
        # 'last_sync_time' operation type does not exist so it will add it
        last_sync_time = infoblox_db.get_last_sync_time(self.ctx.session)
        self.assertIsNone(last_sync_time)

        # 'last_sync_time' should exist now but its value should be None
        last_sync_time = infoblox_db.get_last_sync_time(self.ctx.session)
        self.assertIsNone(last_sync_time)

        # attempt to add 'last_sync_time' operation type should fail with
        # DBDuplicateEntry exception
        try:
            infoblox_db.add_operation_type(self.ctx.session, 'last_sync_time',
                                           '')
            self.ctx.session.flush()
        except db_exc.DBDuplicateEntry as db_err:
            self.assertIsInstance(db_err, db_exc.DBDuplicateEntry)

        # test record_last_sync_time
        current_time = datetime.utcnow().replace(microsecond=0)
        infoblox_db.record_last_sync_time(self.ctx.session, current_time)
        last_sync_time = infoblox_db.get_last_sync_time(self.ctx.session)
        self.assertEqual(current_time, last_sync_time)
    def test_grid_operations(self):
        # 'last_sync_time' operation type does not exist so it will add it
        last_sync_time = infoblox_db.get_last_sync_time(self.ctx.session)
        self.assertIsNone(last_sync_time)

        # 'last_sync_time' should exist now but its value should be None
        last_sync_time = infoblox_db.get_last_sync_time(self.ctx.session)
        self.assertIsNone(last_sync_time)

        # attempt to add 'last_sync_time' operation type should fail with
        # DBDuplicateEntry exception
        try:
            infoblox_db.add_operation_type(self.ctx.session,
                                           'last_sync_time',
                                           '')
            self.ctx.session.flush()
        except db_exc.DBDuplicateEntry as db_err:
            self.assertIsInstance(db_err, db_exc.DBDuplicateEntry)

        # test record_last_sync_time
        current_time = datetime.utcnow().replace(microsecond=0)
        infoblox_db.record_last_sync_time(self.ctx.session, current_time)
        last_sync_time = infoblox_db.get_last_sync_time(self.ctx.session)
        self.assertEqual(current_time, last_sync_time)
Example #5
0
 def is_sync_needed(self, resync_interval):
     session = self.grid_config.context.session
     self.last_sync_time = dbi.get_last_sync_time(session)
     return (not self.last_sync_time
             or (datetime.utcnow() - self.last_sync_time >
                 timedelta(seconds=resync_interval)))
Example #6
0
 def is_sync_needed(self, resync_interval):
     session = self.grid_config.context.session
     self.last_sync_time = dbi.get_last_sync_time(session)
     return (not self.last_sync_time or
             (datetime.utcnow() - self.last_sync_time > timedelta(
                 seconds=resync_interval)))